コード例 #1
0
        public void TestGetReactionByAtomContainerID_IReactionSet_String()
        {
            IReactionSet set       = builder.NewReactionSet();
            IReaction    reaction1 = builder.NewReaction();

            set.Add(reaction1);
            IAtomContainer mol1a = builder.NewAtomContainer();

            mol1a.Id = "1";
            IAtomContainer mol1b = builder.NewAtomContainer();

            mol1b.Id = "2";
            reaction1.Reactants.Add(mol1a);
            reaction1.Reactants.Add(builder.NewAtomContainer());
            reaction1.Products.Add(builder.NewAtomContainer());
            reaction1.Products.Add(builder.NewAtomContainer());

            IReaction reaction2 = builder.NewReaction();

            reaction2.Reactants.Add(builder.NewAtomContainer());
            reaction2.Products.Add(mol1b);
            set.Add(reaction2);

            IReaction reaction3 = builder.NewReaction();

            reaction3.Reactants.Add(builder.NewAtomContainer());
            reaction3.Products.Add(builder.NewAtomContainer());
            set.Add(reaction3);
            Assert.AreEqual(reaction1, ReactionSetManipulator.GetReactionByAtomContainerID(set, "1"));
            Assert.AreEqual(reaction2, ReactionSetManipulator.GetReactionByAtomContainerID(set, "2"));
            Assert.IsNull(ReactionSetManipulator.GetReactionByAtomContainerID(set, "3"));
        }
コード例 #2
0
        public void TestNewReactionSet()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IReactionSet       set     = builder.NewReactionSet();

            Assert.IsNotNull(set);
        }
コード例 #3
0
        public void TestGetAllIDs_IReactionSet()
        {
            IReactionSet set       = builder.NewReactionSet();
            IReaction    reaction1 = builder.NewReaction();

            set.Add(reaction1);
            reaction1.Id = "r1";
            IAtomContainer water = new AtomContainer {
                Id = "m1"
            };
            Atom oxygen = new Atom("O")
            {
                Id = "a1"
            };

            water.Atoms.Add(oxygen);
            reaction1.Reactants.Add(water);
            reaction1.Products.Add(water);
            IReaction reaction2 = builder.NewReaction();

            reaction2.Id = "r2";
            set.Add(reaction2);

            var ids = ReactionSetManipulator.GetAllIDs(set);

            Assert.IsNotNull(ids);
            Assert.AreEqual(6, ids.Count());
        }
コード例 #4
0
        public void TestGetRelevantReactionsAsProduct_IReactionSet_IAtomContainer()
        {
            IReactionSet set       = builder.NewReactionSet();
            IReaction    reaction1 = builder.NewReaction();

            set.Add(reaction1);
            IAtomContainer mol1a = builder.NewAtomContainer();
            IAtomContainer mol1b = builder.NewAtomContainer();

            reaction1.Reactants.Add(mol1a);
            reaction1.Reactants.Add(mol1b);
            reaction1.Products.Add(builder.NewAtomContainer());
            reaction1.Products.Add(builder.NewAtomContainer());

            IReaction reaction2 = builder.NewReaction();

            reaction2.Reactants.Add(mol1b);
            reaction2.Products.Add(builder.NewAtomContainer());
            set.Add(reaction2);

            IReaction reaction3 = builder.NewReaction();

            reaction3.Reactants.Add(builder.NewAtomContainer());
            reaction3.Products.Add(mol1a);
            set.Add(reaction3);

            Assert.AreEqual(3, set.Count);
            IReactionSet reactionSet2 = ReactionSetManipulator.GetRelevantReactionsAsProduct(set, mol1b);

            Assert.AreEqual(0, reactionSet2.Count);
            IReactionSet reactionSet1 = ReactionSetManipulator.GetRelevantReactionsAsProduct(set, mol1a);

            Assert.AreEqual(1, reactionSet1.Count);
            Assert.AreEqual(reaction3, reactionSet1[0]);
        }
コード例 #5
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);
 }
コード例 #6
0
        //    public Rectangle PaintReactionSet(
        //            IReactionSet reactionSet, IDrawVisitor drawVisitor) {
        //        // total up the bounding boxes
        //        Rectangle2D totalBounds = CreateRectangle();
        //        foreach (var reaction in reactionSet.reactions()) {
        //            Rectangle2D modelBounds = BoundsCalculator.CalculateBounds(reaction);
        //            if (totalBounds == null) {
        //                totalBounds = modelBounds;
        //            } else {
        //                totalBounds = totalBounds.CreateUnion(modelBounds);
        //            }
        //        }
        //
        //        // setup and draw
        //        this.SetupTransformNatural(totalBounds);
        //        ElementGroup diagram = new ElementGroup();
        //        foreach (var reaction in reactionSet.reactions()) {
        //            diagram.Add(this.GenerateDiagram(reaction));
        //        }
        //        this.Paint(drawVisitor, diagram);
        //
        //        // the size of the painted diagram is returned
        //        return this.ConvertToDiagramBounds(totalBounds);
        //    }
        //
        //    public Rectangle PaintReaction(
        //            IReaction reaction, IDrawVisitor drawVisitor) {
        //
        //        // calculate the bounds
        //        Rectangle2D modelBounds = BoundsCalculator.CalculateBounds(reaction);
        //
        //        // setup and draw
        //        this.SetupTransformNatural(modelBounds);
        //        IRenderingElement diagram = this.GenerateDiagram(reaction);
        //        this.Paint(drawVisitor, diagram);
        //
        //        return this.ConvertToDiagramBounds(modelBounds);
        //    }

        /// <summary>
        /// Paint a ChemModel.
        /// </summary>
        /// <param name="chemModel"></param>
        /// <param name="drawVisitor">the visitor that does the drawing</param>
        /// <param name="bounds">the bounds of the area to paint on.</param>
        /// <param name="resetCenter">if true, set the modelCenter to the center of the ChemModel's bounds.</param>
        public void Paint(IChemModel chemModel, IDrawVisitor drawVisitor, Rect bounds, bool resetCenter)
        {
            // check for an empty model
            var          moleculeSet = chemModel.MoleculeSet;
            IReactionSet reactionSet = chemModel.ReactionSet;

            // nasty, but it seems that reactions can be read in as ChemModels
            // with BOTH a ReactionSet AND a MoleculeSet...
            if (moleculeSet == null || reactionSet != null)
            {
                if (reactionSet != null)
                {
                    reactionSetRenderer.Paint(reactionSet, drawVisitor, bounds, resetCenter);
                }
                return;
            }

            // calculate the total bounding box
            var modelBounds = BoundsCalculator.CalculateBounds(moleculeSet);

            this.SetupTransformToFit(bounds, modelBounds,
                                     AverageBondLengthCalculator.CalculateAverageBondLength(chemModel), resetCenter);

            // generate the elements
            IRenderingElement diagram = moleculeSetRenderer.GenerateDiagram(moleculeSet);

            // paint it
            this.Paint(drawVisitor, diagram);
        }
コード例 #7
0
        public ValidationReport ValidateChemModel(IChemModel subject)
        {
            Trace.TraceInformation($"Validating {nameof(IChemModel)}");
            var report = new ValidationReport();

            // apply validators
            foreach (var test in validators.Values)
            {
                report.Add(test.ValidateChemModel(subject));
            }
            // traverse into super class
            report.Add(ValidateChemObject(subject));
            // traverse into hierarchy
            ICrystal crystal = subject.Crystal;

            if (crystal != null)
            {
                report.Add(ValidateCrystal(crystal));
            }
            IReactionSet reactionSet = subject.ReactionSet;

            if (reactionSet != null)
            {
                report.Add(ValidateReactionSet(reactionSet));
            }
            var moleculeSet = subject.MoleculeSet;

            if (moleculeSet != null)
            {
                report.Add(ValidateMoleculeSet(moleculeSet));
            }
            return(report);
        }
コード例 #8
0
        private static IChemObjectSet <IAtomContainer> GetReactionPath(IAtomContainer reactant, IAtomContainer finalMol,
                                                                       IReactionSet reactionSet)
        {
            var allSet = reactionSet.Builder.NewAtomContainerSet();

            foreach (var reaction in reactionSet)
            {
                foreach (var reactant2 in reaction.Reactants)
                {
                    if (reactant2.Equals(reactant))
                    {
                        foreach (var product in reaction.Products)
                        {
                            if (!product.Equals(finalMol))
                            {
                                var allSet2 = GetReactionPath(product, finalMol, reactionSet);
                                if (allSet2.Count() != 0)
                                {
                                    allSet.Add(reactant);
                                    allSet.AddRange(allSet2);
                                }
                            }
                            else
                            {
                                allSet.Add(product);
                                return(allSet);
                            }
                        }
                    }
                }
            }
            return(allSet);
        }
コード例 #9
0
        /// <summary>
        /// Extract a set of Reactions which are in top of a IReactionScheme. The top reactions are those
        /// which any of their reactants are participating in other reactions as a products.
        /// </summary>
        /// <param name="reactionScheme">The IReactionScheme</param>
        /// <returns>The set of top reactions</returns>
        public static IReactionSet ExtractTopReactions(IReactionScheme reactionScheme)
        {
            IReactionSet reactionSet = reactionScheme.Builder.NewReactionSet();

            IReactionSet allSet = GetAllReactions(reactionScheme);

            foreach (var reaction in allSet)
            {
                IReactionSet precuSet = ExtractPrecursorReaction(reaction, allSet);
                if (precuSet.Count == 0)
                {
                    bool found = false;
                    foreach (var reactIn in reactionSet)
                    {
                        if (reactIn.Equals(reaction))
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        reactionSet.Add(reaction);
                    }
                }
            }
            return(reactionSet);
        }
コード例 #10
0
        public override void TestClone()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();
            object       clone       = reactionSet.Clone();

            Assert.IsTrue(clone is IReactionSet);
        }
コード例 #11
0
ファイル: MDLRXNReaderTest.cs プロジェクト: roddickchen/NCDK
        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);
        }
コード例 #12
0
        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.");
            }
        }
コード例 #13
0
        /// <summary>
        /// Remove an ElectronContainer from all AtomContainers
        /// inside an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <param name="electrons">The ElectronContainer to remove.</param>
        public static void RemoveElectronContainer(IChemModel chemModel, IElectronContainer electrons)
        {
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.Contains(electrons))
                {
                    crystal.Remove(electrons);
                }
                return;
            }
            IChemObjectSet <IAtomContainer> moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                MoleculeSetManipulator.RemoveElectronContainer(moleculeSet, electrons);
            }
            IReactionSet reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                ReactionSetManipulator.RemoveElectronContainer(reactionSet, electrons);
            }
        }
コード例 #14
0
        /// <summary>
        /// This badly named methods tries to determine which AtomContainer in the
        /// ChemModel is best suited to contain added Atom's and Bond's.
        /// </summary>
        public static IAtomContainer GetRelevantAtomContainer(IChemModel chemModel, IAtom atom)
        {
            IAtomContainer result = null;

            if (chemModel.MoleculeSet != null)
            {
                IChemObjectSet <IAtomContainer> moleculeSet = chemModel.MoleculeSet;
                result = MoleculeSetManipulator.GetRelevantAtomContainer(moleculeSet, atom);
                if (result != null)
                {
                    return(result);
                }
            }
            if (chemModel.ReactionSet != null)
            {
                IReactionSet reactionSet = chemModel.ReactionSet;
                return(ReactionSetManipulator.GetRelevantAtomContainer(reactionSet, atom));
            }
            if (chemModel.Crystal != null && chemModel.Crystal.Contains(atom))
            {
                return(chemModel.Crystal);
            }
            if (chemModel.RingSet != null)
            {
                return(AtomContainerSetManipulator.GetRelevantAtomContainer(chemModel.RingSet, atom));
            }
            throw new ArgumentException("The provided atom is not part of this IChemModel.");
        }
コード例 #15
0
ファイル: MDLRXNWriter.cs プロジェクト: ch-hristov/NCDK
 /// <summary>
 ///  Writes an array of Reaction to an Stream in MDL rdf format.
 /// </summary>
 /// <param name="reactions">Array of Reactions that is written to an Stream</param>
 private void WriteReactionSet(IReactionSet reactions)
 {
     foreach (var iReaction in reactions)
     {
         WriteReaction(iReaction);
     }
 }
コード例 #16
0
        /// <summary>
        /// Remove an Atom and the connected ElectronContainers from all AtomContainers
        /// inside an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <param name="atom">The Atom object to remove.</param>
        public static void RemoveAtomAndConnectedElectronContainers(IChemModel chemModel, IAtom atom)
        {
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.Contains(atom))
                {
                    crystal.RemoveAtom(atom);
                }
                return;
            }
            IChemObjectSet <IAtomContainer> moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                MoleculeSetManipulator.RemoveAtomAndConnectedElectronContainers(moleculeSet, atom);
            }
            IReactionSet reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                ReactionSetManipulator.RemoveAtomAndConnectedElectronContainers(reactionSet, atom);
            }
        }
コード例 #17
0
 public static void RemoveElectronContainer(IReactionSet set, IElectronContainer electrons)
 {
     foreach (var reaction in set)
     {
         ReactionManipulator.RemoveElectronContainer(reaction, electrons);
     }
 }
コード例 #18
0
        /// <summary>
        /// get all Molecules object from a set of Reactions.
        /// </summary>
        /// <param name="set">The set of reaction to inspect</param>
        /// <returns>The IAtomContanerSet</returns>
        public static IChemObjectSet <IAtomContainer> GetAllMolecules(IReactionSet set)
        {
            var moleculeSet = set.Builder.NewAtomContainerSet();

            foreach (var reaction in set)
            {
                var molecules = ReactionManipulator.GetAllMolecules(reaction);
                foreach (var ac in molecules)
                {
                    bool contain = false;
                    foreach (var atomContainer in moleculeSet)
                    {
                        if (atomContainer.Equals(ac))
                        {
                            contain = true;
                            break;
                        }
                    }
                    if (!contain)
                    {
                        moleculeSet.Add(ac);
                    }
                }
            }
            return(moleculeSet);
        }
コード例 #19
0
 public static void SetAtomProperties(IReactionSet set, string propKey, object propVal)
 {
     foreach (var reaction in set)
     {
         ReactionManipulator.SetAtomProperties(reaction, propKey, propVal);
     }
 }
コード例 #20
0
 public static void RemoveAtomAndConnectedElectronContainers(IReactionSet set, IAtom atom)
 {
     foreach (var reaction in set)
     {
         ReactionManipulator.RemoveAtomAndConnectedElectronContainers(reaction, atom);
     }
 }
コード例 #21
0
ファイル: MDLRXNReaderTest.cs プロジェクト: roddickchen/NCDK
        public void TestAsadExamples()
        {
            var filename = "NCDK.Data.MDL.output.rxn";

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

            reader.Close();
            filename = "NCDK.Data.MDL.output_Cleaned.rxn";
            Trace.TraceInformation("Testing: " + filename);
            ins    = ResourceLoader.GetAsStream(filename);
            reader = new MDLRXNReader(ins);
            IReactionSet reactionSet2 = (IReactionSet)reader.Read(builder.NewReactionSet());

            reader.Close();
            Assert.AreEqual(reactionSet[0].Mappings.Count, reactionSet2[0].Mappings.Count);
            for (int i = 0; i < reactionSet[0].Mappings.Count; i++)
            {
                Assert.AreEqual(
                    _GetAtomNumber(reactionSet, reactionSet[0].Mappings[i][0]),
                    _GetAtomNumber(reactionSet2, reactionSet2[0].Mappings[i][0]));
                Assert.AreEqual(
                    _GetAtomNumber(reactionSet, reactionSet[0].Mappings[i][1]),
                    _GetAtomNumber(reactionSet2, reactionSet2[0].Mappings[i][1]));
            }
        }
コード例 #22
0
        /// <summary>
        /// Create a IReactionScheme give a IReactionSet object.
        /// </summary>
        /// <param name="reactionSet">The IReactionSet</param>
        /// <returns>The IReactionScheme</returns>
        public static IReactionScheme NewReactionScheme(IReactionSet reactionSet)
        {
            IReactionScheme reactionScheme = reactionSet.Builder.NewReactionScheme();

            // Looking for those reactants which doesn't have any precursor. They are the top.
            List <IReaction> listTopR = new List <IReaction>();

            foreach (var reaction in reactionSet)
            {
                if (ExtractPrecursorReaction(reaction, reactionSet).Count == 0)
                {
                    listTopR.Add(reaction);
                }
            }

            foreach (var reaction in listTopR)
            {
                reactionScheme.Add(reaction);
                IReactionScheme newReactionScheme = SetScheme(reaction, reactionSet);
                if (newReactionScheme.Reactions.Count() != 0 || newReactionScheme.Schemes.Count != 0)
                {
                    reactionScheme.Add(newReactionScheme);
                }
            }
            return(reactionScheme);
        }
コード例 #23
0
ファイル: CMLRoundTripTool.cs プロジェクト: roddickchen/NCDK
        public static IReaction RoundTripReaction(Convertor convertor, IReaction reaction)
        {
            string cmlString = "<!-- failed -->";
            var    cmlDOM    = convertor.CDKReactionToCMLReaction(reaction);

            cmlString = cmlDOM.ToString();

            IReaction roundTrippedReaction = null;

            Debug.WriteLine("CML string: ", cmlString);
            CMLReader reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(cmlString)));

            IChemFile file = (IChemFile)reader.Read(builder.NewChemFile());

            reader.Close();
            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);
            IReactionSet reactionSet = chemModel.ReactionSet;

            Assert.IsNotNull(reactionSet);
            Assert.AreEqual(1, reactionSet.Count);
            roundTrippedReaction = reactionSet[0];
            Assert.IsNotNull(roundTrippedReaction);

            return(roundTrippedReaction);
        }
コード例 #24
0
 public void TestSetReactionSet_IReactionSet()
 {
     IChemModel chemModel = (IChemModel)NewChemObject();
     IReactionSet crystal = chemModel.Builder.NewReactionSet();
     chemModel.ReactionSet = crystal;
     Assert.AreEqual(crystal, chemModel.ReactionSet);
 }
コード例 #25
0
 /// <summary>
 /// Takes an object which subclasses IChemObject, e.g.Molecule, and will read
 /// this (from file, database, Internet etc). If the specific implementation
 /// does not support a specific IChemObject it will throw an Exception.
 /// </summary>
 /// <param name="obj">The object that subclasses <see cref="IChemObject"/></param>
 /// <returns>The <see cref="IChemObject"/> read</returns>
 /// <exception cref="CDKException"></exception>
 public override T Read <T>(T obj)
 {
     if (obj is IReaction)
     {
         return((T)ReadReaction(obj.Builder));
     }
     else if (obj is IReactionSet)
     {
         IReactionSet reactionSet = obj.Builder.NewReactionSet();
         reactionSet.Add(ReadReaction(obj.Builder));
         return((T)reactionSet);
     }
     else if (obj is IChemModel)
     {
         IChemModel   model       = obj.Builder.NewChemModel();
         IReactionSet reactionSet = obj.Builder.NewReactionSet();
         reactionSet.Add(ReadReaction(obj.Builder));
         model.ReactionSet = reactionSet;
         return((T)model);
     }
     else if (obj is IChemFile)
     {
         IChemFile     chemFile = obj.Builder.NewChemFile();
         IChemSequence sequence = obj.Builder.NewChemSequence();
         sequence.Add((IChemModel)Read(obj.Builder.NewChemModel()));
         chemFile.Add(sequence);
         return((T)chemFile);
     }
     else
     {
         throw new CDKException($"Only supported are Reaction and ChemModel, and not {obj.GetType().Name}.");
     }
 }
コード例 #26
0
        private IReaction CheckForXReactionFile(IChemFile chemFile, int numberOfReactions)
        {
            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);

            IReactionSet reactionSet = model.ReactionSet;

            Assert.IsNotNull(reactionSet);

            Assert.AreEqual(reactionSet.Count, numberOfReactions);
            IReaction reaction = null;

            for (int i = 0; i < numberOfReactions; i++)
            {
                reaction = reactionSet[i];
                Assert.IsNotNull(reaction);
            }
            return(reaction);
        }
コード例 #27
0
 public void SetUp()
 {
     molecule1  = new AtomContainer();
     atomInMol1 = new Atom("Cl")
     {
         Charge                = -1.0,
         FormalCharge          = -1,
         ImplicitHydrogenCount = 1
     };
     molecule1.Atoms.Add(atomInMol1);
     molecule1.Atoms.Add(new Atom("Cl"));
     bondInMol1 = new Bond(atomInMol1, molecule1.Atoms[1]);
     molecule1.Bonds.Add(bondInMol1);
     molecule2  = new AtomContainer();
     atomInMol2 = new Atom("O")
     {
         ImplicitHydrogenCount = 2
     };
     molecule2.Atoms.Add(atomInMol2);
     moleculeSet = ChemObjectBuilder.Instance.NewAtomContainerSet();
     moleculeSet.Add(molecule1);
     moleculeSet.Add(molecule2);
     reaction = new Reaction();
     reaction.Reactants.Add(molecule1);
     reaction.Products.Add(molecule2);
     reactionSet = new ReactionSet
     {
         reaction
     };
     chemModel = new ChemModel
     {
         MoleculeSet = moleculeSet,
         ReactionSet = reactionSet
     };
 }
コード例 #28
0
        internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, BondCheck bondChecker)
        {
            CheckInitiateParams(reactants, agents);

            IReactionSet   setOfReactions = reactants.Builder.NewReactionSet();
            IAtomContainer reactant       = reactants[0];

            // if the parameter hasActiveCenter is not fixed yet, set the active centers
            IParameterReaction ipr = base.GetParameterClass(typeof(SetReactionCenter));

            if (ipr != null && !ipr.IsSetParameter)
            {
                SetActiveCenters(reactant, bondChecker);
            }
            foreach (var bondi in reactant.Bonds)
            {
                IAtom atom1 = bondi.Begin;
                IAtom atom2 = bondi.End;
                if (bondi.IsReactiveCenter &&
                    bondChecker(bondi) &&
                    atom1.IsReactiveCenter && atom2.IsReactiveCenter &&
                    (atom1.FormalCharge ?? 0) == 0 &&
                    (atom2.FormalCharge ?? 0) == 0 &&
                    !reactant.GetConnectedSingleElectrons(atom1).Any() &&
                    !reactant.GetConnectedSingleElectrons(atom2).Any())
                {
                    for (int j = 0; j < 2; j++)
                    {
                        var atomList = new List <IAtom>();
                        if (j == 0)
                        {
                            atomList.Add(atom1);
                            atomList.Add(atom2);
                        }
                        else
                        {
                            atomList.Add(atom2);
                            atomList.Add(atom1);
                        }
                        var bondList = new List <IBond>
                        {
                            bondi
                        };

                        IChemObjectSet <IAtomContainer> moleculeSet = reactant.Builder.NewAtomContainerSet();
                        moleculeSet.Add(reactant);
                        IReaction reaction = Mechanism.Initiate(moleculeSet, atomList, bondList);
                        if (reaction == null)
                        {
                            continue;
                        }
                        else
                        {
                            setOfReactions.Add(reaction);
                        }
                    }
                }
            }
            return(setOfReactions);
        }
コード例 #29
0
        public virtual void TestRemoveAllReactions()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();

            reactionSet.Add(reactionSet.Builder.NewReaction());
            reactionSet.Clear();
            Assert.AreEqual(0, reactionSet.Count);
        }
コード例 #30
0
        internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, bool isReverse, CheckReactantAtom checkReactantAtom, CheckAtom checkAtom, CheckBond checkBond)
        {
            CheckInitiateParams(reactants, agents);

            IReactionSet   setOfReactions = reactants.Builder.NewReactionSet();
            IAtomContainer reactant       = reactants[0];

            // if the parameter hasActiveCenter is not fixed yet, set the active centers
            IParameterReaction ipr = base.GetParameterClass(typeof(SetReactionCenter));

            if (ipr != null && !ipr.IsSetParameter)
            {
                SetActiveCenters(reactant, checkReactantAtom, checkAtom, checkBond);
            }

            foreach (var atomi in reactant.Atoms)
            {
                if (atomi.IsReactiveCenter && checkReactantAtom(reactant, atomi))
                {
                    foreach (var bondi in reactant.GetConnectedBonds(atomi))
                    {
                        if (bondi.IsReactiveCenter && checkBond(bondi))
                        {
                            IAtom atomj = bondi.GetOther(atomi);
                            if (atomj.IsReactiveCenter && checkAtom(atomj) && !reactant.GetConnectedSingleElectrons(atomj).Any())
                            {
                                IAtom[] atomList;
                                if (isReverse)
                                {
                                    atomList = new[] { atomj, atomi }
                                }
                                ;
                                else
                                {
                                    atomList = new[] { atomi, atomj }
                                };
                                var bondList = new[] { bondi };

                                IChemObjectSet <IAtomContainer> moleculeSet = reactant.Builder.NewChemObjectSet <IAtomContainer>();

                                moleculeSet.Add(reactant);
                                IReaction reaction = Mechanism.Initiate(moleculeSet, atomList, bondList);
                                if (reaction == null)
                                {
                                    continue;
                                }
                                else
                                {
                                    setOfReactions.Add(reaction);
                                }
                            }
                        }
                    }
                }
            }
            return(setOfReactions);
        }