Exemplo n.º 1
0
        public void TestBug1649526()
        {
            //Read the original
            var filename = "NCDK.Data.MDL.bug-1649526.mol";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new MDLReader(ins);
            var mol      = reader.Read(builder.NewAtomContainer());

            reader.Close();
            //Write it as cml
            var writer    = new StringWriter();
            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(mol);
            cmlWriter.Close();
            //Read this again
            var cmlreader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(writer.ToString())));
            var file      = (IChemFile)cmlreader.Read(builder.NewChemFile());

            cmlreader.Close();
            //And finally write as mol
            var writermdl = new StringWriter();
            var mdlWriter = new MDLV2000Writer(writermdl);

            mdlWriter.Write(file);
            mdlWriter.Close();
            var output = writermdl.ToString().Replace("\r\n", "\n");

            //if there would be 3 instances (as in the bug), the only instance wouldnt't be right at the end
            Assert.AreEqual(2994, output.IndexOf("M  END"));
            //there would need some $$$$ to be in
            Assert.AreEqual(-1, output.IndexOf("$$$$"));
            //check atom/bond count
            Assert.AreEqual(25, output.IndexOf(" 31 33  0  0  0  0"));
        }
Exemplo n.º 2
0
        public void TestBug1275()
        {
            var ins    = ResourceLoader.GetAsStream("NCDK.Data.CML.(1R)-1-aminoethan-1-ol-malformedDictRef.cml");
            var reader = new CMLReader(ins);

            try
            {
                IChemFile cfile = reader.Read(ChemObjectBuilder.Instance.NewChemFile());

                Assert.IsNotNull(cfile, "ChemFile was Null");

                var containers = ChemFileManipulator.GetAllAtomContainers(cfile);

                Assert.AreEqual(1, containers.Count(), "Expected a single atom container");

                IAtomContainer container = containers.First();

                Assert.IsNotNull(container, "Null atom container read");

                // we check here that the malformed dictRef doesn't throw an exception
                Assert.AreEqual(BondStereo.None, container.Bonds[0].Stereo, "expected non-stereo bond");
                Assert.AreEqual(BondStereo.Up, container.Bonds[1].Stereo, "expected Wedge (Up) Bond");
                Assert.AreEqual(BondStereo.None, container.Bonds[2].Stereo, "expected non-stereo bond");
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 3
0
        public void TestBug1248()
        {
            var ins    = ResourceLoader.GetAsStream("NCDK.Data.CML.(1R)-1-aminoethan-1-ol.cml");
            var reader = new CMLReader(ins);

            try
            {
                IChemFile cfile = reader.Read(ChemObjectBuilder.Instance.NewChemFile());

                Assert.IsNotNull(cfile, "ChemFile was Null");

                var containers = ChemFileManipulator.GetAllAtomContainers(cfile);

                Assert.AreEqual(1, containers.Count(), "Expected a single atom container");

                IAtomContainer container = containers.First();

                Assert.IsNotNull(container, "Null atom container read");

                IBond bond = container.Bonds[2];

                Assert.IsNotNull(bond, "Null bond");

                Assert.AreEqual(BondStereo.Up, bond.Stereo, "Expected Wedge (Up) Bond");
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 4
0
        public void TestBug1274()
        {
            var ins    = ResourceLoader.GetAsStream("NCDK.Data.CML.(1R)-1-aminoethan-1-ol-multipleBondStereo.cml");
            var reader = new CMLReader(ins);

            try
            {
                IChemFile cfile = reader.Read(ChemObjectBuilder.Instance.NewChemFile());

                Assert.IsNotNull(cfile, "ChemFile was Null");

                var containers = ChemFileManipulator.GetAllAtomContainers(cfile);

                Assert.AreEqual(1, containers.Count(), "Expected a single atom container");

                IAtomContainer container = containers.First();

                Assert.IsNotNull(container, "Null atom container read");

                // we check here that the charContent is not used and also that more then
                // one stereo isn't set
                Assert.AreEqual(BondStereo.None, container.Bonds[0].Stereo, "expected non-stereo bond");
                Assert.AreEqual(BondStereo.Down, container.Bonds[1].Stereo, "expected Hatch (Down) Bond");
                Assert.AreEqual(BondStereo.None, container.Bonds[2].Stereo, "expected non-stereo bond");
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 5
0
        public void TestBug1245()
        {
            var ins    = ResourceLoader.GetAsStream("NCDK.Data.CML.(1R)-1-aminoethan-1-ol.cml");
            var reader = new CMLReader(ins);

            try
            {
                IChemFile cfile = reader.Read(ChemObjectBuilder.Instance.NewChemFile());

                Assert.IsNotNull(cfile, "ChemFile was Null");

                var containers = ChemFileManipulator.GetAllAtomContainers(cfile);

                Assert.AreEqual(1, containers.Count(), "Expected a single atom container");

                IAtomContainer container = containers.First();

                Assert.IsNotNull(container, "Null atom container read");

                foreach (var atom in container.Atoms)
                {
                    Assert.AreEqual(
                        PeriodicTable.GetAtomicNumber(atom.Symbol),
                        atom.AtomicNumber,
                        "Incorrect atomic number");
                }
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 6
0
        public void TestSFBug1085912_1()
        {
            string cmlContent = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
                                + "<molecule convention=\"PDB\" dictRef=\"pdb:model\" xmlns=\"http://www.xml-cml.org/schema\">"
                                + "  <molecule dictRef=\"pdb:sequence\" id=\"ALAA116\">"
                                + "    <atomArray>"
                                + "      <atom id=\"a9794931\" elementType=\"N\" x3=\"-10.311\" y3=\"2.77\" z3=\"-9.837\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a5369354\" elementType=\"C\" x3=\"-9.75\" y3=\"4.026\" z3=\"-9.35\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a14877152\" elementType=\"C\" x3=\"-10.818\" y3=\"5.095\" z3=\"-9.151\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a26221736\" elementType=\"O\" x3=\"-11.558\" y3=\"5.433\" z3=\"-10.074\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a4811470\" elementType=\"C\" x3=\"-8.678\" y3=\"4.536\" z3=\"-10.304\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a211489\" elementType=\"H\" x3=\"-10.574\" y3=\"2.695\" z3=\"-10.778\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a31287617\" elementType=\"H\" x3=\"-9.279\" y3=\"3.829\" z3=\"-8.398\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a19487109\" elementType=\"H\" x3=\"-8.523\" y3=\"3.813\" z3=\"-11.09\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a28589522\" elementType=\"H\" x3=\"-8.994\" y3=\"5.477\" z3=\"-10.737\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>"
                                + "      <atom id=\"a4638116\" elementType=\"H\" x3=\"-7.754\" y3=\"4.682\" z3=\"-9.763\" formalCharge=\"0\">"
                                + "        <scalar dictRef=\"cdk:partialCharge\" dataType=\"xsd:double\">0.0</scalar>"
                                + "      </atom>" + "    </atomArray>" + "  </molecule>" + "</molecule>";
            CMLReader reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(cmlContent)));

            try
            {
                IChemFile cfile = reader.Read(ChemObjectBuilder.Instance.NewChemFile());
                Assert.IsNotNull(cfile, "ChemFile was Null");
                var containers = ChemFileManipulator.GetAllAtomContainers(cfile);
                Assert.AreEqual(1, containers.Count(), "Expected a single atom container");
                IAtomContainer container = containers.First();
                Assert.IsNotNull(container, "Null atom container read");

                // OK, now test that the residue identifier is properly read
                Assert.AreEqual("ALAA116", container.Id);
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 7
0
        public void TestMixedNamespaces()
        {
            var ins    = ResourceLoader.GetAsStream(this.GetType(), "US06358966-20020319-C00001-enr.cml");
            var reader = new CMLReader(ins);

            try
            {
                IChemFile cfile = reader.Read(ChemObjectBuilder.Instance.NewChemFile());
                Assert.AreEqual(34, ChemFileManipulator.GetAtomCount(cfile));
                Assert.AreEqual(39, ChemFileManipulator.GetBondCount(cfile));
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 8
0
        public void TestWedgeBondParsing()
        {
            var ins    = ResourceLoader.GetAsStream("NCDK.Data.CML.AZD5423.xml");
            var reader = new CMLReader(ins);

            try
            {
                IChemFile cfile = reader.Read(ChemObjectBuilder.Instance.NewChemFile());
                Assert.IsNotNull(cfile, "ChemFile was Null");
                var containers = ChemFileManipulator.GetAllAtomContainers(cfile);
                Assert.AreEqual(1, containers.Count(), "Expected a single atom container");
                IAtomContainer container = containers.First();
                Assert.IsNotNull(container, "Null atom container read");

                // we check here that the malformed dictRef doesn't throw an exception
                for (int i = 0; i < 19; i++)
                {
                    Assert.AreEqual(
                        BondStereo.None, container.Bonds[i].Stereo,
                        "found an unexpected wedge bond for " + i + ": " + container.Bonds[i].Stereo);
                }
                Assert.AreEqual(BondStereo.Down, container.Bonds[19].Stereo, "expected a wedge bond");
                for (int i = 20; i < 30; i++)
                {
                    Assert.AreEqual(
                        BondStereo.None, container.Bonds[i].Stereo,
                        "found an unexpected wedge bond for " + i + ": " + container.Bonds[i].Stereo);
                }
                Assert.AreEqual(BondStereo.Up, container.Bonds[30].Stereo, "expected a wedge bond");
                for (int i = 31; i <= 37; i++)
                {
                    Assert.AreEqual(
                        BondStereo.None, container.Bonds[i].Stereo,
                        "found an unexpected wedge bond for " + i + ": " + container.Bonds[i].Stereo);
                }
            }
            finally
            {
                reader.Close();
            }
        }