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; }
public static IEnumerable <string> GetAllIDs(IReaction reaction) { if (reaction.Id != null) { yield return(reaction.Id); } var reactants = reaction.Reactants; for (int i = 0; i < reactants.Count; i++) { var mol = reactants[i]; foreach (var id in AtomContainerManipulator.GetAllIDs(mol)) { yield return(id); } } var products = reaction.Products; for (int i = 0; i < products.Count; i++) { var mol = products[i]; foreach (var id in AtomContainerManipulator.GetAllIDs(mol)) { yield return(id); } } yield break; }
public static IEnumerable <string> GetAllIDs <T>(IChemObjectSet <T> set) where T : IAtomContainer { if (set != null) { if (set.Id != null) { yield return(set.Id); } foreach (var atomContainer in set) { foreach (var id in AtomContainerManipulator.GetAllIDs(atomContainer)) { yield return(id); } } } yield break; }
public void TestNoDuplicateCreation() { var mol = new AtomContainer(); Atom atom1 = new Atom("C") { Id = "a1" }; Atom atom2 = new Atom("C"); mol.Atoms.Add(atom2); mol.Atoms.Add(atom1); IDCreator.CreateIDs(mol); Assert.AreEqual("a2", atom2.Id); var ids = AtomContainerManipulator.GetAllIDs(mol); Assert.AreEqual(3, ids.Count()); }
public void TestKeepingIDs() { var mol = new AtomContainer(); Atom atom = new Atom("C") { Id = "atom1" }; mol.Atoms.Add(atom); IDCreator.CreateIDs(mol); Assert.AreEqual("atom1", atom.Id); Assert.IsNotNull(mol.Id); var ids = AtomContainerManipulator.GetAllIDs(mol); Assert.AreEqual(2, ids.Count()); }
/// <summary> /// Labels the Atom's and Bond's in the AtomContainer using the a1, a2, b1, b2 /// scheme often used in CML. /// </summary> /// <seealso cref="CreateIDs(IChemObject)"/> private static void CreateIDsForAtomContainer(IAtomContainer container, List <string> tabuList) { if (tabuList == null) { tabuList = AtomContainerManipulator.GetAllIDs(container).ToList(); } if (null == container.Id) { // generate new ID and remember it atomContainerCount = SetId(ATOMCONTAINER_PREFIX, atomContainerCount, container, tabuList); } // the tabu list for the container should force singularity // within a container only! var internalTabuList = AtomContainerManipulator.GetAllIDs(container).ToList(); if (policy == UniquePolicy.Object) { // start atom and bond indices within a container set always from 1 atomCount = 0; bondCount = 0; } else { internalTabuList = tabuList; } foreach (var atom in container.Atoms) { if (null == atom.Id) { atomCount = SetId(ATOM_PREFIX, atomCount, atom, internalTabuList); } } foreach (var bond in container.Bonds) { if (null == bond.Id) { bondCount = SetId(BOND_PREFIX, bondCount, bond, internalTabuList); } } }
public void TestCreateIDs_IChemObject() { var mol = new AtomContainer(); Atom atom1 = new Atom("C"); Atom atom2 = new Atom("C"); mol.Atoms.Add(atom1); mol.Atoms.Add(atom2); Bond bond = new Bond(atom1, atom2); mol.Bonds.Add(bond); IDCreator.CreateIDs(mol); Assert.AreEqual("a1", atom1.Id); Assert.AreEqual("b1", bond.Id); var ids = AtomContainerManipulator.GetAllIDs(mol); Assert.AreEqual(4, ids.Count()); }