/// <summary> /// Adds a new Molecule to the MoleculeSet inside a given ChemModel. /// Creates a MoleculeSet if none is contained. /// </summary> /// <param name="chemModel">The ChemModel object.</param> /// <returns>The created Molecule object.</returns> public static IAtomContainer CreateNewMolecule(IChemModel chemModel) { // Add a new molecule either the set of molecules IAtomContainer molecule = chemModel.Builder.NewAtomContainer(); if (chemModel.MoleculeSet != null) { IChemObjectSet <IAtomContainer> moleculeSet = chemModel.MoleculeSet; for (int i = 0; i < moleculeSet.Count; i++) { if (moleculeSet[i].Atoms.Count == 0) { moleculeSet.RemoveAt(i); i--; } } moleculeSet.Add(molecule); } else { var moleculeSet = chemModel.Builder.NewAtomContainerSet(); moleculeSet.Add(molecule); chemModel.MoleculeSet = moleculeSet; } return(molecule); }
public virtual void TestRemoveAtomContainer_int() { IChemObjectSet <T> som = (IChemObjectSet <T>)NewChemObject(); T ac1 = NewContainerObject(); T ac2 = NewContainerObject(); som.Add(ac1); som.Add(ac2); som.RemoveAt(0); Assert.AreEqual(1, som.Count); Assert.AreEqual(ac2, som[0]); }