public boolean saturate(IBond[] bonds, IAtomContainer atomContainer) throws CDKException {
        logger.debug("Saturating bond set of size: ", bonds.length);
        boolean bondsAreFullySaturated = false;
        if (bonds.length > 0) {
            IBond bond = bonds[0];

            // determine bonds left
            int leftBondCount = bonds.length - 1;
            IBond[] leftBonds = new IBond[leftBondCount];
            System.arraycopy(bonds, 1, leftBonds, 0, leftBondCount);

            // examine this bond
            logger.debug("Examining this bond: ", bond);
            if (isSaturated(bond, atomContainer)) {
                logger.debug("OK, bond is saturated, now try to saturate remaining bonds (if needed)");
                bondsAreFullySaturated = saturate(leftBonds, atomContainer);
            } else if (isUnsaturated(bond, atomContainer)) {
                logger.debug("Ok, this bond is unsaturated, and can be saturated");
                // two options now:
                // 1. saturate this one directly
                // 2. saturate this one by saturating the rest
                logger.debug("Option 1: Saturating this bond directly, then trying to saturate rest");
                // considering organic bonds, the max order is 3, so increase twice
                boolean bondOrderIncreased = saturateByIncreasingBondOrder(bond, atomContainer);
                bondsAreFullySaturated = bondOrderIncreased && saturate(bonds, atomContainer);
                if (bondsAreFullySaturated) {
                    logger.debug("Option 1: worked");
                } else {
                    logger.debug("Option 1: failed. Trying option 2.");
                    logger.debug("Option 2: Saturing this bond by saturating the rest");
                    // revert the increase (if succeeded), then saturate the rest
                    if (bondOrderIncreased) unsaturateByDecreasingBondOrder(bond);
                    bondsAreFullySaturated = saturate(leftBonds, atomContainer) && isSaturated(bond, atomContainer);
                    if (!bondsAreFullySaturated) logger.debug("Option 2: failed");
                }
            } else {
                logger.debug("Ok, this bond is unsaturated, but cannot be saturated");
                // try recursing and see if that fixes things
                bondsAreFullySaturated = saturate(leftBonds, atomContainer) && isSaturated(bond, atomContainer);
            }
        } else {
            bondsAreFullySaturated = true; // empty is saturated by default
        }
        return bondsAreFullySaturated;
    }
public boolean saturate ( IBond [ ] bonds , IAtomContainer atomContainer ) throws CDKException { logger . debug ( "Saturating bond set of size: " , bonds . length ) ; boolean bondsAreFullySaturated = false ; if ( bonds . length > 0 ) { IBond bond = bonds [ 0 ] ; int leftBondCount = bonds . length - 1 ; IBond [ ] leftBonds = new IBond [ leftBondCount ] ; System . arraycopy ( bonds , 1 , leftBonds , 0 , leftBondCount ) ; logger . debug ( "Examining this bond: " , bond ) ; if ( isSaturated ( bond , atomContainer ) ) { logger . debug ( "OK, bond is saturated, now try to saturate remaining bonds (if needed)" ) ; bondsAreFullySaturated = saturate ( leftBonds , atomContainer ) ; } else if ( isUnsaturated ( bond , atomContainer ) ) { logger . debug ( "Ok, this bond is unsaturated, and can be saturated" ) ; logger . debug ( "Option 1: Saturating this bond directly, then trying to saturate rest" ) ; boolean bondOrderIncreased = saturateByIncreasingBondOrder ( bond , atomContainer ) ; bondsAreFullySaturated = bondOrderIncreased && saturate ( bonds , atomContainer ) ; if ( bondsAreFullySaturated ) { logger . debug ( "Option 1: worked" ) ; } else { logger . debug ( "Option 1: failed. Trying option 2." ) ; logger . debug ( "Option 2: Saturing this bond by saturating the rest" ) ; if ( bondOrderIncreased ) unsaturateByDecreasingBondOrder ( bond ) ; bondsAreFullySaturated = saturate ( leftBonds , atomContainer ) && isSaturated ( bond , atomContainer ) ; if ( ! bondsAreFullySaturated ) logger . debug ( "Option 2: failed" ) ; } } else { logger . debug ( "Ok, this bond is unsaturated, but cannot be saturated" ) ; bondsAreFullySaturated = saturate ( leftBonds , atomContainer ) && isSaturated ( bond , atomContainer ) ; } } else { bondsAreFullySaturated = true ; } return bondsAreFullySaturated ; }
Saturates a set of Bonds in an AtomContainer.