Пример #1
0
        public Salz(Kation kation, Anion anion)
        {
            Kation = kation;
            Anion  = anion;

            (int anzahlKation, int anzahlAnionen)benoetigeMolekuehle = Ion.BerechneAnzahlMolekuele(kation, anion);
            Kation.Molekuel.Anzahl = benoetigeMolekuehle.anzahlKation;
            Anion.Molekuel.Anzahl  = benoetigeMolekuehle.anzahlAnionen;

            if (Anion.Molekuel.Atombindung.IstElementbindung())
            {
                if (!String.IsNullOrEmpty(Anion.Molekuel.Atombindung.ErhalteElement().Wurzel))
                {
                    Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.ErhalteElement().Wurzel.ToLower() + "id";
                }
                else
                {
                    Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.ErhalteElement().Name.ToLower() + "id";
                }
            }
            else
            {
                Name = Kation.Molekuel.Atombindung.Name + Anion.Molekuel.Atombindung.Name.ToLower();
            }

            if (Kation.Molekuel.Anzahl > 1)
            {
                if (Kation.Molekuel.Atombindung.IstElementbindung())
                {
                    ChemischeFormel += $"{Kation.Molekuel.Atombindung.ChemischeFormel}{UnicodeHelfer.GetSubscriptOfNumber(Kation.Molekuel.Anzahl)}";
                }
                else
                {
                    ChemischeFormel += $"({Kation.Molekuel.Atombindung.ChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(Kation.Molekuel.Anzahl)}";
                }
            }
            else
            {
                ChemischeFormel += $"{Kation.Molekuel.Atombindung.ChemischeFormel}";
            }

            if (Anion.Molekuel.Anzahl > 1)
            {
                if (UnicodeHelfer.GetNumberOfSubscript(Anion.Molekuel.Atombindung.ChemischeFormel.Last()) != -1)
                {
                    ChemischeFormel += $"({Anion.Molekuel.Atombindung.ChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(Anion.Molekuel.Anzahl)}";
                }
                else
                {
                    ChemischeFormel += $"{Anion.Molekuel.Atombindung.ChemischeFormel}{UnicodeHelfer.GetSubscriptOfNumber(Anion.Molekuel.Anzahl)}";
                }
            }
            else
            {
                ChemischeFormel += $"{Anion.Molekuel.Atombindung.ChemischeFormel}";
            }
        }
Пример #2
0
        public Saeure(string chemischeFormel)
        {
            // Überprüfe, ob die Formel mit einem Wasserstoffatom beginnt
            if (chemischeFormel[0].Equals('H') == false)
            {
                throw new Exception("Die Säureformel muss mit mindestens einem Wasserstoffatom beginnen");
            }

            // Überprüfe, ob des den Stoff Wasserstoff im Periodensystem gibt
            Nichtmetall wasserstoff = Periodensystem.Instance.FindeNichtmetallNachAtomsymbol("H");

            if (wasserstoff == null)
            {
                throw new Exception("Wasserstoff konnte im Periodensystem nicht gefunden werden");
            }

            if (chemischeFormel.Contains("(") == false)
            {
                // Muss präperiert werden
                if (UnicodeHelfer.GetNumberOfSubscript(chemischeFormel[1]) != -1)
                {
                    if (chemischeFormel.Length > 3 && Periodensystem.Instance.UberpruefeObElement(chemischeFormel.Substring(2)) == false)
                    {
                        chemischeFormel = $"{chemischeFormel.Substring(0, 2)}({chemischeFormel.Substring(2)})₁";
                    }
                }
                else
                {
                    if (chemischeFormel.Length > 2 && Periodensystem.Instance.UberpruefeObElement(chemischeFormel.Substring(1)) == false)
                    {
                        chemischeFormel = $"{chemischeFormel.Substring(0, 1)}({chemischeFormel.Substring(1)})₁";
                    }
                }
            }

            // Generiere die Bestandteile aus der chemischen Formel
            Bestandteile = GeneriereBestandteileAusChemischerFormel(chemischeFormel);

            foreach (Molekuel molekuel in ErhalteAlleMolekuele())
            {
                if (molekuel.Atombindung.IstElementbindung())
                {
                    Element element = molekuel.Atombindung.ErhalteElement();
                    if (element.Symol.Equals("H"))
                    {
                        Wasserstoff = molekuel;
                        continue;
                    }
                }

                Saeurerest = molekuel;
            }

            // Generiere die chemische Formel
            GeneriereName();
            ChemischeFormel = GeneriereChemischeFormelAusBestandteilen(fuerAnzeige: false);
        }
Пример #3
0
        public Atombindung(Element element, int anzahlAtome)
        {
            Bestandteile     = new List <Element[]>();
            ChemischeFormel += (anzahlAtome == 1) ? element.Symol : element.Symol + UnicodeHelfer.GetSubscriptOfNumber(anzahlAtome);
            Name             = (anzahlAtome == 1) ? element.Name : NomenklaturHelfer.Praefix(anzahlAtome) + element.Name.ToLower();

            AddBestandteil(element, anzahlAtome);
            AnzahlAtome = anzahlAtome;

            //Name = GeneriereNameErsterOrdnung();
        }
Пример #4
0
        public List <Element[]> GeneriereBestandteileAusChemischerFormel(string chemischeFormel = null)
        {
            List <Element[]> bestandteile = new List <Element[]>();

            if (chemischeFormel == null)
            {
                chemischeFormel = ChemischeFormel;
            }

            string[] splittedArray = chemischeFormel.Split('(', ')');
            for (int cnt = 0; cnt < splittedArray.Length; cnt++)
            {
                if (cnt + 1 != splittedArray.Length && splittedArray[cnt + 1].Length == 1)
                {
                    int anzahlSubBestandteil = UnicodeHelfer.GetNumberOfSubscript(splittedArray[cnt + 1][0]);
                    if (anzahlSubBestandteil != -1)
                    {
                        Element[] subBestandteil = GeneriereBestandteileAusChemischerFormel(splittedArray[cnt]).SelectMany(x => x).ToArray();
                        for (int zaehler = 0; zaehler < anzahlSubBestandteil; zaehler++)
                        {
                            bestandteile.Add(subBestandteil);
                        }
                    }

                    // Um das Subscript zu überspringen
                    cnt++;
                }
                else
                {
                    // Erhalte die einzelnen elementaren Bestandteile aus der Formel
                    char[] formelzeichen = splittedArray[cnt].ToCharArray();
                    for (int position = 0; position < formelzeichen.Length; position++)
                    {
                        // Erhalte das aktuelle Symbol aus der Formel
                        string elementSymbol = formelzeichen[position].ToString();

                        if (position + 1 < formelzeichen.Length)
                        {
                            // Überprüfe, ob das nächste Symbol zum selben Element gehört
                            if (char.IsLower(formelzeichen[position + 1]))
                            {
                                // Erhöhe die Position um 1
                                position += 1;

                                // Erweitere das Symbol des Elementes
                                elementSymbol += formelzeichen[position].ToString();
                            }

                            Element element = Periodensystem.Instance.FindeMetallNachAtomsymbol(elementSymbol);
                            if (element == null)
                            {
                                element = Periodensystem.Instance.FindeNichtmetallNachAtomsymbol(elementSymbol);
                                if (element == null)
                                {
                                    throw new System.Exception($"Konnte das Element[{elementSymbol}] im Periodensystem nicht finden.");
                                }
                            }

                            if (position + 1 < formelzeichen.Length)
                            {
                                //Überprüfe, ob das nächste Symbol die Atomzahl des Elementes angibt
                                if (UnicodeHelfer.GetNumberOfSubscript(formelzeichen[position + 1]) != -1)
                                {
                                    // Erhöhe die Position um 1
                                    position += 1;

                                    // Erhalte die Atomzahl des Elementes
                                    int atomAnzahl = UnicodeHelfer.GetNumberOfSubscript(formelzeichen[position]);

                                    // Ersetlle das Molekuel
                                    for (int cnt2 = 0; cnt2 < atomAnzahl; cnt2++)
                                    {
                                        bestandteile.Add(new Element[] { element });
                                    }
                                }
                                else
                                {
                                    bestandteile.Add(new Element[] { element });
                                }
                            }
                            else
                            {
                                bestandteile.Add(new Element[] { element });
                            }
                        }
                        else
                        {
                            Element element = Periodensystem.Instance.FindeMetallNachAtomsymbol(elementSymbol);
                            if (element == null)
                            {
                                element = Periodensystem.Instance.FindeNichtmetallNachAtomsymbol(elementSymbol);
                                if (element == null)
                                {
                                    throw new System.Exception($"Konnte das Element[{elementSymbol}] im Periodensystem nicht finden.");
                                }
                            }

                            bestandteile.Add(new Element[] { element });
                        }
                    }
                }
            }

            return(bestandteile);
        }
Пример #5
0
        public string GeneriereChemischeFormelAusBestandteilen(List <Element[]> bestandteile = null, bool fuerAnzeige = false)
        {
            string chemischeFormel = null;

            if (bestandteile == null)
            {
                bestandteile = Bestandteile;
            }

            int anzahlAktuellerBestandteil = 1;

            for (int zaehler = 0; zaehler < bestandteile.Count; zaehler++)
            {
                // Erhalte das aktuelle Bestandteil
                Element[] bestandteil = bestandteile[zaehler];

                // Überprüfe, ob es das letze Bestandteil in der Sequenz ist
                if (zaehler != bestandteile.Count - 1)
                {
                    // Es gibt noch weitere bestandteile. Überprüfe, ob es sich ums selbe Bestandteil handelt
                    if (bestandteil.Length == bestandteile[zaehler + 1].Length)
                    {
                        // Überprüfe, ob die sequenz identisch ist
                        bool identisch = true;
                        for (int cnt = 0; cnt < bestandteil.Length; cnt++)
                        {
                            if (bestandteil[cnt].Symol.Equals(bestandteile[zaehler + 1][cnt].Symol) == false)
                            {
                                identisch = false;
                            }
                        }

                        if (identisch)
                        {
                            anzahlAktuellerBestandteil++;
                            continue;
                        }
                    }
                }

                // Der nächste Bestandteil unterschiedet sich von diesem => Erstelle die Formel für dieses Molekül

                // Überprüfe, ob sich um eine Elementarbindung handelt
                if (bestandteil.Length == 1)
                {
                    chemischeFormel += (anzahlAktuellerBestandteil == 1) ? bestandteil[0].Symol : $"{bestandteil[0].Symol}{UnicodeHelfer.GetSubscriptOfNumber(anzahlAktuellerBestandteil)}";
                }
                else
                {
                    string subChemischeFormel            = null;
                    int    anzahlAktuellerSubBestandteil = 1;
                    for (int cnt = 0; cnt < bestandteil.Length; cnt++)
                    {
                        if (cnt + 1 != bestandteil.Length)
                        {
                            if (bestandteil[cnt].Symol.Equals(bestandteil[cnt + 1].Symol))
                            {
                                anzahlAktuellerSubBestandteil++;
                                continue;
                            }
                        }

                        subChemischeFormel += (anzahlAktuellerSubBestandteil == 1) ? bestandteil[cnt].Symol : $"{bestandteil[cnt].Symol}{UnicodeHelfer.GetSubscriptOfNumber(anzahlAktuellerSubBestandteil)}";
                    }

                    if (fuerAnzeige)
                    {
                        chemischeFormel += (anzahlAktuellerBestandteil == 1) ? subChemischeFormel : $"({subChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(anzahlAktuellerBestandteil)}";
                    }
                    else
                    {
                        chemischeFormel += $"({subChemischeFormel}){UnicodeHelfer.GetSubscriptOfNumber(anzahlAktuellerBestandteil)}";
                    }
                }

                // Bestandteile zurücksetzen
                anzahlAktuellerBestandteil = 1;
            }

            return(chemischeFormel);
        }
Пример #6
0
        public List <Element[]> ErhalteBestandteileSequentiell(string chemischeFormel = null)
        {
            List <Element[]> bestandteile = new List <Element[]>();

            if (chemischeFormel == null)
            {
                chemischeFormel = ChemischeFormel;
            }

            if (chemischeFormel.Contains("("))
            {
                string molekuelFormel = chemischeFormel.Substring(chemischeFormel.IndexOf("(") + 1, chemischeFormel.IndexOf(")") - (chemischeFormel.IndexOf("(") + 1));
                bestandteile.AddRange(ErhalteBestandteileSequentiell(molekuelFormel));

                chemischeFormel = chemischeFormel.Substring(0, chemischeFormel.IndexOf("("));
            }

            // Erhalte die einzelnen elementaren Bestandteile aus der Formel
            char[] formelzeichen = chemischeFormel.ToCharArray();
            for (int position = 0; position < formelzeichen.Length; position++)
            {
                // Erhalte das aktuelle Symbol aus der Formel
                string elementSymbol = formelzeichen[position].ToString();

                if (position + 1 < formelzeichen.Length)
                {
                    // Überprüfe, ob das nächste Symbol zum selben Element gehört
                    if (char.IsLower(formelzeichen[position + 1]))
                    {
                        // Erhöhe die Position um 1
                        position += 1;

                        // Erweitere das Symbol des Elementes
                        elementSymbol += formelzeichen[position].ToString();
                    }

                    Element element = Periodensystem.Instance.FindeMetallNachAtomsymbol(elementSymbol);
                    if (element == null)
                    {
                        element = Periodensystem.Instance.FindeNichtmetallNachAtomsymbol(elementSymbol);
                        if (element == null)
                        {
                            throw new System.Exception($"Konnte das Element[{elementSymbol}] im Periodensystem nicht finden.");
                        }
                    }

                    if (position + 1 < formelzeichen.Length)
                    {
                        //Überprüfe, ob das nächste Symbol die Atomzahl des Elementes angibt
                        if (UnicodeHelfer.GetNumberOfSubscript(formelzeichen[position + 1]) != -1)
                        {
                            // Erhöhe die Position um 1
                            position += 1;

                            // Erhalte die Atomzahl des Elementes
                            int atomAnzahl = UnicodeHelfer.GetNumberOfSubscript(formelzeichen[position]);

                            // Ersetlle das Molekuel
                            for (int cnt = 0; cnt < atomAnzahl; cnt++)
                            {
                                bestandteile.Add(new Element[] { element });
                            }
                        }
                        else
                        {
                            bestandteile.Add(new Element[] { element });
                        }
                    }
                    else
                    {
                        bestandteile.Add(new Element[] { element });
                    }
                }
                else
                {
                    Element element = Periodensystem.Instance.FindeMetallNachAtomsymbol(elementSymbol);
                    if (element == null)
                    {
                        element = Periodensystem.Instance.FindeNichtmetallNachAtomsymbol(elementSymbol);
                        if (element == null)
                        {
                            throw new System.Exception($"Konnte das Element[{elementSymbol}] im Periodensystem nicht finden.");
                        }
                    }

                    bestandteile.Add(new Element[] { element });
                }
            }

            return(bestandteile);
        }