private static String calculateMolecularFormula ( List < AbstractMolecule > molecules ) throws BuilderMoleculeException , CTKException , ChemistryException { Map < String , Integer > atomNumberMap = new TreeMap < String , Integer > ( ) ; for ( AbstractMolecule molecule : molecules ) { LOG . info ( molecule . getMolecule ( ) . toString ( ) ) ; atomNumberMap = generateAtomNumberMap ( molecule , atomNumberMap ) ; } LOG . info ( "GET map" ) ; StringBuilder sb = new StringBuilder ( ) ; Set < String > atoms = atomNumberMap . keySet ( ) ; for ( Iterator < String > i = atoms . iterator ( ) ; i . hasNext ( ) ; ) { String atom = i . next ( ) ; String num = atomNumberMap . get ( atom ) . toString ( ) ; if ( num . equals ( "1" ) ) { num = "" ; } sb . append ( atom ) ; sb . append ( num . toString ( ) ) ; } return sb . toString ( ) ; }
intern method to calculate the molecular formular for a list of molecules