public IAtomContainer fixAromaticBondOrders ( IAtomContainer atomContainer ) throws CDKException { // preset all bond orders to single for ( IBond bond : atomContainer . bonds ( ) ) { if ( bond . isAromatic ( ) && bond . getOrder ( ) == IBond . Order . UNSET ) bond . setOrder ( IBond . Order . SINGLE ) ; } // OK, we take advantage here from the fact that this class does not take // into account rings larger than 7 atoms. See fixAromaticBondOrders(). IRingSet rs = allRingsFinder . findAllRings ( atomContainer , 7 ) ; storeRingSystem ( atomContainer , rs ) ; IRingSet ringSet ; // TODO remove rings with nonsp2 carbons(?) and rings larger than 7 atoms ringSet = removeExtraRings ( atomContainer ) ; if ( ringSet == null ) throw new CDKException ( "failure in AllRingsFinder.findAllRings" ) ; List < List < List < String > > > MasterList = new ArrayList < List < List < String > > > ( ) ; //this.counter=0;// counter which keeps track of all current possibilities for placing double bonds this . FixPyridineNOxides ( atomContainer , ringSet ) ; for ( int i = 0 ; i <= ringSet . getAtomContainerCount ( ) - 1 ; i ++ ) { IRing ring = ( IRing ) ringSet . getAtomContainer ( i ) ; // only takes into account rings up to 7 atoms... if that changes, // make sure to update the findAllRings() calls too! if ( ring . getAtomCount ( ) == 5 ) { fiveMemberedRingPossibilities ( atomContainer , ring , MasterList ) ; } else if ( ring . getAtomCount ( ) == 6 ) { sixMemberedRingPossibilities ( atomContainer , ring , MasterList ) ; } else if ( ring . getAtomCount ( ) == 7 ) { sevenMemberedRingPossibilities ( atomContainer , ring , MasterList ) ; //TODO- add code for all 7 membered aromatic ring possibilities not just 3 bonds } else { //TODO: what about other rings systems? logger . debug ( "Found ring of size: " + ring . getAtomCount ( ) ) ; } } IAtomContainerSet som = atomContainer . getBuilder ( ) . newInstance ( IAtomContainerSet . class ) ; // int number=1; // total number of possibilities // // for (int ii=0;ii<=MasterList.size()-1;ii++) { // ArrayList ringlist=(ArrayList)MasterList.get(ii); // number*=ringlist.size(); // } // logger.debug("number= "+number); int [ ] choices ; //if (number> 1000000) return null; choices = new int [ MasterList . size ( ) ] ; if ( MasterList . size ( ) > 0 ) { IAtomContainer iAtomContainer = loop ( System . currentTimeMillis ( ) , atomContainer , 0 , MasterList , choices , som ) ; if ( iAtomContainer != null ) return iAtomContainer ; } int mincount = 99999999 ; int best = - 1 ; // one with minimum number of bad atoms // minimize number of potentially bad nitrogens among AtomContainers in the set for ( int i = 0 ; i <= som . getAtomContainerCount ( ) - 1 ; i ++ ) { IAtomContainer mol = som . getAtomContainer ( i ) ; ringSet = removeExtraRings ( mol ) ; if ( ringSet == null ) continue ; int count = getBadCount ( mol , ringSet ) ; //logger.debug(i + "\t" + count); if ( count < mincount ) { mincount = count ; best = i ; } } if ( som . getAtomContainerCount ( ) > 0 ) return som . getAtomContainer ( best ) ; return atomContainer ; }
Added missing bond orders based on atom type information .