private synchronized boolean isSubgraphIdentical(IAtomContainer _mol, IAtomContainer _rMol, boolean removeHydrogen) throws CDKException, IOException { // System.out.println("Graph matching"); IAtomContainer mol1 = _mol; IAtomContainer mol2 = _rMol; AtomMatcher atomMatcher = AtomBondMatcher.atomMatcher(true, true); BondMatcher bondMatcher = AtomBondMatcher.bondMatcher(true, true); Substructure mcs = new Substructure(mol1, mol2, atomMatcher, bondMatcher, false); mcs.setChemFilters(false, false, false); return mcs.isSubgraph() && !mcs.isStereoMisMatch() && mol1.getAtomCount() == mol2.getAtomCount(); }
boolean findAllSubgraph) throws CDKException { super(query, target, shouldMatchBonds, matchRings, matchAtomType); if (isMatchRings()) { try { MoleculeInitializer.initializeMolecule(getQuery()); MoleculeInitializer.initializeMolecule(getTarget()); } catch (CDKException ex) { setSubgraph(findSubgraphs()); } else { setSubgraph(findSubgraph());
private static int getSMSDSolutionCount(IAtomContainer queryMol, IAtomContainer target) throws CDKException { Substructure substructure = new Substructure(queryMol, target, true, true, true, false); if (substructure.isSubgraph()) { return 1; } else { return 0; } }
/** * Constructor for VF Substructure Algorithm * * @param query * @param target * @param findAllSubgraph report all subgraphs * @throws CDKException */ public Substructure( IQueryAtomContainer query, IAtomContainer target, boolean findAllSubgraph) throws CDKException { super(query, target); if (findAllSubgraph) { setSubgraph(findSubgraphs()); } else { setSubgraph(findSubgraph()); } }
private synchronized boolean singleMapping() { SingleMappingHandler mcs; if (!(getQuery() instanceof IQueryAtomContainer) && !(getTarget() instanceof IQueryAtomContainer)) { mcs = new SingleMappingHandler(getQuery(), getTarget(), isMatchRings()); } else { mcs = new SingleMappingHandler((IQueryAtomContainer) getQuery(), getTarget()); } return mcs.getAllAtomMapping() != null && !mcs.getAllAtomMapping().isEmpty(); } }
boolean isSubgraph; if ((getTarget() == null) || (getQuery() == null)) { throw new CDKException("Query or Target molecule is not initialized (NULL)"); if (getQuery().getAtomCount() > getTarget().getAtomCount()) { return false; if (getQuery().getAtomCount() == 1 || getTarget().getAtomCount() == 1) { isSubgraph = singleMapping(); } else { List<AtomAtomMapping> mappingsVF2 = new ArrayList<>(); VF2Sub mapper; if (getQuery() instanceof IQueryAtomContainer) { mapper = new VF2Sub((IQueryAtomContainer) getQuery(), getTarget()); } else { mapper = new VF2Sub(getQuery(), getTarget(), isMatchBonds(), isMatchRings(), isMatchAtomType()); return false; setVFMappings(mappingsVF2);
substructure = new Substructure(ac1, ac2, am, bm, true); if (!substructure.isSubgraph() && !theory.equals(IMappingAlgorithm.RINGS)) { am = AtomBondMatcher.atomMatcher(false, ringFlag); bm = AtomBondMatcher.bondMatcher(false, isHasPerfectRings()); substructure = new Substructure(ac1, ac2, am, bm, true); } else if (moleculeConnected && !substructure.isSubgraph()) { am = AtomBondMatcher.atomMatcher(false, false); bm = AtomBondMatcher.bondMatcher(false, isHasPerfectRings()); substructure = new Substructure(ac1, ac2, am, bm, true); substructure.setChemFilters(true, true, true); if (substructure.isSubgraph() && substructure.getFirstAtomMapping().getCount() == ac1.getAtomCount()) { if (DEBUG1) { System.out.println("Found Substructure 1"); substructure.getQuery(), substructure.getTarget(), substructure.getFirstAtomMapping()); mcs.setEnergy(substructure.getEnergyScore(0)); mcs.setFragmentSize(substructure.getFragmentSize(0)); mcs.setStereoScore(substructure.getStereoScore(0)); if (DEBUG1) { long stopTime = currentTimeMillis(); substructure = new Substructure(ac2, ac1, am, bm, true);
private synchronized boolean substructureAlgorithm() throws CDKException { if (DEBUG) { System.out.println("Check substructureAlgorithm"); } Substructure mcs; if (getQuery() instanceof IQueryAtomContainer) { mcs = new Substructure((IQueryAtomContainer) getQuery(), getTarget(), atomMatcher, bondMatcher, true); } else { mcs = new Substructure(getQuery(), getTarget(), atomMatcher, bondMatcher, true); } clearMaps(); if (mcs.isSubgraph()) { getMCSList().addAll(mcs.getAllAtomMapping()); } return mcs.isSubgraph(); }
private synchronized void setVFMappings(List<AtomAtomMapping> mappingsVF2) { int counter = 0; for (AtomAtomMapping solution : mappingsVF2) { AtomAtomMapping atomatomMapping = new AtomAtomMapping(getQuery(), getTarget()); if (solution.getCount() > vfMappingSize) { this.vfMappingSize = solution.getCount(); counter = 0; } for (Map.Entry<IAtom, IAtom> mapping : solution.getMappingsByAtoms().entrySet()) { IAtom qAtom; IAtom tAtom; qAtom = mapping.getKey(); tAtom = mapping.getValue(); if (qAtom != null && tAtom != null) { atomatomMapping.put(qAtom, tAtom); } else { try { throw new CDKException("Atom index pointing to NULL"); } catch (CDKException ex) { Logger.error(Level.SEVERE, null, ex); } } } if (!atomatomMapping.isEmpty() && !hasMap(atomatomMapping, getMCSList()) && atomatomMapping.getCount() == vfMappingSize) { getMCSList().add(counter, atomatomMapping); counter++; } } }
if ((getTarget() == null) || (getQuery() == null)) { throw new CDKException("Query or Target molecule is not initialized (NULL)"); if (getQuery().getAtomCount() > getTarget().getAtomCount()) { return false; int rBondCount = getQuery().getBondCount(); int pBondCount = getTarget().getBondCount(); int rAtomCount = getQuery().getAtomCount(); int pAtomCount = getTarget().getAtomCount(); int expectedMaxGraphmatch = expectedMaxGraphmatch(getQuery(), getTarget()); isSubgraph = singleMapping(); } else { List<AtomAtomMapping> mappingsVF2 = new ArrayList<>(); VF2Substructure mapper; if (getQuery() instanceof IQueryAtomContainer) { mapper = new VF2Substructure((IQueryAtomContainer) getQuery(), getTarget(), findAllMatches, atomMatcher, bondMatcher); } else { if (DEBUG) { System.out.println("calling VF2Sub"); mapper = new VF2Substructure(getQuery(), getTarget(), atomMatcher, bondMatcher, findAllMatches); if (DEBUG) { System.out.println("done calling VF2Sub"); setVFMappings(mappingsVF2);
if (source.getAtomCount() <= target.getAtomCount()) { try { s = new Substructure(source, target, atomMatcher, bondMatcher, false); s.setChemFilters(true, true, true); return s.getFirstAtomMapping().getMappingsByAtoms(); } catch (CDKException ex) { Logger.getLogger(uk.ac.ebi.reactionblast.mechanism.helper.Utility.class.getName()).log(Level.SEVERE, null, ex);
private synchronized boolean singleMapping() { SingleMappingHandler mcs; if (!(getQuery() instanceof IQueryAtomContainer) && !(getTarget() instanceof IQueryAtomContainer)) { mcs = new SingleMappingHandler(getQuery(), getTarget(), atomMatcher); } else { mcs = new SingleMappingHandler((IQueryAtomContainer) getQuery(), getTarget(), atomMatcher); } return mcs.getAllAtomMapping() != null && !mcs.getAllAtomMapping().isEmpty(); } }
private static BaseMapping runSubstructure( IAtomContainer query, IAtomContainer target, int filter, boolean matchBonds, boolean matchRings, boolean matchAtomTypes) throws CDKException { // XXX - if clean and configure is 'true', is that not duplicate configuring? BaseMapping smsd = new Substructure(query, target, matchBonds, matchRings, matchAtomTypes, true); if (smsd.isSubgraph()) { if (filter == 0) { smsd.setChemFilters(false, false, false); } if (filter == 1) { smsd.setChemFilters(true, false, false); } if (filter == 2) { smsd.setChemFilters(true, true, false); } if (filter == 3) { smsd.setChemFilters(true, true, true); } } return smsd; }
/** * Constructor for VF Substructure Algorithm * * Please call before calling substructure search * * if (super.isMatchRings()) { try { * MoleculeInitializer.initializeMolecule(super.getQuery()); * MoleculeInitializer.initializeMolecule(super.getTarget()); } catch * (CDKException ex) { } } * * @param query * @param target * @param shouldMatchBonds Match bond types (i.e. double to double etc) * @param matchRings Match ring atoms and ring size * @param findAllSubgraph report all subgraphs * @param matchAtomType * @throws CDKException */ public Substructure( IAtomContainer query, IAtomContainer target, AtomMatcher am, BondMatcher bm, boolean findAllSubgraph) throws CDKException { super(query, target, am, bm); super.setSubgraph(findSubgraphs(findAllSubgraph)); }
boolean isSubgraph; if ((getTarget() == null) || (getQuery() == null)) { throw new CDKException("Query or Target molecule is not initialized (NULL)"); if (getQuery().getAtomCount() > getTarget().getAtomCount()) { return false; if (getQuery().getAtomCount() == 1 || getTarget().getAtomCount() == 1) { isSubgraph = singleMapping(); } else { if (getQuery() instanceof IQueryAtomContainer) { mapper = new VF2((IQueryAtomContainer) getQuery(), getTarget()); } else { mapper = new VF2(getQuery(), getTarget(), isMatchBonds(), isMatchRings(), isMatchAtomType()); return false; setVFMappings(mappingsVF2);
private synchronized boolean substructureAlgorithm() throws CDKException { Substructure mcs; if (getQuery() instanceof IQueryAtomContainer) { mcs = new Substructure((IQueryAtomContainer) getQuery(), getTarget(), true); } else { mcs = new Substructure(getQuery(), getTarget(), isMatchBonds(), isMatchRings(), isMatchAtomType(), true); } clearMaps(); if (mcs.isSubgraph()) { getMCSList().addAll(mcs.getAllAtomMapping()); } return mcs.isSubgraph(); }
private synchronized void setVFMappings(List<AtomAtomMapping> mappingsVF2) { int counter = 0; for (AtomAtomMapping solution : mappingsVF2) { AtomAtomMapping atomatomMapping = new AtomAtomMapping(getQuery(), getTarget()); if (solution.getCount() > vfMappingSize) { this.vfMappingSize = solution.getCount(); counter = 0; } solution.getMappingsByAtoms().entrySet().stream().forEach((mapping) -> { IAtom qAtom; IAtom tAtom; qAtom = mapping.getKey(); tAtom = mapping.getValue(); if (qAtom != null && tAtom != null) { atomatomMapping.put(qAtom, tAtom); } else { try { throw new CDKException("Atom index pointing to NULL"); } catch (CDKException ex) { Logger.error(Level.SEVERE, null, ex); } } }); if (!atomatomMapping.isEmpty() && !hasMap(atomatomMapping, getMCSList()) && atomatomMapping.getCount() == vfMappingSize) { getMCSList().add(counter, atomatomMapping); counter++; } } }
/** * If either is a subgraph * * @param ac1 * @param ac2 * @return * @throws CDKException */ public static boolean isMatch(IAtomContainer ac1, IAtomContainer ac2, boolean either) throws CDKException { AtomMatcher atomMatcher = AtomBondMatcher.atomMatcher(false, true); BondMatcher bondMatcher = AtomBondMatcher.bondMatcher(true, true); if (ac1.getAtomCount() <= ac2.getAtomCount()) { Substructure pattern = new Substructure(ac1, ac2, atomMatcher, bondMatcher, false); // create pattern return pattern.isSubgraph(); } if (either && ac1.getAtomCount() >= ac2.getAtomCount()) { Substructure pattern = new Substructure(ac2, ac1, atomMatcher, bondMatcher, false); // create pattern return pattern.isSubgraph(); } return false; }
private synchronized boolean singleMapping() { SingleMappingHandler mcs; if (!(getQuery() instanceof IQueryAtomContainer) && !(getTarget() instanceof IQueryAtomContainer)) { mcs = new SingleMappingHandler(getQuery(), getTarget(), isMatchRings()); } else { mcs = new SingleMappingHandler((IQueryAtomContainer) getQuery(), getTarget()); } return mcs.getAllAtomMapping() != null && !mcs.getAllAtomMapping().isEmpty(); } }
/** * Constructor for VF Substructure Algorithm * * @param query * @param target * @param findAllSubgraph report all subgraphs * @throws CDKException */ public Substructure( IQueryAtomContainer query, IAtomContainer target, boolean findAllSubgraph) throws CDKException { super(query, target); if (findAllSubgraph) { setSubgraph(findSubgraphs()); } else { setSubgraph(findSubgraph()); } }