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