int QueryMolecule::parseQueryAtom (QueryMolecule& qm, int aid, Array<int>& list) { QueryMolecule::Atom& qa = qm.getAtom(aid); QueryMolecule::Atom* qc = stripKnownAttrs(qa); if (qc != NULL && isNotAtom(*qc, ELEM_H)) return QUERY_ATOM_A; bool notList = false; if (collectAtomList(qa, list, notList) || (qa.type == QueryMolecule::OP_NOT && collectAtomList(*qa.child(0), list, notList) && !notList)) { // !notList is to check there's no double negation if (list.size() == 0) return -1; notList = notList || qa.type == QueryMolecule::OP_NOT; if (!notList && list.size() == 5 && list[0] == ELEM_F && list[1] == ELEM_Cl && list[2] == ELEM_Br && list[3] == ELEM_I && list[4] == ELEM_At) return QUERY_ATOM_X; if (notList && list.size() == 2 && ((list[0] == ELEM_C && list[1] == ELEM_H) || (list[0] == ELEM_H && list[1] == ELEM_C))) return QUERY_ATOM_Q; return notList ? QUERY_ATOM_NOTLIST : QUERY_ATOM_LIST; } return -1; }
bool MoleculePiSystemsMatcher::_fixAtoms (QueryMolecule &query, const int *mapping) { // Fix charges for (int qv = query.vertexBegin(); qv != query.vertexEnd(); qv = query.vertexNext(qv)) { int v = mapping[qv]; if (v < 0) continue; // Such vertex must be ignored int pi_system_idx = _atom_pi_system_idx[v]; if (pi_system_idx == _NOT_IN_PI_SYSTEM) continue; _Pi_System &pi_system = _pi_systems[pi_system_idx]; QueryMolecule::Atom &qatom = query.getAtom(qv); int pv = pi_system.inv_mapping[v]; int charge = query.getAtomCharge(qv); if (charge != CHARGE_UNKNOWN) { bool ret = pi_system.localizer->fixAtomCharge(pv, charge); if (!ret) return false; } else if (qatom.hasConstraint(QueryMolecule::ATOM_CHARGE)) throw Error("Unsupported atom charge specified"); int valence = query.getExplicitValence(qv); if (valence != -1) { bool ret = pi_system.localizer->fixAtomConnectivity(pv, valence); if (!ret) return false; } else if (qatom.hasConstraint(QueryMolecule::ATOM_VALENCE)) throw Error("Unsupported atom charge specified"); } return true; }
bool QueryMolecule::queryAtomIsRegular (QueryMolecule& qm, int aid) { QueryMolecule::Atom& qa = qm.getAtom(aid); QueryMolecule::Atom* qc = stripKnownAttrs(qa); return qc && qc->type == QueryMolecule::ATOM_NUMBER; }
bool MoleculeSubstructureMatcher::_shouldUnfoldTargetHydrogens (QueryMolecule &query, bool is_fragment, bool disable_folding_query_h) { int i, j; for (i = query.vertexBegin(); i != query.vertexEnd(); i = query.vertexNext(i)) { // skip R-atoms if (query.isRSite(i)) continue; if (query.possibleAtomNumberAndIsotope(i, ELEM_H, 0)) { const Vertex &vertex = query.getVertex(i); // Degree 2 or higher => definilely not a hydrogen if (vertex.degree() > 1) continue; // Can be lone hydrogen? if (vertex.degree() == 0) return true; // degree is 1 at this point int edge_idx = vertex.neiEdge(vertex.neiBegin()); // is it is double or triple bond => not hydrogen if (query.getBondOrder(edge_idx) > 1) continue; // ring bond? if (query.getBondTopology(edge_idx) == TOPOLOGY_RING) continue; // can be something other than hydrogen? if (query.getAtomNumber(i) == -1) return true; if (is_fragment && i == query.vertexBegin()) // If first atom in a fragment is hydrogen then hydrogens should // be unfolded because of the matching logic: when fragment will be // matched this first hydrogen should match some atom. // If hydrogens is not be unfolded in this case then // [$([#1][N])]C will not match NC. return true; // If we need to find all embeddings then query hydrogens cannot be ignored: // For example, if we are searching number of matcher for N-[#1] in N then // it should 3 instead of 1 if (disable_folding_query_h) return true; // Check if hydrogen forms a cis-trans bond or stereocenter int nei_vertex_idx = vertex.neiVertex(vertex.neiBegin()); if (query.stereocenters.exists(nei_vertex_idx)) return true; // For example for this query hydrogens should be unfolded: [H]\\C=C/C const Vertex &nei_vertex = query.getVertex(nei_vertex_idx); for (int nei = nei_vertex.neiBegin(); nei != nei_vertex.neiEnd(); nei = nei_vertex.neiNext(nei)) { int edge = nei_vertex.neiEdge(nei); if (query.cis_trans.getParity(edge) != 0) return true; } } if (_shouldUnfoldTargetHydrogens_A(&query.getAtom(i), is_fragment, disable_folding_query_h)) return true; } MoleculeRGroups &rgroups = query.rgroups; int n_rgroups = rgroups.getRGroupCount(); for (i = 1; i <= n_rgroups; i++) { PtrPool<BaseMolecule> &frags = rgroups.getRGroup(i).fragments; for (j = frags.begin(); j != frags.end(); j = frags.next(j)) if (_shouldUnfoldTargetHydrogens(frags[j]->asQueryMolecule(), is_fragment, disable_folding_query_h)) return true; } return false; }