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]);
        }
        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"));
        }
        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());
        }
        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);
        }
Exemple #5
0
        public virtual void TestRemoveReaction_int()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();

            reactionSet.Add(reactionSet.Builder.NewReaction()); // 1
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 2
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 3
            Assert.AreEqual(3, reactionSet.Count);
            reactionSet.RemoveAt(1);
            Assert.AreEqual(2, reactionSet.Count);
            Assert.IsNotNull(reactionSet[0]);
            Assert.IsNotNull(reactionSet[1]);
        }
Exemple #6
0
        public virtual void TestGetReaction_int()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();

            reactionSet.Add(reactionSet.Builder.NewReaction()); // 1
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 2
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 3
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 4

            for (int i = 0; i < reactionSet.Count; i++)
            {
                Assert.IsNotNull(reactionSet[i]);
            }
        }
Exemple #7
0
        public virtual void TestAddReaction_IReaction()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();

            reactionSet.Add(reactionSet.Builder.NewReaction()); // 1
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 2
            IReaction third = reactionSet.Builder.NewReaction();

            reactionSet.Add(third);                             // 3
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 4

            Assert.AreEqual(4, reactionSet.Count);
            Assert.AreEqual(third, reactionSet[2]);
        }
Exemple #8
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 #9
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}.");
     }
 }
        /// <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);
        }
        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);
        }
Exemple #12
0
        public virtual void TestRemoveAllReactions()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();

            reactionSet.Add(reactionSet.Builder.NewReaction());
            reactionSet.Clear();
            Assert.AreEqual(0, reactionSet.Count);
        }
Exemple #13
0
        /// <summary>
        /// Get all Reactions object containing a Molecule from a set of Reactions.
        /// </summary>
        /// <param name="reactSet">The set of reaction to inspect</param>
        /// <param name="molecule">The molecule to find</param>
        /// <returns>The IReactionSet</returns>
        public static IReactionSet GetRelevantReactions(IReactionSet reactSet, IAtomContainer molecule)
        {
            IReactionSet newReactSet  = reactSet.Builder.NewReactionSet();
            IReactionSet reactSetProd = GetRelevantReactionsAsProduct(reactSet, molecule);

            foreach (var reaction in reactSetProd)
            {
                newReactSet.Add(reaction);
            }
            IReactionSet reactSetReact = GetRelevantReactionsAsReactant(reactSet, molecule);

            foreach (var reaction in reactSetReact)
            {
                newReactSet.Add(reaction);
            }
            return(newReactSet);
        }
        public void TestGetAllMolecules_IReactionSet2()
        {
            IReactionSet   reactionSet = builder.NewReactionSet();
            IReaction      reaction1   = builder.NewReaction();
            IAtomContainer molecule    = builder.NewAtomContainer();

            reaction1.Products.Add(molecule);
            reaction1.Reactants.Add(builder.NewAtomContainer());
            reactionSet.Add(reaction1);
            IReaction reaction2 = builder.NewReaction();

            reaction2.Products.Add(builder.NewAtomContainer());
            reaction2.Reactants.Add(molecule);
            reactionSet.Add(reaction2);

            Assert.AreEqual(3, ReactionSetManipulator.GetAllMolecules(reactionSet).Count);
        }
Exemple #15
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);
        }
Exemple #16
0
        public virtual void TestReactions()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();

            reactionSet.Add(reactionSet.Builder.NewReaction()); // 1
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 2
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 3
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 4

            IEnumerator <IReaction> reactionIter = reactionSet.GetEnumerator();

            Assert.IsNotNull(reactionIter);
            int count = 0;

            while (reactionIter.MoveNext())
            {
                Assert.IsNotNull(reactionIter.Current);
                ++count;
            }
            Assert.AreEqual(4, count);
        }
        internal IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents, string atomSymbol)
        {
            CheckInitiateParams(reactants, agents);

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

            IParameterReaction ipr = base.GetParameterClass(typeof(SetReactionCenter));

            if (ipr != null && !ipr.IsSetParameter)
            {
                SetActiveCenters(reactant);
            }

            if (AtomContainerManipulator.GetTotalCharge(reactant) > 0)
            {
                return(setOfReactions);
            }

            foreach (var atomi in reactant.Atoms)
            {
                if (atomi.IsReactiveCenter &&
                    (atomi.FormalCharge ?? 0) <= 0 &&
                    reactant.GetConnectedLonePairs(atomi).Any() &&
                    !reactant.GetConnectedSingleElectrons(atomi).Any())
                {
                    var atomList = new List <IAtom> {
                        atomi
                    };
                    IAtom atomH = reactant.Builder.NewAtom(atomSymbol);
                    atomH.FormalCharge = 1;
                    atomList.Add(atomH);

                    var moleculeSet = reactant.Builder.NewAtomContainerSet();
                    moleculeSet.Add(reactant);
                    IAtomContainer adduct = reactant.Builder.NewAtomContainer();
                    adduct.Atoms.Add(atomH);
                    moleculeSet.Add(adduct);

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

            return(setOfReactions);
        }
Exemple #18
0
        public virtual void TestRemoveReaction_IReaction()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();
            IReaction    reaction    = reactionSet.Builder.NewReaction();

            reaction.Id = "1";
            reactionSet.Add(reaction);
            IReaction relevantReaction = reactionSet.Builder.NewReaction();

            relevantReaction.Id = "2";
            reactionSet.Add(relevantReaction);
            Assert.AreEqual(2, reactionSet.Count);
            reactionSet.Remove(relevantReaction);
            Assert.AreEqual(1, reactionSet.Count);
            Assert.AreEqual("1", reactionSet[0].Id);
            reactionSet.Add(relevantReaction);
            reactionSet.Add(relevantReaction);
            Assert.AreEqual(3, reactionSet.Count);
            reactionSet.Remove(relevantReaction);
            Assert.AreEqual(1, reactionSet.Count);
            Assert.AreEqual("1", reactionSet[0].Id);
        }
Exemple #19
0
        public override void TestStateChanged_IChemObjectChangeEvent()
        {
            ChemObjectListenerImpl listener   = new ChemObjectListenerImpl();
            IReactionSet           chemObject = (IReactionSet)NewChemObject();

            chemObject.Listeners.Add(listener);

            chemObject.Add(chemObject.Builder.NewReaction());
            Assert.IsTrue(listener.Changed);

            listener.Reset();
            Assert.IsFalse(listener.Changed);
        }
Exemple #20
0
        public virtual void TestClone_Reaction()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();

            reactionSet.Add(reactionSet.Builder.NewReaction()); // 1
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 2
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 3
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 4

            IReactionSet clone = (IReactionSet)reactionSet.Clone();

            Assert.AreEqual(reactionSet.Count, clone.Count);
            for (int f = 0; f < reactionSet.Count; f++)
            {
                for (int g = 0; g < clone.Count; g++)
                {
                    Assert.IsNotNull(reactionSet[f]);
                    Assert.IsNotNull(clone[g]);
                    Assert.AreNotSame(reactionSet[f], clone[g]);
                }
            }
        }
        /// <summary>
        /// Get all IReaction's object from a given IReactionScheme.
        /// </summary>
        /// <param name="scheme">The IReactionScheme to extract</param>
        /// <returns>The IReactionSet</returns>
        public static IReactionSet GetAllReactions(IReactionScheme scheme)
        {
            IReactionSet reactionSet = scheme.Builder.NewReactionSet();

            // A ReactionScheme can contain other IRreactionSet objects
            if (scheme.Schemes.Count != 0)
            {
                foreach (var schemeInt in scheme.Schemes)
                {
                    foreach (var reaction in GetAllReactions(schemeInt))
                    {
                        reactionSet.Add(reaction);
                    }
                }
            }
            foreach (var reaction in scheme.Reactions)
            {
                reactionSet.Add(reaction);
            }

            return(reactionSet);
        }
        public void TestCalculateBounds_IReactionSet_SingleAtom()
        {
            IAtomContainer container = new AtomContainer();

            container.Atoms.Add(container.Builder.NewAtom("C"));
            IReaction reaction = container.Builder.NewReaction();

            reaction.Reactants.Add(container.Builder.NewAtomContainer(container));
            IReactionSet set = container.Builder.NewReactionSet();

            set.Add(reaction);
            BoundsCalculator.CalculateBounds(set);
        }
Exemple #23
0
        public virtual void TestIsEmpty()
        {
            IReactionSet set = (IReactionSet)NewChemObject();

            Assert.IsTrue(set.IsEmpty(), "new reaction set should be empty");

            set.Add(set.Builder.NewReaction());

            Assert.IsFalse(set.IsEmpty(), "reaction set with a single reaction should not be empty");

            set.Clear();

            Assert.IsTrue(set.IsEmpty(), "reaction set with all reactions removed should be empty");
        }
Exemple #24
0
        public virtual void TestStateChanged_EventPropagation_ReactionSet()
        {
            ChemObjectListenerImpl listener = new ChemObjectListenerImpl();
            IChemModel chemObject = (IChemModel)NewChemObject();
            chemObject.Listeners.Add(listener);

            IReactionSet reactionSet = chemObject.Builder.NewReactionSet();
            chemObject.ReactionSet = reactionSet;
            Assert.IsTrue(listener.Changed);
            // reset the listener
            listener.Reset();
            Assert.IsFalse(listener.Changed);
            // changing the set should trigger a change event in the IChemModel
            reactionSet.Add(chemObject.Builder.NewReaction());
            Assert.IsTrue(listener.Changed);
        }
Exemple #25
0
        /// <summary>
        /// Get all Reactions object containing a Molecule as a Product from a set of
        /// Reactions.
        /// </summary>
        /// <param name="reactSet">The set of reaction to inspect</param>
        /// <param name="molecule">The molecule to find as a product</param>
        /// <returns>The IReactionSet</returns>
        public static IReactionSet GetRelevantReactionsAsProduct(IReactionSet reactSet, IAtomContainer molecule)
        {
            IReactionSet newReactSet = reactSet.Builder.NewReactionSet();

            foreach (var reaction in reactSet)
            {
                foreach (var atomContainer in reaction.Products)
                {
                    if (atomContainer.Equals(molecule))
                    {
                        newReactSet.Add(reaction);
                    }
                }
            }
            return(newReactSet);
        }
        /// <summary>
        ///  Initiate process.
        ///  It is needed to call the addExplicitHydrogensToSatisfyValency
        ///  from the class tools.HydrogenAdder.
        /// </summary>
        /// <param name="reactants">Reactants of the reaction</param>
        /// <param name="agents">Agents of the reaction (Must be in this case null)</param>
        /// <exception cref="CDKException"> Description of the Exception</exception>
        public IReactionSet Initiate(IChemObjectSet <IAtomContainer> reactants, IChemObjectSet <IAtomContainer> agents)
        {
            Debug.WriteLine("initiate reaction: ElectronImpactNBEReaction");

            if (reactants.Count != 1)
            {
                throw new CDKException("ElectronImpactNBEReaction only expects one reactant");
            }
            if (agents != null)
            {
                throw new CDKException("ElectronImpactNBEReaction don't expects 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);
            }
            foreach (var atom in reactant.Atoms)
            {
                if (atom.IsReactiveCenter && reactant.GetConnectedLonePairs(atom).Any() &&
                    !reactant.GetConnectedSingleElectrons(atom).Any())
                {
                    var atomList = new List <IAtom>
                    {
                        atom
                    };
                    IChemObjectSet <IAtomContainer> moleculeSet = reactant.Builder.NewAtomContainerSet();
                    moleculeSet.Add(reactant);
                    IReaction reaction = Mechanism.Initiate(moleculeSet, atomList, null);
                    if (reaction == null)
                    {
                        continue;
                    }
                    else
                    {
                        setOfReactions.Add(reaction);
                    }
                }
            }
            return(setOfReactions);
        }
Exemple #27
0
        public virtual void TestGetReactionCount()
        {
            IReactionSet reactionSet = (IReactionSet)NewChemObject();

            reactionSet.Add(reactionSet.Builder.NewReaction()); // 1
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 2
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 3
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 4
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 5
            reactionSet.Add(reactionSet.Builder.NewReaction()); // 6 (force growing)
            Assert.AreEqual(6, reactionSet.Count);
        }
Exemple #28
0
        public virtual void TestStateChanged_ButNotAfterRemoval_ReactionSet()
        {
            ChemObjectListenerImpl listener = new ChemObjectListenerImpl();
            IChemModel chemObject = (IChemModel)NewChemObject();
            chemObject.Listeners.Add(listener);

            IReactionSet reactionSet = chemObject.Builder.NewReactionSet();
            chemObject.ReactionSet = reactionSet;
            Assert.IsTrue(listener.Changed);
            // remove the set from the IChemModel
            chemObject.ReactionSet = null;
            // reset the listener
            listener.Reset();
            Assert.IsFalse(listener.Changed);
            // changing the set must *not* trigger a change event in the IChemModel
            reactionSet.Add(chemObject.Builder.NewReaction());
            Assert.IsFalse(listener.Changed);
        }
Exemple #29
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");
        }
        /// <summary>
        /// Extract reactions from a IReactionSet which at least one reactant is existing
        /// as precursor given a IReaction
        /// </summary>
        /// <param name="reaction">The IReaction to analyze</param>
        /// <param name="reactionSet">The IReactionSet to inspect</param>
        /// <returns>A IReactionSet containing the reactions</returns>
        private static IReactionSet ExtractSubsequentReaction(IReaction reaction, IReactionSet reactionSet)
        {
            IReactionSet reactConSet = reaction.Builder.NewReactionSet();

            foreach (var reactant in reaction.Products)
            {
                foreach (var reactionInt in reactionSet)
                {
                    foreach (var precursor in reactionInt.Reactants)
                    {
                        if (reactant.Equals(precursor))
                        {
                            reactConSet.Add(reactionInt);
                        }
                    }
                }
            }
            return(reactConSet);
        }