Example #1
0
        /// <summary>
        /// This is a Class designed to convert raw values into element objects (including masses and isotope abundances)
        /// and create an element dictionary searchable by key string such as "C" for carbon.
        /// </summary>
        public override void LoadLibrary()
        {
            m_symbolToCompoundMap = new Dictionary <string, Element>();
            m_enumToSymbolMap     = new Dictionary <ElementName, string>();

            ResolveUNCPath.MappedDriveResolver uncPathCheck = new ResolveUNCPath.MappedDriveResolver();
            string asemblyDirectoryOrUNCDirectory           = uncPathCheck.ResolveToUNC(PathUtilities.AssemblyDirectory);

            FileInfo constantsFileInfo = new FileInfo(System.IO.Path.Combine(asemblyDirectoryOrUNCDirectory, OMICS_ELEMENT_DATA_FILE));
            //FileInfo constantsFileInfo = new FileInfo(System.IO.Path.Combine(PathUtil.AssemblyDirectory, OMICS_ELEMENT_DATA_FILE));



            List <string>  elementSymbolList = new List <string>();
            List <Element> elementList       = new List <Element>();

            if (constantsFileInfo.Exists)
            {
                try
                {
                    LoadXML(constantsFileInfo.FullName, out elementSymbolList, out elementList);
                }
                catch
                {
                    LoadHardCoded(out elementSymbolList, out elementList);
                }
            }
            else
            {
                LoadHardCoded(out elementSymbolList, out elementList);
            }

            //if there is no file load from code
            if (elementSymbolList.Count == 0)//file did not work
            {
                LoadHardCoded(out elementSymbolList, out elementList);
            }

            if (elementSymbolList.Count == 0)//we still failed
            {
                throw new FileNotFoundException("The " + OMICS_ELEMENT_DATA_FILE + " file cannot be found at " + constantsFileInfo.FullName);
            }

            for (int i = 0; i < elementSymbolList.Count; i++)
            {
                m_symbolToCompoundMap.Add(elementSymbolList[i], elementList[i]);
            }

            int counter = 0;

            foreach (ElementName enumElement in Enum.GetValues(typeof(ElementName)))
            {
                m_enumToSymbolMap.Add(enumElement, elementList[counter].Symbol);
                counter++;
            }
        }
Example #2
0
        public void LoadPeriodicDableFromDiskOrCode()
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            string OMICS_ELEMENT_DATA_FILE = "PNNLOmicsElementData.xml";

            ResolveUNCPath.MappedDriveResolver uncPathCheck = new ResolveUNCPath.MappedDriveResolver();
            string asemblyDirectoryOrUNCDirectory           = uncPathCheck.ResolveToUNC(PathUtilities.AssemblyDirectory);

            FileInfo constantsFileInfo = new FileInfo(System.IO.Path.Combine(asemblyDirectoryOrUNCDirectory, OMICS_ELEMENT_DATA_FILE));

            ElementLibrary libraryLoad = new ElementLibrary();

            List <string>  elementSymbolList = new List <string>();
            List <Element> elementList       = new List <Element>();

            Assert.IsTrue(constantsFileInfo.Exists);

            if (constantsFileInfo.Exists)
            {
                try
                {
                    libraryLoad.LoadXML(constantsFileInfo.FullName, out elementSymbolList, out elementList);
                }
                catch
                {
                    //file missing
                }
            }

            Assert.AreEqual(elementList.Count, 104);
            Assert.AreEqual(elementSymbolList.Count, 104);
            Assert.AreEqual(elementList[50].MassAverage, 121.76);
            Assert.AreEqual(elementSymbolList[50], "Sb");

            elementSymbolList = null;
            elementList       = null;

            libraryLoad.LoadHardCoded(out elementSymbolList, out elementList);

            Assert.AreEqual(elementList.Count, 104);
            Assert.AreEqual(elementSymbolList.Count, 104);
            Assert.AreEqual(elementList[50].MassAverage, 121.76);
            Assert.AreEqual(elementSymbolList[50], "Sb");

            stopWatch.Stop();
            Console.WriteLine("This took " + stopWatch.Elapsed + "seconds to Load and initialize the library twice");
        }