Java Code Examples for org.openscience.cdk.interfaces.IAtomContainer#getConnectedBondsList()

The following examples show how to use org.openscience.cdk.interfaces.IAtomContainer#getConnectedBondsList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaseHandler.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean findAndChipBond(IAtomContainer container, IAtomContainer referenceContainer) {
    boolean flag = false;

    if (container != null) {
        for (IBond bond : container.bonds()) {
            if ((bond.getAtom(0).getSymbol().equalsIgnoreCase("O")
                    && bond.getAtom(1).getSymbol().equalsIgnoreCase("C"))
                    || (bond.getAtom(0).getSymbol().equalsIgnoreCase("C")
                    && bond.getAtom(1).getSymbol().equalsIgnoreCase("O"))) {
                if (!bond.getAtom(0).getFlag(ISAROMATIC)
                        && !bond.getAtom(1).getFlag(ISAROMATIC)) {
                    if (referenceContainer.contains(bond)) {
                        IAtom atom = bond.getAtom(0).getSymbol().equalsIgnoreCase("C") ? bond.getAtom(0) : bond.getAtom(1);
                        List<IBond> neighbourhoodBonds = referenceContainer.getConnectedBondsList(atom);
                        flag = false;
                        for (IBond neighbourhoodBond : neighbourhoodBonds) {
                            if (neighbourhoodBond.contains(atom) && !neighbourhoodBond.getFlag(ISINRING)) {
                                if ((neighbourhoodBond.getAtom(0).getSymbol().equalsIgnoreCase("O")
                                        && neighbourhoodBond.getAtom(1).getSymbol().equalsIgnoreCase("C"))
                                        || (neighbourhoodBond.getAtom(0).getSymbol().equalsIgnoreCase("C")
                                        && neighbourhoodBond.getAtom(1).getSymbol().equalsIgnoreCase("O"))) {
                                    flag = true;
                                }
                            }
                        }

                        if (flag) {
                            referenceContainer.removeBond(bond);
                            break;
                        }
                    }
                }
            }
        }
    }
    return flag;
}
 
Example 2
Source File: CaseHandler.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean findAndChipBondPhophate(IAtomContainer container) {
    boolean flag = false;

    for (IBond bond : container.bonds()) {
        IAtom atomE = bond.getAtom(0);
        IAtom atomP = bond.getAtom(1);
        if ((atomE.getSymbol().equals("O") && atomP.getSymbol().equals("P"))
                || (atomE.getSymbol().equals("P") && atomP.getSymbol().equals("O"))) {
            if (bond.getOrder().equals(SINGLE)) {
                IAtom oxygen = atomE.getSymbol().equals("O") ? atomE : atomP;
                List<IBond> neighbourBonds = container.getConnectedBondsList(oxygen);
                if (neighbourBonds.size() == 2) {
                    neighbourBonds.stream().filter((b) -> (b.getAtom(0).getSymbol().equals("O")
                            || b.getAtom(0).getSymbol().equals("P"))).filter((b) -> (b.getAtom(1).getSymbol().equals("O")
                            || b.getAtom(1).getSymbol().equals("P"))).map((b) -> {
                        container.removeBond(b);
                        return b;
                    }).filter((b) -> (DEBUG)).map((b) -> {
                        out.println("bondToBeChipped " + b.getAtom(0).getSymbol());
                        return b;
                    }).map((b) -> {
                        out.println("bondToBeChipped " + b.getAtom(1).getSymbol());
                        return b;
                    }).forEach((_item) -> {
                        out.println("removeBond o-p ");
                    });
                    return true;
                }
            }
        }
    }

    return flag;
}
 
Example 3
Source File: CDKCentreProvider.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean onlyConnectedToSingleBonds(IBond bond, IAtom atom, IAtomContainer container) {
    for (IBond connected : container.getConnectedBondsList(atom)) {
        if (!SINGLE.equals(connected.getOrder()) && !connected.equals(bond)) {
            return FALSE;
        }
    }
    return TRUE;
}
 
Example 4
Source File: CDKCentreProvider.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean hasVariableBond(IAtomContainer container, IAtom atom) {
    for (IBond bond : container.getConnectedBondsList(atom)) {
        IBond.Stereo stereo = bond.getStereo();
        if (UP_OR_DOWN.equals(stereo)
                || UP_OR_DOWN_INVERTED.equals(stereo)) {
            return TRUE;
        }
    }
    return FALSE;
}
 
Example 5
Source File: CDKCentreProvider.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean hasStereoBonds(IAtomContainer container, IAtom atom) {
    for (IBond bond : container.getConnectedBondsList(atom)) {
        IBond.Stereo stereo = bond.getStereo();
        if (UP.equals(stereo)
                || DOWN.equals(stereo)
                || UP_INVERTED.equals(stereo)
                || DOWN_INVERTED.equals(stereo)) {
            return TRUE;
        }
    }
    return FALSE;
}
 
Example 6
Source File: CDKMCS.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This makes a map of matching atoms out of a map of matching bonds as
 * produced by the get(Subgraph|Ismorphism)Map methods.
 *
 * @param l The list produced by the getMap method.
 * @param g1 first molecule. Must not be an {@link IQueryAtomContainer}.
 * @param g2 second molecule. May be an {@link IQueryAtomContainer}.
 * @return The mapping found projected on g1. This is a {@link List} of
 * {@link CDKRMap} objects containing Ids of matching atoms.
 */
private static List<CDKRMap> makeAtomsMapOfBondsMap(List<CDKRMap> l, IAtomContainer g1, IAtomContainer g2) {
    if (l == null) {
        return (l);
    }
    List<CDKRMap> result = new ArrayList<>();
    for (int i = 0; i < l.size(); i++) {
        IBond bond1 = g1.getBond(l.get(i).getId1());
        IBond bond2 = g2.getBond(l.get(i).getId2());
        IAtom[] atom1 = BondManipulator.getAtomArray(bond1);
        IAtom[] atom2 = BondManipulator.getAtomArray(bond2);
        for (int j = 0; j < 2; j++) {
            List<IBond> bondsConnectedToAtom1j = g1.getConnectedBondsList(atom1[j]);
            for (int k = 0; k < bondsConnectedToAtom1j.size(); k++) {
                if (bondsConnectedToAtom1j.get(k) != bond1) {
                    IBond testBond = bondsConnectedToAtom1j.get(k);
                    for (int m = 0; m < l.size(); m++) {
                        IBond testBond2;
                        if (l.get(m).getId1() == g1.indexOf(testBond)) {
                            testBond2 = g2.getBond(l.get(m).getId2());
                            for (int n = 0; n < 2; n++) {
                                List<IBond> bondsToTest = g2.getConnectedBondsList(atom2[n]);
                                if (bondsToTest.contains(testBond2)) {
                                    CDKRMap map;
                                    if (j == n) {
                                        map = new CDKRMap(g1.indexOf(atom1[0]), g2.indexOf(atom2[0]));
                                    } else {
                                        map = new CDKRMap(g1.indexOf(atom1[1]), g2.indexOf(atom2[0]));
                                    }
                                    if (!result.contains(map)) {
                                        result.add(map);
                                    }
                                    CDKRMap map2;
                                    if (j == n) {
                                        map2 = new CDKRMap(g1.indexOf(atom1[1]), g2.indexOf(atom2[1]));
                                    } else {
                                        map2 = new CDKRMap(g1.indexOf(atom1[0]), g2.indexOf(atom2[1]));
                                    }
                                    if (!result.contains(map2)) {
                                        result.add(map2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
 
Example 7
Source File: MappingHandler.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This makes a map of matching atoms out of a map of matching bonds as
 * produced by the get(Subgraph|Ismorphism)Map methods.
 *
 * @param l The list produced by the getMap method.
 * @param g1 first molecule. Must not be an {@link IQueryAtomContainer}.
 * @param g2 second molecule. May be an {@link IQueryAtomContainer}.
 * @param shouldMatchRings
 * @param matchAtomTypes
 * @return The mapping found projected on g1. This is a {@link List} of
 * {@link RMap} objects containing Ids of matching atoms.
 */
public static Map<Integer, Integer> makeAtomsMapOfBondsMap(
        Map<Integer, Integer> l, IAtomContainer g1, IAtomContainer g2,
        AtomMatcher am, BondMatcher bm) {
    if (l == null) {
        return (new TreeMap<>());
    }
    Map<Integer, Integer> result = new TreeMap<>();
    for (Map.Entry<Integer, Integer> map : l.entrySet()) {
        IBond bond1 = g1.getBond(map.getKey());
        IBond bond2 = g2.getBond(map.getValue());
        IAtom[] atom1 = BondManipulator.getAtomArray(bond1);
        IAtom[] atom2 = BondManipulator.getAtomArray(bond2);
        for (int j = 0; j < 2; j++) {
            List<IBond> bondsConnectedToAtom1j = g1.getConnectedBondsList(atom1[j]);
            for (int k = 0; k < bondsConnectedToAtom1j.size(); k++) {
                if (!bondsConnectedToAtom1j.get(k).equals(bond1)) {
                    IBond testBond = (IBond) bondsConnectedToAtom1j.get(k);
                    for (Map.Entry<Integer, Integer> m : l.entrySet()) {
                        IBond testBond2;
                        if (m.getKey() == g1.indexOf(testBond)) {
                            testBond2 = g2.getBond(m.getValue());
                            for (int n = 0; n < 2; n++) {
                                List<IBond> bondsToTest = g2.getConnectedBondsList(atom2[n]);
                                if (bondsToTest.contains(testBond2)) {

                                    if (j == n) {
                                        if (!result.containsKey(g1.indexOf(atom1[0]))
                                                && !result.containsValue(g2.indexOf(atom2[0]))) {
                                            result.put(g1.indexOf(atom1[0]), g2.indexOf(atom2[0]));
                                        }
                                    } else {
                                        if (!result.containsKey(g1.indexOf(atom1[1]))
                                                && !result.containsValue(g2.indexOf(atom2[0]))) {
                                            result.put(g1.indexOf(atom1[1]), g2.indexOf(atom2[0]));
                                        }
                                    }

                                    if (j == n) {
                                        if (!result.containsKey(g1.indexOf(atom1[1]))
                                                && !result.containsValue(g2.indexOf(atom2[1]))) {
                                            result.put(g1.indexOf(atom1[1]), g2.indexOf(atom2[1]));
                                        }
                                    } else {
                                        if (!result.containsKey(g1.indexOf(atom1[0]))
                                                && !result.containsValue(g2.indexOf(atom2[1]))) {
                                            result.put(g1.indexOf(atom1[0]), g2.indexOf(atom2[1]));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (result.isEmpty() && l.size() == 1) {
        result = SingleMappingCase(l, g1, g2, am, bm);
    }
    return result;
}
 
Example 8
Source File: CaseHandler.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean findAndChipBondBetweenRings(IAtomContainer container) {
    if (DEBUG) {
        out.println("Find and Chip Bond Between Rings");
    }
    List<IBond> bond_to_be_removed = new ArrayList<>();
    for (IAtom atom : container.atoms()) {
        if (atom.getSymbol().equals("O") && !atom.isAromatic()) {
            int number_of_rings = ((Integer) atom.getProperty(RING_CONNECTIONS));
            if (DEBUG) {
                out.println("number_of_rings " + number_of_rings);
            }

            List<IBond> bonds = container.getConnectedBondsList(atom);
            if (DEBUG) {
                out.println("number_of_bonds " + bonds.size());
                bonds.stream().forEach((bond) -> {
                    out.println("BONDS "
                            + " B0 " + bond.getAtom(0).getSymbol()
                            + " B1 " + bond.getAtom(1).getSymbol());
                });
            }

            if (bonds.size() == 2 && number_of_rings == 2) {
                IBond bondToBeChipped = bonds.iterator().next();
                bond_to_be_removed.add(bondToBeChipped);
            }
        }
    }
    bond_to_be_removed.stream().map((bond) -> {
        container.removeBond(bond);
        return bond;
    }).filter((bond) -> (DEBUG)).forEach((bond) -> {
        try {
            out.println("CHIPPING BONDS "
                    + " B0 " + bond.getAtom(0).getSymbol()
                    + " B1 " + bond.getAtom(1).getSymbol());
            out.println("CHIPPED SM " + new SmilesGenerator(SmiFlavor.Generic).create(container));
        } catch (CDKException ex) {
            LOGGER.error(SEVERE, "Clipping Bonds: ", ex.getMessage());
        }
    });
    return !bond_to_be_removed.isEmpty();
}