public static IMolecularFormula getMaxOccurrenceElements ( IMolecularFormulaSet mfSet ) { IMolecularFormula molecularFormula = mfSet . getBuilder ( ) . newInstance ( IMolecularFormula . class ) ; for ( IMolecularFormula mf : mfSet . molecularFormulas ( ) ) { for ( IIsotope isotope : mf . isotopes ( ) ) { IElement element = mfSet . getBuilder ( ) . newInstance ( IElement . class , isotope ) ; int occur_new = MolecularFormulaManipulator . getElementCount ( mf , element ) ; if ( ! MolecularFormulaManipulator . containsElement ( molecularFormula , element ) ) { molecularFormula . addIsotope ( mfSet . getBuilder ( ) . newInstance ( IIsotope . class , element ) , occur_new ) ; } else { int occur_old = MolecularFormulaManipulator . getElementCount ( molecularFormula , element ) ; if ( occur_new > occur_old ) { MolecularFormulaManipulator . removeElement ( molecularFormula , element ) ; molecularFormula . addIsotope ( mfSet . getBuilder ( ) . newInstance ( IIsotope . class , element ) , occur_new ) ; } } } } return molecularFormula ; }
Extract from a set of MolecularFormula the maximum occurrence of each element found and put the element and occurrence in a new IMolecularFormula .