RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
VdwSF.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// Base implementation class for all vdW scoring functions
14
15#ifndef _RBTVDWSF_H_
16#define _RBTVDWSF_H_
17
18#include "rxdock/AnnotationHandler.h"
19#include "rxdock/Atom.h"
20#include "rxdock/BaseSF.h"
21#include "rxdock/ParameterFileSource.h"
22#include "rxdock/TriposAtomType.h"
23
24#include <nlohmann/json.hpp>
25
26using json = nlohmann::json;
27
28namespace rxdock {
29
30class VdwSF : public virtual BaseSF, public virtual AnnotationHandler {
31public:
32 // Class type string
33 static const std::string _CT;
34 // Parameter names
35 static const std::string _USE_4_8; // TRUE = 4-8; FALSE = 6-12
36 static const std::string
37 _USE_TRIPOS; // TRUE = Tripos 5.2 well depths; FALSE = GOLD well depths
38 static const std::string _RMAX; // Maximum range as a multiple of rmin
39 static const std::string _ECUT; // Energy cutoff for transition to short-range
40 // quadratic, as a multiple of well depth
41 static const std::string
42 _E0; // Energy at zero distance, as a multiple of ECUT
43
44 RBTDLL_EXPORT static const std::string &GetEcut();
45
46 virtual ~VdwSF();
47
48 friend void to_json(json &j, const VdwSF &vswSF);
49 friend void from_json(const json &j, VdwSF &vswSF);
50
51protected:
52 VdwSF();
53
54 // As this has a virtual base class we need a separate OwnParameterUpdated
55 // which can be called by concrete subclass ParameterUpdated methods
56 // See Stroustrup C++ 3rd edition, p395, on programming virtual base classes
57 void OwnParameterUpdated(const std::string &strName);
58
59 // Used by subclasses to calculate vdW potential between pAtom and all atoms
60 // in atomList
61 double VdwScore(const Atom *pAtom, const AtomRList &atomList) const;
62 // As above, but with additional checks for enabled state of each atom
63 double VdwScoreEnabledOnly(const Atom *pAtom,
64 const AtomRList &atomList) const;
65 // XB Same as above, used to calcutate intra terms without the reweighting
66 // factors Double VdwScoreIntra(const Atom* pAtom, const AtomRList&
67 // atomList) const; Looks up the maximum range (rmax_sq) for any interaction
68 // i.e. from across a row of m_vdwTable
69 double MaxVdwRange(const Atom *pAtom) const;
70 double MaxVdwRange(TriposAtomType::eType t) const;
71
72 // Index the intramolecular interactions
73 void BuildIntraMap(const AtomRList &atomList, AtomRListList &intns) const;
74 void BuildIntraMap(const AtomRList &atomList1, const AtomRList &atomList2,
75 AtomRListList &intns) const;
76 void Partition(const AtomRList &atomList, const AtomRListList &intns,
77 AtomRListList &prtIntns, double dist = 0.0) const;
78
79private:
80 // vdW scoring function params
81 struct vdwprms {
82 double A, B; // 6-12 or 4-8 params
83 double rmin; // Sum of vdw radii
84 double kij; // Well depth
85 double rmax_sq; // Max distance**2 over which the vdw score should be
86 // calculated
87 double rcutoff_sq; // Distance**2 at which the short-range quadratic
88 // potential kicks in
89 double ecutoff; // Energy at the cutoff point
90 double slope; // Slope of the short-range quadratic potential
91 double e0; // Energy at zero distance
92 };
93
94 typedef std::vector<VdwSF::vdwprms> VdwRow;
95 typedef VdwRow::iterator VdwRowIter;
96 typedef VdwRow::const_iterator VdwRowConstIter;
97 typedef std::vector<VdwRow> VdwTable;
98 typedef VdwTable::iterator VdwTableIter;
99 typedef VdwTable::const_iterator VdwTableConstIter;
100
101 // Generic scoring function primitive for 6-12
102 inline double f6_12(double R_sq, const vdwprms &prms) const {
103 // Zero well depth or long range: return zero
104 if ((prms.kij == 0.0) || (R_sq > prms.rmax_sq)) {
105 return 0.0;
106 }
107 // Short range: use quadratic potential
108 else if (R_sq < prms.rcutoff_sq) {
109 return prms.e0 - (prms.slope * R_sq);
110 }
111 // Everywhere else is 6-12
112 else {
113 double rr6 = 1.0 / (R_sq * R_sq * R_sq);
114 return rr6 * (rr6 * prms.A - prms.B);
115 }
116 }
117
118 // Generic scoring function primitive for 4-8
119 inline double f4_8(double R_sq, const vdwprms &prms) const {
120 // Zero well depth or long range: return zero
121 if ((prms.kij == 0.0) || (R_sq > prms.rmax_sq)) {
122 return 0.0;
123 }
124 // Short range: use quadratic potential
125 else if (R_sq < prms.rcutoff_sq) {
126 return prms.e0 - (prms.slope * R_sq);
127 }
128 // Everywhere else is 4-8
129 else {
130 double rr4 = 1.0 / (R_sq * R_sq);
131 return rr4 * (rr4 * prms.A - prms.B);
132 }
133 }
134
135 void Setup(); // Initialise m_vdwTable with appropriate params for each atom
136 // type pair
137 void SetupCloseRange(); // Regenerate the short-range params only (called more
138 // frequently)
139
140 // Private predicate
141 // Is the distance between atoms less than a given value ?
142 // Function checks d**2 to save performing a sqrt
143 class isD_lt : public std::function<bool(Atom *)> {
144 double d_sq;
145 Atom *a;
146
147 public:
148 explicit isD_lt(Atom *aa, double dd) : d_sq(dd * dd), a(aa) {}
149 bool operator()(Atom *aa) const {
150 return Length2(aa->GetCoords(), a->GetCoords()) < d_sq;
151 }
152 };
153
154 // Private data members
155 bool m_use_4_8;
156 bool m_use_tripos;
157 double m_rmax;
158 double m_ecut;
159 double m_e0;
160 ParameterFileSourcePtr m_spVdwSource; // File source for vdw params
161 VdwTable m_vdwTable; // Lookup table for all vdW params (indexed by Tripos
162 // atom type)
163 std::vector<double>
164 m_maxRange; // Vector of max ranges for each Tripos atom type
165};
166
167void to_json(json &j, const VdwSF &vswSF);
168void from_json(const json &j, VdwSF &vswSF);
169
170} // namespace rxdock
171
172#endif //_RBTVDWSF_H_
Definition AnnotationHandler.h:28
Definition Atom.h:49
Definition BaseSF.h:28
Definition VdwSF.h:30