/** * {@inheritDoc} * */ private boolean findSubgraph() { if (DEBUG) { System.out.println("=======findSubgraph======="); } if (DEBUG) { System.out.println("Calling searchVFCDKMapping"); } boolean subgraph = searchVFCDKMapping(); // System.out.println("mappings " + subgraph); if (!allAtomMCSCopy.isEmpty() && allAtomMCSCopy.iterator().next().getCount() == source.getAtomCount()) { allAtomMCS.addAll(allAtomMCSCopy); allMCS.addAll(allMCSCopy); } return !allAtomMCS.isEmpty() && allAtomMCS.iterator().next().getCount() == source.getAtomCount(); }
/** * {@inheritDoc} * */ private boolean findSubgraph() { if (!MoleculeInitializer.testIsSubgraphHeuristics(source, target, this.matchBonds)) { return false; } boolean timoutVF = searchVFMappings(); boolean flag = isExtensionFeasible(); // System.out.println("find subgraph " + flag); if (flag && !vfLibSolutions.isEmpty() && !timoutVF && (!(source instanceof IQueryAtomContainer))) { try { searchMcGregorMapping(); } catch (CDKException | IOException ex) { Logger.error(Level.SEVERE, null, ex); } } else if (!allAtomMCSCopy.isEmpty() && allAtomMCSCopy.iterator().next().getCount() == source.getAtomCount()) { allAtomMCS.addAll(allAtomMCSCopy); allMCS.addAll(allMCSCopy); } return !allAtomMCS.isEmpty() && allAtomMCS.iterator().next().getCount() == source.getAtomCount(); }
/** * {@inheritDoc} * */ private boolean findSubgraph() { if (!MoleculeInitializer.testIsSubgraphHeuristics(source, target, this.matchBonds)) { return false; } boolean timoutVF = searchVFMappings(); boolean flag = isExtensionFeasible(); // System.out.println("find subgraph " + flag); if (flag && !vfLibSolutions.isEmpty() && !timoutVF && (!(source instanceof IQueryAtomContainer))) { try { searchMcGregorMapping(); } catch (CDKException | IOException ex) { Logger.error(Level.SEVERE, null, ex); } } else if (!allAtomMCSCopy.isEmpty() && allAtomMCSCopy.iterator().next().getCount() == source.getAtomCount()) { allAtomMCS.addAll(allAtomMCSCopy); allMCS.addAll(allMCSCopy); } return !allAtomMCS.isEmpty() && allAtomMCS.iterator().next().getCount() == source.getAtomCount(); }
/** * {@inheritDoc} */ @Override public synchronized double getTanimotoSimilarity() { int decimalPlaces = 4; double rAtomCount; double pAtomCount; double tanimotoAtom = 0.0; if (getMappingCount() > 0) { AtomAtomMapping firstAtomMCS = getMCSList().iterator().next(); if (!firstAtomMCS.isEmpty()) { rAtomCount = (double) this.getMCSList().iterator().next().getQuery().getAtomCount(); pAtomCount = (double) this.getMCSList().iterator().next().getTarget().getAtomCount(); double matchCount = (double) firstAtomMCS.getCount(); tanimotoAtom = (matchCount) / (rAtomCount + pAtomCount - matchCount); BigDecimal tan = new BigDecimal(tanimotoAtom); tan = tan.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); tanimotoAtom = tan.doubleValue(); } } return tanimotoAtom; }
/** * {@inheritDoc} */ @Override public synchronized double getTanimotoSimilarity() { int decimalPlaces = 4; double rAtomCount; double pAtomCount; double tanimotoAtom = 0.0; if (getMappingCount() > 0) { AtomAtomMapping firstAtomMCS = getMCSList().iterator().next(); if (!firstAtomMCS.isEmpty()) { rAtomCount = (double) this.getMCSList().iterator().next().getQuery().getAtomCount(); pAtomCount = (double) this.getMCSList().iterator().next().getTarget().getAtomCount(); double matchCount = (double) firstAtomMCS.getCount(); tanimotoAtom = (matchCount) / (rAtomCount + pAtomCount - matchCount); BigDecimal tan = new BigDecimal(tanimotoAtom); tan = tan.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); tanimotoAtom = tan.doubleValue(); } } return tanimotoAtom; }
/** * {@inheritDoc} */ @Override public synchronized double getEuclideanDistance() { int decimalPlaces = 4; double sourceAtomCount; double targetAtomCount; double euclidean = -1.; if (getMappingCount() > 0) { AtomAtomMapping firstAtomMCS = getMCSList().iterator().next(); if (!firstAtomMCS.isEmpty()) { sourceAtomCount = (double) this.getMCSList().iterator() .next().getQuery().getAtomCount(); targetAtomCount = (double) this.getMCSList().iterator() .next().getTarget().getAtomCount(); double common = (double) firstAtomMCS.getCount(); euclidean = Math.sqrt(sourceAtomCount + targetAtomCount - 2 * common); BigDecimal dist = new BigDecimal(euclidean); dist = dist.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); euclidean = dist.doubleValue(); } } return euclidean; }
/** * {@inheritDoc} */ @Override public synchronized double getEuclideanDistance() { int decimalPlaces = 4; double sourceAtomCount; double targetAtomCount; double euclidean = -1.; if (getMappingCount() > 0) { AtomAtomMapping firstAtomMCS = getMCSList().iterator().next(); if (!firstAtomMCS.isEmpty()) { sourceAtomCount = (double) this.getMCSList().iterator() .next().getQuery().getAtomCount(); targetAtomCount = (double) this.getMCSList().iterator() .next().getTarget().getAtomCount(); double common = (double) firstAtomMCS.getCount(); euclidean = Math.sqrt(sourceAtomCount + targetAtomCount - 2 * common); BigDecimal dist = new BigDecimal(euclidean); dist = dist.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); euclidean = dist.doubleValue(); } } return euclidean; }
/** * {@inheritDoc} */ @Override public synchronized double getTanimotoSimilarity() { int decimalPlaces = 4; double rAtomCount; double pAtomCount; double tanimotoAtom = 0.0; if (getMappingCount() > 0) { AtomAtomMapping firstAtomMCS = getMCSList().iterator().next(); if (!firstAtomMCS.isEmpty()) { rAtomCount = (double) this.getMCSList().iterator().next().getQuery().getAtomCount(); pAtomCount = (double) this.getMCSList().iterator().next().getTarget().getAtomCount(); double matchCount = (double) firstAtomMCS.getCount(); tanimotoAtom = (matchCount) / (rAtomCount + pAtomCount - matchCount); BigDecimal tan = new BigDecimal(tanimotoAtom); tan = tan.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); tanimotoAtom = tan.doubleValue(); } } return tanimotoAtom; }
/** * {@inheritDoc} */ @Override public synchronized double getEuclideanDistance() { int decimalPlaces = 4; double sourceAtomCount; double targetAtomCount; double euclidean = -1.; if (getMappingCount() > 0) { AtomAtomMapping firstAtomMCS = getMCSList().iterator().next(); if (!firstAtomMCS.isEmpty()) { sourceAtomCount = (double) this.getMCSList().iterator() .next().getQuery().getAtomCount(); targetAtomCount = (double) this.getMCSList().iterator() .next().getTarget().getAtomCount(); double common = (double) firstAtomMCS.getCount(); euclidean = Math.sqrt(sourceAtomCount + targetAtomCount - 2 * common); BigDecimal dist = new BigDecimal(euclidean); dist = dist.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); euclidean = dist.doubleValue(); } } return euclidean; }
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++; } } }
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++; } } }
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++; } } }
/** * * @return true if query is a subgraph of the target */ @Override public synchronized boolean isSubgraph() { float mappingSize; if (getMappingCount() > 0) { mappingSize = getAllAtomMapping().iterator().next().getCount(); } else { return false; } int sourceAtomCount = getQuery().getAtomCount(); int targetAtomCount = getTarget().getAtomCount(); if (mappingSize == sourceAtomCount && mappingSize <= targetAtomCount) { if (mappingSize == 1) { return true; } else if (!getAllBondMaps().isEmpty() && getAllBondMaps().iterator().next().size() == getQuery().getBondCount()) { return true; } } return false; }
/** * * @return true if query is a subgraph of the target */ @Override public synchronized boolean isSubgraph() { float mappingSize; if (getMappingCount() > 0) { mappingSize = getAllAtomMapping().iterator().next().getCount(); } else { return false; } int sourceAtomCount = getQuery().getAtomCount(); int targetAtomCount = getTarget().getAtomCount(); if (mappingSize == sourceAtomCount && mappingSize <= targetAtomCount) { if (mappingSize == 1) { return true; } else if (!getAllBondMaps().isEmpty() && getAllBondMaps().iterator().next().size() == getQuery().getBondCount()) { return true; } } return false; }
/** * * @return true if query is a subgraph of the target */ @Override public synchronized boolean isSubgraph() { float mappingSize; if (getMappingCount() > 0) { mappingSize = getAllAtomMapping().iterator().next().getCount(); } else { return false; } int sourceAtomCount = getQuery().getAtomCount(); int targetAtomCount = getTarget().getAtomCount(); if (mappingSize == sourceAtomCount && mappingSize <= targetAtomCount) { if (mappingSize == 1) { return true; } else if (!getAllBondMaps().isEmpty() && getAllBondMaps().iterator().next().size() == getQuery().getBondCount()) { return true; } } return false; }
System.out.println("MCS First size: " + mcs.getFirstAtomMapping().getCount());
public int substructureSize(String smiles) throws CDKException { AtomMatcher atomMatcher = AtomBondMatcher.atomMatcher(false, false); BondMatcher bondMatcher = AtomBondMatcher.bondMatcher(false, false); try { IAtomContainer parseSmiles = sp.parseSmiles(smiles); VF2 vf = new VF2(parseSmiles, mol, atomMatcher, bondMatcher); return vf.isSubgraph() ? vf.getFirstAtomMapping().getCount() : 0; } catch (InvalidSmilesException ex) { VF2 vf = new VF2(parse(smiles, mol.getBuilder()), mol); return vf.isSubgraph() ? vf.getFirstAtomMapping().getCount() : 0; } } }
private synchronized void defaultMCSAlgorithm() { try { boolean substructureAlgorithm = substructureAlgorithm(); if (!substructureAlgorithm) { boolean timeoutMCS1 = cdkMCSAlgorithm(); if ((getMappingCount() == 0 && timeoutMCS1) || (timeoutMCS1 && getMappingCount() > 0 && (getFirstAtomMapping().getCount() != getQuery().getAtomCount() || getFirstAtomMapping().getCount() != getTarget().getAtomCount()))) { vfLibMCSAlgorithm(); } } } catch (CDKException e) { logger.error(Level.SEVERE, null, e); } }
private synchronized void defaultMCSAlgorithm() { try { boolean substructureAlgorithm = substructureAlgorithm(); if (!substructureAlgorithm) { boolean timeoutMCS1 = cdkMCSAlgorithm(); if ((getMappingCount() == 0 && timeoutMCS1) || (timeoutMCS1 && getMappingCount() > 0 && (getFirstAtomMapping().getCount() != getQuery().getAtomCount() || getFirstAtomMapping().getCount() != getTarget().getAtomCount()))) { vfLibMCSAlgorithm(); } } } catch (CDKException e) { logger.error(Level.SEVERE, null, e); } }
synchronized void printMatch(BaseMapping isomorphism) { int overlap = isomorphism.getFirstAtomMapping().isEmpty() ? 0 : isomorphism.getFirstAtomMapping().getCount(); try { System.out.println("Q: " + isomorphism.getQuery().getID() + " T: " + isomorphism.getTarget().getID() + " atoms: " + isomorphism.getQuery().getAtomCount() + " atoms: " + isomorphism.getTarget().getAtomCount() + " overlaps: " + overlap + " mcs " + isomorphism.getFirstAtomMapping().getCommonFragmentAsSMILES()); } catch (CloneNotSupportedException | CDKException ex) { LOGGER.error(Level.SEVERE, "Print MCS ", ex.getMessage()); } }