/// <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."); }
/// <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); } }
/// <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 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 void TestSetAtomProperties_IAtomContainerSet_Object_Object() { string key = "key"; string value = "value"; MoleculeSetManipulator.SetAtomProperties(som, key, value); Assert.AreEqual(value, atomInMol1.GetProperty <string>(key)); Assert.AreEqual(value, atomInMol2.GetProperty <string>(key)); }
public void TestGetRelevantAtomContainer_IAtomContainerSet_IAtom() { IAtomContainer ac1 = MoleculeSetManipulator.GetRelevantAtomContainer(som, atomInMol1); Assert.AreEqual(mol1, ac1); IAtomContainer ac2 = MoleculeSetManipulator.GetRelevantAtomContainer(som, atomInMol2); Assert.AreEqual(mol2, ac2); }
public void TestGetAllIDs_IAtomContainerSet() { som.Id = "som"; mol2.Id = "mol"; atomInMol2.Id = "atom"; bondInMol1.Id = "bond"; var list = MoleculeSetManipulator.GetAllIDs(som); Assert.AreEqual(4, list.Count()); }
public static IAtomContainer GetRelevantAtomContainer(IReaction reaction, IBond bond) { var result = MoleculeSetManipulator.GetRelevantAtomContainer(reaction.Reactants, bond); if (result != null) { return(result); } return(MoleculeSetManipulator.GetRelevantAtomContainer(reaction.Products, bond)); }
/// <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)); }
/// <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 TestRemoveElectronContainer_IAtomContainerSet_IElectronContainer() { IChemObjectSet <IAtomContainer> ms = new ChemObjectSet <IAtomContainer>(); var mol = new AtomContainer(); mol.Atoms.Add(new Atom("O")); mol.Atoms.Add(new Atom("O")); mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Double); IBond bond = mol.Bonds[0]; ms.Add(mol); IBond otherBond = new Bond(new Atom(), new Atom()); MoleculeSetManipulator.RemoveElectronContainer(ms, otherBond); Assert.AreEqual(1, MoleculeSetManipulator.GetBondCount(ms)); MoleculeSetManipulator.RemoveElectronContainer(ms, bond); Assert.AreEqual(0, MoleculeSetManipulator.GetBondCount(ms)); }
public void TestRemoveAtomAndConnectedElectronContainers_IAtomContainerSet_IAtom() { IChemObjectSet <IAtomContainer> ms = new ChemObjectSet <IAtomContainer>(); var mol = new AtomContainer(); mol.Atoms.Add(new Atom("O")); mol.Atoms.Add(new Atom("O")); mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Double); IAtom atom = mol.Atoms[0]; ms.Add(mol); IAtom otherAtom = new Atom("O"); MoleculeSetManipulator.RemoveAtomAndConnectedElectronContainers(ms, otherAtom); Assert.AreEqual(1, MoleculeSetManipulator.GetBondCount(ms)); Assert.AreEqual(2, MoleculeSetManipulator.GetAtomCount(ms)); MoleculeSetManipulator.RemoveAtomAndConnectedElectronContainers(ms, atom); Assert.AreEqual(0, MoleculeSetManipulator.GetBondCount(ms)); Assert.AreEqual(1, MoleculeSetManipulator.GetAtomCount(ms)); }
/// <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); }
/// <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); }
/// <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); }
/// <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_IAtomContainerSet() { int count = MoleculeSetManipulator.GetBondCount(som); Assert.AreEqual(1, count); }
public void TestGetAllChemObjects_IAtomContainerSet() { var list = MoleculeSetManipulator.GetAllChemObjects(som); Assert.AreEqual(3, list.Count()); // only MoleculeSets and AtomContainers at the moment (see source code comment) }
public void TestGetRelevantAtomContainer_IAtomContainerSet_IBond() { IAtomContainer ac1 = MoleculeSetManipulator.GetRelevantAtomContainer(som, bondInMol1); Assert.AreEqual(mol1, ac1); }
public void TestGetAllAtomContainers_IAtomContainerSet() { var list = MoleculeSetManipulator.GetAllAtomContainers(som); Assert.AreEqual(2, list.Count()); }
public void TestGetTotalHydrogenCount_IAtomContainerSet() { int hCount = MoleculeSetManipulator.GetTotalHydrogenCount(som); Assert.AreEqual(3, hCount); }
public void TestGetTotalFormalCharge_IAtomContainerSet() { double charge = MoleculeSetManipulator.GetTotalFormalCharge(som); Assert.AreEqual(-1.0, charge, 0.000001); }
/// <summary> /// Returns all the AtomContainer's of a Reaction. /// </summary> /// <param name="set">the reaction set to get the molecules from</param> /// <returns>a List containing the IAtomContainer objects in the IReactionSet</returns> public static IEnumerable <IAtomContainer> GetAllAtomContainers(IReactionSet set) { return(MoleculeSetManipulator.GetAllAtomContainers(GetAllMolecules(set))); }