RDKit
Open-source cheminformatics and machine learning.
RDKit::ChemicalReaction Class Reference

This is a class for storing and applying general chemical reactions. More...

#include <Reaction.h>

Inheritance diagram for RDKit::ChemicalReaction:
RDKit::RDProps

Public Member Functions

 ChemicalReaction ()
 
 ChemicalReaction (const ChemicalReaction &other)
 
 ChemicalReaction (const std::string &binStr)
 construct a reaction from a pickle string More...
 
unsigned int addReactantTemplate (ROMOL_SPTR mol)
 Adds a new reactant template. More...
 
unsigned int addAgentTemplate (ROMOL_SPTR mol)
 Adds a new agent template. More...
 
unsigned int addProductTemplate (ROMOL_SPTR mol)
 Adds a new product template. More...
 
void removeUnmappedReactantTemplates (double thresholdUnmappedAtoms=0.2, bool moveToAgentTemplates=true, MOL_SPTR_VECT *targetVector=NULL)
 Removes the reactant templates from a reaction if atom mapping ratio is. More...
 
void removeUnmappedProductTemplates (double thresholdUnmappedAtoms=0.2, bool moveToAgentTemplates=true, MOL_SPTR_VECT *targetVector=NULL)
 Removes the product templates from a reaction if its atom mapping ratio is. More...
 
void removeAgentTemplates (MOL_SPTR_VECT *targetVector=NULL)
 
std::vector< MOL_SPTR_VECTrunReactants (const MOL_SPTR_VECT reactants, unsigned int numProducts=1000) const
 Runs the reaction on a set of reactants. More...
 
std::vector< MOL_SPTR_VECTrunReactant (ROMOL_SPTR reactant, unsigned int reactantTemplateIdx) const
 Runs a single reactant against a single reactant template. More...
 
const MOL_SPTR_VECTgetReactants () const
 
const MOL_SPTR_VECTgetAgents () const
 
const MOL_SPTR_VECTgetProducts () const
 
MOL_SPTR_VECT::const_iterator beginReactantTemplates () const
 
MOL_SPTR_VECT::const_iterator endReactantTemplates () const
 
MOL_SPTR_VECT::const_iterator beginProductTemplates () const
 
MOL_SPTR_VECT::const_iterator endProductTemplates () const
 
MOL_SPTR_VECT::const_iterator beginAgentTemplates () const
 
MOL_SPTR_VECT::const_iterator endAgentTemplates () const
 
MOL_SPTR_VECT::iterator beginReactantTemplates ()
 
MOL_SPTR_VECT::iterator endReactantTemplates ()
 
MOL_SPTR_VECT::iterator beginProductTemplates ()
 
MOL_SPTR_VECT::iterator endProductTemplates ()
 
MOL_SPTR_VECT::iterator beginAgentTemplates ()
 
MOL_SPTR_VECT::iterator endAgentTemplates ()
 
unsigned int getNumReactantTemplates () const
 
unsigned int getNumProductTemplates () const
 
unsigned int getNumAgentTemplates () const
 
void initReactantMatchers ()
 initializes our internal reactant-matching datastructures. More...
 
bool isInitialized () const
 
bool validate (unsigned int &numWarnings, unsigned int &numErrors, bool silent=false) const
 validates the reactants and products to make sure the reaction seems More...
 
bool getImplicitPropertiesFlag () const
 
void setImplicitPropertiesFlag (bool val)
 
- Public Member Functions inherited from RDKit::RDProps
 RDProps ()
 
 RDProps (const RDProps &rhs)
 
RDPropsoperator= (const RDProps &rhs)
 
void clear ()
 
const DictgetDict () const
 gets the underlying Dictionary More...
 
DictgetDict ()
 
STR_VECT getPropList (bool includePrivate=true, bool includeComputed=true) const
 returns a list with the names of our properties More...
 
template<typename T >
void setProp (const std::string &key, T val, bool computed=false) const
 sets a property value More...
 
template<typename T >
void getProp (const std::string &key, T &res) const
 allows retrieval of a particular property value More...
 
template<typename T >
getProp (const std::string &key) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename T >
bool getPropIfPresent (const std::string &key, T &res) const
 
bool hasProp (const std::string &key) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void clearProp (const std::string &key) const
 clears the value of a property More...
 
void clearComputedProps () const
 clears all of our computed properties More...
 
void updateProps (const RDProps &source, bool preserveExisting=false)
 update the properties from another More...
 

Friends

class ReactionPickler
 

Additional Inherited Members

- Protected Attributes inherited from RDKit::RDProps
Dict d_props
 

Detailed Description

This is a class for storing and applying general chemical reactions.

basic usage will be something like:

ChemicalReaction rxn;
rxn.addReactantTemplate(r1);
rxn.addReactantTemplate(r2);
rxn.addProductTemplate(p1);
rxn.initReactantMatchers();

MOL_SPTR_VECT prods;
for(MOL_SPTR_VECT::const_iterator r1It=reactantSet1.begin();
    r1It!=reactantSet1.end();++r1It;){
  for(MOL_SPTR_VECT::const_iterator r2It=reactantSet2.begin();
      r2It!=reactantSet2.end();++r2It;){
    MOL_SPTR_VECT rVect(2);
    rVect[0] = *r1It;
    rVect[1] = *r2It;

    std::vector<MOL_SPTR_VECT> lprods;
    lprods = rxn.runReactants(rVect);
    for(std::vector<MOL_SPTR_VECT>::const_iterator lpIt=lprods.begin();
       lpIt!=lprods.end();++lpIt){
       // we know this is a single-product reaction:
       prods.push_back((*lpIt)[0]);
    }
  }
}

NOTES:

  • to allow more control over the reaction, it is possible to flag reactant atoms as being protected by setting the common_properties::_protected property on those atoms. Here's an example:
           std::string smi="[O:1]>>[N:1]";
           ChemicalReaction *rxn = RxnSmartsToChemicalReaction(smi);
           rxn->initReactantMatchers();
    
           MOL_SPTR_VECT reacts;
           reacts.clear();
           smi = "OCO";
           ROMol *mol = SmilesToMol(smi);
           reacts.push_back(ROMOL_SPTR(mol));
           std::vector<MOL_SPTR_VECT> prods;
           prods = rxn->runReactants(reacts);
           // here prods has two entries, because there are two Os in the
           // reactant.
    
           reacts[0]->getAtomWithIdx(0)->setProp(common_properties::_protected,1);
           prods = rxn->runReactants(reacts);
           // here prods only has one entry, the reaction at atom 0
           // has been blocked by the _protected property

Definition at line 119 of file Reaction.h.

Constructor & Destructor Documentation

◆ ChemicalReaction() [1/3]

RDKit::ChemicalReaction::ChemicalReaction ( )
inline

Definition at line 123 of file Reaction.h.

◆ ChemicalReaction() [2/3]

RDKit::ChemicalReaction::ChemicalReaction ( const ChemicalReaction other)
inline

◆ ChemicalReaction() [3/3]

RDKit::ChemicalReaction::ChemicalReaction ( const std::string &  binStr)

construct a reaction from a pickle string

Member Function Documentation

◆ addAgentTemplate()

unsigned int RDKit::ChemicalReaction::addAgentTemplate ( ROMOL_SPTR  mol)
inline

Adds a new agent template.

Returns
the number of agent

Definition at line 164 of file Reaction.h.

◆ addProductTemplate()

unsigned int RDKit::ChemicalReaction::addProductTemplate ( ROMOL_SPTR  mol)
inline

Adds a new product template.

Returns
the number of products

Definition at line 174 of file Reaction.h.

◆ addReactantTemplate()

unsigned int RDKit::ChemicalReaction::addReactantTemplate ( ROMOL_SPTR  mol)
inline

Adds a new reactant template.

Returns
the number of reactants

Definition at line 153 of file Reaction.h.

◆ beginAgentTemplates() [1/2]

MOL_SPTR_VECT::iterator RDKit::ChemicalReaction::beginAgentTemplates ( )
inline

Definition at line 275 of file Reaction.h.

◆ beginAgentTemplates() [2/2]

MOL_SPTR_VECT::const_iterator RDKit::ChemicalReaction::beginAgentTemplates ( ) const
inline

Definition at line 254 of file Reaction.h.

Referenced by ChemicalReaction().

◆ beginProductTemplates() [1/2]

MOL_SPTR_VECT::iterator RDKit::ChemicalReaction::beginProductTemplates ( )
inline

Definition at line 268 of file Reaction.h.

◆ beginProductTemplates() [2/2]

MOL_SPTR_VECT::const_iterator RDKit::ChemicalReaction::beginProductTemplates ( ) const
inline

Definition at line 247 of file Reaction.h.

Referenced by ChemicalReaction().

◆ beginReactantTemplates() [1/2]

MOL_SPTR_VECT::iterator RDKit::ChemicalReaction::beginReactantTemplates ( )
inline

Definition at line 261 of file Reaction.h.

◆ beginReactantTemplates() [2/2]

MOL_SPTR_VECT::const_iterator RDKit::ChemicalReaction::beginReactantTemplates ( ) const
inline

Definition at line 240 of file Reaction.h.

Referenced by ChemicalReaction().

◆ endAgentTemplates() [1/2]

MOL_SPTR_VECT::iterator RDKit::ChemicalReaction::endAgentTemplates ( )
inline

Definition at line 278 of file Reaction.h.

◆ endAgentTemplates() [2/2]

MOL_SPTR_VECT::const_iterator RDKit::ChemicalReaction::endAgentTemplates ( ) const
inline

Definition at line 257 of file Reaction.h.

Referenced by ChemicalReaction().

◆ endProductTemplates() [1/2]

MOL_SPTR_VECT::iterator RDKit::ChemicalReaction::endProductTemplates ( )
inline

Definition at line 271 of file Reaction.h.

◆ endProductTemplates() [2/2]

MOL_SPTR_VECT::const_iterator RDKit::ChemicalReaction::endProductTemplates ( ) const
inline

Definition at line 250 of file Reaction.h.

Referenced by ChemicalReaction().

◆ endReactantTemplates() [1/2]

MOL_SPTR_VECT::iterator RDKit::ChemicalReaction::endReactantTemplates ( )
inline

Definition at line 264 of file Reaction.h.

◆ endReactantTemplates() [2/2]

MOL_SPTR_VECT::const_iterator RDKit::ChemicalReaction::endReactantTemplates ( ) const
inline

Definition at line 243 of file Reaction.h.

Referenced by ChemicalReaction().

◆ getAgents()

const MOL_SPTR_VECT& RDKit::ChemicalReaction::getAgents ( ) const
inline

Definition at line 237 of file Reaction.h.

◆ getImplicitPropertiesFlag()

bool RDKit::ChemicalReaction::getImplicitPropertiesFlag ( ) const
inline

returns whether or not the reaction uses implicit properties on the product atoms

This toggles whether or not unspecified atomic properties in the products are considered to be implicit and should be copied from the actual reactants. This is necessary due to a semantic difference between the "reaction SMARTS" approach and the MDL RXN approach: In "reaction SMARTS", this reaction: [C:1]-[Br:2].[O-:3]>>[C:1]-[O:3].[Br-:2] applied to [CH4+]Br should yield [CH4+]O Something similar drawn in an rxn file, and applied to [CH4+]Br should yield [CH3]O. In rxn there is no charge on the product C because nothing is specified in the rxn file; in "SMARTS" the charge from the actual reactants is not removed because no charge is specified in the reaction.

Definition at line 340 of file Reaction.h.

◆ getNumAgentTemplates()

unsigned int RDKit::ChemicalReaction::getNumAgentTemplates ( ) const
inline

Definition at line 287 of file Reaction.h.

◆ getNumProductTemplates()

unsigned int RDKit::ChemicalReaction::getNumProductTemplates ( ) const
inline

Definition at line 284 of file Reaction.h.

◆ getNumReactantTemplates()

unsigned int RDKit::ChemicalReaction::getNumReactantTemplates ( ) const
inline

Definition at line 281 of file Reaction.h.

◆ getProducts()

const MOL_SPTR_VECT& RDKit::ChemicalReaction::getProducts ( ) const
inline

Definition at line 238 of file Reaction.h.

◆ getReactants()

const MOL_SPTR_VECT& RDKit::ChemicalReaction::getReactants ( ) const
inline

Definition at line 234 of file Reaction.h.

◆ initReactantMatchers()

void RDKit::ChemicalReaction::initReactantMatchers ( )

initializes our internal reactant-matching datastructures.

This must be called after adding reactants and before calling runReactants.

Referenced by RDKit::EnumerateLibraryBase::EnumerateLibraryBase().

◆ isInitialized()

bool RDKit::ChemicalReaction::isInitialized ( ) const
inline

Definition at line 298 of file Reaction.h.

◆ removeAgentTemplates()

void RDKit::ChemicalReaction::removeAgentTemplates ( MOL_SPTR_VECT targetVector = NULL)

Removes the agent templates from a reaction if a pointer to a molecule vector is provided the agents are stored therein.

◆ removeUnmappedProductTemplates()

void RDKit::ChemicalReaction::removeUnmappedProductTemplates ( double  thresholdUnmappedAtoms = 0.2,
bool  moveToAgentTemplates = true,
MOL_SPTR_VECT targetVector = NULL 
)

Removes the product templates from a reaction if its atom mapping ratio is.

By default the removed products templates were attached to the agent templates. An alternative will be to provide a pointer to a molecule vector where these products should be saved.

◆ removeUnmappedReactantTemplates()

void RDKit::ChemicalReaction::removeUnmappedReactantTemplates ( double  thresholdUnmappedAtoms = 0.2,
bool  moveToAgentTemplates = true,
MOL_SPTR_VECT targetVector = NULL 
)

Removes the reactant templates from a reaction if atom mapping ratio is.

By default the removed reactant templates were attached to the agent templates. An alternative will be to provide a pointer to a molecule vector where these reactants should be saved.

◆ runReactant()

std::vector<MOL_SPTR_VECT> RDKit::ChemicalReaction::runReactant ( ROMOL_SPTR  reactant,
unsigned int  reactantTemplateIdx 
) const

Runs a single reactant against a single reactant template.

Parameters
reactantThe single reactant to use
reactantTemplateIdxthe reactant template to target in the reaction

◆ runReactants()

std::vector<MOL_SPTR_VECT> RDKit::ChemicalReaction::runReactants ( const MOL_SPTR_VECT  reactants,
unsigned int  numProducts = 1000 
) const

Runs the reaction on a set of reactants.

Parameters
reactantsthe reactants to be used. The length of this must be equal to this->getNumReactantTemplates()
maxProductsif non zero, the maximum number of products to generate before stopping. If hit a warning will be generated.
Returns
a vector of vectors of products. Each subvector will be this->getNumProductTemplates() long.

We return a vector of vectors of products because each individual template may map multiple times onto its reactant. This leads to multiple possible result sets.

◆ setImplicitPropertiesFlag()

void RDKit::ChemicalReaction::setImplicitPropertiesFlag ( bool  val)
inline

sets the implicit properties flag. See the documentation for getImplicitProertiesFlag() for a discussion of what this means.

Definition at line 343 of file Reaction.h.

◆ validate()

bool RDKit::ChemicalReaction::validate ( unsigned int &  numWarnings,
unsigned int &  numErrors,
bool  silent = false 
) const

validates the reactants and products to make sure the reaction seems

Returns
true if the reaction validates without errors (warnings do not stop validation)
Parameters
numWarningsused to return the number of validation warnings
numErrorsused to return the number of validation errors
silentIf this bool is true, no messages will be logged during the validation. By default, validation problems are reported to the warning and error logs depending on their severity.

Friends And Related Function Documentation

◆ ReactionPickler

friend class ReactionPickler
friend

Definition at line 120 of file Reaction.h.


The documentation for this class was generated from the following file: