private boolean checkQuery(IQueryAtomContainer query) { if (!(query instanceof PharmacophoreQuery)) return false; HashMap<String, String> map = new HashMap<String, String>(); for (int i = 0; i < query.getAtomCount(); i++) { IQueryAtom atom = (IQueryAtom) query.getAtom(i); if (!(atom instanceof PharmacophoreQueryAtom)) return false; PharmacophoreQueryAtom pqatom = (PharmacophoreQueryAtom) atom; String label = pqatom.getSymbol(); String smarts = pqatom.getSmarts(); if (!map.containsKey(label)) map.put(label, smarts); else { if (!map.get(label).equals(smarts)) return false; } } return true; }
/** * Constructor for the McGregor algorithm. * * @param source * @param target * @param mappings */ public McGregor(IQueryAtomContainer source, IAtomContainer target, List<List<Integer>> mappings) { this.shouldMatchRings = true; this.bondMatch = true; this.matchAtomType = true; this.target = target; this.mappings = Collections.synchronizedList(mappings); this.bestarcsleft = 0; setIterationManager(new IterationManager((source.getAtomCount() + this.target.getAtomCount()) * 1000)); if (!mappings.isEmpty()) { this.globalMCSSize = mappings.get(0).size(); } else { this.globalMCSSize = 0; } this.modifiedARCS = Collections.synchronizedList(new ArrayList<Integer>()); this.bestARCS = new Stack<>(); this.newMatrix = false; }
private boolean checkQuery(IQueryAtomContainer query) { if (!(query instanceof PharmacophoreQuery)) return false; HashMap<String, String> map = new HashMap<String, String>(); for (int i = 0; i < query.getAtomCount(); i++) { IQueryAtom atom = (IQueryAtom) query.getAtom(i); if (!(atom instanceof PharmacophoreQueryAtom)) return false; PharmacophoreQueryAtom pqatom = (PharmacophoreQueryAtom) atom; String label = pqatom.getSymbol(); String smarts = pqatom.getSmarts(); if (!map.containsKey(label)) map.put(label, smarts); else { if (!map.get(label).equals(smarts)) return false; } } return true; }
/** * Returns single mapping solutions. * * @param source * @param target * @return Mappings * @throws CDKException */ protected synchronized List<Map<IAtom, IAtom>> getOverLaps( IQueryAtomContainer source, IAtomContainer target, AtomMatcher am) throws CDKException { List<Map<IAtom, IAtom>> mappings = new ArrayList<>(); this.source = source; this.target = target; if (source.getAtomCount() > 0) { setSingleAtomMap(mappings, am); } return postFilter(mappings); }
/** * Constructor for the McGregor algorithm. * * @param source * @param target * @param mappings */ public McGregor(IQueryAtomContainer source, IAtomContainer target, List<List<Integer>> mappings) { this.shouldMatchRings = true; this.bondMatch = true; this.matchAtomType = true; this.target = target; this.mappings = Collections.synchronizedList(mappings); this.bestarcsleft = 0; setIterationManager(new IterationManager((source.getAtomCount() + this.target.getAtomCount()) * 1000)); if (!mappings.isEmpty()) { this.globalMCSSize = mappings.get(0).size(); } else { this.globalMCSSize = 0; } this.modifiedARCS = Collections.synchronizedList(new ArrayList<Integer>()); this.bestARCS = new Stack<>(); this.newMatrix = false; }
@Override public boolean matches(IAtom atom) { if (!((IQueryAtom) query.getAtom(0)).matches(atom)) return false; if (query.getAtomCount() == 1) return true; IAtomContainer target = invariants(atom).target(); return cache.getUnchecked(target).get(target.indexOf(atom)); } }
private synchronized void mcsBuilder(IQueryAtomContainer mol1, IAtomContainer mol2) { int rBondCount = mol1.getBondCount(); int pBondCount = mol2.getBondCount(); int rAtomCount = mol1.getAtomCount(); int pAtomCount = mol2.getAtomCount(); if ((rBondCount == 0 && rAtomCount > 0) || (pBondCount == 0 && pAtomCount > 0)) { singleMapping(); } else { chooseAlgorithm(rBondCount, pBondCount); } if (!allAtomMCS.isEmpty() && !firstAtomMCS.isEmpty() && firstAtomMCS.size() > 1) { setAllBondMaps(makeBondMapsOfAtomMaps(mol1, mol2, allAtomMCS)); if (getAllBondMaps().iterator().hasNext()) { setFirstBondMap(getAllBondMaps().iterator().next()); } } }
public Object visit(ASTChirality node, Object data) { ChiralityAtom atom = new ChiralityAtom(builder); atom.setClockwise(node.isClockwise()); atom.setUnspecified(node.isUnspecified()); tetrahedral.set(query.getAtomCount()); return atom; }
/** * Returns single mapping solutions. * @param source * @param target * @param removeHydrogen * @return Mappings * @throws CDKException */ protected List<Map<IAtom, IAtom>> getOverLaps(IQueryAtomContainer source, IAtomContainer target, boolean removeHydrogen) throws CDKException { mappings = new ArrayList<Map<IAtom, IAtom>>(); connectedBondOrder = new TreeMap<Integer, Double>(); this.source = source; this.target = target; if (source.getAtomCount() == 1 || (source.getAtomCount() > 0 && source.getBondCount() == 0)) { setSourceSingleAtomMap(source, removeHydrogen); } if (target.getAtomCount() == 1 || (target.getAtomCount() > 0 && target.getBondCount() == 0)) { setTargetSingleAtomMap(removeHydrogen); } postFilter(); return mappings; }
/** * Returns single mapping solutions. * * @param source * @param target * @return Mappings * @throws CDKException */ protected synchronized List<Map<IAtom, IAtom>> getOverLaps( IQueryAtomContainer source, IAtomContainer target) throws CDKException { List<Map<IAtom, IAtom>> mappings = new ArrayList<>(); this.source = source; this.target = target; if (source.getAtomCount() == 1 || (source.getAtomCount() > 0 && source.getBondCount() == 0)) { setSourceSingleAtomMap(mappings); } if (target.getAtomCount() == 1 || (target.getAtomCount() > 0 && target.getBondCount() == 0)) { setTargetSingleAtomMap(mappings); } return postFilter(mappings); }
/** * Returns single mapping solutions. * * @param source * @param target * @return Mappings * @throws CDKException */ protected synchronized List<Map<IAtom, IAtom>> getOverLaps( IQueryAtomContainer source, IAtomContainer target) throws CDKException { List<Map<IAtom, IAtom>> mappings = new ArrayList<>(); this.source = source; this.target = target; if (source.getAtomCount() == 1 || (source.getAtomCount() > 0 && source.getBondCount() == 0)) { setSourceSingleAtomMap(mappings); } if (target.getAtomCount() == 1 || (target.getAtomCount() > 0 && target.getBondCount() == 0)) { setTargetSingleAtomMap(mappings); } return postFilter(mappings); }
private synchronized void mcsBuilder(IQueryAtomContainer mol1, IAtomContainer mol2) { int rBondCount = mol1.getBondCount(); int pBondCount = mol2.getBondCount(); int rAtomCount = mol1.getAtomCount(); int pAtomCount = mol2.getAtomCount(); if ((rBondCount == 0 && rAtomCount > 0) || (pBondCount == 0 && pAtomCount > 0)) { singleMapping(); } else { chooseAlgorithm(); } }
private synchronized void mcsBuilder(IQueryAtomContainer mol1, IAtomContainer mol2) { int rBondCount = mol1.getBondCount(); int pBondCount = mol2.getBondCount(); int rAtomCount = mol1.getAtomCount(); int pAtomCount = mol2.getAtomCount(); if ((rBondCount == 0 && rAtomCount > 0) || (pBondCount == 0 && pAtomCount > 0)) { singleMapping(); } else { chooseAlgorithm(); } }
State(IQueryAtomContainer source, IAtomContainer target) { this.size = 0; this.sourceTerminalSize = 0; this.targetTerminalSize = 0; this.source = source; this.target = target; this.ownSharedState = true; this.matches = new boolean[this.source.getAtomCount()][this.target.getAtomCount()]; this.isMatchPossible = isFeasible(); this.lastAddition = new Pair<>(-1, -1); this.sharedState = new SharedState(source.getAtomCount(), target.getAtomCount()); this.shouldMatchBonds = true; this.shouldMatchRings = true; this.shouldMatchAtomType = true; }
State(IQueryAtomContainer source, IAtomContainer target) { this.size = 0; this.sourceTerminalSize = 0; this.targetTerminalSize = 0; this.source = source; this.target = target; this.ownSharedState = true; this.matches = new boolean[this.source.getAtomCount()][this.target.getAtomCount()]; this.isMatchPossible = isFeasible(); this.lastAddition = new Pair<>(-1, -1); this.sharedState = new SharedState(source.getAtomCount(), target.getAtomCount()); this.shouldMatchBonds = true; this.shouldMatchRings = true; this.shouldMatchAtomType = true; }
/** * {@inheritDoc} */ @Override public Mappings matchAll(IAtomContainer mol) { if (mol.getAtomCount() < query.getAtomCount()) return new Mappings(query, mol, Collections.<int[]>emptySet()); if (mol.getAtomCount() > 0) checkCompatibleAPI(mol.getAtom(0)); DfState local = new DfState(state); local.setMol(mol); return filter(new Mappings(query, mol, local), query, mol); }
/** * Match the pattern at the provided root. * * @param root the root atom of the molecule * @return mappings * @see Mappings */ Mappings matchRoot(IAtom root) { checkCompatibleAPI(root); IAtomContainer mol = root.getContainer(); if (query.getAtomCount() > 0 && ((IQueryAtom) query.getAtom(0)).matches(root)) { DfState local = new DfState(state); local.setRoot(root); return filter(new Mappings(query, mol, local), query, mol); } else { return new Mappings(query, mol, Collections.<int[]>emptySet()); } }
DfState(IQueryAtomContainer query) { IChemObjectBuilder builder = query.getBuilder(); if (builder == null) { builder = findBuilder(); if (builder == null) throw new IllegalArgumentException("Please ensure query molecule" + "has a IChemObjectBuilder set!"); } IAtomContainer tmp = builder.newAtomContainer(); tmp.add(query); this.qbonds = new IQueryBond[tmp.getBondCount()]; this.amap = new int[query.getAtomCount()]; int stackSize = 0; for (IAtom atom : tmp.atoms()) { if (atom instanceof IQueryAtom) { if (amap[atom.getIndex()] == 0) { stackSize += prepare(atom, null) + 1; } } else throw new IllegalArgumentException( "All atoms must be IQueryAtoms!"); } this.stack = new StackFrame[stackSize + 2]; for (int i = 0; i < stack.length; i++) this.stack[i] = new StackFrame(); this.numAtoms = amap.length; this.query = tmp; }
State(IQueryAtomContainer source, IAtomContainer target) { this.size = 0; this.sourceTerminalSize = 0; this.targetTerminalSize = 0; this.source = source; this.target = target; this.ownSharedState = true; this.matches = new boolean[this.source.getAtomCount()][this.target.getAtomCount()]; this.isMatchPossible = isFeasible(); this.lastAddition = new Pair<>(-1, -1); this.sharedState = new SharedState(source.getAtomCount(), target.getAtomCount()); this.am = AtomMatcher.forQuery(); this.bm = BondMatcher.forQuery(); }
@Test public void testReadPcoreDef() throws Exception { String filename = "data/pcore/pcore.xml"; InputStream ins = PharmacophoreUtilityTest.class.getClassLoader().getResourceAsStream(filename); List<PharmacophoreQuery> defs = PharmacophoreUtils.readPharmacophoreDefinitions(ins); Assert.assertEquals(2, defs.size()); IQueryAtomContainer def1 = defs.get(0); Assert.assertEquals(4, def1.getAtomCount()); Assert.assertEquals(2, def1.getBondCount()); Assert.assertEquals("An imaginary pharmacophore definition", def1.getProperty("description")); Assert.assertEquals("Imaginary", def1.getTitle()); IQueryAtomContainer def2 = defs.get(1); Assert.assertEquals(3, def2.getAtomCount()); Assert.assertEquals(3, def2.getBondCount()); Assert.assertNull(def2.getTitle()); String[] ids = {"Aromatic", "Hydroxyl", "BasicAmine"}; for (IAtom atom : def2.atoms()) { String sym = atom.getSymbol(); boolean found = false; for (String s : ids) { if (sym.equals(s)) { found = true; break; } } Assert.assertTrue("'" + sym + "' in pcore.xml is invalid", found); } }