AddIsotope() приватный Метод

Add an isotope to this element
private AddIsotope ( int atomicNumber, double atomicMass, float abundance ) : Isotope
atomicNumber int The atomic number of the isotope
atomicMass double The atomic mass of the isotope
abundance float The natural relative abundance of the isotope
Результат Isotope
Пример #1
0
        /// <summary>
        /// Load a xml file containing elemental and isotopic data into the periodic table
        /// </summary>
        public void LoadElements(Stream elementsListXml)
        {
            using (XmlReader reader = XmlReader.Create(elementsListXml))
            {
                reader.ReadToFollowing("PeriodicTable");
                _uniqueId = int.Parse(reader.GetAttribute("defaultID"));
                int isotopes = int.Parse(reader.GetAttribute("isotopesCount"));
                _isotopes = new Isotope[isotopes];
                while (reader.ReadToFollowing("Element"))
                {
                    reader.ReadToFollowing("Name");
                    string name = reader.ReadElementContentAsString();
                    reader.ReadToFollowing("Symbol");
                    string symbol = reader.ReadElementContentAsString();
                    reader.ReadToFollowing("AtomicNumber");
                    int atomicnumber = reader.ReadElementContentAsInt();
                    reader.ReadToFollowing("ValenceElectrons");
                    int valenceElectrons = reader.ReadElementContentAsInt();
                    Element element = new Element(name, symbol, atomicnumber, valenceElectrons);

                    bool isStartNode = reader.ReadToNextSibling("Isotope");
                    while(isStartNode)
                    {
                        string unqiueId = reader.GetAttribute("uniqueID");
                        reader.ReadToFollowing("Mass");
                        double mass = reader.ReadElementContentAsDouble();
                        reader.ReadToFollowing("MassNumber");
                        int massNumber = reader.ReadElementContentAsInt();
                        reader.ReadToFollowing("RelativeAbundance");
                        float abundance = reader.ReadElementContentAsFloat();
                        if (abundance > 0)
                        {
                            Isotope isotope = element.AddIsotope(massNumber, mass, abundance);

                            if (unqiueId != null)
                            {
                                int uniqueId = int.Parse(unqiueId);
                                isotope.UniqueId = uniqueId;
                                _isotopes[uniqueId] = isotope;
                            }
                            else
                            {
                                isotope.UniqueId = _uniqueId;
                                _isotopes[_uniqueId++] = isotope;
                            }
                        }
                        if (!reader.IsStartElement("Isotope"))
                            isStartNode = reader.ReadToNextSibling("Isotope");
                    }
                    AddElement(element);
                }
            }

            if(_isotopes.Length != _uniqueId)
                Array.Resize(ref _isotopes, _uniqueId);
        }
Пример #2
0
        /// <summary>
        /// Load a xml file containing elemental and isotopic data into the periodic table
        /// </summary>
        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);
            }
        }
Пример #3
0
        /// <summary>
        /// Load a xml file containing elemental and isotopic data into the periodic table
        /// </summary>
        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);
        }