Пример #1
0
        public void TestReactionCustomization()
        {
            var writer   = new StringWriter();
            var reaction = builder.NewReaction();

            reaction.Id = "reaction1";
            IAtomContainer reactant = reaction.Builder.NewAtomContainer();

            reactant.Id = "react";
            IAtomContainer product = reaction.Builder.NewAtomContainer();

            product.Id = "product";
            IAtomContainer agent = reaction.Builder.NewAtomContainer();

            agent.Id = "agent";

            reaction.Reactants.Add(reactant);
            reaction.Products.Add(product);
            reaction.Agents.Add(agent);

            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(reaction);
            cmlWriter.Close();
            string cmlContent = writer.ToString();

            Debug.WriteLine("****************************** TestReactionCustomization()");
            Debug.WriteLine(cmlContent);
            Debug.WriteLine("******************************");
            Assert.IsTrue(cmlContent.IndexOf("<reaction id=\"reaction1") != -1);
            Assert.IsTrue(cmlContent.IndexOf("<molecule id=\"react") != -1);
            Assert.IsTrue(cmlContent.IndexOf("<molecule id=\"product") != -1);
            Assert.IsTrue(cmlContent.IndexOf("<molecule id=\"agent") != -1);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public void TestNullFormalCharge()
        {
            var            writer   = new StringWriter();
            IAtomContainer molecule = builder.NewAtomContainer(); // methane

            molecule.Atoms.Add(molecule.Builder.NewAtom(ChemicalElement.C));
            molecule.Atoms[0].FormalCharge = null;
            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(molecule);
            cmlWriter.Close();
            Debug.WriteLine("****************************** TestNullFormalCharge()");
            Debug.WriteLine(writer.ToString());
            Debug.WriteLine("******************************");
            Assert.IsFalse(writer.ToString().Contains("formalCharge"));
        }
Пример #4
0
        public void TestHydrogenCount()
        {
            var            writer   = new StringWriter();
            IAtomContainer molecule = builder.NewAtomContainer(); // methane

            molecule.Atoms.Add(molecule.Builder.NewAtom(ChemicalElement.C));
            molecule.Atoms[0].ImplicitHydrogenCount = 4;
            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(molecule);
            cmlWriter.Close();
            Debug.WriteLine("****************************** TestHydrogenCount()");
            Debug.WriteLine(writer.ToString());
            Debug.WriteLine("******************************");
            Assert.IsTrue(writer.ToString().IndexOf("hydrogenCount=\"4\"") != -1);
        }
Пример #5
0
        public void TestCMLWriterBenzene()
        {
            var            writer   = new StringWriter();
            IAtomContainer molecule = TestMoleculeFactory.MakeBenzene();

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            Aromaticity.CDKLegacy.Apply(molecule);
            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(molecule);
            cmlWriter.Close();
            Debug.WriteLine("****************************** TestCMLWriterBenzene()");
            Debug.WriteLine(writer.ToString());
            Debug.WriteLine("******************************");
            Assert.IsTrue(writer.ToString().IndexOf("</molecule>") != -1);
        }
Пример #6
0
        public void TestMassNumber()
        {
            var writer = new StringWriter();
            var mol    = builder.NewAtomContainer();
            var atom   = builder.NewAtom("C");

            atom.MassNumber = 12;
            mol.Atoms.Add(atom);
            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(mol);
            cmlWriter.Close();
            Debug.WriteLine("****************************** TestMAssNumber()");
            Debug.WriteLine(writer.ToString());
            Debug.WriteLine("******************************");
            Assert.IsTrue(writer.ToString().IndexOf("isotopeNumber=\"12\"") != -1);
        }
Пример #7
0
        public void TestReactionProperty()
        {
            var writer   = new StringWriter();
            var reaction = builder.NewReaction();

            reaction.Id = "r1";
            reaction.SetProperty("blabla", "blabla2");
            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(reaction);
            cmlWriter.Close();
            string cmlContent = writer.ToString();

            Debug.WriteLine("****************************** TestReactionCustomization()");
            Debug.WriteLine(cmlContent);
            Debug.WriteLine("******************************");
            Assert.IsTrue(cmlContent.IndexOf("<scalar dictRef=\"cdk:reactionProperty") != -1);
        }
Пример #8
0
        public void TestMoleculeSetID()
        {
            var writer      = new StringWriter();
            var moleculeSet = builder.NewChemObjectSet <IAtomContainer>();

            moleculeSet.Id = "ms0";

            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(moleculeSet);
            cmlWriter.Close();
            string cmlContent = writer.ToString();

            Debug.WriteLine("****************************** TestReactionCustomization()");
            Debug.WriteLine(cmlContent);
            Debug.WriteLine("******************************");
            Assert.IsTrue(cmlContent.IndexOf("<moleculeList convention=\"cdk:moleculeSet\" id=\"ms0") != -1);
        }
Пример #9
0
        public void TestChemModeID()
        {
            var writer    = new StringWriter();
            var chemModel = builder.NewChemModel();

            chemModel.Id = "cm0";

            var cmlWriter = new CMLWriter(writer);

            cmlWriter.Write(chemModel);
            cmlWriter.Close();
            string cmlContent = writer.ToString();

            Debug.WriteLine("****************************** TestReactionCustomization()");
            Debug.WriteLine(cmlContent);
            Debug.WriteLine("******************************");
            Assert.IsTrue(cmlContent.IndexOf("<list convention=\"cdk:model\" id=\"cm0") != -1);
        }
Пример #10
0
        public void TestMDMoleculeCustomization()
        {
            StringWriter writer = new StringWriter();

            CMLWriter cmlWriter = new CMLWriter(writer);

            cmlWriter.RegisterCustomizer(new MDMoleculeCustomizer());
            try
            {
                IAtomContainer molecule = MakeMDBenzene();
                cmlWriter.Write(molecule);
                cmlWriter.Close();
            }
            catch (Exception exception)
            {
                if (!(exception is CDKException || exception is IOException))
                {
                    throw;
                }
                {
                    Trace.TraceError($"Error while creating an CML2 file: {exception.Message}");
                    Debug.WriteLine(exception);
                    Assert.Fail(exception.Message);
                }
            }
            string cmlContent = writer.ToString();

            Debug.WriteLine("****************************** TestMDMoleculeCustomization()");
            Debug.WriteLine(cmlContent);
            Debug.WriteLine("******************************");
            //        Console.Out.WriteLine("****************************** TestMDMoleculeCustomization()");
            //        Console.Out.WriteLine(cmlContent);
            //        Console.Out.WriteLine("******************************");
            Assert.IsTrue(cmlContent.IndexOf("xmlns:md") != -1);
            Assert.IsTrue(cmlContent.IndexOf("md:residue\"") != -1);
            Assert.IsTrue(cmlContent.IndexOf("md:resNumber\"") != -1);
            Assert.IsTrue(cmlContent.IndexOf("md:chargeGroup\"") != -1);
            Assert.IsTrue(cmlContent.IndexOf("md:cgNumber\"") != -1);
            Assert.IsTrue(cmlContent.IndexOf("md:switchingAtom\"") != -1);
        }
Пример #11
0
        public void TestPDBAtomCustomization()
        {
            StringWriter writer   = new StringWriter();
            var          molecule = builder.NewAtomContainer();
            IPDBAtom     atom     = builder.NewPDBAtom("C");

            atom.Name    = "CA";
            atom.ResName = "PHE";
            molecule.Atoms.Add(atom);

            CMLWriter cmlWriter = new CMLWriter(writer);

            cmlWriter.RegisterCustomizer(new PDBAtomCustomizer());
            cmlWriter.Write(molecule);
            cmlWriter.Close();
            string cmlContent = writer.ToString();

            Debug.WriteLine("****************************** TestPDBAtomCustomization()");
            Debug.WriteLine(cmlContent);
            Debug.WriteLine("******************************");
            Assert.IsTrue(cmlContent.IndexOf("<scalar dictRef=\"pdb:resName") != -1);
        }
Пример #12
0
        public void TestMDMoleculeCustomizationRoundtripping()
        {
            StringWriter writer = new StringWriter();

            CMLWriter cmlWriter = new CMLWriter(writer);

            cmlWriter.RegisterCustomizer(new MDMoleculeCustomizer());
            MDMolecule molecule = MakeMDBenzene();

            cmlWriter.Write(molecule);
            cmlWriter.Close();

            string serializedMol = writer.ToString();

            Debug.WriteLine("****************************** TestMDMoleculeCustomizationRoundtripping()");
            Debug.WriteLine(serializedMol);
            Debug.WriteLine("******************************");
            Debug.WriteLine("****************************** testMDMoleculeCustomization Write first");
            Debug.WriteLine(serializedMol);
            Debug.WriteLine("******************************");

            CMLReader reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(serializedMol)));

            reader.RegisterConvention("md:mdMolecule", new MDMoleculeConvention(builder.NewChemFile()));
            IChemFile file = (IChemFile)reader.Read(builder.NewChemFile());

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

            Assert.AreEqual(1, containers.Count);

            var molecule2 = containers[0];

            Assert.IsTrue(molecule2 is MDMolecule);
            MDMolecule mdMol = (MDMolecule)molecule2;

            Assert.AreEqual(6, mdMol.Atoms.Count);
            Assert.AreEqual(6, mdMol.Bonds.Count);

            var residues = mdMol.GetResidues();

            Assert.AreEqual(2, residues.Count);
            Assert.AreEqual(3, ((Residue)residues[0]).Atoms.Count);
            Assert.AreEqual(3, ((Residue)residues[1]).Atoms.Count);
            Assert.AreEqual("myResidue1", ((Residue)residues[0]).Name);
            Assert.AreEqual("myResidue2", ((Residue)residues[1]).Name);
            Assert.AreEqual(0, ((Residue)residues[0]).GetNumber());
            Assert.AreEqual(1, ((Residue)residues[1]).GetNumber());

            var chargeGroup = mdMol.GetChargeGroups();

            Assert.AreEqual(2, chargeGroup.Count);
            Assert.AreEqual(2, ((ChargeGroup)chargeGroup[0]).Atoms.Count);
            Assert.AreEqual(4, ((ChargeGroup)chargeGroup[1]).Atoms.Count);
            Assert.IsNotNull(((ChargeGroup)chargeGroup[0]).GetSwitchingAtom());
            Assert.AreEqual("a2", ((ChargeGroup)chargeGroup[0]).GetSwitchingAtom().Id);
            Assert.IsNotNull(((ChargeGroup)chargeGroup[1]).GetSwitchingAtom());
            Assert.AreEqual("a5", ((ChargeGroup)chargeGroup[1]).GetSwitchingAtom().Id);

            Assert.AreEqual(2, ((ChargeGroup)chargeGroup[0]).GetNumber());
            Assert.AreEqual(3, ((ChargeGroup)chargeGroup[1]).GetNumber());

            writer = new StringWriter();

            cmlWriter = new CMLWriter(writer);
            cmlWriter.RegisterCustomizer(new MDMoleculeCustomizer());
            cmlWriter.Write(mdMol);
            cmlWriter.Close();

            string serializedMDMol = writer.ToString();

            Debug.WriteLine("****************************** TestMDMoleculeCustomizationRoundtripping()");
            Debug.WriteLine(serializedMol);
            Debug.WriteLine("******************************");
            Debug.WriteLine("****************************** testMDMoleculeCustomization Write second");
            Debug.WriteLine(serializedMDMol);
            Debug.WriteLine("******************************");

            Assert.AreEqual(serializedMol, serializedMDMol);
        }