Exemple #1
0
        public void TestSalt()
        {
            var filename = "NCDK.Data.CML.COONa.cml";

            Trace.TraceInformation("Testing: " + filename);
            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);
            Assert.AreEqual(1, chemFile.Count);
            //Debug.WriteLine($"NO sequences: {chemFile.Count}");
            var seq = chemFile[0];

            Assert.IsNotNull(seq);
            Assert.AreEqual(1, seq.Count);
            //Debug.WriteLine($"NO models: {seq.Count}");
            var model = seq[0];

            Assert.IsNotNull(model);
            Assert.AreEqual(1, model.MoleculeSet.Count);

            // test the molecule
            IAtomContainer mol = model.MoleculeSet[0];

            Assert.IsNotNull(mol);
            Assert.AreEqual(4, mol.Atoms.Count);
            Assert.IsTrue(GeometryUtil.Has3DCoordinates(mol));
        }
Exemple #2
0
        public void TestAceticAcid()
        {
            var filename = "NCDK.Data.PMP.aceticacid.pmp";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new PMPReader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();

            Assert.IsNotNull(chemFile);
            Assert.AreEqual(1, chemFile.Count);
            var seq = chemFile[0];

            Assert.IsNotNull(seq);
            Assert.AreEqual(1, seq.Count);
            var model = seq[0];

            Assert.IsNotNull(model);

            var crystal = model.Crystal;

            Assert.IsNotNull(crystal);
            Assert.AreEqual(32, crystal.Atoms.Count);
            Assert.AreEqual(28, crystal.Bonds.Count);

            Assert.AreEqual("O", crystal.Atoms[6].Symbol);
            Assert.AreEqual(1.4921997, crystal.Atoms[6].Point3D.Value.X, 0.00001);
            Assert.AreEqual("O", crystal.Atoms[7].Symbol);
            Assert.AreEqual(1.4922556, crystal.Atoms[7].Point3D.Value.X, 0.00001);
        }
Exemple #3
0
        public void TestGuanine()
        {
            var filename = "NCDK.Data.InChI.guanine.inchi";

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

            reader.Close();

            Assert.IsNotNull(chemFile);
            Assert.AreEqual(1, chemFile.Count);
            var seq = chemFile[0];

            Assert.IsNotNull(seq);
            Assert.AreEqual(1, seq.Count);
            var model = seq[0];

            Assert.IsNotNull(model);
            var moleculeSet = model.MoleculeSet;

            Assert.IsNotNull(moleculeSet);
            var molecule = moleculeSet[0];

            Assert.IsNotNull(molecule);

            Assert.AreEqual(11, molecule.Atoms.Count);
            Assert.AreEqual(12, molecule.Bonds.Count);
        }
Exemple #4
0
 public void SetUp()
 {
     molecule1  = builder.NewAtomContainer();
     atomInMol1 = builder.NewAtom("Cl");
     molecule1.Atoms.Add(atomInMol1);
     molecule1.Atoms.Add(builder.NewAtom("Cl"));
     bondInMol1 = builder.NewBond(atomInMol1, molecule1.Atoms[1]);
     molecule1.Bonds.Add(bondInMol1);
     molecule2  = builder.NewAtomContainer();
     atomInMol2 = builder.NewAtom("O");
     atomInMol2.ImplicitHydrogenCount = 2;
     molecule2.Atoms.Add(atomInMol2);
     moleculeSet = builder.NewChemObjectSet <IAtomContainer>();
     moleculeSet.Add(molecule1);
     moleculeSet.Add(molecule2);
     reaction = builder.NewReaction();
     reaction.Reactants.Add(molecule1);
     reaction.Products.Add(molecule2);
     reactionSet = builder.NewReactionSet();
     reactionSet.Add(reaction);
     chemModel             = builder.NewChemModel();
     chemModel.MoleculeSet = moleculeSet;
     chemModel.ReactionSet = reactionSet;
     chemSequence1         = builder.NewChemSequence();
     chemSequence1.Add(chemModel);
     chemSequence2 = builder.NewChemSequence();
     chemFile      = builder.NewChemFile();
     chemFile.Add(chemSequence1);
     chemFile.Add(chemSequence2);
 }
Exemple #5
0
        public void TestCuran()
        {
            var filename = "NCDK.Data.CML.curan.xml";

            Trace.TraceInformation("Testing: " + filename);
            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);
            Assert.AreEqual(chemFile.Count, 1);
            var seq = chemFile[0];

            Assert.IsNotNull(seq);
            Assert.AreEqual(seq.Count, 1);
            var model = seq[0];

            Assert.IsNotNull(model);
            Assert.AreEqual(model.MoleculeSet.Count, 1);

            // test the molecule
            IAtomContainer mol = model.MoleculeSet[0];

            Assert.IsNotNull(mol);
            Assert.AreEqual(mol.Atoms.Count, 24);
            Assert.AreEqual(mol.Bonds.Count, 28);
            Assert.IsFalse(GeometryUtil.Has3DCoordinates(mol));
            Assert.IsTrue(GeometryUtil.Has2DCoordinates(mol));
        }
Exemple #6
0
        /// <summary>
        /// Convert a Molecule to CML and back to a Molecule again.
        /// Given that CML reading is working, the problem is with the CMLWriter.
        /// </summary>
        /// <param name="convertor"></param>
        /// <param name="mol"></param>
        /// <returns></returns>
        /// <seealso cref="CMLFragmentsTest"/>
        public static IAtomContainer RoundTripMolecule(Convertor convertor, IAtomContainer mol)
        {
            string cmlString = "<!-- failed -->";
            var    cmlDOM    = convertor.CDKAtomContainerToCMLMolecule(mol);

            cmlString = cmlDOM.ToString();

            Debug.WriteLine("CML string: ", cmlString);
            IChemFile file;

            using (var reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(cmlString))))
            {
                file = (IChemFile)reader.Read(builder.NewChemFile());
            }
            Assert.IsNotNull(file);
            Assert.AreEqual(1, file.Count);
            IChemSequence sequence = file[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(1, sequence.Count);
            IChemModel chemModel = sequence[0];

            Assert.IsNotNull(chemModel);
            var moleculeSet = chemModel.MoleculeSet;

            Assert.IsNotNull(moleculeSet);
            Assert.AreEqual(1, moleculeSet.Count);
            var roundTrippedMol = moleculeSet[0];

            Assert.IsNotNull(roundTrippedMol);

            return(roundTrippedMol);
        }
Exemple #7
0
        public void TestIsConnectedFromHINFile()
        {
            var            filename = "NCDK.Data.HIN.connectivity1.hin";
            var            ins      = ResourceLoader.GetAsStream(filename);
            var            reader   = new HINReader(ins);
            var            content  = reader.Read(builder.NewChemFile());
            var            cList    = ChemFileManipulator.GetAllAtomContainers(content);
            IAtomContainer ac       = cList.First();

            Assert.IsTrue(ConnectivityChecker.IsConnected(ac), "Molecule appears not to be connected");
        }
        public void TestSFBug1085912_1()
        {
            string filename_pdb = "NCDK.Data.PDB.1CKV.pdb";
            var    ins1         = ResourceLoader.GetAsStream(this.GetType(), filename_pdb);

            ISimpleChemObjectReader reader = new PDBReader(ins1);
            IChemFile chemFile1            = (IChemFile)reader.Read(builder.NewChemFile());

            reader.Close();
            IChemSequence  seq1           = chemFile1[0];
            IChemModel     model1         = seq1[0];
            IAtomContainer container      = model1.MoleculeSet[0];
            IBioPolymer    polymer1       = (IBioPolymer)container;
            int            countchemFile1 = chemFile1.Count;
            int            countmodel1    = model1.MoleculeSet.Count;
            int            countpolymer1  = polymer1.Atoms.Count;

            StringWriter writer    = new StringWriter();
            CMLWriter    cmlWriter = new CMLWriter(writer);

            cmlWriter.RegisterCustomizer(new PDBAtomCustomizer());
            cmlWriter.Write(polymer1);
            cmlWriter.Close();
            string cmlContent1 = writer.ToString();

            CMLReader reader2  = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(cmlContent1)));
            var       chemFil2 = reader2.Read(builder.NewChemFile());

            reader2.Close();
            IChemSequence seq2     = chemFil2[0];
            IChemModel    model2   = seq2[0];
            var           polymer2 = (IPDBPolymer)model2.MoleculeSet[0];

            int countchemFile2 = chemFil2.Count;
            int countmodel2    = model2.MoleculeSet.Count;
            int countpolymer2  = polymer2.Atoms.Count;

            Assert.AreEqual(countchemFile1, countchemFile2);
            Assert.AreEqual(countmodel1, countmodel2);
            Assert.AreEqual(countpolymer1, countpolymer2);

            writer    = new StringWriter();
            cmlWriter = new CMLWriter(writer);
            cmlWriter.RegisterCustomizer(new PDBAtomCustomizer());
            cmlWriter.Write(polymer2);
            cmlWriter.Close();
            string cmlContent2 = writer.ToString();

            string conte1 = cmlContent1.Substring(0, 1000);
            string conte2 = cmlContent2.Substring(0, 1000);

            Assert.AreEqual(conte1, conte2);
        }
Exemple #9
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);
        }
Exemple #10
0
        public void TestNewChemFile()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IChemFile          file    = builder.NewChemFile();

            Assert.IsNotNull(file);
        }
        public void TestEthene()
        {
            var filename = "NCDK.Data.Ghemical.ethene.mm1gp";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new GhemicalMMReader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();

            Assert.IsNotNull(chemFile);
            Assert.AreEqual(1, chemFile.Count);
            var seq = chemFile[0];

            Assert.IsNotNull(seq);
            Assert.AreEqual(1, seq.Count);
            var model = seq[0];

            Assert.IsNotNull(model);

            var som = model.MoleculeSet;

            Assert.IsNotNull(som);
            Assert.AreEqual(1, som.Count);
            var m = som[0];

            Assert.IsNotNull(m);
            Assert.AreEqual(6, m.Atoms.Count);
            Assert.AreEqual(5, m.Bonds.Count);
        }
Exemple #12
0
        public void TestReading()
        {
            var filename = "NCDK.Data.VASP.LiMoS2_optimisation_ISIF3.vasp";

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

            Assert.IsNotNull(chemFile);
            var sequence = chemFile[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(6, sequence.Count);
            var model = sequence[0];

            Assert.IsNotNull(model);
            var crystal = model.Crystal;

            Assert.IsNotNull(crystal);
            Assert.AreEqual(16, crystal.Atoms.Count);
            var atom = crystal.Atoms[0];

            Assert.IsNotNull(atom);
            Assert.IsNotNull(atom.FractionalPoint3D);
        }
        public void TestSulfurCompound_ImplicitHydrogens()
        {
            var filename       = "NCDK.Data.MDL.sulfurCompound.mol";
            var ins            = ResourceLoader.GetAsStream(filename);
            var reader         = new MDLV2000Reader(ins);
            var chemFile       = reader.Read(builder.NewChemFile());
            var containersList = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();

            Assert.AreEqual(1, containersList.Count);

            var atomContainer_0 = (IAtomContainer)containersList[0];

            Assert.AreEqual(10, atomContainer_0.Atoms.Count);
            var sulfur = atomContainer_0.Atoms[1];

            FindAndConfigureAtomTypesForAllAtoms(atomContainer_0);
            adder.AddImplicitHydrogens(atomContainer_0);
            Assert.AreEqual("S", sulfur.Symbol);
            Assert.IsNotNull(sulfur.ImplicitHydrogenCount);
            Assert.AreEqual(0, sulfur.ImplicitHydrogenCount.Value);
            Assert.AreEqual(3, atomContainer_0.GetConnectedBonds(sulfur).Count());
            Assert.AreEqual(10, atomContainer_0.Atoms.Count);
            Assert.IsNotNull(sulfur.ImplicitHydrogenCount);
            Assert.AreEqual(0, sulfur.ImplicitHydrogenCount.Value);
            Assert.AreEqual(3, atomContainer_0.GetConnectedBonds(sulfur).Count());
        }
        public virtual void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            EntryReact entry   = (EntryReact)dictionary[entryString.ToLowerInvariant()];
            var        xmlList = entry.ExampleReactions;

            Assert.IsTrue(xmlList.Count != 0, "The representation entry for [" + entryString
                          + "]  must contain at least one example of reaction.");
            Assert.IsTrue(xmlList.Count > 0, "The representation entry for [" + entryString
                          + "]  must contain at least one example of reaction.");
            foreach (var xml in xmlList)
            {
                CMLReader reader       = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(xml)));
                var       chemFile     = (IChemFile)reader.Read(builder.NewChemFile());
                IReaction reactionDict = chemFile[0][0].ReactionSet[0];

                var reactants = reactionDict.Reactants;
                var agents    = reactionDict.Agents;
                var products  = reactionDict.Products;
                if (agents.Count == 0)
                {
                    agents = null;
                }

                IReactionSet reactions = reaction.Initiate(reactants, agents);

                Assert.IsTrue(reactions.Count > 0, "The products for [" + entryString + "] reaction is at least one reaction expected.");

                Assert.AreEqual(products[0].Atoms.Count,
                                reactions[0].Products[0].Atoms.Count,
                                "The products for [" + entryString + "] reaction is not the expected.");
            }
        }
Exemple #15
0
 public override void StartDocument()
 {
     ChemFile       = builder.NewChemFile();
     chemSequence   = builder.NewChemSequence();
     chemModel      = builder.NewChemModel();
     setOfMolecules = builder.NewChemObjectSet <IAtomContainer>();
 }
        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"));
        }
Exemple #17
0
 public SpanningTreeTest()
 {
     if (azulene == null)
     {
         // load azulene
         var            filename        = "NCDK.Data.MDL.azulene.mol";
         var            ins             = ResourceLoader.GetAsStream(filename);
         var            reader          = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
         var            chemFile        = reader.Read(builder.NewChemFile());
         var            seq             = chemFile[0];
         var            model           = seq[0];
         IAtomContainer azuleneMolecule = model.MoleculeSet[0];
         Assert.AreEqual(10, azuleneMolecule.Atoms.Count);
         Assert.AreEqual(11, azuleneMolecule.Bonds.Count);
         azulene = new SpanningTree(azuleneMolecule);
     }
     if (ethane == null)
     {
         // create ethane
         IAtomContainer ethaneMolecule = builder.NewAtomContainer();
         ethaneMolecule.Atoms.Add(builder.NewAtom("C"));
         ethaneMolecule.Atoms.Add(builder.NewAtom("C"));
         ethaneMolecule.AddBond(ethaneMolecule.Atoms[0], ethaneMolecule.Atoms[1], BondOrder.Single);
         ethane = new SpanningTree(ethaneMolecule);
     }
 }
Exemple #18
0
        public void TestStabilityAfterRoundtrip()
        {
            var filename = "NCDK.Data.MDL.bug1014344-1.mol";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new MDLReader(ins, ChemObjectReaderMode.Strict);
            var mol1     = reader.Read(builder.NewAtomContainer());

            AddImplicitHydrogens(mol1);
            var output    = new StringWriter();
            var cmlWriter = new CMLWriter(output);

            cmlWriter.Write(mol1);
            var cmlreader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(output.ToString())));
            var mol2      = ((IChemFile)cmlreader.Read(builder.NewChemFile()))[0][0].MoleculeSet[0];

            AddImplicitHydrogens(mol2);

            labeler.CanonLabel(mol1);
            labeler.CanonLabel(mol2);
            var atoms1 = mol1.Atoms.GetEnumerator();
            var atoms2 = mol2.Atoms.GetEnumerator();

            while (atoms1.MoveNext())
            {
                atoms2.MoveNext();
                var atom1 = atoms1.Current;
                var atom2 = atoms2.Current;
                Assert.AreEqual(atom1.GetProperty <long>(InvPair.CanonicalLabelPropertyKey), atom2.GetProperty <long>(InvPair.CanonicalLabelPropertyKey));
            }
        }
Exemple #19
0
        public void TestRDFChemFile()
        {
            var filename = "NCDK.Data.MDL.qsar-reaction-test.rdf";

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

            reader.Close();
            Assert.IsNotNull(chemFile);

            Assert.AreEqual(2, chemFile[0][0].ReactionSet.Count);
            Assert.AreEqual(2, chemFile[0][0].ReactionSet[0]
                            .Reactants.Count);
            Assert.AreEqual(3, chemFile[0][0].ReactionSet[0]
                            .Reactants[0].Atoms.Count);
            Assert.AreEqual(2, chemFile[0][0].ReactionSet[0]
                            .Reactants[1].Atoms.Count);
            Assert.AreEqual(2, chemFile[0][0].ReactionSet[0]
                            .Products.Count);
            Assert.AreEqual(2, chemFile[0][0].ReactionSet[0]
                            .Products[0].Atoms.Count);
            Assert.AreEqual(2, chemFile[0][0].ReactionSet[0]
                            .Products[1].Atoms.Count);

            Assert.AreEqual(1, chemFile[0][0].ReactionSet[1]
                            .Reactants.Count);
            Assert.AreEqual(3, chemFile[0][0].ReactionSet[1]
                            .Reactants[0].Atoms.Count);
            Assert.AreEqual(1, chemFile[0][0].ReactionSet[1]
                            .Products.Count);
            Assert.AreEqual(2, chemFile[0][0].ReactionSet[1]
                            .Products[0].Atoms.Count);
        }
Exemple #20
0
        public void TestFindHeavyAtomsInChain_IAtomContainer_IAtomContainer()
        {
            var filename = "NCDK.Data.MDL.allmol232.mol";
            var ins      = ResourceLoader.GetAsStream(filename);
            // TODO: shk3-cleanuptests: best to use the STRICT IO mode here
            var reader   = new MDLV2000Reader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();
            var containersList = ChemFileManipulator.GetAllAtomContainers(chemFile);
            var ac             = new Silent.AtomContainer(containersList.First());

            AddExplicitHydrogens(ac);
            var chain = ac.Builder.NewAtomContainer();

            for (int i = 16; i < 25; i++)
            {
                chain.Atoms.Add(ac.Atoms[i]);
            }
            chain.Atoms.Add(ac.Atoms[29]);
            chain.Atoms.Add(ac.Atoms[30]);
            int[] result = new AtomPlacer3D().FindHeavyAtomsInChain(ac, chain);
            Assert.AreEqual(16, result[0]);
            Assert.AreEqual(11, result[1]);
        }
Exemple #21
0
        public void TestNonConnectedPiSystems()
        {
            Trace.TraceInformation("Entering testNonConnectedPiSystems.");
            IAtomContainer mol      = null;
            var            filename = "NCDK.Data.MDL.nonConnectedPiSystems.mol";
            var            ins      = ResourceLoader.GetAsStream(filename);
            MDLReader      reader   = new MDLReader(ins);
            var            chemFile = reader.Read(builder.NewChemFile());

            mol = chemFile[0][0].MoleculeSet[0];
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol);
            Aromaticity.CDKLegacy.Apply(mol);

            var acSet = ConjugatedPiSystemsDetector.Detect(mol);

            Assert.AreEqual(2, acSet.Count);
            IAtomContainer ac1 = acSet[0];

            Assert.AreEqual(4, ac1.Atoms.Count);
            Assert.AreEqual(3, ac1.Bonds.Count);

            for (int i = 0; i < ac1.Atoms.Count; i++)
            {
                Assert.IsTrue(mol.Contains(ac1.Atoms[i]));
            }

            for (int i = 0; i < ac1.Bonds.Count; i++)
            {
                Assert.IsTrue(mol.Contains(ac1.Bonds[i]));
            }

            IAtomContainer ac2 = acSet[1];

            Assert.AreEqual(4, ac2.Atoms.Count);
            Assert.AreEqual(3, ac2.Bonds.Count);

            for (int i = 0; i < ac2.Atoms.Count; i++)
            {
                Assert.IsTrue(mol.Contains(ac2.Atoms[i]));
            }

            for (int i = 0; i < ac2.Bonds.Count; i++)
            {
                Assert.IsTrue(mol.Contains(ac2.Bonds[i]));
            }
        }
        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);
        }
        private IChemFile ParseCMLString(string cmlString)
        {
            IChemFile chemFile = null;

            using (var reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(cmlString))))
            {
                chemFile = reader.Read(builder.NewChemFile());
            }
            return(chemFile);
        }
        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);
        }
Exemple #25
0
        public void TestPorphyrine()
        {
            IRingSet       ringSet = null;
            AllRingsFinder arf     = new AllRingsFinder();

            var            filename = "NCDK.Data.MDL.porphyrin.mol";
            var            ins      = ResourceLoader.GetAsStream(filename);
            var            reader   = new MDLV2000Reader(ins);
            var            chemFile = reader.Read(builder.NewChemFile());
            var            seq      = chemFile[0];
            var            model    = seq[0];
            IAtomContainer molecule = model.MoleculeSet[0];

            ringSet = arf.FindAllRings(molecule);
            Assert.AreEqual(20, ringSet.Count);
        }
        private IAtomContainer LoadMolecule(string path)
        {
            var ins      = ResourceLoader.GetAsStream(path);
            var reader   = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            var chemFile = reader.Read(builder.NewChemFile());

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

            return((IAtomContainer)containersList[0]);
        }
Exemple #27
0
        public void TestReadGz()
        {
            var filename = "NCDK.Data.XYZ.bf3.xyz.gz";
            var input    = new GZipStream(ResourceLoader.GetAsStream(filename), CompressionMode.Decompress);
            // 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);
        }
Exemple #28
0
        public void TestRoundTrip()
        {
            StringWriter sWriter = new StringWriter();
            PDBWriter    writer  = new PDBWriter(sWriter);

            ICrystal crystal = builder.NewCrystal();

            crystal.A = new Vector3(0, 1, 0);
            crystal.B = new Vector3(1, 0, 0);
            crystal.C = new Vector3(0, 0, 2);

            IAtom atom = builder.NewAtom("C");

            atom.Point3D = new Vector3(0.1, 0.1, 0.3);
            crystal.Atoms.Add(atom);

            writer.Write(crystal);
            writer.Close();

            string output = sWriter.ToString();

            Assert.IsNotNull(output);
            Assert.IsTrue(output.Length > 0);

            PDBReader reader   = new PDBReader(new StringReader(""));
            var       chemFile = reader.Read(builder.NewChemFile());

            reader.Close();

            Assert.IsNotNull(chemFile);
            Assert.AreEqual(1, chemFile.Count);
            IChemSequence sequence = chemFile[0];

            Assert.AreEqual(1, sequence.Count);
            IChemModel chemModel = sequence[0];

            Assert.IsNotNull(chemModel);

            // can't do further testing as the PDBReader does not read
            // Crystal structures :(
        }
Exemple #29
0
        public void TestEstron()
        {
            var filename = "NCDK.Data.CML.estron.cml";

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

            using (var ins = ResourceLoader.GetAsStream(filename))
                using (var reader = new CMLReader(ins))
                {
                    chemFile = reader.Read(builder.NewChemFile());
                }

            // test the resulting ChemFile content
            Assert.IsNotNull(chemFile);
            Assert.AreEqual(1, chemFile.Count);
            var seq = chemFile[0];

            Assert.IsNotNull(seq);
            Assert.AreEqual(1, seq.Count);
            var model = seq[0];

            Assert.IsNotNull(model);

            // test the molecule
            ICrystal crystal = model.Crystal;

            Assert.IsNotNull(crystal);
            Assert.AreEqual(4 * 42, crystal.Atoms.Count);
            Assert.IsTrue(GeometryUtil.Has3DCoordinates(crystal));
            // test the cell axes
            Vector3 a = crystal.A;

            Assert.IsTrue(a.X != 0.0);
            Vector3 b = crystal.B;

            Assert.IsTrue(b.Y != 0.0);
            Vector3 c = crystal.C;

            Assert.IsTrue(c.Z != 0.0);
        }
Exemple #30
0
        public void TestBenzene()
        {
            var filename = "NCDK.Data.HIN.benzene.hin";

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

            reader.Close();

            Assert.IsNotNull(chemFile);
            Assert.AreEqual(1, chemFile.Count);
            var seq = chemFile[0];

            Assert.IsNotNull(seq);
            Assert.AreEqual(1, seq.Count);
            var model = seq[0];

            Assert.IsNotNull(model);

            var som = model.MoleculeSet;

            Assert.IsNotNull(som);
            Assert.AreEqual(1, som.Count);
            var m = som[0];

            Assert.IsNotNull(m);
            Assert.AreEqual(12, m.Atoms.Count);
            // AreEqual(?, m.Bonds.Count);
        }