Tinker9 70bd052 (Thu Nov 9 12:11:35 2023 -0800)
Loading...
Searching...
No Matches
pitors.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
16
17 real ptorunit, int i, const int (*restrict ipit)[6],
18 const real* restrict kpit,
19
20 const real* restrict x, const real* restrict y, const real* restrict z)
21{
22 constexpr bool do_e = Ver::e;
23 constexpr bool do_g = Ver::g;
24 constexpr bool do_v = Ver::v;
25 if CONSTEXPR (do_e) e = 0;
26 if CONSTEXPR (do_v) vxx = 0, vyx = 0, vzx = 0, vyy = 0, vzy = 0, vzz = 0;
27
28 const int ia = ipit[i][0];
29 const int ib = ipit[i][1];
30 const int ic = ipit[i][2];
31 const int id = ipit[i][3];
32 const int ie = ipit[i][4];
33 const int ig = ipit[i][5];
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 xie = x[ie];
48 real yie = y[ie];
49 real zie = z[ie];
50 real xig = x[ig];
51 real yig = y[ig];
52 real zig = z[ig];
53 real xad = xia - xid;
54 real yad = yia - yid;
55 real zad = zia - zid;
56 real xbd = xib - xid;
57 real ybd = yib - yid;
58 real zbd = zib - zid;
59 real xec = xie - xic;
60 real yec = yie - yic;
61 real zec = zie - zic;
62 real xgc = xig - xic;
63 real ygc = yig - yic;
64 real zgc = zig - zic;
65
66 real xip = yad * zbd - ybd * zad + xic;
67 real yip = zad * xbd - zbd * xad + yic;
68 real zip = xad * ybd - xbd * yad + zic;
69 real xiq = yec * zgc - ygc * zec + xid;
70 real yiq = zec * xgc - zgc * xec + yid;
71 real ziq = xec * ygc - xgc * yec + zid;
72 real xcp = xic - xip;
73 real ycp = yic - yip;
74 real zcp = zic - zip;
75 real xdc = xid - xic;
76 real ydc = yid - yic;
77 real zdc = zid - zic;
78 real xqd = xiq - xid;
79 real yqd = yiq - yid;
80 real zqd = ziq - zid;
81
82 real xt = ycp * zdc - ydc * zcp;
83 real yt = zcp * xdc - zdc * xcp;
84 real zt = xcp * ydc - xdc * ycp;
85 real xu = ydc * zqd - yqd * zdc;
86 real yu = zdc * xqd - zqd * xdc;
87 real zu = xdc * yqd - xqd * ydc;
88 real xtu = yt * zu - yu * zt;
89 real ytu = zt * xu - zu * xt;
90 real ztu = xt * yu - xu * yt;
91 real rt2 = xt * xt + yt * yt + zt * zt;
92 real ru2 = xu * xu + yu * yu + zu * zu;
93 real rtru = REAL_SQRT(rt2 * ru2);
94
95 if (rtru != 0) {
96 real rdc = REAL_SQRT(xdc * xdc + ydc * ydc + zdc * zdc);
97 real cosine = (xt * xu + yt * yu + zt * zu) * REAL_RECIP(rtru);
98 real sine = (xdc * xtu + ydc * ytu + zdc * ztu) * REAL_RECIP(rdc * rtru);
99
100 // set the pi-system torsion parameters for this angle
101
102 real v2 = kpit[i];
103 real c2 = -1;
104 real s2 = 0;
105
106 // compute the multiple angle trigonometry and the phase terms
107
108 real cosine2 = cosine * cosine - sine * sine;
109 real sine2 = 2 * cosine * sine;
110 real phi2 = 1 + (cosine2 * c2 + sine2 * s2);
111
112 // calculate the pi-system torsion energy for this angle
113
114 if CONSTEXPR (do_e) e = ptorunit * v2 * phi2;
115
116 if CONSTEXPR (do_g) {
117 real dphi2 = 2 * (cosine2 * s2 - sine2 * c2);
118 real dedphi = ptorunit * v2 * dphi2;
119
120 // chain rule terms for first derivative components
121
122 real xdp = xid - xip;
123 real ydp = yid - yip;
124 real zdp = zid - zip;
125 real xqc = xiq - xic;
126 real yqc = yiq - yic;
127 real zqc = ziq - zic;
128 real rt2rdc_inv = REAL_RECIP(rt2 * rdc);
129 real ru2rdc_inv = REAL_RECIP(ru2 * rdc);
130 real dedxt = dedphi * (yt * zdc - ydc * zt) * rt2rdc_inv;
131 real dedyt = dedphi * (zt * xdc - zdc * xt) * rt2rdc_inv;
132 real dedzt = dedphi * (xt * ydc - xdc * yt) * rt2rdc_inv;
133 real dedxu = -dedphi * (yu * zdc - ydc * zu) * ru2rdc_inv;
134 real dedyu = -dedphi * (zu * xdc - zdc * xu) * ru2rdc_inv;
135 real dedzu = -dedphi * (xu * ydc - xdc * yu) * ru2rdc_inv;
136
137 // compute first derivative components for pi-system angle
138
139 real dedxip = zdc * dedyt - ydc * dedzt;
140 real dedyip = xdc * dedzt - zdc * dedxt;
141 real dedzip = ydc * dedxt - xdc * dedyt;
142 real dedxic = ydp * dedzt - zdp * dedyt + zqd * dedyu - yqd * dedzu;
143 real dedyic = zdp * dedxt - xdp * dedzt + xqd * dedzu - zqd * dedxu;
144 real dedzic = xdp * dedyt - ydp * dedxt + yqd * dedxu - xqd * dedyu;
145 real dedxid = zcp * dedyt - ycp * dedzt + yqc * dedzu - zqc * dedyu;
146 real dedyid = xcp * dedzt - zcp * dedxt + zqc * dedxu - xqc * dedzu;
147 real dedzid = ycp * dedxt - xcp * dedyt + xqc * dedyu - yqc * dedxu;
148 real dedxiq = zdc * dedyu - ydc * dedzu;
149 real dedyiq = xdc * dedzu - zdc * dedxu;
150 real dedziq = ydc * dedxu - xdc * dedyu;
151
152 // compute first derivative components for individual atoms
153
154 real dedxia = ybd * dedzip - zbd * dedyip;
155 real dedyia = zbd * dedxip - xbd * dedzip;
156 real dedzia = xbd * dedyip - ybd * dedxip;
157 real dedxib = zad * dedyip - yad * dedzip;
158 real dedyib = xad * dedzip - zad * dedxip;
159 real dedzib = yad * dedxip - xad * dedyip;
160 real dedxie = ygc * dedziq - zgc * dedyiq;
161 real dedyie = zgc * dedxiq - xgc * dedziq;
162 real dedzie = xgc * dedyiq - ygc * dedxiq;
163 real dedxig = zec * dedyiq - yec * dedziq;
164 real dedyig = xec * dedziq - zec * dedxiq;
165 real dedzig = yec * dedxiq - xec * dedyiq;
166
167 dedxic += (dedxip - dedxie - dedxig);
168 dedyic += (dedyip - dedyie - dedyig);
169 dedzic += (dedzip - dedzie - dedzig);
170 dedxid += (dedxiq - dedxia - dedxib);
171 dedyid += (dedyiq - dedyia - dedyib);
172 dedzid += (dedziq - dedzia - dedzib);
173
174 atomic_add(dedxia, deptx, ia);
175 atomic_add(dedyia, depty, ia);
176 atomic_add(dedzia, deptz, ia);
177 atomic_add(dedxib, deptx, ib);
178 atomic_add(dedyib, depty, ib);
179 atomic_add(dedzib, deptz, ib);
180 atomic_add(dedxic, deptx, ic);
181 atomic_add(dedyic, depty, ic);
182 atomic_add(dedzic, deptz, ic);
183 atomic_add(dedxid, deptx, id);
184 atomic_add(dedyid, depty, id);
185 atomic_add(dedzid, deptz, id);
186 atomic_add(dedxie, deptx, ie);
187 atomic_add(dedyie, depty, ie);
188 atomic_add(dedzie, deptz, ie);
189 atomic_add(dedxig, deptx, ig);
190 atomic_add(dedyig, depty, ig);
191 atomic_add(dedzig, deptz, ig);
192
193 if CONSTEXPR (do_v) {
194 real vxterm = dedxid + dedxia + dedxib;
195 real vyterm = dedyid + dedyia + dedyib;
196 real vzterm = dedzid + dedzia + dedzib;
197 vxx = xdc * vxterm + xcp * dedxip - xqd * dedxiq;
198 vyx = ydc * vxterm + ycp * dedxip - yqd * dedxiq;
199 vzx = zdc * vxterm + zcp * dedxip - zqd * dedxiq;
200 vyy = ydc * vyterm + ycp * dedyip - yqd * dedyiq;
201 vzy = zdc * vyterm + zcp * dedyip - zqd * dedyiq;
202 vzz = zdc * vzterm + zcp * dedzip - zqd * dedziq;
203 }
204 }
205 }
206}
207}
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 * kpit
grad_prec * depty
real ptorunit
int(* ipit)[6]
grad_prec * deptx
grad_prec * deptz
Definition: testrt.h:9
__device__ void dk_pitors(real &__restrict__ e, real &__restrict__ vxx, real &__restrict__ vyx, real &__restrict__ vzx, real &__restrict__ vyy, real &__restrict__ vzy, real &__restrict__ vzz, grad_prec *__restrict__ deptx, grad_prec *__restrict__ depty, grad_prec *__restrict__ deptz, real ptorunit, int i, const int(*__restrict__ ipit)[6], const real *__restrict__ kpit, const real *__restrict__ x, const real *__restrict__ y, const real *__restrict__ z)
Definition: pitors.h:10