Tinker9 70bd052 (Thu Nov 9 12:11:35 2023 -0800)
Loading...
Searching...
No Matches
bond.h
1#pragma once
2#include "ff/evalence.h"
3#include "math/libfunc.h"
4#include "seq/add.h"
5#include "seq/seq.h"
6
7namespace tinker {
8#pragma acc routine seq
9template <class Ver>
12 real& restrict vzx, real& restrict vyy, real& restrict vzy,
13 real& restrict vzz,
14
16
17 Bond bndtyp, real bndunit, int i, const int (*restrict ibnd)[2],
18 const real* restrict bl, const real* restrict bk, real cbnd, real qbnd,
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
26 int ia = ibnd[i][0];
27 int ib = ibnd[i][1];
28 real ideal = bl[i];
29 real force = bk[i];
30
31 real xab = x[ia] - x[ib];
32 real yab = y[ia] - y[ib];
33 real zab = z[ia] - z[ib];
34
35 real rab = REAL_SQRT(xab * xab + yab * yab + zab * zab);
36 real dt = rab - ideal;
37
38 real deddt;
39 if (bndtyp == Bond::HARMONIC) {
40 real dt2 = dt * dt;
41 if CONSTEXPR (do_e)
42 e = bndunit * force * dt2 * (1 + cbnd * dt + qbnd * dt2);
43 if CONSTEXPR (do_g)
44 deddt = 2 * bndunit * force * dt
45 * (1 + 1.5f * cbnd * dt + 2 * qbnd * dt2);
46 } else if (bndtyp == Bond::MORSE) {
47 real expterm = REAL_EXP(-2 * dt);
48 real bde = 0.25f * bndunit * force;
49 if CONSTEXPR (do_e) e = bde * (1 - expterm) * (1 - expterm);
50 if CONSTEXPR (do_g) deddt = 4 * bde * (1 - expterm) * expterm;
51 }
52
53 if CONSTEXPR (do_g) {
54 real de = deddt * REAL_RECIP(rab);
55 real dedx = de * xab;
56 real dedy = de * yab;
57 real dedz = de * zab;
58 atomic_add(dedx, debx, ia);
59 atomic_add(dedy, deby, ia);
60 atomic_add(dedz, debz, ia);
61 atomic_add(-dedx, debx, ib);
62 atomic_add(-dedy, deby, ib);
63 atomic_add(-dedz, debz, ib);
64
65 if CONSTEXPR (do_v) {
66 vxx = xab * dedx;
67 vyx = yab * dedx;
68 vzx = zab * dedx;
69 vyy = yab * dedy;
70 vzy = zab * dedy;
71 vzz = zab * dedz;
72 }
73 }
74}
75}
void atomic_add(T value, T *buffer, size_t offset=0)
Definition: acc/adddef.h:14
#define SEQ_CUDA
Definition: acc/seqdef.h:12
int(* ibnd)[2]
Bond
Definition: evalence.h:37
grad_prec * deby
real * bk
grad_prec * debx
grad_prec * debz
real bndunit
real * bl
Bond bndtyp
real cbnd
real qbnd
#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
Definition: testrt.h:9
__device__ void dk_bond(real &__restrict__ e, real &__restrict__ vxx, real &__restrict__ vyx, real &__restrict__ vzx, real &__restrict__ vyy, real &__restrict__ vzy, real &__restrict__ vzz, grad_prec *__restrict__ debx, grad_prec *__restrict__ deby, grad_prec *__restrict__ debz, Bond bndtyp, real bndunit, int i, const int(*__restrict__ ibnd)[2], const real *__restrict__ bl, const real *__restrict__ bk, real cbnd, real qbnd, const real *__restrict__ x, const real *__restrict__ y, const real *__restrict__ z)
Definition: bond.h:11