File: point.cpp

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (156 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// $Id$
//
// Copyright (C) 2003-2006 Rational Discovery LLC
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include "point.h"
//#include <Numerics/Vector.h>

namespace RDGeom {
double computeSignedDihedralAngle(const Point3D& pt1, const Point3D& pt2,
                                  const Point3D& pt3, const Point3D& pt4) {
  Point3D begEndVec = pt3 - pt2;
  Point3D begNbrVec = pt1 - pt2;
  Point3D crs1 = begNbrVec.crossProduct(begEndVec);

  Point3D endNbrVec = pt4 - pt3;
  Point3D crs2 = endNbrVec.crossProduct(begEndVec);

  double ang = crs1.angleTo(crs2);

  // now calculate the sign:
  Point3D crs3 = crs1.crossProduct(crs2);
  double dot = crs3.dotProduct(begEndVec);
  if (dot < 0.0) ang *= -1;

  return ang;
}
double computeDihedralAngle(const Point3D& pt1, const Point3D& pt2,
                            const Point3D& pt3, const Point3D& pt4) {
  Point3D begEndVec = pt3 - pt2;
  Point3D begNbrVec = pt1 - pt2;
  Point3D crs1 = begNbrVec.crossProduct(begEndVec);

  Point3D endNbrVec = pt4 - pt3;
  Point3D crs2 = endNbrVec.crossProduct(begEndVec);

  double ang = crs1.angleTo(crs2);
  return ang;
}

std::ostream& operator<<(std::ostream& target, const Point& pt) {
  for (unsigned int di = 0; di < pt.dimension(); ++di) {
    target << pt[di] << " ";
  }

  return target;
}

Point3D operator+(const Point3D& p1, const Point3D& p2) {
  Point3D res;
  res.x = p1.x + p2.x;
  res.y = p1.y + p2.y;
  res.z = p1.z + p2.z;
  return res;
}

Point3D operator-(const Point3D& p1, const Point3D& p2) {
  Point3D res;
  res.x = p1.x - p2.x;
  res.y = p1.y - p2.y;
  res.z = p1.z - p2.z;
  return res;
}

Point3D operator*(const Point3D& p1, double v) {
  Point3D res;
  res.x = p1.x * v;
  res.y = p1.y * v;
  res.z = p1.z * v;
  return res;
}

Point3D operator/(const Point3D& p1, double v) {
  Point3D res;
  res.x = p1.x / v;
  res.y = p1.y / v;
  res.z = p1.z / v;
  return res;
}

Point2D operator+(const Point2D& p1, const Point2D& p2) {
  Point2D res;
  res.x = p1.x + p2.x;
  res.y = p1.y + p2.y;
  return res;
}

Point2D operator-(const Point2D& p1, const Point2D& p2) {
  Point2D res;
  res.x = p1.x - p2.x;
  res.y = p1.y - p2.y;
  return res;
}

Point2D operator*(const Point2D& p1, double v) {
  Point2D res;
  res.x = p1.x * v;
  res.y = p1.y * v;
  return res;
}

Point2D operator/(const Point2D& p1, double v) {
  Point2D res;
  res.x = p1.x / v;
  res.y = p1.y / v;
  return res;
}

PointND operator+(const PointND& p1, const PointND& p2) {
  unsigned int dim;
  if (p1.dimension() < p2.dimension()) {
    dim = p1.dimension();
  } else {
    dim = p1.dimension();
  }
  PointND res(dim);
  for (unsigned int i = 0; i < dim; ++i) {
    res[i] = p1[i] + p2[i];
  }
  return res;
}
PointND operator-(const PointND& p1, const PointND& p2) {
  unsigned int dim;
  if (p1.dimension() < p2.dimension()) {
    dim = p1.dimension();
  } else {
    dim = p1.dimension();
  }
  PointND res(dim);
  for (unsigned int i = 0; i < dim; ++i) {
    res[i] = p1[i] - p2[i];
  }
  return res;
}

PointND operator*(const PointND& p1, double v) {
  PointND res(p1.dimension());
  for (unsigned int i = 0; i < p1.dimension(); ++i) {
    res[i] = p1[i] * v;
  }
  return res;
}

PointND operator/(const PointND& p1, double v) {
  PointND res(p1.dimension());
  for (unsigned int i = 0; i < p1.dimension(); ++i) {
    res[i] = p1[i] / v;
  }
  return res;
}
}