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

The following examples show how to use org.openscience.cdk.interfaces.IAtomContainer#getConnectedAtomsList() . 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: Reactor.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param id
 * @param molSet
 * @return
 */
private synchronized List<IAtom> markHAroundCoreAtoms(String id, IAtomContainerSet molSet) {

    List<IAtom> list = new ArrayList<>();
    for (int pMol = 0; pMol < molSet.getAtomContainerCount(); pMol++) {
        IAtomContainer pMolecule = molSet.getAtomContainer(pMol);
        for (int pAtom = 0; pAtom < pMolecule.getAtomCount(); pAtom++) {
            IAtom atom = molSet.getAtomContainer(pMol).getAtom(pAtom);
            if (!atom.getSymbol().equalsIgnoreCase("H") && !atom.getID().equalsIgnoreCase("-1")) {
                if (atom.getID().equalsIgnoreCase(id)) {
                    List<IAtom> conAtoms = pMolecule.getConnectedAtomsList(atom);
                    conAtoms.stream().filter((atomH) -> (atomH.getID().equalsIgnoreCase("-1") && atomH.getSymbol().equalsIgnoreCase("H"))).forEach((atomH) -> {
                        list.add(atomH);
                    });
                }
            }
        }
    }
    return list;
}
 
Example 2
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Determines the best alignment for the label of an atom in 2D space. It
 * returns 1 if right (=default) aligned, and -1 if left aligned. returns 2
 * if top aligned, and -2 if H is aligned below the atom See comment for
 * center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param container Description of the Parameter
 * @param atom Description of the Parameter
 * @return The bestAlignmentForLabel value
 */
public static int getBestAlignmentForLabelXY(IAtomContainer container, IAtom atom) {
    double overallDiffX = 0;
    double overallDiffY = 0;
    for (IAtom connectedAtom : container.getConnectedAtomsList(atom)) {
        overallDiffX += connectedAtom.getPoint2d().x - atom.getPoint2d().x;
        overallDiffY += connectedAtom.getPoint2d().y - atom.getPoint2d().y;
    }
    if (Math.abs(overallDiffY) > Math.abs(overallDiffX)) {
        if (overallDiffY < 0) {
            return 2;
        } else {
            return -2;
        }
    } else {
        if (overallDiffX <= 0) {
            return 1;
        } else {
            return -1;
        }
    }
}
 
Example 3
Source File: RBlastSmilesGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Tells if a certain bond is center of a valid double bond configuration.
 *
 * @param container The atomcontainer.
 * @param bond The bond.
 * @return true=is a potential configuration, false=is not.
 */
public boolean isValidDoubleBondConfiguration(IAtomContainer container, IBond bond) {
    IAtom atom0 = bond.getAtom(0);
    IAtom atom1 = bond.getAtom(1);
    List<IAtom> connectedAtoms = container.getConnectedAtomsList(atom0);
    IAtom from = null;
    for (IAtom connectedAtom : connectedAtoms) {
        if (connectedAtom != atom1) {
            from = connectedAtom;
        }
    }
    boolean[] array = new boolean[container.getBondCount()];
    for (int i = 0; i < array.length; i++) {
        array[i] = true;
    }
    if (isStartOfDoubleBond(container, atom0, from, array) && isEndOfDoubleBond(container, atom1, atom0, array) && !bond.getFlag(ISAROMATIC)) {
        return (true);
    } else {
        return (false);
    }
}
 
Example 4
Source File: RBlastSmilesGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private IAtom hasWedges(IAtomContainer ac, IAtom a) {
        List<IAtom> atoms = ac.getConnectedAtomsList(a);
        //      for (int i = 0; i < atoms.size(); i++)
//      {
//          atomi = (IAtom)atoms.get(i);
//          if (ac.getBond(a, atomi).getStereo() != IBond.Stereo.NONE && !atomi.getSymbol().equals("H"))
//          {
//              return (atomi);
//          }
//      }
        for (IAtom atom : atoms) {
            if (ac.getBond(a, atom).getStereo() != NONE) {
                return (atom);
            }
        }
        return (null);
    }
 
Example 5
Source File: RBlastSmilesGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Return the neighbours of atom <code>a</code> in canonical order with the
 * atoms that have high bond order at the front.
 *
 * @param a the atom whose neighbours are to be found.
 * @param container the GraphAtomContainer that is being parsed.
 * @return Vector of atoms in canonical oreder.
 */
private List getCanNeigh(final IAtom a, final IAtomContainer container, final int[] canonicalLabels) {
    List<IAtom> v = container.getConnectedAtomsList(a);
    if (v.size() > 1) {
        sort(v, (IAtom a1, IAtom a2) -> {
            int l1 = canonicalLabels[container.indexOf(a1)];
            int l2 = canonicalLabels[container.indexOf(a2)];
            if (l1 < l2) {
                return -1;
            } else if (l1 > l2) {
                return 1;
            } else {
                return 0;
            }
        });
    }
    return v;
}
 
Example 6
Source File: ValencyCalculator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param m
 * @param atom
 * @param skipHydrogen
 * @return
 * @throws CDKException
 */
public static Integer getFreeValenceElectrons(IAtomContainer m, IAtom atom, boolean skipHydrogen) throws CDKException {
    initialize();
    Integer totalConnectedBondOrder = 0;
    List<IAtom> connectedAtoms = m.getConnectedAtomsList(atom);
    int counterH = 0;
    for (IAtom connAtom : connectedAtoms) {
        if (skipHydrogen && connAtom.getSymbol().equalsIgnoreCase("H")) {
            counterH++;
        }
        IBond bond = m.getBond(atom, connAtom);
        totalConnectedBondOrder += convertBondOrder(bond);
    }
    Integer charge = Objects.equals(atom.getFormalCharge(), UNSET) ? 0 : atom.getFormalCharge();
    return skipHydrogen ? (getValenceElectron(atom) - totalConnectedBondOrder + counterH - charge)
            : (getValenceElectron(atom) - totalConnectedBondOrder - charge);
}
 
Example 7
Source File: DirectBondDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addRingCentersToAtomAnnotationPositions(IAtomContainer mol, IRingSet ringSet) {
    for (IAtomContainer ring : ringSet.atomContainers()) {
        for (IAtom atom : ring.atoms()) {
            List<IAtom> connectedAtoms = mol.getConnectedAtomsList(atom);
            List<IAtom> connectedAtomsInRing = new ArrayList<>();
            connectedAtoms.stream().filter(connectedAtom -> (ring.contains(connectedAtom))).forEachOrdered(connectedAtom -> {
                connectedAtomsInRing.add(connectedAtom);
            });
            labelManager.addRingCenterToAtomAnnotationPosition(
                    atom, connectedAtomsInRing);
        }
    }
}
 
Example 8
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Determines the best alignment for the label of an atom in 2D space. It
 * returns 1 if left aligned, and -1 if right aligned. See comment for
 * center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param container Description of the Parameter
 * @param atom Description of the Parameter
 * @return The bestAlignmentForLabel value
 */
public static int getBestAlignmentForLabel(IAtomContainer container, IAtom atom) {
    double overallDiffX = 0;
    for (IAtom connectedAtom : container.getConnectedAtomsList(atom)) {
        overallDiffX += connectedAtom.getPoint2d().x - atom.getPoint2d().x;
    }
    if (overallDiffX <= 0) {
        return 1;
    } else {
        return -1;
    }
}
 
Example 9
Source File: Chirality3DTool.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get R/S Chirality assignments for an atom container that should have 3D
 * coordinates as Point3d set in the atoms. If getNoneAssignments is set to
 * true, atoms with 4 neighbors that are not chiral will be mapped to
 * IStereoAndConformation.NONE.
 *
 * @param atomContainer the atom container to perform assignments on
 * @param getNoneAssigments if true, map non-chiral tetrahedral centers to
 * NONE
 * @return a map of chiral atoms to assignments
 */
@Override
public Map<IAtom, IStereoAndConformation> getTetrahedralChiralities(IAtomContainer atomContainer, boolean getNoneAssigments) {
    Map<IAtom, IStereoAndConformation> chiralMap = new HashMap<>();
    for (IAtom atom : atomContainer.atoms()) {
        List<IAtom> neighbours = atomContainer.getConnectedAtomsList(atom);
        if (neighbours.size() == 4) {

            IAtom n1 = neighbours.get(0);
            IAtom n2 = neighbours.get(1);
            IAtom n3 = neighbours.get(2);
            IAtom n4 = neighbours.get(3);
            Stereo stereo = getStereo(n1, n2, n3, n4);
            IAtom[] ligands = new IAtom[]{n1, n2, n3, n4};
            ITetrahedralChirality stereoCenter
                    = new TetrahedralChirality(atom, ligands, stereo);
            CIP_CHIRALITY chirality = getCIPChirality(atomContainer, stereoCenter);
            if (getNoneAssigments || chirality != CIP_CHIRALITY.NONE) {
                switch (chirality) {
                    case NONE:
                        chiralMap.put(atom, IStereoAndConformation.NONE);
                    case R:
                        chiralMap.put(atom, IStereoAndConformation.R);
                    case S:
                        chiralMap.put(atom, IStereoAndConformation.S);
                    default:
                        chiralMap.put(atom, IStereoAndConformation.NONE);
                }
            }
        }
    }

    return chiralMap;
}
 
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 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 11
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 12
Source File: GenerateCompatibilityGraphFJ.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Map<IAtom, List<String>> labelAtomsBySymbol(int startIndex, int endIndex, IAtomContainer atomCont) {
        Map<IAtom, List<String>> label_list = new HashMap<>();

        for (int i = startIndex; i < endIndex; i++) {
            List<String> label = new ArrayList<>(7);
            for (int a = 0; a < 7; a++) {
                label.add(a, "Z9");
            }

            IAtom refAtom = atomCont.getAtom(i);
            if (refAtom == null) {
                return label_list;
            }
            /*
             * Important Step: Discriminate between source atom types
             */
            String referenceAtom;
            if (refAtom instanceof IQueryAtom) {
                referenceAtom = ((IQueryAtom) refAtom).getSymbol() == null ? "*" : ((IQueryAtom) refAtom).getSymbol();
                if (DEBUG) {
                    System.out.println("referenceAtom " + referenceAtom);
                }
            } else {
                referenceAtom = refAtom.getSymbol(); //+ refAtom.getAtomicNumber();
            }
            label.set(0, referenceAtom);
            List<IAtom> connAtoms = atomCont.getConnectedAtomsList(refAtom);

            int counter = 1;

            for (IAtom negAtom : connAtoms) {
                String neighbouringAtom;
                if (refAtom instanceof IQueryAtom) {
                    neighbouringAtom = ((IQueryAtom) negAtom).getSymbol() == null ? "*" : ((IQueryAtom) negAtom).getSymbol();
//                    System.out.println("neighbouringAtom " + neighbouringAtom);
                } else {
                    neighbouringAtom = negAtom.getSymbol(); //+ negAtom.getAtomicNumber();
                }
                label.set(counter, neighbouringAtom);
                counter += 1;
            }
            if (DEBUG) {
                System.out.println("label " + label);
            }
            bubbleSort(label);
            label_list.put(refAtom, label);
        }
        return label_list;
    }
 
Example 13
Source File: GenerateCompatibilityGraph.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Map<IAtom, List<String>> labelAtomsBySymbol(IAtomContainer atomCont) {
        Map<IAtom, List<String>> label_list = new HashMap<>();

        for (int i = 0; i < atomCont.getAtomCount(); i++) {
            List<String> label = new ArrayList<>(7);
            for (int a = 0; a < 7; a++) {
                label.add(a, "Z9");
            }

            IAtom refAtom = atomCont.getAtom(i);
            if (refAtom == null) {
                return label_list;
            }
            /*
             * Important Step: Discriminate between source atom types
             */
            String referenceAtom;
            if (refAtom instanceof IQueryAtom) {
                referenceAtom = ((IQueryAtom) refAtom).getSymbol() == null ? "*" : ((IQueryAtom) refAtom).getSymbol();
//                System.out.println("referenceAtom " + referenceAtom);
            } else {
                referenceAtom = refAtom.getSymbol();// + refAtom.getAtomicNumber();
            }
            label.set(0, referenceAtom);
            List<IAtom> connAtoms = atomCont.getConnectedAtomsList(refAtom);

            int counter = 1;

            for (IAtom negAtom : connAtoms) {
                String neighbouringAtom;
                if (refAtom instanceof IQueryAtom) {
                    neighbouringAtom = ((IQueryAtom) negAtom).getSymbol() == null ? "*" : ((IQueryAtom) negAtom).getSymbol();
//                    System.out.println("neighbouringAtom " + neighbouringAtom);
                } else {
                    neighbouringAtom = negAtom.getSymbol();// + negAtom.getAtomicNumber();
                }
                label.set(counter, neighbouringAtom);
                counter += 1;
            }
//            System.out.println("label " + label);
            bubbleSort(label);
            label_list.put(refAtom, label);
        }
        return label_list;
    }
 
Example 14
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Return the RMSD of bonds length between the 2 aligned molecules.
 *
 * @param firstAtomContainer the (largest) first aligned AtomContainer which
 * is the reference
 * @param secondAtomContainer the second aligned AtomContainer
 * @param mappedAtoms Map: a Map of the mapped atoms
 * @param Coords3d boolean: true if moecules has 3D coords, false if
 * molecules has 2D coords
 * @return double: all the RMSD of bonds length
 *
 *
 */
public static double getBondLengthRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
        Map<Integer, Integer> mappedAtoms, boolean Coords3d) {
    //logger.debug("**** GT getBondLengthRMSD ****");
    Iterator<Integer> firstAtoms = mappedAtoms.keySet().iterator();
    IAtom centerAtomFirstMolecule;
    IAtom centerAtomSecondMolecule;
    List<IAtom> connectedAtoms;
    double sum = 0;
    double n = 0;
    double distance1 = 0;
    double distance2 = 0;
    setVisitedFlagsToFalse(firstAtomContainer);
    setVisitedFlagsToFalse(secondAtomContainer);
    while (firstAtoms.hasNext()) {
        centerAtomFirstMolecule = firstAtomContainer.getAtom(firstAtoms.next());
        centerAtomFirstMolecule.setFlag(CDKConstants.VISITED, true);
        centerAtomSecondMolecule = secondAtomContainer.getAtom(mappedAtoms.get(firstAtomContainer
                .indexOf(centerAtomFirstMolecule)));
        connectedAtoms = firstAtomContainer.getConnectedAtomsList(centerAtomFirstMolecule);
        for (int i = 0; i < connectedAtoms.size(); i++) {
            IAtom conAtom = (IAtom) connectedAtoms.get(i);
            //this step is built to know if the program has already calculate a bond length (so as not to have duplicate values)
            if (!conAtom.getFlag(CDKConstants.VISITED)) {
                if (Coords3d) {
                    distance1 = ((Point3d) centerAtomFirstMolecule.getPoint3d()).distance(conAtom.getPoint3d());
                    distance2 = ((Point3d) centerAtomSecondMolecule.getPoint3d()).distance(secondAtomContainer
                            .getAtom(mappedAtoms.get(firstAtomContainer.indexOf(conAtom))).getPoint3d());
                    sum = sum + Math.pow((distance1 - distance2), 2);
                    n++;
                } else {
                    distance1 = ((Point2d) centerAtomFirstMolecule.getPoint2d()).distance(conAtom.getPoint2d());
                    distance2 = ((Point2d) centerAtomSecondMolecule.getPoint2d()).distance(secondAtomContainer
                            .getAtom((mappedAtoms.get(firstAtomContainer.indexOf(conAtom)))).getPoint2d());
                    sum = sum + Math.pow((distance1 - distance2), 2);
                    n++;
                }
            }
        }
    }
    setVisitedFlagsToFalse(firstAtomContainer);
    setVisitedFlagsToFalse(secondAtomContainer);
    return Math.sqrt(sum / n);
}
 
Example 15
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Return the variation of each angle value between the 2 aligned molecules.
 *
 * @param firstAtomContainer the (largest) first aligned AtomContainer which
 * is the reference
 * @param secondAtomContainer the second aligned AtomContainer
 * @param mappedAtoms Map: a Map of the mapped atoms
 * @return double: the value of the RMSD
 *
 *
 */
public static double getAngleRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
        Map<Integer, Integer> mappedAtoms) {
    //logger.debug("**** GT getAngleRMSD ****");
    Iterator<Integer> firstAtoms = mappedAtoms.keySet().iterator();
    //logger.debug("mappedAtoms:"+mappedAtoms.toString());
    IAtom firstAtomfirstAC;
    IAtom centerAtomfirstAC;
    IAtom firstAtomsecondAC;
    IAtom secondAtomsecondAC;
    IAtom centerAtomsecondAC;
    double angleFirstMolecule;
    double angleSecondMolecule;
    double sum = 0;
    double n = 0;
    while (firstAtoms.hasNext()) {
        int firstAtomNumber = firstAtoms.next();
        centerAtomfirstAC = firstAtomContainer.getAtom(firstAtomNumber);
        List<IAtom> connectedAtoms = firstAtomContainer.getConnectedAtomsList(centerAtomfirstAC);
        if (connectedAtoms.size() > 1) {
            //logger.debug("If "+centerAtomfirstAC.getSymbol()+" is the center atom :");
            for (int i = 0; i < connectedAtoms.size() - 1; i++) {
                firstAtomfirstAC = (IAtom) connectedAtoms.get(i);
                for (int j = i + 1; j < connectedAtoms.size(); j++) {
                    angleFirstMolecule = getAngle(centerAtomfirstAC, firstAtomfirstAC,
                            (IAtom) connectedAtoms.get(j));
                    centerAtomsecondAC = secondAtomContainer.getAtom(mappedAtoms.get(firstAtomContainer
                            .indexOf(centerAtomfirstAC)));
                    firstAtomsecondAC = secondAtomContainer.getAtom(mappedAtoms.get(firstAtomContainer
                            .indexOf(firstAtomfirstAC)));
                    secondAtomsecondAC = secondAtomContainer.getAtom(mappedAtoms.get(firstAtomContainer
                            .indexOf((IAtom) connectedAtoms.get(j))));
                    angleSecondMolecule = getAngle(centerAtomsecondAC, firstAtomsecondAC, secondAtomsecondAC);
                    sum = sum + Math.pow(angleFirstMolecule - angleSecondMolecule, 2);
                    n++;
                    //logger.debug("Error for the "+firstAtomfirstAC.getSymbol().toLowerCase()+"-"+centerAtomfirstAC.getSymbol()+"-"+connectedAtoms[j].getSymbol().toLowerCase()+" Angle :"+deltaAngle+" degrees");
                }
            }
        }//if
    }
    return Math.sqrt(sum / n);
}
 
Example 16
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);
}