Example #1
0
        public void TestReadIsotopes2()
        {
            var isotopeData = "<?xml version=\"1.0\"?>" + "<list xmlns=\"http://www.xml-cml.org/schema/cml2/core\""
                              + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
                              + "    xsi:schemaLocation=\"http://www.xml-cml.org/schema/cml2/core ../../io/cml/data/cmlCore.xsd\">"
                              + "" + "    <isotopeList id=\"H\">"
                              + "        <isotope id=\"H1\" isotopeNumber=\"1\" elementType=\"H\">"
                              + "            <abundance dictRef=\"cdk:relativeAbundance\">100.0</abundance>"
                              + "            <scalar dictRef=\"cdk:exactMass\">1.00782504</scalar>"
                              + "            <scalar dictRef=\"cdk:atomicNumber\">1</scalar>" + "        </isotope>"
                              + "        <isotope id=\"H2\" isotopeNumber=\"2\" elementType=\"H\">"
                              + "            <abundance dictRef=\"cdk:relativeAbundance\">0.015</abundance>"
                              + "            <scalar dictRef=\"cdk:exactMass\">2.01410179</scalar>"
                              + "            <scalar dictRef=\"cdk:atomicNumber\">1</scalar>" + "        </isotope>"
                              + "        <isotope id=\"D2\" isotopeNumber=\"2\" elementType=\"D\">"
                              + "            <abundance dictRef=\"cdk:relativeAbundance\">0.015</abundance>"
                              + "            <scalar dictRef=\"cdk:exactMass\">2.01410179</scalar>"
                              + "            <scalar dictRef=\"cdk:atomicNumber\">1</scalar>" + "        </isotope>"
                              + "    </isotopeList>" + "</list>";

            IsotopeReader reader = new IsotopeReader(new MemoryStream(Encoding.UTF8.GetBytes(isotopeData)));

            Assert.IsNotNull(reader);
            var isotopes = reader.ReadIsotopes();

            Assert.IsNotNull(isotopes);
            Assert.AreEqual(3, isotopes.Count);
        }
Example #2
0
        public void TestReadIsotopes()
        {
            IsotopeReader reader = new IsotopeReader(new MemoryStream(Encoding.UTF8.GetBytes("<?xml version=\"1.0\"?><list></list>")));

            Assert.IsNotNull(reader);
            var isotopes = reader.ReadIsotopes();

            Assert.IsNotNull(isotopes);
            Assert.AreEqual(0, isotopes.Count);
        }
Example #3
0
        /// <summary>
        /// Private constructor for the IsotopeFactory object.
        /// </summary>
        /// <exception cref="IOException">A problem with reading the isotopes.xml file</exception>
        private XMLIsotopeFactory()
        {
            Trace.TraceInformation("Creating new IsotopeFactory");

            // ObjIn in = null;
            var errorMessage = $"There was a problem getting NCDK.Config.Data.isotopes.xml as a stream";
            var configFile   = "NCDK.Config.Data.isotopes.xml";

            Debug.WriteLine($"Getting stream for {configFile}");
            using (var reader = new IsotopeReader(ResourceLoader.GetAsStream(configFile)))
            {
                var isotopes = reader.ReadIsotopes();
                foreach (var isotope in isotopes)
                {
                    Add(isotope);
                }
                Debug.WriteLine($"Found #isotopes in file: {isotopes.Count}");
            }
        }
Example #4
0
        //private LoggingTool //logger;

        /// <summary> Private constructor for the IsotopeFactory object.
        ///
        /// </summary>
        /// <exception cref="IOException">            A problem with reading the isotopes.xml
        /// file
        /// </exception>
        /// <exception cref="OptionalDataException">  Unexpected data appeared in the isotope
        /// ObjectInputStream
        /// </exception>
        /// <exception cref="ClassNotFoundException"> A problem instantiating the isotopes
        /// </exception>
        private IsotopeFactory(IChemObjectBuilder builder)
        {
            //logger = new LoggingTool(this);
            //logger.info("Creating new IsotopeFactory");

            System.IO.Stream ins = null;
            // ObjIn in = null;
            System.String errorMessage = "There was a problem getting org.openscience.cdk." + "config.isotopes.xml as a stream";
            try
            {
                System.String configFile = "isotopes.xml";
                //if (debug)
                //logger.debug("Getting stream for ", configFile);
                //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'"
                //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'"
                ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + configFile);
                //this.GetType().getClassLoader().getResourceAsStream(configFile);
            }
            catch (System.Exception exception)
            {
                //logger.error(errorMessage);
                //logger.debug(exception);
                throw new System.IO.IOException(errorMessage);
            }
            if (ins == null)
            {
                //logger.error(errorMessage);
                throw new System.IO.IOException(errorMessage);
            }
            IsotopeReader reader = new IsotopeReader(ins, builder);

            //in = new ObjIn(ins, new Config().aliasID(false));
            //isotopes = (Vector) in.readObject();
            isotopes = reader.readIsotopes();
            //if (debug)
            //logger.debug("Found #isotopes in file: ", isotopes.Count);

            /* for (int f = 0; f < isotopes.size(); f++) {
             * Isotope isotope = (Isotope)isotopes.elementAt(f);
             * } What's this loop for?? */

            majorIsotopes = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
        }
        //private LoggingTool //logger;

        /// <summary> Private constructor for the IsotopeFactory object.
        /// 
        /// </summary>
        /// <exception cref="IOException">            A problem with reading the isotopes.xml
        /// file
        /// </exception>
        /// <exception cref="OptionalDataException">  Unexpected data appeared in the isotope
        /// ObjectInputStream
        /// </exception>
        /// <exception cref="ClassNotFoundException"> A problem instantiating the isotopes
        /// </exception>
        private IsotopeFactory(IChemObjectBuilder builder)
        {
            //logger = new LoggingTool(this);
            //logger.info("Creating new IsotopeFactory");

            System.IO.Stream ins = null;
            // ObjIn in = null;
            System.String errorMessage = "There was a problem getting org.openscience.cdk." + "config.isotopes.xml as a stream";
            try
            {
                System.String configFile = "isotopes.xml";
                //if (debug)
                    //logger.debug("Getting stream for ", configFile);
                //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'"
                //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'"
                ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + configFile);
                    //this.GetType().getClassLoader().getResourceAsStream(configFile);
            }
            catch (System.Exception exception)
            {
                //logger.error(errorMessage);
                //logger.debug(exception);
                throw new System.IO.IOException(errorMessage);
            }
            if (ins == null)
            {
                //logger.error(errorMessage);
                throw new System.IO.IOException(errorMessage);
            }
            IsotopeReader reader = new IsotopeReader(ins, builder);
            //in = new ObjIn(ins, new Config().aliasID(false));
            //isotopes = (Vector) in.readObject();
            isotopes = reader.readIsotopes();
            //if (debug)
                //logger.debug("Found #isotopes in file: ", isotopes.Count);
            /* for (int f = 0; f < isotopes.size(); f++) {
            Isotope isotope = (Isotope)isotopes.elementAt(f);
            } What's this loop for?? */

            majorIsotopes = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
        }
Example #6
0
        public void TestIsotopeReader_InputStream_IChemObjectBuilder()
        {
            IsotopeReader reader = new IsotopeReader(new MemoryStream(System.Array.Empty <byte>()));

            Assert.IsNotNull(reader);
        }