Example #1
0
        public void TestRDFReactioniSet()
        {
            var filename = "NCDK.Data.MDL.qsar-reaction-test.rdf";

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

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

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

            Assert.AreEqual(1, reactionSet[1].Reactants.Count);
            Assert.AreEqual(3, reactionSet[1].Reactants[0].Atoms.Count);
            Assert.AreEqual(1, reactionSet[1].Products.Count);
            Assert.AreEqual(2, reactionSet[1].Products[0].Atoms.Count);
        }
        public void TestGetAllMolecules_IReactionSet()
        {
            IReactionSet reactionSet = builder.NewReactionSet();

            reactionSet.Add(builder.NewReaction()); // 1
            reactionSet.Add(builder.NewReaction()); // 2

            Assert.AreEqual(0, ReactionSetManipulator.GetAllMolecules(reactionSet).Count);
        }
Example #3
0
        public void TestNewReactionSet()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IReactionSet       set     = builder.NewReactionSet();

            Assert.IsNotNull(set);
        }
Example #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);
 }
Example #5
0
        public void TestIsEmpty_ReactionSet()
        {
            var model = (IChemModel)NewChemObject();
            IChemObjectBuilder builder = model.Builder;

            IAtomContainer molecule = builder.NewAtomContainer();
            IReaction reaction = builder.NewReaction();

            reaction.Reactants.Add(molecule);

            IReactionSet set = builder.NewReactionSet();
            model.ReactionSet = set;
            Assert.IsTrue(model.IsEmpty(), "model has an empty reaction set and should be empty");
            set.Add(reaction);
            Assert.IsFalse(model.IsEmpty(), "model has a reaction set and should not be empty");
            model.ReactionSet = null;
            Assert.IsTrue(model.IsEmpty(), "model has no reaction set");
        }
Example #6
0
        public void TestReactionSet_2()
        {
            IReaction      reaction11 = builder.NewReaction();
            IAtomContainer hydroxide  = builder.NewAtomContainer();

            hydroxide.Atoms.Add(builder.NewAtom("O"));
            reaction11.Reactants.Add(hydroxide);
            IAtomContainer proton = builder.NewAtomContainer();

            proton.Atoms.Add(builder.NewAtom("H"));
            reaction11.Reactants.Add(proton);

            IAtomContainer water = builder.NewAtomContainer();

            water.Atoms.Add(builder.NewAtom("O"));
            reaction11.Products.Add(water);

            IReaction      reaction12 = builder.NewReaction();
            IAtomContainer h          = builder.NewAtomContainer();

            h.Atoms.Add(builder.NewAtom("H"));
            IAtomContainer n = builder.NewAtomContainer();

            n.Atoms.Add(builder.NewAtom("N"));
            reaction12.Reactants.Add(h);
            reaction12.Reactants.Add(n);
            IAtomContainer ammonia = builder.NewAtomContainer();

            ammonia.Atoms.Add(builder.NewAtom("N"));
            ammonia.Atoms.Add(builder.NewAtom("H"));
            ammonia.AddBond(ammonia.Atoms[0], ammonia.Atoms[1], BondOrder.Single);
            reaction12.Products.Add(ammonia);

            IReactionSet reactionSet = builder.NewReactionSet();

            reactionSet.Add(reaction11);
            reactionSet.Add(reaction12);

            // now serialize to MDL RXN
            StringWriter writer    = new StringWriter();
            string       file      = "";
            MDLRXNWriter mdlWriter = new MDLRXNWriter(writer);

            mdlWriter.Write(reactionSet);
            mdlWriter.Close();
            file = writer.ToString();

            Assert.IsTrue(file.Length > 0);

            // now deserialize the MDL RXN output
            IReactionSet reactionSetF = builder.NewReactionSet();
            MDLRXNReader reader       = new MDLRXNReader(new StringReader(file));

            reactionSetF = (IReactionSet)reader.Read(reactionSetF);
            reader.Close();

            Assert.AreEqual(2, reactionSetF.Count);
            Assert.AreEqual(1, reactionSetF[0].Reactants[0].Atoms.Count);
            Assert.AreEqual(1, reactionSetF[0].Reactants[1].Atoms.Count);
            Assert.AreEqual(1, reactionSetF[0].Products.Count);
            Assert.AreEqual(1, reactionSetF[0].Products[0].Atoms.Count);
        }
        public void TestCreateReactionScheme_IReactionSet()
        {
            IAtomContainer molA = builder.NewAtomContainer();

            molA.Id = "A";
            IAtomContainer molB = builder.NewAtomContainer();

            molB.Id = "B";
            IAtomContainer molC = builder.NewAtomContainer();

            molC.Id = "C";
            IAtomContainer molD = builder.NewAtomContainer();

            molD.Id = "D";
            IAtomContainer molE = builder.NewAtomContainer();

            molE.Id = "E";

            IReactionSet reactionSet = builder.NewReactionSet();
            IReaction    reaction1   = builder.NewReaction();

            reaction1.Id = "r1";
            reaction1.Reactants.Add(molA);
            reaction1.Products.Add(molB);
            reactionSet.Add(reaction1);

            IReaction reaction2 = builder.NewReaction();

            reaction2.Id = "r2";
            reaction2.Reactants.Add(molB);
            reaction2.Products.Add(molC);
            reactionSet.Add(reaction2);

            IReaction reaction3 = builder.NewReaction();

            reaction3.Id = "r3";
            reaction3.Reactants.Add(molB);
            reaction3.Products.Add(molD);
            reactionSet.Add(reaction3);

            IReaction reaction4 = builder.NewReaction();

            reaction4.Id = "r4";
            reaction4.Reactants.Add(molC);
            reaction4.Products.Add(molE);
            reactionSet.Add(reaction4);

            IReactionScheme scheme1 = ReactionSchemeManipulator.NewReactionScheme(reactionSet);

            Assert.AreEqual(1, scheme1.Reactions.Count());
            Assert.AreEqual("r1", scheme1.Reactions.ElementAt(0).Id);
            Assert.AreEqual(1, scheme1.Schemes.Count);

            IReactionScheme scheme2 = scheme1.Schemes.First();

            Assert.AreEqual(2, scheme2.Reactions.Count());
            Assert.AreEqual("r2", scheme2.Reactions.ElementAt(0).Id);
            Assert.AreEqual("r3", scheme2.Reactions.ElementAt(1).Id);
            Assert.AreEqual(1, scheme2.Schemes.Count);

            IReactionScheme scheme3 = scheme2.Schemes.First();

            Assert.AreEqual(1, scheme3.Reactions.Count());
            Assert.AreEqual("r4", scheme3.Reactions.ElementAt(0).Id);
            Assert.AreEqual(0, scheme3.Schemes.Count);
        }