LOOS  v2.3.2
HBondDetector.cpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2008, Tod D. Romo, Alan Grossfield
6  Department of Biochemistry and Biophysics
7  School of Medicine & Dentistry, University of Rochester
8 
9  This package (LOOS) is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation under version 3 of the License.
12 
13  This package is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include <HBondDetector.hpp>
23 
24 namespace loos {
25  HBondDetector::HBondDetector(const double distance, const double angle,
26  const AtomicGroup &group) {
27 
28  cutoff_cos = cos((angle)*M_PI/180.0);
29  cutoff_dist2 = distance * distance;
30  box = group.sharedPeriodicBox();
31  }
32 
33  HBondDetector::HBondDetector(const AtomicGroup &group) {
34  cutoff_cos = cos((20.)*M_PI/180.);
35  cutoff_dist2 = 3.5 * 3.5;
36  box = group.sharedPeriodicBox();
37  }
38 
39 
40  HBondDetector::HBondDetector() {
41  cutoff_cos = cos((20.)*M_PI/180.);
42  cutoff_dist2 = 3.5 * 3.5;
43  box = SharedPeriodicBox();
44  }
45 
46 
47  bool HBondDetector::hBonded(const pAtom donor, const pAtom hydrogen,
48  const pAtom acceptor) {
49  // Check distance between hydrogen and acceptor
50  double d2;
51  if (box.isPeriodic()) {
52  d2 = hydrogen->coords().distance2(acceptor->coords(), box.box());
53  }
54  else {
55  d2 = hydrogen->coords().distance2(acceptor->coords());
56  }
57 
58  if (d2 > cutoff_dist2) {
59  return false;
60  }
61 
62 
63  // If the distance test passes, try the angle test
64  // We assume the donor and hydrogen are in the same periodic image
65  // Return true if the angle is greater than the threshold (meaning
66  // the cosine is less than the threshold)
67  GCoord d_to_h = hydrogen->coords() - donor->coords();
68  GCoord h_to_a = acceptor->coords() - hydrogen->coords();
69  if (box.isPeriodic()) {
70  h_to_a.reimage(box.box());
71  }
72 
73  double cosine = (d_to_h * h_to_a)/(d_to_h.length() * sqrt(d2));
74  return (cosine > cutoff_cos);
75  }
76 
77 }
double length(void) const
Length of the coordinate (as a vector)
Definition: Coord.hpp:423
bool hBonded(const pAtom donor, const pAtom hydrogen, const pAtom acceptor)
Method to test if this triple of atoms forms an h-bond.
Namespace for most things not already encapsulated within a class.
void reimage(const Coord< T > &box)
Handle coordinates with periodic boundary conditions.
Definition: Coord.hpp:404