This commit is contained in:
Greg Landrum
2018-07-16 16:27:08 +02:00
committed by Brian Kelley
parent 4a73e66829
commit 879a40d9ee
4 changed files with 77 additions and 7 deletions

View File

@@ -23,7 +23,7 @@ namespace {
bool isMapped(const Atom *atom) {
return atom->hasProp(common_properties::molAtomMapNumber);
}
}
} // namespace
namespace MolOps {
ROMol *adjustQueryProperties(const ROMol &mol,
@@ -166,15 +166,39 @@ void adjustQueryProperties(RWMol &mol, const AdjustQueryParameters *inParams) {
}
qa->expandQuery(makeAtomInNRingsQuery(nRings));
} // end of adjust ring count
if (params.adjustRingChain &&
!((params.adjustRingChainFlags & ADJUST_IGNORECHAINS) && !nRings) &&
!((params.adjustRingChainFlags & ADJUST_IGNORERINGS) && nRings) &&
!((params.adjustRingChainFlags & ADJUST_IGNOREDUMMIES) && !atomicNum) &&
!((params.adjustRingChainFlags & ADJUST_IGNORENONDUMMIES) &&
atomicNum) &&
!((params.adjustRingChainFlags & ADJUST_IGNOREMAPPED) &&
isMapped(at))) {
QueryAtom *qa;
if (!at->hasQuery()) {
qa = new QueryAtom(*at);
const bool updateLabel = false;
const bool preserveProps = true;
mol.replaceAtom(i, qa, updateLabel, preserveProps);
delete qa;
qa = static_cast<QueryAtom *>(mol.getAtomWithIdx(i));
at = static_cast<Atom *>(qa);
} else {
qa = static_cast<QueryAtom *>(at);
}
ATOM_EQUALS_QUERY *nq = makeAtomInRingQuery();
if (!nRings) nq->setNegation(true);
qa->expandQuery(nq);
} // end of adjust ring chain
} // end of loop over atoms
if (params.makeBondsGeneric) {
ROMol::EDGE_ITER firstB, lastB;
boost::tie(firstB, lastB) = mol.getEdges();
while (firstB != lastB) {
//Bond *bond = mol[*firstB];
// Bond *bond = mol[*firstB];
++firstB;
}
}
}
} // end of MolOps namespace
} // end of RDKit namespace
} // namespace MolOps
} // namespace RDKit

View File

@@ -286,6 +286,8 @@ struct RDKIT_GRAPHMOL_EXPORT AdjustQueryParameters {
bool adjustHeavyDegree; /**< adjust the heavy-atom degree instead of overall
degree */
boost::uint32_t adjustHeavyDegreeFlags;
bool adjustRingChain; /**< add ring-chain queries */
boost::uint32_t adjustRingChainFlags;
AdjustQueryParameters()
: adjustDegree(true),
@@ -299,7 +301,9 @@ struct RDKIT_GRAPHMOL_EXPORT AdjustQueryParameters {
makeAtomsGeneric(false),
makeAtomsGenericFlags(ADJUST_IGNORENONE),
adjustHeavyDegree(false),
adjustHeavyDegreeFlags(ADJUST_IGNOREDUMMIES | ADJUST_IGNORECHAINS) {}
adjustHeavyDegreeFlags(ADJUST_IGNOREDUMMIES | ADJUST_IGNORECHAINS),
adjustRingChain(false),
adjustRingChainFlags(ADJUST_IGNORENONE) {}
};
//! returns a copy of a molecule with query properties adjusted
/*!

View File

@@ -2160,7 +2160,7 @@ Attributes:\n\
- adjustRingCount: \n\
modified atoms have a ring-count query added based on their ring count in the query \n\
- adjustRingCountFlags: \n\
controls which atoms have a ring-cout query added \n\
controls which atoms have a ring-count query added \n\
- makeDummiesQueries: \n\
dummy atoms that do not have a specified isotope are converted to any-atom queries \n\
- aromatizeIfPossible: \n\
@@ -2173,6 +2173,10 @@ Attributes:\n\
convert atoms to generic (any) atoms \n\
- makeAtomsGenericFlags: \n\
controls which atoms are made generic \n\
- adjustRingChain: \n\
modified atoms have a ring-chain query added based on whether or not they are in a ring \n\
- adjustRingChainFlags: \n\
controls which atoms have a ring-chain query added \n\
\n\
A note on the flags controlling which atoms/bonds are modified: \n\
These generally limit the set of atoms/bonds to be modified.\n\
@@ -2206,7 +2210,11 @@ A note on the flags controlling which atoms/bonds are modified: \n\
.def_readwrite("makeAtomsGeneric",
&MolOps::AdjustQueryParameters::makeAtomsGeneric)
.def_readwrite("makeAtomsGenericFlags",
&MolOps::AdjustQueryParameters::makeAtomsGenericFlags);
&MolOps::AdjustQueryParameters::makeAtomsGenericFlags)
.def_readwrite("adjustRingChain",
&MolOps::AdjustQueryParameters::adjustRingChain)
.def_readwrite("adjustRingChainFlags",
&MolOps::AdjustQueryParameters::adjustRingChainFlags);
docString =
"Returns a new molecule where the query properties of atoms have been "

View File

@@ -5839,6 +5839,40 @@ void testAdjustQueryProperties() {
delete qm;
delete aqm;
}
{ // ring-chain membership
std::string smiles = "CC1CCC1";
ROMol *qm = SmartsToMol(smiles);
TEST_ASSERT(qm);
TEST_ASSERT(qm->getNumAtoms() == 5);
MolOps::AdjustQueryParameters params;
params.adjustRingChain = true;
params.adjustDegree = false;
ROMol *aqm = MolOps::adjustQueryProperties(*qm, &params);
TEST_ASSERT(aqm);
TEST_ASSERT(aqm->getNumAtoms() == 5);
{
smiles = "C1CCC12CCC2";
ROMol *m = SmilesToMol(smiles);
TEST_ASSERT(m);
MatchVectType match;
TEST_ASSERT(SubstructMatch(*m, *qm, match));
TEST_ASSERT(!SubstructMatch(*m, *aqm, match));
delete m;
}
{
smiles = "C1CCC1CCC";
ROMol *m = SmilesToMol(smiles);
TEST_ASSERT(m);
MatchVectType match;
TEST_ASSERT(SubstructMatch(*m, *qm, match));
TEST_ASSERT(SubstructMatch(*m, *aqm, match));
delete m;
}
delete qm;
delete aqm;
}
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
}