Exemple #1
0
        private bool ParseCovalentRadius(string s, Qualities q)
        {
            const string   UNIT = Units.PicoMeter;
            ValueQualifier vq   = DoubleValue.FindQualifier(ref s);
            int            n    = s.IndexOf(UNIT);

            if (n > 0)
            {
                s = s.Substring(0, n - 1).Trim();
                int n2 = s.IndexOf("–");
                if (n2 > 0)
                {
                    string[] parts = s.Split('–');
                    double   d1, d2;
                    if (UnitValue.TryParse(parts[0], out d1) && UnitValue.TryParse(parts[1], out d2))
                    {
                        q.CovalentRadius = new UnitValue((d1 + d2) / 2, UNIT, vq);
                        return(true);
                    }
                }
                if (s.StartsWith("sp3"))
                {
                    s = s.Substring(5);
                }
                double d;
                if (UnitValue.TryParse(s, out d))
                {
                    q.CovalentRadius = new UnitValue(d, UNIT, vq);
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
 private bool ParseCriticalPoint(string s, Qualities q)
 {
     return(ParseTriple(s, Units.MegaPascals, tp =>
     {
         q.CriticalPoint = tp;
     }));
 }
Exemple #3
0
 private bool ParseTriplePoint(string s, Qualities q)
 {
     return(ParseTriple(s, Units.KiloPascals, tp =>
     {
         q.TriplePoint = tp;
     }));
 }
Exemple #4
0
        private bool ParseGroupBlock(string value, Qualities q)
        {
            const string GRP = "group", NA = "n/a";

            if (String.IsNullOrEmpty(value))
            {
                return(false);
            }
            value = value.Trim();
            if (!value.StartsWith(GRP))
            {
                return(false);
            }
            value = value.Substring(GRP.Length + 1);
            int gnum;

            if (value.StartsWith(NA))
            {
                gnum = 3;
            }
            else
            if (!UnitValue.TryParse(value, out gnum))
            {
                return(false);
            }
            int ndx = value.IndexOf(',');

            value = value.Substring(ndx + 2, 1);
            Group grp = new Group(gnum, value, q.Element.Number == 1);

            q.GroupBlock = grp;
            return(true);
        }
Exemple #5
0
        private bool ParseYoungsModulus(string s, Qualities q)
        {
            const string   UNIT = "GPa", EST = "est.";
            ValueQualifier vq = ValueQualifier.None;
            int            n  = s.IndexOf(EST);

            if (n > 0)
            {
                vq = ValueQualifier.Estimated;
                s  = s.Substring(n + EST.Length).Trim();
            }
            n = s.IndexOf(UNIT);
            if (n > 0)
            {
                s = s.Substring(0, n - 1).Trim();
                double d, d1;
                if (DoubleValue.TryParseRange(s, out d, out d1))
                {
                    d = (d + d1) / 2;
                }
                else
                {
                    UnitValue.TryParse(s, out d);
                }
                if (!Double.IsNaN(d))
                {
                    q.YoungsModulus = new UnitValue(d, UNIT, vq);
                    return(true);
                }
            }
            return(false);
        }
Exemple #6
0
        private bool ParseIntegers(string value, Qualities q)
        {
            // "+3, +2,[2] +1[3], −1, −2 ​(an amphoteric oxide)"
            value = RemoveBrackets(value);
            List <int> ri = new List <int>();

            foreach (String s in value.Split(',', ' ', ';'))
            {
                if (String.IsNullOrWhiteSpace(s))
                {
                    continue;
                }
                string ss = s;
                if (ss[0] == '−')
                {
                    ss = '-' + ss.Substring(1);                               // replace unicode $#8722
                }
                int i;
                if (Int32.TryParse(ss, NumberStyles.AllowLeadingSign, null, out i))
                {
                    ri.Add(i);
                }
                else
                {
                    break;
                }
            }
            if (ri.Count > 0)
            {
                SetValue(q, ri.ToArray());
                return(true);
            }
            return(false);
        }
Exemple #7
0
        private bool ParseBrinellHardness(string s, Qualities q)
        {
            const string UNIT = Units.MegaPascals;
            const char   DASH = '–';
            int          ndx  = s.IndexOf(UNIT);

            if (ndx > 0)
            {
                s   = s.Substring(0, ndx - 1).Trim();
                ndx = s.IndexOf(DASH);
                if (ndx > 0)
                {
                    string[] ss = s.Split(DASH);
                    double   d1, d2;
                    if (UnitValue.TryParse(ss[0], out d1) && UnitValue.TryParse(ss[1], out d2))
                    {
                        q.BrinellHardness = new UnitValueRange(d1, d2, UNIT);
                        return(true);
                    }
                }
                else
                {
                    double d;
                    if (UnitValue.TryParse(s, out d))
                    {
                        q.BrinellHardness = new UnitValueRange(d, d, UNIT);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #8
0
        private bool ParseElectricalResistivity(string v, Qualities q)
        {
            ValueQualifier vq = DoubleValue.FindQualifier(ref v);

            string[] UNITS = { "nΩ·m", "Ω·m", "µΩ·m" };
            double   f     = 1;

            for (int i = 0; i < UNITS.Length; ++i)
            {
                string s   = UNITS[i];
                int    ndx = v.IndexOf(s);
                if (ndx > 0)
                {
                    v = v.Substring(0, ndx - 1).Trim();
                    switch (i)
                    {
                    case 0: f = 0.001; break;

                    case 1: f = 1000000; break;
                    }
                }
                double d;
                if (UnitValue.TryParse(v, out d))
                {
                    q.ElectricalResistivity = new UnitValue(d * f, UNITS[2], vq);
                    return(true);
                }
            }
            return(false);
        }
Exemple #9
0
 private bool ParseCAS(string s, Qualities q)
 {
     s = StringEx.RemoveReferences(s);
     if (s.IndexOf('\n') > 0)
     {
         s = s.Replace("\n", "; ");
     }
     q.CASNumber = s;
     return(true);
 }
Exemple #10
0
        private bool ParseInteger(string v, Qualities q)
        {
            int i;

            if (UnitValue.TryParse(v, out i))
            {
                SetValue(q, i);
                return(true);
            }
            return(false);
        }
Exemple #11
0
        private bool ParseCrystalStructure(string v, Qualities q)
        {
            CrystalStructure cs;

            if (CrystalStructureEx.TryParse(v, out cs))
            {
                q.CrystalStructure = cs;
                return(true);
            }
            return(false);
        }
Exemple #12
0
        private bool ParseDouble(string v, Qualities q)
        {
            double d;

            if (UnitValue.TryParse(v, out d))
            {
                SetValue(q, d);
                return(true);
            }
            return(false);
        }
Exemple #13
0
        private bool ParseMagneticSusceptibility(string s, Qualities q)
        {
            s = StringEx.RemoveReferences(s);
            double d;

            if (DoubleValue.TryParseScientific(s, out d))
            {
                q.MagneticSusceptibility = new UnitValue(d, "cm3/mol");
                return(true);
            }
            return(false);
        }
Exemple #14
0
        private bool ParsePeriod(string v, Qualities q)
        {
            v = v.Replace("period", String.Empty).Trim();
            int p;

            if (Int32.TryParse(v, out p))
            {
                q.Period = p;
                return(true);
            }
            return(false);
        }
Exemple #15
0
        public bool TryGetNumeric(Qualities q, out double v)
        {
            v = Double.NaN;
            object o = q.GetValue(QualityName);

            if (o == null)
            {
                return(false);
            }
            v = (double)o;
            return(true);
        }
Exemple #16
0
        private bool SetValue(Qualities q, object v)
        {
            Type         t = q.GetType();
            PropertyInfo p = t.GetProperty(QualityName);

            if (p == null)
            {
                throw new Exception(String.Format("Property Qualities.{0} not found", QualityName));
            }
            p.SetValue(q, v);
            return(true);
        }
Exemple #17
0
        private bool ParseElectronConfiguration(string s, Qualities q)
        {
            s = StringEx.RemoveReferences(s);
            const string   LB = "or\n";
            ValueQualifier vq = DoubleValue.FindQualifier(ref s);

            if (s.IndexOf(LB) > 0)
            {
                s = s.Replace(LB, ";");
            }
            q.ElectronConfiguration = new QualifiedString(s.Trim(), vq);
            return(true);
        }
Exemple #18
0
 private bool ParsePhase(string v, Qualities q)
 {
     v = StringEx.RemoveReferences(v);
     try
     {
         q.Phase = new QualifiedPhase(v);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #19
0
        private bool ParseDiscovery(string s, Qualities q)
        {
            s = StringEx.RemoveReferences(s);
            int n1 = s.LastIndexOf("("), n2 = s.LastIndexOf(')');

            if (n1 > 0 && n2 > n1)
            {
                string disco = s.Substring(0, n1).Trim();
                string syr   = s.Substring(n1 + 1);
                n1 = syr.IndexOf("June");                 // Boron
                if (n1 > 0)
                {
                    syr = syr.Substring(n1 + 5).Trim();
                }
                bool   isBC = syr.IndexOf("BCE") > 0;
                double d;
                if (UnitValue.TryParse(syr, out d))
                {
                    int yr = (int)d;
                    if (isBC)
                    {
                        yr *= -1;
                    }
                    q.Discovery = new Discovery(disco, yr);
                    return(true);
                }
            }
            else             // Sn, Sb have no parens
            {
                n1 = s.IndexOf("BC");
                if (n1 > 0)
                {
                    string disco = String.Empty;
                    s = s.Substring(0, n1 - 1).Trim();
                    // before 5000
                    int nn = s.IndexOfAny(StringEx.Digits);
                    if (nn > 0)
                    {
                        disco = s.Substring(0, nn - 1).Trim();
                        s     = s.Substring(nn).Trim();
                    }
                    double d;
                    if (UnitValue.TryParse(s, out d))
                    {
                        q.Discovery = new Discovery(disco, -(int)d);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #20
0
        private bool ParseHeatCapacity(string s, Qualities q)
        {
            const string UNITS = "J/(mol·K)";

            s = StringEx.RemoveReferences(s);
            double d;

            if (UnitValue.TryParse(s, UNITS, out d))
            {
                q.MolarHeatCapacity = new UnitValue(d, UNITS);
                return(true);
            }
            return(false);
        }
Exemple #21
0
        /// <summary>
        /// Read element qualities from the table
        /// </summary>
        /// <param name="fpath"></param>
        public void ReadTable(string fpath)
        {
            string[] lines = File.ReadAllLines(fpath);
            int      nLine = 2;

            foreach (Element e in this)
            {
                string line = lines[nLine++];
                if (!line.StartsWith(e.Name))
                {
                    throw new Exception(String.Format("Mismatch between element '{0}' and line '{1}'.", e.Name, line));
                }
                Qualities q = new Qualities(e);
                q.ReadValues(line);
            }
        }
Exemple #22
0
        /// <summary>
        /// Dump all qualities of all elements into a table.
        /// </summary>
        /// <param name="outDir"></param>
        /// <param name="tblName"></param>
        public void CreateTable(string outDir, string tblName = "")
        {
            if (String.IsNullOrEmpty(tblName))
            {
                tblName = "table.txt";
            }
            string        fpath = Path.Combine(outDir, tblName);
            StringBuilder s     = new StringBuilder();

            s.AppendLine(Qualities.QualityHeader());
            s.AppendLine(Qualities.UnitsHeader());
            foreach (Element e in this)
            {
                s.AppendLine(e.Qualities.Values());
            }
            File.WriteAllText(fpath, s.ToString());
        }
Exemple #23
0
        private bool ParseSpeedOfSound(string s, Qualities q)
        {
            const string UNIT = "m/s";
            int          n    = s.IndexOf(UNIT);

            if (n > 0)
            {
                s = s.Substring(0, n - 1).Replace(",", String.Empty);
                double d;
                if (UnitValue.TryParse(s, out d))
                {
                    q.SpeedOfSound = new UnitValue(d, UNIT);
                    return(true);
                }
            }
            return(false);
        }
Exemple #24
0
        private bool ParseBulkModulus(string s, Qualities q)
        {
            const string UNIT = Units.GigaPascals;
            int          ndx  = s.IndexOf(UNIT);

            if (ndx > 0)
            {
                s = s.Substring(0, ndx - 1).Trim();
                double d;
                if (UnitValue.TryParse(s, out d))
                {
                    q.BulkModulus = new UnitValue(d, UNIT);
                    return(true);
                }
            }
            return(false);
        }
Exemple #25
0
        private bool ParseDU(string v, string unitName, Qualities q)
        {
            if (String.IsNullOrEmpty(v))
            {
                return(false);
            }
            v = StringEx.RemoveReferences(v);
            ValueQualifier vq = DoubleValue.FindQualifier(ref v);
            double         d;

            if (UnitValue.TryParse(v, unitName, out d))
            {
                UnitValue uv = new UnitValue(d, unitName, vq);
                return(SetValue(q, uv));
            }
            return(false);
        }
Exemple #26
0
        private bool ParseShearModulus(string s, Qualities q)
        {
            const string UNIT = "GPa";

            s = StringEx.RemoveReferences(s);
            double d;

            if (s.IndexOf("–") > 0)
            {
                double d1, d2;
                if (DoubleValue.TryParseRange(s, out d1, out d2))
                {
                    d = (d1 + d2) / 2;
                    q.ShearModulus = new UnitValue(d, UNIT);
                }
            }
            return(ParseDU(s, UNIT, q));
        }
Exemple #27
0
        private bool ParseVanDerWaalsRadius(string s, Qualities q)
        {
            const string   UNIT = "pm";
            ValueQualifier vq   = DoubleValue.FindQualifier(ref s);
            int            n    = s.IndexOf(UNIT);

            if (n > 0)
            {
                s = s.Substring(0, n - 1).Trim();
                double d;
                if (UnitValue.TryParse(s, out d))
                {
                    q.VanDerWaalsRadius = new UnitValue(d, UNIT, vq);
                    return(true);
                }
            }
            return(false);
        }
Exemple #28
0
        private bool ParseAtomicRadius(string s, Qualities q)
        {
            const string   UNIT = Units.PicoMeter;
            ValueQualifier vq   = DoubleValue.FindQualifier(ref s);
            int            ndx  = s.IndexOf(UNIT);

            if (ndx > 0)
            {
                s = s.Substring(0, ndx - 1).Trim();
                double d;
                if (UnitValue.TryParse(s, out d))
                {
                    q.AtomicRadius = new UnitValue(d, UNIT, vq);
                    return(true);
                }
            }
            return(false);
        }
Exemple #29
0
        private bool ParseIE(string value, Qualities q)
        {
            // Parse Ionization Energies
            // "1st: 499 kJ/mol\n2nd: 1170 kJ/mol\n3rd: 1900 kJ/mol\n(more)"
            string[]      parts = value.Split(':', '\n');
            UnitValueList r     = new UnitValueList();

            foreach (string s in parts)
            {
                if (s.IndexOf("kJ/mol") > 0)
                {
                    r.Add(new UnitValue(s));
                }
            }
            if (r.Count > 0)
            {
                SetValue(q, r);
                return(true);
            }
            return(false);
        }
Exemple #30
0
        private bool ParseVickersHardness(string s, Qualities q)
        {
            string UNIT = "MPa";
            int    n    = s.IndexOf(UNIT);

            if (n > 0)
            {
                s = s.Substring(0, n - 1).Trim();
                double d1, d2;
                if (DoubleValue.TryParseRange(s, out d1, out d2))
                {
                    q.VickersHardness = new UnitValueRange(d1, d2, UNIT);
                }
                else
                if (UnitValue.TryParse(s, out d1))
                {
                    q.VickersHardness = new UnitValueRange(d1, d1, UNIT);
                }
            }
            return(q.VickersHardness != null);
        }