LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
Loading...
Searching...
No Matches
hcore.hpp
1/*
2 Core code for hbonds utilties
3*/
4
5
6
7/*
8
9 This file is part of LOOS.
10
11 LOOS (Lightweight Object-Oriented Structure library)
12 Copyright (c) 2010, Tod D. Romo
13 Department of Biochemistry and Biophysics
14 School of Medicine & Dentistry, University of Rochester
15
16 This package (LOOS) is free software: you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation under version 3 of the License.
19
20 This package is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
27*/
28
29#if !defined(LOOS_HCORE_HPP)
30#define LOOS_HCORE_HPP
31
32#include <loos.hpp>
33
34
35namespace loos {
36 namespace HBonds {
37
38
40
41
42 // Our own exception so we can provide a little more helpful
43 // information when we throw-up...
44
45 struct ErrorWithAtom : public std::exception {
46 std::string _msg;
47
48 ErrorWithAtom(const loos::pAtom& a, const std::string& msg) {
49 std::stringstream ss;
50 ss << msg << std::endl << *a << std::endl;
51 _msg = ss.str();
52 }
53
54 const char* what() const throw() { return(_msg.c_str()); }
55
56 ~ErrorWithAtom() throw() { }
57 };
58
59
60
61 // Track the atoms that may participate in a hydrogen bond, and the
62 // atoms they're attached to (if necessary) to compute the bond angle.
63 // Also encapsulates the operations for determining if an h-bond
64 // exists...
65 //
66 // Note that we hook into the parent group's SharedPeriodicBox so we
67 // always have current periodic boundary info...
68
69
70 class SimpleAtom {
71 public:
72 SimpleAtom(const loos::pAtom& a) : atom(a), isHydrogen(divineHydrogen(a->name())), usePeriodicity(false) { }
73 SimpleAtom(const loos::pAtom& a, const loos::SharedPeriodicBox& b, const bool c = true) : atom(a), isHydrogen(divineHydrogen(a->name())), usePeriodicity(c), sbox(b) { }
74
75 void attach(const loos::pAtom&a) { attached_to = a; }
76 loos::pAtom attachedTo() const { return(attached_to); }
77
78 loos::pAtom rawAtom() const { return(atom); }
79
80 double distance2(const SimpleAtom& s) const;
81 double angle(const SimpleAtom& s) const;
82
83 static bool debuggingMode() { return(debugging); }
84 static void debuggingMode(const bool b) { debugging = b; }
85
86 static double innerRadius() { return(sqrt(inner)); }
87 static void innerRadius(const double r) { inner = r*r; }
88
89 static double outerRadius() { return(sqrt(outer)); }
90 static void outerRadius(const double r) { outer = r*r; }
91
92 static double maxDeviation() { return(deviation); }
93 static void maxDeviation(const double d) { deviation = d; }
94
95
96 // Tests whether two SimpleAtoms have a potential hydrogen-bond
97 // between them.
98 bool hydrogenBond(const SimpleAtom& other) const;
99
100 // Returns an AtomicGroup of all atoms that may have hydrogen-bonds
101 // to the current SimpleAtom
102 loos::AtomicGroup findHydrogenBonds(const std::vector<SimpleAtom>& group, const bool findFirstOnly = true);
103
104 std::vector<uint> findHydrogenBondsVector(const std::vector<SimpleAtom>& group);
105
106 // Returns a matrix where the rows represent time (frames in the
107 // trajectory) and columns represent acceptors (i.e. the passed
108 // group). Wherever there is a hydrogen-bond, U_ij is 1, and 0
109 // otherwise.
110 //
111 // maxt determines the maximum time (frame #) that is considered.
112 BondMatrix findHydrogenBondsMatrix(const std::vector<SimpleAtom>& group, loos::pTraj& traj, loos::AtomicGroup& model, const uint maxt) const;
113 BondMatrix findHydrogenBondsMatrix(const std::vector<SimpleAtom>& group, loos::pTraj& traj, loos::AtomicGroup& model) const {
114 return(findHydrogenBondsMatrix(group, traj, model, traj->nframes()));
115 }
116
117
118 // Converts an AtomicGroup into a vector of SimpleAtom's based on
119 // the passed selection. The use_periodicity is applied to all
120 // created SimpleAtoms...they also shared the PeriodicBox with the
121 // passed AtomicGroup.
122
123 static std::vector<SimpleAtom> processSelection(const std::string& selection, const loos::AtomicGroup& system, const bool use_periodicity = false);
124
125 friend std::ostream& operator<<(std::ostream& os, const SimpleAtom& s) {
126 os << "<SimpleAtom>\n";
127 os << *(s.atom) << std::endl;
128 os << "<isHydrogen " << s.isHydrogen << "/>\n";
129 os << "<usePeriodicity " << s.usePeriodicity << "/>\n";
130 if (s.usePeriodicity)
131 os << "<PeriodicBox>" << s.sbox.box() << "</PeriodicBox>\n";
132 if (s.attached_to != 0) {
133 os << "<attached>\n";
134 os << *(s.attached_to) << std::endl;
135 os << "</attached>\n";
136 }
137 os << "</SimpleAtom>";
138 return(os);
139 }
140
141
142 private:
143
144
145 bool divineHydrogen(const std::string& name);
146
147
148 loos::pAtom atom;
149 bool isHydrogen;
150 bool usePeriodicity;
151
152 static double inner, outer, deviation;
153 static bool debugging;
154
156 loos::pAtom attached_to;
157
158 };
159
160
161
162 // Typedefs to make life easier in the tools...
163
164 typedef SimpleAtom SAtom;
165 typedef std::vector<SAtom> SAGroup;
166
167 }
168}
169#endif
Class for handling groups of Atoms (pAtoms, actually)
Definition AtomicGroup.hpp:108
Definition hcore.hpp:70
Simple matrix template class using policy classes to determine behavior.
Definition MatrixImpl.hpp:148
This class manages a shared Periodicbox.
Definition PeriodicBox.hpp:81
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3
Definition hcore.hpp:45