32 if ( molgroup->
bond ) {
33 if (
verbose ) cerr <<
"Warning: Bond list already defined!" << endl;
34 return molgroup->
bond;
37 int i, j, natom, nbond;
38 double dist, bondlength;
40 Bbond* bondlist = NULL;
46 for ( natom=0, mol = molgroup->
mol; mol; mol = mol->
next )
47 for( res = mol->
res; res; res = res->
next )
48 for ( atom = res->
atom; atom; atom = atom->
next ) natom++;
52 for ( i=0, mol = molgroup->
mol; mol; mol = mol->
next )
53 for( res = mol->
res; res; res = res->
next )
54 for ( atom = res->
atom; atom; atom = atom->
next ) {
60 cout <<
"Generating a bond list for" << natom <<
" atoms" << endl;
61 if ( md->
wrap ) cout <<
"With wrapping" << endl;
64 for ( i=0, nbond=0; i<natom-1; i++ ) {
66 for ( j=i+1; j<natom; j++ ) {
73 if ( dist > 0.5*bondlength && dist < 1.1*bondlength ) {
74 if ( bond ) bond =
bond_add(&bond, atom, atom2, bondlength, 1);
75 else bond =
bond_add(&bondlist, atom, atom2, bondlength, 1);
85 cout <<
"Number of bonds generated: " << nbond << endl << endl;
89 molgroup->
bond = bondlist;
107 if ( molgroup->
bond ) {
108 if (
verbose ) cerr <<
"Warning: Bond list already defined!" << endl;
109 return molgroup->
bond;
112 long natom = 0, nbond = 0;
113 double dist, bondlength;
115 Bbond* bondlist = NULL;
121 for ( natom=0, mol = molgroup->
mol; mol; mol = mol->
next ) {
122 for( res = mol->
res; res; res = res->
next ) {
123 for ( atom = res->
atom; atom->
next; atom = atom->
next ) {
125 for ( atom2 = atom->
next; atom2; atom2 = atom2->
next ) {
131 if ( dist > 0.1*bondlength && dist < 1.1*bondlength ) {
132 if ( bond ) bond =
bond_add(&bond, atom, atom2, bondlength, 1);
133 else bond =
bond_add(&bondlist, atom, atom2, bondlength, 1);
145 cout <<
"Number of bonds generated: " << nbond << endl << endl;
147 molgroup->
bond = bondlist;
164 if ( !bondlist )
return NULL;
168 double* val =
new double[number];
170 Bbond* newbond = NULL, *bond;
172 for ( i=0; i<number; i++ ) {
177 for ( bond = bondlist; bond; bond = bond->
next ) {
178 for ( i=imax=0, max=0; i<number; i++ )
if ( max < val[i] ) {
182 if ( val[imax] > bond->k ) {
184 bondarray[imax] = bond;
188 for ( i=0; i<number; i++ )
if ( bondarray[i] )
189 bond_add(&newbond, bondarray[i]->atom1, bondarray[i]->atom2, bondarray[i]->l, 1);
210 if ( molgroup->
bond ) {
211 if (
verbose ) cerr <<
"Warning: Bond list already defined!" << endl;
212 return molgroup->
bond;
215 double cutoff = md->
cutoff;
217 int i, ii, x, y, z, xx, yy, zz, ix, iy, iz;
221 (
int) (box[1]/sampling[1] + 0.001), (
int) (box[2]/sampling[2] + 0.001));
223 for ( i=0; i<3; i++ ) sampling[i] = box[i]/size[i] + 0.001;
224 long boxsize = (long) size.
volume();
225 double dist, bondlength;
227 Latom *latom, *latom2;
228 Bbond* tbondlist = NULL;
233 cout <<
"Sampling intervals for cutoff " << cutoff <<
": " << sampling << endl;
237 for ( z=0; z<size[2]; z++ ) {
238 for ( y=0; y<size[1]; y++ ) {
239 for ( x=0; x<size[0]; x++ ) {
240 i = (z*size[1] + y)*size[0] + x;
241 tbond = tbondlist = NULL;
242 for ( latom = alist[i]; latom; latom = latom->
next ) {
244 for ( zz=z-1; zz<=z+1; zz++ ) {
246 if ( iz < 0 ) iz += size[2];
247 if ( iz >= size[2]) iz -= size[2];
248 for ( yy=y-1; yy<=y+1; yy++ ) {
250 if ( iy < 0 ) iy += size[1];
251 if ( iy >= size[1] ) iy -= size[1];
252 for ( xx=x-1; xx<=x+1; xx++ ) {
254 if ( ix < 0 ) ix += size[0];
255 if ( ix >= size[0] ) ix -= size[0];
256 ii = (iz*size[1] + iy)*size[0] + ix;
257 for ( latom2 = alist[ii]; latom2; latom2 = latom2->
next ) {
258 atom2 = latom2->
atom;
264 if ( dist > 0.1*bondlength && dist < 1.3*bondlength ) {
265 if ( tbond ) tbond =
bond_add(&tbond, atom, atom2, bondlength, dist);
266 else tbond =
bond_add(&tbondlist, atom, atom2, bondlength, dist);
274 if ( bond ) bond->
next = tbond;
275 else bond = molgroup->
bond = tbond;
276 if ( bond )
for ( ; bond->
next; bond = bond->
next ) ;
282 for ( i=0; i<boxsize; i++ )
kill_list((
char *) alist[i],
sizeof(
Latom));
288 return molgroup->
bond;
306 for ( bond = bondlist; bond; bond = bond->
next, ++n ) {
317 cout <<
"Fraction of bond types found: " << f << endl;
334 cout <<
"Bond#\tAtom1\tAtom2\tLength\tStrength" << endl;
335 for ( nbond=0, bond = molgroup->
bond; bond; bond = bond->
next, nbond++ )
355 cout <<
"Angle#\tAtom1\tAtom2\tAtom3\tAngle\tStrength" << endl;
356 for ( nang=0, angle = molgroup->
angle; angle; angle = angle->
next, nang++ )
379 for ( mol = molgroup->
mol; mol; mol = mol->
next )
380 for ( res = mol->
res; res; res = res->
next )
381 for ( atom = res->
atom; atom; atom = atom->
next )
384 for ( nbond=0, bond = molgroup->
bond; bond; bond = bond->
next, nbond++ ) {
389 cout <<
"Number of bonds: " << nbond << endl;
392 for ( i=0; i<100; i++ ) hist[i] = 0;
394 for ( mol = molgroup->
mol; mol; mol = mol->
next )
395 for ( res = mol->
res; res; res = res->
next )
396 for ( atom = res->
atom; atom; atom = atom->
next )
399 cout <<
"Val\tAtoms\tBonds" << endl;
400 for ( i=0; i<10; i++ ) cout << i <<
tab << hist[i] <<
tab << i*hist[i] << endl;
418 if ( !bondlist )
return NULL;
420 Batom *atom1, *atom2, *atom3;
421 Bbond *bond1, *bond2;
424 double set_angle = 0;
425 int nangle = 0, found;
428 for ( bond1=bondlist; bond1->
next; bond1=bond1->
next ) {
429 for ( bond2=bond1->
next; bond2; bond2=bond2->
next ) {
432 atom1 = bond1->
atom2;
433 atom2 = bond1->
atom1;
434 atom3 = bond2->
atom2;
437 atom1 = bond1->
atom2;
438 atom2 = bond1->
atom1;
439 atom3 = bond2->
atom1;
442 atom1 = bond1->
atom1;
443 atom2 = bond1->
atom2;
444 atom3 = bond2->
atom2;
447 atom1 = bond1->
atom1;
448 atom2 = bond1->
atom2;
449 atom3 = bond2->
atom1;
457 set_angle = v1.
angle(v2);
459 angle =
angle_add(&angle, atom1, atom2, atom3, set_angle, 1);
460 if ( !anglelist ) anglelist = angle;
466 molgroup->
angle = anglelist;
472 cout <<
"Number of angles generated: " << nangle << endl << endl;
490 for ( angle = anglelist; angle; angle = angle->
next ) {
492 if ( at ) angle->
a = at->
angle;
512 double bondlength = 0;
515 for ( bt = bondtype; bt && bondlength < 0.01; bt = bt->
next ) {
520 else if ( strcmp(atom1->
el, bt->
type1) == 0 && strcmp(atom2->
el, bt->
type2) == 0 )
522 else if ( strcmp(atom1->
el, bt->
type2) == 0 && strcmp(atom2->
el, bt->
type1) == 0 )
527 cout <<
"DEBUG md_find_bond_length: atom1=" << atom1->
type <<
528 " atom2=" << atom2->
type <<
" bondlength=" << bondlength << endl;
548 for ( bt = bondtype; bt && !bt_found; bt = bt->
next ) {
549 l1 = strlen(bt->
type1);
550 l2 = strlen(bt->
type2);
551 if ( strncmp(atom1->
type, bt->
type1, l1) == 0 && strncmp(atom2->
type, bt->
type2, l2) == 0 )
553 else if ( strncmp(atom1->
type, bt->
type2, l2) == 0 && strncmp(atom2->
type, bt->
type1, l1) == 0 )
555 else if ( strcmp(atom1->
el, bt->
type1) == 0 && strcmp(atom2->
el, bt->
type2) == 0 )
557 else if ( strcmp(atom1->
el, bt->
type2) == 0 && strcmp(atom2->
el, bt->
type1) == 0 )
562 cout <<
"Bond type not found: atom1=" << atom1->
type <<
" atom2=" << atom2->
type << endl;
565 cout <<
"DEBUG md_find_bond_type: atom1=" << atom1->
type <<
566 " atom2=" << atom2->
type <<
" length=" << bt_found->
covlength << endl;
587 cout <<
"Bond types:" << endl;
589 for ( nbt=0, bt = bondtype; bt; bt = bt->
next, nbt++ ) bt->
number = 0;
591 double* dist =
new double[nbt];
592 double* dev =
new double[nbt];
594 for ( i=0; i<nbt; i++ ) dist[i] = dev[i] = 0;
596 for ( bond = molgroup->
bond; bond; bond = bond->
next) {
598 for ( i=0, bt2 = bondtype; bt2 && bt2!=bt; bt2 = bt2->
next, i++ ) ;
607 cout <<
"Type1\tType2\tNumber\tRefLen\tLength\tDeviation" << endl;
608 for ( i=0, bt = bondtype; bt; bt = bt->
next, i++ ) {
611 dev[i] = dev[i]/bt->
number - dist[i]*dist[i];
612 if ( dev[i] > 0 ) dev[i] = sqrt(dev[i]);
642 double angle = d1.
angle(d2);
645 cout <<
"DEBUG md_angle: atom1=" << atom1->
type <<
" atom2=" <<
646 atom2->
type <<
" atom3=" << atom3->
type <<
" angle=" << angle << endl;
670 double angle =
md_angle(atom1, atom2, atom3);
672 for ( at = angletype; at; at = at->
next ) {
673 l1 = strlen(at->
type1);
674 l2 = strlen(at->
type2);
675 l3 = strlen(at->
type3);
676 if ( strncmp(atom2->
type, at->
type2, l2) == 0 ) {
677 if ( strncmp(atom1->
type, at->
type1, l1) == 0 && strncmp(atom3->
type, at->
type3, l3) == 0 )
679 else if ( strncmp(atom1->
type, at->
type3, l3) == 0 && strncmp(atom3->
type, at->
type1, l1) == 0 )
681 }
else if ( strncmp(atom2->
el, at->
type2, l2) == 0 ) {
682 if ( strncmp(atom1->
el, at->
type1, l1) == 0 && strncmp(atom3->
el, at->
type3, l3) == 0 )
684 else if ( strncmp(atom1->
el, at->
type3, l3) == 0 && strncmp(atom3->
el, at->
type1, l1) == 0 )
689 if ( fabs(at_found->
angle - angle) < fabs(at_best->
angle - angle) )
698 cout <<
"Angle type not found: atom1=" << atom1->
type <<
" atom2=" <<
699 atom2->
type <<
" atom3=" << atom3->
type << endl;
702 cout <<
"DEBUG md_find_angle_type: atom1=" << atom1->
type <<
" atom2=" <<
703 atom2->
type <<
" atom3=" << atom3->
type <<
" angle=" << at_best->
angle << endl;
724 if ( at ) angle = at->
angle;
727 angle =
md_angle(atom1, atom2, atom3);
730 cout <<
"DEBUG md_find_angle: atom1=" << atom1->
type <<
" atom2=" <<
731 atom2->
type <<
" atom3=" << atom3->
type <<
" angle=" << angle << endl;
745 double dist, bond_dev = 0, da, angle_dev = 0;
753 cout <<
"Bond#\tAtom1\tAtom2\tdLength\tStrength" << endl;
754 for ( n=0, bond = bondlist; bond; bond = bond->
next, n++ ) {
760 bond_dev += dist*dist;
768 bond_dev = sqrt(bond_dev/n);
773 cout <<
"Bond deviation: " << bond_dev <<
" A" << endl;
776 cout <<
"Angle#\tAtom1\tAtom2\tAtom3\tdAngle\tStrength" << endl;
777 for ( n=0, angle = anglelist; angle; angle = angle->
next, n++ ) {
794 angle_dev = sqrt(angle_dev/n);
799 cout <<
"Angle deviation: " << angle_dev*180.0/
M_PI <<
" degrees" << endl << endl;
812 double radius, radavg=0, radstd=0;
818 for ( natom=0, mol = molgroup->
mol; mol; mol = mol->
next )
819 for( res = mol->
res; res; res = res->
next )
820 for ( atom = res->
atom; atom; atom = atom->
next ) {
823 radstd += radius*radius;
828 radstd = radstd/natom - radavg*radavg;
829 if ( radstd > 0 ) radstd = sqrt(radstd);
832 cout <<
"Radial avg & std: " << radavg <<
" " << radstd << endl << endl;