RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Plane.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// Simple class for representing 3-D planes in normal form
14
15#ifndef _RBTPLANE_H_
16#define _RBTPLANE_H_
17
18#include "rxdock/Coord.h"
19
20#include <nlohmann/json.hpp>
21
22using json = nlohmann::json;
23
24namespace rxdock {
25
26class Plane {
28 // Data members
30private:
31 Vector m_vnorm; // The vector normal to the plane (a,b,c)
32 double m_d; // Distance from plane to origin (in normal form)
33
34public:
36 // Constructors/destructors:
38
39 // Default constructor (initialise to zero)
40 inline Plane() : m_vnorm(0.0, 0.0, 0.0), m_d(0.0) {}
41
42 // Constructor with initial values
43 inline Plane(const Vector &v, double d) : m_vnorm(v), m_d(d) {
44 Normalise(); // Convert to normal form
45 }
46
47 // Constructor taking three coordinates which lie in the plane
48 inline Plane(const Coord &c0, const Coord &c1, const Coord &c2) {
49 // Determine the vectors from c0 to c1 and c0 to c2
50 Vector v1 = c1 - c0;
51 Vector v2 = c2 - c0;
52 m_vnorm = v1.Cross(v2); // Vector normal to the plane
53 m_d = -m_vnorm.Dot(c0);
54 Normalise(); // Convert to normal form
55 }
56
57 // Destructor
58 virtual ~Plane() {}
59
60 friend void to_json(json &j, const Plane &plane) {
61 j = json{{"vec-nor", plane.m_vnorm}, {"dis", plane.m_d}};
62 }
63
64 friend void from_json(const json &j, Plane &plane) {
65 j.at("vec-nor").get_to(plane.m_vnorm);
66 j.at("dis").get_to(plane.m_d);
67 }
68
70 // Operator functions:
72
74 // Friend functions:
76
77 // Insertion operator
78 friend std::ostream &operator<<(std::ostream &s, const Plane &plane) {
79 return s << plane.m_vnorm.xyz(0) << "x + " << plane.m_vnorm.xyz(1) << "y + "
80 << plane.m_vnorm.xyz(2) << "z + " << plane.m_d << " = 0";
81 }
82
84 // Public methods
86 inline double D() const { return m_d; }
87 inline Vector VNorm() const { return m_vnorm; }
88
90 // Private methods
92 inline void Normalise() {
93 // Convert to normal form by dividing by +/- vnorm.Length()
94 // where sign is opposite the sign of d when d<>0,
95 // same as sign of c (vnorm.xyz(2)) when d==0 and c<>0,
96 // and same as sign of b (vnorm.xyz(1)) otherwise
97 double l = m_vnorm.Length();
98 int iSign = (m_d < 0.0) ? 1
99 : (m_d > 0.0) ? -1
100 : (m_vnorm.xyz(2) < 0.0) ? -1
101 : (m_vnorm.xyz(2) > 0.0) ? 1
102 : (m_vnorm.xyz(1) < 0.0) ? -1
103 : 1;
104 l *= iSign;
105 // Check for divide by zero
106 if (l != 0.0) {
107 m_vnorm /= l;
108 m_d /= l;
109 }
110 }
111};
112
114// Non-member functions (in rxdock namespace)
116
117// Since our planes are always in normal form, we don't need to divide
118// by the magnitude of the normal vector
119// DM 31 Mar 1999 - returned signed distance (not absolute value)
120inline double DistanceFromPointToPlane(const Coord &c0, const Plane &p) {
121 // return std::fabs( c0.Dot(p.VNorm()) + p.D() );
122 return c0.Dot(p.VNorm()) + p.D();
123}
124
125// Angle between planes is just the angle between the normal vectors
126inline double AngleBetweenPlanes(const Plane &p0, const Plane &p1) {
127 return Angle(p0.VNorm(), p1.VNorm());
128}
129
130// Cos(Angle) between planes is just the dot product of the normal vectors
131inline double CosAngleBetweenPlanes(const Plane &p0, const Plane &p1) {
132 return Dot(p0.VNorm(), p1.VNorm());
133}
134
135} // namespace rxdock
136
137#endif //_RBTPLANE_H_
Definition Coord.h:45
Definition Plane.h:26