RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Cavity.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// Struct for holding a coordinate list representing an active site cavity
14// Properties are read-only once set in the constructor
15
16#ifndef _RBTCAVITY_H_
17#define _RBTCAVITY_H_
18
19#include "rxdock/Config.h"
20#include "rxdock/Coord.h"
21#include "rxdock/PrincipalAxes.h"
22#include "rxdock/RealGrid.h"
23
24namespace rxdock {
25
26class Cavity {
27public:
29 // Constructors/destructors
30
31 // Constructor
32 Cavity(const CoordList &coordList, const Vector gridStep)
33 : m_coordList(coordList), m_gridStep(gridStep),
34 m_prAxes(GetPrincipalAxesOfAtoms(coordList)),
35 m_minCoord(Min(coordList)), m_maxCoord(Max(coordList)) {}
36
37 // Constructor reading from binary stream
38 Cavity(json j) { j.get_to(*this); }
39
40 // Destructor
41 virtual ~Cavity() {}
42
44 // Stream functions
46
47 // Insertion operator
48 friend std::ostream &operator<<(std::ostream &s, const Cavity &cavity) {
49 cavity.Print(s);
50 return s;
51 }
52
53 // Virtual function for dumping cavity details to an output stream
54 // Derived classes can override if required
55 virtual void Print(std::ostream &s) const {
56 s << "Size=" << m_coordList.size() << " points; Vol=" << GetVolume()
57 << " A^3; Min=" << m_minCoord << "; Max=" << m_maxCoord
58 << "; Center=" << m_prAxes.com << "; Extent=" << m_maxCoord - m_minCoord;
59 }
60
61 // DM 4 Apr 2002 - return a grid with all cavity points set to 1.0
62 RealGridPtr GetGrid() const {
63 Vector extent = m_maxCoord - m_minCoord;
64 // Add +3 to allow a small border
65 Eigen::Vector3d nXYZ = extent.xyz.array() / m_gridStep.xyz.array();
66 unsigned int nX = static_cast<unsigned int>(nXYZ(0)) + 3;
67 unsigned int nY = static_cast<unsigned int>(nXYZ(1)) + 3;
68 unsigned int nZ = static_cast<unsigned int>(nXYZ(2)) + 3;
69 RealGridPtr spGrid = RealGridPtr(
70 new RealGrid(m_minCoord - m_gridStep, m_gridStep, nX, nY, nZ));
71 for (CoordListConstIter iter = m_coordList.begin();
72 iter != m_coordList.end(); iter++) {
73 spGrid->SetValue(*iter, 1.0);
74 }
75 return spGrid;
76 }
77
79 // Public methods
81 const Coord &GetCenterOfMass() const { return m_prAxes.com; }
82 const PrincipalAxes &GetPrincipalAxes() const { return m_prAxes; }
83 int GetNumCoords() const { return m_coordList.size(); }
84 const CoordList &GetCoordList() const { return m_coordList; }
85 const Coord &GetMinCoord() const { return m_minCoord; }
86 const Coord &GetMaxCoord() const { return m_maxCoord; }
87 const Vector &GetGridStep() const { return m_gridStep; }
88 double GetVolume() const {
89 return m_coordList.size() * m_gridStep.xyz.prod();
90 }
91
92 friend void to_json(json &j, const Cavity &c) {
93 j = json{{"grid-step", c.m_gridStep}, {"coordinates", c.m_coordList}};
94 }
95
96 friend void from_json(const json &j, Cavity &c) {
97 j.at("grid-step").get_to(c.m_gridStep);
98 j.at("coordinates").get_to(c.m_coordList);
99 }
100
101protected:
103 // Protected methods
105
106private:
108 // Private methods
110 Cavity(); // Disable default constructor
111 Cavity(const Cavity &); // Copy constructor disabled by default
112 Cavity &operator=(const Cavity &); // Copy assignment disabled by
113 // default
114
115protected:
117 // Protected data
119
120private:
122 // Private data
124 CoordList m_coordList;
125 Vector m_gridStep;
126 PrincipalAxes m_prAxes;
127 Coord m_minCoord;
128 Coord m_maxCoord;
129};
130
131// Useful typedefs
132typedef SmartPtr<Cavity> CavityPtr; // Smart pointer
133typedef std::vector<CavityPtr> CavityList; // Vector of smart pointers
134typedef CavityList::iterator CavityListIter;
135typedef CavityList::const_iterator CavityListConstIter;
136
138// Comparison functions for sorting CavityPtr containers
139// For use by STL sort algorithms
141// Less than operator for sorting CavityPtrs into ascending order by center
142// of mass distance from a given coord
144 const Coord &c;
145
146public:
147 CavityPtrCmp_Distance(const Coord &cc) : c(cc) {}
148 bool operator()(CavityPtr spCav1, CavityPtr spCav2) const {
149 return Length2(spCav1->GetCenterOfMass() - c) <
150 Length2(spCav2->GetCenterOfMass() - c);
151 }
152};
153// Less than operator for sorting CavityPtrs into descending order by volume
155public:
157 bool operator()(CavityPtr spCav1, CavityPtr spCav2) const {
158 return spCav1->GetNumCoords() > spCav2->GetNumCoords();
159 }
160};
162// Predicate functions for CavityPtr
163// For use by STL algorithms
165class isCavityNearCoord : public std::function<bool(CavityPtr)> {
166 const Coord &c;
167 double r2; // radius squared (to avoid taking square roots)
168public:
169 explicit isCavityNearCoord(const Coord &cc, double rr) : c(cc), r2(rr * rr) {}
170 bool operator()(CavityPtr spCavity) const {
171 return Length2(spCavity->GetCenterOfMass() - c) <= r2;
172 }
173};
174
176// Functions objects for performing actions on cavities
177// For use by STL algorithms
179inline const Coord &ExtractCavityMinCoord(CavityPtr spCav) {
180 return spCav->GetMinCoord();
181}
182inline const Coord &ExtractCavityMaxCoord(CavityPtr spCav) {
183 return spCav->GetMaxCoord();
184}
185
186} // namespace rxdock
187
188#endif //_RBTCAVITY_H_
Definition Cavity.h:143
Definition Cavity.h:154
Definition Cavity.h:26
Definition Coord.h:45
Definition PrincipalAxes.h:29
Definition RealGrid.h:30
Definition Cavity.h:165