Psi4
v3d.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
33 #ifndef _opt_v3d_h_
34 #define _opt_v3d_h_
35 
36 #include "package.h"
37 
38 #if defined(OPTKING_PACKAGE_PSI)
39  #include <cmath>
40 #elif defined (OPTKING_PACKAGE_QCHEM)
41  #include "qcmath.h"
42 #endif
43 
44 #define V3D_SQR(x) ((x)*(x))
45 
46 #define PARALLEL_LIMIT (1.0e-10)
47 
48 namespace opt { namespace v3d {
49 
50 // scalar multiply a vector
51 inline void v3d_scm(const double a, double *A) {
52  A[0] *= a; A[1] *= a; A[2] *= a;
53 }
54 
55 // compute norm of a vector
56 inline double v3d_norm(const double *A) {
57  return sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
58 }
59 
60 // take dot product of two vectors
61 inline double v3d_dot(const double *A, const double *B) {
62  return (A[0]*B[0] + A[1]*B[1] + A[2]*B[2]);
63 }
64 
65 // returns distance between 2 points
66 inline double v3d_dist(const double *A, const double *B) {
67  return sqrt(V3D_SQR(B[0]-A[0]) + V3D_SQR(B[1]-A[1]) + V3D_SQR(B[2]-A[2]));
68 }
69 
70 // Compute a*X + Y -> Z
71 inline void v3d_axpy(const double a, const double *X, const double *Y, double *Z) {
72  Z[0] = a*X[0] + Y[0];
73  Z[1] = a*X[1] + Y[1];
74  Z[2] = a*X[2] + Y[2];
75 }
76 
77 // normalize vector. Return "false and leave A unchanged if norm of A is
78 // less than min_norm or greater than max_norm
79 inline bool v3d_normalize(double *A, const double min_norm=1.0e-8, const double max_norm=1.0e8) {
80  double tval = v3d_norm(A);
81  if ( tval < min_norm || tval > max_norm)
82  return false;
83  else
84  v3d_scm(1.0/tval, A);
85  return true;
86 }
87 
88 // Compute cross product of two vectors
89 inline void v3d_cross_product(const double *u, const double *v, double *X) {
90  X[0] = u[1]*v[2]-u[2]*v[1];
91  X[1] = -1.0*(u[0]*v[2]-u[2]*v[0]);
92  X[2] = u[0]*v[1]-u[1]*v[0];
93  return;
94 }
95 
96 // check to see if two vectors are parallel, i.e., is |A.B| close to 1
97 inline bool v3d_is_parallel(const double *A, const double *B) {
98  if ( fabs( fabs(v3d_dot(A,B)) - 1.0e0) > PARALLEL_LIMIT )
99  return false;
100  else
101  return true;
102 }
103 
104 // Compute vector A->B. Normalize eAB. Return "false" and do not normalize
105 // eAB if points are too close or distant
106 inline bool v3d_eAB(const double *A, const double *B, double *eAB,
107 const double min_norm=1.0e-8, const double max_norm=1.0e15) {
108  v3d_axpy(-1, A, B, eAB);
109  return ( v3d_normalize(eAB, min_norm, max_norm) );
110 }
111 
112 // Computed angle in radians A-B-C (between vector B->A and vector B->C)
113 // if points are absurdly close or far apart, returns false
114 // tol is nearness of cos to 1/-1 to make angle 0/pi
115 bool v3d_angle(const double *A, const double *B, const double *C, double & phi, double tol=1e-14);
116 
117 // Computed torsional angle in radians A-B-C-D
118 // Returns false if bond angles ABC or BCD are too close to 0 or 180
119 bool v3d_tors(const double *A, const double *B, const double *C, const double *D, double & tau);
120 
121 // Computed out-of-plane angle in radians A-B-C-D for angle between A-B and C-B-D planes.
122 // Returns false if bond angles BCD is too close to 0 or 180
123 bool v3d_oofp(const double *A, const double *B, const double *C, const double *D,
124  double & oop_angle);
125 
126 }}
127 
128 #endif
void v3d_cross_product(const double *u, const double *v, double *X)
Definition: v3d.h:89
bool v3d_is_parallel(const double *A, const double *B)
Definition: v3d.h:97
double ** u
Definition: densgrid_RHF.cc:65
bool v3d_normalize(double *A, const double min_norm=1.0e-8, const double max_norm=1.0e8)
Definition: v3d.h:79
#define PARALLEL_LIMIT
Definition: v3d.h:46
bool v3d_eAB(const double *A, const double *B, double *eAB, const double min_norm=1.0e-8, const double max_norm=1.0e15)
Definition: v3d.h:106
#define V3D_SQR(x)
Definition: v3d.h:44
double v3d_dist(const double *A, const double *B)
Definition: v3d.h:66
double v3d_dot(const double *A, const double *B)
Definition: v3d.h:61
double v3d_norm(const double *A)
Definition: v3d.h:56
bool v3d_tors(const double *A, const double *B, const double *C, const double *D, double &tau)
Definition: v3d.cc:78
bool v3d_angle(const double *A, const double *B, const double *C, double &phi, double tol)
Definition: v3d.cc:44
void v3d_axpy(const double a, const double *X, const double *Y, double *Z)
Definition: v3d.h:71
bool v3d_oofp(const double *A, const double *B, const double *C, const double *D, double &oop_angle)
Definition: v3d.cc:126
void v3d_scm(const double a, double *A)
Definition: v3d.h:51
Definition: PsiFileImpl.h:38