RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Model.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 _RBTMODEL_H_
14#define _RBTMODEL_H_
15
16#include "rxdock/Atom.h"
17#include "rxdock/Bond.h"
18#include "rxdock/Config.h"
19#include "rxdock/ModelMutator.h"
20#include "rxdock/PrincipalAxes.h"
21#include "rxdock/PseudoAtom.h"
22#include "rxdock/Variant.h"
23
24#include <nlohmann/json.hpp>
25
26using json = nlohmann::json;
27
28namespace rxdock {
29
30class BaseMolecularFileSource;
31class FlexData;
32class ChromElement;
33
34class Model {
35public:
37 // Constructors
39 // Read topology from MolecularFileSource, and coordinates if supported by
40 // source
41 RBTDLL_EXPORT Model(BaseMolecularFileSource *pMolSource);
42
43 //(Fairly) temporary constructor taking arbitrary atom and bond lists
44 // Use with caution
45 RBTDLL_EXPORT Model(AtomList &atomList, BondList &bondList);
46
47 Model(json j);
48
49 // Default destructor
50 virtual ~Model();
51
52 friend void to_json(json &j, const Model &model);
53 friend void from_json(const json &j, Model &model);
54
56 // Friend functions/classes
58 // DM 30 Jul 2001 - allow access to atom list by helper class for flexible
59 // models
60 friend class ModelMutator;
61
63 // Public accessor functions
65
66 // Only Get functions are currently provided
67 // Models are designed to be CreateOnce (from file), ReadMany
68
69 // Model name
70 std::string GetName() const { return m_strName; }
71
72 // Titles
73 int GetNumTitles() const { return m_titleList.size(); }
74 std::vector<std::string> GetTitleList() const { return m_titleList; }
75 void SetTitle(std::size_t index, const std::string &strTitle) {
76 m_titleList[index] = strTitle;
77 }
78
79 // Atoms
80 int GetNumAtoms() const { return m_atomList.size(); }
81 AtomList GetAtomList() const { return m_atomList; }
82
83 // Bonds
84 int GetNumBonds() const { return m_bondList.size(); }
85 BondList GetBondList() const { return m_bondList; }
86
87 // Segments
88 int GetNumSegments() const { return m_segmentMap.size(); }
89 SegmentMap GetSegmentMap() const { return m_segmentMap; }
90
91 // Rings
92 int GetNumRings() const { return m_ringList.size(); }
93 AtomListList GetRingAtomLists() const { return m_ringList; }
94
95 // DM 12 May 1999 - support for associated model data (e.g. SD file, or
96 // generated by rbdock etc) Get number of data fields
97 int GetNumData() const { return m_dataMap.size(); }
98 // Get list of field names as string list
99 std::vector<std::string> GetDataFieldList() const;
100 // Get all data as map of key=field name, value=variant (double,string or
101 // string list)
102 StringVariantMap GetDataMap() const { return m_dataMap; }
103 // Query as to whether a particular data field name is present
104 bool isDataFieldPresent(const std::string &strDataField) const;
105 // Get a particular data value
106 RBTDLL_EXPORT Variant GetDataValue(const std::string &strDataField) const;
107 // Set a data value (replaces existing value if field name already exists)
108 RBTDLL_EXPORT void SetDataValue(const std::string &strDataField,
109 const Variant &dataValue);
110 // Removes a data field completely from the data map
111 void ClearDataField(const std::string &strDataField);
112 // Removes all data fields starting with a given prefix from the data map
113 RBTDLL_EXPORT void ClearAllDataFields(const std::string &strDataFieldPrefix);
114 // Removes all data fields from the data map
115 void ClearAllDataFields();
116
117 // DM 11 Jul 2000 - pseudoatom handling
118 PseudoAtomPtr AddPseudoAtom(const AtomList &atomList);
119 void ClearPseudoAtoms();
120 void UpdatePseudoAtoms(); // Updates pseudoatom coords
121 unsigned int GetNumPseudoAtoms() const;
122 PseudoAtomList GetPseudoAtomList() const;
123
124 // DM 1 Jul 2002 - tethered atom handling
125 unsigned int GetNumTetheredAtoms() const;
126 AtomList GetTetheredAtomList() const;
127
128 // DM 7 June 2006 - occupancy handling
129 // The model occupancy is represented in two ways:
130 // 1) Occupancy variable (0.0 to 1.0)
131 // 2) Enabled state (true/false)
132 // If occupancy >= threshold, enabled=true
133 // If occupancy < threshold, enabled=false
134 // The occupancy variable is managed by the occupancy chromosome element
135 // Scoring functions read the enabled state to determined if a model is
136 // considered as present or absent
137 double GetOccupancy() const { return m_occupancy; }
138 bool GetEnabled() const { return m_enabled; }
139 // Sets the occupancy and enabled state simultaneously
140 RBTDLL_EXPORT void SetOccupancy(double occupancy, double threshold = 0.5);
141
143 // Public methods
145
146 // Update coords from a data source
147 void UpdateCoords(BaseMolecularFileSource *pMolSource);
148
149 // DM 07 Jan 1999
150 // Translate molecule by the given vector
151 void Translate(const Vector &vector);
152 // Rotate molecule around the given axis (through the center of mass) by theta
153 // degrees
154 void Rotate(const Vector &axis, double thetaDeg);
155 // DM 09 Feb 1999 - Rotate molecule around the given axis (through the given
156 // coordinate) by theta degrees
157 void Rotate(const Vector &axis, double thetaDeg, const Coord &center);
158 // Rotate around a given bond by theta degrees (spins both ends of the bond in
159 // opposite directions)
160 RBTDLL_EXPORT void RotateBond(BondPtr spBond, double thetaDeg);
161 // DM 09 Feb 1999 - Rotate around a given bond by theta degrees, keeping the
162 // given atom fixed (only spins the other end of the bond)
163 void RotateBond(BondPtr spBond, double thetaDeg, AtomPtr spFixedAtom);
164 // DM 25 Feb 1999 - Rotate around a given bond by theta degrees, only spinning
165 // one end of the bond If bSwap is false, spins the end bonded to atom2 in the
166 // bond If bSwap is true, spins the end bonded to atom1 in the bond
167 RBTDLL_EXPORT void RotateBond(BondPtr spBond, double thetaDeg, bool bSwap);
168
169 // DM 8 Feb 1999
170 void SaveCoords(const std::string &coordName = "");
171 RBTDLL_EXPORT void RevertCoords(const std::string &coordName = "");
172 std::map<std::string, int> GetSavedCoordNames() const { return m_coordNames; }
173 int GetNumSavedCoords() const { return m_coordNames.size(); }
174 int GetCurrentCoords() const { return m_currentCoord; }
175 RBTDLL_EXPORT void RevertCoords(int);
176
177 // Returns center of mass of model
178 Coord GetCenterOfMass() const;
179 // Translates the model so that the center of mass is at the given coord
180 void SetCenterOfMass(const Coord &c) { Translate(c - GetCenterOfMass()); }
181
182 // DM 9 Nov 1999
183 // Returns total atomic mass (molecular weight) for the model
184 RBTDLL_EXPORT double GetTotalMass() const;
185
186 // DM 14 Apr 1999 - principal axes methods
187 // Return principal axes and center of mass for the model
188 PrincipalAxes GetPrincipalAxes() const;
189 // Aligns the principal axes of the model to lie along alignAxes
190 // If required (bAlignCOM=true), also aligns the center of mass with
191 // alignAxes.com Default is to align with X,Y,Z Cartesian axes centered at
192 // origin
193 void AlignPrincipalAxes(const PrincipalAxes &alignAxes = PrincipalAxes(),
194 bool bAlignCOM = true);
195
196 // DM 19 Oct 2005 - new chromosome handling
197 // Sets the flexibility type for this model
198 // To revert to a rigid model, call SetFlexData(nullptr)
199 RBTDLL_EXPORT void SetFlexData(FlexData *pFlexData);
200 // Gets the flexibility type of this model
201 // Returns nullptr for a rigid model
202 RBTDLL_EXPORT FlexData *GetFlexData() const;
203 // Returns a clone of the current chromosome for this model
204 // The caller has the responsibility for mem management of the clone
205 // Returns nullptr for a rigid model
206 RBTDLL_EXPORT ChromElement *GetChrom() const;
207
208 bool isFlexible() const;
209 const AtomRList &GetFlexIntns(Atom *pAtom) const;
210 BondList GetFlexBonds() const;
211 // Selects all atoms that are rotated by at least one rotable bond
212 void SelectFlexAtoms();
213 void SelectFlexAtoms(Atom *pAtom);
214
216 // Atom list functions (provided for convenience, as user could just as well
217 // call the rxdock namespace functions with Model::GetAtomList)
218 // e.g. AtomList atomList =
219 // GetSelectedAtomList(spModel->GetAtomList); is equivalent to
220 // AtomList atomList = spModel->GetSelectedAtomList();
222
223 // Unary
224 // Generic template version of GetNumAtoms, passing in your own predicate
225 // template<class Predicate> UInt GetNumAtoms(const Predicate& pred);
226 // Generic template version of GetAtomList, passing in your own predicate
227 // template<class Predicate> AtomList GetAtomList(const Predicate& pred);
228
229 // Selected atoms
230 void SetAtomSelectionFlags(bool bSelected = true);
231 unsigned int GetNumSelectedAtoms();
232 AtomList GetSelectedAtomList();
233
234 // Cyclic atoms
235 void SetAtomCyclicFlags(bool bCyclic = true);
236 unsigned int GetNumCyclicAtoms();
237 AtomList GetCyclicAtomList();
238
239 // DM 21 Jul 1999 User1 flag
240 void SetAtomUser1Flags(bool bUser1 = true);
241 // DM 29 Jan 2000 User1 double
242 void SetAtomUser1Values(double dUser1 = 0.0);
243 // DM 27 Jul 2000 User2 double
244 void SetAtomUser2Values(double dUser2 = 0.0);
245
246 // Hydrogen bond acceptor atoms
247 unsigned int GetNumHBondAcceptorAtoms();
248 AtomList GetHBondAcceptorAtomList();
249
250 // Hydrogen bond donor atoms
251 unsigned int GetNumHBondDonorAtoms();
252 AtomList GetHBondDonorAtomList();
253
254 //(Formally) charged atoms
255 unsigned int GetNumChargedAtoms();
256 AtomList GetChargedAtomList();
257
258 // Planar atoms
259 unsigned int GetNumPlanarAtoms();
260 AtomList GetPlanarAtomList();
261
262 // Binary
263
264 // Atoms with atomic no = nAtomicNo
265 unsigned int GetNumAtomsWithAtomicNo(int nAtomicNo);
266 AtomList GetAtomListWithAtomicNo(int nAtomicNo);
267
268 // Atoms with FFType = strFFType
269 unsigned int GetNumAtomsWithFFType(std::string strFFType);
270 AtomList GetAtomListWithFFType(std::string strFFType);
271
273 // Bond list functions (provided for convenience, as user could just as well
274 // call the rxdock namespace functions with Model::GetBondList)
275 // e.g. BondList bondList =
276 // GetSelectedBondList(spModel->GetBondList); is equivalent to
277 // BondList bondList = spModel->GetSelectedBondList();
279
280 // Unary
281
282 // Generic template version of GetNumBonds, passing in your own predicate
283 template <class Predicate> unsigned int GetNumBonds(const Predicate &pred);
284 // Generic template version of GetBondList, passing in your own predicate
285 template <class Predicate> BondList GetBondList(const Predicate &pred);
286
287 // Selected bonds
288 void SetBondSelectionFlags(bool bSelected = true);
289 unsigned int GetNumSelectedBonds();
290 BondList GetSelectedBondList();
291
292 // Cyclic bonds
293 void SetBondCyclicFlags(bool bCyclic = true);
294 unsigned int GetNumCyclicBonds();
295 BondList GetCyclicBondList();
296
297 // DM 10 Dec 1998 - at some point these functions should be implemented as
298 // generic rxdock namespace functions operating on arbitrary atom and bond
299 // lists
300
301 // D Morley, 2 Dec 1998 - go back to the old way, it's more convenient to get
302 // all donors in the same list and separate them later void
303 // GetHBondDonorLists(AtomList& donorList, AtomList& donorHList);
304
305 // Get min and max x,y,z coords
306 // bInit = true => initialize min, max
307 // bInit = false => don't initialize min, max (useful for accumulating min,max
308 // over several Models)
309 void GetMinMaxCoords(Coord &minCoord, Coord &maxCoord, bool bInit = true);
310
311 // Get map of (key=force field atom type string, value=no. of occurrences)
312 std::map<std::string, int> GetAtomTypeMap();
313
314 // Get map of (key=force field bond type (atom type pair) string, value=no. of
315 // occurrences)
316 std::map<std::string, int> GetBondTypeMap();
317
318protected:
320 // Private methods
322
323private:
324 Model(); // Disable default constructor
325 Model(const Model &); // Copy constructor disabled by default
326 Model &operator=(const Model &); // Copy assignment disabled by default
327
328 // Create a new model from a data source
329 void Create(BaseMolecularFileSource *pMolSource);
330 void Clear(); // Clear the current model
331 void AddAtoms(AtomList &atomList); // Register an atom list with the model
332
334 // Private data
336private:
337 std::string m_strName; // Model name
338 std::vector<std::string> m_titleList; // Title list (read from file)
339 AtomList m_atomList; // atom list
340 BondList m_bondList; // bond list
341 SegmentMap m_segmentMap; // map of (key=segment name, value=atom count)
342 AtomListList m_ringList; //(DM 7 Dec 1998) list of atom lists for each ring
343 std::map<std::string, int>
344 m_coordNames; //(DM 8 Feb 1999) map of named coord sets
345 //(key=name, value=index into Atom coord map)
346 int m_currentCoord; // DM 11 Jul 2003 - which coord set is current
347 StringVariantMap m_dataMap; // DM 12 May 1999 - associated data (e.g. from
348 // SD file or generated by rbdock)
349 PseudoAtomList
350 m_pseudoAtomList; // DM 11 Jul 2000 - store associated pseudoatoms
352 m_spMutator; // DM 30 Jul 2001 - helper object for fast dihedral mutations
353 FlexData *m_pFlexData; // Stores the flexibility data for this model
354 ChromElement *m_pChrom; // Reference chromosome. GetChrom() returns a clone
355 // of this object.
356 double m_occupancy; // Occupancy value (0->1), in support of solvent occupancy
357 bool m_enabled; // Enabled state, depends on occupancy value and threshold
358};
359
360void to_json(json &j, const Model &model);
361void from_json(const json &j, Model &model);
362
363// Useful typedefs
364typedef SmartPtr<Model> ModelPtr; // Smart pointer
365typedef std::vector<ModelPtr> ModelList; // Vector of smart pointers
366typedef ModelList::iterator ModelListIter;
367typedef ModelList::const_iterator ModelListConstIter;
368
369} // namespace rxdock
370
371#endif //_RBTMODEL_H_
Definition Atom.h:49
Definition BaseMolecularFileSource.h:29
Definition ChromElement.h:36
Definition Coord.h:45
Definition FlexData.h:27
Definition ModelMutator.h:39
Definition Model.h:34
Definition PrincipalAxes.h:29
Definition Atom.h:988
Definition SmartPointer.h:48
Definition Variant.h:30