RDKit: StereoGroup.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
StereoGroup.h
Go to the documentation of this file.
1//
2// Copyright (C) 2018-2021 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 StereoGroup.h
11
12 \brief Defines the class StereoGroup which stores relationships between
13 the absolute configurations of atoms within a structure.
14
15*/
16
17#include <RDGeneral/export.h>
18#ifndef RD_StereoGroup_092018
19#define RD_StereoGroup_092018
20
21#include <vector>
22
23namespace RDKit {
24class Atom;
25class Bond;
26class ROMol;
27
28// OR means that it is known to be one or the other, but not both
29// AND means that it is known to be a mix.
30 enum class StereoGroupType {
31 STEREO_ABSOLUTE = 0,
32 STEREO_OR = 1,
33 STEREO_AND = 2
34};
35
36//! StereoGroup is a collection of atoms with a known stereochemical
37//! relationship
38/*!
39 Used to help represent a sample with unknown stereochemistry, or that is a mix
40 of diastereomers.
41
42 */
43 class RDKIT_GRAPHMOL_EXPORT StereoGroup {
44 private:
45 StereoGroupType d_grouptype{StereoGroupType::STEREO_ABSOLUTE};
46 std::vector<Atom *> d_atoms;
47 std::vector<Bond *> d_bonds;
48
49 // The group ID for AND/OR groups (it has no meaning in ABS groups).
50 // 0 means no group ID is defined.
51 unsigned d_readId = 0u;
52 unsigned d_writeId = 0u;
53
54 public:
55 StereoGroup() {}
56 // Takes control of atoms if possible.
57 StereoGroup(StereoGroupType grouptype, std::vector<Atom *> &&atoms,
58 std::vector<Bond *> &&bonds, unsigned readId = 0);
59 StereoGroup(StereoGroupType grouptype, const std::vector<Atom *> &atoms,
60 const std::vector<Bond *> &bonds, unsigned readId = 0);
61
62 StereoGroup(const StereoGroup &other) = default;
63 StereoGroup &operator=(const StereoGroup &other) = default;
64 StereoGroup(StereoGroup &&other) = default;
65 StereoGroup &operator=(StereoGroup &&other) = default;
66
67 StereoGroupType getGroupType() const;
68 const std::vector<Atom *> &getAtoms() const;
69 const std::vector<Bond *> &getBonds() const;
70
71 unsigned getReadId() const { return d_readId; }
72 unsigned getWriteId() const { return d_writeId; }
73 void setWriteId(unsigned id) { d_writeId = id; }
74
75 // Seems odd to have to define these, but otherwise the SWIG wrappers
76 // won't build
77 bool operator==(const StereoGroup &other) const {
78 return (d_grouptype == other.d_grouptype) && (d_atoms == other.d_atoms) &&
79 (d_bonds == other.d_bonds);
80 }
81 bool operator!=(const StereoGroup &other) const {
82 return (d_grouptype != other.d_grouptype) || (d_atoms != other.d_atoms) ||
83 (d_bonds != other.d_bonds);
84 }
85 friend RDKIT_GRAPHMOL_EXPORT void removeAtomFromGroups(
86 const Atom *atom, std::vector<StereoGroup> &groups);
87 friend RDKIT_GRAPHMOL_EXPORT void removeBondFromGroups(
88 const Bond *bond, std::vector<StereoGroup> &groups);
89};
90 RDKIT_GRAPHMOL_EXPORT void removeAtomFromGroups(
91 const Atom *atom, std::vector<StereoGroup> &groups);
92 RDKIT_GRAPHMOL_EXPORT void removeBondFromGroups(
93 const Bond *bond, std::vector<StereoGroup> &groups);
94 RDKIT_GRAPHMOL_EXPORT void removeGroupsWithAtom(
95 const Atom *atom, std::vector<StereoGroup> &groups);
96 RDKIT_GRAPHMOL_EXPORT void removeGroupsWithAtoms(
97 const std::vector<Atom *> &atoms, std::vector<StereoGroup> &groups);
98
99//! Assign Group output IDs to all AND and OR StereoGroups in the vector
100//! that don't already have one. The IDs are assigned based on the order
101//! of the groups.
102 RDKIT_GRAPHMOL_EXPORT void assignStereoGroupIds(
103 std::vector<StereoGroup> &groups);
104
105//! Copy StereoGroup "read" IDs to "write" IDs so that they will be preserved
106//! when the mol is exported.
107 RDKIT_GRAPHMOL_EXPORT void forwardStereoGroupIds(ROMol &mol);
108
109} // namespace RDKit
110
111//! allows StereoGroup objects to be dumped to streams
112 RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &target,
113 const RDKit::StereoGroup &stg);
114
115#endif
operator<<
RDKIT_GRAPHMOL_EXPORT std::ostream & operator<<(std::ostream &target, const RDKit::StereoGroup &stg)
allows StereoGroup objects to be dumped to streams
RDKit::Atom
The class for representing atoms.
Definition Atom.h:74
RDKit::Bond
class for representing a bond
Definition Bond.h:46
RDKit::ROMol
Definition ROMol.h:199
RDKit::StereoGroup
Definition StereoGroup.h:43
RDKit::StereoGroup::StereoGroup
StereoGroup(StereoGroupType grouptype, std::vector< Atom * > &&atoms, std::vector< Bond * > &&bonds, unsigned readId=0)
RDKit::StereoGroup::operator=
StereoGroup & operator=(const StereoGroup &other)=default
RDKit::StereoGroup::operator=
StereoGroup & operator=(StereoGroup &&other)=default
RDKit::StereoGroup::getWriteId
unsigned getWriteId() const
Definition StereoGroup.h:72
RDKit::StereoGroup::StereoGroup
StereoGroup(const StereoGroup &other)=default
RDKit::StereoGroup::getGroupType
StereoGroupType getGroupType() const
RDKit::StereoGroup::getReadId
unsigned getReadId() const
Definition StereoGroup.h:71
RDKit::StereoGroup::StereoGroup
StereoGroup(StereoGroup &&other)=default
RDKit::StereoGroup::operator==
bool operator==(const StereoGroup &other) const
Definition StereoGroup.h:77
RDKit::StereoGroup::setWriteId
void setWriteId(unsigned id)
Definition StereoGroup.h:73
RDKit::StereoGroup::StereoGroup
StereoGroup(StereoGroupType grouptype, const std::vector< Atom * > &atoms, const std::vector< Bond * > &bonds, unsigned readId=0)
RDKit::StereoGroup::removeAtomFromGroups
friend RDKIT_GRAPHMOL_EXPORT void removeAtomFromGroups(const Atom *atom, std::vector< StereoGroup > &groups)
RDKit::StereoGroup::removeBondFromGroups
friend RDKIT_GRAPHMOL_EXPORT void removeBondFromGroups(const Bond *bond, std::vector< StereoGroup > &groups)
RDKit::StereoGroup::operator!=
bool operator!=(const StereoGroup &other) const
Definition StereoGroup.h:81
RDKit::StereoGroup::getAtoms
const std::vector< Atom * > & getAtoms() const
RDKit::StereoGroup::getBonds
const std::vector< Bond * > & getBonds() const
RDKit::StereoGroup::StereoGroup
StereoGroup()
Definition StereoGroup.h:55
export.h
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:249
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::forwardStereoGroupIds
RDKIT_GRAPHMOL_EXPORT void forwardStereoGroupIds(ROMol &mol)
RDKit::StereoGroupType
StereoGroupType
Definition StereoGroup.h:30
RDKit::StereoGroupType::STEREO_OR
@ STEREO_OR
Definition StereoGroup.h:32
RDKit::StereoGroupType::STEREO_AND
@ STEREO_AND
Definition StereoGroup.h:33
RDKit::StereoGroupType::STEREO_ABSOLUTE
@ STEREO_ABSOLUTE
Definition StereoGroup.h:31
RDKit::removeGroupsWithAtom
RDKIT_GRAPHMOL_EXPORT void removeGroupsWithAtom(const Atom *atom, std::vector< StereoGroup > &groups)
RDKit::removeBondFromGroups
RDKIT_GRAPHMOL_EXPORT void removeBondFromGroups(const Bond *bond, std::vector< StereoGroup > &groups)
RDKit::assignStereoGroupIds
RDKIT_GRAPHMOL_EXPORT void assignStereoGroupIds(std::vector< StereoGroup > &groups)
RDKit::removeAtomFromGroups
RDKIT_GRAPHMOL_EXPORT void removeAtomFromGroups(const Atom *atom, std::vector< StereoGroup > &groups)
RDKit::removeGroupsWithAtoms
RDKIT_GRAPHMOL_EXPORT void removeGroupsWithAtoms(const std::vector< Atom * > &atoms, std::vector< StereoGroup > &groups)