LOOS  v2.3.2
Geometry.cpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2008, 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 
23 
24 #include <Geometry.hpp>
25 #include <Atom.hpp>
26 
27 
28 namespace loos {
29 
30  //const double DEGREES = 180 / M_PI ;
31 
36  greal Math::angle(const GCoord &a, const GCoord &b, const GCoord &c,
37  const GCoord *box) {
38  GCoord ba = b - a;
39  GCoord bc = b - c;
40  if (box != NULL) {
41  ba.reimage(*box);
42  bc.reimage(*box);
43  }
44  greal cosine = (ba * bc) / (ba.length() * bc.length());
45  return (acos(cosine) * DEGREES);
46  }
47 
52  greal Math::angle(const pAtom& a, const pAtom& b, const pAtom& c,
53  const GCoord *box) {
54  return(angle(a->coords(), b->coords(), c->coords(), box));
55  }
56 
61  greal Math::torsion(const GCoord &a, const GCoord &b, const GCoord &c,
62  const GCoord &d, const GCoord *box) {
63  GCoord b1 = b - a;
64  GCoord b2 = c - b;
65  GCoord b3 = d - c;
66  if (box != NULL) {
67  b1.reimage(*box);
68  b2.reimage(*box);
69  b3.reimage(*box);
70  }
71 
72  greal phi = atan2( (b2.length() * b1) * (b2.cross(b3)),
73  (b1.cross(b2)) * (b2.cross(b3)) );
74  return(phi * DEGREES);
75  }
76 
81  greal Math::torsion(const pAtom& a, const pAtom& b, const pAtom& c,
82  const pAtom& d, const GCoord *box) {
83  return(torsion(a->coords(), b->coords(), c->coords(), d->coords()));
84  }
85 
86 }
double length(void) const
Length of the coordinate (as a vector)
Definition: Coord.hpp:423
greal angle(const GCoord &, const GCoord &, const GCoord &, const GCoord *=NULL)
Compute the angle in degrees assuming the middle is the vertex.
Definition: Geometry.cpp:36
greal torsion(const GCoord &a, const GCoord &b, const GCoord &c, const GCoord &d, const GCoord *=NULL)
Compute the torsion in degrees.
Definition: Geometry.cpp:61
Namespace for most things not already encapsulated within a class.
Coord< T > cross(const Coord< T > &rhs) const
Cross-product. Returns a new Coord
Definition: Coord.hpp:360
void reimage(const Coord< T > &box)
Handle coordinates with periodic boundary conditions.
Definition: Coord.hpp:404