RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
InteractionTemplate.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#ifndef _RBTINTERACTIONTEMPLATE_H_
14#define _RBTINTERACTIONTEMPLATE_H_
15#include "rxdock/BaseGrid.h"
16#include "rxdock/Config.h"
17
18#include <loguru.hpp>
19
20namespace rxdock {
21
22template <class T> class InteractionNode {
23 T property;
24
25public:
26 InteractionNode() { _RBTOBJECTCOUNTER_CONSTR_("InteractionNode"); }
27 InteractionNode(T aProperty) {
28 _RBTOBJECTCOUNTER_CONSTR_("InteractionNode");
29 property = aProperty;
30 }
31 ~InteractionNode() { _RBTOBJECTCOUNTER_DESTR_("InteractionNode"); }
32
33 T GetProperty() const { return property; }
34 void SetProperty(T aProperty) { property = aProperty; }
35};
36
37template <typename T> // instead InteractionCenterList
38class InteractionNodeList : public std::vector<InteractionNode<T> *> {
39}; // std:vector ctors
40
41template <typename T> // instead InteractionListMap
42class InteractionNodeListMap : public std::vector<InteractionNodeList<T>> {
43}; // std:vector ctors
44
45template <typename T>
47};
48
49template <typename T>
51 : public InteractionNodeListMap<T>::const_iterator {};
52// Most of the stuff is copied shamelessly from InteractionGrid.[cxx,h]
53template <class T> class InteractionGridTemplate : public BaseGrid {
54public:
55 static std::string _CT;
56
57 InteractionGridTemplate(const Coord &gridMin, const Coord &gridStep,
58 unsigned int NX, unsigned int NY, unsigned int NZ,
59 unsigned int NPad = 0) {
60 _CT = "InteractionGridTemplate";
61 CreateMap();
62 _RBTOBJECTCOUNTER_CONSTR_("InteractionGridTemplate");
63 }
64
65 // Constructor reading params from binary stream
66 InteractionGridTemplate(std::istream &istr) {
67 _CT = "InteractionGridTemplate";
68 CreateMap();
69 _RBTOBJECTCOUNTER_CONSTR_("InteractionGridTemplate");
70 }
71
73 ClearInteractionLists();
74 _RBTOBJECTCOUNTER_DESTR_("InteractionGridTemplate");
75 }
76
77 // Copy constructor
79 : BaseGrid(aGrid) {
80 CreateMap();
81 CopyGrid(aGrid);
82 _RBTOBJECTCOUNTER_COPYCONSTR_("InteractionGridTemplate");
83 }
84
85 // Copy constructor taking base class argument
87 CreateMap();
88 _RBTOBJECTCOUNTER_COPYCONSTR_("InteractionGridTemplate");
89 }
90
91 // Copy assignment
92 InteractionGridTemplate &operator=(const InteractionGridTemplate &aGrid) {
93 if (this != &aGrid) {
94 ClearInteractionLists();
95 BaseGrid::Operator = (aGrid);
96 CopyGrid(aGrid);
97 }
98 return *this;
99 }
100
101 // Copy assignment taking base class argument
102 InteractionGridTemplate &operator=(const BaseGrid &aGrid) {
103 if (this != &aGrid) {
104 ClearInteractionLists();
105 BaseGrid::Operator = (aGrid);
106 }
107 return *this;
108 }
109
110 virtual void Print(std::ostream &ostr) const { // Text output
111 BaseGrid::Print(ostr);
112 OwnPrint(ostr);
113 }
114
115 const InteractionNodeList<T> &GetInteractionList(unsigned int iXYZ) const {
116 if (isValid(iXYZ)) {
117 return m_intnMap[iXYZ];
118 } else {
119 return m_emptyList;
120 }
121 }
122
123 const InteractionNodeList<T> &GetInteractionList(const Coord &c) const {
124 if (isValid(c)) {
125 return m_intnMap[GetIXYZ(c)];
126 } else {
127 LOG_F(1, "InteractionGridTemplate::GetInteractionList: {} is off grid",
128 c);
129 return m_emptyList;
130 }
131 }
132
133 void SetInteractionLists(T *pIntn, double radius) {
134 Atom *pAtom = pIntn->GetProperty().atom;
135 if (nullptr == pAtom)
136 return;
137 const Coord &c = pAtom->GetCoords();
138 std::vector<unsigned int> sphereIndices;
139 GetSphereIndices(c, radius, sphereIndices);
140 for (std::vector<unsigned int>::const_iterator sphereIter =
141 sphereIndices.begin();
142 sphereIter != sphereIndices.end(); sphereIter++) {
143 m_intnMap[*sphereIter].push_back(pIntn);
144 }
145 }
146
147 void ClearInteractionLists() {
148 for (InteractionNodeListMap<T>::iterator iter = m_intnMap.begin();
149 iter != m_intnMap.end(); iter++) {
150 (*iter).clear();
151 }
152 }
153
154protected:
155 void OwnPrint(std::ostream &ostr) const {
156 ostr << std::endl << "Class\t" << _CT << std::endl;
157 ostr << "No. of entries in the map: " << m_intnMap.size() << std::endl;
158 }
159
160private:
162
163 void CopyGrid(const InteractionGridTemplate<T> &aGrid) {
164 m_intnMap = aGrid.m_intnMap;
165 }
166
167 void CreateMap() { m_intnMap = InteractionNodeListMap<T>(GetN()); }
168
169 InteractionNodeListMap<T> m_intnMap; // Used to store the interaction
170 // center lists at each grid point
171 const InteractionNodeList<T> m_emptyList; // Dummy list used by GetAtomList
172};
173
174template <typename T> // instead InteractionGridPtr
175class InteractionGridTemplatePtr : public SmartPtr<InteractionGridTemplate<T>> {
176};
177
178} // namespace rxdock
179
180#endif // _RBTINTERACTIONTEMPLATE_H_
Definition Atom.h:49
Definition BaseGrid.h:27
Definition Coord.h:45
Definition InteractionTemplate.h:175
Definition InteractionTemplate.h:53
Definition InteractionTemplate.h:51
Definition InteractionTemplate.h:46
Definition InteractionTemplate.h:42
Definition InteractionTemplate.h:38
Definition InteractionTemplate.h:22
Definition SmartPointer.h:48