RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
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/Atom.h> /* for Atom:ChiralType enum */
18#include <GraphMol/Bond.h> /* for Bond::BondDir enum */
19#include <boost/dynamic_bitset.hpp>
20#include <limits>
21
22namespace RDKit {
23class Atom;
24class Bond;
25class ROMol;
26class Conformer;
27
28namespace Chirality {
29
30//! double bond stereo will be ignored/removed for rings smaller than this:
31constexpr unsigned int minRingSizeForDoubleBondStereo = 8;
32
33constexpr auto nonTetrahedralStereoEnvVar = "RDK_ENABLE_NONTETRAHEDRAL_STEREO";
34constexpr auto useLegacyStereoEnvVar = "RDK_USE_LEGACY_STEREO_PERCEPTION";
36 true; //!< whether or not nontetrahedral stereo is perceived by default
38 true; //!< whether or not the legacy stereo perception code is used by
39 //!< default
40
43
46
48
49RDKIT_GRAPHMOL_EXPORT extern bool
50 useLegacyStereoPerception; //!< Toggle usage of the legacy stereo
51 //!< perception code
52
53RDKIT_GRAPHMOL_EXPORT extern bool
54 useLegacyStereoPerception; //!< Toggle usage of the legacy stereo
55 //!< perception code
56
57/// @cond
58/*!
59 \param mol the molecule to be altered
60 \param ranks used to return the set of ranks.
61 Should be at least mol.getNumAtoms() long.
62
63 <b>Notes:</b>
64 - All atoms gain a property common_properties::_CIPRank with their overall
65 CIP ranking.
66
67*/
68RDKIT_GRAPHMOL_EXPORT void assignAtomCIPRanks(const ROMol &mol,
69 UINT_VECT &ranks);
70
71RDKIT_GRAPHMOL_EXPORT bool hasStereoBondDir(const Bond *bond);
72
73/**
74 * Returns the first neighboring bond that can be found which has a stereo
75 * bond direction set. If no such bond can be found, it returns null. No
76 * checks are made to ensure there aren't any other conflicting directed bonds.
77 */
78RDKIT_GRAPHMOL_EXPORT const Bond *getNeighboringDirectedBond(const ROMol &mol,
79 const Atom *atom);
80
81/**
82 * This just translates the labels, setting/translating StereoAtoms or the
83 * label is not the responsibility of this function. If the passed label is not
84 * E/Z, it will be returned unchanged.
85 */
86RDKIT_GRAPHMOL_EXPORT Bond::BondStereo translateEZLabelToCisTrans(
87 Bond::BondStereo label);
88/// @endcond
89
90enum class StereoType {
96 Bond_Double, // single double bond and odd-numbered cumulenes
97 Bond_Cumulene_Even, // even-numbered cumulenes
99};
100
110
111enum class StereoSpecified {
112 Unspecified, // no information provided
114 Unknown // deliberately marked as unknown
115};
116
118 // REVIEW: absolute stereo data member?
119
124 unsigned permutation = 0; // for the non-tetrahedral stereo cases
125 std::vector<unsigned> controllingAtoms; // all atoms around the atom or bond.
126 // Order is important
127 bool operator==(const StereoInfo &other) const {
128 return type == other.type && specified == other.specified &&
129 centeredOn == other.centeredOn && descriptor == other.descriptor &&
130 permutation == other.permutation &&
132 }
133 bool operator!=(const StereoInfo &other) const { return !(*this == other); }
134};
135
136//! identifies potential stereoatoms and stereobonds in a molecule
137/*!
138 Note that this function is still somewhat experimental and the API
139 and results may change in a future release.
140
141 \param mol the molecule to look for stereo in
142 \param cleanIt remove chirality/stereo specifications from atoms/bonds that
143 cannot be chiral/stereo
144*/
146 ROMol &mol, bool cleanIt, bool flagPossible = true);
147//! overload
149 const ROMol &mol);
150
151//! removes atoms without specified chirality from stereo groups
153
154//! calls the approximate legacy code for assigning CIP labels
156 ROMol &mol, bool flagPossibleStereoCenters = false);
157
158/// @cond
159namespace detail {
160RDKIT_GRAPHMOL_EXPORT bool isAtomPotentialNontetrahedralCenter(
161 const Atom *atom);
162RDKIT_GRAPHMOL_EXPORT bool isAtomPotentialTetrahedralCenter(const Atom *atom);
163RDKIT_GRAPHMOL_EXPORT bool isAtomPotentialStereoAtom(const Atom *atom);
164RDKIT_GRAPHMOL_EXPORT bool isBondPotentialStereoBond(const Bond *bond);
165RDKIT_GRAPHMOL_EXPORT StereoInfo getStereoInfo(const Bond *bond);
166RDKIT_GRAPHMOL_EXPORT StereoInfo getStereoInfo(const Atom *atom);
167RDKIT_GRAPHMOL_EXPORT bool bondAffectsAtomChirality(const Bond *bond,
168 const Atom *atom);
169RDKIT_GRAPHMOL_EXPORT unsigned int getAtomNonzeroDegree(const Atom *atom);
170
171RDKIT_GRAPHMOL_EXPORT bool has_protium_neighbor(const ROMol &mol,
172 const Atom *atom);
173
174} // namespace detail
175/// @endcond
176
178
179//! \name Non-tetrahedral stereochemistry
180//! @{
183 const Bond *qry);
185 const Atom *qry);
187 const Bond *qry);
189 const Atom *qry);
190//! \param which: if this is -1 then the second axial bond will be returned,
191//! otherwise the first
193 int which = 0);
195 int which = 0);
196
197//! \returns 1 if it's the first axial atom, -1 if it's the second
199 const Bond *qry);
201 const Atom *qry);
202
204 const Atom *lig1,
205 const Atom *lig2);
206
208
209//
210// Get the chiral permutation from the storage order of bonds on an atom
211// to the desired output order (probe). Missing/implicit neihgbors can be
212// represented with (-1). To get the inverse order, i.e. from the probe to the
213// current storage order set (inverse=true)
214//
216 const INT_LIST &probe,
217 bool inverse = false);
218//! @}
219
220RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &oss,
221 const StereoSpecified &s);
222RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &oss,
223 const StereoType &s);
224
227 false; //!< If this is enabled then two bonds will be wedged at chiral
228 //!< centers subject to the following constraints:
229 //!< 1. ring bonds will not be wedged
230 //!< 2. bonds to chiral centers will not be wedged
231 //!< 3. bonds separated by more than 120 degrees will not be
232 //!< wedged
233};
234
239
241 public:
242 WedgeInfoBase(int idxInit) : idx(idxInit){};
243 virtual ~WedgeInfoBase(){};
244
245 virtual WedgeInfoType getType() const = 0;
246 virtual Bond::BondDir getDir() const = 0;
247
248 int getIdx() const { return idx; }
249
250 private:
251 int idx = -1;
252};
253
255 public:
256 WedgeInfoChiral(int atomId) : WedgeInfoBase(atomId){};
257 ~WedgeInfoChiral() override {}
258
262 Bond::BondDir getDir() const override {
263 throw std::runtime_error(
264 "BondDir is not stored/used in Chiral type WedgInfos");
265 }
266};
267
269 public:
271 : WedgeInfoBase(bondId) {
272 dir = dirInit;
273 };
275
277
281
282 Bond::BondDir getDir() const override { return dir; }
283};
284
285namespace detail {
287 const Bond *bond, unsigned int fromAtomIdx, const Conformer *conf);
289 const Bond *bond,
290 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
291 &wedgeBonds,
292 const Conformer *conf);
293
294RDKIT_GRAPHMOL_EXPORT std::pair<bool, INT_VECT> countChiralNbrs(
295 const ROMol &mol, int noNbrs);
297 const Atom *atom, const ROMol &mol, const INT_VECT &nChiralNbrs,
298 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
299 &resSoFar,
300 int noNbrs);
301
302//! If useCXSmilesOrdering is true, the stereo will be assigned relative to the
303/// lowest-numbered neighbor of each double bond atom.
304/// Otherwise it uses the lowest-numbered neighbor on the lower-numbered atom of
305/// the double bond and the highest-numbered neighbor on the higher-numbered
306/// atom
308 Bond::BondStereo stereo,
309 bool useCXSmilesOrdering = false);
310} // namespace detail
311
312//! picks the bonds which should be wedged
313/// returns a map from bond idx -> controlling atom idx
315std::map<int, std::unique_ptr<Chirality::WedgeInfoBase>> pickBondsToWedge(
316 const ROMol &mol, const BondWedgingParameters *params = nullptr);
317
319std::map<int, std::unique_ptr<Chirality::WedgeInfoBase>> pickBondsToWedge(
320 const ROMol &mol, const BondWedgingParameters *params,
321 const Conformer *conf);
322
324 ROMol &mol, const Conformer *conf = nullptr,
325 const BondWedgingParameters *params = nullptr);
326RDKIT_GRAPHMOL_EXPORT void wedgeBond(Bond *bond, unsigned int fromAtomIdx,
327 const Conformer *conf);
328
329//! Returns true for double bonds which should be shown as a crossed bonds.
330// It always returns false if any adjacent bond is a squiggle bond.
332
333//! Clears existing bond wedging and forces use of atom wedging from MolBlock.
334/*!
335 \param mol: molecule to have its wedges altered
336 \param allBondTypes: reapply the wedging also on bonds other than single and
337 aromatic ones
338 \param verify: if true, the function will check that the wedges are only
339 applied in sensible places (i.e. single bonds connected to chiral centers or
340 atropisomeric bonds)
341 */
343 bool allBondTypes = true,
344 bool verify = false);
345
346//! Remove MolBlock bond wedging information from molecule.
347/*!
348 \param mol: molecule to modify
349 */
351//! Invert bond wedging information read from a mol block (if present).
352/*!
353 \param mol: molecule to modify
354 */
356
357//! gets stereo info for a bond
358/*!
359 \param bond: bond to check
360 \param wedgeBonds - the list of bonds to have wedges
361 \param conf - Conformer to use
362 \param dirCode - receives the dircode for the bond
363 \param reverse - receives the reverse flag
364 only returned if it was exlicility set witha wiggle bond
365 */
366
368 const Bond *bond,
369 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
370 &wedgeBonds,
371 const Conformer *conf, int &dirCode, bool &reverse);
372
374 const Bond *bond,
375 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
376 &wedgeBonds,
377 const Conformer *conf, Bond::BondDir &dir, bool &reverse);
378
379//! add R/S, relative stereo, and E/Z annotations to atoms and bonds
380/*!
381 \param mol: molecule to modify
382 \param absLabel: label for atoms in an ABS stereo group
383 \param orLabel: label for atoms in an OR stereo group
384 \param andLabel: label for atoms in an AND stereo group
385 \param cipLabel: label for chiral atoms that aren't in a stereo group.
386 \param bondLabel: label for CIP stereochemistry on bonds
387
388 If any label is empty, the corresponding annotations will not be added.
389
390 The labels can contain the following placeholders:
391 {id} - the stereo group's index
392 {cip} - the atom or bond's CIP stereochemistry
393
394 Note that CIP labels will only be added if CIP stereochemistry has been
395 assigned to the molecule.
396
397 */
399 ROMol &mol, std::string absLabel = "abs ({cip})",
400 std::string orLabel = "or{id}", std::string andLabel = "and{id}",
401 std::string cipLabel = "({cip})", std::string bondLabel = "({cip})");
402
403//! simplifies the stereochemical representation of a molecule where all
404//! specified stereocenters are in the same StereoGroup
405/*!
406 \param mol: molecule to modify
407 \param removeAffectedStereoGroups: if set then the affected StereoGroups will
408 be removed
409
410If all specified stereocenters are in the same AND or OR stereogroup, a
411moleculeNote property will be set on the molecule with the value "AND
412enantiomer" or "OR enantiomer". CIP labels, if present, are removed.
413
414*/
416 ROMol &mol, bool removeAffectedStereoGroups = true);
417
418//! returns the meso centers in a molecule (if any)
419/*!
420 \param mol: molecule to work with
421
422*/
423RDKIT_GRAPHMOL_EXPORT std::vector<std::pair<unsigned int, unsigned int>>
424findMesoCenters(const ROMol &mol, bool includeIsotopes = true,
425 bool includeAtomMaps = false);
426
427} // namespace Chirality
428} // namespace RDKit
429#endif
Defines the Atom class and associated typedefs.
The class for representing atoms.
Definition Atom.h:75
ChiralType
store type of chirality
Definition Atom.h:106
static constexpr unsigned int NOATOM
Definition Atom.h:86
class for representing a bond
Definition Bond.h:48
BondStereo
the nature of the bond's stereochem (for cis/trans)
Definition Bond.h:96
BondDir
the bond's direction (for chirality)
Definition Bond.h:84
@ NONE
no special style
Definition Bond.h:85
WedgeInfoType getType() const override
Definition Chirality.h:278
WedgeInfoAtropisomer(int bondId, RDKit::Bond::BondDir dirInit)
Definition Chirality.h:270
Bond::BondDir getDir() const override
Definition Chirality.h:282
virtual Bond::BondDir getDir() const =0
virtual WedgeInfoType getType() const =0
Bond::BondDir getDir() const override
Definition Chirality.h:262
WedgeInfoType getType() const override
Definition Chirality.h:259
The class for representing 2D or 3D conformation of a molecule.
Definition Conformer.h:46
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:321
RDKIT_GRAPHMOL_EXPORT std::pair< bool, INT_VECT > countChiralNbrs(const ROMol &mol, int noNbrs)
RDKIT_GRAPHMOL_EXPORT void setStereoForBond(ROMol &mol, Bond *bond, Bond::BondStereo stereo, bool useCXSmilesOrdering=false)
RDKIT_GRAPHMOL_EXPORT int pickBondToWedge(const Atom *atom, const ROMol &mol, const INT_VECT &nChiralNbrs, const std::map< int, std::unique_ptr< RDKit::Chirality::WedgeInfoBase > > &resSoFar, 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 unsigned int getChiralPermutation(const Atom *center, const INT_LIST &probe, bool inverse=false)
RDKIT_GRAPHMOL_EXPORT bool getAllowNontetrahedralChirality()
RDKIT_GRAPHMOL_EXPORT void wedgeMolBonds(ROMol &mol, const Conformer *conf=nullptr, const BondWedgingParameters *params=nullptr)
RDKIT_GRAPHMOL_EXPORT unsigned int getMaxNbors(const Atom::ChiralType tag)
RDKIT_GRAPHMOL_EXPORT Atom * getTrigonalBipyramidalAxialAtom(const Atom *center, int which=0)
RDKIT_GRAPHMOL_EXPORT void invertMolBlockWedgingInfo(ROMol &mol)
Invert bond wedging information read from a mol block (if present).
RDKIT_GRAPHMOL_EXPORT void setUseLegacyStereoPerception(bool val)
RDKIT_GRAPHMOL_EXPORT std::vector< std::pair< unsigned int, unsigned int > > findMesoCenters(const ROMol &mol, bool includeIsotopes=true, bool includeAtomMaps=false)
returns the meso centers in a molecule (if any)
RDKIT_GRAPHMOL_EXPORT void simplifyEnhancedStereo(ROMol &mol, bool removeAffectedStereoGroups=true)
RDKIT_GRAPHMOL_EXPORT bool shouldBeACrossedBond(const Bond *bond)
Returns true for double bonds which should be shown as a crossed bonds.
constexpr unsigned int minRingSizeForDoubleBondStereo
double bond stereo will be ignored/removed for rings smaller than this:
Definition Chirality.h:31
constexpr bool useLegacyStereoDefaultVal
Definition Chirality.h:37
RDKIT_GRAPHMOL_EXPORT void GetMolFileBondStereoInfo(const Bond *bond, const std::map< int, std::unique_ptr< RDKit::Chirality::WedgeInfoBase > > &wedgeBonds, const Conformer *conf, int &dirCode, bool &reverse)
gets stereo info for a bond
RDKIT_GRAPHMOL_EXPORT Atom * getChiralAcrossAtom(const Atom *center, const Bond *qry)
RDKIT_GRAPHMOL_EXPORT void setAllowNontetrahedralChirality(bool val)
RDKIT_GRAPHMOL_EXPORT Bond * getTrigonalBipyramidalAxialBond(const Atom *center, int which=0)
constexpr auto nonTetrahedralStereoEnvVar
Definition Chirality.h:33
RDKIT_GRAPHMOL_EXPORT void removeNonExplicit3DChirality(ROMol &mol)
constexpr auto useLegacyStereoEnvVar
Definition Chirality.h:34
RDKIT_GRAPHMOL_EXPORT bool useLegacyStereoPerception
Definition Chirality.h:54
RDKIT_GRAPHMOL_EXPORT void reapplyMolBlockWedging(ROMol &mol, bool allBondTypes=true, bool verify=false)
Clears existing bond wedging and forces use of atom wedging from MolBlock.
RDKIT_GRAPHMOL_EXPORT std::ostream & operator<<(std::ostream &oss, const StereoSpecified &s)
RDKIT_GRAPHMOL_EXPORT void wedgeBond(Bond *bond, unsigned int fromAtomIdx, const Conformer *conf)
RDKIT_GRAPHMOL_EXPORT std::map< int, std::unique_ptr< Chirality::WedgeInfoBase > > pickBondsToWedge(const ROMol &mol, 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 addStereoAnnotations(ROMol &mol, std::string absLabel="abs ({cip})", std::string orLabel="or{id}", std::string andLabel="and{id}", std::string cipLabel="({cip})", std::string bondLabel="({cip})")
add R/S, relative stereo, and E/Z annotations to atoms and bonds
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
RDKIT_GRAPHMOL_EXPORT Bond * getChiralAcrossBond(const Atom *center, const Bond *qry)
constexpr bool nonTetrahedralStereoDefaultVal
whether or not nontetrahedral stereo is perceived by default
Definition Chirality.h:35
RDKIT_GRAPHMOL_EXPORT void clearMolBlockWedgingInfo(ROMol &mol)
Remove MolBlock bond wedging information from molecule.
RDKIT_GRAPHMOL_EXPORT INT_VECT findStereoAtoms(const Bond *bond)
RDKIT_GRAPHMOL_EXPORT void assignLegacyCIPLabels(ROMol &mol, bool flagPossibleStereoCenters=false)
calls the approximate legacy code for assigning CIP labels
Std stuff.
std::list< int > INT_LIST
Definition types.h:229
std::vector< int > INT_VECT
Definition types.h:223
std::vector< UINT > UINT_VECT
Definition types.h:242
std::vector< unsigned > controllingAtoms
Definition Chirality.h:125
StereoSpecified specified
Definition Chirality.h:121
StereoDescriptor descriptor
Definition Chirality.h:123
bool operator!=(const StereoInfo &other) const
Definition Chirality.h:133
bool operator==(const StereoInfo &other) const
Definition Chirality.h:127