RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
MacroMolTemplate.h
Go to the documentation of this file.
1//
2// Copyright (C) 2026 Tad Hurst, Schrödinger 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
11#ifndef RD_MACROMOLTEMPLATE_H
12#define RD_MACROMOLTEMPLATE_H
13
14#include <RDGeneral/export.h>
16#include <GraphMol/RWMol.h>
18
19#include <map>
20#include <memory>
21#include <string>
22#include <utility>
23#include <vector>
24
25namespace RDKit {
26
27//! Describes the atoms removed at one MacroMol template attachment point.
29 MacroMolLeavingGroup(std::vector<unsigned int> atomIdxs,
30 unsigned int attachAtomIdx,
31 unsigned int leavingAtomIdx, int attachPoint)
32 : atomIdxs(std::move(atomIdxs)),
36
37 std::vector<unsigned int> atomIdxs;
38 unsigned int attachAtomIdx;
39 unsigned int leavingAtomIdx;
41};
42
44
45//! A logically read-only, annotated molecule template for a macromolecule
46//! monomer.
47/*!
48 The typed main- and leaving-group definitions are authoritative. The owned
49 molecule mirrors those definitions as SUP SGroups for RDKit I/O. Accessors
50 follow RDKit's normal const semantics, including its legacy owning-molecule
51 back-references.
52*/
54 public:
56 MacroMolTemplate(MacroMolTemplate &&) noexcept = default;
57 MacroMolTemplate &operator=(const MacroMolTemplate &) = default;
58 MacroMolTemplate &operator=(MacroMolTemplate &&) = default;
59
60 //! Returns a read-only view of the underlying template molecule.
61 const ROMol &getMol() const { return d_mol; }
62 //! Returns the monomer class used for lookup and the main SGroup CLASS.
63 MonomerClass getMonomerClass() const { return d_monomerClass; }
64 //! Returns the name, e.g. "ALA".
65 const std::string &getName() const { return d_name; }
66 //! Returns the template symbol, e.g. "A" for alanine.
67 const std::string &getSymbol() const { return d_symbol; }
68 //! Returns the original template definition (SMILES, SDF, etc.).
69 const std::string &getOriginalData() const { return d_originalData; }
70 //! Returns the SCSR subclass, or an empty string if unspecified.
71 const std::string &getSubclass() const { return d_subclass; }
72 //! Returns the atom indices belonging to the retained monomer group.
73 const std::vector<unsigned int> &getMainAtomIdxs() const {
74 return d_mainAtomIdxs;
75 }
76 //! Returns the typed leaving-group definitions.
77 const std::vector<MacroMolLeavingGroup> &getLeavingGroups() const {
78 return d_leavingGroups;
79 }
80 //! Returns the main SUP SGroup mirrored onto the owned molecule.
82
83 private:
85
86 MacroMolTemplate(RWMol mol, MonomerClass monomerClass,
87 std::string name, std::string symbol,
88 std::string originalData, std::string subclass,
89 std::vector<unsigned int> mainAtomIdxs,
90 std::vector<MacroMolLeavingGroup> leavingGroups,
91 unsigned int mainSgroupIdx)
92 : d_mol(std::move(mol)),
93 d_monomerClass(monomerClass),
94 d_name(std::move(name)),
95 d_symbol(std::move(symbol)),
96 d_originalData(std::move(originalData)),
97 d_subclass(std::move(subclass)),
98 d_mainAtomIdxs(std::move(mainAtomIdxs)),
99 d_leavingGroups(std::move(leavingGroups)),
100 d_mainSgroupIdx(mainSgroupIdx) {}
101
102 RWMol d_mol;
103 MonomerClass d_monomerClass;
104 std::string d_name;
105 std::string d_symbol;
106 std::string d_originalData;
107 std::string d_subclass;
108 std::vector<unsigned int> d_mainAtomIdxs;
109 std::vector<MacroMolLeavingGroup> d_leavingGroups;
110 unsigned int d_mainSgroupIdx;
111};
112
113//! Collects and validates the pieces needed to create a MacroMolTemplate.
114/*!
115 Main-group and leaving-group definitions depend on one another, so the
116 builder holds the incomplete definition until build() can validate it as a
117 whole. build() returns a complete template without modifying the builder,
118 allowing callers to use the normal builder.build() syntax.
119*/
121 public:
123 std::string name, std::string symbol,
124 std::string originalData)
125 : d_mol(mol),
126 d_monomerClass(monomerClass),
127 d_name(std::move(name)),
128 d_symbol(std::move(symbol)),
129 d_originalData(std::move(originalData)) {}
130
131 //! Returns the mutable molecule being prepared for the template.
132 /*!
133 Structural edits should be completed before defining the main and
134 leaving groups.
135 */
136 RWMol &getMol() { return d_mol; }
137
138 //! Defines the atoms retained as the main monomer group.
139 MacroMolTemplateBuilder &setMainGroup(std::vector<unsigned int> &&atomIdxs);
140 //! Adds a leaving group and its attachment-point definition.
142 MacroMolLeavingGroup &&leavingGroup);
143 //! Sets the optional SCSR subclass.
144 MacroMolTemplateBuilder &setSubclass(std::string subclass);
145 //! Validates the complete definition and returns an immutable template.
146 std::unique_ptr<MacroMolTemplate> build() const;
147
148 private:
149 RWMol d_mol;
150 MonomerClass d_monomerClass;
151 std::string d_name;
152 std::string d_symbol;
153 std::string d_originalData;
154 std::string d_subclass;
155 std::vector<unsigned int> d_mainAtomIdxs;
156 std::vector<MacroMolLeavingGroup> d_leavingGroups;
157 bool d_mainGroupSet = false;
158};
159
161 public:
167 default;
168
169 //! Adds a completed template and takes ownership of it.
170 void addTemplate(std::unique_ptr<MacroMolTemplate> macroMolTemplate);
171
172 //! Returns a matching template, or nullptr if none has been added.
174 MonomerClass monomerClass, const std::string &name) const;
175 //! Returns a matching template, or nullptr if none has been added.
177 MonomerClass monomerClass, const std::string &symbol) const;
178
179 private:
180 using MacroMolTemplateKey = std::pair<MonomerClass, std::string>;
181
182 std::map<MacroMolTemplateKey, std::unique_ptr<const MacroMolTemplate>> byName;
183 std::map<MacroMolTemplateKey, const MacroMolTemplate *> bySymbol;
184};
185
186} // namespace RDKit
187
188#endif
Defines atom-level macro atom information.
Defines the editable molecule class RWMol.
Defines the SubstanceGroup class.
Collects and validates the pieces needed to create a MacroMolTemplate.
MacroMolTemplateBuilder(const ROMol &mol, MonomerClass monomerClass, std::string name, std::string symbol, std::string originalData)
RWMol & getMol()
Returns the mutable molecule being prepared for the template.
MacroMolTemplateBuilder & setMainGroup(std::vector< unsigned int > &&atomIdxs)
Defines the atoms retained as the main monomer group.
MacroMolTemplateBuilder & setSubclass(std::string subclass)
Sets the optional SCSR subclass.
std::unique_ptr< MacroMolTemplate > build() const
Validates the complete definition and returns an immutable template.
MacroMolTemplateBuilder & addLeavingGroup(MacroMolLeavingGroup &&leavingGroup)
Adds a leaving group and its attachment-point definition.
void addTemplate(std::unique_ptr< MacroMolTemplate > macroMolTemplate)
Adds a completed template and takes ownership of it.
const MacroMolTemplate * getByName(MonomerClass monomerClass, const std::string &name) const
Returns a matching template, or nullptr if none has been added.
MacroMolTemplateLibrary(MacroMolTemplateLibrary &&) noexcept=default
const MacroMolTemplate * getBySymbol(MonomerClass monomerClass, const std::string &symbol) const
Returns a matching template, or nullptr if none has been added.
MacroMolTemplateLibrary(const MacroMolTemplateLibrary &other)
const std::vector< MacroMolLeavingGroup > & getLeavingGroups() const
Returns the typed leaving-group definitions.
const std::vector< unsigned int > & getMainAtomIdxs() const
Returns the atom indices belonging to the retained monomer group.
MacroMolTemplate(MacroMolTemplate &&) noexcept=default
const std::string & getOriginalData() const
Returns the original template definition (SMILES, SDF, etc.).
const std::string & getName() const
Returns the name, e.g. "ALA".
MonomerClass getMonomerClass() const
Returns the monomer class used for lookup and the main SGroup CLASS.
const SubstanceGroup & getMainSgroup() const
Returns the main SUP SGroup mirrored onto the owned molecule.
const std::string & getSubclass() const
Returns the SCSR subclass, or an empty string if unspecified.
MacroMolTemplate(const MacroMolTemplate &)=default
friend class MacroMolTemplateBuilder
const ROMol & getMol() const
Returns a read-only view of the underlying template molecule.
const std::string & getSymbol() const
Returns the template symbol, e.g. "A" for alanine.
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
The class for representing SubstanceGroups.
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:321
static const char * symbol[119]
Definition mf.h:257
Std stuff.
MonomerClass
Format-neutral classes of monomer that a macro atom can represent.
Describes the atoms removed at one MacroMol template attachment point.
MacroMolLeavingGroup(std::vector< unsigned int > atomIdxs, unsigned int attachAtomIdx, unsigned int leavingAtomIdx, int attachPoint)
std::vector< unsigned int > atomIdxs