RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
InteractionGrid.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// Grid for indexing interactions involving more than 2 atoms
14
15#ifndef _RBTINTERACTIONGRID_H_
16#define _RBTINTERACTIONGRID_H_
17
18#include "rxdock/Atom.h"
19#include "rxdock/BaseGrid.h"
20
21#include <nlohmann/json.hpp>
22
23using json = nlohmann::json;
24
25namespace rxdock {
26
27// simple container for up to 3 atoms, to hold one half of an interaction
28// i.e. receptor atoms or ligand atoms.
30public:
31 enum eLP { NONE, PLANE, LONEPAIR };
32 InteractionCenter(Atom *pAtom1 = nullptr, Atom *pAtom2 = nullptr,
33 Atom *pAtom3 = nullptr, eLP LP = NONE)
34 : m_pAtom1(pAtom1), m_pAtom2(pAtom2), m_pAtom3(pAtom3), m_LP(LP) {
35 _RBTOBJECTCOUNTER_CONSTR_("InteractionCenter");
36 }
37 ~InteractionCenter() { _RBTOBJECTCOUNTER_DESTR_("InteractionCenter"); }
38
39 friend void to_json(json &j, const InteractionCenter &interactionCenter);
40 friend void from_json(const json &j, InteractionCenter &interactionCenter);
41
42 Atom *GetAtom1Ptr() const { return m_pAtom1; }
43 Atom *GetAtom2Ptr() const { return m_pAtom2; }
44 Atom *GetAtom3Ptr() const { return m_pAtom3; }
45 eLP LP() const { return m_LP; }
46 // Returns list of constituent atoms
47 //(deconvolutes pseudoatoms into their constituent Atom* lists)
48 AtomRList GetAtomList() const;
49 bool isSelected() const;
50
51private:
52 // Could be a useful general function
53 // If pAtom is a pseudo atom, then pushes all the constituent atoms onto list
54 // else, push pAtom onto the list
55 void AccumulateAtomList(const Atom *pAtom, AtomRList &atomList) const;
56 Atom *m_pAtom1;
57 Atom *m_pAtom2;
58 Atom *m_pAtom3;
59 eLP m_LP;
60};
61
62void to_json(json &j, const InteractionCenter &interactionCenter);
63void from_json(const json &j, InteractionCenter &interactionCenter);
64
65typedef std::vector<InteractionCenter *>
66 InteractionCenterList; // Vector of regular pointers
67typedef InteractionCenterList::iterator InteractionCenterListIter;
68typedef InteractionCenterList::const_iterator InteractionCenterListConstIter;
69
70// Less than operator for sorting InteractionCenter* by pointer value
72public:
73 bool operator()(const InteractionCenter *pIC1,
74 const InteractionCenter *pIC2) const {
75 return pIC1 < pIC2;
76 }
77};
78// Is interaction center selected ?
80 : public std::function<bool(InteractionCenter *)> {
81public:
82 explicit isInteractionCenterSelected() {}
83 bool operator()(const InteractionCenter *pIC) const {
84 return pIC->isSelected();
85 }
86};
87
88// Is the distance between interaction centers less than a given value ?
89// Function checks d**2 to save performing a sqrt
90class isInteractionD_lt : public std::function<bool(InteractionCenter *)> {
91 double d_sq;
92 Atom *a;
93
94public:
95 explicit isInteractionD_lt(const InteractionCenter *pIC1, double dd)
96 : d_sq(dd * dd), a(pIC1->GetAtom1Ptr()) {}
97 bool operator()(const InteractionCenter *pIC2) const {
98 return Length2(pIC2->GetAtom1Ptr()->GetCoords(), a->GetCoords()) < d_sq;
99 }
100};
101
102// Select/deselect the interaction center (selects all constituent atoms)
104 bool b;
105
106public:
107 explicit SelectInteractionCenter(bool bb) : b(bb) {}
108 void operator()(InteractionCenter *pIC);
109};
110
111// A map of interaction centers indexed by unsigned int
112// Used to store the receptor atom lists at each grid point
113// DM 11 Jul 2000 - use map of regular Atom* list (not AtomPtr smart
114// pointer list)
115
116// DM 3 Nov 2000 - replace map by vector for faster lookup
117// typedef std::map<UInt,InteractionCenterList> InteractionListMap;
118typedef std::vector<InteractionCenterList> InteractionListMap;
119
120typedef InteractionListMap::iterator InteractionListMapIter;
121typedef InteractionListMap::const_iterator InteractionListMapConstIter;
122
123class InteractionGrid : public BaseGrid {
124public:
125 // Class type string
126 static const std::string _CT;
128 // Constructors/destructors
129 // Construct a NXxNYxNZ grid running from gridMin at gridStep resolution
130 InteractionGrid(const Coord &gridMin, const Coord &gridStep, unsigned int NX,
131 unsigned int NY, unsigned int NZ, unsigned int NPad = 0);
132
133 // Constructor reading all params from binary stream
134 InteractionGrid(json j);
135
136 ~InteractionGrid(); // Default destructor
137
138 /*friend void to_json(json &j, const InteractionGrid &interactionGrid);
139 friend void from_json(const json &j, InteractionGrid &interactionGrid);*/
140
141 // Copy constructor
143 // Copy constructor taking base class argument
144 InteractionGrid(const BaseGrid &);
145 // Copy assignment
146 InteractionGrid &operator=(const InteractionGrid &);
147 // Copy assignment taking base class argument
148 InteractionGrid &operator=(const BaseGrid &);
149
151 // Virtual functions for reading/writing grid data to streams in
152 // text and binary format
153 // Subclasses should provide their own private OwnPrint
154 // method to handle subclass data members, and override the public
155 // Print method
156 virtual void Print(std::ostream &ostr) const; // Text output
157
159 // Public methods
161
163 // Get attribute functions
165 const InteractionCenterList &GetInteractionList(unsigned int iXYZ) const;
166 const InteractionCenterList &GetInteractionList(const Coord &c) const;
167
169 // Set attribute functions
171 void SetInteractionLists(InteractionCenter *pIntn, double radius);
172 void ClearInteractionLists();
173 void UniqueInteractionLists();
174
175protected:
177 // Protected methods
179 // Protected method for writing data members for this class to text stream
180 void OwnPrint(std::ostream &ostr) const;
181
182private:
184 // Private methods
186 InteractionGrid(); // Disable default constructor
187
188 // Helper function called by copy constructor and assignment operator
189 void CopyGrid(const InteractionGrid &);
190 // DM 3 Nov 2000 - create InteractionListMap of the appropriate size
191 void CreateMap();
192
193protected:
195 // Protected data
197
198private:
200 // Private data
202 InteractionListMap m_intnMap; // Used to store the interaction center lists
203 // at each grid point
204 const InteractionCenterList m_emptyList; // Dummy list used by GetAtomList
205};
206/*
207void to_json(json &j, const InteractionGrid &interactionGrid);
208void from_json(const json &j, InteractionGrid &interactionGrid);*/
209
210// Useful typedefs
211typedef SmartPtr<InteractionGrid> InteractionGridPtr; // Smart pointer
212
213} // namespace rxdock
214
215#endif //_RBTINTERACTIONGRID_H_
Definition Atom.h:49
Definition BaseGrid.h:27
Definition Coord.h:45
Definition InteractionGrid.h:71
Definition InteractionGrid.h:29
Definition InteractionGrid.h:123
Definition InteractionGrid.h:103
Definition SmartPointer.h:48
Definition InteractionGrid.h:80
Definition InteractionGrid.h:90