/** * Returns the first isomorph 'atom mapping' found for g2 in g1. * * @param g1 first molecule. Must not be an {@link IQueryAtomContainer}. * @param g2 second molecule. May be an {@link IQueryAtomContainer}. * @return the first isomorph atom mapping found projected on g1. * This is a List of RMap objects containing Ids of matching atoms. * @throws CDKException if the first molecules is not an instance of {@link IQueryAtomContainer} */ public List<RMap> getIsomorphAtomsMap(IAtomContainer g1, IAtomContainer g2) throws CDKException { if (g1 instanceof IQueryAtomContainer) throw new CDKException("The first IAtomContainer must not be an IQueryAtomContainer"); List<RMap> list = checkSingleAtomCases(g1, g2); if (list == null) { return makeAtomsMapOfBondsMap(getIsomorphMap(g1, g2), g1, g2); } else if (list.isEmpty()) { return null; } else { return list; } }
/** * Tests if g1 and g2 are isomorph. * * @param g1 first molecule. Must not be an {@link IQueryAtomContainer}. * @param g2 second molecule. May be an {@link IQueryAtomContainer}. * @return true if the 2 molecule are isomorph * @throws CDKException if the first molecule is an instance of IQueryAtomContainer */ public boolean isIsomorph(IAtomContainer g1, IAtomContainer g2) throws CDKException { if (g1 instanceof IQueryAtomContainer) throw new CDKException("The first IAtomContainer must not be an IQueryAtomContainer"); if (g2.getAtomCount() != g1.getAtomCount()) return false; // check single atom case if (g2.getAtomCount() == 1) { IAtom atom = g1.getAtom(0); IAtom atom2 = g2.getAtom(0); if (atom instanceof IQueryAtom) { IQueryAtom qAtom = (IQueryAtom) atom; return qAtom.matches(g2.getAtom(0)); } else if (atom2 instanceof IQueryAtom) { IQueryAtom qAtom = (IQueryAtom) atom2; return qAtom.matches(g1.getAtom(0)); } else { String atomSymbol = atom2.getSymbol(); return g1.getAtom(0).getSymbol().equals(atomSymbol); } } return (getIsomorphMap(g1, g2) != null); }