kforce_CDLJ.br 24.5 KB
Newer Older
1

2
3
4
5
6
7
8
9
/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
10
11
 * Portions copyright (c) 2009 Stanford University and the Authors.           *
 * Authors: Mark Friedrichs, Mike Houston                                     *
12
13
 * Contributors:                                                              *
 *                                                                            *
14
15
16
17
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU Lesser General Public License as published   *
 * by the Free Software Foundation, either version 3 of the License, or       *
 * (at your option) any later version.                                        *
18
 *                                                                            *
19
20
21
22
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU Lesser General Public License for more details.                        *
23
 *                                                                            *
24
25
 * You should have received a copy of the GNU Lesser General Public License   *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
26
27
 * -------------------------------------------------------------------------- */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
28
kernel float4 scalar_force_CDLJ( float4 qq, float epsfac, float4 sig, float4 eps, float4 r2 ) {
Mark Friedrichs's avatar
Mark Friedrichs committed
29
30
31
32
33
34
35
36
37
38
39
40
41
 float4 invr, invrsig2, invrsig6;
 float4 f;

 invr = rsqrt( r2 );
 invrsig2 = invr * sig;
 invrsig2 = invrsig2 * invrsig2;
 invrsig6 = invrsig2 * invrsig2 * invrsig2;
 f = eps * ( 12.0f*invrsig6 - 6.0f ) * invrsig6;
 f += epsfac*qq*invr;
 f *= invr*invr;
 return f;
}

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
42
kernel float scalar_force_single_CDLJ( float qq, float epsfac, float sig, float eps, float r2 ) {
Mark Friedrichs's avatar
Mark Friedrichs committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 float invr, invrsig2, invrsig6;
 float f;

 invr = rsqrt( r2 );
 invrsig2 = invr * sig;
 invrsig2 = invrsig2 * invrsig2;
 invrsig6 = invrsig2 * invrsig2 * invrsig2;
 f = eps * ( 12.0f*invrsig6 - 6.0f ) * invrsig6;
 f += epsfac*qq*invr;
 f *= invr*invr;
 return f;
}
kernel float4 get_r2_CDLJ( float3 d1, float3 d2, float3 d3, float3 d4 ) {
 float4 r2;
 r2 = float4( dot(d1, d1), dot( d2, d2 ), dot( d3, d3 ), dot( d4, d4 ) );
 return r2;
}
Mark Friedrichs's avatar
Mark Friedrichs committed
60

Mark Friedrichs's avatar
Mark Friedrichs committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
kernel void knbforce_CDLJ (
  float natoms,
  float dupfac,
  float strheight,
  float strwidth,
  float jstrwidth,
  float fstrwidth,
  float epsfac,
  float4 params,
  float4 posq[][],
  float4 isigeps<>,
  float4 sigma[][],
  float4 epsilon[][],
  float2 excl[][],


  out float3 outforce1<>,
  out float3 outforce2<> ) {

 float4 jsig, jeps;
 float3 ipos1, ipos2;
 float3 jpos1, jpos2, jpos3, jpos4;
 float qi1, qi2;
 float4 qj, qq;
 float3 d1, d2, d3, d4;
 float2 exclind;
 float4 sig, eps;
 float2 exclusions;
 float4 r2;
 float3 pad;
 float4 exclmask;
 float4 exclconst;
 float2 iatom;
 float2 jstrindex;
 float a_iatom;
 float linind;

 float breakflag;
 float2 jatom;
 float4 fs;
 float jend, jstart;
 float which_rep;

 exclconst = float4( 2.0f, 3.0f, 5.0f, 7.0f );


 outforce1 = float4( 0.0f, 0.0f, 0.0f, 0.0f );
 outforce2 = float4( 0.0f, 0.0f, 0.0f, 0.0f );


   a_iatom = 2.0f*((indexof outforce1).x + (indexof outforce1).y * fstrwidth);


 linind = fmod( a_iatom, natoms );
 iatom.x = fmod( linind, strwidth );
 iatom.y = round( (linind - fmod(linind, strwidth))/strwidth );



 ipos1 = posq[ iatom ].xyz;
 qi1 = posq[ iatom ].w;

 iatom.x += 1;
 ipos2 = posq[ iatom ].xyz;
 qi2 = posq[ iatom ].w;


 breakflag = 1.0f;
 jatom.y = 0.0f;







 which_rep = round( (a_iatom - fmod(a_iatom, natoms))/natoms );
 jend = 1 + round( (natoms - fmod(natoms, (dupfac * strwidth )))/(dupfac * strwidth ) );
 jstart = which_rep * jend;
 if ( which_rep > dupfac - 1 - 0.5f ) {

  jend = 1e6f;
 }
 jend += jstart;

 exclind.x = linind/2.0f;
 exclind.y = jstart * strwidth/4.0f;

 jatom.y = jstart;
 while ( jatom.y < jend && breakflag > 0.0f ) {
  jatom.x = 0;
  while ( jatom.x < strwidth && breakflag > 0.0f ) {

   exclusions = excl[ exclind ];

   exclmask = fmod( exclusions.x, exclconst );


   linind = (jatom.x + jatom.y*strwidth)/4.0f;
   jstrindex.y = round( (linind - fmod(linind, jstrwidth))/jstrwidth );
   jstrindex.x = linind - jstrindex.y * jstrwidth;


   jsig = sigma[ jstrindex ];
   jeps = epsilon[ jstrindex ];

   jpos1 = posq[ jatom ].xyz;
   qj.x = posq[ jatom ].w;
   jatom.x += 1.0f;

   jpos2 = posq[ jatom ].xyz;
   qj.y = posq[ jatom ].w;
   jatom.x += 1.0f;

   jpos3 = posq[ jatom ].xyz;
   qj.z = posq[ jatom ].w;
   jatom.x += 1.0f;

   jpos4 = posq[ jatom ].xyz;
   qj.w = posq[ jatom ].w;
   jatom.x += 1.0f;


   sig = isigeps.x + jsig;
   eps = isigeps.y * jeps;
   qq = qi1 * qj;

   d1 = ipos1 - jpos1;
   d2 = ipos1 - jpos2;
   d3 = ipos1 - jpos3;
   d4 = ipos1 - jpos4;


   r2 = get_r2_CDLJ( d1, d2, d3, d4 ) + exclmask * 10000.0f;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
195
   fs = scalar_force_CDLJ( qq, epsfac, sig, eps, r2 );
Mark Friedrichs's avatar
Mark Friedrichs committed
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

   outforce1 += fs.x * d1;
   outforce1 += fs.y * d2;
   outforce1 += fs.z * d3;
   outforce1 += fs.w * d4;
/*
outforce1.x += exclmask.x;
outforce1.x += exclmask.y;
outforce1.x += exclmask.z;
outforce1.x += exclmask.w;
if( exclmask.x > 0.5f ){
   outforce1.x += 1.0f;
}
if( exclmask.y > 0.5f ){
   outforce1.x += 1.0f;
}
if( exclmask.z > 0.5f ){
   outforce1.x += 1.0f;
}
if( exclmask.w > 0.5f ){
   outforce1.x += 1.0f;
}
*/

   exclmask = fmod( exclusions.y, exclconst );

   sig = isigeps.z + jsig;
   eps = isigeps.w * jeps;
   qq = qi2 * qj;

   d1 = ipos2 - jpos1;
   d2 = ipos2 - jpos2;
   d3 = ipos2 - jpos3;
   d4 = ipos2 - jpos4;

   r2 = get_r2_CDLJ( d1, d2, d3, d4 ) + exclmask * 10000.0f;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
232
   fs = scalar_force_CDLJ( qq, epsfac, sig, eps, r2 );
Mark Friedrichs's avatar
Mark Friedrichs committed
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

   outforce2 += fs.x * d1;
   outforce2 += fs.y * d2;
   outforce2 += fs.z * d3;
   outforce2 += fs.w * d4;

/*
outforce2.x += exclmask.x;
outforce2.x += exclmask.y;
outforce2.x += exclmask.z;
outforce2.x += exclmask.w;
if( exclmask.x > 0.5f ){
   outforce2.x += 1.0f;
}
if( exclmask.y > 0.5f ){
   outforce2.x += 1.0f;
}
if( exclmask.z > 0.5f ){
   outforce2.x += 1.0f;
}
if( exclmask.w > 0.5f ){
   outforce2.x += 1.0f;
}
*/

   exclind.y += 1.0f;


   if ( natoms - (jatom.y*strwidth + jatom.x) < 0.9f )
    breakflag = -1.0f;
  }

  jatom.y += 1.0f;
 }

}

Mark Friedrichs's avatar
Mark Friedrichs committed
270
kernel void knbforce_CDLJ4(
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
  float natoms,
  float nAtomsCeiling,
  float dupfac,
  float strheight,
  float strwidth,
  float jstrwidth,
  float fstrwidth,
  float epsfac,
  float3 posq[][],
  float  charge[][],
  float4 isigeps[][],
  float4 sigma[][],
  float4 epsilon[][],
  float excl[][],
  out float3 outforce1<>,
  out float3 outforce2<>,
  out float3 outforce3<>,
  out float3 outforce4<> ) {

 float4 jsig, jeps;
 float3 ipos1, ipos2, ipos3, ipos4;
 float4 jpos;
 float3 jpos1, jpos2, jpos3, jpos4;
 float qi1, qi2, qi3, qi4;

 float isig1, isig2, isig3, isig4;
 float ieps1, ieps2, ieps3, ieps4;

 float4 qj, qq;
 float3 d1, d2, d3, d4;
 float2 exclind;
 float4 sig, eps;
 float  exclusions;
 float4 r2;
 float3 pad;
 float4 exclmask;
 float4 exclconst;
 float2 iatom;
 float2 jstrindex;
 float a_iatom;
 float linind;

 float breakflag;
 float2 jatom;
 float4 fs;
 float jend, jstart;
 float which_rep;
Mark Friedrichs's avatar
Mark Friedrichs committed
318
319
320
 float maskMultiplier;

 maskMultiplier = 1.0e+06f;
321
322
323

 exclconst  = float4( 2.0f, 3.0f, 5.0f, 7.0f );

Mark Friedrichs's avatar
Mark Friedrichs committed
324
325
326
327
 outforce1  = float3( 0.0f, 0.0f, 0.0f );
 outforce2  = float3( 0.0f, 0.0f, 0.0f );
 outforce3  = float3( 0.0f, 0.0f, 0.0f );
 outforce4  = float3( 0.0f, 0.0f, 0.0f );
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

 a_iatom    = 4.0f*((indexof outforce1).x + (indexof outforce1).y * fstrwidth);

 // linind     = fmod( a_iatom, natoms );
 linind     = fmod( a_iatom, nAtomsCeiling );

 iatom.x    = fmod( linind, strwidth );
 iatom.y    = round( (linind - fmod(linind, strwidth))/strwidth );

/* --------------------------------------------------------------------- */

 ipos1      = posq[ iatom ];
 qi1        = charge[ iatom ];

 jstrindex  = isigeps[ iatom ];
 isig1      = jstrindex.x;
 ieps1      = jstrindex.y;

/* --------------------------------------------------------------------- */

 iatom.x   += 1;
 ipos2      = posq[ iatom ];
 qi2        = charge[ iatom ];

 jstrindex  = isigeps[ iatom ];
 isig2      = jstrindex.x;
 ieps2      = jstrindex.y;

/* --------------------------------------------------------------------- */

 iatom.x   += 1;
 ipos3      = posq[ iatom ];
 qi3        = charge[ iatom ];

 jstrindex  = isigeps[ iatom ];
 isig3      = jstrindex.x;
 ieps3      = jstrindex.y;

/* --------------------------------------------------------------------- */

 iatom.x   += 1;
 ipos4      = posq[ iatom ];
 qi4        = charge[ iatom ];

Mark Friedrichs's avatar
Mark Friedrichs committed
372

373
374
375
376
377
378
379
380
381
382
383
384
 jstrindex  = isigeps[ iatom ];
 isig4      = jstrindex.x;
 ieps4      = jstrindex.y;

/* --------------------------------------------------------------------- */

 breakflag  = 1.0f;
 jatom.y    = 0.0f;

 // which_rep  = round( (a_iatom - fmod(a_iatom, natoms))/natoms );
 which_rep  = round( (a_iatom - fmod(a_iatom, nAtomsCeiling ))/nAtomsCeiling );

Mark Friedrichs's avatar
Mark Friedrichs committed
385
 jend       = 1.0f + round( (natoms - fmod(natoms, (dupfac * strwidth )))/(dupfac * strwidth ) );
386
 jstart     = which_rep * jend;
Mark Friedrichs's avatar
Mark Friedrichs committed
387
 if ( which_rep > dupfac - 1.5f ) {
388
389
390
391
  jend = 1e6f;
 }
 jend      += jstart;

Mark Friedrichs's avatar
Mark Friedrichs committed
392
393
394
 exclind.x  = linind;
 exclind.y  = jstart * strwidth/4.0f;
 exclind.y  = floor(  exclind.y  + 0.25f );
395
396
397
398
399
400

 jatom.y    = jstart;
 while ( jatom.y < jend && breakflag > 0.0f ) {
  jatom.x = 0;
  while ( jatom.x < strwidth && breakflag > 0.0f ) {

Mark Friedrichs's avatar
Mark Friedrichs committed
401
402
   exclusions  = excl[ exclind ];
   exclmask    = fmod( exclusions, exclconst );
403
404

   linind      = (jatom.x + jatom.y*strwidth)/4.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
405
   linind      = floor( linind + 0.25f );
406
407
408

   jstrindex.y = round( (linind - fmod(linind, jstrwidth))/jstrwidth );
   jstrindex.x = linind - jstrindex.y * jstrwidth;
Mark Friedrichs's avatar
Mark Friedrichs committed
409
   jstrindex.x = floor( jstrindex.x + 0.25f );
410
411
412
413
414
415
416
417

   /* --------------------------------------------------------------------- */

   jsig        = sigma[ jstrindex ];
   jeps        = epsilon[ jstrindex ];

   jpos1       = posq[ jatom ];
   qj.x        = charge[ jatom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
418
   jatom.x     = floor( jatom.x + 1.2f );
419
420
421

   jpos2       = posq[ jatom ];
   qj.y        = charge[ jatom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
422
   jatom.x     = floor( jatom.x + 1.2f );
423
424
425

   jpos3       = posq[ jatom ];
   qj.z        = charge[ jatom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
426
   jatom.x     = floor( jatom.x + 1.2f );
427
428
429

   jpos4       = posq[ jatom ];
   qj.w        = charge[ jatom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
430
   jatom.x     = floor( jatom.x + 1.2f );
431
432
433
434
435
436
437
438
439
440
441
442

   /* --------------------------------------------------------------------- */

   sig         = isig1 + jsig;
   eps         = ieps1 * jeps;
   qq          = qi1*qj;

   d1          = ipos1 - jpos1;
   d2          = ipos1 - jpos2;
   d3          = ipos1 - jpos3;
   d4          = ipos1 - jpos4;

Mark Friedrichs's avatar
Mark Friedrichs committed
443
   r2          = get_r2_CDLJ( d1, d2, d3, d4 ) + (exclmask*maskMultiplier);
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
444
   fs          = scalar_force_CDLJ( qq, epsfac, sig, eps, r2 );
445
446
447
448
449
450
451
452
453

   outforce1  += fs.x * d1;
   outforce1  += fs.y * d2;
   outforce1  += fs.z * d3;
   outforce1  += fs.w * d4;

   /* --------------------------------------------------------------------- */

   //exclind.x  += 1.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
454
455
456
   exclind.x   = floor( exclind.x + 1.2f );
   exclusions  = excl[ exclind ];
   exclmask    = fmod( exclusions, exclconst );
457
458
459
460
461
462
463
464
465
466

   sig         = isig2 + jsig;
   eps         = ieps2 * jeps;
   qq          = qi2 * qj;

   d1          = ipos2 - jpos1;
   d2          = ipos2 - jpos2;
   d3          = ipos2 - jpos3;
   d4          = ipos2 - jpos4;

Mark Friedrichs's avatar
Mark Friedrichs committed
467
   r2          = get_r2_CDLJ( d1, d2, d3, d4 ) + (exclmask*maskMultiplier);
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
468
   fs          = scalar_force_CDLJ( qq, epsfac, sig, eps, r2 );
469
470
471
472
473
474
475
476
477

   outforce2  += fs.x * d1;
   outforce2  += fs.y * d2;
   outforce2  += fs.z * d3;
   outforce2  += fs.w * d4;

   /* --------------------------------------------------------------------- */

   //exclind.x  += 1.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
478
479
480
   exclind.x   = floor( exclind.x + 1.2f );
   exclusions  = excl[ exclind ];
   exclmask    = fmod( exclusions, exclconst );
481
482
483
484
485
486
487
488
489
490

   sig         = isig3 + jsig;
   eps         = ieps3 * jeps;
   qq          = qi3   * qj;

   d1          = ipos3 - jpos1;
   d2          = ipos3 - jpos2;
   d3          = ipos3 - jpos3;
   d4          = ipos3 - jpos4;

Mark Friedrichs's avatar
Mark Friedrichs committed
491
   r2          = get_r2_CDLJ( d1, d2, d3, d4 ) + (exclmask*maskMultiplier);
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
492
   fs          = scalar_force_CDLJ( qq, epsfac, sig, eps, r2 );
493
494
495
496
497
498
499
500
501

   outforce3  += fs.x * d1;
   outforce3  += fs.y * d2;
   outforce3  += fs.z * d3;
   outforce3  += fs.w * d4;

   /* --------------------------------------------------------------------- */

   //exclind.x  += 1.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
502
503
504
   exclind.x   = floor( exclind.x + 1.2f );
   exclusions  = excl[ exclind ];
   exclmask    = fmod( exclusions, exclconst );
505
506
507
508
509
510
511
512
513
514

   sig         = isig4 + jsig;
   eps         = ieps4 * jeps;
   qq          = qi4   * qj;

   d1          = ipos4 - jpos1;
   d2          = ipos4 - jpos2;
   d3          = ipos4 - jpos3;
   d4          = ipos4 - jpos4;

Mark Friedrichs's avatar
Mark Friedrichs committed
515
   r2          = get_r2_CDLJ( d1, d2, d3, d4 ) + (exclmask*maskMultiplier);
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
516
   fs          = scalar_force_CDLJ( qq, epsfac, sig, eps, r2 );
517
518
519
520
521
522
523
524
525

   outforce4  += fs.x * d1;
   outforce4  += fs.y * d2;
   outforce4  += fs.z * d3;
   outforce4  += fs.w * d4;

   /* --------------------------------------------------------------------- */

   //exclind.x  -= 3.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
526
527
   exclind.x   = floor( exclind.x - 2.9f );

528
   //exclind.y  += 1.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
529
   exclind.y  = floor(  exclind.y  + 1.25f );
530

Mark Friedrichs's avatar
Mark Friedrichs committed
531
   if( natoms - (jatom.y*strwidth + jatom.x) < 0.9f )breakflag = -1.0f;
532
533
  }

Mark Friedrichs's avatar
Mark Friedrichs committed
534
535
  //jatom.y += 1.0f;
  jatom.y  = floor( jatom.y + 1.2f );
536
537
538
 }

}
Mark Friedrichs's avatar
Mark Friedrichs committed
539

Mark Friedrichs's avatar
Mark Friedrichs committed
540
kernel void kforce14_CDLJ(
Mark Friedrichs's avatar
Mark Friedrichs committed
541
542
543
544
  float natoms,
  float strwidth,
  float epsfac,
  float4 params,
Mark Friedrichs's avatar
Mark Friedrichs committed
545
546
547
548
549
550
551
552
553
554
555
  float2 atoms<>,
  float4 posq[][],
  float2 sigeps<>,
  out float3 fi<>,
  out float3 fj<>
  )
{
 float2 ai, aj;
 float3 d1;
 float r2;
 float qq, fs;
Mark Friedrichs's avatar
Mark Friedrichs committed
556

Mark Friedrichs's avatar
Mark Friedrichs committed
557
558
559
 //ai.y = floor( atoms.x / strwidth );
 ai.y = round( (atoms.x - fmod( atoms.x, strwidth ))/strwidth );
 ai.x = atoms.x - ai.y * strwidth;
Mark Friedrichs's avatar
Mark Friedrichs committed
560

Mark Friedrichs's avatar
Mark Friedrichs committed
561
562
563
 //aj.y = floor( atoms.y / strwidth );
 aj.y = round( (atoms.y - fmod( atoms.y, strwidth ))/strwidth );
 aj.x = atoms.y - aj.y * strwidth;
564

Mark Friedrichs's avatar
Mark Friedrichs committed
565
566
 d1 = posq[ai].xyz - posq[aj].xyz;
 qq = posq[ai].w * posq[aj].w;
Mark Friedrichs's avatar
Mark Friedrichs committed
567

Mark Friedrichs's avatar
Mark Friedrichs committed
568
 r2 = dot( d1, d1 );
Mark Friedrichs's avatar
Mark Friedrichs committed
569

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
570
 fs = scalar_force_single_CDLJ( qq, epsfac, sigeps.x, sigeps.y, r2 );
Mark Friedrichs's avatar
Mark Friedrichs committed
571

Mark Friedrichs's avatar
Mark Friedrichs committed
572
573
574
 fi = fs.x * d1;
 fj = -fi;
}
Mark Friedrichs's avatar
Mark Friedrichs committed
575

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
kernel void kAcosV( float x<>, out float acosVal<> ){

   float x2, x3, x5, x7, x9, x11, x13, x15, x17, x19;

   float pi2           = 1.57079632679489661923f;
   float coefficient3  = 1.0f/6.0f;
   float coefficient5  = 3.0f/40.0f;
   float coefficient7  = 5.0f/112.0f;
   float coefficient9  = 35.0f/1152.0f;
   float coefficient11 = 63.0f/2816.0f;
   float coefficient13 = 231.0f/13312.0f;
   float coefficient15 = 143.0f/10240.0f;
   float coefficient17 = 6435.0f/557056.0f;
   float coefficient19 = 12155.0f/1245184.0f;
 
   // ---------------------------------------------------------------------------------------

   x2             =  x*x;
   x3             =  x*x2;
   x5             = x3*x2;
   x7             = x5*x2;
   x9             = x7*x2;
   x11            = x9*x2;
   x13            = x11*x2;
   x15            = x13*x2;
   x17            = x15*x2;
   x19            = x17*x2;

   acosVal        = x19*coefficient19;
   acosVal       += x17*coefficient17;
   acosVal       += x15*coefficient15;
   acosVal       += x13*coefficient13;
   acosVal       += x11*coefficient11;
   acosVal       += x9*coefficient9;
   acosVal       += x7*coefficient7;
   acosVal       += x5*coefficient5;
   acosVal       += x3*coefficient3 + x;
   acosVal        = pi2 - acosVal;
Mark Friedrichs's avatar
Mark Friedrichs committed
614

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
615
}
Mark Friedrichs's avatar
Mark Friedrichs committed
616

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
kernel void kAcosTanV( float xIn<>, out float acosVal<> ){

   const float c1             = 48.70107004404898384f;
   const float c2             = 49.5326263772254345f;
   const float c3             = 9.40604244231624f;
   const float c4             = 48.70107004404996166f;
   const float c5             = 65.7663163908956299f;
   const float c6             = 21.587934067020262f;
   const float tantwelfthpi   = 0.26794919243112270647255365849413f;
   const float tansixthpi     = 0.57735026918962576450914878050196f;
   const float sixthpi        = 0.52359877559829887307710723054658f;
   const float halfpi         = 1.5707963267948966192313216916398f;

   float x2, y, x;
   float sign, complement, region;

   // ---------------------------------------------------------------------------------------

   complement                 = 0.0f;
   region                     = 0.0f;

   x                          = xIn;
   y                          = rsqrt( (1.0f + x)*(1.0f  - x) );
   x                         *= y;
   if( x < 0.0f ){
      x     = -x;
      sign  = -1.0f;
   } else {
      sign  =  1.0f;
   }

   if( x > 1.0f ){
      x           = 1.0f/x;
      complement  = 1.0f;
   } else {
      complement  = 0.0f;
   }

   if( x > tantwelfthpi ){
      x        = (x-tansixthpi)/(1.0f + tansixthpi*x);
      region   = sixthpi;
   } else {
      region   = 0.0f;
   }

   x2          = x*x;
   y           = (x*(c1 + x2*(c2 + x2*c3))/(c4 + x2*(c5 + x2*(c6 + x2))));

   y          += region;

   y           = (complement > 0.0f) ? (halfpi- y) : y;
   acosVal     = halfpi - sign*y;
Mark Friedrichs's avatar
Mark Friedrichs committed
669

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
670
}
Mark Friedrichs's avatar
Mark Friedrichs committed
671

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
672
kernel void kAcos( float xIn, out float acosVal<> ){
Mark Friedrichs's avatar
Mark Friedrichs committed
673

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
674
675
676
677
678
679
680
681
682
683
   const float c1             = 48.70107004404898384f;
   const float c2             = 49.5326263772254345f;
   const float c3             = 9.40604244231624f;
   const float c4             = 48.70107004404996166f;
   const float c5             = 65.7663163908956299f;
   const float c6             = 21.587934067020262f;
   const float tantwelfthpi   = 0.26794919243112270647255365849413f;
   const float tansixthpi     = 0.57735026918962576450914878050196f;
   const float sixthpi        = 0.52359877559829887307710723054658f;
   const float halfpi         = 1.5707963267948966192313216916398f;
Mark Friedrichs's avatar
Mark Friedrichs committed
684

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
685
686
   float x2, y, x;
   float sign, complement, region;
Mark Friedrichs's avatar
Mark Friedrichs committed
687

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
688
   // ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
689

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
690
   // acos(x) = atan(x/sqrt(1-x**2))
Mark Friedrichs's avatar
Mark Friedrichs committed
691

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
692
693
694
   x        = xIn;
   y        = rsqrt( (1.0f + x)*(1.0f - x) );
   x        *= y;
Mark Friedrichs's avatar
Mark Friedrichs committed
695

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
696
697
698
699
700
701
   if( x < 0.0f ){
      x     = -x;
      sign  = -1.0f;
   } else {
      sign  =  1.0f;
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
702

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
703
704
705
706
707
708
   if( x > 1.0f ){
      x           = 1.0f/x;
      complement  = 1.0f;
   } else {
      complement  = 0.0f;
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
709

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
710
711
712
713
714
715
   if( x > tantwelfthpi ){
      x        = (x - tansixthpi)/(1.0f + tansixthpi*x);
      region   = sixthpi;
   } else {
      region   = 0.0f;
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
716

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
717
718
   x2          = x*x;
   y           = (x*(c1 + x2*(c2 + x2*c3))/(c4 + x2*(c5 + x2*(c6 + x2))));
Mark Friedrichs's avatar
Mark Friedrichs committed
719

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
720
   y          += region;
Mark Friedrichs's avatar
Mark Friedrichs committed
721

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
722
723
   y           = (complement > 0.0f) ? (halfpi- y) : y;
   acosVal     = halfpi - sign*y;
Mark Friedrichs's avatar
Mark Friedrichs committed
724

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
725
}
Mark Friedrichs's avatar
Mark Friedrichs committed
726

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
kernel void kbonded_CDLJ (
      float epsfac,
      float xstrwidth,
      float3 posq[][],
      float  charge<>,
      float4 atoms<>,
      float4 parm0<>,
      float4 parm1<>,
      float4 parm2<>,
      float4 parm3<>,
      float4 parm4<>,
      out float3 fi<>,
      out float3 fj<>,
      out float3 fk<>,
      out float3 fl<>
   ){
  
   float3 rij, rkj, rkl, ril;
   float2 ai, aj, ak, al;
   float3 m, n;
   float sgnphi;
   float cosfac;
   float ddphi, ddphi_rb;
   float3 u, v, s;
   float invlkj, invlij, invlkl, msq, nsq, cos_phi, sin_phi;
   float3 uij, ukj, ukl;
   float phi, mdphi;
   float rij_d_ukj, ukj_d_rkl;
   float normfac;
   float qq;
   float3 fi_ang, fj_ang, fk_ang;
   float3 fi_bond;
   float cii, ckk, cik;
   float fs, st, sth;
   float3 fi_pair;
   float r2 ;
   float torsion_numerator;
   float theta1, costheta1, invsintheta1;
   float theta2, costheta2, invsintheta2;
   float3 posqi, posqj, posqk, posql;
   float sig, eps;
  
   // i-coordinates

   ai.y  = round( (atoms.x - fmod( atoms.x, xstrwidth ))/xstrwidth );
   ai.x  = atoms.x - ai.y * xstrwidth;
   posqi = posq[ ai ];
  
   // j-coordinates

   if ( atoms.y > -0.5f ) {
      aj.y  = round( (atoms.y - fmod( atoms.y, xstrwidth ))/xstrwidth );
      aj.x  = atoms.y - aj.y * xstrwidth;
      posqj = posq[ aj ];
   } else {
      posqj = float3( 0.0f, 1.0f, 0.0f );
   }
  
   // k-coordinates

   if ( atoms.z > -0.5f ) {
      ak.y = round( (atoms.z - fmod( atoms.z, xstrwidth ))/xstrwidth );
      ak.x = atoms.z - ak.y * xstrwidth;
      posqk = posq[ ak ];
   } else { 
      posqk = float3( 1.0f, 1.0f, 0.0f );
   }
  
   // l-coordinates

   if ( atoms.w > -0.5f ) {
      al.y  = round( (atoms.w - fmod( atoms.w, xstrwidth ))/xstrwidth );
      al.x  = atoms.w - al.y * xstrwidth;
      posql = posq[ al ];
   } else {
      posql = float3( 1.0f, 1.0f, 1.0f );
   }
  
   rij             = posqi - posqj;
   rkj             = posqk - posqj;
   rkl             = posqk - posql;
   ril             = posqi - posql;
  
   invlij          = rsqrt( dot( rij, rij ) );
   invlkj          = rsqrt( dot( rkj, rkj ) );
   invlkl          = rsqrt( dot( rkl, rkl ) );
  
   uij             = rij * invlij;
   ukj             = rkj * invlkj;
   ukl             = rkl * invlkl;
  
   rij_d_ukj       = dot( rij, ukj );
   ukj_d_rkl       = dot( ukj, rkl );
  
   m               = cross( uij, ukj );
   n               = cross( ukj, ukl );
  
   costheta1       = clamp( rij_d_ukj * invlij, -1.0f, 1.0f );
   //theta1          = acos( costheta1 );
   kAcos( costheta1, theta1 );
   invsintheta1    = rsqrt( (1.0f - costheta1) * (1.0f + costheta1) );
  
   costheta2       = clamp( ukj_d_rkl * invlkl, -1.0f, 1.0f );
   //theta2          = acos( costheta2 );
   kAcos( costheta2, theta2 );
   invsintheta2    = rsqrt( (1.0f - costheta2) * (1.0f + costheta2) );
  
   cos_phi         = clamp( dot(m,n) * invsintheta1 * invsintheta2, -1.0f, 1.0f );
   sgnphi          = sign( dot(rij, n) );
  
   phi             = sgnphi * acos( cos_phi );
   mdphi           = parm1.w * phi - parm1.z;
   ddphi           = -parm1.y * parm1.w * sin( mdphi );
  
   cos_phi         = -cos_phi;
   sin_phi         = -sgnphi*sqrt( (1.0f - cos_phi) * (1.0f + cos_phi) );
  
   ddphi_rb        = 5.0f * parm1.x;
   ddphi_rb        = 4.0f * parm0.w + ddphi_rb * cos_phi;
   ddphi_rb        = 3.0f * parm0.z + ddphi_rb * cos_phi;
   ddphi_rb        = 2.0f * parm0.y + ddphi_rb * cos_phi;
   ddphi_rb        = parm0.x + ddphi_rb * cos_phi;
   ddphi_rb        = -ddphi_rb * sin_phi;
  
   ddphi          += ddphi_rb;
/*
fi = float3( cos_phi, sgnphi, ddphi_rb );
fj = float3( sin_phi, parm1.x, parm0.w );
fk = float3( parm0.z, parm0.y, parm0.x );
fl = float3( ddphi, 0.0f, 0.0f );
*/
  
   fi              = (-ddphi * invlij * invsintheta1 * invsintheta1 ) * m;
   fl              = ( ddphi * invlkl * invsintheta2 * invsintheta2 ) * n;
  
   u               = rij_d_ukj * invlkj * fi;
   v               = ukj_d_rkl * invlkj * fl;
   s               = u - v;
  
   fj              = s - fi;
   fk              = -(s + fl);
  
  
   fs              = -parm2.y * ( theta1 - parm2.x );
   st              = fs * invsintheta1;
   st              = clamp( st, -100000.0f, 100000.0f );
  
   sth             = st * costheta1;
  
   cik             = st * invlkj * invlij;
   cii             = sth * invlij;
   ckk             = sth * invlkj;
  
   fi_ang          = -( cik * rkj - cii * uij );
   fk_ang          = -( cik * rij - ckk * ukj );
   fj_ang          = -fi_ang - fk_ang;
  
   fi             += fi_ang;
   fj             += fj_ang;
   fk             += fk_ang;
   fs              = -parm2.w * ( theta2 - parm2.z );
   st              = fs * invsintheta2;
   st              = clamp( st, -100000.0f, 100000.0f );
  
   sth             = st * costheta2;
  
   cik             = st * invlkj * invlkl;
   cii             = sth * invlkj;
   ckk             = sth * invlkl;
  
   fi_ang          = ( cik * rkl - cii * ukj );
   fk_ang          = ( cik * rkj - ckk * ukl );
   fj_ang          = -fi_ang - fk_ang;
  
   fj             += fi_ang;
   fk             += fj_ang;
   fl             += fk_ang;
  
  
   fi_bond         = -parm3.y * ( 1.0f - parm3.x * invlij ) * rij;
   fi             += fi_bond;
   fj             += -fi_bond;
  
   fi_bond         = parm3.w * ( 1.0f - parm3.z * invlkj ) * rkj;
   fj             += fi_bond;
   fk             += -fi_bond;
  
   fi_bond         = -parm4.y * ( 1.0f - parm4.x * invlkl ) * rkl;
   fk             += fi_bond;
   fl             += -fi_bond;
  
   if( parm4.z > -0.5f ){
      r2        = dot( ril, ril );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
920
      fs        = scalar_force_single_CDLJ( charge, epsfac, parm4.z, parm4.w, r2 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
921
922
923
      fi_pair   = fs * ril;
      fi       += fi_pair;
      fl       -= fi_pair;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
924
925
926
927
928
929
930
931
932
//fi = float3( charge, parm4.z, parm4.w );
//fj = float3( 1.0f, 2.f, 3.0f );
/*
   } else {
      fi = float3( 0.0f, 0.f, 0.0f );
      fj = float3( 0.0f, 0.f, 0.0f );
      fk = float3( 0.0f, 0.f, 0.0f );
      fl = float3( 0.0f, 0.f, 0.0f );
*/
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
933
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
934
935

}
Mark Friedrichs's avatar
Mark Friedrichs committed
936