29 double OHbond = 0.9572;
30 double HOHangle = 109.47*
M_PI/180.0;
31 char resname[12] =
"HOH";
32 char atomname[12] =
"O";
40 strcpy(atomname,
"O");
48 strcpy(atomname,
"HO1");
54 H1vec[0] = random()/rand_max - 0.5;
55 H1vec[1] = random()/rand_max - 0.5;
56 H1vec[2] = random()/rand_max - 0.5;
58 atom->
coord = (H1vec * OHbond) + Ocoord;
60 strcpy(atomname,
"HO2");
66 H2vec[0] = random()/rand_max - 0.5;
67 H2vec[1] = random()/rand_max - 0.5;
68 H2vec[2] = random()/rand_max - 0.5;
71 H2vec = H1vec.
cross(H2vec);
74 atom->
coord = (H2vec * OHbond) + Ocoord;
92 cerr <<
"Error: A box size must be specified!" << endl;
106 interval[1] = interval[0]*sqrt(3.0)/2.0;
107 interval[2] = interval[0]*sqrt(2.0/3.0);
110 size[0] = interval[0]*((int) (size[0]/interval[0])) + 0.001;
111 size[1] = interval[1]*((int) (size[1]/interval[1])) + 0.001;
112 size[2] = interval[2]*((int) (size[2]/interval[2])) + 0.001;
114 double volume = size.volume();
115 long n = (long) (
volume*0.03346);
119 char watername[20] =
"A";
122 cout <<
"Generating regular water" << endl;
125 cout <<
"Volume: " << size <<
" = " <<
volume <<
" A3" << endl;
126 cout <<
"Interval between molecules: " << interval <<
" A" << endl;
127 cout <<
"Estimated number of waters: " << n << endl << endl;
130 if ( molgroup->
mol )
for ( mol = molgroup->
mol; mol->
next; mol = mol->
next ) ;
133 for ( z=interval[2]/2; z<size[2]; z+=interval[2] ) {
134 if ( type == 3 ) start[1] = 1 - start[1];
136 for ( y=interval[1]/2+start[1]*interval[0]/(2*sqrt(3.0)); y<size[1]; y+=interval[1] ) {
137 if ( type == 3 ) start[0] = 1 - start[0];
138 for ( x=(2-start[0])*interval[0]/2; x<size[0]; x+=interval[0] ) {
144 if ( !molgroup->
mol ) molgroup->
mol = mol;
147 if ( c > 90 ) c = 65;
154 molgroup->
box[0] = molgroup->
max[0] + interval[0]/2;
155 molgroup->
box[1] = molgroup->
max[1] + interval[1]/2;
156 molgroup->
box[2] = molgroup->
max[2] + interval[2]/2;
158 molgroup->
box = size;
163 cout <<
"Number of waters: " << n << endl;
164 cout <<
"Volume: " << molgroup->
box <<
" = " <<
volume <<
" A3" << endl;
165 cout <<
"Density: " << n*1.0/
volume <<
166 " molecules/A3 (" << n/(
volume*0.03346) <<
")" << endl << endl;
183 if ( size.
volume() < 1 ) {
184 cerr <<
"Error: A box size must be specified!" << endl;
195 long n = (long) (
volume*0.03346);
201 char watername[20] =
"A";
204 cout <<
"Generating random water" << endl;
207 cout <<
"Volume: " << size <<
" = " <<
volume <<
" A3" << endl;
208 cout <<
"Number of waters: " << n << endl << endl;
213 if ( molgroup->
mol )
for ( mol = molgroup->
mol; mol->
next; mol = mol->
next ) ;
215 for ( i=0; i<n; i++ ) {
217 Ocoord[0] = size[0]*random()/rand_max;
218 Ocoord[1] = size[1]*random()/rand_max;
219 Ocoord[2] = size[2]*random()/rand_max;
221 if ( !molgroup->
mol ) molgroup->
mol = mol;
222 for ( atom = mol->
res->
atom; atom; atom = atom->
next )
225 if ( c > 90 ) c = 65;
230 molgroup->
box = size;
235 cout <<
"Number of waters: " << n << endl;
236 cout <<
"Volume: " << molgroup->
box <<
" = " <<
volume <<
" A3" << endl;
237 cout <<
"Density: " << n*1.0/
volume <<
238 " molecules/A3 (" << n/(
volume*0.03346) <<
")" << endl << endl;
256 if ( molgroup->
bond ) {
257 if (
verbose ) cerr <<
"Warning: Deleting original bond list!" << endl;
264 Bbond* bondlist = NULL;
266 double OHbond = 0.9572;
269 for ( nbond = 0, mol = molgroup->
mol; mol; mol = mol->
next ) {
272 if ( bond ) bond =
bond_add(&bond, atom, atom->
next, OHbond, 1);
273 else bond =
bond_add(&bondlist, atom, atom->
next, OHbond, 1);
279 cout <<
"Number of bonds generated: " << nbond << endl;
281 molgroup->
bond = bondlist;
297 double OHangle = 109.47*
M_PI/180.0;
300 molgroup->
angle = NULL;
302 for ( nangle = 0, mol = molgroup->
mol; mol; mol = mol->
next ) {
306 if ( !molgroup->
angle ) molgroup->
angle = angle;
311 cout <<
"Number of angles generated: " << nangle << endl;
313 return molgroup->
angle;
325 int i, ii, j, t, x, y, z, xx, yy, zz, ix, iy, iz;
330 (
int) (box[1]/sampling[1] + 0.001), (
int) (box[2]/sampling[2] + 0.001));
332 for ( i=0; i<3; i++ ) sampling[i] = box[i]/size[i] + 0.001;
338 Latom *latom, *latom2;
340 double mult = 1.0/interval;
341 int n = (int) (mult*cutoff);
342 int* rdf =
new int[n*3];
343 for ( i=0; i<n*3; i++ ) rdf[i] = 0;
345 for ( i=z=0; z<size[2]; z++ ) {
346 for ( y=0; y<size[1]; y++ ) {
347 for ( x=0; x<size[0]; x++, i++ ) {
348 for ( latom = alist[i]; latom; latom = latom->
next ) {
349 for ( zz=z-1; zz<=z+1; zz++ ) {
351 if ( iz < 0 ) iz += size[2];
352 if ( iz >= size[2]) iz -= size[2];
353 for ( yy=y-1; yy<=y+1; yy++ ) {
355 if ( iy < 0 ) iy += size[1];
356 if ( iy >= size[1] ) iy -= size[1];
357 for ( xx=x-1; xx<=x+1; xx++ ) {
359 if ( ix < 0 ) ix += size[0];
360 if ( ix >= size[0] ) ix -= size[0];
361 ii = (iz*size[1] + iy)*size[0] + ix;
362 for ( latom2 = alist[ii]; latom2; latom2 = latom2->
next )
363 if ( latom2->
atom != latom->
atom ) {
366 if ( dist < cutoff ) {
367 j = (int) (mult*dist + 0.5);
369 if ( latom->
atom->
el[0] ==
'H' && latom2->
atom->
el[0] ==
'H' ) t = 0;
370 else if ( latom->
atom->
el[0] ==
'H' || latom2->
atom->
el[0] ==
'H' ) t = 1;
384 for ( i=0; i<size.volume(); i++ )
kill_list((
char *) alist[i],
sizeof(
Latom));
388 for ( nwater = 0, mol = molgroup->
mol; mol; mol = mol->
next )
389 for ( res = mol->
res; res; res = res->
next ) nwater++;
391 cout <<
"Calculating the radial distribution function:" << endl;
393 double vol_per_water = 180/6.022;
396 long ndist[3] = {0,0,0};
397 double rdftot[3] = {0,0,0};
398 double norm[3], vol_surface;
399 double vol_surf_fac = (4.0/3.0)*
M_PI*interval*interval*interval;
400 cout << endl <<
"r(A)\tH-H\tRDF(HH)\tH-O\tRDF(HO)\tO-O\tRDF(OO)" << endl;
401 for ( i=1; i<n; i++ ) {
403 vol_surface = vol_surf_fac*(3*i*i + 0.25);
404 norm[2] = vol_per_water/(vol_surface*2*nwater);
405 norm[0] = norm[1] = 0.25*norm[2];
406 for ( t=0; t<3; t++ ) {
407 cout <<
tab << rdf[3*i+t] <<
tab << rdf[3*i+t]*norm[t];
408 ndist[t] += rdf[3*i+t];
409 rdftot[t] += rdf[3*i+t]*norm[t];
413 cout <<
"Number of distances included = " << ndist[0] <<
" " << ndist[1] <<
" " << ndist[2] << endl;
414 cout <<
"RDF sum = " << rdftot[0] <<
" " << rdftot[1] <<
" " << rdftot[2] << endl;
415 cout <<
"RDF avg = " << rdftot[0]/n <<
" " << rdftot[1]/n <<
" " << rdftot[2]/n << endl << endl;