Tinker9 70bd052 (Thu Nov 9 12:11:35 2023 -0800)
Loading...
Searching...
No Matches
torsion.h
1#pragma once
2#include "math/libfunc.h"
3#include "seq/add.h"
4#include "seq/seq.h"
5
6namespace tinker {
7#pragma acc routine seq
8template <class Ver>
11 real& restrict vzx, real& restrict vyy, real& restrict vzy,
12 real& restrict vzz,
13
15
16 real torsunit, int i, const int (*restrict itors)[4],
17
18 const real (*restrict tors1)[4], const real (*restrict tors2)[4],
19 const real (*restrict tors3)[4], const real (*restrict tors4)[4],
20 const real (*restrict tors5)[4], const real (*restrict tors6)[4],
21
22 const real* restrict x, const real* restrict y, const real* restrict z)
23{
24 constexpr bool do_e = Ver::e;
25 constexpr bool do_g = Ver::g;
26 constexpr bool do_v = Ver::v;
27 if CONSTEXPR (do_e) e = 0;
28 if CONSTEXPR (do_v) vxx = 0, vyx = 0, vzx = 0, vyy = 0, vzy = 0, vzz = 0;
29
30 const int ia = itors[i][0];
31 const int ib = itors[i][1];
32 const int ic = itors[i][2];
33 const int id = itors[i][3];
34
35 real xia = x[ia];
36 real yia = y[ia];
37 real zia = z[ia];
38 real xib = x[ib];
39 real yib = y[ib];
40 real zib = z[ib];
41 real xic = x[ic];
42 real yic = y[ic];
43 real zic = z[ic];
44 real xid = x[id];
45 real yid = y[id];
46 real zid = z[id];
47 real xba = xib - xia;
48 real yba = yib - yia;
49 real zba = zib - zia;
50 real xcb = xic - xib;
51 real ycb = yic - yib;
52 real zcb = zic - zib;
53 real xdc = xid - xic;
54 real ydc = yid - yic;
55 real zdc = zid - zic;
56
57 real xt = yba * zcb - ycb * zba;
58 real yt = zba * xcb - zcb * xba;
59 real zt = xba * ycb - xcb * yba;
60 real xu = ycb * zdc - ydc * zcb;
61 real yu = zcb * xdc - zdc * xcb;
62 real zu = xcb * ydc - xdc * ycb;
63 real xtu = yt * zu - yu * zt;
64 real ytu = zt * xu - zu * xt;
65 real ztu = xt * yu - xu * yt;
66 real rt2 = xt * xt + yt * yt + zt * zt;
67 real ru2 = xu * xu + yu * yu + zu * zu;
68 real rtru = REAL_SQRT(rt2 * ru2);
69
70 if (rtru != 0) {
71 real rcb = REAL_SQRT(xcb * xcb + ycb * ycb + zcb * zcb);
72 real cosine = (xt * xu + yt * yu + zt * zu) * REAL_RECIP(rtru);
73 real sine = (xcb * xtu + ycb * ytu + zcb * ztu) * REAL_RECIP(rcb * rtru);
74
75 // set the torsional parameters for this angle
76
77 real v1 = tors1[i][0];
78 real c1 = tors1[i][2];
79 real s1 = tors1[i][3];
80 real v2 = tors2[i][0];
81 real c2 = tors2[i][2];
82 real s2 = tors2[i][3];
83 real v3 = tors3[i][0];
84 real c3 = tors3[i][2];
85 real s3 = tors3[i][3];
86 real v4 = tors4[i][0];
87 real c4 = tors4[i][2];
88 real s4 = tors4[i][3];
89 real v5 = tors5[i][0];
90 real c5 = tors5[i][2];
91 real s5 = tors5[i][3];
92 real v6 = tors6[i][0];
93 real c6 = tors6[i][2];
94 real s6 = tors6[i][3];
95
96 // compute the multiple angle trigonometry and the phase terms
97
98 real cosine2 = cosine * cosine - sine * sine;
99 real sine2 = 2 * cosine * sine;
100 real cosine3 = cosine * cosine2 - sine * sine2;
101 real sine3 = cosine * sine2 + sine * cosine2;
102 real cosine4 = cosine * cosine3 - sine * sine3;
103 real sine4 = cosine * sine3 + sine * cosine3;
104 real cosine5 = cosine * cosine4 - sine * sine4;
105 real sine5 = cosine * sine4 + sine * cosine4;
106 real cosine6 = cosine * cosine5 - sine * sine5;
107 real sine6 = cosine * sine5 + sine * cosine5;
108
109 real phi1 = 1 + (cosine * c1 + sine * s1);
110 real phi2 = 1 + (cosine2 * c2 + sine2 * s2);
111 real phi3 = 1 + (cosine3 * c3 + sine3 * s3);
112 real phi4 = 1 + (cosine4 * c4 + sine4 * s4);
113 real phi5 = 1 + (cosine5 * c5 + sine5 * s5);
114 real phi6 = 1 + (cosine6 * c6 + sine6 * s6);
115 real dphi1 = (cosine * s1 - sine * c1);
116 real dphi2 = 2 * (cosine2 * s2 - sine2 * c2);
117 real dphi3 = 3 * (cosine3 * s3 - sine3 * c3);
118 real dphi4 = 4 * (cosine4 * s4 - sine4 * c4);
119 real dphi5 = 5 * (cosine5 * s5 - sine5 * c5);
120 real dphi6 = 6 * (cosine6 * s6 - sine6 * c6);
121
122 if CONSTEXPR (do_e)
123 e = torsunit
124 * (v1 * phi1 + v2 * phi2 + v3 * phi3 + v4 * phi4 + v5 * phi5
125 + v6 * phi6);
126
127 if CONSTEXPR (do_g) {
128 real dedphi = torsunit
129 * (v1 * dphi1 + v2 * dphi2 + v3 * dphi3 + v4 * dphi4 + v5 * dphi5
130 + v6 * dphi6);
131
132 // chain rule terms for first derivative components
133
134 real xca = xic - xia;
135 real yca = yic - yia;
136 real zca = zic - zia;
137 real xdb = xid - xib;
138 real ydb = yid - yib;
139 real zdb = zid - zib;
140
141 real rt_inv = REAL_RECIP(rt2 * rcb);
142 real ru_inv = REAL_RECIP(ru2 * rcb);
143 real dedxt = dedphi * (yt * zcb - ycb * zt) * rt_inv;
144 real dedyt = dedphi * (zt * xcb - zcb * xt) * rt_inv;
145 real dedzt = dedphi * (xt * ycb - xcb * yt) * rt_inv;
146 real dedxu = -dedphi * (yu * zcb - ycb * zu) * ru_inv;
147 real dedyu = -dedphi * (zu * xcb - zcb * xu) * ru_inv;
148 real dedzu = -dedphi * (xu * ycb - xcb * yu) * ru_inv;
149
150 // compute first derivative components for this angle
151
152 real dedxia = zcb * dedyt - ycb * dedzt;
153 real dedyia = xcb * dedzt - zcb * dedxt;
154 real dedzia = ycb * dedxt - xcb * dedyt;
155 real dedxib = yca * dedzt - zca * dedyt + zdc * dedyu - ydc * dedzu;
156 real dedyib = zca * dedxt - xca * dedzt + xdc * dedzu - zdc * dedxu;
157 real dedzib = xca * dedyt - yca * dedxt + ydc * dedxu - xdc * dedyu;
158 real dedxic = zba * dedyt - yba * dedzt + ydb * dedzu - zdb * dedyu;
159 real dedyic = xba * dedzt - zba * dedxt + zdb * dedxu - xdb * dedzu;
160 real dedzic = yba * dedxt - xba * dedyt + xdb * dedyu - ydb * dedxu;
161 real dedxid = zcb * dedyu - ycb * dedzu;
162 real dedyid = xcb * dedzu - zcb * dedxu;
163 real dedzid = ycb * dedxu - xcb * dedyu;
164
165 atomic_add(dedxia, detx, ia);
166 atomic_add(dedyia, dety, ia);
167 atomic_add(dedzia, detz, ia);
168 atomic_add(dedxib, detx, ib);
169 atomic_add(dedyib, dety, ib);
170 atomic_add(dedzib, detz, ib);
171 atomic_add(dedxic, detx, ic);
172 atomic_add(dedyic, dety, ic);
173 atomic_add(dedzic, detz, ic);
174 atomic_add(dedxid, detx, id);
175 atomic_add(dedyid, dety, id);
176 atomic_add(dedzid, detz, id);
177
178 if CONSTEXPR (do_v) {
179 vxx = xcb * (dedxic + dedxid) - xba * dedxia + xdc * dedxid;
180 vyx = ycb * (dedxic + dedxid) - yba * dedxia + ydc * dedxid;
181 vzx = zcb * (dedxic + dedxid) - zba * dedxia + zdc * dedxid;
182 vyy = ycb * (dedyic + dedyid) - yba * dedyia + ydc * dedyid;
183 vzy = zcb * (dedyic + dedyid) - zba * dedyia + zdc * dedyid;
184 vzz = zcb * (dedzic + dedzid) - zba * dedzia + zdc * dedzid;
185 }
186 }
187 }
188}
189}
void atomic_add(T value, T *buffer, size_t offset=0)
Definition: acc/adddef.h:14
#define SEQ_CUDA
Definition: acc/seqdef.h:12
#define restrict
Definition: macro.h:51
#define CONSTEXPR
Definition: macro.h:61
real * z
Current coordinates used in energy evaluation and neighbor lists.
real * x
Number of the trajectory frames.
real * y
Current coordinates used in energy evaluation and neighbor lists.
float real
Definition: precision.h:80
fixed grad_prec
Definition: precision.h:103
real(* tors4)[4]
grad_prec * detx
grad_prec * detz
real(* tors5)[4]
int(* itors)[4]
real(* tors2)[4]
real(* tors1)[4]
grad_prec * dety
real(* tors3)[4]
real torsunit
real(* tors6)[4]
Definition: testrt.h:9
__device__ void dk_tors(real &__restrict__ e, real &__restrict__ vxx, real &__restrict__ vyx, real &__restrict__ vzx, real &__restrict__ vyy, real &__restrict__ vzy, real &__restrict__ vzz, grad_prec *__restrict__ detx, grad_prec *__restrict__ dety, grad_prec *__restrict__ detz, real torsunit, int i, const int(*__restrict__ itors)[4], const real(*__restrict__ tors1)[4], const real(*__restrict__ tors2)[4], const real(*__restrict__ tors3)[4], const real(*__restrict__ tors4)[4], const real(*__restrict__ tors5)[4], const real(*__restrict__ tors6)[4], const real *__restrict__ x, const real *__restrict__ y, const real *__restrict__ z)
Definition: torsion.h:10