RDKit: Charge.h Source File

| 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>
22#include <GraphMol/MolStandardize/AcidBaseCatalog/AcidBaseCatalogEntry.h>
23#include <GraphMol/MolStandardize/AcidBaseCatalog/AcidBaseCatalogParams.h>
24
25namespace RDKit {
26class RWMol;
27class ROMol;
28
29namespace MolStandardize {
30
31 RDKIT_MOLSTANDARDIZE_EXPORT extern const CleanupParameters
32 defaultCleanupParameters;
33
34typedef RDCatalog::HierarchCatalog<AcidBaseCatalogEntry, AcidBaseCatalogParams,
35 int>
36 AcidBaseCatalog;
37
38 struct RDKIT_MOLSTANDARDIZE_EXPORT ChargeCorrection {
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.
48 RDKIT_MOLSTANDARDIZE_EXPORT extern std::vector<ChargeCorrection>
49 CHARGE_CORRECTIONS;
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
59 class RDKIT_MOLSTANDARDIZE_EXPORT Reionizer {
60 public:
61 Reionizer();
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;
84 ~Reionizer();
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
90 void reionizeInPlace(RWMol &mol);
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
106 inline Reionizer *reionizerFromParams(const CleanupParameters &params) {
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
136 class RDKIT_MOLSTANDARDIZE_EXPORT Uncharger {
137 public:
138 Uncharger();
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);
156 void unchargeInPlace(RWMol &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
AcidBaseCatalogEntry.h
AcidBaseCatalogParams.h
Catalog.h
MolStandardize.h
Defines the CleanupParameters and some convenience functions.
RDKit::MolStandardize::AcidBaseCatalogEntry
Definition AcidBaseCatalogEntry.h:25
RDKit::MolStandardize::AcidBaseCatalogParams
Definition AcidBaseCatalogParams.h:25
RDKit::MolStandardize::Reionizer
Definition Charge.h:59
RDKit::MolStandardize::Reionizer::Reionizer
Reionizer(const std::string acidbaseFile, const std::vector< ChargeCorrection > ccs)
RDKit::MolStandardize::Reionizer::operator=
Reionizer & operator=(Reionizer const &)=delete
RDKit::MolStandardize::Reionizer::reionize
ROMol * reionize(const ROMol &mol)
Enforce charges on certain atoms, then perform competitive reionization.
RDKit::MolStandardize::Reionizer::Reionizer
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
RDKit::MolStandardize::Reionizer::Reionizer
Reionizer(std::istream &acidbaseStream, const std::vector< ChargeCorrection > ccs)
RDKit::MolStandardize::Reionizer::Reionizer
Reionizer()
RDKit::MolStandardize::Reionizer::~Reionizer
~Reionizer()
RDKit::MolStandardize::Reionizer::reionizeInPlace
void reionizeInPlace(RWMol &mol)
RDKit::MolStandardize::Reionizer::Reionizer
Reionizer(const std::vector< std::tuple< std::string, std::string, std::string > > &data)
construct a Reionizer with parameter data
RDKit::MolStandardize::Reionizer::Reionizer
Reionizer(const std::string acidbaseFile)
construct a Reionizer with a particular acidbaseFile
RDKit::MolStandardize::Reionizer::Reionizer
Reionizer(const Reionizer &other)=delete
making Reionizer objects non-copyable
RDKit::MolStandardize::Uncharger::Uncharger
Uncharger(bool canonicalOrdering, bool force)
Definition Charge.h:142
RDKit::MolStandardize::Uncharger::Uncharger
Uncharger(bool canonicalOrdering, bool force, bool protonationOnly)
Definition Charge.h:146
RDKit::MolStandardize::Uncharger::unchargeInPlace
void unchargeInPlace(RWMol &mol)
RDKit::MolStandardize::Uncharger::uncharge
ROMol * uncharge(const ROMol &mol)
RDKit::MolStandardize::Uncharger::Uncharger
Uncharger(const Uncharger &)=default
RDKit::MolStandardize::Uncharger::Uncharger
Uncharger(bool canonicalOrdering)
Definition Charge.h:139
RDKit::MolStandardize::Uncharger::Uncharger
Uncharger()
RDKit::MolStandardize::Uncharger::~Uncharger
~Uncharger()=default
RDKit::ROMol
Definition ROMol.h:199
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
export.h
RDKIT_MOLSTANDARDIZE_EXPORT
#define RDKIT_MOLSTANDARDIZE_EXPORT
Definition export.h:369
RDKit::MolStandardize
Definition AcidBaseCatalogEntry.h:22
RDKit::MolStandardize::CHARGE_CORRECTIONS
RDKIT_MOLSTANDARDIZE_EXPORT std::vector< ChargeCorrection > CHARGE_CORRECTIONS
RDKit::MolStandardize::reionizerFromParams
Reionizer * reionizerFromParams(const CleanupParameters &params)
Definition Charge.h:106
RDKit::MolStandardize::defaultCleanupParameters
RDKIT_MOLSTANDARDIZE_EXPORT const CleanupParameters defaultCleanupParameters
Definition Fragment.h:25
RDKit::MolStandardize::AcidBaseCatalog
RDCatalog::HierarchCatalog< AcidBaseCatalogEntry, AcidBaseCatalogParams, int > AcidBaseCatalog
Definition Charge.h:36
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::MolStandardize::ChargeCorrection::Name
std::string Name
Definition Charge.h:39
RDKit::MolStandardize::ChargeCorrection::Charge
int Charge
Definition Charge.h:41
RDKit::MolStandardize::ChargeCorrection::Smarts
std::string Smarts
Definition Charge.h:40
RDKit::MolStandardize::ChargeCorrection::ChargeCorrection
ChargeCorrection(std::string name, std::string smarts, int charge)
Definition Charge.h:43
RDKit::MolStandardize::CleanupParameters
Definition MolStandardize.h:41
RDKit::MolStandardize::CleanupParameters::acidbaseData
std::vector< std::tuple< std::string, std::string, std::string > > acidbaseData
Definition MolStandardize.h:82
RDKit::MolStandardize::CleanupParameters::acidbaseFile
std::string acidbaseFile
Definition MolStandardize.h:49