kshakeh.br 17.2 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
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

/*
 * This kernel constrains bonds involving hydrogen using an unrolled
 * shake implementation. We assume that a heavy atom can have at most 
 * 3 hydrogens attached. The hydrogens are expected to be identical
 *
 * For atoms that have ewer than 3 hydrogens
 *
 * Also we don't check the constraints!
 *  
 * We do a fixed number of iterations without checking for convergence
 * to avoid stalling
 * *************************************************************/

/*
kernel void
kshakeh(
		float nit,      //number of iterations
		float strwidth, //stream width of posq
		float invmH,    //inverse mass of hydrogen
		float omega,    //parameter from gromacs, possibly unused
		float4 atoms<>, //heavy0, h1, h2, h3
		float4 posq[][], //positions before update
		float4 posqp[][], //positions after update
		float4 params<>, // (1/m0, mu/2, blensq, 0.0f )
		out float4 cposq0<>, //constrained position for heavy atom
		out float4 cposq1<>, //ditto for h1
		out float4 cposq2<>, //ditto for h2
		out float4 cposq3<> //ditto for h3
		) {
	float2 ai, aj1, aj2, aj3; //2d indices, can be precalc.
	float i; //iteration count
	float3 xi, xj1, xj2, xj3; //coordinates
	float3 xpi, xpj1, xpj2, xpj3; //coordinates
	float3 rij1, rij2, rij3, rpij, dr;
	float rpsqij, rrpr, acor;
	float mask2, mask3;
	float diff;
	
	ai.y  = floor( atoms.x / strwidth );
	ai.x  = atoms.x - ai.y * strwidth;

	aj1.y = floor( atoms.y / strwidth );
	aj1.x = atoms.y - aj1.y * strwidth;

	//If further hydrogens are absent,
	//just set to the coordinates of the first
	//so we don't have any junk memory accesses
	//or nans/infs in the calcs.	
	if ( atoms.z > -0.5f ) {
		aj2.y = floor( atoms.z / strwidth );
		aj2.x = atoms.z - aj2.y * strwidth;
		mask2 = 1.0f;
	}
	else {
		aj2 = aj1; 
		mask2 = 0.0f;
	}

	if ( atoms.w > -0.5f ) {	
		aj3.y = floor( atoms.w / strwidth );
		aj3.x = atoms.w - aj3.y * strwidth;
		mask3 = 1.0f;
	}
	else {
		aj3 = aj1;
		mask3 = 0.0f;
	}


	cposq0 = posq[ai];
	cposq1 = posq[aj1];
	cposq2 = posq[aj2];
	cposq3 = posq[aj3];
	
	
	xi  = cposq0.xyz;
	xj1 = cposq1.xyz;
	xj2 = cposq2.xyz;
	xj3 = cposq3.xyz;
	
	rij1 = xi - xj1;
	rij2 = xi - xj2;
	rij3 = xi - xj3;

	xpi  = posqp[ai].xyz;
	xpj1 = posqp[aj1].xyz;
	xpj2 = posqp[aj2].xyz;
	xpj3 = posqp[aj3].xyz;

	i = 0.0f;
	while ( i < 15.0f ) {
		//First hydrogen
		rpij   = xpi - xpj1;
		rpsqij = dot( rpij, rpij );
		rrpr   = dot( rij1, rpij );
		//for debugging only
		diff = abs( params.z - rpsqij ) / (params.z * 2 * 1e-4 );
		if ( diff < 1.0f )
			acor = 0.0f;
		else
			//params.y = mu/2, params.z = blen*blen
			acor = omega * ( params.z - rpsqij ) * params.y / rrpr ;
		dr   = rij1 * acor;
		xpi  += dr * params.x;
		xpj1 -= dr * invmH;

		//Second hydrogen
		rpij   = xpi - xpj2;
		rpsqij = dot( rpij, rpij );
		rrpr   = dot( rij2, rpij );
		//for debugging only
		diff = abs( params.z - rpsqij ) / (params.z * 2 * 1e-4 );
		if ( diff < 1.0f )
			acor = 0.0f;
		else
			//params.y = mu/2, params.z = blen*blen
			acor = mask2 * omega * ( params.z - rpsqij ) * params.y / rrpr ;
		dr   = rij2 * acor;
		xpi  += dr * params.x;
		xpj2 -= dr * invmH;

		//Third hydrogen
		rpij   = xpi - xpj3;
		rpsqij = dot( rpij, rpij );
		rrpr   = dot( rij3, rpij );
		//for debugging only
		diff = abs( params.z - rpsqij ) / (params.z * 2 * 1e-4 );
		if ( diff < 1.0f )
			acor = 0.0f;
		else
			//params.y = mu/2, params.z = blen*blen
			acor = mask3 * omega * ( params.z - rpsqij ) * params.y / rrpr ;
		dr   = rij3 * acor;
		xpi  += dr * params.x;
		xpj3 -= dr * invmH;
		
		i += 1.0f;
	}

	cposq0.xyz = xpi;
	cposq1.xyz = xpj1;
	cposq2.xyz = xpj2;
	cposq3.xyz = xpj3;
} */

/*Applies the updated positions
 *Each atom occurs at one and only one position
 * */
/*
kernel void kshakeh_update( 
		float strwidth, //width of cposq streams
		float2 invmap<>,    //shakeh inverse map
		float4 posq<>,     //untouched positions
		float4 cposq0[][], //constrained position for heavy atom
		float4 cposq1[][], //ditto for h1
		float4 cposq2[][], //ditto for h2
		float4 cposq3[][], //ditto for h3
		out float4 oposq<> //updated positions
		){
	float2 atom;
	
	atom.y = floor( invmap.x / strwidth );
	atom.x = invmap.x - atom.y * strwidth;
	
	if ( invmap.y < 0 )
		oposq = posq;
	else if ( invmap.y < 0.5f ) 
		oposq = cposq0[ atom ];
	else if ( invmap.y < 1.5f )
		oposq = cposq1[ atom ];
	else if ( invmap.y < 2.5f )
		oposq = cposq2[ atom ];
	else if ( invmap.y < 3.5f )
		oposq = cposq3[ atom ];
} */

/* Fix for precision of terms first order in dt
 * To be used with corresponding update kernels
 * The input posqp is now changes to posq rather than
 * posq+changes
 * */
kernel void
kshakeh_fix1(
		float nit,      //number of iterations
		float strwidth, //stream width of posq
		float invmH,    //inverse mass of hydrogen
		float omega,    //parameter from gromacs, possibly unused
		float4 atoms<>, //heavy0, h1, h2, h3
221
222
		float3 posq[][], //positions before update
		float3 posqp[][], //changes to positions
Mark Friedrichs's avatar
Mark Friedrichs committed
223
		float4 params<>, // (1/m0, mu/2, blensq, 0.0f )
224
225
226
227
		out float3 cposq0<>, //constrained position for heavy atom
		out float3 cposq1<>, //ditto for h1
		out float3 cposq2<>, //ditto for h2
		out float3 cposq3<> //ditto for h3
Mark Friedrichs's avatar
Mark Friedrichs committed
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
274
275
276
277
278
		) {
	float2 ai, aj1, aj2, aj3; //2d indices, can be precalc.
	float i; //iteration count
	float3 xi, xj1, xj2, xj3; //coordinates
	float3 xpi, xpj1, xpj2, xpj3; //coordinates
	float3 rij1, rij2, rij3, rpij, dr;
	float rpsqij, rrpr, acor;
	float mask2, mask3;
	float diff;
	float rij1sq, rij2sq, rij3sq;
	float ld1, ld2, ld3;
	
	// ai.y  = floor( atoms.x / strwidth );
   ai.y  = round( (atoms.x - fmod( atoms.x, strwidth ))/strwidth );
	ai.x  = atoms.x - ai.y * strwidth;

	// aj1.y = floor( atoms.y / strwidth );
   aj1.y  = round( (atoms.y - fmod( atoms.y, strwidth ))/strwidth );
	aj1.x = atoms.y - aj1.y * strwidth;

	//If further hydrogens are absent,
	//just set to the coordinates of the first
	//so we don't have any junk memory accesses
	//or nans/infs in the calcs.	
	if ( atoms.z > -0.5f ) {
		// aj2.y = floor( atoms.z / strwidth );
		aj2.y = round( (atoms.z - fmod( atoms.z, strwidth ))/strwidth );
		aj2.x = atoms.z - aj2.y * strwidth;
		mask2 = 1.0f;
	}
	else {
		aj2 = aj1; 
		mask2 = 0.0f;
	}

	if ( atoms.w > -0.5f ) {	
		// aj3.y = floor( atoms.w / strwidth );
		aj3.y = round( (atoms.w - fmod( atoms.w, strwidth ))/strwidth );
		aj3.x = atoms.w - aj3.y * strwidth;
		mask3 = 1.0f;
	}
	else {
		aj3 = aj1;
		mask3 = 0.0f;
	}

	cposq0 = posq[ai];
	cposq1 = posq[aj1];
	cposq2 = posq[aj2];
	cposq3 = posq[aj3];
	
279
280
281
282
	xi  = cposq0;
	xj1 = cposq1;
	xj2 = cposq2;
	xj3 = cposq3;
Mark Friedrichs's avatar
Mark Friedrichs committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
	
	rij1 = xi - xj1;
	rij2 = xi - xj2;
	rij3 = xi - xj3;

	rij1sq = dot( rij1, rij1 );
	rij2sq = dot( rij2, rij2 );
	rij3sq = dot( rij3, rij3 );

	ld1 = params.z - rij1sq;
	ld2 = params.z - rij2sq;
	ld3 = params.z - rij3sq;

/*
297
298
299
300
	xpi  = posqp[ai];
	xpj1 = posqp[aj1];
	xpj2 = posqp[aj2];
	xpj3 = posqp[aj3];
Mark Friedrichs's avatar
Mark Friedrichs committed
301
302
303
*/


304
305
306
307
	xpi  = posqp[ai]   - xi;
	xpj1 = posqp[aj1]  - xj1;
	xpj2 = posqp[aj2]  - xj2;
	xpj3 = posqp[aj3]  - xj3;
Mark Friedrichs's avatar
Mark Friedrichs committed
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
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


// XXX
	// cposq0 = posqp[ai];
	// cposq1 = posqp[aj1];
	// cposq2 = posqp[aj2];
	// cposq3 = posqp[aj3];
// OK
// XXX
	


	i = 0.0f;
	while ( i < 15.0f ) {
		//First hydrogen
		rpij   = xpi - xpj1; //This is really rpij - rij
		rpsqij = dot( rpij, rpij ); //This is really deltar ^ 2
		rrpr   = dot( rij1, rpij ); //This is r.deltar
		//for debugging only
		//params.y = mu/2, params.z = blen*blen
		diff = abs( ld1 - 2 * rrpr - rpsqij ) / (params.z * 2 * 1e-4f );
		if ( diff < 1.0f )
		  acor = 0.0f;
		 else
			acor = omega * ( ld1 - 2 * rrpr - rpsqij ) * params.y / ( rrpr + rij1sq ) ;
		dr   = rij1 * acor;
		xpi  += dr * params.x;
		xpj1 -= dr * invmH;

		//Second hydrogen
		rpij   = xpi - xpj2;
		rpsqij = dot( rpij, rpij );
		rrpr   = dot( rij2, rpij );
		//for debugging only
		diff = abs( ld2 - 2 * rrpr - rpsqij ) / (params.z * 2 * 1e-4f );
		if ( diff < 1.0f )
			acor = 0.0f;
		else
			acor = mask2 * omega * ( ld2 - 2 * rrpr - rpsqij ) * params.y / ( rrpr + rij2sq ) ;
		dr   = rij2 * acor;
		xpi  += dr * params.x;
		xpj2 -= dr * invmH;

		//Third hydrogen
		rpij   = xpi - xpj3;
		rpsqij = dot( rpij, rpij );
		rrpr   = dot( rij3, rpij );
		diff = abs( ld3 - 2 * rrpr - rpsqij ) / (params.z * 2 * 1e-4f );
		// for debugging only
		if ( diff < 1.0f )
			 acor = 0.0f;
		else
			acor = mask3 * omega * ( ld3 - 2 * rrpr - rpsqij ) * params.y / ( rrpr + rij3sq ) ;
		dr   = rij3 * acor;
		xpi  += dr * params.x;
		xpj3 -= dr * invmH;
		
		i += 1.0f;
	}

	//Output modified delta's
369
370
371
372
	cposq0 = xpi;
	cposq1 = xpj1;
	cposq2 = xpj2;
	cposq3 = xpj3;
Mark Friedrichs's avatar
Mark Friedrichs committed
373
374
375
376
377
378
379
380
381
382

}

kernel void
kshakeh_fix2(
		float nit,      //number of iterations
		float strwidth, //stream width of posq
		float invmH,    //inverse mass of hydrogen
		float omega,    //parameter from gromacs, possibly unused
		float4 atoms<>, //heavy0, h1, h2, h3
383
384
		float3 posq[][], //positions before update
		float3 posqp[][], //changes to positions
Mark Friedrichs's avatar
Mark Friedrichs committed
385
		float4 params<>, // (1/m0, mu/2, blensq, 0.0f )
386
387
388
389
		out float3 cposq0<>, //constrained position for heavy atom
		out float3 cposq1<>, //ditto for h1
		out float3 cposq2<>, //ditto for h2
		out float3 cposq3<> //ditto for h3
Mark Friedrichs's avatar
Mark Friedrichs committed
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
		) {
	float2 ai, aj1, aj2, aj3; //2d indices, can be precalc.
	float i; //iteration count
	float3 xi, xj1, xj2, xj3; //coordinates
	float3 xpi, xpj1, xpj2, xpj3; //coordinates
	float3 rij1, rij2, rij3, rpij, dr;
	float rpsqij, rrpr, acor;
	float mask2, mask3;
	float diff;
	float rij1sq, rij2sq, rij3sq;
	float ld1, ld2, ld3;
	
	// ai.y  = floor( atoms.x / strwidth );
   ai.y  = round( (atoms.x - fmod( atoms.x, strwidth ))/strwidth );
	ai.x  = atoms.x - ai.y * strwidth;

	// aj1.y = floor( atoms.y / strwidth );
   aj1.y  = round( (atoms.y - fmod( atoms.y, strwidth ))/strwidth );
	aj1.x = atoms.y - aj1.y * strwidth;

	//If further hydrogens are absent,
	//just set to the coordinates of the first
	//so we don't have any junk memory accesses
	//or nans/infs in the calcs.	
	if ( atoms.z > -0.5f ) {
		// aj2.y = floor( atoms.z / strwidth );
		aj2.y = round( (atoms.z - fmod( atoms.z, strwidth ))/strwidth );
		aj2.x = atoms.z - aj2.y * strwidth;
		mask2 = 1.0f;
	}
	else {
		aj2 = aj1; 
		mask2 = 0.0f;
	}

	if ( atoms.w > -0.5f ) {	
		// aj3.y = floor( atoms.w / strwidth );
		aj3.y = round( (atoms.w - fmod( atoms.w, strwidth ))/strwidth );
		aj3.x = atoms.w - aj3.y * strwidth;
		mask3 = 1.0f;
	}
	else {
		aj3 = aj1;
		mask3 = 0.0f;
	}


	cposq0 = posq[ai];
	cposq1 = posq[aj1];
	cposq2 = posq[aj2];
	cposq3 = posq[aj3];
	
442
443
444
445
	xi  = cposq0;
	xj1 = cposq1;
	xj2 = cposq2;
	xj3 = cposq3;
Mark Friedrichs's avatar
Mark Friedrichs committed
446
447
448
449
450
451
452
453
454
455
456
457
458
	
	rij1 = xi - xj1;
	rij2 = xi - xj2;
	rij3 = xi - xj3;

	rij1sq = dot( rij1, rij1 );
	rij2sq = dot( rij2, rij2 );
	rij3sq = dot( rij3, rij3 );

	ld1 = params.z - rij1sq;
	ld2 = params.z - rij2sq;
	ld3 = params.z - rij3sq;

459
460
461
462
	xpi  = posqp[ai];
	xpj1 = posqp[aj1];
	xpj2 = posqp[aj2];
	xpj3 = posqp[aj3];
Mark Friedrichs's avatar
Mark Friedrichs committed
463
464
465


/*
466
467
468
469
	xpi  = posqp[ai]   - xi;
	xpj1 = posqp[aj1]  - xj1;
	xpj2 = posqp[aj2]  - xj2;
	xpj3 = posqp[aj3]  - xj3;
Mark Friedrichs's avatar
Mark Friedrichs committed
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531

*/

// XXX
	// cposq0 = posqp[ai];
	// cposq1 = posqp[aj1];
	// cposq2 = posqp[aj2];
	// cposq3 = posqp[aj3];
// OK
// XXX
	


	i = 0.0f;
	while ( i < 15.0f ) {
		//First hydrogen
		rpij   = xpi - xpj1; //This is really rpij - rij
		rpsqij = dot( rpij, rpij ); //This is really deltar ^ 2
		rrpr   = dot( rij1, rpij ); //This is r.deltar
		//for debugging only
		//params.y = mu/2, params.z = blen*blen
		diff = abs( ld1 - 2 * rrpr - rpsqij ) / (params.z * 2 * 1e-4f );
		if ( diff < 1.0f )
		  acor = 0.0f;
		 else
			acor = omega * ( ld1 - 2 * rrpr - rpsqij ) * params.y / ( rrpr + rij1sq ) ;
		dr   = rij1 * acor;
		xpi  += dr * params.x;
		xpj1 -= dr * invmH;

		//Second hydrogen
		rpij   = xpi - xpj2;
		rpsqij = dot( rpij, rpij );
		rrpr   = dot( rij2, rpij );
		//for debugging only
		diff = abs( ld2 - 2 * rrpr - rpsqij ) / (params.z * 2 * 1e-4f );
		if ( diff < 1.0f )
			acor = 0.0f;
		else
			acor = mask2 * omega * ( ld2 - 2 * rrpr - rpsqij ) * params.y / ( rrpr + rij2sq ) ;
		dr   = rij2 * acor;
		xpi  += dr * params.x;
		xpj2 -= dr * invmH;

		//Third hydrogen
		rpij   = xpi - xpj3;
		rpsqij = dot( rpij, rpij );
		rrpr   = dot( rij3, rpij );
		diff = abs( ld3 - 2 * rrpr - rpsqij ) / (params.z * 2 * 1e-4f );
		// for debugging only
		if ( diff < 1.0f )
			 acor = 0.0f;
		else
			acor = mask3 * omega * ( ld3 - 2 * rrpr - rpsqij ) * params.y / ( rrpr + rij3sq ) ;
		dr   = rij3 * acor;
		xpi  += dr * params.x;
		xpj3 -= dr * invmH;
		
		i += 1.0f;
	}

	//Output modified delta's
532
533
534
535
	cposq0 = xpi;
	cposq1 = xpj1;
	cposq2 = xpj2;
	cposq3 = xpj3;
Mark Friedrichs's avatar
Mark Friedrichs committed
536
537
538
539
540
541
542
543
544

}

/*Applies the updated delta's
 *Each atom occurs at one and only one position
 * */
kernel void kshakeh_update1_fix1Old( 
		float strwidth, //width of cposq streams
		float2 invmap<>,    //shakeh inverse map
545
546
547
548
549
550
		float3 posq<>,     //constrained deltas
		float3 cposq0[][], //constrained delta for heavy atom
		float3 cposq1[][], //ditto for h1
		float3 cposq2[][], //ditto for h2
		float3 cposq3[][], //ditto for h3
		out float3 oposq<> //updated deltas
Mark Friedrichs's avatar
Mark Friedrichs committed
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
		){
	float2 atom;
	
	//atom.y = floor( invmap.x / strwidth );
   atom.y  = round( (invmap.x - fmod( invmap.x, strwidth ))/strwidth );
	atom.x = invmap.x - atom.y * strwidth;
	
	if ( invmap.y < 0 )
		oposq = posq;
	else if ( invmap.y < 0.5f ) 
		oposq = cposq0[ atom ];
	else if ( invmap.y < 1.5f )
		oposq = cposq1[ atom ];
	else if ( invmap.y < 2.5f )
		oposq = cposq2[ atom ];
	else if ( invmap.y < 3.5f )
		oposq = cposq3[ atom ];
}

kernel void kshakeh_update2_fix1( 
		float strwidth, //width of cposq streams
		float2 invmap<>,    //shakeh inverse map
573
574
575
576
577
578
579
		float3 posq<>,     //old positions
		float3 posqp<>,    //deltas from sd2
		float3 cposq0[][], //constrained delta for heavy atom
		float3 cposq1[][], //ditto for h1
		float3 cposq2[][], //ditto for h2
		float3 cposq3[][], //ditto for h3
		out float3 oposq<> //updated deltas
Mark Friedrichs's avatar
Mark Friedrichs committed
580
581
582
583
584
585
586
587
		){
	float2 atom;
	
	// atom.y = floor( invmap.x / strwidth );
   atom.y  = round( (invmap.x - fmod( invmap.x, strwidth ))/strwidth );
	atom.x = invmap.x - atom.y * strwidth;
	
	if ( invmap.y < 0 ){
588
		oposq = posqp - posq;
Mark Friedrichs's avatar
Mark Friedrichs committed
589
590
591
592
593
594
595
596
597
	} else if ( invmap.y < 0.5f ) 
		oposq = cposq0[ atom ];
	else if ( invmap.y < 1.5f)
		oposq = cposq1[ atom ];
	else if ( invmap.y < 2.5f )
		oposq = cposq2[ atom ];
	else if ( invmap.y < 3.5f )
		oposq = cposq3[ atom ];

598
	oposq += posq;
Mark Friedrichs's avatar
Mark Friedrichs committed
599
600
601
602
603
604
}

kernel void kshakeh_update1_fix1( 
		float strwidth, //width of cposq streams
      float sdFactor,
		float2 invmap<>,    //shakeh inverse map
605
606
		float3 posq<>,     //old positions
		float3 posqp<>,    //deltas from sd2
Mark Friedrichs's avatar
Mark Friedrichs committed
607
		float3 vp<>,    //deltas from sd2
608
609
610
611
612
		float3 cposq0[][], //constrained delta for heavy atom
		float3 cposq1[][], //ditto for h1
		float3 cposq2[][], //ditto for h2
		float3 cposq3[][], //ditto for h3
		out float3 oposq<> //updated deltas
Mark Friedrichs's avatar
Mark Friedrichs committed
613
614
615
616
617
618
619
620
621
622
623
		){
	float2 atom;
	
	// atom.y = floor( invmap.x / strwidth );
   atom.y  = round( (invmap.x - fmod( invmap.x, strwidth ))/strwidth );
	atom.x = invmap.x - atom.y * strwidth;
	
	oposq = posq;
	if ( invmap.y < 0 ){
		oposq = posqp;
	} else if ( invmap.y < 0.5f ) 
624
		oposq += cposq0[ atom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
625
	else if ( invmap.y < 1.5f )
626
		oposq += cposq1[ atom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
627
	else if ( invmap.y < 2.5f )
628
		oposq += cposq2[ atom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
629
	else if ( invmap.y < 3.5f )
630
		oposq += cposq3[ atom ];
Mark Friedrichs's avatar
Mark Friedrichs committed
631
632

}