RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Geometry/Utils.h
Go to the documentation of this file.
1//
2// Copyright (C) 2004-2006 Rational Discovery LLC
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10#include <RDGeneral/export.h>
11#ifndef __RD_DIST_UTILS_H__
12#define __RD_DIST_UTILS_H__
13
14#include <cmath>
15#include "point.h"
16#include "Transform3D.h"
17#include "Transform.h"
18
19namespace RDGeom {
20
21/*! \brief Compute the 13 distance between points give the 12 distances
22 * and the angle between the axes.
23 */
24inline double compute13Dist(double d1, double d2, double angle) {
25 double res = d1 * d1 + d2 * d2 - 2 * d1 * d2 * cos(angle);
26 return sqrt(res);
27}
28
29/*! \brief Compute the 14 distances give the 12 distance and the angles
30 *
31 * This is computed by aligning the d2 axis with the x-axis (with atom 2 at
32 * the origin. Atom 1 is made to lie int he xy-plane with a +ve y-coordinate
33 * and finally the coordinates for atom 4 are computed.
34 *
35 * ARGUMENTS:
36 * d1 - distance between atoms 1 and 2
37 * d2 - distance between atoms 2 and 3
38 * d3 - distance between atoms 3 and 4
39 * ang12 - angle between the axes d1 and d2
40 * ang23 - angle between the axes d2 and d3
41 * torAng - torsional agnle of the axis d2
42 *
43 * NOTE:
44 * we are specifically calling this function compute14Dist3D because
45 * we assume the torsional angle can take any value including 0 and 180 deg.
46 * However, if using either 0 or 180 as the torsional angle (which is often
47 * the case) the user is recommended to use the specialized functions below
48 * instead of this function; they will be speedier.
49 */
50inline double compute14Dist3D(double d1, double d2, double d3, double ang12,
51 double ang23, double torAng) {
52 // location of atom1
53 Point3D p1(d1 * cos(ang12), d1 * sin(ang12), 0.0);
54
55 // location of atom 4 if the rosion angle was 0
56 Point3D p4(d2 - d3 * cos(ang23), d3 * sin(ang23), 0.0);
57
58 // now we will rotate p4 about the x-axis by the desired torsion angle
59 Transform3D trans;
60 trans.SetRotation(torAng, X_Axis);
61 trans.TransformPoint(p4);
62
63 // find the distance
64 p4 -= p1;
65 return p4.length();
66}
67
68/*! \brief Compute the 14 distances give the 12 distance and bond angle
69 * for cis configuration
70 *
71 * This is simply a special case of the above function compute14Dist3D;
72 * with torsion angle set to 0. However, this function should be speedier
73 */
74inline double compute14DistCis(double d1, double d2, double d3, double ang12,
75 double ang23) {
76 double dx = d2 - d3 * cos(ang23) - d1 * cos(ang12);
77 double dy = d3 * sin(ang23) - d1 * sin(ang12);
78 double res = dx * dx + dy * dy;
79 return sqrt(res);
80}
81
82/*! \brief Compute the 14 distances give the 12 distance and bond angle
83 * for trans configuration
84 *
85 * This is simply a special case of the above function compute14Dist3D;
86 * with torsion angle set to 180. However, this function should be speedier
87 */
88inline double compute14DistTrans(double d1, double d2, double d3, double ang12,
89 double ang23) {
90 double dx = d2 - d3 * cos(ang23) - d1 * cos(ang12);
91 double dy = d3 * sin(ang23) + d1 * sin(ang12);
92 double res = dx * dx + dy * dy;
93 return sqrt(res);
94}
95} // namespace RDGeom
96
97#endif
double length() const override
Definition point.h:153
void SetRotation(double angle, AxisType axis)
set the rotation matrix
void TransformPoint(Point3D &pt) const
double compute14DistTrans(double d1, double d2, double d3, double ang12, double ang23)
Compute the 14 distances give the 12 distance and bond angle for trans configuration.
@ X_Axis
Definition Transform.h:16
double compute14DistCis(double d1, double d2, double d3, double ang12, double ang23)
Compute the 14 distances give the 12 distance and bond angle for cis configuration.
double compute13Dist(double d1, double d2, double angle)
Compute the 13 distance between points give the 12 distances and the angle between the axes.
double compute14Dist3D(double d1, double d2, double d3, double ang12, double ang23, double torAng)
Compute the 14 distances give the 12 distance and the angles.