Esempio n. 1
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)
            {
                var moleculeSet = chemModel.MoleculeSet;
                result = MoleculeSetManipulator.GetRelevantAtomContainer(moleculeSet, atom);
                if (result != null)
                {
                    return(result);
                }
            }
            if (chemModel.ReactionSet != null)
            {
                var 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.");
        }
Esempio n. 2
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)
        {
            var crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.Contains(electrons))
                {
                    crystal.Remove(electrons);
                }
                return;
            }
            var moleculeSet = chemModel.MoleculeSet;

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

            if (reactionSet != null)
            {
                ReactionSetManipulator.RemoveElectronContainer(reactionSet, electrons);
            }
        }
        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());
        }
Esempio n. 6
0
        public static IEnumerable <string> GetAllIDs(IChemModel chemModel)
        {
            if (chemModel.Id != null)
            {
                yield return(chemModel.Id);
            }
            var crystal = chemModel.Crystal;

            if (crystal != null)
            {
                foreach (var e in AtomContainerManipulator.GetAllIDs(crystal))
                {
                    yield return(e);
                }
            }
            var moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                foreach (var e in MoleculeSetManipulator.GetAllIDs(moleculeSet))
                {
                    yield return(e);
                }
            }
            var reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                foreach (var e in ReactionSetManipulator.GetAllIDs(reactionSet))
                {
                    yield return(e);
                }
            }
            yield break;
        }
Esempio n. 7
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)
        {
            var crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.Contains(atom))
                {
                    crystal.RemoveAtom(atom);
                }
                return;
            }
            var moleculeSet = chemModel.MoleculeSet;

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

            if (reactionSet != null)
            {
                ReactionSetManipulator.RemoveAtomAndConnectedElectronContainers(reactionSet, atom);
            }
        }
        public void TestGetAllChemObjects_IReactionSet()
        {
            var allObjects = ReactionSetManipulator.GetAllChemObjects(set);

            // does not recurse beyond the IAtomContainer, so:
            // set, reaction, 2xreactant, 1xproduct
            Assert.AreEqual(5, allObjects.Count());
        }
 public void TestGetRelevantReaction_IReactionSet_IAtom()
 {
     foreach (var container in ReactionSetManipulator.GetAllAtomContainers(set))
     {
         IAtom anAtom = container.Atoms[0];
         Assert.AreEqual(set[0], ReactionSetManipulator.GetRelevantReaction(set, anAtom));
     }
 }
 public void TestGetRelevantAtomContainer_IReactionSet_IBond()
 {
     foreach (var container in ReactionSetManipulator.GetAllAtomContainers(set))
     {
         IBond aBond = container.Bonds[0];
         Assert.AreEqual(container, ReactionSetManipulator.GetRelevantAtomContainer(set, aBond));
     }
 }
        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);
        }
Esempio n. 12
0
        /// <summary>
        /// Retrieves the first IReaction containing a given IAtom from an
        /// IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <param name="atom">The IAtom object to search.</param>
        /// <returns>The IAtomContainer object found, null if none is found.</returns>
        public static IReaction GetRelevantReaction(IChemModel chemModel, IAtom atom)
        {
            IReaction reaction = null;

            if (chemModel.ReactionSet != null)
            {
                IReactionSet reactionSet = chemModel.ReactionSet;
                reaction = ReactionSetManipulator.GetRelevantReaction(reactionSet, atom);
            }
            return(reaction);
        }
Esempio n. 13
0
        /// <summary>
        /// Returns all the AtomContainer's of a ChemModel.
        /// </summary>
        public static IEnumerable <IAtomContainer> GetAllAtomContainers(IChemModel chemModel)
        {
            var moleculeSet = chemModel.Builder.NewAtomContainerSet();

            if (chemModel.MoleculeSet != null)
            {
                moleculeSet.AddRange(chemModel.MoleculeSet);
            }
            if (chemModel.ReactionSet != null)
            {
                moleculeSet.AddRange(ReactionSetManipulator.GetAllMolecules(chemModel.ReactionSet));
            }
            return(MoleculeSetManipulator.GetAllAtomContainers(moleculeSet));
        }
 public void TestSetAtomProperties_IReactionSet_Object_Object()
 {
     ReactionSetManipulator.SetAtomProperties(set, "test", "ok");
     foreach (var container in ReactionSetManipulator.GetAllAtomContainers(set))
     {
         foreach (var atom in container.Atoms)
         {
             Assert.IsNotNull(atom.GetProperty <string>("test"));
             Assert.AreEqual("ok", atom.GetProperty <string>("test"));
         }
     }
     // reset things
     SetUp();
 }
Esempio n. 15
0
 /// <summary>
 /// Sets the AtomProperties of all Atoms inside an IChemModel.
 /// </summary>
 /// <param name="chemModel">The IChemModel object.</param>
 /// <param name="propKey">The key of the property.</param>
 /// <param name="propVal">The value of the property.</param>
 public static void SetAtomProperties(IChemModel chemModel, string propKey, object propVal)
 {
     if (chemModel.MoleculeSet != null)
     {
         MoleculeSetManipulator.SetAtomProperties(chemModel.MoleculeSet, propKey, propVal);
     }
     if (chemModel.ReactionSet != null)
     {
         ReactionSetManipulator.SetAtomProperties(chemModel.ReactionSet, propKey, propVal);
     }
     if (chemModel.Crystal != null)
     {
         AtomContainerManipulator.SetAtomProperties(chemModel.Crystal, propKey, propVal);
     }
 }
        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);
        }
Esempio n. 17
0
        /// <summary>
        /// Retrieves the first IAtomContainer containing a given IBond from an
        /// IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <param name="bond">The IBond object to search.</param>
        /// <returns>The IAtomContainer object found, null if none is found.</returns>
        public static IAtomContainer GetRelevantAtomContainer(IChemModel chemModel, IBond bond)
        {
            IAtomContainer result = null;

            if (chemModel.MoleculeSet != null)
            {
                var moleculeSet = chemModel.MoleculeSet;
                result = MoleculeSetManipulator.GetRelevantAtomContainer(moleculeSet, bond);
                if (result != null)
                {
                    return(result);
                }
            }
            if (chemModel.ReactionSet != null)
            {
                var reactionSet = chemModel.ReactionSet;
                return(ReactionSetManipulator.GetRelevantAtomContainer(reactionSet, bond));
            }
            // This should never happen.
            return(null);
        }
Esempio n. 18
0
        /// <summary>
        /// Retrieve a List of all ChemObject objects within an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <returns>A List of all ChemObjects inside.</returns>
        public static List <IChemObject> GetAllChemObjects(IChemModel chemModel)
        {
            var list = new List <IChemObject>();
            // list.Add(chemModel); // only add ChemObjects contained within
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                list.Add(crystal);
            }
            var moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                list.Add(moleculeSet);
                var current = MoleculeSetManipulator.GetAllChemObjects(moleculeSet);
                foreach (var chemObject in current)
                {
                    if (!list.Contains(chemObject))
                    {
                        list.Add(chemObject);
                    }
                }
            }
            var reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                list.Add(reactionSet);
                var current = ReactionSetManipulator.GetAllChemObjects(reactionSet);
                foreach (var chemObject in current)
                {
                    if (!list.Contains(chemObject))
                    {
                        list.Add(chemObject);
                    }
                }
            }
            return(list);
        }
Esempio n. 19
0
        /// <summary>
        /// Get the total number of bonds inside an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <returns>The number of Bond object inside.</returns>
        public static int GetBondCount(IChemModel chemModel)
        {
            int count   = 0;
            var crystal = chemModel.Crystal;

            if (crystal != null)
            {
                count += crystal.Bonds.Count;
            }
            var moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                count += MoleculeSetManipulator.GetBondCount(moleculeSet);
            }
            var reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                count += ReactionSetManipulator.GetBondCount(reactionSet);
            }
            return(count);
        }
        public void TestRemoveAtomAndConnectedElectronContainers_IReactionSet_IAtom()
        {
            IReactionSet set      = builder.NewReactionSet();
            IReaction    reaction = builder.NewReaction();

            set.Add(reaction);
            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());
            ReactionSetManipulator.RemoveAtomAndConnectedElectronContainers(set, mol.Atoms[0]);

            Assert.AreEqual(1, mol.Atoms.Count);
            Assert.AreEqual(0, mol.Bonds.Count);
        }
Esempio n. 21
0
        /// <summary>
        /// Get the total number of bonds inside an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <returns>The number of Bond object inside.</returns>
        public static int GetBondCount(IChemModel chemModel)
        {
            int      count   = 0;
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                count += crystal.Bonds.Count;
            }
            IChemObjectSet <IAtomContainer> moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                count += MoleculeSetManipulator.GetBondCount(moleculeSet);
            }
            IReactionSet reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                count += ReactionSetManipulator.GetBondCount(reactionSet);
            }
            return(count);
        }
 public void TestGetBondCount_IReactionSet()
 {
     Assert.AreEqual(18, ReactionSetManipulator.GetBondCount(set));
 }
 public void TestGetAllAtomContainers_IReactionSet()
 {
     Assert.AreEqual(3, ReactionSetManipulator.GetAllAtomContainers(set).Count());
 }