RDKit
Open-source cheminformatics and machine learning.
Chirality.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2008-2022 Greg Landrum and other RDKit contributors
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 /*! \file Chirality.h
11 
12 */
13 #include <RDGeneral/export.h>
14 #ifndef RD_CHIRALITY_20AUG2008_H
15 #define RD_CHIRALITY_20AUG2008_H
16 #include <RDGeneral/types.h>
17 #include <GraphMol/Bond.h>
18 #include <boost/dynamic_bitset.hpp>
19 #include <limits>
20 
21 namespace RDKit {
22 class Atom;
23 class Bond;
24 class ROMol;
25 class Conformer;
26 
27 namespace Chirality {
28 
29 //! double bond stereo will be ignored/removed for rings smaller than this:
30 constexpr unsigned int minRingSizeForDoubleBondStereo = 8;
31 
32 constexpr auto nonTetrahedralStereoEnvVar = "RDK_ENABLE_NONTETRAHEDRAL_STEREO";
33 constexpr auto useLegacyStereoEnvVar = "RDK_USE_LEGACY_STEREO_PERCEPTION";
35  true; //!< whether or not nontetrahedral stereo is perceived by default
36 constexpr bool useLegacyStereoDefaultVal =
37  true; //!< whether or not the legacy stereo perception code is used by
38  //!< default
39 
42 
45 
46 RDKIT_GRAPHMOL_EXPORT extern bool
47  useLegacyStereoPerception; //!< Toggle usage of the legacy stereo
48  //!< perception code
49 
50 RDKIT_GRAPHMOL_EXPORT extern bool
51  useLegacyStereoPerception; //!< Toggle usage of the legacy stereo
52  //!< perception code
53 
54 /// @cond
55 /*!
56  \param mol the molecule to be altered
57  \param ranks used to return the set of ranks.
58  Should be at least mol.getNumAtoms() long.
59 
60  <b>Notes:</b>
61  - All atoms gain a property common_properties::_CIPRank with their overall
62  CIP ranking.
63 
64 */
65 RDKIT_GRAPHMOL_EXPORT void assignAtomCIPRanks(const ROMol &mol,
66  UINT_VECT &ranks);
67 
68 RDKIT_GRAPHMOL_EXPORT bool hasStereoBondDir(const Bond *bond);
69 
70 /**
71  * Returns the first neighboring bond that can be found which has a stereo
72  * bond direction set. If no such bond can be found, it returns null. No
73  * checks are made to ensure there aren't any other conflicting directed bonds.
74  */
75 RDKIT_GRAPHMOL_EXPORT const Bond *getNeighboringDirectedBond(const ROMol &mol,
76  const Atom *atom);
77 
78 /**
79  * This just translates the labels, setting/translating StereoAtoms or the
80  * label is not the responsibility of this function. If the passed label is not
81  * E/Z, it will be returned unchanged.
82  */
83 RDKIT_GRAPHMOL_EXPORT Bond::BondStereo translateEZLabelToCisTrans(
84  Bond::BondStereo label);
85 /// @endcond
86 
87 enum class StereoType {
93  Bond_Double, // single double bond and odd-numbered cumulenes
94  Bond_Cumulene_Even, // even-numbered cumulenes
96 };
97 
99 
100 enum class StereoSpecified {
101  Unspecified, // no information provided
102  Specified,
103  Unknown // deliberately marked as unknown
104 };
105 
107  // REVIEW: absolute stereo data member?
108 #ifdef _MSC_VER
109  static const unsigned NOATOM =
110  std::numeric_limits<unsigned>::max(); // used to mark missing atoms
111 #else
112  static const unsigned NOATOM; // used to mark missing atoms
113 #endif
116  unsigned centeredOn = NOATOM;
118  unsigned permutation = 0; // for the non-tetrahedral stereo cases
119  std::vector<unsigned> controllingAtoms; // all atoms around the atom or bond.
120  // Order is important
121  bool operator==(const StereoInfo &other) const {
122  return type == other.type && specified == other.specified &&
123  centeredOn == other.centeredOn && descriptor == other.descriptor &&
124  permutation == other.permutation &&
125  controllingAtoms == other.controllingAtoms;
126  }
127  bool operator!=(const StereoInfo &other) const { return !(*this == other); }
128 };
129 
130 //! identifies potential stereoatoms and stereobonds in a molecule
131 /*!
132  Note that this function is still somewhat experimental and the API
133  and results may change in a future release.
134 
135  \param mol the molecule to look for stereo in
136  \param cleanIt remove chirality/stereo specifications from atoms/bonds that
137  cannot be chiral/stereo
138 */
140  ROMol &mol, bool cleanIt, bool flagPossible = true);
141 //! overload
143  const ROMol &mol);
144 
145 //! removes atoms without specified chirality from stereo groups
147 
148 //! calls the approximate legacy code for assigning CIP labels
150  ROMol &mol, bool flagPossibleStereoCenters = false);
151 
152 /// @cond
153 namespace detail {
154 RDKIT_GRAPHMOL_EXPORT bool isAtomPotentialNontetrahedralCenter(
155  const Atom *atom);
156 RDKIT_GRAPHMOL_EXPORT bool isAtomPotentialTetrahedralCenter(const Atom *atom);
157 RDKIT_GRAPHMOL_EXPORT bool isAtomPotentialStereoAtom(const Atom *atom);
158 RDKIT_GRAPHMOL_EXPORT bool isBondPotentialStereoBond(const Bond *bond);
159 RDKIT_GRAPHMOL_EXPORT StereoInfo getStereoInfo(const Bond *bond);
160 RDKIT_GRAPHMOL_EXPORT StereoInfo getStereoInfo(const Atom *atom);
161 RDKIT_GRAPHMOL_EXPORT bool bondAffectsAtomChirality(const Bond *bond,
162  const Atom *atom);
163 RDKIT_GRAPHMOL_EXPORT unsigned int getAtomNonzeroDegree(const Atom *atom);
164 
165 RDKIT_GRAPHMOL_EXPORT bool has_protium_neighbor(const ROMol &mol,
166  const Atom *atom);
167 
168 } // namespace detail
169 /// @endcond
170 
172 
173 //! \name Non-tetrahedral stereochemistry
174 //! @{
177  const Bond *qry);
179  const Atom *qry);
181  const Bond *qry);
183  const Atom *qry);
184 //! \param which: if this is -1 then the second axial bond will be returned,
185 //! otherwise the first
187  int which = 0);
189  int which = 0);
190 
191 //! \returns 1 if it's the first axial atom, -1 if it's the second
193  const Bond *qry);
195  const Atom *qry);
196 
198  const Atom *lig1,
199  const Atom *lig2);
200 
202  const INT_LIST &probe);
203 //! @}
204 
205 RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &oss,
206  const StereoSpecified &s);
207 RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &oss,
208  const StereoType &s);
209 
211  bool wedgeTwoBondsIfPossible =
212  false; //!< If this is enabled then two bonds will be wedged at chiral
213  //!< centers subject to the following constraints:
214  //!< 1. ring bonds will not be wedged
215  //!< 2. bonds to chiral centers will not be wedged
216  //!< 3. bonds separated by more than 120 degrees will not be
217  //!< wedged
218 };
219 
220 namespace detail {
222  const Bond *bond, unsigned int fromAtomIdx, const Conformer *conf);
224  const Bond *bond, const INT_MAP_INT &wedgeBonds, const Conformer *conf);
225 RDKIT_GRAPHMOL_EXPORT std::pair<bool, INT_VECT> countChiralNbrs(
226  const ROMol &mol, int noNbrs);
227 RDKIT_GRAPHMOL_EXPORT int pickBondToWedge(const Atom *atom, const ROMol &mol,
228  const INT_VECT &nChiralNbrs,
229  const INT_MAP_INT &resSoFar,
230  int noNbrs);
231 } // namespace detail
232 
233 //! picks the bonds which should be wedged
234 /// \returns a map from bond idx -> controlling atom idx
236  const ROMol &mol, const BondWedgingParameters *params = nullptr);
237 
239  ROMol &mol, const Conformer *conf = nullptr,
240  const BondWedgingParameters *params = nullptr);
241 RDKIT_GRAPHMOL_EXPORT void wedgeBond(Bond *bond, unsigned int fromAtomIdx,
242  const Conformer *conf);
243 
244 } // namespace Chirality
245 } // namespace RDKit
246 #endif
The class for representing atoms.
Definition: Atom.h:68
class for representing a bond
Definition: Bond.h:47
BondDir
the bond's direction (for chirality)
Definition: Bond.h:83
BondStereo
the nature of the bond's stereochem (for cis/trans)
Definition: Bond.h:95
The class for representing 2D or 3D conformation of a molecule.
Definition: Conformer.h:45
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:225
RDKIT_GRAPHMOL_EXPORT int pickBondToWedge(const Atom *atom, const ROMol &mol, const INT_VECT &nChiralNbrs, const INT_MAP_INT &resSoFar, int noNbrs)
RDKIT_GRAPHMOL_EXPORT std::pair< bool, INT_VECT > countChiralNbrs(const ROMol &mol, int noNbrs)
RDKIT_GRAPHMOL_EXPORT Bond::BondDir determineBondWedgeState(const Bond *bond, unsigned int fromAtomIdx, const Conformer *conf)
RDKIT_GRAPHMOL_EXPORT bool getUseLegacyStereoPerception()
RDKIT_GRAPHMOL_EXPORT int isTrigonalBipyramidalAxialAtom(const Atom *center, const Atom *qry)
RDKIT_GRAPHMOL_EXPORT bool getAllowNontetrahedralChirality()
RDKIT_GRAPHMOL_EXPORT Bond * getChiralAcrossBond(const Atom *center, const Bond *qry)
RDKIT_GRAPHMOL_EXPORT void wedgeMolBonds(ROMol &mol, const Conformer *conf=nullptr, const BondWedgingParameters *params=nullptr)
RDKIT_GRAPHMOL_EXPORT std::vector< StereoInfo > findPotentialStereo(ROMol &mol, bool cleanIt, bool flagPossible=true)
identifies potential stereoatoms and stereobonds in a molecule
RDKIT_GRAPHMOL_EXPORT void setUseLegacyStereoPerception(bool val)
constexpr unsigned int minRingSizeForDoubleBondStereo
double bond stereo will be ignored/removed for rings smaller than this:
Definition: Chirality.h:30
constexpr bool useLegacyStereoDefaultVal
Definition: Chirality.h:36
RDKIT_GRAPHMOL_EXPORT Atom * getTrigonalBipyramidalAxialAtom(const Atom *center, int which=0)
RDKIT_GRAPHMOL_EXPORT Bond * getTrigonalBipyramidalAxialBond(const Atom *center, int which=0)
RDKIT_GRAPHMOL_EXPORT void setAllowNontetrahedralChirality(bool val)
constexpr auto nonTetrahedralStereoEnvVar
Definition: Chirality.h:32
constexpr auto useLegacyStereoEnvVar
Definition: Chirality.h:33
RDKIT_GRAPHMOL_EXPORT bool useLegacyStereoPerception
Definition: Chirality.h:51
RDKIT_GRAPHMOL_EXPORT void wedgeBond(Bond *bond, unsigned int fromAtomIdx, const Conformer *conf)
RDKIT_GRAPHMOL_EXPORT unsigned int getChiralPermutation(const Atom *center, const INT_LIST &probe)
RDKIT_GRAPHMOL_EXPORT bool hasNonTetrahedralStereo(const Atom *center)
RDKIT_GRAPHMOL_EXPORT int isTrigonalBipyramidalAxialBond(const Atom *center, const Bond *qry)
RDKIT_GRAPHMOL_EXPORT double getIdealAngleBetweenLigands(const Atom *center, const Atom *lig1, const Atom *lig2)
RDKIT_GRAPHMOL_EXPORT void cleanupStereoGroups(ROMol &mol)
removes atoms without specified chirality from stereo groups
constexpr bool nonTetrahedralStereoDefaultVal
whether or not nontetrahedral stereo is perceived by default
Definition: Chirality.h:34
RDKIT_GRAPHMOL_EXPORT INT_VECT findStereoAtoms(const Bond *bond)
RDKIT_GRAPHMOL_EXPORT INT_MAP_INT pickBondsToWedge(const ROMol &mol, const BondWedgingParameters *params=nullptr)
RDKIT_GRAPHMOL_EXPORT void assignLegacyCIPLabels(ROMol &mol, bool flagPossibleStereoCenters=false)
calls the approximate legacy code for assigning CIP labels
RDKIT_GRAPHMOL_EXPORT std::ostream & operator<<(std::ostream &oss, const StereoSpecified &s)
RDKIT_GRAPHMOL_EXPORT Atom * getChiralAcrossAtom(const Atom *center, const Bond *qry)
Std stuff.
Definition: Abbreviations.h:19
std::list< int > INT_LIST
Definition: types.h:285
std::vector< int > INT_VECT
Definition: types.h:279
std::map< int, int > INT_MAP_INT
Definition: types.h:317
std::vector< UINT > UINT_VECT
Definition: types.h:298
static const unsigned NOATOM
Definition: Chirality.h:112
std::vector< unsigned > controllingAtoms
Definition: Chirality.h:119
StereoSpecified specified
Definition: Chirality.h:115
StereoDescriptor descriptor
Definition: Chirality.h:117
bool operator!=(const StereoInfo &other) const
Definition: Chirality.h:127
bool operator==(const StereoInfo &other) const
Definition: Chirality.h:121