14#include <boost/function.hpp>
23#include <boost/dynamic_bitset.hpp>
29namespace MolStandardize {
35namespace TautomerScoringFunctions {
58 Tautomer() : d_numModifiedAtoms(0), d_numModifiedBonds(0), d_done(
false) {}
62 d_numModifiedAtoms(a),
63 d_numModifiedBonds(b),
69 size_t d_numModifiedAtoms;
70 size_t d_numModifiedBonds;
95 return (d_it == other.d_it);
98 return !(*
this == other);
120 SmilesTautomerMap::const_iterator d_it;
124 : d_tautomers(other.d_tautomers),
125 d_status(other.d_status),
126 d_modifiedAtoms(other.d_modifiedAtoms),
127 d_modifiedBonds(other.d_modifiedBonds) {
128 fillTautomersItVec();
134 size_t size()
const {
return d_tautomers.size(); }
135 bool empty()
const {
return d_tautomers.empty(); }
137 PRECONDITION(pos < d_tautomers.size(),
"index out of bounds");
138 return d_tautomersItVec.at(pos)->second.tautomer;
142 return d_modifiedAtoms;
145 return d_modifiedBonds;
149 std::vector<ROMOL_SPTR> tautomerVec;
150 tautomerVec.reserve(d_tautomers.size());
152 d_tautomers.begin(), d_tautomers.end(), std::back_inserter(tautomerVec),
156 std::vector<ROMOL_SPTR>
operator()()
const {
return tautomers(); }
157 std::vector<std::string>
smiles()
const {
158 std::vector<std::string> smilesVec;
159 smilesVec.reserve(d_tautomers.size());
160 std::transform(d_tautomers.begin(), d_tautomers.end(),
161 std::back_inserter(smilesVec),
168 void fillTautomersItVec() {
169 for (
auto it = d_tautomers.begin(); it != d_tautomers.end(); ++it) {
170 d_tautomersItVec.push_back(it);
174 SmilesTautomerMap d_tautomers;
177 std::vector<SmilesTautomerMap::const_iterator> d_tautomersItVec;
180 TautomerEnumeratorStatus d_status;
182 boost::dynamic_bitset<> d_modifiedAtoms;
184 boost::dynamic_bitset<> d_modifiedBonds;
197 : dp_catalog(tautCat),
198 d_maxTautomers(1000),
199 d_maxTransforms(1000),
200 d_removeSp3Stereo(true),
201 d_removeBondStereo(true),
202 d_removeIsotopicHs(true),
203 d_reassignStereo(true) {}
206 : dp_catalog(other.dp_catalog),
207 d_callback(other.d_callback),
208 d_maxTautomers(other.d_maxTautomers),
209 d_maxTransforms(other.d_maxTransforms),
210 d_removeSp3Stereo(other.d_removeSp3Stereo),
211 d_removeBondStereo(other.d_removeBondStereo),
212 d_removeIsotopicHs(other.d_removeIsotopicHs),
213 d_reassignStereo(other.d_reassignStereo) {}
215 if (
this == &other) {
218 dp_catalog = other.dp_catalog;
219 d_callback = other.d_callback;
220 d_maxTautomers = other.d_maxTautomers;
221 d_maxTransforms = other.d_maxTransforms;
222 d_removeSp3Stereo = other.d_removeSp3Stereo;
223 d_removeBondStereo = other.d_removeBondStereo;
224 d_removeIsotopicHs = other.d_removeIsotopicHs;
225 d_reassignStereo = other.d_reassignStereo;
230 d_maxTautomers = maxTautomers;
240 d_maxTransforms = maxTransforms;
252 d_removeSp3Stereo = removeSp3Stereo;
266 d_removeBondStereo = removeBondStereo;
276 d_removeIsotopicHs = removeIsotopicHs;
287 d_reassignStereo = reassignStereo;
299 d_callback.reset(callback);
329 "please use the form returning a TautomerEnumeratorResult "
330 "instead")]] std::vector<ROMOL_SPTR>
332 boost::dynamic_bitset<> *modifiedBonds =
nullptr)
const;
336 boost::function<
int(
const ROMol &mol)> scoreFunc =
337 TautomerScoringFunctions::scoreTautomer)
const;
343 template <
class Iterable,
344 typename std::enable_if<
345 !std::is_same<Iterable, TautomerEnumeratorResult>::value,
348 boost::function<
int(
const ROMol &mol)> scoreFunc =
349 TautomerScoringFunctions::scoreTautomer)
const {
351 if (tautomers.size() == 1) {
352 bestMol = *tautomers.begin();
355 int bestScore = std::numeric_limits<int>::min();
356 std::string bestSmiles =
"";
357 for (
const auto &t : tautomers) {
358 auto score = scoreFunc(*t);
359#ifdef VERBOSE_ENUMERATION
360 std::cerr <<
" " << MolToSmiles(*t) <<
" " << score << std::endl;
362 if (score > bestScore) {
364 bestSmiles = MolToSmiles(*t);
366 }
else if (score == bestScore) {
367 auto smiles = MolToSmiles(*t);
368 if (smiles < bestSmiles) {
376 static const bool cleanIt =
true;
377 static const bool force =
true;
378 MolOps::assignStereochemistry(*res, cleanIt, force);
397 boost::function<
int(
const ROMol &mol)> scoreFunc =
398 TautomerScoringFunctions::scoreTautomer)
const;
400 boost::function<
int(
const ROMol &mol)> scoreFunc =
401 TautomerScoringFunctions::scoreTautomer)
const;
404 bool setTautomerStereoAndIsoHs(
const ROMol &mol,
ROMol &taut,
406 std::shared_ptr<TautomerCatalog> dp_catalog;
407 std::shared_ptr<TautomerEnumeratorCallback> d_callback;
408 unsigned int d_maxTautomers;
409 unsigned int d_maxTransforms;
410 bool d_removeSp3Stereo;
411 bool d_removeBondStereo;
412 bool d_removeIsotopicHs;
413 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 int scoreSubstructs(const ROMol &mol)
RDKIT_MOLSTANDARDIZE_EXPORT int scoreRings(const ROMol &mol)
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