38 for ( i=0; i<sym->
n; i++ ) nunits *= sym->
op[i].
order;
43 cout << endl <<
"Applying symmetry " << sym->
label <<
":" << endl;
44 cout <<
"Number of asymmetric units: " << nunits << endl;
45 cout <<
"Reference symmetry axis: {" <<
46 ref_view[0] <<
"," << ref_view[1] <<
"," << ref_view[2] <<
"}" << endl;
47 cout <<
"Reference rotation angle: " <<
48 ref_view.
angle()*180/
M_PI << endl << endl;
50 cout << endl <<
"Applying symmetry " << sym->
label << endl << endl;
71 for ( mol = molgroup->
mol; mol; mol = mol->
next ) nmol++;
73 for ( i=0; i<sym->
n; i++ ) {
74 new_axis = ref_mat * sym->
op[i].
axis;
75 for ( j=1; j<sym->
op[i].
order; j++ ) {
80 new_molgroup = new_molgroup->
next;
81 for ( mol = new_molgroup->
mol; mol; mol = mol->
next ) {
82 for( res = mol->
res; res; res = res->
next ) {
83 for ( atom = res->
atom; atom; atom = atom->
next ) {
90 bond = molgroup->
bond;
91 angle = molgroup->
angle;
92 for ( new_molgroup = molgroup->
next; new_molgroup; new_molgroup = new_molgroup->
next ) {
94 for ( ; mol->
next; mol = mol->
next ) ;
97 mol = molgroup->
mol = new_molgroup->
mol;
99 new_molgroup->
mol = NULL;
101 for ( ; bond->
next; bond = bond->
next ) ;
104 bond = molgroup->
bond = new_molgroup->
bond;
106 new_molgroup->
bond = NULL;
108 for ( ; angle->
next; angle = angle->
next ) ;
111 angle = molgroup->
angle = new_molgroup->
angle;
113 new_molgroup->
angle = NULL;
116 molgroup->
next = NULL;
117 new_molgroup = molgroup;
136 double helix_rise,
double helix_angle,
int gen_down,
int gen_up)
142 if ( gen_down < 0 ) gen_down = 0;
143 if ( gen_up < 0 ) gen_up = 0;
146 cout << endl <<
"Applying helical symmetry:" << endl;
147 cout <<
"Number of asymmetric units: " << gen_down + 1 + gen_up << endl;
148 cout <<
"Helical rise: " << helix_rise << endl;
149 cout <<
"Helical rotation angle: " << helix_angle*180/
M_PI << endl;
150 cout <<
"Reference symmetry axis: {" <<
151 ref_view[0] <<
"," << ref_view[1] <<
"," << ref_view[2] <<
"}" << endl << endl;
153 cout << endl <<
"Applying helical symmetry" << endl << endl;
169 for ( mg = molgroup, i=-gen_down; i<gen_up; i++, mg = mg->
next )
172 for ( mg = molgroup, i=-gen_down; i<=gen_up; i++, mg = mg->
next ) {
173 shift[2] = i*helix_rise;
174 mat =
Matrix3(axis, i*helix_angle);
177 for ( mol = mg->mol; mol; mol = mol->
next ) {
178 for( res = mol->
res; res; res = res->
next ) {
179 for ( atom = res->
atom; atom; atom = atom->
next ) {
181 atom->
coord += shift;
206 ifstream fpdb(filename.
c_str());
207 if ( fpdb.fail() )
return -1;
211 char aline[100], tag1[12], tag2[12], tag3[12], tag4[12];
214 while ( fpdb.getline(aline, 100) && fpdb.good() ) {
215 if ( strncmp(aline,
"REMARK 290 SMTRY", 18) == 0 ) {
216 if ( i==0 ) sscanf(aline,
"%s %s %s %s %lf %lf %lf %lf",
217 tag1, tag2, tag3, tag4, &mat[n][0][0], &mat[n][0][1], &mat[n][0][2], &trans[n][0]);
218 else if ( i==1 ) sscanf(aline,
"%s %s %s %s %lf %lf %lf %lf",
219 tag1, tag2, tag3, tag4, &mat[n][1][0], &mat[n][1][1], &mat[n][1][2], &trans[n][1]);
220 else sscanf(aline,
"%s %s %s %s %lf %lf %lf %lf",
221 tag1, tag2, tag3, tag4, &mat[n][2][0], &mat[n][2][1], &mat[n][2][2], &trans[n][2]);
223 if ( strstr(aline,
"SMTRY3") ) {
236 for ( mol = molgroup->
mol; mol; mol = mol->
next ) nmol++;
239 cout <<
"Extracting " << n <<
" matrices from " << filename <<
" and applying:" << endl;
241 for ( i=1; i<n; i++ ) {
243 cout <<
"Matrix " << i+1 <<
":" << endl;
244 cout << mat[i] << endl;
245 cout <<
"Shift: " << trans[i] << endl;
247 for ( m=0, mol = molgroup->
mol; m<nmol; mol = mol->next, m++ ) {
249 for( res = new_mol->
res; res; res = res->
next ) {
250 for ( atom = res->
atom; atom; atom = atom->
next ) {
252 atom->
coord += trans[i];
276 ifstream fpdb(filename.
c_str());
277 if ( fpdb.fail() )
return -1;
281 char aline[100], tag1[12], tag2[12], tag3[12], tag4[12];
284 while ( fpdb.getline(aline, 100) && fpdb.good() ) {
285 if ( strncmp(aline,
"REMARK 350 BIOMT", 18) == 0 ) {
286 if ( i==0 ) sscanf(aline,
"%s %s %s %s %lf %lf %lf %lf",
287 tag1, tag2, tag3, tag4, &mat[n][0][0], &mat[n][0][1], &mat[n][0][2], &trans[n][0]);
288 else if ( i==1 ) sscanf(aline,
"%s %s %s %s %lf %lf %lf %lf",
289 tag1, tag2, tag3, tag4, &mat[n][1][0], &mat[n][1][1], &mat[n][1][2], &trans[n][1]);
290 else sscanf(aline,
"%s %s %s %s %lf %lf %lf %lf",
291 tag1, tag2, tag3, tag4, &mat[n][2][0], &mat[n][2][1], &mat[n][2][2], &trans[n][2]);
293 if ( strstr(aline,
"BIOMT3") ) {
306 for ( mol = molgroup->
mol; mol; mol = mol->
next ) nmol++;
309 cout <<
"Extracting " << n <<
" matrices from " << filename <<
" and applying:" << endl;
311 for ( i=1; i<n; i++ ) {
313 cout <<
"Matrix " << i+1 <<
":" << endl;
314 cout << mat[i] << endl;
315 cout <<
"Shift: " << trans[i] << endl;
317 for ( m=0, mol = molgroup->
mol; m<nmol; mol = mol->next, m++ ) {
319 for( res = new_mol->
res; res; res = res->
next ) {
320 for ( atom = res->
atom; atom; atom = atom->
next ) {
322 atom->
coord += trans[i];
336 static int QsortMassCOM(
const void *x,
const void *y)
342 if ( c1->
mass < c2->
mass )
return 1;
370 int g, i, j, k, nmol, nunits, nmassif;
375 for ( nunits = 1, i=0; i<sym->
n; i++ ) nunits *= sym->
op[i].
order;
376 for ( nmol = 0, mol = molgroup->
mol; mol; mol = mol->
next ) nmol++;
378 if ( nmol < nunits ) {
379 cerr <<
"Error: Not enough molecules (" << nmol <<
") to fit into " << nunits <<
" asymmetric units!" << endl << endl;
384 double themass, themass2, maxmass(0);
386 for ( i=0; i<nmol; i++ ) c[i].com = c[i].mass = 0;
389 for ( i=0, mol = molgroup->
mol; mol; mol = mol->
next, i++ ) {
390 for( res = mol->
res; res; res = res->
next ) {
391 for ( atom = res->
atom; atom; atom = atom->
next ) {
400 if ( maxmass < c[i].mass ) maxmass = c[i].
mass;
404 qsort((
void *) c, nmol,
sizeof(
MassCOM), (
int (*)(
const void *,
const void *)) QsortMassCOM);
407 cout << endl <<
"Ordered list of centers-of-mass:" << endl;
408 cout <<
" x\t y\t z\tMass (Da)" << endl;
409 for ( i=0; i<nmol; i++ )
410 cout << c[i].com[0] <<
tab << c[i].com[1] <<
tab << c[i].com[2] <<
tab << c[i].mass << endl;
411 cout << endl << endl;
421 cout << endl <<
"Group\tMass\tStDev" << endl;
422 for ( i=0; i<nmol-nunits+1; i+=nunits ) {
423 themass = themass2 = 0;
425 for ( j=i; j<i+nunits; j++ ) {
426 themass += c[j].mass;
427 themass2 += c[j].mass*c[j].mass;
431 themass2 = themass2/nunits - themass*themass;
432 if ( themass2 > 0 ) themass2 = sqrt(themass2);
434 if ( themass > 100 && themass2/themass < 0.05 ) {
440 cout << ngroup <<
tab << themass <<
tab << themass2 << endl;
446 for ( i=0; i<nmassif; i++ ) com += c[i].com;
448 for ( i=0; i<nmassif; i++ ) c[i].com -= com;
451 int n(0), nvec = (ngroup*nunits*(nunits-1)*(nunits-2))/6;
457 cout << endl <<
"Group\tv1\tv2\tv3\tx\ty\tz" << endl;
458 for ( g=0; g<ngroup; g++ ) {
460 for ( i=2+nunits*g; i<nunits*(g+1); i++ ) {
461 for ( j=1+nunits*g; j<i; j++ ) {
462 v1 = c[i].com - c[j].com;
463 for ( k=nunits*g; k<j; k++ ) {
464 v2 = c[i].com - c[k].com;
470 << v[n][0] <<
tab << v[n][1] <<
tab << v[n][2] << endl;
478 cout <<
"DEBUG molgroup_find_standard_view: nvec=" << nvec <<
" n=" << n << endl;
481 int vbest = -1, m = 100;
482 int nx = 2*m, ny = 2*m, nz = 2;
483 int sv = nx * ny * nz;
484 int* nv =
new int[sv];
485 for ( i=0; i<sv; i++ ) nv[i] = 0;
487 for ( i=1; i<n; i++ ) {
488 for ( j=0; j<i; j++ ) {
491 a = fabs(v[i].angle(v[j]));
498 k = (int) (nx*(v1[1]+m)) + (
int) (v1[0]+m);
499 if ( k > nx*ny ) k = 0;
500 if ( v1[2] > 0 ) k += nx*ny;
502 if ( vbest < nv[k] ) {
511 for ( i=0; i<n; i++ ) {
512 a = fabs(axis.
angle(v[i]));
517 if ( a < 0.05 ) axis += v[i];
524 double ang(0), ang_min = 1000;
525 if ( sym->
point > 200 ) {
526 for ( i=1; i<nunits; i++ ) {
527 for ( j=0; j<i; j++ ) {
528 d = c[i].com - c[j].com;
530 if ( fabs(ang_min) > fabs(ang) ) {
532 v2 = c[i].com + c[j].com;
543 cout <<
"Angle with major axis: " << ang_min*180/
M_PI << endl;
544 cout <<
"Dihedral axis: " << v2 << endl;
545 cout <<
"Angle between axes: " << (axis.
angle(v2))*180/
M_PI << endl;
549 cout <<
"Translate: " << translate << endl;
550 cout <<
"Major symmetry axis: " << axis << endl;
551 if ( sym->
point > 200 )
552 cout <<
"Minor symmetry axis: " << v2 << endl;
558 View view(-axis[0], -axis[1], axis[2], 0);
560 if ( sym->
point > 200 ) {
565 view=
View(0, 0, 1, ang);
566 mat = view.
matrix() * mat;
570 cout <<
"Dihedral axis: " << v2 << endl;
571 cout <<
"Angle: " << ang*180.0/
M_PI << endl;
574 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
575 for( res = mol->
res; res; res = res->
next ) {
576 for ( atom = res->
atom; atom; atom = atom->
next ) {
577 atom->
coord += translate;
613 if ( sym->
point < 102 ) {
618 long i, j, k, m, nmol, nres_cut, cut_max(30), nunit, ngroup, nid, n2=0, nn=0, no;
624 for ( nunit = 1, i=m=0; i<sym->
n; i++ ) {
626 if ( m < sym->op[i].order ) m = sym->
op[i].
order;
629 double a, refang =
TWOPI/m;
631 for ( nmol = 0, mol = molgroup->
mol; mol; mol = mol->
next ) nmol++;
635 cerr <<
"Error: Not enough molecules (" << nmol <<
") to fit into " << nunit <<
" asymmetric units!" << endl << endl;
642 cout <<
"Orienting to the standard view for symmetry " << sym->
label << endl;
643 cout <<
"Number of molecules: " << nmol << endl;
644 cout <<
"Number of groups: " << ngroup << endl;
647 int* g =
new int[nmol];
648 for ( i=0; i<nmol; i++ ) g[i] = 0;
651 int offset, notfound;
654 for ( k=0, i=1; k<nmol; k++, i++, i=(i>ngroup)?1:i ) g[k] = i;
655 for ( i=0, mol = molgroup->
mol; mol->
next; mol = mol->
next, i++ ) {
656 nres_cut = mol->
nres/2;
657 if ( nres_cut > cut_max )
for ( j=i+1, mol2 = mol->
next; mol2; mol2 = mol2->
next, j++ ) {
660 if ( nid > cut_max || nid >= nres_cut ) {
669 no = (long) (a + 0.5);
671 for ( k=0, notfound=1; k<n2 && notfound; k++ ) {
672 if ( a2[k].angle(t.
axis) < 0.1 ) {
682 if ( fabs(a - no) < 0.03 ) {
683 for ( k=0, notfound=1; k<nn && notfound; k++ ) {
684 if ( an[k].angle(t.
axis) < 0.1 ) {
700 cout <<
"Num\tMol\tGroup\tLength" << endl;
701 for ( i=0, mol = molgroup->
mol; mol; mol = mol->
next, i++ )
702 cout << i+1 <<
tab << mol->
id <<
tab << g[i] <<
tab << mol->
nres << endl;
713 for ( k=0, dm=0; k<n2; k++ ) {
721 for ( k=0, dm=0; k<n2; k++ ) {
722 a = axis1.
angle(a2[k]);
723 if ( fabs(a -
M_PI_2) < 0.1 ) {
731 }
else if ( sym->
point == 432 ) {
733 for ( k=0, dm=0; k<nn; k++ ) {
741 for ( k=0, dm=0; k<nn; k++ ) {
742 a = axis1.
angle(an[k]);
743 if ( fabs(a -
M_PI_2) < 0.1 ) {
753 for ( k=0, dm=0; k<nn; k++ ) {
761 for ( k=0, dm=0; k<n2; k++ ) {
762 a = axis1.
angle(a2[k]);
763 if ( fabs(a -
M_PI_2) < 0.1 ) {
773 if ( axis1.
length() < 0.9 ) {
774 cerr <<
"Error: Major axis not found!" << endl;
778 cerr <<
"Error: Minor axis not found!" << endl;
789 if ( sym->
point < 200 ) {
790 cout <<
"Symmetry axis: " << axis1 << endl;
792 cout <<
"Major symmetry axis: " << axis1 << endl;
793 cout <<
"Minor symmetry axis: " << axis2 << endl;
801 if ( sym->
point > 200 ) {
806 for ( mol = molgroup->
mol; mol; mol = mol->
next ) {
807 for( res = mol->
res; res; res = res->
next ) {
808 for ( atom = res->
atom; atom; atom = atom->
next ) {
832 int i, j, k, l, n, nmol;
833 double d, mind, R(0);
839 for ( nmol=0, mol=molgroup->
mol; mol; mol=mol->
next ) nmol++;
843 for ( i=0, mol=molgroup->
mol; mol; mol=mol->
next, i++ )
846 for ( i=n=0; i<sym->
n; i++ ) {
847 for ( j=1; j<sym->
op[i].
order; j++ ) {
849 for ( k=0; k<nmol; k++ ) {
851 for ( mind=1e30, l=0; l<nmol; l++ ) {
853 if ( mind > d ) mind = d;
864 cout <<
"Symmetry RMSD: " << R <<
" A (" << n <<
")" << endl << endl;
885 long i, j, nmol(0), nsym(0);
886 double d, mind, R(0);
894 for ( nmol=0, mol=molgroup->
mol; mol; mol=mol->
next ) nmol++;
897 cout <<
"Calculating B-factors for symmetry " << sym->
label << endl;
902 for ( i=0, mol=molgroup->
mol; mol; mol=mol->
next, i++ ) {
904 for ( mind=1e30, j=0; j<nsym; j++ ) {
905 coms = mat[j] * com[i];
912 cout << mol->
id << endl << mat[mol->
sel] << endl;
916 molr = molgroup->
mol;
917 for( res = molr->
res; res; res = res->
next )
918 for ( atom = res->
atom; atom; atom = atom->
next ) {
924 for ( i=0, mol=molgroup->
mol; mol; mol=mol->
next, i++ ) {
925 for( res = mol->
res, resr = molr->
res; res; res = res->
next, resr = resr->
next ) {
926 for ( atom = res->
atom, atomr = resr->
atom; atom; atom = atom->
next, atomr = atomr->
next ) {
936 for( res = molr->
res; res; res = res->
next )
937 for ( atom = res->
atom; atom; atom = atom->
next )
941 for ( mol=molgroup->
mol->
next; mol; mol=mol->
next )
942 for( res = mol->
res, resr = molr->
res; res; res = res->
next, resr = resr->
next )
943 for ( atom = res->
atom, atomr = resr->
atom; atom; atom = atom->
next, atomr = atomr->
next )
965 if ( number.
volume() < 2 )
return 0;
968 cerr <<
"Error: Please specify the unit cell!" << endl;
972 int i, x, y, z, nmol(0);
979 Batom *atom, *newatom;
981 for ( nmol=0, mol = molgroup->
mol; mol; mol = mol->
next ) nmol++;
984 cout <<
"Generating new unit cells for " << nmol <<
" molecules:" << endl;
985 cout <<
"Number: " << number <<
" = " << (int)number.
volume() << endl;
988 for ( z=0; z<number[2]; z++ ) {
989 for ( y=0; y<number[1]; y++ ) {
990 for ( x=0; x<number[0]; x++ ) {
992 cout <<
"Generating unit cell: " << x <<
" " << y <<
" " << z << endl;
995 if ( x+y+z > 0 )
for ( i=0, mol = molgroup->
mol; i<nmol; mol = mol->next, i++ ) {
997 for ( res = mol->
res, newres = newmol->
res; res; res = res->
next, newres = newres->
next ) {
998 for ( atom = res->
atom, newatom = newres->
atom; atom; atom = atom->
next, newatom = newatom->
next ) {