Example #1
0
        public void TestBCUT()
        {
            var       filename = "NCDK.Data.HIN.gravindex.hin";
            IChemFile content;

            using (var reader = new HINReader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            var descriptor      = CreateDescriptor(true);
            var descriptorValue = descriptor.Calculate(ac, 2, 2);

            var retval = descriptorValue.Values;

            Assert.IsNotNull(retval);
            foreach (var v in retval)
            {
                Assert.IsTrue(Math.Abs(0.0 - v) > 0.0000001, "The returned value must be non-zero");
            }

            var names = descriptorValue.Keys;

            foreach (var name in names)
            {
                Assert.IsNotNull(name);
            }

            // Assert.AreEqual(1756.5060703860984,
            // ((Double)retval[0]).Value, 0.00000001);
            // Assert.AreEqual(41.91069159994975,
            // ((Double)retval[1]).Value, 0.00000001);
            // Assert.AreEqual(12.06562671430088,
            // ((Double)retval[2]).Value, 0.00000001);
            // Assert.AreEqual(1976.6432599699767,
            // ((Double)retval[3]).Value, 0.00000001);
            // Assert.AreEqual(44.45945636161082,
            // ((Double)retval[4]).Value, 0.00000001);
            // Assert.AreEqual(12.549972243701887,
            // ((Double)retval[5]).Value, 0.00000001);
            // Assert.AreEqual(4333.097373073368,
            // ((Double)retval[6]).Value, 0.00000001);
            // Assert.AreEqual(65.82626658920714,
            // ((Double)retval[7]).Value, 0.00000001);
            // Assert.AreEqual(16.302948232909483,
            // ((Double)retval[8]).Value, 0.00000001);
        }
Example #2
0
        public void TestBug3141611()
        {
            var filename = "NCDK.Data.MDL.error.sdf";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new MDLV2000Reader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            // test the resulting ChemFile content
            Assert.IsNotNull(chemFile);
            IAtomContainer mol = ChemFileManipulator.GetAllAtomContainers(chemFile).First();

            string[] expectedTypes = { "C.sp3", "C.sp2", "O.sp2", "C.sp3", "C.sp3", "C.sp3", "C.sp3", "P.ate", "O.sp2",
                                       "O.minus" };
            AssertAtomTypes(testedAtomTypes, expectedTypes, mol);
        }
Example #3
0
        public void TestModelBuilder3D_bug_1241421()
        {
            var mb3d     = ModelBuilder3D.GetInstance();
            var filename = "NCDK.Data.MDL.bug1241421.mol";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new MDLV2000Reader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();
            var            containersList = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();
            IAtomContainer ac             = new Silent.AtomContainer(containersList[0]);

            ac = mb3d.Generate3DCoordinates(ac, false);
            CheckAverageBondLength(ac);
        }
Example #4
0
        public void TestFile3()
        {
            var filename = "NCDK.Data.CML.3.cml";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new CMLReader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            // test the resulting ChemFile content
            Assert.IsNotNull(chemFile);
            IAtomContainer mol = ChemFileManipulator.GetAllAtomContainers(chemFile).First();

            string[] expectedTypes = { "C.sp2", "N.sp2", "C.sp2", "N.sp3", "C.sp2", "N.sp2", "O.sp3", "C.sp2", "C.sp2",
                                       "C.sp2" };
            AssertAtomTypes(testedAtomTypes, expectedTypes, mol);
        }
Example #5
0
        public void TestAtomProperties()
        {
            var      filename = "NCDK.Data.CML.custompropertiestest.cml";
            var      ins      = ResourceLoader.GetAsStream(filename);
            var      reader   = new CMLReader(ins);
            ChemFile chemFile = (ChemFile)reader.Read((ChemFile) new ChemFile());

            reader.Close();
            Assert.IsNotNull(chemFile);
            IAtomContainer container = ChemFileManipulator.GetAllAtomContainers(chemFile).First();

            for (int i = 0; i < container.Atoms.Count; i++)
            {
                Assert.AreEqual(2, container.Atoms[i].GetProperties().Count);
            }
        }
Example #6
0
        public void TestCMLTestCase()
        {
            var filename = "NCDK.Data.CML.olaCmlAtomType.cml";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new CMLReader(ins);
            var chemFile = builder.NewChemFile();

            chemFile = (IChemFile)reader.Read(chemFile);
            reader.Close();
            var container = ChemFileManipulator.GetAllAtomContainers(chemFile).First();

            foreach (var atom in container.Atoms)
            {
                Assert.AreEqual(null, atom.ImplicitHydrogenCount);
            }
        }
Example #7
0
        public void TestCranbinSurface()
        {
            var       bldr = CDK.Builder;
            IChemFile chemFile;
            var       path = "NCDK.Data.PDB.1CRN.pdb";

            using (var pdbr = new PDBReader(ResourceLoader.GetAsStream(path)))
            {
                chemFile = pdbr.Read(bldr.NewChemFile());
                var mol     = ChemFileManipulator.GetAllAtomContainers(chemFile).ElementAt(0);
                var surface = new NumericalSurface(mol);
                var map     = surface.GetAtomSurfaceMap();
                Assert.AreEqual(222, map.Count);
                Assert.AreEqual(327, mol.Atoms.Count);
            }
        }
Example #8
0
        public void TestMultiMolButSingle()
        {
            var filename = "NCDK.Data.Mol2.fromWebsite.mol2";

            Trace.TraceInformation("Testing: ", filename);
            IChemFile chemFile;

            using (var reader = new Mol2Reader(ResourceLoader.GetAsStream(filename)))
            {
                chemFile = reader.Read(builder.NewChemFile());
            }
            var mols = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();

            Assert.AreEqual(1, mols.Count);
            Assert.AreEqual(12, mols[0].Atoms.Count);
        }
Example #9
0
        public void Testbug2917084()
        {
            string filename1 = "NCDK.Data.MDL.boronBuckyBall.mol";

            Trace.TraceInformation("Testing: " + filename1);
            var ins1     = ResourceLoader.GetAsStream(filename1);
            var reader   = new MDLV2000Reader(ins1, ChemObjectReaderMode.Strict);
            var chemFile = reader.Read(builder.NewChemFile());

            Assert.IsNotNull(chemFile);
            var mol = ChemFileManipulator.GetAllAtomContainers(chemFile).First();

            Fingerprinter fingerprinter = new Fingerprinter(1024, 8);

            Assert.IsNotNull(fingerprinter.GetBitFingerprint(mol));
        }
Example #10
0
        public void TestBug1542467()
        {
            var filename = "NCDK.Data.MDL.Strychnine_nichtOK.mol";

            Trace.TraceInformation("Testing: " + filename);
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new MDLReader(ins, ChemObjectReaderMode.Strict);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();
            Assert.IsNotNull(chemFile);
            var containersList = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();

            Assert.AreEqual(1, containersList.Count);
            Assert.IsTrue((containersList[0]).Atoms.Count > 0);
            Assert.IsTrue((containersList[0]).Bonds.Count > 0);
        }
Example #11
0
        public void TestNMRReading()
        {
            IAtomContainer atomContainer = null;
            //bool foundOneShieldingEntry = false;
            //Double shielding = null;
            object           obj = null;
            int              shieldingCounter = 0;
            var              filename         = "NCDK.Data.Gaussian.g98ReaderNMRTest.log";
            var              ins         = ResourceLoader.GetAsStream(filename);
            var              inputReader = new StreamReader(ins);
            Gaussian98Reader g98Reader   = new Gaussian98Reader(inputReader);
            ChemFile         chemFile    = (ChemFile)g98Reader.Read(new ChemFile());

            g98Reader.Close();
            var atomContainersList = ChemFileManipulator.GetAllAtomContainers(chemFile);

            Assert.IsNotNull(atomContainersList);
            Assert.IsTrue(atomContainersList.Count() == 54);
            //Debug.WriteLine("Found " + atomContainers.Length + " atomContainers");
            int counter = 0;

            foreach (var ac in atomContainersList)
            {
                shieldingCounter = 0;
                atomContainer    = ac;
                for (int g = 0; g < atomContainer.Atoms.Count; g++)
                {
                    obj = atomContainer.Atoms[g].GetProperty <double?>(CDKPropertyName.IsotropicShielding);
                    if (obj != null)
                    {
                        //shielding = (double)object;
                        shieldingCounter++;
                    }
                }
                if (counter < 53)
                {
                    Assert.IsTrue(shieldingCounter == 0);
                }
                else
                {
                    Assert.IsTrue(shieldingCounter == ac.Atoms.Count);
                }
                //Debug.WriteLine("AtomContainer " + (f + 1) + " has " + atomContainers[f].Atoms.Count + " atoms and " + shieldingCounter + " shielding entries");
                counter++;
            }
        }
Example #12
0
        public void TestModelBuilder3D_232()
        {
            ModelBuilder3D mb3d     = ModelBuilder3D.GetInstance();
            var            filename = "NCDK.Data.MDL.allmol232.mol";
            var            ins      = ResourceLoader.GetAsStream(filename);
            var            reader   = new MDLV2000Reader(ins);
            var            chemFile = reader.Read(builder.NewChemFile());

            reader.Close();
            var            containersList = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();
            IAtomContainer ac             = new Silent.AtomContainer(containersList[0]);

            AddExplicitHydrogens(ac);
            ac = mb3d.Generate3DCoordinates(ac, false);
            Assert.IsNotNull(ac.Atoms[0].Point3D);
            CheckAverageBondLength(ac);
        }
Example #13
0
        public void TestMDE1()
        {
            var       filename = "NCDK.Data.MDL.mdeotest.sdf";
            IChemFile content;

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            var result = CreateDescriptor().Calculate(ac);

            Assert.AreEqual(0.0000, result.MDEO11, 0.0001);
            Assert.AreEqual(1.1547, result.MDEO12, 0.0001);
            Assert.AreEqual(2.9416, result.MDEO22, 0.0001);
        }
Example #14
0
        public void TestLOBDescriptor2()
        {
            var       filename = "NCDK.Data.MDL.lobtest2.sdf";
            IChemFile content;

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(ac);

            var result = CreateDescriptor().Calculate(ac);

            Assert.IsNotNull(result);
        }
Example #15
0
        public void TestStereoReadZeroDefault()
        {
            var filename = "NCDK.Data.MDL.prev2000.sd";

            Trace.TraceInformation("Testing: " + filename);
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new MDLReader(ins, ChemObjectReaderMode.Strict);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();
            Assert.IsNotNull(chemFile);
            var containersList = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();

            Assert.AreEqual(2, containersList.Count);
            var container = containersList[0];

            Assert.AreEqual(BondStereo.None, container.Bonds[0].Stereo);
        }
Example #16
0
        public void TestEhccentricConnectivityIndex()
        {
            var       filename = "NCDK.Data.HIN.gravindex.hin";
            IChemFile content;

            using (var reader = new HINReader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            AddImplicitHydrogens(ac);

            var retval = CreateDescriptor().Calculate(ac).Value;

            Assert.AreEqual(254, retval, 0);
        }
Example #17
0
        public void TestLOBDescriptorNButane()
        {
            var       filename = "NCDK.Data.MDL.lobtest.sdf";
            IChemFile content;

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[3];

            BODRIsotopeFactory.Instance.ConfigureAtoms(ac);

            var result = CreateDescriptor().Calculate(ac);

            Assert.AreEqual(2.0880171, result.Values[0], 0.000001);
            Assert.AreEqual(2.0880171, result.Values[1], 0.000001);
        }
Example #18
0
        public void TestCPSA()
        {
            var       filename = "NCDK.Data.HIN.benzene.hin";
            IChemFile content;

            using (var reader = new HINReader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            var retval = CreateDescriptor().Calculate(ac).Values;

            Assert.AreEqual(0, retval[28], 0.0001);
            Assert.AreEqual(1, retval[27], 0.0001);
            Assert.AreEqual(0, retval[26], 0.0001);
            Assert.AreEqual(356.8849, retval[25], 0.0001);
        }
Example #19
0
        public void TestReadGzWithGzipDetection()
        {
            var filename = "NCDK.Data.XYZ.bf3.xyz.gz";
            var input    = ResourceLoader.GetAsStream(filename);
            // ok, if format ok, try instantiating a reader
            ISimpleChemObjectReader reader = factory.CreateReader(input);

            Assert.IsNotNull(reader);
            Assert.AreEqual(((IChemFormat)XYZFormat.Instance).ReaderClassName, reader.GetType().FullName);
            // now try reading something from it
            var chemFile = reader.Read(builder.NewChemFile());
            var molecule = builder.NewAtomContainer();

            foreach (var container in ChemFileManipulator.GetAllAtomContainers(chemFile))
            {
                molecule.Add(container);
            }
            Assert.IsNotNull(molecule);
            Assert.AreEqual(4, molecule.Atoms.Count);
        }
Example #20
0
        public void TestUnChargedMolecule()
        {
            var       filename = "NCDK.Data.MDL.cpsa-uncharged.sdf";
            IChemFile content;

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            var retval = CreateDescriptor().Calculate(ac).Values;
            int ndesc  = retval.Count;

            for (int i = 0; i < ndesc; i++)
            {
                Assert.IsTrue(retval[i] != double.NaN);
            }
        }
Example #21
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();
            }
        }
Example #22
0
        public void TestFile3()
        {
            var filename = "NCDK.Data.CML.3.cml";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new CMLReader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();

            // test the resulting ChemFile content
            Assert.IsNotNull(chemFile);
            var mol = ChemFileManipulator.GetAllAtomContainers(chemFile).First();

            for (int i = 0; i <= 3; i++)
            {
                Assert.IsFalse(mol.Bonds[i].IsAromatic, "Bond " + (i + 1) + " is not aromatic in the file");
            }
            for (int i = 4; i <= 9; i++)
            {
                Assert.IsTrue(mol.Bonds[i].IsAromatic, "Bond " + (i + 1) + " is aromatic in the file");
            }
        }
        public void TestMomentOfInertia2()
        {
            var       filename = "NCDK.Data.HIN.momi2.hin";
            IChemFile content;

            using (var reader = new HINReader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            var retval = CreateDescriptor().Calculate(ac).Values;

            Assert.AreEqual(10068.419360, retval[0], 0.00001);
            Assert.AreEqual(9731.078356, retval[1], 0.00001);
            Assert.AreEqual(773.612799, retval[2], 0.00001);
            Assert.AreEqual(1.034666, retval[3], 0.00001);
            Assert.AreEqual(13.014804, retval[4], 0.00001);
            Assert.AreEqual(12.578745, retval[5], 0.00001);
            Assert.AreEqual(8.2966226, retval[6], 0.00001);
        }
        public void TestMomentOfInertia1()
        {
            var       filename = "NCDK.Data.HIN.gravindex.hin";
            IChemFile content;

            using (var reader = new HINReader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            var retval = CreateDescriptor().Calculate(ac).Values;

            Assert.AreEqual(1820.692519, retval[0], 0.00001);
            Assert.AreEqual(1274.532522, retval[1], 0.00001);
            Assert.AreEqual(979.210423, retval[2], 0.00001);
            Assert.AreEqual(1.428517, retval[3], 0.00001);
            Assert.AreEqual(1.859347, retval[4], 0.00001);
            Assert.AreEqual(1.301592, retval[5], 0.00001);
            Assert.AreEqual(5.411195, retval[6], 0.00001);
        }
Example #25
0
        public void TestPetitjeanShapeIndexDescriptor()
        {
            // first molecule is nbutane, second is naphthalene
            var       filename = "NCDK.Data.MDL.petitejean.sdf";
            IChemFile content;

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            var result = CreateDescriptor().Calculate(ac);

            Assert.AreEqual(0.5, result.TopologicalShapeIndex, 0.00001);
            Assert.AreEqual(0.606477, result.GeometricShapeIndex, 0.000001);

            ac     = cList[1];
            result = CreateDescriptor().Calculate(ac);
            Assert.AreEqual(0.666666, result.TopologicalShapeIndex, 0.000001);
            Assert.AreEqual(0.845452, result.GeometricShapeIndex, 0.000001);
        }
Example #26
0
        public void TestUndefinedValues()
        {
            var       filename = "NCDK.Data.MDL.burden_undefined.sdf";
            IChemFile content;

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var ac    = cList[0];

            Assert.IsNotNull(ac);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(ac);
            AddExplicitHydrogens(ac);
            Aromaticity.CDKLegacy.Apply(ac);

            var e = CreateDescriptor().Calculate(ac).Exception;

            Assert.IsNotNull(e);
            // make sure exception was a NPE etc.
            Assert.AreEqual("Could not calculate partial charges: Partial charge not-supported for element: 'As'.", e.Message);
        }
Example #27
0
        public void TestReadAromaticRingsKeyword()
        {
            var filename = "NCDK.Data.HIN.arorings.hin";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new HINReader(ins);
            var content  = reader.Read(builder.NewChemFile());

            reader.Close();
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();

            Assert.AreEqual(1, cList.Count);

            var mol = cList[0];

            Assert.IsTrue(mol.Atoms[0].IsAromatic);
            Assert.IsTrue(mol.Atoms[2].IsAromatic);
            Assert.IsTrue(mol.Atoms[3].IsAromatic);
            Assert.IsTrue(mol.Atoms[5].IsAromatic);
            Assert.IsTrue(mol.Atoms[4].IsAromatic);
            Assert.IsTrue(mol.Atoms[1].IsAromatic);

            Assert.IsTrue(mol.Atoms[7].IsAromatic);
            Assert.IsTrue(mol.Atoms[12].IsAromatic);
            Assert.IsTrue(mol.Atoms[11].IsAromatic);
            Assert.IsTrue(mol.Atoms[10].IsAromatic);
            Assert.IsTrue(mol.Atoms[9].IsAromatic);
            Assert.IsTrue(mol.Atoms[8].IsAromatic);

            // make sure that only the phenyl C's were marked as aromatic
            foreach (var atom in mol.Atoms)
            {
                if (atom.Symbol.Equals("C"))
                {
                    Assert.IsTrue(atom.IsAromatic, $"{atom.Symbol} (index {mol.Atoms.IndexOf(atom)}) was wrongly marked as aromatic");
                }
            }
        }
Example #28
0
 /// <summary>
 /// Loads all existing templates into memory. To add templates to be used in
 /// SDG, place a drawing with the new template in org/openscience/cdk/layout/templates and add the
 /// template filename to org/openscience/cdk/layout/templates/template.list
 /// </summary>
 public void LoadTemplates()
 {
     try
     {
         using (var reader = new StreamReader(ResourceLoader.GetAsStream("NCDK.Layout.Templates.templates.list")))
         {
             string line;
             while ((line = reader.ReadLine()) != null)
             {
                 line = "NCDK.Layout.Templates." + line;
                 Debug.WriteLine($"Attempting to read template {line}");
                 try
                 {
                     CMLReader structureReader = new CMLReader(ResourceLoader.GetAsStream(line));
                     IChemFile file            = structureReader.Read(builder.NewChemFile());
                     var       files           = ChemFileManipulator.GetAllAtomContainers(file);
                     foreach (var f in files)
                     {
                         AddMolecule(f);
                     }
                     Debug.WriteLine($"Successfully read template {line}");
                 }
                 catch (CDKException e)
                 {
                     Trace.TraceWarning($"Could not read template {line}, reason: {e.Message}");
                     Debug.WriteLine(e.Message);
                 }
             }
         }
     }
     catch (IOException e)
     {
         Trace.TraceWarning($"Could not read (all of the) templates, reason: {e.Message}");
         Debug.WriteLine(e.Message);
     }
 }
        public void TestUITTimeoutFix()
        {
            // Load molecules
            var filename  = "NCDK.Data.MDL.UITTimeout.sdf";
            var ins       = ResourceLoader.GetAsStream(filename);
            var reader    = new MDLV2000Reader(ins);
            var content   = reader.Read(builder.NewChemFile());
            var cList     = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var molecules = new IAtomContainer[2];

            for (int j = 0; j < 2; j++)
            {
                var aAtomContainer = cList[j];
                var tmpMatcher     = CDK.AtomTypeMatcher;
                var tmpAdder       = CDK.HydrogenAdder;
                for (int i = 0; i < aAtomContainer.Atoms.Count; i++)
                {
                    var tmpAtom = aAtomContainer.Atoms[i];
                    var tmpType = tmpMatcher.FindMatchingAtomType(aAtomContainer, tmpAtom);
                    AtomTypeManipulator.Configure(tmpAtom, tmpType);
                    tmpAdder.AddImplicitHydrogens(aAtomContainer, tmpAtom);
                }
                AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(aAtomContainer);
                molecules[j] = aAtomContainer;
            }
            var query = QueryAtomContainerCreator.CreateAnyAtomForPseudoAtomQueryContainer(molecules[1]);
            // test
            var starttime = System.DateTime.Now.Ticks;

            uiTester.Timeout = 200;
            uiTester.GetSubgraphAtomsMaps(molecules[0], query);
            var duration = System.DateTime.Now.Ticks - starttime;

            // The search must last much longer then two seconds if the timeout not works
            Assert.IsTrue(duration < 2000 * 10000);  // 1 msec = 10000 ticks
        }
Example #30
0
        public void TestReading()
        {
            var filename = "NCDK.Data.ASN.PubChem.cid1.asn";

            Trace.TraceInformation("Testing: " + filename);
            var ins = ResourceLoader.GetAsStream(filename);
            PCCompoundASNReader reader = new PCCompoundASNReader(ins);
            IChemFile           cFile  = (IChemFile)reader.Read(builder.NewChemFile());

            reader.Close();
            var containers = ChemFileManipulator.GetAllAtomContainers(cFile).ToReadOnlyList();

            Assert.AreEqual(1, containers.Count);
            Assert.IsTrue(containers[0] is IAtomContainer);
            IAtomContainer molecule = containers[0];

            Assert.IsNotNull(molecule);

            // check atom stuff
            Assert.AreEqual(31, molecule.Atoms.Count);
            Assert.IsNotNull(molecule.Atoms[3]);
            Assert.AreEqual("O", molecule.Atoms[3].Symbol);
            Assert.IsNotNull(molecule.Atoms[4]);
            Assert.AreEqual("N", molecule.Atoms[4].Symbol);

            // check bond stuff
            Assert.AreEqual(30, molecule.Bonds.Count);
            Assert.IsNotNull(molecule.Bonds[3]);
            Assert.AreEqual(molecule.Atoms[2], molecule.Bonds[3].Begin);
            Assert.AreEqual(molecule.Atoms[11], molecule.Bonds[3].End);

            // some extracted props
            Assert.AreEqual("InChI=1/C9H17NO4/c1-7(11)14-8(5-9(12)13)6-10(2,3)4/h8H,5-6H2,1-4H3",
                            molecule.GetProperty <string>(CDKPropertyName.InChI));
            Assert.AreEqual("CC(=O)OC(CC(=O)[O-])C[N+](C)(C)C", molecule.GetProperty <string>(CDKPropertyName.SMILES));
        }