/// <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 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)); }