40 if ( max_iter < 1 )
return 1e10;
49 double E(0), dE(0), vel;
52 double minvel = -velocitylimit, maxvel = velocitylimit;
57 error_show(
"Error in md_leapfrog: No bond list!", __FILE__, __LINE__);
61 if ( !anglelist && md->
Kangle ) {
62 error_show(
"Error in md_leapfrog: No angle list!", __FILE__, __LINE__);
68 molgroup->
box = molgroup->
max;
69 molgroup->
box[0] += 1.7;
70 molgroup->
box[1] += 1.7;
71 molgroup->
box[2] += 1.7;
76 cout <<
"Molecular dynamics using the leapfrog integrator:" << endl;
77 cout <<
"Periodic box: " << molgroup->
box <<
" " <<
volume <<
" A3" << endl;
78 cout <<
"Maximum iterations: " << max_iter << endl;
79 cout <<
"Time step: " << timestep << endl;
80 cout <<
"Kfriction: " << Kfriction << endl;
81 cout <<
"Kbond: " << md->
Kbond << endl;
82 cout <<
"Kangle: " << md->
Kangle << endl;
83 cout <<
"Kelectrostatic: " << md->
Kelec << endl;
84 cout <<
"KVanderWaals: " << md->
Kvdw << endl;
85 cout <<
"Non-bonded cutoff distance: " << md->
cutoff <<
" A" << endl;
87 cout << endl <<
"Cycle\tEbond\tEangle\tEelec\tEvdw\tEpoint\tEnergy\tdE\tEkin" << endl;
91 while ( cycle < max_iter &&
isfinite(E) ) {
115 if ( dE <= 0 ) Kfriction = md->
Kfriction;
119 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
120 for( res = mol->
res; res; res = res->
next ) {
121 for ( atom = res->
atom; atom; atom = atom->
next ) {
122 atom->
vel += atom->
F * (timestep/atom->
mass);
123 atom->
vel *= Kfriction;
125 atom->
coord += atom->
vel * timestep;
141 cout << cycle <<
tab << E << endl;
144 cerr << endl <<
"***** Warning: The system exploded!!! *****" << endl << endl;
167 for ( mol = molgroup->
mol; mol; mol = mol->
next )
168 for( res = mol->
res; res; res = res->
next )
192 if ( Kbond <= 0 )
return 0;
194 double dist, dev, fac, energy(0);
199 for ( bond = bondlist; bond; bond = bond->
next ) {
205 dev = dist - bond->
l;
206 energy += Kbond*dev*dev;
207 fac = -2*Kbond*dev/dist;
235 if ( Kangle <= 0 )
return 0;
237 double d1len2, d2len2, dot, fac, dcosa, c11, c12, c22, energy(0);
241 for ( angle = molgroup->
angle; angle; angle = angle->
next ) {
252 fac = 1/sqrt(d1len2*d2len2);
253 dcosa = cos(angle->
a) - dot*fac;
254 energy += Kangle*dcosa*dcosa;
255 c12 = 2*Kangle*fac*dcosa;
256 c11 = c12*dot/d1len2;
257 c22 = c12*dot/d2len2;
258 Force = (d1 * c11) - (d2 * c12);
260 Force = (d2 * c22) - (d1 * c12);
287 if ( md->
Kvdw <= 0 && md->
Kelec <= 0 )
return 0;
290 long i, ii, x, y, z, xx, yy, zz, ix, iy, iz;
294 (
int) (box[1]/sampling[1] + 0.001), (
int) (box[2]/sampling[2] + 0.001));
296 for ( i=0; i<3; i++ ) sampling[i] = box[i]/size[i] + 0.001;
297 long boxsize = (long) size.
volume();
298 Latom *latom, *latom2;
304 for ( z=0; z<size[2]; z++ ) {
305 for ( y=0; y<size[1]; y++ ) {
306 for ( x=0; x<size[0]; x++ ) {
307 i = (z*size[1] + y)*size[0] + x;
308 for ( latom = alist[i]; latom; latom = latom->
next ) {
309 for ( zz=z-1; zz<=z+1; zz++ ) {
311 if ( iz < 0 ) iz += size[2];
312 if ( iz >= size[2]) iz -= size[2];
313 for ( yy=y-1; yy<=y+1; yy++ ) {
315 if ( iy < 0 ) iy += size[1];
316 if ( iy >= size[1] ) iy -= size[1];
317 for ( xx=x-1; xx<=x+1; xx++ ) {
319 if ( ix < 0 ) ix += size[0];
320 if ( ix >= size[0] ) ix -= size[0];
321 ii = (iz*size[1] + iy)*size[0] + ix;
322 for ( latom2 = alist[ii]; latom2; latom2 = latom2->
next ) {
324 if ( latom2->
atom == latom->
atom ) dononbond = 0;
325 else if ( latom2->
atom->
next == latom->
atom ) dononbond = 0;
326 else if ( latom2->
atom == latom->
atom->
next ) dononbond = 0;
344 for ( i=0; i<boxsize; i++ )
kill_list((
char *) alist[i],
sizeof(
Latom));
372 if ( md->
Kvdw <= 0 && md->
Kelec <= 0 )
return 0;
375 double rd2, rd6, rd12, dist2, invdist2, fac;
383 if ( dist2 < md->cutoff*md->
cutoff ) {
392 fac = -md->
Kvdw*(rd12 - rd6)*invdist2;
430 if ( Kpoint <= 0 )
return 0;
432 double dist, en1, energy = 0;
438 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
439 for( res = mol->
res; res; res = res->
next ) {
440 for ( atom = res->
atom; atom; atom = atom->
next ) {
441 dir = atom->
coord - point;
443 en1 = Kpoint*exp(-decay*dist);
445 atom->
F += dir * (decay*en1/dist);