public static IAtomContainer createNewMolecule ( IChemModel chemModel ) { // Add a new molecule either the set of molecules IAtomContainer molecule = chemModel . getBuilder ( ) . newInstance ( IAtomContainer . class ) ; if ( chemModel . getMoleculeSet ( ) != null ) { IAtomContainerSet moleculeSet = chemModel . getMoleculeSet ( ) ; for ( int i = 0 ; i < moleculeSet . getAtomContainerCount ( ) ; i ++ ) { if ( moleculeSet . getAtomContainer ( i ) . getAtomCount ( ) == 0 ) { moleculeSet . removeAtomContainer ( i ) ; i -- ; } } moleculeSet . addAtomContainer ( molecule ) ; } else { IAtomContainerSet moleculeSet = chemModel . getBuilder ( ) . newInstance ( IAtomContainerSet . class ) ; moleculeSet . addAtomContainer ( molecule ) ; chemModel . setMoleculeSet ( moleculeSet ) ; } return molecule ; }
Adds a new Molecule to the MoleculeSet inside a given ChemModel . Creates a MoleculeSet if none is contained .