RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Bond.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// Handles all the properties of a bond
14
15#ifndef _RBTBOND_H_
16#define _RBTBOND_H_
17
18#include "rxdock/Atom.h"
19#include "rxdock/Config.h"
20
21#include <nlohmann/json.hpp>
22
23using json = nlohmann::json;
24
25namespace rxdock {
26
27class Bond {
28public:
30 // Constructors/destructors
32
33 // Default constructor
34 Bond();
35
36 // Cconstructor supplying all parameters
37 Bond(int nBondId, AtomPtr &spAtom1, AtomPtr &spAtom2,
38 int nFormalBondOrder = 1);
39
40 Bond(json j);
41
42 virtual ~Bond(); // Default destructor
43
44 Bond(const Bond &bond); // Copy constructor
45
46 Bond &operator=(const Bond &bond); // Copy assignment
47
49 // Stream functions
51
52 // Insertion operator (primarily for debugging)
53 // Note: needs to be friend so can access bond private data
54 // without using the accessor functions
55 RBTDLL_EXPORT friend std::ostream &operator<<(std::ostream &s,
56 const Bond &bond);
57
58 friend void to_json(json &j, const Bond &bond);
59 friend void from_json(const json &j, Bond &bond);
60
62 // Public accessor functions
64
65 // Bond ID
66 int GetBondId() const { return m_nBondId; }
67 void SetBondId(const int nBondId) { m_nBondId = nBondId; }
68
69 // Atom pointers
70 AtomPtr GetAtom1Ptr() const { return m_spAtom1; }
71 AtomPtr GetAtom2Ptr() const { return m_spAtom2; }
72 void SetAtom1Ptr(AtomPtr &spAtom1) { m_spAtom1 = spAtom1; }
73 void SetAtom2Ptr(AtomPtr &spAtom2) { m_spAtom2 = spAtom2; }
74
75 // Formal Bond order
76 int GetFormalBondOrder() const { return m_nFormalBondOrder; }
77 void SetFormalBondOrder(const int nFormalBondOrder) {
78 m_nFormalBondOrder = nFormalBondOrder;
79 }
80
81 // Partial Bond order
82 double GetPartialBondOrder() const { return m_dPartialBondOrder; }
83 void SetPartialBondOrder(const double dPartialBondOrder) {
84 m_dPartialBondOrder = dPartialBondOrder;
85 }
86
87 // CyclicFlag - flag to indicate bond is in a ring (set by Model::FindRing)
88 bool GetCyclicFlag() const { return m_bCyclic; }
89 void SetCyclicFlag(bool bCyclic = true) { m_bCyclic = bCyclic; }
90
91 // SelectionFlag - general purpose flag can be set/cleared by various search
92 // algorithms (e.g. FindRings)
93 bool GetSelectionFlag() const { return m_bSelected; }
94 void SetSelectionFlag(bool bSelected = true) { m_bSelected = bSelected; }
95
97 // Public methods
99 // Returns bond length
100 double Length() const;
101
102protected:
104 // Protected methods
106
107private:
109 // Private methods
111
112protected:
114 // Protected data
116
117private:
119 // Private data
121 int m_nBondId; // Original bond ID in PSF file
122 AtomPtr m_spAtom1; // Smart pointer to atom 1
123 AtomPtr m_spAtom2; // Smart pointer to atom 2
124 int m_nFormalBondOrder; // Formal bond order (1,2,3, no aromatic bond
125 // orders of 1.5)
126 double m_dPartialBondOrder; // Partial bond order (1.0, 1.5, 2.0, 3.0 etc)
127 bool m_bCyclic; // Is the bond in a ring ?
128 bool m_bSelected; // Can be set/cleared by various search algorithms (e.g.
129 // FindRings)
130};
131
132// Useful typedefs
133typedef SmartPtr<Bond> BondPtr; // Smart pointer
134typedef std::vector<BondPtr> BondList; // Vector of smart pointers
135typedef BondList::iterator BondListIter;
136typedef BondList::const_iterator BondListConstIter;
137
139// Non-member functions (in rxdock namespace)
141
142std::ostream &operator<<(std::ostream &s, const Bond &bond);
143
144void to_json(json &j, const Bond &bond);
145void from_json(const json &j, Bond &bond);
146
148// Predicates (for use by STL algorithms)
150// DM 08 May 2002 - convert to regular Bond* functions
151// More universal as BondPtr parameters will be automatically degraded to
152// regular pointers anyway
153
154// Is bond selected ?
155class isBondSelected : public std::function<bool(Bond *)> {
156public:
157 explicit isBondSelected() = default;
158 bool operator()(Bond *pBond) const { return pBond->GetSelectionFlag(); }
159};
160
161// Is bond cyclic ?
162class isBondCyclic : public std::function<bool(Bond *)> {
163public:
164 explicit isBondCyclic() = default;
165 bool operator()(Bond *pBond) const { return pBond->GetCyclicFlag(); }
166};
167
168// Is bond rotatable ?
169class isBondRotatable : public std::function<bool(Bond *)> {
170public:
171 explicit isBondRotatable() = default;
172 RBTDLL_EXPORT bool operator()(Bond *) const;
173};
174
175// Is bond to a terminal NH3+ group?
176class isBondToNH3 : public std::function<bool(Bond *)> {
177public:
178 explicit isBondToNH3() = default;
179 RBTDLL_EXPORT bool operator()(Bond *) const;
180};
181
182// Is bond to a terminal OH group?
183class isBondToOH : public std::function<bool(Bond *)> {
184public:
185 explicit isBondToOH() = default;
186 RBTDLL_EXPORT bool operator()(Bond *pBond) const;
187};
188
189// DM 1 April 1999
190// Is bond2 equal to bond1 (checks if underlying regular pointers match)
191// Note: this is a binary rather than unary predicate
192// class isBondPtr_eq : public std::function<bool(Bond *, Bond *)> {
193// public:
194// explicit isBondPtr_eq() {}
195// Bool operator() (BondPtr spBond1, BondPtr spBond2) const {return
196// spBond1.Ptr() == spBond2.Ptr();}
197//};
198
199// Is bond.Ptr() equal to Bond* (checks if underlying regular pointers match)
200class isBondPtr_eq : public std::function<bool(Bond *)> {
201 Bond *p;
202
203public:
204 explicit isBondPtr_eq(Bond *pp) : p(pp) {}
205 bool operator()(Bond *pBond) const { return pBond == p; }
206};
207
208// DM 2 Aug 1999
209// Is bond2 equal to bond1 (checks if bond ID, atom1 and atom2 match)
210class isBond_eq : public std::function<bool(Bond *)> {
211 Bond *p;
212 isAtom_eq bIsAtomEqual;
213
214public:
215 explicit isBond_eq(Bond *pp) : p(pp) {}
216 bool operator()(Bond *pBond) const {
217 return ((pBond->GetBondId() == p->GetBondId()) &&
218 (bIsAtomEqual(pBond->GetAtom1Ptr(), p->GetAtom1Ptr())) &&
219 (bIsAtomEqual(pBond->GetAtom2Ptr(), p->GetAtom2Ptr())));
220 }
221};
222
223// DM 7 June 1999
224// Is bond an amide bond?
225class isBondAmide : public std::function<bool(Bond *)> {
226public:
227 explicit isBondAmide() = default;
228 RBTDLL_EXPORT bool operator()(Bond *) const;
229};
230
232// Bond list functions (implemented as STL algorithms)
234
235// Generic template version of GetNumBonds, passing in your own predicate
236template <class Predicate>
237unsigned int GetNumBondsWithPredicate(const BondList &bondList,
238 const Predicate &pred) {
239 return static_cast<unsigned int>(
240 std::count_if(bondList.begin(), bondList.end(), pred));
241}
242
243// Generic template version of GetBondList, passing in your own predicate
244template <class Predicate>
245BondList GetBondListWithPredicate(const BondList &bondList,
246 const Predicate &pred) {
247 BondList newBondList;
248 std::copy_if(bondList.begin(), bondList.end(),
249 std::back_inserter(newBondList), pred);
250 return newBondList;
251}
252
253// Generic template version of FindBond, passing in your own predicate
254template <class Predicate>
255BondListIter FindBond(BondList &bondList, const Predicate &pred) {
256 return std::find_if(bondList.begin(), bondList.end(), pred);
257}
258
259// Selected bonds
260void SetBondSelectionFlagsInList(BondList &bondList, bool bSelected = true);
261inline unsigned int GetNumSelectedBondsInList(const BondList &bondList) {
262 return GetNumBondsWithPredicate(bondList, isBondSelected());
263}
264
265inline BondList GetSelectedBondsFromList(const BondList &bondList) {
266 return GetBondListWithPredicate(bondList, isBondSelected());
267}
268
269// Cyclic bonds
270void SetBondCyclicFlagsInList(BondList &bondList, bool bCyclic = true);
271inline unsigned int GetNumCyclicBondsInList(const BondList &bondList) {
272 return GetNumBondsWithPredicate(bondList, isBondCyclic());
273}
274inline BondList GetCyclicBondsFromList(const BondList &bondList) {
275 return GetBondListWithPredicate(bondList, isBondCyclic());
276}
277
278// Rotatable bonds
279inline unsigned int GetNumRotatableBonds(const BondList &bondList) {
280 return GetNumBondsWithPredicate(bondList, isBondRotatable());
281}
282inline BondList GetRotatableBondList(const BondList &bondList) {
283 return GetBondListWithPredicate(bondList, isBondRotatable());
284}
285
286} // namespace rxdock
287
288#endif //_RBTBOND_H_
Definition Bond.h:27
Definition Atom.h:623
Definition Bond.h:225
Definition Bond.h:162
Definition Bond.h:200
Definition Bond.h:169
Definition Bond.h:155
Definition Bond.h:176
Definition Bond.h:183
Definition Bond.h:210