RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Charge.h
Go to the documentation of this file.
1//
2// Copyright (C) 2018-2021 Susan H. Leung 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 Charge.h
11
12 \brief Defines the Reionizer class and Uncharger class.
13
14*/
15#include <RDGeneral/export.h>
16#ifndef RD_CHARGE_H
17#define RD_CHARGE_H
18#include <utility>
19
20#include "MolStandardize.h"
21#include <Catalogs/Catalog.h>
24
25namespace RDKit {
26class RWMol;
27class ROMol;
28
29namespace MolStandardize {
30
31RDKIT_MOLSTANDARDIZE_EXPORT extern const CleanupParameters
33
34typedef RDCatalog::HierarchCatalog<AcidBaseCatalogEntry, AcidBaseCatalogParams,
35 int>
37
39 std::string Name;
40 std::string Smarts;
41 int Charge;
42
43 ChargeCorrection(std::string name, std::string smarts, int charge)
44 : Name(std::move(name)), Smarts(std::move(smarts)), Charge(charge) {}
45};
46
47// The default list of ChargeCorrections.
48RDKIT_MOLSTANDARDIZE_EXPORT extern std::vector<ChargeCorrection>
50
51//! The reionizer class to fix charges and reionize a molecule such that the
52/// strongest acids ionize first.
53/*!
54
55 <b>Notes:</b>
56 -
57*/
58
60 public:
62 //! construct a Reionizer with a particular acidbaseFile
63 Reionizer(const std::string acidbaseFile);
64 //! construct a Reionizer with parameter data
65 Reionizer(const std::vector<std::tuple<std::string, std::string, std::string>>
66 &data);
67 //! construct a Reionizer with a particular acidbaseFile and charge
68 /// corrections
69 Reionizer(const std::string acidbaseFile,
70 const std::vector<ChargeCorrection> ccs);
71 //! construct a Reionizer with a particular acidbaseFile and charge
72 /// corrections
73 Reionizer(std::istream &acidbaseStream,
74 const std::vector<ChargeCorrection> ccs);
75
76 //! construct a Reionizer with parameter data and charge corrections
77 Reionizer(const std::vector<std::tuple<std::string, std::string, std::string>>
78 &data,
79 const std::vector<ChargeCorrection> ccs);
80
81 //! making Reionizer objects non-copyable
82 Reionizer(const Reionizer &other) = delete;
83 Reionizer &operator=(Reionizer const &) = delete;
85
86 //! Enforce charges on certain atoms, then perform competitive reionization.
87 ROMol *reionize(const ROMol &mol);
88 //! Enforce charges on certain atoms, then perform competitive reionization,
89 //! modifies molecule in place
91
92 private:
93 AcidBaseCatalog *d_abcat;
94 std::vector<ChargeCorrection> d_ccs;
95
96 std::pair<unsigned int, std::vector<unsigned int>> *strongestProtonated(
97 const ROMol &mol,
98 const std::vector<std::pair<ROMOL_SPTR, ROMOL_SPTR>> &abpairs);
99 std::pair<unsigned int, std::vector<unsigned int>> *weakestIonized(
100 const ROMol &mol,
101 const std::vector<std::pair<ROMOL_SPTR, ROMOL_SPTR>> &abpairs);
102
103}; // Reionizer class
104
105// caller owns the returned pointer
107 if (params.acidbaseData.empty()) {
108 return new Reionizer(params.acidbaseFile);
109 } else {
110 return new Reionizer(params.acidbaseData);
111 }
112}
113
114//! The Uncharger class for neutralizing ionized acids and bases.
115/*!
116
117 <b>Notes:</b>
118 - This class uncharges molecules by adding and/or removing hydrogens.
119 - For zwitterions, hydrogens are moved to eliminate charges where
120 possible.
121 - By default, in cases where there is a positive or negative charge
122 that is not possible to remove, an attempt is made to also preserve the
123 corresponding amount of opposite charge and result in an overall neutral
124 output structure.
125 - When the `force` option is set, all neutralizable sites are
126 uncharged, also when not-removable charges are present and the resulting
127 overall charge is therefore not null.
128 - By default, the removal of the existing charges is performed with
129 the addition or subtraction of both protons and hydride ions as appropriate.
130 If the `protonationOnly` option is enabled, the transformations applying to
131 the input structure are limited to changes in its protonation state and
132 charges that would otherwise require the exchange of a hydride ion (e.g.,
133 carbocations) are handled as not-removable.
134*/
135
137 public:
139 Uncharger(bool canonicalOrdering) : Uncharger() {
140 df_canonicalOrdering = canonicalOrdering;
141 }
142 Uncharger(bool canonicalOrdering, bool force) : Uncharger() {
143 df_canonicalOrdering = canonicalOrdering;
144 df_force = force;
145 }
146 Uncharger(bool canonicalOrdering, bool force, bool protonationOnly)
147 : Uncharger() {
148 df_canonicalOrdering = canonicalOrdering;
149 df_force = force;
150 df_protonationOnly = protonationOnly;
151 }
152 Uncharger(const Uncharger &) = default;
153 ~Uncharger() = default;
154
155 ROMol *uncharge(const ROMol &mol);
157
158 private:
159 bool df_canonicalOrdering = true;
160 bool df_force = false;
161 bool df_protonationOnly = false;
162 std::shared_ptr<ROMol> pos_h;
163 std::shared_ptr<ROMol> pos_noh;
164 std::shared_ptr<ROMol> neg;
165 std::shared_ptr<ROMol> neg_acid;
166}; // Uncharger class
167
168} // namespace MolStandardize
169} // namespace RDKit
170#endif
A Catalog with a hierarchical structure.
Definition Catalog.h:135
Reionizer(const std::string acidbaseFile, const std::vector< ChargeCorrection > ccs)
Reionizer & operator=(Reionizer const &)=delete
ROMol * reionize(const ROMol &mol)
Enforce charges on certain atoms, then perform competitive reionization.
Reionizer(const std::vector< std::tuple< std::string, std::string, std::string > > &data, const std::vector< ChargeCorrection > ccs)
construct a Reionizer with parameter data and charge corrections
Reionizer(std::istream &acidbaseStream, const std::vector< ChargeCorrection > ccs)
Reionizer(const std::vector< std::tuple< std::string, std::string, std::string > > &data)
construct a Reionizer with parameter data
Reionizer(const std::string acidbaseFile)
construct a Reionizer with a particular acidbaseFile
Reionizer(const Reionizer &other)=delete
making Reionizer objects non-copyable
The Uncharger class for neutralizing ionized acids and bases.
Definition Charge.h:136
Uncharger(bool canonicalOrdering, bool force)
Definition Charge.h:142
Uncharger(bool canonicalOrdering, bool force, bool protonationOnly)
Definition Charge.h:146
ROMol * uncharge(const ROMol &mol)
Uncharger(const Uncharger &)=default
Uncharger(bool canonicalOrdering)
Definition Charge.h:139
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
#define RDKIT_MOLSTANDARDIZE_EXPORT
Definition export.h:353
RDKIT_MOLSTANDARDIZE_EXPORT std::vector< ChargeCorrection > CHARGE_CORRECTIONS
Reionizer * reionizerFromParams(const CleanupParameters &params)
Definition Charge.h:106
RDKIT_MOLSTANDARDIZE_EXPORT const CleanupParameters defaultCleanupParameters
Definition Fragment.h:25
RDCatalog::HierarchCatalog< AcidBaseCatalogEntry, AcidBaseCatalogParams, int > AcidBaseCatalog
Definition Charge.h:36
Std stuff.
ChargeCorrection(std::string name, std::string smarts, int charge)
Definition Charge.h:43
std::vector< std::tuple< std::string, std::string, std::string > > acidbaseData