kforce_CDLJ.br 19.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* -------------------------------------------------------------------------- *
 *                                   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.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * Authors: Peter Eastman, Mark Friedrichs, Chris Bruns                       *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

Mark Friedrichs's avatar
Mark Friedrichs committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
kernel float4 scalar_force_CDLJ( float4 qq, float epsfac, float4 sig, float4 eps, float4 r2, float4 params ) {
 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;
}

46
kernel float scalar_force_single_CDLJ( float qq, float epsfac, float sig, float eps, float r2, float4 params ) {
Mark Friedrichs's avatar
Mark Friedrichs committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 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
64

Mark Friedrichs's avatar
Mark Friedrichs committed
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
195
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
232
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
270
271
272
273
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;
   fs = scalar_force_CDLJ( qq, epsfac, sig, eps, r2, params );

   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;
   fs = scalar_force_CDLJ( qq, epsfac, sig, eps, r2, params );

   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
274
kernel void knbforce_CDLJ4(
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
318
319
320
321
322
  float natoms,
  float nAtomsCeiling,
  float dupfac,
  float strheight,
  float strwidth,
  float jstrwidth,
  float fstrwidth,
  float epsfac,
  float4 params,
  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
323
324
325
 float maskMultiplier;

 maskMultiplier = 1.0e+06f;
326
327
328

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

Mark Friedrichs's avatar
Mark Friedrichs committed
329
330
331
332
 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 );
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
372
373
374
375
376

 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
377

378
379
380
381
382
383
384
385
386
387
388
389
 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
390
 jend       = 1.0f + round( (natoms - fmod(natoms, (dupfac * strwidth )))/(dupfac * strwidth ) );
391
 jstart     = which_rep * jend;
Mark Friedrichs's avatar
Mark Friedrichs committed
392
 if ( which_rep > dupfac - 1.5f ) {
393
394
395
396
  jend = 1e6f;
 }
 jend      += jstart;

Mark Friedrichs's avatar
Mark Friedrichs committed
397
398
399
 exclind.x  = linind;
 exclind.y  = jstart * strwidth/4.0f;
 exclind.y  = floor(  exclind.y  + 0.25f );
400
401
402
403
404
405

 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
406
407
   exclusions  = excl[ exclind ];
   exclmask    = fmod( exclusions, exclconst );
408
409

   linind      = (jatom.x + jatom.y*strwidth)/4.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
410
   linind      = floor( linind + 0.25f );
411
412
413

   jstrindex.y = round( (linind - fmod(linind, jstrwidth))/jstrwidth );
   jstrindex.x = linind - jstrindex.y * jstrwidth;
Mark Friedrichs's avatar
Mark Friedrichs committed
414
   jstrindex.x = floor( jstrindex.x + 0.25f );
415
416
417
418
419
420
421
422

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

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

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

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

   jpos3       = posq[ jatom ];
   qj.z        = charge[ jatom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
431
   jatom.x     = floor( jatom.x + 1.2f );
432
433
434

   jpos4       = posq[ jatom ];
   qj.w        = charge[ jatom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
435
   jatom.x     = floor( jatom.x + 1.2f );
436
437
438
439
440
441
442
443
444
445
446
447

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

   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
448
   r2          = get_r2_CDLJ( d1, d2, d3, d4 ) + (exclmask*maskMultiplier);
449
450
451
452
453
454
455
456
457
458
   fs          = scalar_force_CDLJ( qq, epsfac, sig, eps, r2, params );

   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
459
460
461
   exclind.x   = floor( exclind.x + 1.2f );
   exclusions  = excl[ exclind ];
   exclmask    = fmod( exclusions, exclconst );
462
463
464
465
466
467
468
469
470
471

   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
472
   r2          = get_r2_CDLJ( d1, d2, d3, d4 ) + (exclmask*maskMultiplier);
473
474
475
476
477
478
479
480
481
482
   fs          = scalar_force_CDLJ( qq, epsfac, sig, eps, r2, params );

   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
483
484
485
   exclind.x   = floor( exclind.x + 1.2f );
   exclusions  = excl[ exclind ];
   exclmask    = fmod( exclusions, exclconst );
486
487
488
489
490
491
492
493
494
495

   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
496
   r2          = get_r2_CDLJ( d1, d2, d3, d4 ) + (exclmask*maskMultiplier);
497
498
499
500
501
502
503
504
505
506
   fs          = scalar_force_CDLJ( qq, epsfac, sig, eps, r2, params );

   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
507
508
509
   exclind.x   = floor( exclind.x + 1.2f );
   exclusions  = excl[ exclind ];
   exclmask    = fmod( exclusions, exclconst );
510
511
512
513
514
515
516
517
518
519

   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
520
   r2          = get_r2_CDLJ( d1, d2, d3, d4 ) + (exclmask*maskMultiplier);
521
522
523
524
525
526
527
528
529
530
   fs          = scalar_force_CDLJ( qq, epsfac, sig, eps, r2, params );

   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
531
532
   exclind.x   = floor( exclind.x - 2.9f );

533
   //exclind.y  += 1.0f;
Mark Friedrichs's avatar
Mark Friedrichs committed
534
   exclind.y  = floor(  exclind.y  + 1.25f );
535

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

Mark Friedrichs's avatar
Mark Friedrichs committed
539
540
  //jatom.y += 1.0f;
  jatom.y  = floor( jatom.y + 1.2f );
541
542
543
 }

}
Mark Friedrichs's avatar
Mark Friedrichs committed
544

Mark Friedrichs's avatar
Mark Friedrichs committed
545
kernel void kforce14_CDLJ(
Mark Friedrichs's avatar
Mark Friedrichs committed
546
547
548
549
  float natoms,
  float strwidth,
  float epsfac,
  float4 params,
Mark Friedrichs's avatar
Mark Friedrichs committed
550
551
552
553
554
555
556
557
558
559
560
  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
561

Mark Friedrichs's avatar
Mark Friedrichs committed
562
563
564
 //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
565

Mark Friedrichs's avatar
Mark Friedrichs committed
566
567
568
 //aj.y = floor( atoms.y / strwidth );
 aj.y = round( (atoms.y - fmod( atoms.y, strwidth ))/strwidth );
 aj.x = atoms.y - aj.y * strwidth;
569

Mark Friedrichs's avatar
Mark Friedrichs committed
570
571
 d1 = posq[ai].xyz - posq[aj].xyz;
 qq = posq[ai].w * posq[aj].w;
Mark Friedrichs's avatar
Mark Friedrichs committed
572

Mark Friedrichs's avatar
Mark Friedrichs committed
573
 r2 = dot( d1, d1 );
Mark Friedrichs's avatar
Mark Friedrichs committed
574

Mark Friedrichs's avatar
Mark Friedrichs committed
575
 fs = scalar_force_single_CDLJ( qq, epsfac, sigeps.x, sigeps.y, r2, params );
Mark Friedrichs's avatar
Mark Friedrichs committed
576

Mark Friedrichs's avatar
Mark Friedrichs committed
577
578
579
 fi = fs.x * d1;
 fj = -fi;
}
Mark Friedrichs's avatar
Mark Friedrichs committed
580

Mark Friedrichs's avatar
Mark Friedrichs committed
581
kernel void kbonded_CDLJ (
Mark Friedrichs's avatar
Mark Friedrichs committed
582
583
584
  float epsfac,
  float xstrwidth,
  float4 nbparams,
Mark Friedrichs's avatar
Mark Friedrichs committed
585
586
  float3 posq[][],
  float  charge[][],
Mark Friedrichs's avatar
Mark Friedrichs committed
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
  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;
Mark Friedrichs's avatar
Mark Friedrichs committed
614
615
616
617
618
619
620
621
622
623
 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  chargei, chargel;
 float sig, eps;
Mark Friedrichs's avatar
Mark Friedrichs committed
624
625
626
627
628
629






Mark Friedrichs's avatar
Mark Friedrichs committed
630
631
632
633
   ai.y = round( (atoms.x - fmod( atoms.x, xstrwidth ))/xstrwidth );
 ai.x = atoms.x - ai.y * xstrwidth;
 posqi = posq[ ai ];
 chargei = charge[ ai ];
Mark Friedrichs's avatar
Mark Friedrichs committed
634
635
636
637
638
639






Mark Friedrichs's avatar
Mark Friedrichs committed
640
 if ( atoms.y > -0.5f ) {
Mark Friedrichs's avatar
Mark Friedrichs committed
641

Mark Friedrichs's avatar
Mark Friedrichs committed
642
643
644
645
646
647
      aj.y = round( (atoms.y - fmod( atoms.y, xstrwidth ))/xstrwidth );
  aj.x = atoms.y - aj.y * xstrwidth;
  posqj = posq[ aj ];
 }
 else
  posqj = float4( 0.0f, 0.0f, 1.0f, 0.0f );
Mark Friedrichs's avatar
Mark Friedrichs committed
648

Mark Friedrichs's avatar
Mark Friedrichs committed
649
 if ( atoms.z > -0.5f ) {
Mark Friedrichs's avatar
Mark Friedrichs committed
650

Mark Friedrichs's avatar
Mark Friedrichs committed
651
652
653
654
655
656
      ak.y = round( (atoms.z - fmod( atoms.z, xstrwidth ))/xstrwidth );
  ak.x = atoms.z - ak.y * xstrwidth;
  posqk = posq[ ak ];
 }
 else
  posqk = float4( 0.0f, 1.0f, 1.0f, 0.0f );
Mark Friedrichs's avatar
Mark Friedrichs committed
657

Mark Friedrichs's avatar
Mark Friedrichs committed
658
 if ( atoms.w > -0.5f ) {
Mark Friedrichs's avatar
Mark Friedrichs committed
659

Mark Friedrichs's avatar
Mark Friedrichs committed
660
661
662
663
664
665
666
667
      al.y = round( (atoms.w - fmod( atoms.w, xstrwidth ))/xstrwidth );
  al.x = atoms.w - al.y * xstrwidth;
  posql = posq[ al ];
  chargel = charge[ al ];
 } else {
  posql = float4( 1.0f, 1.0f, 1.0f, 0.0f );
  chargel = 0.0f;
}
Mark Friedrichs's avatar
Mark Friedrichs committed
668

Mark Friedrichs's avatar
Mark Friedrichs committed
669
670
671
672
673
 qq = chargei*chargel;
 rij = posqi.xyz - posqj.xyz;
 rkj = posqk.xyz - posqj.xyz;
 rkl = posqk.xyz - posql.xyz;
 ril = posqi.xyz - posql.xyz;
Mark Friedrichs's avatar
Mark Friedrichs committed
674
675
676



Mark Friedrichs's avatar
Mark Friedrichs committed
677
678
679
 invlij = rsqrt( dot( rij, rij ) );
 invlkj = rsqrt( dot( rkj, rkj ) );
 invlkl = rsqrt( dot( rkl, rkl ) );
Mark Friedrichs's avatar
Mark Friedrichs committed
680

Mark Friedrichs's avatar
Mark Friedrichs committed
681
682
683
 uij = rij * invlij;
 ukj = rkj * invlkj;
 ukl = rkl * invlkl;
Mark Friedrichs's avatar
Mark Friedrichs committed
684
685


Mark Friedrichs's avatar
Mark Friedrichs committed
686
687
 rij_d_ukj = dot( rij, ukj );
 ukj_d_rkl = dot( ukj, rkl );
Mark Friedrichs's avatar
Mark Friedrichs committed
688

Mark Friedrichs's avatar
Mark Friedrichs committed
689
690
 m = cross( uij, ukj );
 n = cross( ukj, ukl );
Mark Friedrichs's avatar
Mark Friedrichs committed
691
692


Mark Friedrichs's avatar
Mark Friedrichs committed
693
694
695
 costheta1 = clamp( rij_d_ukj * invlij, -1.0f, 1.0f );
 theta1 = acos( costheta1 );
 invsintheta1 = rsqrt( 1.0f - costheta1 * costheta1 );
Mark Friedrichs's avatar
Mark Friedrichs committed
696
697


Mark Friedrichs's avatar
Mark Friedrichs committed
698
699
700
 costheta2 = clamp( ukj_d_rkl * invlkl, -1.0f, 1.0f );
 theta2 = acos( costheta2 );
 invsintheta2 = rsqrt( 1.0f - costheta2 * costheta2 );
Mark Friedrichs's avatar
Mark Friedrichs committed
701

Mark Friedrichs's avatar
Mark Friedrichs committed
702
 cos_phi = clamp( dot(m,n) * invsintheta1 * invsintheta2, -1.0f, 1.0f );
Mark Friedrichs's avatar
Mark Friedrichs committed
703

Mark Friedrichs's avatar
Mark Friedrichs committed
704
 sgnphi = sign( dot(rij, n) );
Mark Friedrichs's avatar
Mark Friedrichs committed
705
706


Mark Friedrichs's avatar
Mark Friedrichs committed
707
708
709
 phi   = sgnphi * acos( cos_phi );
 mdphi = parm1.w * phi - parm1.z;
 ddphi = -parm1.y * parm1.w * sin( mdphi );
Mark Friedrichs's avatar
Mark Friedrichs committed
710
711


Mark Friedrichs's avatar
Mark Friedrichs committed
712
713
 cos_phi = -cos_phi;
 sin_phi = -sgnphi*sqrt( clamp( 1.0f - cos_phi * cos_phi, 0.0f, 1.0f) );
Mark Friedrichs's avatar
Mark Friedrichs committed
714

Mark Friedrichs's avatar
Mark Friedrichs committed
715
716
717
718
719
720
 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;
Mark Friedrichs's avatar
Mark Friedrichs committed
721
722


Mark Friedrichs's avatar
Mark Friedrichs committed
723
 ddphi += ddphi_rb;
Mark Friedrichs's avatar
Mark Friedrichs committed
724

Mark Friedrichs's avatar
Mark Friedrichs committed
725
726
 fi = (-ddphi * invlij * invsintheta1 * invsintheta1 ) * m;
 fl = ( ddphi * invlkl * invsintheta2 * invsintheta2 ) * n;
Mark Friedrichs's avatar
Mark Friedrichs committed
727
728


Mark Friedrichs's avatar
Mark Friedrichs committed
729
730
731
 u = rij_d_ukj * invlkj * fi;
 v = ukj_d_rkl * invlkj * fl;
 s = u - v;
Mark Friedrichs's avatar
Mark Friedrichs committed
732

Mark Friedrichs's avatar
Mark Friedrichs committed
733
734
 fj = s - fi;
 fk = -(s + fl);
Mark Friedrichs's avatar
Mark Friedrichs committed
735
736
737
738
739





Mark Friedrichs's avatar
Mark Friedrichs committed
740
741
742
 fs = -parm2.y * ( theta1 - parm2.x );
 st = fs * invsintheta1;
 st = clamp( st, -100000.0f, 100000.0f );
Mark Friedrichs's avatar
Mark Friedrichs committed
743

Mark Friedrichs's avatar
Mark Friedrichs committed
744
 sth = st * costheta1;
Mark Friedrichs's avatar
Mark Friedrichs committed
745

Mark Friedrichs's avatar
Mark Friedrichs committed
746
747
748
 cik = st * invlkj * invlij;
 cii = sth * invlij;
 ckk = sth * invlkj;
Mark Friedrichs's avatar
Mark Friedrichs committed
749

Mark Friedrichs's avatar
Mark Friedrichs committed
750
751
752
 fi_ang = -( cik * rkj - cii * uij );
 fk_ang = -( cik * rij - ckk * ukj );
 fj_ang = -fi_ang - fk_ang;
Mark Friedrichs's avatar
Mark Friedrichs committed
753

Mark Friedrichs's avatar
Mark Friedrichs committed
754
755
756
757
758
759
 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 );
Mark Friedrichs's avatar
Mark Friedrichs committed
760

Mark Friedrichs's avatar
Mark Friedrichs committed
761
 sth = st * costheta2;
Mark Friedrichs's avatar
Mark Friedrichs committed
762

Mark Friedrichs's avatar
Mark Friedrichs committed
763
764
765
 cik = st * invlkj * invlkl;
 cii = sth * invlkj;
 ckk = sth * invlkl;
Mark Friedrichs's avatar
Mark Friedrichs committed
766

Mark Friedrichs's avatar
Mark Friedrichs committed
767
768
769
 fi_ang = ( cik * rkl - cii * ukj );
 fk_ang = ( cik * rkj - ckk * ukl );
 fj_ang = -fi_ang - fk_ang;
Mark Friedrichs's avatar
Mark Friedrichs committed
770

Mark Friedrichs's avatar
Mark Friedrichs committed
771
772
773
 fj += fi_ang;
 fk += fj_ang;
 fl += fk_ang;
Mark Friedrichs's avatar
Mark Friedrichs committed
774
775


Mark Friedrichs's avatar
Mark Friedrichs committed
776
777
778
 fi_bond = -parm3.y * ( 1.0f - parm3.x * invlij ) * rij;
 fi += fi_bond;
 fj += -fi_bond;
Mark Friedrichs's avatar
Mark Friedrichs committed
779
780


Mark Friedrichs's avatar
Mark Friedrichs committed
781
782
783
 fi_bond = parm3.w * ( 1.0f - parm3.z * invlkj ) * rkj;
 fj += fi_bond;
 fk += -fi_bond;
Mark Friedrichs's avatar
Mark Friedrichs committed
784
785


Mark Friedrichs's avatar
Mark Friedrichs committed
786
787
788
789
790
791
792
793
794
795
 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 );
  fs = scalar_force_single_CDLJ( qq, epsfac, parm4.z, parm4.w, r2, nbparams );
  fi_pair = fs * ril;
  fi += fi_pair;
  fl -= fi_pair;
Mark Friedrichs's avatar
Mark Friedrichs committed
796
797
798
 }

}
Mark Friedrichs's avatar
Mark Friedrichs committed
799