Exemplo n.º 1
0
 public static void PerceiveDativeBonds(IReaction reaction)
 {
     foreach (var mol in ReactionManipulator.GetAllMolecules(reaction))
     {
         AtomContainerManipulator.PerceiveDativeBonds(mol);
     }
 }
Exemplo n.º 2
0
 public static void RemoveAtomAndConnectedElectronContainers(IReactionSet set, IAtom atom)
 {
     foreach (var reaction in set)
     {
         ReactionManipulator.RemoveAtomAndConnectedElectronContainers(reaction, atom);
     }
 }
Exemplo n.º 3
0
 public static void SetAtomProperties(IReactionSet set, string propKey, object propVal)
 {
     foreach (var reaction in set)
     {
         ReactionManipulator.SetAtomProperties(reaction, propKey, propVal);
     }
 }
Exemplo n.º 4
0
        public void TestGetMappedChemObject_IReaction_IBond()
        {
            var            builder  = ChemObjectBuilder.Instance;
            IReaction      reaction = builder.NewReaction();
            IAtomContainer reactant = CDK.SmilesParser.ParseSmiles("[C+]-C=C");
            IAtomContainer product  = CDK.SmilesParser.ParseSmiles("C=C=C");

            IMapping mapping = builder.NewMapping(reactant.Atoms[0], product.Atoms[0]);

            reaction.Mappings.Add(mapping);
            mapping = builder.NewMapping(reactant.Bonds[0], product.Bonds[0]);
            reaction.Mappings.Add(mapping);
            mapping = builder.NewMapping(reactant.Bonds[1], product.Bonds[1]);
            reaction.Mappings.Add(mapping);

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

            IBond mappedBond = (IBond)ReactionManipulator.GetMappedChemObject(reaction, reactant.Bonds[0]);

            Assert.AreEqual(mappedBond, product.Bonds[0]);

            mappedBond = (IBond)ReactionManipulator.GetMappedChemObject(reaction, product.Bonds[1]);
            Assert.AreEqual(mappedBond, reactant.Bonds[1]);
        }
Exemplo n.º 5
0
 public static void RemoveElectronContainer(IReactionSet set, IElectronContainer electrons)
 {
     foreach (var reaction in set)
     {
         ReactionManipulator.RemoveElectronContainer(reaction, electrons);
     }
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public void TestGetRelevantAtomContainer_IReaction_IBond()
 {
     foreach (var container in ReactionManipulator.GetAllAtomContainers(reaction))
     {
         IBond aBond = container.Bonds[0];
         Assert.AreEqual(container, ReactionManipulator.GetRelevantAtomContainer(reaction, aBond));
     }
 }
Exemplo n.º 8
0
 public void TestGetRelevantAtomContainer_IReaction_IAtom()
 {
     foreach (var container in ReactionManipulator.GetAllAtomContainers(reaction))
     {
         IAtom anAtom = container.Atoms[0];
         Assert.AreEqual(container, ReactionManipulator.GetRelevantAtomContainer(reaction, anAtom));
     }
 }
Exemplo n.º 9
0
        public void TestGetAllChemObjects_IReactionSet()
        {
            var allObjects = ReactionManipulator.GetAllChemObjects(reaction);

            // does not recurse beyond the IAtomContainer, so:
            // reaction, 2xreactant, 1xproduct
            Assert.AreEqual(4, allObjects.Count());
        }
Exemplo n.º 10
0
        public static int GetBondCount(IReactionSet set)
        {
            int count = 0;

            foreach (var iReaction in set)
            {
                count += ReactionManipulator.GetBondCount(iReaction);
            }
            return(count);
        }
Exemplo n.º 11
0
 public void TestSetAtomProperties_IReactionSet_Object_Object()
 {
     ReactionManipulator.SetAtomProperties(reaction, "test", "ok");
     foreach (var container in ReactionManipulator.GetAllAtomContainers(reaction))
     {
         foreach (var atom in container.Atoms)
         {
             Assert.IsNotNull(atom.GetProperty <string>("test"));
             Assert.AreEqual("ok", atom.GetProperty <string>("test"));
         }
     }
 }
Exemplo n.º 12
0
        public void TestGetAllReactants_IReaction()
        {
            var       builder  = ChemObjectBuilder.Instance;
            IReaction reaction = builder.NewReaction();

            reaction.Reactants.Add(builder.NewAtomContainer());
            reaction.Reactants.Add(builder.NewAtomContainer());
            reaction.Reactants.Add(builder.NewAtomContainer());
            reaction.Products.Add(builder.NewAtomContainer());
            reaction.Products.Add(builder.NewAtomContainer());
            Assert.AreEqual(2, ReactionManipulator.GetAllProducts(reaction).Count());
        }
Exemplo n.º 13
0
        public void InliningReactionsWithRadicals()
        {
            IChemObjectBuilder bldr     = ChemObjectBuilder.Instance;
            SmilesParser       smipar   = new SmilesParser(bldr);
            IReaction          reaction = smipar.ParseReactionSmiles("[CH2]CO.CC(=O)O>[H+]>CCOC(=O)C.O |^1:0| ethyl esterification");
            SmilesGenerator    smigen   = new SmilesGenerator(SmiFlavors.CxSmiles);
            // convert to molecule
            IAtomContainer mol = ReactionManipulator.ToMolecule(reaction);

            Assert.AreEqual("[CH2]CO.CC(=O)O.[H+].CCOC(=O)C.O |^1:0|", smigen.Create(mol));
            Assert.AreEqual("[CH2]CO.CC(=O)O>[H+]>CCOC(=O)C.O |^1:0|", smigen.CreateReactionSMILES(ReactionManipulator.ToReaction(mol)));
        }
Exemplo n.º 14
0
 public static IReaction GetRelevantReaction(IReactionSet set, IAtom atom)
 {
     foreach (var reaction in set)
     {
         var container = ReactionManipulator.GetRelevantAtomContainer(reaction, atom);
         if (container != null)
         { // a match!
             return(reaction);
         }
     }
     return(null);
 }
Exemplo n.º 15
0
 public static IAtomContainer GetRelevantAtomContainer(IReactionSet set, IBond bond)
 {
     foreach (var reaction in set)
     {
         var container = ReactionManipulator.GetRelevantAtomContainer(reaction, bond);
         if (container != null)
         { // a match!
             return(container);
         }
     }
     return(null);
 }
Exemplo n.º 16
0
        public static List <IChemObject> GetAllChemObjects(IReactionSet set)
        {
            List <IChemObject> list = new List <IChemObject>
            {
                set
            };

            foreach (var reaction in set)
            {
                list.AddRange(ReactionManipulator.GetAllChemObjects(reaction));
            }
            return(list);
        }
Exemplo n.º 17
0
        public static IEnumerable <IChemObject> GetAllChemObjects(IReactionSet set)
        {
            yield return(set);

            foreach (var reaction in set)
            {
                foreach (var o in ReactionManipulator.GetAllChemObjects(reaction))
                {
                    yield return(o);
                }
            }
            yield break;
        }
Exemplo n.º 18
0
 public static IEnumerable <string> GetAllIDs(IReactionSet set)
 {
     if (set.Id != null)
     {
         yield return(set.Id);
     }
     foreach (var reaction in set)
     {
         foreach (var e in ReactionManipulator.GetAllIDs(reaction))
         {
             yield return(e);
         }
     }
     yield break;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Get all molecule objects from a set of Reactions given a <see cref="IAtomContainerSet"/> to add.
        /// </summary>
        /// <param name="scheme">The set of reaction to inspect</param>
        /// <param name="molSet">The set of molecules to be added</param>
        /// <returns>All molecules</returns>
        public static IChemObjectSet <IAtomContainer> GetAllAtomContainers(IReactionScheme scheme, IChemObjectSet <IAtomContainer> molSet)
        {
            // A ReactionScheme can contain other IRreactionSet objects
            foreach (var rm in scheme.Schemes)
            {
                foreach (var ac in GetAllAtomContainers(rm, molSet))
                {
                    bool contain = false;
                    foreach (var atomContainer in molSet)
                    {
                        if (atomContainer.Equals(ac))
                        {
                            contain = true;
                            break;
                        }
                    }
                    if (!contain)
                    {
                        molSet.Add((IAtomContainer)(ac));
                    }
                }
            }
            foreach (var reaction in scheme.Reactions)
            {
                var newAtomContainerSet = ReactionManipulator.GetAllAtomContainers(reaction);
                foreach (var ac in newAtomContainerSet)
                {
                    bool contain = false;
                    foreach (var atomContainer in molSet)
                    {
                        if (atomContainer.Equals(ac))
                        {
                            contain = true;
                            break;
                        }
                    }
                    if (!contain)
                    {
                        molSet.Add(ac);
                    }
                }
            }

            return(molSet);
        }
Exemplo n.º 20
0
        public void TestReverse_IReaction()
        {
            Reaction reaction = new Reaction {
                Direction = ReactionDirection.Backward
            };
            IAtomContainer water = new AtomContainer();

            reaction.Reactants.Add(water, 3.0);
            reaction.Reactants.Add(new AtomContainer());
            reaction.Products.Add(new AtomContainer());

            Reaction reversedReaction = (Reaction)ReactionManipulator.Reverse(reaction);

            Assert.AreEqual(ReactionDirection.Forward, reversedReaction.Direction);
            Assert.AreEqual(2, reversedReaction.Products.Count);
            Assert.AreEqual(1, reversedReaction.Reactants.Count);
            Assert.AreEqual(3.0, reversedReaction.Products.GetMultiplier(water).Value, 0.00001);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Get all ID of this IReactionSet.
        /// </summary>
        /// <param name="scheme">The IReactionScheme to analyze</param>
        /// <returns>A List with all ID</returns>
        public static IEnumerable <string> GetAllIDs(IReactionScheme scheme)
        {
            var IDlist = new List <string>();

            if (scheme.Id != null)
            {
                IDlist.Add(scheme.Id);
            }
            foreach (var reaction in scheme.Reactions)
            {
                IDlist.AddRange(ReactionManipulator.GetAllIDs(reaction));
            }
            if (scheme.Schemes.Count != 0)
            {
                foreach (var rs in scheme.Schemes)
                {
                    IDlist.AddRange(GetAllIDs(rs));
                }
            }
            return(IDlist);
        }
Exemplo n.º 22
0
        public void TestRemoveAtomAndConnectedElectronContainers_IReaction_IAtom()
        {
            var            builder  = ChemObjectBuilder.Instance;
            IReaction      reaction = builder.NewReaction();
            IAtomContainer mol      = builder.NewAtomContainer();

            mol.Atoms.Add(builder.NewAtom("C"));
            mol.Atoms.Add(builder.NewAtom("C"));
            mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single);
            Assert.AreEqual(2, mol.Atoms.Count);
            Assert.AreEqual(1, mol.Bonds.Count);
            reaction.Reactants.Add(mol);
            reaction.Reactants.Add(builder.NewAtomContainer());
            reaction.Reactants.Add(builder.NewAtomContainer());
            reaction.Products.Add(builder.NewAtomContainer());
            reaction.Products.Add(builder.NewAtomContainer());
            ReactionManipulator.RemoveAtomAndConnectedElectronContainers(reaction, mol.Atoms[0]);

            Assert.AreEqual(1, mol.Atoms.Count);
            Assert.AreEqual(0, mol.Bonds.Count);
        }
Exemplo n.º 23
0
        public void TestGetAllIDs_IReaction()
        {
            Reaction reaction = new Reaction()
            {
                Id = "r1"
            };
            IAtomContainer water = new AtomContainer {
                Id = "m1"
            };
            Atom oxygen = new Atom("O")
            {
                Id = "a1"
            };

            water.Atoms.Add(oxygen);
            reaction.Reactants.Add(water);
            reaction.Products.Add(water);

            var ids = ReactionManipulator.GetAllIDs(reaction);

            Assert.IsNotNull(ids);
            Assert.AreEqual(5, ids.Count());
        }
Exemplo n.º 24
0
 public void TestGetAtomCount_IReaction()
 {
     Assert.AreEqual(19, ReactionManipulator.GetAtomCount(reaction));
 }
Exemplo n.º 25
0
 public void TestGetBondCount_IReaction()
 {
     Assert.AreEqual(18, ReactionManipulator.GetBondCount(reaction));
 }
Exemplo n.º 26
0
 public void TestGetAllAtomContainers_IReaction()
 {
     Assert.AreEqual(3, ReactionManipulator.GetAllAtomContainers(reaction).Count());
 }