CSMSL.Chemistry.PeriodicTable.Load C# (CSharp) Method

Load() public static method

Load a xml file containing elemental and isotopic data into the periodic table
public static Load ( string filePath ) : void
filePath string
return void
        public static void Load(string filePath)
        {
            _elements.Clear();
            Element element = null;
            _isotopes = new Isotope[500];
            BiggestIsotopeNumber = -1;
            using (XmlReader reader = XmlReader.Create(filePath))
            {
                while (reader.Read())
                {
                    if (!reader.IsStartElement())
                        continue;

                    switch (reader.Name)
                    {
                        case "Element":
                            string name = reader["Name"];
                            string symbol = reader["Symbol"];
                            int atomicnumber = int.Parse(reader["AtomicNumber"]);
                            int valenceElectrons = int.Parse(reader["ValenceElectrons"]);
                            element = new Element(name, symbol, atomicnumber, valenceElectrons);
                            AddElement(element);
                            break;
                        case "Isotope":
                            string unqiueId = reader["Id"];
                            string a = reader["Mass"];
                            double mass = double.Parse(reader["Mass"], CultureInfo.CurrentCulture);
                            int massNumber = int.Parse(reader["MassNumber"]);
                            float abundance = float.Parse(reader["Abundance"], CultureInfo.CurrentCulture);
                            if (abundance > 0 && element != null)
                            {
                                Isotope isotope = element.AddIsotope(massNumber, mass, abundance);

                                if (unqiueId != null)
                                {
                                    int uniqueId = int.Parse(unqiueId);
                                    if (uniqueId > BiggestIsotopeNumber)
                                        BiggestIsotopeNumber = uniqueId;
                                    isotope.UniqueId = uniqueId;
                                    _isotopes[uniqueId] = isotope;
                                }
                                else
                                {
                                    isotope.UniqueId = BiggestIsotopeNumber;
                                    _isotopes[BiggestIsotopeNumber++] = isotope;
                                }
                            }
                            break;
                    }
                }
            }

            if (_isotopes.Length > BiggestIsotopeNumber)
                Array.Resize(ref _isotopes, BiggestIsotopeNumber + 1);
        }

Same methods

PeriodicTable::Load ( ) : void