Coverage Report

Created: 2026-01-25 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openbabel/include/openbabel/phmodel.h
Line
Count
Source
1
/**********************************************************************
2
phmodel.h - Read pH rules and assign charges.
3
4
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
5
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison
6
7
This file is part of the Open Babel project.
8
For more information, see <http://openbabel.org/>
9
10
This program is free software; you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation version 2 of the License.
13
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
GNU General Public License for more details.
18
***********************************************************************/
19
20
#ifndef OB_PHMODEL_H
21
#define OB_PHMODEL_H
22
23
#include <openbabel/parsmart.h>
24
#include <openbabel/data.h>
25
26
namespace OpenBabel
27
{
28
29
// class introduction in phmodel.cpp
30
class OBAPI OBChemTsfm
31
{
32
    std::vector<int>                            _vadel;
33
    std::vector<std::pair<int,int> >            _vele;
34
    std::vector<std::pair<int,int> >            _vchrg;
35
    std::vector<std::pair<int,int> >            _vbdel;
36
    std::vector<std::pair<std::pair<int,int>,int> >  _vbond;
37
    OBSmartsPattern _bgn,_end;
38
public:
39
39
    OBChemTsfm()    {}
40
39
    ~OBChemTsfm()   {}
41
    //! Initialize this transformation with the supplied SMARTS patterns
42
    bool Init(std::string&start, std::string &end);
43
    //! Apply this transformation to all matches in the supplied OBMol
44
    bool Apply(OBMol&);
45
    /*! Is this transformation an acid dissociation?
46
     *  \code
47
     *      Ka
48
     *  HA ----> A(-)         (the H(+) will be deleted)
49
     *  \endcode
50
     *
51
     *  IsAcid() will check the charge in the end SMARTS pattern.
52
     *  \return true if the charge is less than 0 (-1).
53
     */
54
    bool IsAcid();
55
    /*! Is this a transformation to the conjugated acid from a base?
56
     *  \code
57
     *      Ka
58
     *  HA ----> A(-)         (the H(+) will be deleted)
59
     *  \endcode
60
     *
61
     *  IsBase() will check the charge in the end SMARTS pattern.
62
     *  \return true if the charge is higher than 0 (+1).
63
     */
64
    bool IsBase();
65
};
66
67
/*! \brief Corrections for pH used by OBMol::CorrectForPH()
68
 *
69
 *  The data/phmodel.txt file contains transformations which are applied
70
 *  to correct the charges for a given pH. This function uses the
71
 *  Henderson-Hasselbalch equation to calculate which species (protonated/
72
 *  unprotonated) is present in the highest concentration at the given pH.
73
 *
74
 *  For acids an entry would look like:
75
 *  \code
76
 *  # carboxylic acid
77
 *  O=C[OD1:1] >> O=C[O-:1] 4.0
78
 *  \endcode
79
 *
80
 *  The 4.0 is the pKa for the dissociation [HA] -> [H+] + [A-]. To
81
 *  calculate [HA]/[A-] we use:
82
 *  \code
83
 *  [HA] / [A-] = 10^(pKa - pH)
84
 *
85
 *  [HA]/[A-] > 1  :  [HA] > [A-]
86
 *  [HA]/[A-] < 1  :  [A-] > [HA]
87
 *  \endcode
88
 *
89
 *  For a base, an entry would look be:
90
 *  \code
91
 *  # methyl amine
92
 *  C[N:1] >> C[N+:1] 10.7
93
 *  \endcode
94
 *
95
 *  Here, the 10.7 is the pKa for the dissociation [BH+] -> [H+] + [B:]. To
96
 *  calculate [BH+]/[B:] we use:
97
 *  \code
98
 *  [BH+] / [B:] = 10^(pKa - pH)
99
 *
100
 *  [BH+]/[B:] > 1  :  [BH+] > [B:]
101
 *  [BH+]/[B:] < 1  :  [B:] > [BH+]
102
 *  \endcode
103
 *
104
 *  The transformations are all applied (if needed at the specified pH value) in
105
 *  the same order they are found in data/phmodel.txt.
106
 */
107
class OBAPI OBPhModel : public OBGlobalDataBase
108
{
109
    std::vector<OBChemTsfm*>                            _vtsfm;
110
    std::vector<double>                                 _vpKa;
111
    std::vector<std::pair<OBSmartsPattern*,std::vector<double> > > _vschrg;
112
public:
113
    OBPhModel();
114
    ~OBPhModel();
115
116
    void ParseLine(const char*) override;
117
    //! \return the number of chemical transformations
118
1
    size_t GetSize() override { return _vtsfm.size(); }
119
    void AssignSeedPartialCharge(OBMol&);
120
    //void CorrectForPH(OBMol&);
121
    void CorrectForPH(OBMol&, double pH  = 7.4 );
122
};
123
124
125
126
} //namespace OpenBabel
127
128
#endif // OB_PHMODEL_H
129
130
//! \file phmodel.h
131
//! \brief Read pH rules and assign charges.
132