| Bsoft 2.0.5 Bernard's software package

mol_util.cpp
Go to the documentation of this file.
1
9 #include "rwmolecule.h"
10 #include "rwatomprop.h"
11 #include "rwresprop.h"
12 #include "mol_util.h"
13 #include "seq_util.h"
14 #include "linked_list.h"
15 #include "Matrix.h"
16 #include "utilities.h"
17
18 #include <map>
19
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22
28 int molgroup_Bfactors(Bmolgroup* molgroup)
29 {
30 int nat = 0;
31 double avgB = 0, sdB = 0, atomB = 0, dist, maxdist = 0;
32 char atomtype[10];
33 Vector3<double> ca;
34 Bmolecule* mol;
35 Bresidue* res;
36 Batom* atom;
37
38 if ( verbose & VERB_LABEL )
39 cout << "Residue\tNatoms\tAvgB\tStDevB" << endl;
40
41 for ( mol = molgroup->mol; mol; mol = mol->next ) {
42 for( res = mol->res; res; res = res->next ) {
43 nat = 0;
44 avgB = sdB = 0;
45 for ( atom = res->atom; atom; atom = atom->next ) {
46 nat++;
47 avgB += atom->b;
48 sdB += atom->b*atom->b;
49 }
50 avgB /= nat;
51 sdB = sqrt(sdB/nat - avgB*avgB);
52 cout << res->num << tab << nat << tab << avgB << tab << sdB << endl;
53 }
54 }
55
56 if ( verbose & VERB_PROCESS )
57 cout << "Residue\tMaxDist\tBfactor\tAtom" << endl;
58
59 for ( mol = molgroup->mol; mol; mol = mol->next ) {
60 for( res = mol->res; res; res = res->next ) {
61 for ( atom = res->atom; atom; atom = atom->next ) {
62 if ( strstr(atom->type, "CA" ) ) {
63 ca = atom->coord;
64 strncpy(atomtype, atom->type, 8);
65 atomB = atom->b;
66 } else if ( strncmp(atom->type, "H", 1 ) &&
67 strncmp(atom->type, " H", 2 ) &&
68 !strstr(atom->type, "N " ) &&
69 !strstr(atom->type, "C " ) &&
70 !strstr(atom->type, "O " ) ) {
71 dist = (atom->coord - ca).length();
72 if ( maxdist < dist ) {
73 maxdist = dist;
74 strncpy(atomtype, atom->type, 8);
75 atomB = atom->b;
76 }
77 }
78 }
79 cout << res->num << tab << maxdist << tab << atomB << tab << atomtype << endl;
80 maxdist = 0;
81 }
82 }
83
84 return 0;
85 }
86
92 int molgroup_print_sequence(Bmolgroup* molgroup)
93 {
94 Bmolecule* mol;
95
96 if ( verbose & VERB_LABEL )
97 cout << "Sequence:" << endl;
98
99 for ( mol = molgroup->mol; mol; mol = mol->next ) {
100 cout << "Molecule: " << mol->id << endl << mol->seq << endl;
101 if ( verbose & VERB_PROCESS )
102 cout << endl << "Length = " << mol->nres << endl << endl;
103 }
104
105 return 0;
106 }
107
114 int molgroup_set_radius(Bmolgroup* molgroup, double radius)
115 {
116 if ( radius < 0.1 ) return 0;
117
118 long natom;
119 double dist, sum, sumsq, avg, std;
120 Bmolecule* mol;
121 Bresidue* res;
122 Batom* atom;
123
124 if ( verbose & VERB_LABEL )
125 cout << "Shifting to radius: " << radius << endl << endl;
126
127 for ( sum=sumsq=natom=0, mol = molgroup->mol; mol; mol = mol->next ) {
128 for( res = mol->res; res; res = res->next ) {
129 for ( atom = res->atom; atom; atom = atom->next, natom++ ) {
130 dist = atom->coord.length();
131 sum += dist;
132 sumsq += dist*dist;
133 atom->coord *= radius/dist;
134 }
135 }
136 }
137
138 avg = sum/natom;
139 std = sumsq/natom - avg*avg;
140 if ( std > 0 ) std = sqrt(std);
141 else std = 0;
142
143 if ( verbose & VERB_PROCESS )
144 cout << "Radius avg and std: " << avg << " " << std << endl << endl;
145
146 molgroup_stats(molgroup);
147
148 return 0;
149 }
150
161 int molgroup_rename(Bmolgroup* molgroup, char first_name)
162 {
163 if ( first_name == 0 ) return 0;
164
165 char letter = first_name;
166 Bmolecule* mol;
167
168 for ( mol=molgroup->mol; mol; mol=mol->next ) {
169 mol->id[0] = letter++;
170 if ( letter > 'Z' ) letter = 'A';
171 }
172
173 return 0;
174 }
175
182 int molgroup_residue_renumber(Bmolgroup* molgroup, int first)
183 {
184 if ( first < 1 ) return 0;
185
186 int resnum;
187 Bmolecule* mol;
188 Bresidue* res;
189
190 if ( verbose & VERB_LABEL )
191 cout << "Renumbering residues from: " << first << endl;
192
193 for ( mol = molgroup->mol; mol; mol = mol->next ) {
194 resnum = first;
195 for( res = mol->res; res; res = res->next ) {
196 res->num = resnum;
197 res->insert[0] = ' ';
198 resnum++;
199 }
200 }
201
202 return 0;
203 }
204
211 int molgroup_atom_renumber(Bmolgroup* molgroup, int first)
212 {
213 if ( first < 1 ) return 0;
214
215 int atomnum = first;
216 Bmolecule* mol;
217 Bresidue* res;
218 Batom* atom;
219
220 if ( verbose & VERB_LABEL )
221 cout << "Renumbering atoms from: " << first << endl;
222
223 for ( mol = molgroup->mol; mol; mol = mol->next ) {
224 for( res = mol->res; res; res = res->next ) {
225 for ( atom = res->atom; atom; atom = atom->next ) {
226 atom->num = atomnum;
227 atomnum++;
228 }
229 }
230 }
231
232 return 0;
233 }
234
243 int molgroup_coor_reset_occupancy(Bmolgroup* molgroup, int range_first,
244 int range_last, double occupancy)
245 {
246 Bmolecule* mol;
247 Bresidue* res;
248 Batom* atom;
249
250 if ( verbose & VERB_LABEL )
251 cout << "Reseting occupancy to range: " << range_first << " " <<range_last << endl;
252
253 for ( mol = molgroup->mol; mol; mol = mol->next ) {
254 for( res = mol->res; res; res = res->next ) {
255 if ( res->num >= range_first && res->num <= range_last )
256 for ( atom = res->atom; atom; atom = atom->next ) {
257 atom->q = occupancy;
258 }
259 }
260 }
261
262 return 0;
263 }
264
270 double molgroup_calculate_weight(Bmolgroup* molgroup)
271 {
272 int n;
273 double summass(0), totmass = 0;
274 Bmolecule* mol;
275 Bresidue* res;
276 Batom* atom;
277
278 if ( verbose & VERB_PROCESS )
279 cout << "Molecule\tMW(Da)\tAtoms" << endl;
280 for ( mol = molgroup->mol; mol; mol = mol->next ) {
281 summass = 0;
282 n = 0;
283 for( res = mol->res; res; res = res->next ) {
284 for ( atom = res->atom; atom; atom = atom->next ) {
285 n++;
286 summass += atom->mass;
287 }
288 }
289 if ( verbose & VERB_PROCESS )
290 cout << mol->id << tab << summass << tab << n << endl;
291 totmass += summass;
292 }
293
294 if ( verbose ) {
295 cout << "Total molecular weight: " << totmass << " Da" << endl;
296 cout << "Total volume: " << totmass/RHO << " A3" << endl << endl;
297 }
298
299 return totmass;
300 }
301
307 Vector3<double> molgroup_center_of_mass(Bmolgroup* molgroup)
308 {
309 double summass(0);
310 Bmolecule* mol;
311 Bresidue* res;
312 Batom* atom;
313 Vector3<double> acoord, com, vec;
314
315 for ( mol = molgroup->mol; mol; mol = mol->next ) {
316 for( res = mol->res; res; res = res->next ) {
317 for ( atom = res->atom; atom; atom = atom->next ) {
318 acoord = atom->coord * atom->mass;
319 com += acoord;
320 vec += acoord*acoord;
321 summass += atom->mass;
322 }
323 }
324 }
325
326 if ( summass ) {
327 com /= summass;
328 vec = vec/summass - com*com;
329 vec = vec.square_root();
330 vec.normalize();
331 } else cout << "Error: No atom masses found!" << endl << endl;
332
333 if ( verbose & VERB_FULL ) {
334 cout << "Total molecular weight: " << summass << " Da" << endl;
335 cout << "Center of mass: " << com << " A" << endl;
336 cout << "Major axis: " << vec << endl;
337 }
338
339 return com;
340 }
341
347 Vector3<double> molgroup_selected_center_of_mass(Bmolgroup* molgroup)
348 {
349 double summass(0);
350 Bmolecule* mol;
351 Bresidue* res;
352 Batom* atom;
353 Vector3<double> acoord, com, vec;
354
355 for ( mol = molgroup->mol; mol; mol = mol->next ) if ( mol->sel ) {
356 for( res = mol->res; res; res = res->next ) {
357 for ( atom = res->atom; atom; atom = atom->next ) if ( atom->sel ) {
358 acoord = atom->coord * atom->mass;
359 com += acoord;
360 vec += acoord*acoord;
361 summass += atom->mass;
362 }
363 }
364 }
365
366 if ( summass ) {
367 com /= summass;
368 vec = vec/summass - com*com;
369 vec = vec.square_root();
370 vec.normalize();
371 } else cout << "Error: No atom masses found!" << endl << endl;
372
373 if ( verbose & VERB_FULL ) {
374 cout << "Total molecular weight: " << summass << " Da" << endl;
375 cout << "Center of mass: " << com << " A" << endl;
376 cout << "Major axis: " << vec << endl;
377 }
378
379 return com;
380 }
381
387 Vector3<double> molgroup_show_center_of_mass(Bmolgroup* molgroup)
388 {
389 Vector3<double> com = molgroup_center_of_mass(molgroup);
390
391 cout << "Center of mass: " << com << " A" << endl;
392
393 return com;
394 }
395
401 Vector3<double> mol_center_of_mass(Bmolecule* mol)
402 {
403 double summass(0);
404 Bresidue* res;
405 Batom* atom;
406 Vector3<double> acoord, com, vec;
407
408 for( res = mol->res; res; res = res->next ) {
409 for ( atom = res->atom; atom; atom = atom->next ) {
410 acoord = atom->coord * atom->mass;
411 com += acoord;
412 vec += acoord*acoord;
413 summass += atom->mass;
414 }
415 }
416
417 if ( summass ) {
418 com /= summass;
419 vec = vec/summass - com*com;
420 vec = vec.square_root();
421 vec.normalize();
422 } else cerr << "Error: No atom masses found!" << endl << endl;
423
424 if ( verbose & VERB_FULL ) {
425 cout << "Molecule: " << mol->id << endl;
426 cout << "Molecular weight: " << summass << " Da" << endl;
427 cout << "Center of mass: " << com << " A" << endl;
428 cout << "Major axis: " << vec << endl << endl;
429 }
430
431 return com;
432 }
433
439 Vector3<double> mol_show_center_of_mass(Bmolecule* mol)
440 {
441 Vector3<double> com = mol_center_of_mass(mol);
442
443 cout << "Molecule: " << mol->id << endl;
444 cout << "Center of mass: " << com << " A" << endl;
445
446 return com;
447 }
448
455 Vector3<double> molgroup_principal_axes(Bmolgroup* molgroup, Vector3<double>* eigenvec)
456 {
457 double summass(0);
458 Bmolecule* mol;
459 Bresidue* res;
460 Batom* atom;
461 Vector3<double> eigenval, vec, vec2, vecx;
462
463 for ( mol = molgroup->mol; mol; mol = mol->next ) {
464 mol_principal_axes(mol, eigenvec);
465 for( res = mol->res; res; res = res->next ) {
466 for ( atom = res->atom; atom; atom = atom->next ) {
467 vec += atom->coord * atom->mass; // Sums
468 vec2 += (atom->coord*atom->coord) * atom->mass; // Square sums
469 vecx[0] += atom->mass*atom->coord[0]*atom->coord[1]; // Cross-term sums
470 vecx[1] += atom->mass*atom->coord[0]*atom->coord[2];
471 vecx[2] += atom->mass*atom->coord[1]*atom->coord[2];
472 summass += atom->mass;
473 }
474 }
475 }
476
477 if ( verbose & VERB_PROCESS ) {
478 cout << "Molecule group:" << endl;
479 cout << "Molecular weight: " << summass << " Da" << endl;
480 }
481
482 if ( summass < 1 ) {
483 cout << "Error: No atom masses found!" << endl << endl;
484 return vec;
485 }
486
487 vec /= summass;
488 vec2 /= summass;
489 vecx /= summass;
490
491 return principal_axes(vec, vec2, vecx, eigenvec);
492 }
493
500 Vector3<double> mol_principal_axes(Bmolecule* mol, Vector3<double>* eigenvec)
501 {
502 double summass(0);
503 Bresidue* res;
504 Batom* atom;
505 Vector3<double> eigenval, vec, vec2, vecx;
506
507 for( res = mol->res; res; res = res->next ) {
508 for ( atom = res->atom; atom; atom = atom->next ) {
509 vec += atom->coord * atom->mass; // Sums
510 vec2 += (atom->coord*atom->coord) * atom->mass; // Square sums
511 vecx[0] += atom->mass*atom->coord[0]*atom->coord[1]; // Cross-term sums
512 vecx[1] += atom->mass*atom->coord[0]*atom->coord[2];
513 vecx[2] += atom->mass*atom->coord[1]*atom->coord[2];
514 summass += atom->mass;
515 }
516 }
517
518 if ( verbose & VERB_PROCESS ) {
519 cout << "Molecule: " << mol->id << endl;
520 cout << "Molecular weight: " << summass << " Da" << endl;
521 }
522
523 if ( summass < 1 ) {
524 cout << "Error: No atom masses found!" << endl << endl;
525 bexit(-1);
526 }
527
528 vec /= summass;
529 vec2 /= summass;
530 vecx /= summass;
531
532 return principal_axes(vec, vec2, vecx, eigenvec);
533 }
534
548 double molgroup_density(Bmolgroup* molgroup)
549 {
550 long nmol, nres, natom;
551 double mass = 0;
552 Bmolecule* mol;
553 Bresidue* res;
554 Batom* atom;
555
556 for ( nmol=nres=natom=0, mol = molgroup->mol; mol; mol = mol->next, nmol++ )
557 for( res = mol->res; res; res = res->next, nres++ )
558 for ( atom = res->atom; atom; atom = atom->next, natom++ ) mass += atom->mass;
559
560 double volume = molgroup->box.volume();
561
562 double density = mass/volume;
563
564 if ( verbose & VERB_PROCESS ) {
565 cout << "Number of molecules and atoms: " << nmol << " " << nres << " " << natom << endl;
566 cout << "Volume: " << molgroup->box << " = " << volume << " A3" << endl;
567 cout << "Density: " << density << " Da/A3" << density*1.66058 << " g/ml" << endl;
568 cout << "Density: " << nmol*1.0/volume << " molecules/A3 "
569 << nres*1.0/volume << " residues/A3 " << natom*1.0/volume << " atoms/A3" << endl << endl;
570 }
571
572 return density;
573 }
574
586 double molgroup_volume(Bmolgroup* molgroup, Bstring& paramfile, int wrap)
587 {
588 Batomtype* atompar = get_atom_properties(paramfile);
589 Bresidue_type* respar = get_residue_properties(paramfile);
590
591 // write_atom_properties("at.star", atompar);
592
593 if ( molgroup->box.volume() < 1 )
594 molgroup->box = molgroup->max - molgroup->min;
595
596 long i, x, y, z, ix, iy, iz, rad;
597 double volume = 0, VdWvol = 0, mass = 0, resmass, sampling = 1, edge = 3, dist, dist2;
598 double voxel_volume = sampling*sampling*sampling;
599 Vector3<int> gridsize, lo, hi;
600 Vector3<double> c, d;
601 if ( wrap ) edge = 0;
602 gridsize[0] = (int) ((molgroup->max[0] - molgroup->min[0] + 2*edge)/sampling + 1);
603 gridsize[1] = (int) ((molgroup->max[1] - molgroup->min[1] + 2*edge)/sampling + 1);
604 gridsize[2] = (int) ((molgroup->max[2] - molgroup->min[2] + 2*edge)/sampling + 1);
605 // Vector3<int> h = gridsize * 0.5;
606 long size = (long) gridsize.volume();
607
608 char* grid = new char[size];
609 for ( i=0; i<size; i++ ) grid[i] = 0;
610
611 Bmolecule* mol;
612 Bresidue* res;
613 Batom* atom;
614 Batomtype* at;
615 Bresidue_type* rt;
616
617 cout << "Calculating the Van der Waals volume:" << endl;
618 cout << " in volume: " << gridsize << " = " << size << endl;
619 if ( wrap ) cout << "with wrapping." << endl;
620
621 for ( mol = molgroup->mol; mol; mol = mol->next ) {
622 for( res = mol->res; res; res = res->next ) {
623 for ( atom = res->atom, resmass=0; atom; atom = atom->next ) {
624 resmass += atom->mass;
625 for ( at = atompar; at && strncmp(atom->el, at->el, 2)!=0; at = at->next ) ;
626 dist = 2/sampling; // Atom types not found tend to be larger
627 if ( at ) {
628 if ( at->vdw < 0.8 )
629 cout << "VdW distance too short! atom=" << atom->el << " dist=" << at->vdw << endl;
630 else
631 dist = at->vdw/sampling;
632 }
633 dist2 = dist*dist;
634 rad = (long) (dist + 1);
635 c = atom->coord - molgroup->min;
636 c += edge;
637 c /= sampling;
638 lo = Vector3<int>((int)c[0], (int)c[1], (int)c[2]) - rad;
639 hi = Vector3<int>((int)c[0], (int)c[1], (int)c[2]) + rad;
640 if ( !wrap ) {
641 lo = lo.max(0);
642 hi = hi.min(gridsize - 1);
643 }
644 for ( z=lo[2]; z<=hi[2]; z++ ) {
645 iz = z;
646 if ( iz < 0 ) iz += gridsize[2];
647 if ( iz >= gridsize[2] ) iz -= gridsize[2];
648 d[2] = c[2] - z;
649 for ( y=lo[1]; y<=hi[1]; y++ ) {
650 iy = y;
651 if ( iy < 0 ) iy += gridsize[1];
652 if ( iy >= gridsize[1] ) iy -= gridsize[1];
653 d[1] = c[1] - iy;
654 for ( x=lo[0]; x<=hi[0]; x++ ) {
655 ix = x;
656 if ( ix < 0 ) ix += gridsize[0];
657 if ( ix >= gridsize[0] ) ix -= gridsize[0];
658 d[0] = c[0] - ix;
659 if ( d.length2() <= dist2 )
660 grid[(iz*gridsize[1] + iy)*gridsize[0] + ix] = 1;
661 }
662 }
663 }
664 }
665 mass += resmass;
666 for ( rt = respar; rt && strncmp(rt->cod, res->type, 3)!=0; rt = rt->next ) ;
667 if ( rt ) volume += rt->vol;
668 else volume += resmass/RHO;
669 }
670 }
671
672 cout << "Mass: " << mass << " Da" << endl;
673 cout << "Volume from residue volumes: " << volume << " A3 (" <<
674 volume*100.0/molgroup->box.volume() << " %)" << endl;
675 cout << "Density: " << mass/volume << " Da/A3 "
676 << 1.66058*mass/volume << " g/ml" << endl << endl;
677
678 for ( i=0, VdWvol=0; i<size; i++ ) VdWvol += grid[i];
679 VdWvol *= voxel_volume;
680
681 cout << "Van der Waals volume: " << VdWvol << " A3 ("
682 << VdWvol*100.0/(voxel_volume*size) << " %)" << endl;
683 cout << "Packing density: " << VdWvol/volume << endl << endl;
684
685 delete[] grid;
686
687 kill_list((char *) atompar, sizeof(Batomtype));
688 kill_list((char *) respar, sizeof(Bresidue_type));
689
690 return volume;
691 }
692
699 int molgroup_composition(Bmolgroup* molgroup, Bstring& paramfile)
700 {
701 Batomtype* atompar = get_atom_properties(paramfile);
702
703 long i, t, nel(0), nres(0), el[1024], an(0);
704 double mass[1024], mw(0), extinc(0);
705 Bmolecule* mol;
706 Bresidue* res;
707 Batom* atom;
708 Batomtype* at;
709
710 map<char, long> num;
711
712 for ( t=0, at = atompar; at && t < 1022; at = at->next, t++ )
713 mass[t] = el[t] = 0;
714
715 for ( mol = molgroup->mol; mol; mol = mol->next ) {
716 if ( mol->seq.length() ) {
717 for ( i=0; i<mol->seq.length(); i++, nres++ ) {
718 if ( num.find(mol->seq[i]) == num.end() )
719 num[mol->seq[i]] = 1;
720 else
721 num[mol->seq[i]]++;
722 }
723 }
724 for( res = mol->res; res; res = res->next )
725 for ( atom = res->atom; atom; atom = atom->next ) {
726 el[atom->tnum]++;
727 mass[atom->tnum] += atom->mass;
728 mw += atom->mass;
729 nel++;
730 }
731 }
732
733 for ( t=0, at = atompar; at && t < 1022; at = at->next, t++ )
734 an += el[t]*at->z;
735
736 // From Mach, Middaugh and Lewis (1992) Analytical Biochemistry 200:74-80
737 // From Pace et al. (1995) Protein Science 4:2411-2423.
738 // Cystines: 125 /M/cm
739 extinc += num['W'] * 5500;
740 extinc += num['Y'] * 1490;
741 // From different source
742 extinc += num['F'] * 200;
743
744 if ( nel ) {
745 cout << "Elemental composition:" << endl;
746 cout << "Element\tNumber\tMass" << endl;
747 for ( t=0, at = atompar; at && t < 1022; at = at->next, t++ )
748 if ( el[t] ) cout << at->el << tab << el[t] << tab << mass[t] << endl;
749 cout << endl;
750 cout << endl;
751 cout << "Total molecular weight: " << mw << " Da" << endl;
752 cout << "Total atomic number: " << an << endl << endl;
753 }
754
755 if ( nres ) {
756 cout << "Residue composition:" << endl;
757 cout << "Residue\tNumber" << endl;
758 for ( auto it=num.begin(); it!=num.end(); ++it )
759 cout << it->first << tab << it->second << endl;
760 cout << endl;
761 cout << "Extinction coefficient (280 nm): " << extinc << " /M/cm" << endl << endl;
762 }
763
764 kill_list((char *) atompar, sizeof(Batomtype));
765
766 return 0;
767 }
768
780 int molgroup_radial_density(Bmolgroup* molgroup, double interval, double cutoff, int wrap)
781 {
782 int i, ii, j, x, y, z, xx, yy, zz, ix, iy, iz;
783 int xlo, ylo, zlo, xhi, yhi, zhi;
784 Vector3<double> box = molgroup->box;
785 double dist;
786 Vector3<double> d, sampling(cutoff, cutoff, cutoff);
787 Vector3<int> size((int) (box[0]/sampling[0] + 0.001),
788 (int) (box[1]/sampling[1] + 0.001), (int) (box[2]/sampling[2] + 0.001));
789 size = size.max(1);
790 for ( i=0; i<3; i++ ) sampling[i] = box[i]/size[i] + 0.001;
791
792 Latom** alist = molgroup_atom_mesh_lists(molgroup, size, sampling);
793 Latom *latom, *latom2;
794
795 double mult = 1.0/interval;
796 int n = (int) (mult*cutoff+1);
797 int* rdf = new int[n];
798 for ( i=0; i<n; i++ ) rdf[i] = 0;
799
800 for ( i=z=0; z<size[2]; z++ ) {
801 zlo = z - 1;
802 zhi = z + 1;
803 if ( !wrap ) {
804 if ( zlo < 0 ) zlo = 0;
805 if ( zhi >= size[2] ) zhi = size[2] - 1;
806 }
807 for ( y=0; y<size[1]; y++ ) {
808 ylo = y - 1;
809 yhi = y + 1;
810 if ( !wrap ) {
811 if ( ylo < 0 ) ylo = 0;
812 if ( yhi >= size[1] ) yhi = size[1] - 1;
813 }
814 for ( x=0; x<size[0]; x++, i++ ) {
815 xlo = x - 1;
816 xhi = x + 1;
817 if ( !wrap ) {
818 if ( xlo < 0 ) xlo = 0;
819 if ( xhi >= size[0] ) xhi = size[0] - 1;
820 }
821 for ( latom = alist[i]; latom; latom = latom->next ) {
822 for ( zz=zlo; zz<=zhi; zz++ ) {
823 iz = zz;
824 if ( wrap ) {
825 if ( iz < 0 ) iz += size[2];
826 if ( iz >= size[2]) iz -= size[2];
827 }
828 for ( yy=ylo; yy<=yhi; yy++ ) {
829 iy = yy;
830 if ( wrap ) {
831 if ( iy < 0 ) iy += size[1];
832 if ( iy >= size[1] ) iy -= size[1];
833 }
834 for ( xx=xlo; xx<=xhi; xx++ ) {
835 ix = xx;
836 if ( wrap ) {
837 if ( ix < 0 ) ix += size[0];
838 if ( ix >= size[0] ) ix -= size[0];
839 }
840 ii = (iz*size[1] + iy)*size[0] + ix;
841 for ( latom2 = alist[ii]; latom2; latom2 = latom2->next )
842 if ( latom2->atom != latom->atom ) {
843 d = vector3_difference_PBC(latom2->atom->coord, latom->atom->coord, box);
844 dist = d.length();
845 if ( dist <= cutoff ) {
846 j = (int) (mult*dist);
847 if ( j < n ) rdf[j]++;
848 }
849 }
850 }
851 }
852 }
853 }
854 }
855 }
856 }
857
858 for ( i=0; i<size.volume(); i++ ) kill_list((char *) alist[i], sizeof(Latom));
859 delete[] alist;
860
861 cout << "Calculating the radial distribution function within " << cutoff << " A" << endl;
862
863 cout << "r(A)\tRDF" << endl;
864 for ( i=0; i<n; i++ ) cout << i*interval << tab << rdf[i] << endl;
865 cout << endl;
866
867 delete[] rdf;
868
869 return 0;
870 }
871
882 Latom** molgroup_atom_mesh_lists(Bmolgroup* molgroup, Vector3<int> size, Vector3<double> sampling)
883 {
884 long i, x, y, z;
885
886 Vector3<double> origin = molgroup->min;
887
888 long gridvol = (long) size.volume();
889 Bmolecule* mol;
890 Bresidue* res;
891 Batom* atom;
892 Latom** alist = new Latom*[gridvol];
893 Latom** alistp = new Latom*[gridvol];
894
895 for ( i=0; i<gridvol; i++ ) alist[i] = alistp[i] = NULL;
896
897 for ( mol = molgroup->mol; mol; mol = mol->next ) {
898 for ( res = mol->res; res; res = res->next ) {
899 for ( atom = res->atom; atom; atom = atom->next ) {
900 x = (long) ((atom->coord[0] - origin[0])/sampling[0]);
901 y = (long) ((atom->coord[1] - origin[1])/sampling[1]);
902 z = (long) ((atom->coord[2] - origin[2])/sampling[2]);
903 if ( x < 0 ) x = 0;
904 if ( y < 0 ) y = 0;
905 if ( z < 0 ) z = 0;
906 if ( x >= size[0] ) x = size[0] - 1;
907 if ( y >= size[1] ) y = size[1] - 1;
908 if ( z >= size[2] ) z = size[2] - 1;
909 i = (z*size[1] + y)*size[0] + x;
910 alistp[i] = (Latom *) add_item((char **) &alistp[i], sizeof(Latom));
911 alistp[i]->atom = atom;
912 if ( !alist[i] ) alist[i] = alistp[i];
913 }
914 }
915 }
916
917 delete[] alistp;
918
919 if ( verbose & VERB_DEBUG )
920 cout << "DEBUG molgroup_atom_mesh_lists: Done!" << endl;
921
922 return alist;
923 }
924
931 Batom** atom_get_array(Bmolgroup* molgroup, long* natom)
932 {
933 long n;
934 Bmolecule* mol;
935 Bresidue* res;
936 Batom* atom;
937
938 for ( n=0, mol = molgroup->mol; mol; mol = mol->next )
939 for( res = mol->res; res; res = res->next )
940 for ( atom = res->atom; atom; atom = atom->next )
941 n++;
942
943 Batom** atomarray = new Batom*[n];
944
945 for ( n=0, mol = molgroup->mol; mol; mol = mol->next )
946 for( res = mol->res; res; res = res->next )
947 for ( atom = res->atom; atom; atom = atom->next )
948 atomarray[n++] = atom;
949
950 *natom = n;
951
952 return atomarray;
953 }
954
955
Bmolecule::id
Bstring id
Definition: rwmolecule.h:110
Bmolgroup::mol
Bmolecule * mol
Definition: rwmolecule.h:189
rwresprop.h
Header file for reading residue property files.
seq_util.h
Header file for sequence utilities.
molgroup_print_sequence
int molgroup_print_sequence(Bmolgroup *molgroup)
Prints the sequence of a molecule as a single letter code string.
Definition: mol_util.cpp:92
molgroup_rename
int molgroup_rename(Bmolgroup *molgroup, char first_name)
Renames molecules.
Definition: mol_util.cpp:161
Latom::next
Latom * next
Definition: mol_util.h:22
Vector3::normalize
double normalize()
Definition: Vector3.h:236
Vector3::length
double length()
Definition: Vector3.h:222
Latom
Definition: mol_util.h:21
molgroup_residue_renumber
int molgroup_residue_renumber(Bmolgroup *molgroup, int first)
Renumbers residues.
Definition: mol_util.cpp:182
Bmolecule::nres
long nres
Definition: rwmolecule.h:111
Latom::atom
Batom * atom
Definition: mol_util.h:23
utilities.h
Header file for general utilities.
get_atom_properties
Batomtype * get_atom_properties(Bstring &filename)
Reading atomic properties from parameter files.
Definition: rwatomprop.cpp:47
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Batomtype::next
Batomtype * next
Definition: rwatomprop.h:20
Bmolecule::res
Bresidue * res
Definition: rwmolecule.h:122
mol_center_of_mass
Vector3< double > mol_center_of_mass(Bmolecule *mol)
Calculates the center of mass of a molecule.
Definition: mol_util.cpp:401
molgroup_Bfactors
int molgroup_Bfactors(Bmolgroup *molgroup)
Calculates the average Bfactors for residues in molecules.
Definition: mol_util.cpp:28
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
molgroup_calculate_weight
double molgroup_calculate_weight(Bmolgroup *molgroup)
Calculates the weight of each molecule.
Definition: mol_util.cpp:270
Bresidue::insert
char insert[2]
Definition: rwmolecule.h:52
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
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:882
Bstring::length
long length() const
Definition: Bstring.cpp:263
molgroup_center_of_mass
Vector3< double > molgroup_center_of_mass(Bmolgroup *molgroup)
Calculates the center of mass of a molecule group.
Definition: mol_util.cpp:307
principal_axes
Vector3< double > principal_axes(Vector3< double > avg, Vector3< double > avg2, Vector3< double > avgx, Vector3< double > *eigenvec)
Calculates the principal axes of 3D coordinates.
Definition: matrix.cpp:706
Matrix.h
Generalized matrix class.
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
Bresidue::type
char type[6]
Definition: rwmolecule.h:53
Vector3::square_root
Vector3 square_root()
Definition: Vector3.h:229
molgroup_atom_renumber
int molgroup_atom_renumber(Bmolgroup *molgroup, int first)
Renumbers all atoms, disregarding molecule distinction.
Definition: mol_util.cpp:211
Batom::q
double q
Definition: rwmolecule.h:31
Batom::sel
int sel
Definition: rwmolecule.h:34
Bmolgroup::box
Vector3< double > box
Definition: rwmolecule.h:184
mol_util.h
Library routines used for atomic coordinates.
Batom::type
char type[8]
Definition: rwmolecule.h:28
Vector3::max
Type max()
Definition: Vector3.h:175
Batom::num
int num
Definition: rwmolecule.h:26
molgroup_selected_center_of_mass
Vector3< double > molgroup_selected_center_of_mass(Bmolgroup *molgroup)
Calculates the center of mass of a molecule group.
Definition: mol_util.cpp:347
Bmolecule::seq
Bstring seq
Definition: rwmolecule.h:114
linked_list.h
Header file for generalized linked list functions.
rwmolecule.h
Header file for reading reflection files.
Bmolgroup
Definition: rwmolecule.h:170
molgroup_stats
long molgroup_stats(Bmolgroup *molgroup, int show)
Calculates the statistics of a molecule group.
Definition: rwmolecule.cpp:1291
Batomtype
Definition: rwatomprop.h:19
rwatomprop.h
Header file for reading atom property files.
molgroup_density
double molgroup_density(Bmolgroup *molgroup)
Calculates the number and mass density of a molecular system.
Definition: mol_util.cpp:548
length
double length(vector< T > v)
Definition: Vector3.h:528
vector3_difference_PBC
Vector3< T1 > vector3_difference_PBC(Vector3< T1 > &v1, Vector3< T1 > &v2, Vector3< T2 > &box)
Definition: Vector3.h:695
Bmolecule::next
Bmolecule * next
Definition: rwmolecule.h:108
molgroup_show_center_of_mass
Vector3< double > molgroup_show_center_of_mass(Bmolgroup *molgroup)
Calculates the center of mass of a molecule group.
Definition: mol_util.cpp:387
Batom::b
double b
Definition: rwmolecule.h:31
Bmolgroup::max
Vector3< double > max
Definition: rwmolecule.h:183
Batomtype::z
int z
Definition: rwatomprop.h:21
Bresidue_type
Definition: rwresprop.h:22
molgroup_principal_axes
Vector3< double > molgroup_principal_axes(Bmolgroup *molgroup, Vector3< double > *eigenvec)
Calculates the principal axes of a molecule group.
Definition: mol_util.cpp:455
Bresidue::atom
Batom * atom
Definition: rwmolecule.h:54
Bmolecule
Definition: rwmolecule.h:107
molgroup_set_radius
int molgroup_set_radius(Bmolgroup *molgroup, double radius)
Shifts all coordinates to a given radius.
Definition: mol_util.cpp:114
Bresidue::next
Bresidue * next
Definition: rwmolecule.h:50
Bresidue
Definition: rwmolecule.h:49
volume
T volume(vector< T > v)
Definition: Vector3.h:545
mol_principal_axes
Vector3< double > mol_principal_axes(Bmolecule *mol, Vector3< double > *eigenvec)
Calculates the principal axes of a molecule.
Definition: mol_util.cpp:500
Bstring
Definition: Bstring.h:29
Batom
Definition: rwmolecule.h:24
get_residue_properties
Bresidue_type * get_residue_properties(Bstring &filename)
Reading residue properties from parameter files.
Definition: rwresprop.cpp:99
Batomtype::el
char el[4]
Definition: rwatomprop.h:22
Bmolecule::sel
int sel
Definition: rwmolecule.h:120
Vector3< double >
Bresidue::num
int num
Definition: rwmolecule.h:51
molgroup_composition
int molgroup_composition(Bmolgroup *molgroup, Bstring &paramfile)
Calculates the elemental composition of a molecular system.
Definition: mol_util.cpp:699
molgroup_radial_density
int molgroup_radial_density(Bmolgroup *molgroup, double interval, double cutoff, int wrap)
Calculates a radial distribution function.
Definition: mol_util.cpp:780
RHO
#define RHO
Definition: utilities.h:91
Batom::coord
Vector3< double > coord
Definition: rwmolecule.h:30
molgroup_coor_reset_occupancy
int molgroup_coor_reset_occupancy(Bmolgroup *molgroup, int range_first, int range_last, double occupancy)
Sets occupancies to new values..
Definition: mol_util.cpp:243
Bresidue_type::vol
float vol
Definition: rwresprop.h:27
verbose
int verbose
Batom::el
char el[4]
Definition: rwmolecule.h:27
Bmolgroup::min
Vector3< double > min
Definition: rwmolecule.h:182
atom_get_array
Batom ** atom_get_array(Bmolgroup *molgroup, long *natom)
Generates an array of pointers to atom structures.
Definition: mol_util.cpp:931
Batom::tnum
int tnum
Definition: rwmolecule.h:29
Vector3::volume
double volume()
Definition: Vector3.h:235
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
Batom::next
Batom * next
Definition: rwmolecule.h:25
Batom::mass
double mass
Definition: rwmolecule.h:32
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
mol_show_center_of_mass
Vector3< double > mol_show_center_of_mass(Bmolecule *mol)
Calculates the center of mass of a molecule.
Definition: mol_util.cpp:439
molgroup_volume
double molgroup_volume(Bmolgroup *molgroup, Bstring &paramfile, int wrap)
Calculates the volume of a molecular system.
Definition: mol_util.cpp:586
Bresidue_type::cod
char cod[3]
Definition: rwresprop.h:25
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Batomtype::vdw
float vdw
Definition: rwatomprop.h:27
Bresidue_type::next
Bresidue_type * next
Definition: rwresprop.h:23