Bsoft  2.1.0
Bernard's software package
mol_bonds.cpp
Go to the documentation of this file.
1 
9 #include "mol_bonds.h"
10 #include "rwmd.h"
11 #include "rwmolecule.h"
12 #include "Matrix.h"
13 #include "linked_list.h"
14 #include "utilities.h"
15 
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18 
31 {
32  if ( molgroup->bond ) {
33  if ( verbose ) cerr << "Warning: Bond list already defined!" << endl;
34  return molgroup->bond;
35  }
36 
37  int i, j, natom, nbond;
38  double dist, bondlength;
39  Bbond* bond = NULL;
40  Bbond* bondlist = NULL;
41 
42  Bmolecule* mol;
43  Bresidue* res;
44  Batom* atom, *atom2;
45 
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++;
49 
50  Batom** atomlist = new Batom*[natom];
51 
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 ) {
55  atomlist[i++] = atom;
56 // atom->sel = 0;
57  }
58 
59  if ( verbose ) {
60  cout << "Generating a bond list for" << natom << " atoms" << endl;
61  if ( md->wrap ) cout << "With wrapping" << endl;
62  }
63 
64  for ( i=0, nbond=0; i<natom-1; i++ ) {
65  atom = atomlist[i];
66  for ( j=i+1; j<natom; j++ ) {
67  atom2 = atomlist[j];
68  bondlength = md_find_bond_length(atom, atom2, md->bond);
69  if ( md->wrap )
70  dist = (vector3_difference_PBC(atom->coord, atom2->coord, molgroup->box)).length();
71  else
72  dist = atom->coord.distance(atom2->coord);
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);
76  nbond++;
77  }
78  }
79  }
80 
81  if ( verbose & VERB_FULL )
82  md_show_bonds(molgroup);
83 
84  if ( verbose )
85  cout << "Number of bonds generated: " << nbond << endl << endl;
86 
87  delete[] atomlist;
88 
89  molgroup->bond = bondlist;
90 
91  return bondlist;
92 }
93 
106 {
107  if ( molgroup->bond ) {
108  if ( verbose ) cerr << "Warning: Bond list already defined!" << endl;
109  return molgroup->bond;
110  }
111 
112  long natom = 0, nbond = 0;
113  double dist, bondlength;
114  Bbond* bond = NULL;
115  Bbond* bondlist = NULL;
116 
117  Bmolecule* mol;
118  Bresidue* res;
119  Batom* atom, *atom2;
120 
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 ) {
124  natom++;
125  for ( atom2 = atom->next; atom2; atom2 = atom2->next ) {
126  bondlength = md_find_bond_length(atom, atom2, md->bond);
127  if ( md->wrap )
128  dist = (vector3_difference_PBC(atom->coord, atom2->coord, molgroup->box)).length();
129  else
130  dist = atom->coord.distance(atom2->coord);
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);
134  nbond++;
135  }
136  }
137  }
138  }
139  }
140 
141  if ( verbose & VERB_FULL )
142  md_show_bonds(molgroup);
143 
144  if ( verbose )
145  cout << "Number of bonds generated: " << nbond << endl << endl;
146 
147  molgroup->bond = bondlist;
148 
149  return bondlist;
150 }
151 
152 /*
153 @brief Finds the top shortest bonds.
154 @param *bondlist list of bonds.
155 @param number number of shortest bonds to find.
156 @return Bbond* short bond list.
157 
158  This function finds the top number of shortests bonds with the aim
159  of assigning bonds based valence. The current bond length must be
160  given by the bond strength variable, k, in the bond structure.
161 **/
162 Bbond* md_bondlist_get_top(Bbond* bondlist, int number)
163 {
164  if ( !bondlist ) return NULL;
165 
166  int i, imax = 0;
167  double max = 0;
168  double* val = new double[number];
169  Bbond** bondarray = new Bbond*[number];
170  Bbond* newbond = NULL, *bond;
171 
172  for ( i=0; i<number; i++ ) {
173  val[i] = 1e37;
174  bondarray[i] = NULL;
175  }
176 
177  for ( bond = bondlist; bond; bond = bond->next ) {
178  for ( i=imax=0, max=0; i<number; i++ ) if ( max < val[i] ) {
179  max = val[i];
180  imax = i;
181  }
182  if ( val[imax] > bond->k ) {
183  val[imax] = bond->k;
184  bondarray[imax] = bond;
185  }
186  }
187 
188  for ( i=0; i<number; i++ ) if ( bondarray[i] )
189  bond_add(&newbond, bondarray[i]->atom1, bondarray[i]->atom2, bondarray[i]->l, 1);
190 
191  delete[] val;
192  delete[] bondarray;
193 
194  return newbond;
195 }
196 
209 {
210  if ( molgroup->bond ) {
211  if ( verbose ) cerr << "Warning: Bond list already defined!" << endl;
212  return molgroup->bond;
213  }
214 
215  double cutoff = md->cutoff;
216 
217  int i, ii, x, y, z, xx, yy, zz, ix, iy, iz;
218  Vector3<double> box = molgroup->box;
219  Vector3<double> sampling(cutoff, cutoff, cutoff);
220  Vector3<int> size((int) (box[0]/sampling[0] + 0.001),
221  (int) (box[1]/sampling[1] + 0.001), (int) (box[2]/sampling[2] + 0.001));
222  size = size.max(1);
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;
226  Batom *atom, *atom2;
227  Latom *latom, *latom2;
228  Bbond* tbondlist = NULL;
229  Bbond* tbond = NULL;
230  Bbond* bond = NULL;
231 
232  if ( verbose )
233  cout << "Sampling intervals for cutoff " << cutoff << ": " << sampling << endl;
234 
235  Latom** alist = molgroup_atom_mesh_lists(molgroup, size, sampling);
236 
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 ) {
243  atom = latom->atom;
244  for ( zz=z-1; zz<=z+1; zz++ ) {
245  iz = 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++ ) {
249  iy = 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++ ) {
253  ix = 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;
259  bondlength = md_find_bond_length(atom, atom2, md->bond);
260  if ( md->wrap )
261  dist = (vector3_difference_PBC(atom->coord, atom2->coord, box)).length();
262  else
263  dist = atom->coord.distance(atom2->coord);
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);
267  }
268  }
269  }
270  }
271  }
272  }
273  tbond = md_bondlist_get_top(tbondlist, valence);
274  if ( bond ) bond->next = tbond;
275  else bond = molgroup->bond = tbond;
276  if ( bond ) for ( ; bond->next; bond = bond->next ) ;
277  bond_kill(tbondlist);
278  }
279  }
280  }
281 
282  for ( i=0; i<boxsize; i++ ) kill_list((char *) alist[i], sizeof(Latom));
283  delete[] alist;
284 
285  if ( verbose & VERB_FULL )
286  md_show_bonds(molgroup);
287 
288  return molgroup->bond;
289 }
290 
299 double md_bond_list_set_parameters(Bbond* bondlist, Bbondtype* bondtype)
300 {
301  long n(0), nf(0);
302  double f(0);
303  Bbond* bond;
304  Bbondtype* bt;
305 
306  for ( bond = bondlist; bond; bond = bond->next, ++n ) {
307  bt = md_find_bond_type(bond->atom1, bond->atom2, bondtype);
308  if ( bt ) {
309  bond->l = bt->covlength;
310  nf++;
311  }
312  }
313 
314  f = nf*1.0L/n;
315 
316  if ( verbose )
317  cout << "Fraction of bond types found: " << f << endl;
318 
319  return f;
320 }
321 
329 int md_show_bonds(Bmolgroup* molgroup)
330 {
331  int nbond;
332  Bbond* bond;
333 
334  cout << "Bond#\tAtom1\tAtom2\tLength\tStrength" << endl;
335  for ( nbond=0, bond = molgroup->bond; bond; bond = bond->next, nbond++ )
336  cout << nbond+1 << tab << bond->atom1->num << tab <<
337  bond->atom2->num << tab << bond->l << tab << bond->k << endl;
338  cout << endl;
339 
340  return nbond;
341 }
342 
350 int md_show_angles(Bmolgroup* molgroup)
351 {
352  int nang;
353  Bangle* angle = NULL;
354 
355  cout << "Angle#\tAtom1\tAtom2\tAtom3\tAngle\tStrength" << endl;
356  for ( nang=0, angle = molgroup->angle; angle; angle = angle->next, nang++ )
357  cout << nang+1 << tab << angle->atom1->num << tab << angle->atom2->num << tab <<
358  angle->atom3->num << tab << angle->a*180.0/M_PI << tab << angle->k << endl;
359  cout << endl;
360 
361  return nang;
362 }
363 
372 {
373  int i, nbond;
374  Bmolecule* mol;
375  Bresidue* res;
376  Batom* atom;
377  Bbond* bond;
378 
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 )
382  atom->sel = 0;
383 
384  for ( nbond=0, bond = molgroup->bond; bond; bond = bond->next, nbond++ ) {
385  bond->atom1->sel++;
386  bond->atom2->sel++;
387  }
388 
389  cout << "Number of bonds: " << nbond << endl;
390 
391  int hist[100];
392  for ( i=0; i<100; i++ ) hist[i] = 0;
393 
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 )
397  hist[atom->sel]++;
398 
399  cout << "Val\tAtoms\tBonds" << endl;
400  for ( i=0; i<10; i++ ) cout << i << tab << hist[i] << tab << i*hist[i] << endl;
401 
402  return nbond;
403 }
404 
416 {
417  Bbond* bondlist = molgroup->bond;
418  if ( !bondlist ) return NULL;
419 
420  Batom *atom1, *atom2, *atom3;
421  Bbond *bond1, *bond2;
422  Bangle* anglelist = NULL;
423  Bangle* angle = NULL;
424  double set_angle = 0;
425  int nangle = 0, found;
426  Vector3<double> v1, v2;
427 
428  for ( bond1=bondlist; bond1->next; bond1=bond1->next ) {
429  for ( bond2=bond1->next; bond2; bond2=bond2->next ) {
430  found = 0;
431  if ( bond1->atom1 == bond2->atom1 ) {
432  atom1 = bond1->atom2;
433  atom2 = bond1->atom1;
434  atom3 = bond2->atom2;
435  found = 1;
436  } else if ( bond1->atom1 == bond2->atom2 ) {
437  atom1 = bond1->atom2;
438  atom2 = bond1->atom1;
439  atom3 = bond2->atom1;
440  found = 1;
441  } else if ( bond1->atom2 == bond2->atom1 ) {
442  atom1 = bond1->atom1;
443  atom2 = bond1->atom2;
444  atom3 = bond2->atom2;
445  found = 1;
446  } else if ( bond1->atom2 == bond2->atom2 ) {
447  atom1 = bond1->atom1;
448  atom2 = bond1->atom2;
449  atom3 = bond2->atom1;
450  found = 1;
451  }
452  if ( found ) {
453  if ( md ) set_angle = md_find_angle(atom1, atom2, atom3, md->angle);
454  else {
455  v1 = atom1->coord - atom2->coord;
456  v2 = atom3->coord - atom2->coord;
457  set_angle = v1.angle(v2);
458  }
459  angle = angle_add(&angle, atom1, atom2, atom3, set_angle, 1);
460  if ( !anglelist ) anglelist = angle;
461  nangle ++;
462  }
463  }
464  }
465 
466  molgroup->angle = anglelist;
467 
468  if ( verbose & VERB_FULL )
469  md_show_angles(molgroup);
470 
471  if ( verbose & VERB_PROCESS )
472  cout << "Number of angles generated: " << nangle << endl << endl;
473 
474  return anglelist;
475 }
476 
485 int md_angle_list_set_parameters(Bangle* anglelist, Bangletype* angletype)
486 {
487  Bangle* angle;
488  Bangletype* at;
489 
490  for ( angle = anglelist; angle; angle = angle->next ) {
491  at = md_find_angle_type(angle->atom1, angle->atom2, angle->atom3, angletype);
492  if ( at ) angle->a = at->angle;
493  else if ( verbose & VERB_FULL )
494  cout << "Angle type not found: " << angle->atom1->type << tab << angle->atom2->type << tab << angle->atom3->type << endl;
495  }
496 
497  return 0;
498 }
499 
510 double md_find_bond_length(Batom* atom1, Batom* atom2, Bbondtype* bondtype)
511 {
512  double bondlength = 0;
513  Bbondtype* bt;
514 
515  for ( bt = bondtype; bt && bondlength < 0.01; bt = bt->next ) {
516  if ( strstr(atom1->type, bt->type1) && strstr(atom2->type, bt->type2) )
517  bondlength = bt->covlength;
518  else if ( strstr(atom1->type, bt->type2) && strstr(atom2->type, bt->type1) )
519  bondlength = bt->covlength;
520  else if ( strcmp(atom1->el, bt->type1) == 0 && strcmp(atom2->el, bt->type2) == 0 )
521  bondlength = bt->covlength;
522  else if ( strcmp(atom1->el, bt->type2) == 0 && strcmp(atom2->el, bt->type1) == 0 )
523  bondlength = bt->covlength;
524  }
525 
526  if ( verbose & VERB_DEBUG )
527  cout << "DEBUG md_find_bond_length: atom1=" << atom1->type <<
528  " atom2=" << atom2->type << " bondlength=" << bondlength << endl;
529 
530  return bondlength;
531 }
532 
542 Bbondtype* md_find_bond_type(Batom* atom1, Batom* atom2, Bbondtype* bondtype)
543 {
544  int l1, l2;
545  Bbondtype* bt;
546  Bbondtype* bt_found = NULL;
547 
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 )
552  bt_found = bt;
553  else if ( strncmp(atom1->type, bt->type2, l2) == 0 && strncmp(atom2->type, bt->type1, l1) == 0 )
554  bt_found = bt;
555  else if ( strcmp(atom1->el, bt->type1) == 0 && strcmp(atom2->el, bt->type2) == 0 )
556  bt_found = bt;
557  else if ( strcmp(atom1->el, bt->type2) == 0 && strcmp(atom2->el, bt->type1) == 0 )
558  bt_found = bt;
559  }
560 
561  if ( !bt_found && ( verbose & VERB_FULL ) )
562  cout << "Bond type not found: atom1=" << atom1->type << " atom2=" << atom2->type << endl;
563 
564  if ( verbose & VERB_DEBUG )
565  cout << "DEBUG md_find_bond_type: atom1=" << atom1->type <<
566  " atom2=" << atom2->type << " length=" << bt_found->covlength << endl;
567 
568  return bt_found;
569 }
570 
580 int md_show_bond_types(Bmolgroup* molgroup, Bbondtype* bondtype)
581 {
582  long nbt, i;
583  double d;
584  Bbond* bond;
585  Bbondtype* bt, *bt2;
586 
587  cout << "Bond types:" << endl;
588 
589  for ( nbt=0, bt = bondtype; bt; bt = bt->next, nbt++ ) bt->number = 0;
590 
591  double* dist = new double[nbt];
592  double* dev = new double[nbt];
593 
594  for ( i=0; i<nbt; i++ ) dist[i] = dev[i] = 0;
595 
596  for ( bond = molgroup->bond; bond; bond = bond->next) {
597  bt = md_find_bond_type(bond->atom1, bond->atom2, bondtype);
598  for ( i=0, bt2 = bondtype; bt2 && bt2!=bt; bt2 = bt2->next, i++ ) ;
599  d = bond->atom1->coord.distance(bond->atom2->coord);
600  if ( i < nbt ) {
601  dist[i] += d;
602  dev[i] += d*d;
603  bt->number++;
604  }
605  }
606 
607  cout << "Type1\tType2\tNumber\tRefLen\tLength\tDeviation" << endl;
608  for ( i=0, bt = bondtype; bt; bt = bt->next, i++ ) {
609  if ( bt->number ) {
610  dist[i] /= bt->number;
611  dev[i] = dev[i]/bt->number - dist[i]*dist[i];
612  if ( dev[i] > 0 ) dev[i] = sqrt(dev[i]);
613  else dev[i] = 0;
614  cout << bt->type1 << tab << bt->type2 << tab << bt->number << tab <<
615  bt->covlength << tab << dist[i] << tab << dev[i] << endl;
616  }
617  }
618  cout << endl;
619 
620  delete[] dist;
621  delete[] dev;
622 
623  return 0;
624 }
625 
637 double md_angle(Batom* atom1, Batom* atom2, Batom* atom3)
638 {
639  Vector3<double> d1 = atom1->coord - atom2->coord;
640  Vector3<double> d2 = atom3->coord - atom2->coord;
641 
642  double angle = d1.angle(d2);
643 
644  if ( verbose & VERB_DEBUG )
645  cout << "DEBUG md_angle: atom1=" << atom1->type << " atom2=" <<
646  atom2->type << " atom3=" << atom3->type << " angle=" << angle << endl;
647 
648  return angle;
649 }
650 
663 Bangletype* md_find_angle_type(Batom* atom1, Batom* atom2, Batom* atom3, Bangletype* angletype)
664 {
665  int l1, l2, l3;
666  Bangletype* at;
667  Bangletype* at_found = NULL;
668  Bangletype* at_best = NULL;
669 
670  double angle = md_angle(atom1, atom2, atom3);
671 
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 )
678  at_found = at;
679  else if ( strncmp(atom1->type, at->type3, l3) == 0 && strncmp(atom3->type, at->type1, l1) == 0 )
680  at_found = at;
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 )
683  at_found = at;
684  else if ( strncmp(atom1->el, at->type3, l3) == 0 && strncmp(atom3->el, at->type1, l1) == 0 )
685  at_found = at;
686  }
687  if ( at_found ) {
688  if ( at_best ) {
689  if ( fabs(at_found->angle - angle) < fabs(at_best->angle - angle) )
690  at_best = at_found;
691  } else {
692  at_best = at_found;
693  }
694  }
695  }
696 
697  if ( !at_best && ( verbose & VERB_FULL ) )
698  cout << "Angle type not found: atom1=" << atom1->type << " atom2=" <<
699  atom2->type << " atom3=" << atom3->type << endl;
700 
701  if ( verbose & VERB_DEBUG )
702  cout << "DEBUG md_find_angle_type: atom1=" << atom1->type << " atom2=" <<
703  atom2->type << " atom3=" << atom3->type << " angle=" << at_best->angle << endl;
704 
705  return at_best;
706 }
707 
719 double md_find_angle(Batom* atom1, Batom* atom2, Batom* atom3, Bangletype* angletype)
720 {
721  double angle = 0;
722  Bangletype* at = md_find_angle_type(atom1, atom2, atom3, angletype);
723 
724  if ( at ) angle = at->angle;
725 
726  if ( angle < 0.1 )
727  angle = md_angle(atom1, atom2, atom3);
728 
729  if ( verbose & VERB_DEBUG )
730  cout << "DEBUG md_find_angle: atom1=" << atom1->type << " atom2=" <<
731  atom2->type << " atom3=" << atom3->type << " angle=" << angle << endl;
732 
733  return angle;
734 }
735 
742 double md_calculate_deviations(Bmolgroup* molgroup, int wrap)
743 {
744  int n = 0;
745  double dist, bond_dev = 0, da, angle_dev = 0;
746  Vector3<double> d1, d2;
747  Bbond* bond;
748  Bangle* angle;
749  Bbond* bondlist = molgroup->bond;
750  Bangle* anglelist = molgroup->angle;
751 
752  if ( verbose & VERB_FULL )
753  cout << "Bond#\tAtom1\tAtom2\tdLength\tStrength" << endl;
754  for ( n=0, bond = bondlist; bond; bond = bond->next, n++ ) {
755  if ( wrap )
756  dist = (vector3_difference_PBC(bond->atom1->coord, bond->atom2->coord, molgroup->box)).length();
757  else
758  dist = bond->atom1->coord.distance(bond->atom2->coord);
759  dist -= bond->l;
760  bond_dev += dist*dist;
761  if ( verbose & VERB_FULL )
762  cout << n+1 << tab << bond->atom1->num << tab <<
763  bond->atom2->num << tab << dist << tab << bond->k << endl;
764  }
765 
766  if ( n ) {
767  if ( bond_dev > 0 )
768  bond_dev = sqrt(bond_dev/n);
769  else
770  bond_dev = 0;
771  }
772 
773  cout << "Bond deviation: " << bond_dev << " A" << endl;
774 
775  if ( verbose & VERB_FULL )
776  cout << "Angle#\tAtom1\tAtom2\tAtom3\tdAngle\tStrength" << endl;
777  for ( n=0, angle = anglelist; angle; angle = angle->next, n++ ) {
778  if ( wrap ) {
779  d1 = vector3_difference_PBC(angle->atom2->coord, angle->atom1->coord, molgroup->box);
780  d2 = vector3_difference_PBC(angle->atom2->coord, angle->atom3->coord, molgroup->box);
781  } else {
782  d1 = angle->atom2->coord - angle->atom1->coord;
783  d2 = angle->atom2->coord - angle->atom3->coord;
784  }
785  da = angle_set_negPI_to_PI(fabs(d1.angle(d2) - angle->a));
786  angle_dev += da*da;
787  if ( verbose & VERB_FULL )
788  cout << n+1 << tab << angle->atom1->num << tab << angle->atom2->num <<
789  tab << angle->atom3->num << tab << da*180.0/M_PI << tab << angle->k << endl;
790  }
791 
792  if ( n ) {
793  if ( angle_dev > 0 )
794  angle_dev = sqrt(angle_dev/n);
795  else
796  angle_dev = 0;
797  }
798 
799  cout << "Angle deviation: " << angle_dev*180.0/M_PI << " degrees" << endl << endl;
800 
801  return bond_dev;
802 }
803 
810 {
811  int natom;
812  double radius, radavg=0, radstd=0;
813  Bmolecule* mol;
814  Bresidue* res;
815  Batom* atom;
816  Vector3<double> center = (molgroup->min + molgroup->max) * 0.5;
817 
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 ) {
821  radius = atom->coord.distance(center);
822  radavg += radius;
823  radstd += radius*radius;
824  natom++;
825  }
826 
827  radavg /= natom;
828  radstd = radstd/natom - radavg*radavg;
829  if ( radstd > 0 ) radstd = sqrt(radstd);
830  else radstd = 0;
831 
832  cout << "Radial avg & std: " << radavg << " " << radstd << endl << endl;
833 
834  return 0;
835 }
836 
md_generate_angle_list
Bangle * md_generate_angle_list(Bmolgroup *molgroup, Bmd *md)
Generates an angle list.
Definition: mol_bonds.cpp:415
vector3_difference_PBC
Vector3< T1 > vector3_difference_PBC(Vector3< T1 > &v1, Vector3< T1 > &v2, Vector3< T2 > &box)
Definition: Vector3.h:697
Bbond::l
double l
Definition: rwmolecule.h:138
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bresidue::next
Bresidue * next
Definition: rwmolecule.h:50
Bangletype::next
Bangletype * next
Definition: rwmd.h:39
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
verbose
int verbose
Bangle::a
double a
Definition: rwmolecule.h:155
Bbond::next
Bbond * next
Definition: rwmolecule.h:135
Bbond::atom1
Batom * atom1
Definition: rwmolecule.h:136
Bresidue::atom
Batom * atom
Definition: rwmolecule.h:54
Bangle
Definition: rwmolecule.h:150
Batom::num
int num
Definition: rwmolecule.h:26
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
Vector3< double >
rwmd.h
Header to read and write molecular dynamics parameters in STAR format.
Bbondtype::number
long number
Definition: rwmd.h:27
Batom::el
char el[4]
Definition: rwmolecule.h:27
md_calculate_radial_deviation
int md_calculate_radial_deviation(Bmolgroup *molgroup)
Calculates the radial deviations from the center of the box.
Definition: mol_bonds.cpp:809
md_find_bond_type
Bbondtype * md_find_bond_type(Batom *atom1, Batom *atom2, Bbondtype *bondtype)
Finds the bond type.
Definition: mol_bonds.cpp:542
md_find_angle_type
Bangletype * md_find_angle_type(Batom *atom1, Batom *atom2, Batom *atom3, Bangletype *angletype)
Finds the reference angle type between three atoms.
Definition: mol_bonds.cpp:663
Bbond::atom2
Batom * atom2
Definition: rwmolecule.h:137
Bmd
Definition: rwmd.h:56
md_generate_bond_list_with_valence
Bbond * md_generate_bond_list_with_valence(Bmolgroup *molgroup, Bmd *md, int valence)
Generates a bond list based on a single valence and the shortest current bond lengths.
Definition: mol_bonds.cpp:208
Bangletype::type1
char type1[8]
Definition: rwmd.h:40
length
double length(vector< T > v)
Definition: Vector3.h:530
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Batom::next
Batom * next
Definition: rwmolecule.h:25
Bmolecule::res
Bresidue * res
Definition: rwmolecule.h:122
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:558
Bangletype::type2
char type2[8]
Definition: rwmd.h:41
md_show_bond_types
int md_show_bond_types(Bmolgroup *molgroup, Bbondtype *bondtype)
Shows the bond type composition.
Definition: mol_bonds.cpp:580
Latom::atom
Batom * atom
Definition: mol_util.h:24
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Bangle::atom1
Batom * atom1
Definition: rwmolecule.h:152
md_generate_bond_list
Bbond * md_generate_bond_list(Bmolgroup *molgroup, Bmd *md)
Generates a distance-based bond list.
Definition: mol_bonds.cpp:30
Bbondtype::type1
char type1[8]
Definition: rwmd.h:23
Bbondtype::covlength
float covlength
Definition: rwmd.h:25
md_generate_molecular_bond_list
Bbond * md_generate_molecular_bond_list(Bmolgroup *molgroup, Bmd *md)
Generates an intramolecular distance-based bond list.
Definition: mol_bonds.cpp:105
Bbondtype::type2
char type2[8]
Definition: rwmd.h:24
mol_bonds.h
Header for molecular dynamics.
rwmolecule.h
Header file for reading reflection files.
Bbond
Definition: rwmolecule.h:134
angle_add
Bangle * angle_add(Bangle **angle, Batom *atom1, Batom *atom2, Batom *atom3, double a, double k)
Adds an angle to a linked list.
Definition: rwmolecule.cpp:312
Bmd::angle
Bangletype * angle
Definition: rwmd.h:85
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
Bmolecule
Definition: rwmolecule.h:107
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
Bmolgroup::bond
Bbond * bond
Definition: rwmolecule.h:190
Bangle::next
Bangle * next
Definition: rwmolecule.h:151
Batom::type
char type[8]
Definition: rwmolecule.h:28
Bangletype::angle
float angle
Definition: rwmd.h:43
molgroup_atom_mesh_lists
Latom ** molgroup_atom_mesh_lists(Bmolgroup *molgroup, Vector3< int > size, Vector3< double > sampling)
Generates lists of atoms based on a grid.
Definition: mol_util.cpp:1132
md_angle_list_set_parameters
int md_angle_list_set_parameters(Bangle *anglelist, Bangletype *angletype)
Assigns angles from angle types.
Definition: mol_bonds.cpp:485
md_calculate_deviations
double md_calculate_deviations(Bmolgroup *molgroup, int wrap)
Calculates deviations from the reference bond lengths and angles.
Definition: mol_bonds.cpp:742
Latom
Definition: mol_util.h:22
Bbondtype::next
Bbondtype * next
Definition: rwmd.h:22
md_bond_list_set_parameters
double md_bond_list_set_parameters(Bbond *bondlist, Bbondtype *bondtype)
Assigns covalent bond lengths to bonds.
Definition: mol_bonds.cpp:299
M_PI
#define M_PI
Definition: utilities.h:63
Bangletype::type3
char type3[8]
Definition: rwmd.h:42
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
md_bondlist_get_top
Bbond * md_bondlist_get_top(Bbond *bondlist, int number)
Definition: mol_bonds.cpp:162
Bmolgroup::max
Vector3< double > max
Definition: rwmolecule.h:183
bond_add
Bbond * bond_add(Bbond **bond, Batom *atom1, Batom *atom2, double l, double k)
Adds a bond to a linked list.
Definition: rwmolecule.cpp:269
Bangle::atom2
Batom * atom2
Definition: rwmolecule.h:153
Vector3::volume
double volume()
Definition: Vector3.h:237
Bmolgroup::min
Vector3< double > min
Definition: rwmolecule.h:182
Batom::sel
int sel
Definition: rwmolecule.h:34
Vector3::angle
double angle(Vector3< T2 > &v)
Definition: Vector3.h:259
Matrix.h
Generalized matrix class.
Bmd::bond
Bbondtype * bond
Definition: rwmd.h:84
Bresidue
Definition: rwmolecule.h:49
md_show_bond_stats
int md_show_bond_stats(Bmolgroup *molgroup)
Shows the number of bonds and the valency per atom.
Definition: mol_bonds.cpp:371
linked_list.h
Header file for generalized linked list functions.
md_show_angles
int md_show_angles(Bmolgroup *molgroup)
Shows the angles and angular sizes.
Definition: mol_bonds.cpp:350
Bangletype
Definition: rwmd.h:38
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
md_angle
double md_angle(Batom *atom1, Batom *atom2, Batom *atom3)
Calculates the angle between three atoms.
Definition: mol_bonds.cpp:637
md_find_bond_length
double md_find_bond_length(Batom *atom1, Batom *atom2, Bbondtype *bondtype)
Finds the reference covalent bond length.
Definition: mol_bonds.cpp:510
Bmolgroup
Definition: rwmolecule.h:170
Bbond::k
double k
Definition: rwmolecule.h:139
md_show_bonds
int md_show_bonds(Bmolgroup *molgroup)
Shows the bonds and bond lengths.
Definition: mol_bonds.cpp:329
Bmd::wrap
int wrap
Definition: rwmd.h:72
Bangle::atom3
Batom * atom3
Definition: rwmolecule.h:154
md_find_angle
double md_find_angle(Batom *atom1, Batom *atom2, Batom *atom3, Bangletype *angletype)
Finds the reference angle between three atoms.
Definition: mol_bonds.cpp:719
bond_kill
int bond_kill(Bbond *bond)
Dealocates a list of bonds.
Definition: rwmolecule.cpp:480
Bbondtype
Definition: rwmd.h:21
Latom::next
Latom * next
Definition: mol_util.h:23
Bangle::k
double k
Definition: rwmolecule.h:156
Bmd::cutoff
double cutoff
Definition: rwmd.h:69
Batom::coord
Vector3< double > coord
Definition: rwmolecule.h:30
Bmolgroup::angle
Bangle * angle
Definition: rwmolecule.h:191
Batom
Definition: rwmolecule.h:24
Vector3::max
Type max()
Definition: Vector3.h:175