mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
commit 7f7b5268a62eecd260027e0918abbdf62b100034 Merge:90e9fd36dd173dAuthor: Greg Landrum <greg.landrum@gmail.com> Date: Tue Aug 8 01:19:15 2017 +0200 merge back to master commit6dd173dec6Merge:45a94bde11ad49Author: Brian Kelley <fustigator@gmail.com> Date: Thu Aug 3 07:54:26 2017 -0400 Merge pull request #8 from greglandrum/dev/rgroup-decomposition support using generic iterators in ctor; commite11ad49068Author: Greg Landrum <greg.landrum@gmail.com> Date: Tue Aug 1 06:29:52 2017 +0200 move notebooks to docs commit606c03c28fAuthor: Greg Landrum <greg.landrum@gmail.com> Date: Thu Jul 27 05:13:13 2017 +0200 support using generic iterators in ctor; general comment: this is a useful pattern that we could use elsewhere commit45a94bd663Author: Brian Kelley <brian.kelley@novartis.com> Date: Wed Jul 26 13:30:23 2017 -0400 Updates notebooks commit8f78ba97d3Author: Brian Kelley <brian.kelley@novartis.com> Date: Wed Jul 26 09:00:42 2017 -0400 Updates notebooks commit44728803aeMerge:d67409d4d0b00dAuthor: Brian Kelley <fustigator@gmail.com> Date: Wed Jul 26 08:53:11 2017 -0400 Merge pull request #7 from greglandrum/dev/rgroup-decomposition clean up a couple leaks and some compiler warnings commit4d0b00dd2eAuthor: Greg Landrum <greg.landrum@gmail.com> Date: Wed Jul 26 07:47:56 2017 +0200 clean up a couple leaks and some compiler warnings commitd67409da0cAuthor: Brian Kelley <brian.kelley@novartis.com> Date: Tue Jul 25 11:43:14 2017 -0400 Makes the scoring system more sane commit1b5181dc2fAuthor: Brian Kelley <brian.kelley@novartis.com> Date: Tue Jul 25 10:55:33 2017 -0400 Finalizes enums commit7e9ee61556Author: Brian Kelley <brian.kelley@novartis.com> Date: Tue Jul 25 10:55:18 2017 -0400 Fixes constructor botched in the last commit commitaed2a201bfAuthor: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 24 18:22:42 2017 -0400 Cleans up some code commit95e82a1398Author: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 24 18:14:31 2017 -0400 Removes unused variable commit0b1ed09316Author: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 24 18:14:23 2017 -0400 Slight optimization by combining two loops commited3340a516Author: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 24 13:53:06 2017 -0400 Fixes post increments in for loops commit25b1678a58Author: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 24 13:52:53 2017 -0400 Fixes memory leak and doesn’t call SmartsToMol twice commit86c8c42688Author: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 24 13:52:32 2017 -0400 Adds header guards commitb043e38d3aAuthor: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 24 13:52:25 2017 -0400 Removes unused variable commit631aa77153Author: Brian Kelley <brian.kelley@novartis.com> Date: Tue Jul 11 08:10:39 2017 -0400 Fixes typo in filename commitd6e0dc753aAuthor: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 10 14:48:04 2017 -0400 Fixes c++11 style enums commitb9a31eae9aAuthor: Brian Kelley <brian.kelley@novartis.com> Date: Mon Jul 10 14:00:04 2017 -0400 Adds RGroupDecomposition attempt
165 lines
5.8 KiB
C++
165 lines
5.8 KiB
C++
//
|
|
// Copyright (c) 2015 Greg Landrum
|
|
//
|
|
// @@ All Rights Reserved @@
|
|
// This file is part of the RDKit.
|
|
// The contents are covered by the terms of the BSD license
|
|
// which is included in the file license.txt, found at the root
|
|
// of the RDKit source tree.
|
|
//
|
|
#include <GraphMol/GraphMol.h>
|
|
#include <GraphMol/QueryAtom.h>
|
|
#include <GraphMol/QueryBond.h>
|
|
#include <GraphMol/MolOps.h>
|
|
#include <GraphMol/QueryOps.h>
|
|
#include <GraphMol/AtomIterators.h>
|
|
#include <GraphMol/BondIterators.h>
|
|
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
namespace RDKit {
|
|
namespace {
|
|
bool isMapped(const Atom *atom) {
|
|
return atom->hasProp(common_properties::molAtomMapNumber);
|
|
}
|
|
}
|
|
|
|
namespace MolOps {
|
|
ROMol *adjustQueryProperties(const ROMol &mol,
|
|
const AdjustQueryParameters *params) {
|
|
RWMol *res = new RWMol(mol);
|
|
try {
|
|
adjustQueryProperties(*res, params);
|
|
} catch (MolSanitizeException &se) {
|
|
delete res;
|
|
throw se;
|
|
}
|
|
return static_cast<ROMol *>(res);
|
|
}
|
|
void adjustQueryProperties(RWMol &mol, const AdjustQueryParameters *inParams) {
|
|
AdjustQueryParameters params;
|
|
if (inParams) {
|
|
params = *inParams;
|
|
}
|
|
const RingInfo *ringInfo = mol.getRingInfo();
|
|
|
|
if (params.aromatizeIfPossible) {
|
|
unsigned int failed;
|
|
sanitizeMol(mol, failed, SANITIZE_SYMMRINGS | SANITIZE_SETAROMATICITY);
|
|
} else {
|
|
if (!ringInfo->isInitialized()) {
|
|
MolOps::symmetrizeSSSR(mol);
|
|
}
|
|
}
|
|
|
|
if (params.makeAtomsGeneric) {
|
|
for (unsigned int i = 0; i < mol.getNumAtoms(); ++i) {
|
|
if (!((params.makeAtomsGenericFlags & ADJUST_IGNORECHAINS) &&
|
|
!ringInfo->numAtomRings(i)) &&
|
|
!((params.makeAtomsGenericFlags & ADJUST_IGNORERINGS) &&
|
|
ringInfo->numAtomRings(i)) &&
|
|
!((params.adjustDegreeFlags & ADJUST_IGNOREMAPPED) &&
|
|
isMapped(mol.getAtomWithIdx(i)))) {
|
|
QueryAtom *qa = new QueryAtom();
|
|
qa->setQuery(makeAtomNullQuery());
|
|
const bool updateLabel = false;
|
|
const bool preserveProps = true;
|
|
mol.replaceAtom(i, qa, updateLabel, preserveProps);
|
|
delete qa;
|
|
}
|
|
}
|
|
} // end of makeAtomsGeneric
|
|
if (params.makeBondsGeneric) {
|
|
for (unsigned int i = 0; i < mol.getNumBonds(); ++i) {
|
|
if (!((params.makeBondsGenericFlags & ADJUST_IGNORECHAINS) &&
|
|
!ringInfo->numBondRings(i)) &&
|
|
!((params.makeBondsGenericFlags & ADJUST_IGNORERINGS) &&
|
|
ringInfo->numBondRings(i))) {
|
|
QueryBond *qb = new QueryBond();
|
|
qb->setQuery(makeBondNullQuery());
|
|
const bool preserveProps = true;
|
|
mol.replaceBond(i, qb, preserveProps);
|
|
delete qb;
|
|
}
|
|
}
|
|
} // end of makeBondsGeneric
|
|
for (unsigned int i = 0; i < mol.getNumAtoms(); ++i) {
|
|
Atom *at = mol.getAtomWithIdx(i);
|
|
// pull properties we need from the atom here, once we
|
|
// create a query atom they may no longer be valid.
|
|
unsigned int nRings = ringInfo->numAtomRings(i);
|
|
int atomicNum = at->getAtomicNum();
|
|
if (params.makeDummiesQueries && atomicNum == 0 && !at->hasQuery() &&
|
|
!at->getIsotope()) {
|
|
QueryAtom *qa = new QueryAtom();
|
|
qa->setQuery(makeAtomNullQuery());
|
|
const bool updateLabel = false;
|
|
const bool preserveProps = true;
|
|
mol.replaceAtom(i, qa, updateLabel, preserveProps);
|
|
delete qa;
|
|
at = mol.getAtomWithIdx(i);
|
|
} // end of makeDummiesQueries
|
|
if (params.adjustDegree &&
|
|
!((params.adjustDegreeFlags & ADJUST_IGNORECHAINS) && !nRings) &&
|
|
!((params.adjustDegreeFlags & ADJUST_IGNORERINGS) && nRings) &&
|
|
!((params.adjustDegreeFlags & ADJUST_IGNOREDUMMIES) && !atomicNum) &&
|
|
!((params.adjustDegreeFlags & ADJUST_IGNORENONDUMMIES) && atomicNum) &&
|
|
!((params.adjustDegreeFlags & 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);
|
|
}
|
|
if (params.adjustDegree == 2) {
|
|
ATOM_EQUALS_QUERY *tmp = new ATOM_EQUALS_QUERY;
|
|
tmp->setVal(qa->getTotalDegree() - qa->getTotalNumHs(true));
|
|
tmp->setDataFunc(queryAtomHeavyAtomDegree);
|
|
tmp->setDescription("queryAtomHeavyDegree");
|
|
qa->expandQuery(tmp);
|
|
} else {
|
|
qa->expandQuery(makeAtomExplicitDegreeQuery(qa->getDegree()));
|
|
}
|
|
} // end of adjust degree
|
|
if (params.adjustRingCount &&
|
|
!((params.adjustRingCountFlags & ADJUST_IGNORECHAINS) && !nRings) &&
|
|
!((params.adjustRingCountFlags & ADJUST_IGNORERINGS) && nRings) &&
|
|
!((params.adjustRingCountFlags & ADJUST_IGNOREDUMMIES) && !atomicNum) &&
|
|
!((params.adjustRingCountFlags & ADJUST_IGNORENONDUMMIES) &&
|
|
!((params.adjustRingCountFlags & ADJUST_IGNOREMAPPED) &&
|
|
isMapped(at)) &&
|
|
atomicNum)) {
|
|
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);
|
|
}
|
|
qa->expandQuery(makeAtomInNRingsQuery(nRings));
|
|
} // end of adjust ring count
|
|
} // end of loop over atoms
|
|
if (params.makeBondsGeneric) {
|
|
ROMol::EDGE_ITER firstB, lastB;
|
|
boost::tie(firstB, lastB) = mol.getEdges();
|
|
while (firstB != lastB) {
|
|
BOND_SPTR bond = mol[*firstB];
|
|
++firstB;
|
|
}
|
|
}
|
|
}
|
|
} // end of MolOps namespace
|
|
} // end of RDKit namespace
|