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

The following examples show how to use org.openscience.cdk.interfaces.IAtomContainer#indexOf() . 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: McGregorChecks.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param corresponding_atom
 * @param new_symbol
 * @param neighbor_bondnum
 * @param atomContainer
 * @param c_bond_neighbors
 * @return bond index
 */
protected static int changeCharBonds(int corresponding_atom, String new_symbol, int neighbor_bondnum,
        IAtomContainer atomContainer, List<String> c_bond_neighbors) {
    for (int atomIndex = 0; atomIndex < neighbor_bondnum; atomIndex++) {
        IBond bond = atomContainer.getBond(atomIndex);
        if ((atomContainer.indexOf(bond.getAtom(0)) == corresponding_atom)
                && (c_bond_neighbors.get(atomIndex * 4 + 2).compareToIgnoreCase("X") == 0)) {
            c_bond_neighbors.set(atomIndex * 4 + 2, c_bond_neighbors.get(atomIndex * 4 + 0));
            c_bond_neighbors.set(atomIndex * 4 + 0, new_symbol);
        }

        if ((atomContainer.indexOf(bond.getAtom(1)) == corresponding_atom)
                && (c_bond_neighbors.get(atomIndex * 4 + 3).compareToIgnoreCase("X") == 0)) {
            c_bond_neighbors.set(atomIndex * 4 + 3, c_bond_neighbors.get(atomIndex * 4 + 1));
            c_bond_neighbors.set(atomIndex * 4 + 1, new_symbol);
        }

    }

    return 0;
}
 
Example 2
Source File: SmilesMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param container
 * @return
 */
@Override
public IAtomContainer getCanonicalMolecule(IAtomContainer container) {
    try {
        IAtomContainer clone = container.clone();
        for (IAtom a : container.atoms()) {
            if (a.getID() != null) {
                int index = container.indexOf(a);
                clone.getAtom(index).setID(a.getID());
            }
        }

        if (container.getID() != null) {
            clone.setID(container.getID());
        }

        int[] canonicalPermutation = getCanonicalPermutation(clone);
        getCanonicalPermutation(clone, canonicalPermutation);
        return clone;

    } catch (CloneNotSupportedException ex) {
        LOGGER.error(SEVERE, null, ex);
    }
    return null;
}
 
Example 3
Source File: BlockReactionCanoniser.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void printAtomIndices(IAtom[] atoms, IAtomContainer container) {
    List<Integer> indices = new ArrayList<>();

    for (int i = 0; i < container.getAtomCount(); i++) {
        IAtom atom = atoms[i];

        if (atom == null) {
            out.println("atom " + i + " is null");
        }
        int index = container.indexOf(atom);
        indices.add(index);

    }
    out.println("array atoms " + indices);

}
 
Example 4
Source File: CDKRMapHandler.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
     *
     * @param list
     * @param source
     * @param target
     */
    protected synchronized void identifySingleAtomsMatchedParts(List<CDKRMap> list,
            IAtomContainer source,
            IAtomContainer target) {

//        List<IAtom> array1 = new ArrayList<>();
//        List<IAtom> array2 = new ArrayList<>();

        /* We have serial numbers of the bonds/Atoms to delete
         * Now we will collect the actual bond/Atoms rather than
         * serial number for deletion. RonP flag check whether reactant is
         * mapped on product or Vise Versa
         */
        TreeMap<Integer, Integer> atomNumbersFromContainer = new TreeMap<>();

        for (CDKRMap rmap : list) {
            //System.err.print("Map " + o.getClass());

            IAtom sAtom = source.getAtom(rmap.getId1());
            IAtom tAtom = target.getAtom(rmap.getId2());

//            array1.add(sAtom);
//            array2.add(tAtom);
            int indexI = source.indexOf(sAtom);
            int indexJ = target.indexOf(tAtom);

            atomNumbersFromContainer.put(indexI, indexJ);

            /*Added the Mapping Numbers to the FinalMapping*
             */
            getMappings().add(atomNumbersFromContainer);

        }
    }
 
Example 5
Source File: BlockReactionCanoniser.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void printAtomIndices(List<IAtom> atoms, IAtomContainer container) {
    List<Integer> indices = new ArrayList<>();

    for (int i = 0; i < atoms.size(); i++) {
        IAtom atom = atoms.get(i);

        if (atom == null) {
            // System.out.println("atom " + i + " is null");
        }
        int index = container.indexOf(atom);
        indices.add(index);

    } // System.out.println("list atoms " + indices);
}
 
Example 6
Source File: BlockReactionCanoniser.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String tmpAtomPrint(Iterable<IAtom> atoms, IAtomContainer ac) {
    String s = "";

    for (IAtom atom : atoms) {
        if (atom == null) {
            s += "!";
        } else {
            s += atom.getSymbol() + ac.indexOf(atom) + "("
                    + atom.getID() + ")";
        }
    }
    return s;

}
 
Example 7
Source File: MappingGraph.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private AtomContainerAtomPair getByID(IAtomContainerSet moleculeSet, String id) {
//        System.out.println("getting id " + id);
        for (IAtomContainer ac : moleculeSet.atomContainers()) {
            for (IAtom atom : ac.atoms()) {
                String atomID = atom.getID();
                if (atomID != null && atomID.equals(id)) {
                    int index = ac.indexOf(atom);
                    return new AtomContainerAtomPair(ac, atom, index);
                }
            }
        }
        return null;
    }
 
Example 8
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Return atom by ID match
 *
 * @param molWithoutH
 * @param refAtom
 * @return
 */
protected static int getAtomIndexByID(IAtomContainer molWithoutH, IAtom refAtom) {
    for (IAtom atom : molWithoutH.atoms()) {
        if (atom.getID().equalsIgnoreCase(refAtom.getID())) {
            return molWithoutH.indexOf(atom);
        }
    }
    return -1;
}
 
Example 9
Source File: RBlastSmilesGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Says if an atom is the end of a double bond configuration
 *
 * @param atom The atom which is the end of configuration
 * @param container The atomContainer the atom is in
 * @param parent The atom we came from
 * @param doubleBondConfiguration The array indicating where double bond
 * configurations are specified (this method ensures that there is actually
 * the possibility of a double bond configuration)
 * @return false=is not end of configuration, true=is
 */
private boolean isEndOfDoubleBond(IAtomContainer container, IAtom atom, IAtom parent, boolean[] doubleBondConfiguration) {
    IBond bond = container.getBond(atom, parent);
    if (bond != null
            || doubleBondConfiguration.length <= container.indexOf(bond)
            || !doubleBondConfiguration[container.indexOf(bond)]) {
        return false;
    }
    // TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here.
    int lengthAtom = container.getConnectedBondsCount(atom) + ((Objects.equals(atom.getImplicitHydrogenCount(), UNSET)) ? 0 : atom.getImplicitHydrogenCount());
    // TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here.
    int lengthParent = container.getConnectedBondsCount(parent) + ((Objects.equals(parent.getImplicitHydrogenCount(), UNSET)) ? 0 : parent.getImplicitHydrogenCount());
    if (container.getBond(atom, parent) != null) {
        if (container.getBond(atom, parent).getOrder() == IBond.Order.DOUBLE
                && (lengthAtom == 3 || (lengthAtom == 2 && atom.getSymbol().equals("N")))
                && (lengthParent == 3 || (lengthParent == 2 && parent.getSymbol().equals("N")))) {
            List<IAtom> atoms = container.getConnectedAtomsList(atom);
            IAtom one = null;
            IAtom two = null;
            IAtom atomi = null;
            for (int i = 0; i < atoms.size(); i++) {
                atomi = container.getAtom(i);
                if (atomi != parent && one == null) {
                    one = atomi;
                } else if (atomi != parent && one != null) {
                    two = atomi;
                }
            }
            String[] morgannumbers = getMorganNumbersWithElementSymbol(container);
            if ((one != null && two == null && atom.getSymbol().equals("N") && abs(giveAngleBothMethods(parent, atom, one, true)) > PI / 10) || (!atom.getSymbol().equals("N") && one != null && two != null && !morgannumbers[container.indexOf(one)].equals(morgannumbers[container.indexOf(two)]))) {
                return (true);
            } else {
                return (false);
            }
        }
    }
    return (false);
}
 
Example 10
Source File: RBlastSmilesGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Says if an atom is the start of a double bond configuration
 *
 * @param a The atom which is the start of configuration
 * @param container The atomContainer the atom is in
 * @param parent The atom we came from
 * @param doubleBondConfiguration The array indicating where double bond
 * configurations are specified (this method ensures that there is actually
 * the possibility of a double bond configuration)
 * @return false=is not start of configuration, true=is
 */
private boolean isStartOfDoubleBond(IAtomContainer container, IAtom a, IAtom parent, boolean[] doubleBondConfiguration) {
    // TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here.
    int lengthAtom = container.getConnectedBondsCount(a) + ((Objects.equals(a.getImplicitHydrogenCount(), UNSET)) ? 0 : a.getImplicitHydrogenCount());
    if (lengthAtom != 3 && (lengthAtom != 2 && !a.getSymbol().equals("N"))) {
        return (false);
    }
    List<IAtom> atoms = container.getConnectedAtomsList(a);
    IAtom one = null;
    IAtom two = null;
    boolean doubleBond = false;
    IAtom nextAtom = null;
    for (IAtom atomi : atoms) {
        if (atomi != parent && container.getBond(atomi, a).getOrder() == IBond.Order.DOUBLE
                && isEndOfDoubleBond(container, atomi, a, doubleBondConfiguration)) {
            doubleBond = true;
            nextAtom = atomi;
        }
        if (atomi != nextAtom && one == null) {
            one = atomi;
        } else if (atomi != nextAtom && one != null) {
            two = atomi;
        }
    }
    String[] morgannumbers = getMorganNumbersWithElementSymbol(container);

    IBond bond = container.getBond(a, nextAtom);
    if (bond == null) {
        return false;
    }
    if (one != null && ((!a.getSymbol().equals("N") && two != null
            && !morgannumbers[container.indexOf(one)].equals(morgannumbers[container.indexOf(two)])
            && doubleBond && doubleBondConfiguration[container.indexOf(bond)])
            || (doubleBond && a.getSymbol().equals("N") && abs(giveAngleBothMethods(nextAtom, a, parent, true)) > PI / 10))) {
        return (true);
    } else {
        return (false);
    }
}
 
Example 11
Source File: AtomContainerPrinter.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param atomContainer
 * @return
 */
public String toString(IAtomContainer atomContainer) {
    StringBuilder sb = new StringBuilder();
    for (IAtom atom : atomContainer.atoms()) {
        sb.append(atom.getSymbol());
    }
    sb.append(" ");
    List<Edge> edges = new ArrayList<>();
    for (IBond bond : atomContainer.bonds()) {
        if (bond.getAtomCount() < 2) {
            edges.add(new Edge(-1, -1, -1, "!", "!"));
            continue;
        }
        IAtom a0 = bond.getAtom(0);
        IAtom a1 = bond.getAtom(1);
        int a0N = atomContainer.indexOf(a0);
        int a1N = atomContainer.indexOf(a1);
        String a0S = a0.getSymbol();
        String a1S = a1.getSymbol();
        int o = bond.getOrder().numeric();
        if (a0N < a1N) {
            edges.add(new Edge(a0N, a1N, o, a0S, a1S));
        } else {
            edges.add(new Edge(a1N, a0N, o, a1S, a0S));
        }
    }
    sort(edges);
    sb.append(edges.toString());
    return sb.toString();
}
 
Example 12
Source File: QueryProcessor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
     *
     * @param query
     * @param target
     * @param unmapped_atoms_molA
     * @param mapped_atoms
     * @param counter
     */
    protected void process(
            IAtomContainer query,
            IAtomContainer target,
            List<Integer> unmapped_atoms_molA,
            List<Integer> mapped_atoms,
            int counter) {

        int unmapped_numA = unmapped_atoms_molA.size();

//        System.out.println("\n" + cTab1Copy + "\n");
        for (int atomIndex = 0; atomIndex < query.getBondCount(); atomIndex++) {

            Integer indexI = query.indexOf(query.getBond(atomIndex).getAtom(0));
            Integer indexJ = query.indexOf(query.getBond(atomIndex).getAtom(1));
            Integer order = query.getBond(atomIndex).getOrder().numeric();

            boolean bond_considered = false;
            boolean normal_bond = true;

//            System.out.println(AtomI + "= , =" + AtomJ );
            for (Integer unMappedAtomIndex = 0; unMappedAtomIndex < unmapped_numA; unMappedAtomIndex++) {

                if (unmapped_atoms_molA.get(unMappedAtomIndex).equals(indexI)) {
                    normal_bond = unMappedAtomsEqualsIndexJ(query, target, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
                    bond_considered = true;
                } else //if a connecting atom found?
                if (unmapped_atoms_molA.get(unMappedAtomIndex).equals(indexJ)) {
                    normal_bond = unMappedAtomsEqualsIndexI(query, target, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
                    bond_considered = true;
                }
                if (normal_bond && bond_considered) {
                    markNormalBonds(atomIndex, indexI, indexJ, order);
                    break;
                }
            }
        }
    }
 
Example 13
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 14
Source File: CDKRMapHandler.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This makes atom map1 of matching atoms out of atom map1 of matching bonds
 * as produced by the get(Subgraph|Ismorphism)Map methods. Added by Asad
 * since CDK one doesn't pick up the correct changes
 *
 * @param list The list produced by the getMap method.
 * @param sourceGraph first molecule. Must not be an IQueryAtomContainer.
 * @param targetGraph second molecule. May be an IQueryAtomContainer.
 * @return The mapping found projected on sourceGraph. This is atom List of
 * CDKRMap objects containing Ids of matching atoms.
 */
private synchronized List<List<CDKRMap>> makeAtomsMapOfBondsMapSingleBond(List<CDKRMap> list, IAtomContainer sourceGraph, IAtomContainer targetGraph) {
    if (list == null) {
        return null;
    }
    Map<IBond, IBond> bondMap = new HashMap<>(list.size());
    list.stream().forEach((solBondMap) -> {
        int id1 = solBondMap.getId1();
        int id2 = solBondMap.getId2();
        IBond qBond = sourceGraph.getBond(id1);
        IBond tBond = targetGraph.getBond(id2);
        bondMap.put(qBond, tBond);
    });
    List<CDKRMap> result1 = new ArrayList<>();
    List<CDKRMap> result2 = new ArrayList<>();
    for (IBond qbond : sourceGraph.bonds()) {
        if (bondMap.containsKey(qbond)) {
            IBond tbond = bondMap.get(qbond);
            CDKRMap map00 = null;
            CDKRMap map01 = null;
            CDKRMap map10 = null;
            CDKRMap map11 = null;

            if ((qbond.getAtom(0).getSymbol().equals(tbond.getAtom(0).getSymbol()))
                    && (qbond.getAtom(1).getSymbol().equals(tbond.getAtom(1).getSymbol()))) {
                map00 = new CDKRMap(sourceGraph.indexOf(qbond.getAtom(0)),
                        targetGraph.indexOf(tbond.getAtom(0)));
                map11 = new CDKRMap(sourceGraph.indexOf(qbond.getAtom(1)),
                        targetGraph.indexOf(tbond.getAtom(1)));
                if (!result1.contains(map00)) {
                    result1.add(map00);
                }
                if (!result1.contains(map11)) {
                    result1.add(map11);
                }
            }
            if ((qbond.getAtom(0).getSymbol().equals(tbond.getAtom(1).getSymbol()))
                    && (qbond.getAtom(1).getSymbol().equals(tbond.getAtom(0).getSymbol()))) {
                map01 = new CDKRMap(sourceGraph.indexOf(qbond.getAtom(0)),
                        targetGraph.indexOf(tbond.getAtom(1)));
                map10 = new CDKRMap(sourceGraph.indexOf(qbond.getAtom(1)),
                        targetGraph.indexOf(tbond.getAtom(0)));
                if (!result2.contains(map01)) {
                    result2.add(map01);
                }
                if (!result2.contains(map10)) {
                    result2.add(map10);
                }
            }
        }
    }
    List<List<CDKRMap>> result = new ArrayList<>();
    if (result1.size() == result2.size()) {
        result.add(result1);
        result.add(result2);
    } else if (result1.size() > result2.size()) {
        result.add(result1);
    } else {
        result.add(result2);
    }
    return result;
}
 
Example 15
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 16
Source File: TargetProcessor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void process(
        IAtomContainer target,
        List<Integer> unmapped_atoms_molB,
        int mappingSize,
        List<Integer> i_bond_setB,
        List<String> c_bond_setB,
        List<Integer> mapped_atoms,
        int counter) {

    int unmapped_numB = unmapped_atoms_molB.size();
    boolean bond_considered = false;
    boolean normal_bond = true;

    for (int atomIndex = 0; atomIndex < target.getBondCount(); atomIndex++) {

        Integer indexI = target.indexOf(target.getBond(atomIndex).getAtom(0));
        Integer indexJ = target.indexOf(target.getBond(atomIndex).getAtom(1));
        IBond bond = target.getBond(atomIndex);
        Integer order = null;
        if (!(bond instanceof IQueryBond)) {
            order = (bond.getOrder().numeric());
        } else {
            IQueryBond queryBond = (IQueryBond) bond;
            order = queryBond.getOrder() != null ? (queryBond.getOrder().numeric()) : null;
        }

        for (int b = 0; b < unmapped_numB; b++) {
            if (unmapped_atoms_molB.get(b).equals(indexI)) {
                normal_bond = unMappedAtomsEqualsIndexI(target, mappingSize, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
                bond_considered = true;
            } else if (unmapped_atoms_molB.get(b).equals(indexJ)) {
                normal_bond = unMappedAtomsEqualsIndexJ(target, mappingSize, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
                bond_considered = true;
            }

            if (normal_bond && bond_considered) {
                markNormalBonds(atomIndex, i_bond_setB, c_bond_setB, indexI, indexJ, order);
                normal_bond = true;
                break;
            }

        }
        bond_considered = false;
    }

}
 
Example 17
Source File: SubgraphMoleculeSignature.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
     *
     * @param fullContainer
     * @param subgraphAtoms
     * @param dummy
     */
    public SubgraphMoleculeSignature(
            IAtomContainer fullContainer, List<IAtom> subgraphAtoms, int dummy) {
        this.atomContainer
                = fullContainer.getBuilder().newInstance(IAtomContainer.class);

//        for (IAtom atom : subgraphAtoms) {
//            this.atomContainer.addAtom(atom);
//        }
        // sort the atoms
        IAtom[] sortedAtoms = new IAtom[fullContainer.getAtomCount()];
        List<String> debugList = new ArrayList<>();
        subgraphAtoms.stream().forEach((atom) -> {
            int atomNumber = fullContainer.indexOf(atom);
            sortedAtoms[atomNumber] = atom;
            debugList.add(atom.getSymbol() + atomNumber);
        });
        sort(debugList);
//        System.out.println("atoms of " + fullContainer.getID() + " " + debugList);

        List<Integer> debugList2 = new ArrayList<>();
        for (int i = 0; i < sortedAtoms.length; i++) {
            if (sortedAtoms[i] != null) {
                this.atomContainer.addAtom(sortedAtoms[i]);
                debugList2.add(i);
            }
        }
//        System.out.println("atoms (2) of " + atomContainer.getID() + " " + debugList2);

        for (IBond bond : fullContainer.bonds()) {
            IAtom a0 = bond.getAtom(0);
            IAtom a1 = bond.getAtom(1);
            int a0n = fullContainer.indexOf(a0);
            int a1n = fullContainer.indexOf(a1);
            if (subgraphAtoms.contains(a0) && subgraphAtoms.contains(a1)) {
                this.atomContainer.addBond(bond);
//                System.out.println("adding bond " + a0n + " " + a1n);
            } else {
//                System.out.println("rejecting bond " + a0n + " " + a1n);
            }
        }

        this.vertexCount = subgraphAtoms.size();
        useAdjLists = false;
    }
 
Example 18
Source File: StereoCenterAnalyser.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Check an atom to see if it has a potential tetrahedral stereo center.
 * This can only be true if:
 * <ol>
 * <li>It has 4 neighbours OR 3 neighbours and a single implicit
 * hydrogen</li>
 * <li>These four neighbours are different according to CIP rules</li>
 * </ol>
 * If these conditions are met, it returns true.
 *
 * @param atom the central atom of the stereocenter
 * @param atomContainer the atom container the atom is in
 * @return true if all conditions for a stereocenter are met
 */
public static synchronized boolean hasPotentialStereoCenter(IAtom atom, IAtomContainer atomContainer) {
    List<IAtom> neighbours = atomContainer.getConnectedAtomsList(atom);
    int numberOfNeighbours = neighbours.size();
    boolean hasImplicitHydrogen = false;
    if (numberOfNeighbours == 4) {
        hasImplicitHydrogen = false;
    } else if (numberOfNeighbours == 3) {
        Integer implicitCount = atom.getImplicitHydrogenCount();
        if (implicitCount != null && implicitCount == 1) {
            hasImplicitHydrogen = true;
        } else {
            SaturationChecker checker = new SaturationChecker();
            try {
                if (checker.calculateNumberOfImplicitHydrogens(
                        atom, atomContainer) == 1) {
                    hasImplicitHydrogen = true;
                }
            } catch (CDKException e) {
                e.printStackTrace();
            }
        }
        if (!hasImplicitHydrogen) {
            return false;
        }
    } else if (numberOfNeighbours > 4) {
        return false;   // not tetrahedral, anyway
    } else if (numberOfNeighbours < 3) {
        return false;   // definitely not chiral
    }
    ILigand[] ligands = new ILigand[4];
    int index = 0;
    VisitedAtoms bitSet = new VisitedAtoms();
    int chiralAtomIndex = atomContainer.indexOf(atom);
    for (IAtom neighbour : neighbours) {
        int ligandAtomIndex = atomContainer.indexOf(neighbour);
        ligands[index] = defineLigand(
                atomContainer, bitSet, chiralAtomIndex, ligandAtomIndex);
        index++;
    }
    if (hasImplicitHydrogen) {
        ligands[index] = defineLigand(atomContainer, bitSet, chiralAtomIndex, HYDROGEN);
    }
    order(ligands);
    return checkIfAllLigandsAreDifferent(ligands);
}