public virtual void TestSort_BrokenComparator()
        {
            IChemObjectSet <T> set = (IChemObjectSet <T>)NewChemObject();

            IChemObjectBuilder builder = set.Builder;

            T a = NewContainerObject();
            T b = NewContainerObject();

            a.Atoms.Add(builder.NewAtom("C"));
            a.Atoms.Add(builder.NewAtom("C"));
            b.Atoms.Add(builder.NewAtom("C"));

            set.Add(a);
            set.Add(b);

            // this comparator is deliberately broken but serves for the test
            //  - null should be a high value (Interger.MAX)
            //  - also, avoid boxed primitives in comparators
            set.Sort(new ComparerByBroken());

            // despite null being low, the two atom containers should
            // still be in the first slot
            Assert.IsNotNull(set[0]);
            Assert.IsNotNull(set[1]);
            Assert.IsTrue(set.Count == 2 || set[2] == null);
        }
Ejemplo n.º 2
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);
 }
        public virtual void TestGetAtomContainerCount()
        {
            IChemObjectSet <T> som = (IChemObjectSet <T>)NewChemObject();

            som.Add(NewContainerObject());
            som.Add(NewContainerObject());
            som.Add(NewContainerObject());

            Assert.AreEqual(3, som.Count);
        }
Ejemplo n.º 4
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)
        {
            IChemObjectSet <IAtomContainer> 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);
        }
Ejemplo n.º 5
0
        public virtual void TestSetReactants_IAtomContainerSet()
        {
            IReaction      reaction                   = (IReaction)NewChemObject();
            IAtomContainer sodiumhydroxide            = reaction.Builder.NewAtomContainer();
            IAtomContainer aceticAcid                 = reaction.Builder.NewAtomContainer();
            IAtomContainer water                      = reaction.Builder.NewAtomContainer();
            IChemObjectSet <IAtomContainer> reactants = reaction.Builder.NewAtomContainerSet();

            reactants.Add(sodiumhydroxide);
            reactants.Add(aceticAcid);
            reactants.Add(water);
            reaction.Reactants.AddRange(reactants);
            Assert.AreEqual(3, reaction.Reactants.Count);

            Assert.AreEqual(1.0, reaction.Reactants.GetMultiplier(aceticAcid).Value, 0.00001);
        }
        /// <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);
        }
 public void SetUp()
 {
     mol1                             = builder.NewAtomContainer();
     atomInMol1                       = builder.NewAtom("Cl");
     atomInMol1.Charge                = -1.0;
     atomInMol1.FormalCharge          = -1;
     atomInMol1.ImplicitHydrogenCount = 1;
     mol1.Atoms.Add(atomInMol1);
     mol1.Atoms.Add(builder.NewAtom("Cl"));
     bondInMol1 = builder.NewBond(atomInMol1, mol1.Atoms[1]);
     mol1.Bonds.Add(bondInMol1);
     mol2       = builder.NewAtomContainer();
     atomInMol2 = builder.NewAtom("O");
     atomInMol2.ImplicitHydrogenCount = 2;
     mol2.Atoms.Add(atomInMol2);
     som.Add(mol1);
     som.Add(mol2);
 }