14#include <boost/function.hpp>
23#include <boost/dynamic_bitset.hpp>
29namespace MolStandardize {
35namespace TautomerScoringFunctions {
79 const ROMol &mol,
const std::vector<SubstructTerm> &
terms =
109 d_numModifiedAtoms(a),
110 d_numModifiedBonds(b),
116 size_t d_numModifiedAtoms;
117 size_t d_numModifiedBonds;
142 return (d_it == other.d_it);
145 return !(*
this == other);
167 SmilesTautomerMap::const_iterator d_it;
171 : d_tautomers(other.d_tautomers),
172 d_status(other.d_status),
173 d_modifiedAtoms(other.d_modifiedAtoms),
174 d_modifiedBonds(other.d_modifiedBonds) {
175 fillTautomersItVec();
181 size_t size()
const {
return d_tautomers.size(); }
182 bool empty()
const {
return d_tautomers.empty(); }
184 PRECONDITION(pos < d_tautomers.size(),
"index out of bounds");
185 return d_tautomersItVec.at(pos)->second.tautomer;
189 return d_modifiedAtoms;
192 return d_modifiedBonds;
196 std::vector<ROMOL_SPTR> tautomerVec;
197 tautomerVec.reserve(d_tautomers.size());
199 d_tautomers.begin(), d_tautomers.end(), std::back_inserter(tautomerVec),
203 std::vector<ROMOL_SPTR>
operator()()
const {
return tautomers(); }
204 std::vector<std::string>
smiles()
const {
205 std::vector<std::string> smilesVec;
206 smilesVec.reserve(d_tautomers.size());
207 std::transform(d_tautomers.begin(), d_tautomers.end(),
208 std::back_inserter(smilesVec),
215 void fillTautomersItVec() {
216 for (
auto it = d_tautomers.begin(); it != d_tautomers.end(); ++it) {
217 d_tautomersItVec.push_back(it);
221 SmilesTautomerMap d_tautomers;
224 std::vector<SmilesTautomerMap::const_iterator> d_tautomersItVec;
227 TautomerEnumeratorStatus d_status;
229 boost::dynamic_bitset<> d_modifiedAtoms;
231 boost::dynamic_bitset<> d_modifiedBonds;
244 : dp_catalog(tautCat),
245 d_maxTautomers(1000),
246 d_maxTransforms(1000),
247 d_removeSp3Stereo(true),
248 d_removeBondStereo(true),
249 d_removeIsotopicHs(true),
250 d_reassignStereo(true) {}
253 : dp_catalog(other.dp_catalog),
254 d_callback(other.d_callback),
255 d_maxTautomers(other.d_maxTautomers),
256 d_maxTransforms(other.d_maxTransforms),
257 d_removeSp3Stereo(other.d_removeSp3Stereo),
258 d_removeBondStereo(other.d_removeBondStereo),
259 d_removeIsotopicHs(other.d_removeIsotopicHs),
260 d_reassignStereo(other.d_reassignStereo) {}
262 if (
this == &other) {
265 dp_catalog = other.dp_catalog;
266 d_callback = other.d_callback;
267 d_maxTautomers = other.d_maxTautomers;
268 d_maxTransforms = other.d_maxTransforms;
269 d_removeSp3Stereo = other.d_removeSp3Stereo;
270 d_removeBondStereo = other.d_removeBondStereo;
271 d_removeIsotopicHs = other.d_removeIsotopicHs;
272 d_reassignStereo = other.d_reassignStereo;
277 d_maxTautomers = maxTautomers;
287 d_maxTransforms = maxTransforms;
299 d_removeSp3Stereo = removeSp3Stereo;
313 d_removeBondStereo = removeBondStereo;
323 d_removeIsotopicHs = removeIsotopicHs;
334 d_reassignStereo = reassignStereo;
346 d_callback.reset(callback);
376 "please use the form returning a TautomerEnumeratorResult "
377 "instead")]] std::vector<ROMOL_SPTR>
379 boost::dynamic_bitset<> *modifiedBonds =
nullptr)
const;
383 boost::function<
int(
const ROMol &mol)> scoreFunc =
384 TautomerScoringFunctions::scoreTautomer)
const;
390 template <
class Iterable,
391 typename std::enable_if<
392 !std::is_same<Iterable, TautomerEnumeratorResult>::value,
395 boost::function<
int(
const ROMol &mol)> scoreFunc =
396 TautomerScoringFunctions::scoreTautomer)
const {
398 if (tautomers.size() == 1) {
399 bestMol = *tautomers.begin();
402 int bestScore = std::numeric_limits<int>::min();
403 std::string bestSmiles =
"";
404 for (
const auto &t : tautomers) {
405 auto score = scoreFunc(*t);
406#ifdef VERBOSE_ENUMERATION
407 std::cerr <<
" " << MolToSmiles(*t) <<
" " << score << std::endl;
409 if (score > bestScore) {
411 bestSmiles = MolToSmiles(*t);
413 }
else if (score == bestScore) {
414 auto smiles = MolToSmiles(*t);
415 if (smiles < bestSmiles) {
423 static const bool cleanIt =
true;
424 static const bool force =
true;
425 MolOps::assignStereochemistry(*res, cleanIt, force);
444 boost::function<
int(
const ROMol &mol)> scoreFunc =
445 TautomerScoringFunctions::scoreTautomer)
const;
447 boost::function<
int(
const ROMol &mol)> scoreFunc =
448 TautomerScoringFunctions::scoreTautomer)
const;
451 bool setTautomerStereoAndIsoHs(
const ROMol &mol,
ROMol &taut,
453 std::shared_ptr<TautomerCatalog> dp_catalog;
454 std::shared_ptr<TautomerEnumeratorCallback> d_callback;
455 unsigned int d_maxTautomers;
456 unsigned int d_maxTransforms;
457 bool d_removeSp3Stereo;
458 bool d_removeBondStereo;
459 bool d_removeIsotopicHs;
460 bool d_reassignStereo;
#define PRECONDITION(expr, mess)
A Catalog with a hierarchical structure.
virtual bool operator()(const ROMol &, const TautomerEnumeratorResult &)=0
virtual ~TautomerEnumeratorCallback()
TautomerEnumeratorCallback()
const_iterator & operator++()
const_iterator operator--(int)
const ROMOL_SPTR & reference
pointer operator->() const
std::ptrdiff_t difference_type
std::bidirectional_iterator_tag iterator_category
reference operator*() const
bool operator!=(const const_iterator &other) const
const_iterator operator++(int)
bool operator==(const const_iterator &other) const
const_iterator(const SmilesTautomerMap::const_iterator &it)
const_iterator & operator--()
Contains results of tautomer enumeration.
const SmilesTautomerMap & smilesTautomerMap() const
const boost::dynamic_bitset & modifiedBonds() const
TautomerEnumeratorResult()
const boost::dynamic_bitset & modifiedAtoms() const
const const_iterator end() const
const const_iterator begin() const
const ROMOL_SPTR & operator[](size_t pos) const
std::vector< ROMOL_SPTR > tautomers() const
TautomerEnumeratorResult(const TautomerEnumeratorResult &other)
std::vector< ROMOL_SPTR > operator()() const
const ROMOL_SPTR & at(size_t pos) const
std::vector< std::string > smiles() const
TautomerEnumeratorStatus status() const
void setRemoveSp3Stereo(bool removeSp3Stereo)
TautomerEnumerator(const CleanupParameters ¶ms=CleanupParameters())
bool getRemoveBondStereo()
void setRemoveIsotopicHs(bool removeIsotopicHs)
bool getRemoveSp3Stereo()
unsigned int getMaxTransforms()
std::vector< ROMOL_SPTR > enumerate(const ROMol &mol, boost::dynamic_bitset<> *modifiedAtoms, boost::dynamic_bitset<> *modifiedBonds=nullptr) const
ROMol * pickCanonical(const TautomerEnumeratorResult &tautRes, boost::function< int(const ROMol &mol)> scoreFunc=TautomerScoringFunctions::scoreTautomer) const
returns the canonical tautomer from a TautomerEnumeratorResult
TautomerEnumeratorCallback * getCallback() const
ROMol * canonicalize(const ROMol &mol, boost::function< int(const ROMol &mol)> scoreFunc=TautomerScoringFunctions::scoreTautomer) const
returns the canonical tautomer for a molecule
bool getRemoveIsotopicHs()
TautomerEnumerator(TautomerCatalog *tautCat)
void canonicalizeInPlace(RWMol &mol, boost::function< int(const ROMol &mol)> scoreFunc=TautomerScoringFunctions::scoreTautomer) const
void setReassignStereo(bool reassignStereo)
void setRemoveBondStereo(bool removeBondStereo)
TautomerEnumeratorResult enumerate(const ROMol &mol) const
returns a TautomerEnumeratorResult structure for the input molecule
TautomerEnumerator & operator=(const TautomerEnumerator &other)
unsigned int getMaxTautomers()
void setCallback(TautomerEnumeratorCallback *callback)
TautomerEnumerator(const TautomerEnumerator &other)
void setMaxTransforms(unsigned int maxTransforms)
void setMaxTautomers(unsigned int maxTautomers)
ROMol * pickCanonical(const Iterable &tautomers, boost::function< int(const ROMol &mol)> scoreFunc=TautomerScoringFunctions::scoreTautomer) const
Tautomer(ROMOL_SPTR t, ROMOL_SPTR k, size_t a=0, size_t b=0)
RWMol is a molecule class that is intended to be edited.
#define RDKIT_MOLSTANDARDIZE_EXPORT
RDKIT_MOLSTANDARDIZE_EXPORT int scoreHeteroHs(const ROMol &mol)
int scoreTautomer(const ROMol &mol)
const std::string tautomerScoringVersion
RDKIT_MOLSTANDARDIZE_EXPORT const std::vector< SubstructTerm > & getDefaultTautomerScoreSubstructs()
RDKIT_MOLSTANDARDIZE_EXPORT int scoreRings(const ROMol &mol)
RDKIT_MOLSTANDARDIZE_EXPORT int scoreSubstructs(const ROMol &mol, const std::vector< SubstructTerm > &terms=getDefaultTautomerScoreSubstructs())
scoreSubstructs scores the molecule based on the substructure definitions
RDKIT_MOLSTANDARDIZE_EXPORT const TautomerTransformDefs defaultTautomerTransformsv1
std::map< std::string, Tautomer > SmilesTautomerMap
TautomerEnumerator * tautomerEnumeratorFromParams(const CleanupParameters ¶ms)
TautomerEnumerator * getV1TautomerEnumerator()
RDCatalog::HierarchCatalog< TautomerCatalogEntry, TautomerCatalogParams, int > TautomerCatalog
std::pair< std::string, Tautomer > SmilesTautomerPair
bool rdvalue_is(const RDValue_cast_t)
boost::shared_ptr< ROMol > ROMOL_SPTR
SubstructTerm(const SubstructTerm &rhs)=default
SubstructTerm(std::string aname, std::string asmarts, int ascore)
bool operator==(const SubstructTerm &rhs) const