public boolean apply(IAtomContainer molecule) throws CDKException {

        Set<IBond> bonds = findBonds(molecule);

        // clear existing flags
        molecule.setFlag(ISAROMATIC, false);
        for (IBond bond : molecule.bonds())
            bond.setIsAromatic(false);
        for (IAtom atom : molecule.atoms())
            atom.setIsAromatic(false);

        // set the new flags
        for (final IBond bond : bonds) {
            bond.setIsAromatic(true);
            bond.getBegin().setIsAromatic(true);
            bond.getEnd().setIsAromatic(true);
        }

        molecule.setFlag(ISAROMATIC, !bonds.isEmpty());

        return !bonds.isEmpty();
    }
public boolean apply ( IAtomContainer molecule ) throws CDKException { Set < IBond > bonds = findBonds ( molecule ) ; molecule . setFlag ( ISAROMATIC , false ) ; for ( IBond bond : molecule . bonds ( ) ) bond . setIsAromatic ( false ) ; for ( IAtom atom : molecule . atoms ( ) ) atom . setIsAromatic ( false ) ; for ( final IBond bond : bonds ) { bond . setIsAromatic ( true ) ; bond . getBegin ( ) . setIsAromatic ( true ) ; bond . getEnd ( ) . setIsAromatic ( true ) ; } molecule . setFlag ( ISAROMATIC , ! bonds . isEmpty ( ) ) ; return ! bonds . isEmpty ( ) ; }
Apply this aromaticity model to a molecule. Any existing aromaticity
flags are removed - even if no aromatic bonds were found. This follows
the idea of <i>applying</i> an aromaticity model to a molecule such that
the result is the same irrespective of existing aromatic flags. If you
require aromatic flags to be preserved the {@link
#findBonds(IAtomContainer)} can be used to find bonds without setting any
flags.

<blockquote><pre>
Aromaticity aromaticity = new Aromaticity(ElectronDonation.cdk(),
Cycles.all());
IAtomContainer container = ...;
try {
if (aromaticity.apply(container)) {
//
}
} catch (CDKException e) {
// cycle computation was intractable
}
</pre></blockquote>

@param molecule the molecule to apply the model to
@return the model found the molecule was aromatic