38#include <boost/random.hpp>
41 typedef unsigned int uint;
45 typedef unsigned int uint;
52 double diff = ((
double *) a)[0] - ((
double *) b)[0];
62 double diff = ((
double *) a)[1] - ((
double *) b)[1];
72 double diff = ((
double *) a)[2] - ((
double *) b)[2];
82 double diff = ((
double *) a)[3] - ((
double *) b)[3];
93 double diff = *((
float *) a) - *((
float *) b);
103PointArray::PointArray()
119 points = (
double *) calloc(4 *
n,
sizeof(
double));
146 memset((
void *)
points, 0, 4 *
n *
sizeof(
double));
193if (
n==0)
return NULL;
201 for (j=i+1; j<
n; j++) {
203 ret->set_value_at(i,j,0,r);
204 ret->set_value_at(j,i,0,r);
209 float *data=ret->get_data();
210 for (i=0; i<
n; i++) qsort(&data[i*
n],
n,
sizeof(
float),
cmp_float);
220unsigned int n2=mx1->get_xsize();
222if (max_miss<0) max_miss=(float)mx0->get_attr(
"sigma")/10.0f;
227vector<int> ret(
n,-1);
228vector<float> rete(
n,0.0);
242 for (j=0; j<n2; j++) {
245 for (k=l=0; k<
n-1 && l<n2-1; k++,l++) {
246 float d1=fabs(mx0->get_value_at(k,i)-mx1->get_value_at(l,j));
247 float d2=fabs(mx0->get_value_at(k+1,i)-mx1->get_value_at(l,j));
248 float d3=fabs(mx0->get_value_at(k,i)-mx1->get_value_at(l+1,j));
249 float d4=fabs(mx0->get_value_at(k+1,i)-mx1->get_value_at(l+1,j));
250 if (d2<d1 && d4>d2) { l--;
continue; }
251 if (d3<d1 && d4>d3) { k--;
continue; }
257 if (d<bestd) { bestd=d; bestn=j; }
260 rete[i]=
static_cast<float>(bestd);
266 for (j=0; j<
n; j++) {
267 if (rete[i]>max_miss) { ret[i]=-1;
break; }
268 if (i==j || ret[i]!=ret[j] || ret[i]==-1)
continue;
269 if (rete[i]>rete[j]) { ret[i]=-1;
break; }
289for (i=0; i<match.size(); i++) {
290 if (match[i]==-1)
continue;
301for (i=j=0; i<match.size(); i++) {
302 if (match[i]==-1)
continue;
315ret->
set(0, 0, vx[1]);
316ret->
set(0, 1, vy[1]);
318ret->
set(1, 0, vx[2]);
319ret->
set(1, 1, vy[2]);
331 struct stat filestat;
332 stat(file, &filestat);
336 printf(
"PointArray::read_from_pdb(): try %4lu atoms first\n",
get_number_points());
339 FILE *fp = fopen(file,
"r");
341 fprintf(stderr,
"ERROR in PointArray::read_from_pdb(): cannot open file %s\n",file);
349 set<int> lines_set(begin(lines), end(lines));
351 while ((fgets(s, 200, fp) != NULL)) {
354 if(find(begin(lines_set), end(lines_set), line_num) == end(lines_set))
357 if (strncmp(s,
"ENDMDL", 6) == 0)
359 if (strncmp(s,
"ATOM", 4) != 0)
368 char ctt, ctt2 =
' ';
371 else if (s[12] ==
' ') {
412 fprintf(stderr,
"Unknown atom %c%c\n", ctt, ctt2);
419 sscanf(&s[28],
" %f %f %f", &
x, &
y, &z);
420 sscanf(&s[60],
" %f", &q);
426 printf(
"Atom %4lu: x,y,z = %8g,%8g,%8g\te = %g\n", count,
x,
y, z, e);
430 points[4 * count + 2] = z;
431 points[4 * count + 3] = e;
443 FILE *fp = fopen(file,
"w");
445 fprintf(fp,
"ATOM %5lu CA ALA A%4lu %8.3f%8.3f%8.3f%6.2f%6.2f%8s\n", i, i,
465 fprintf(stderr,
"Abnormal total value (%g) for PointArray, it should be >0\n", norm);
469 return FloatPoint(xc / norm, yc / norm, zc / norm);
477 points[i + 1] -= center[1];
478 points[i + 2] -= center[2];
484 double xmin, ymin, zmin;
485 double xmax, ymax, zmax;
503 return Region(xmin, ymin, zmin, xmax - xmin, ymax - ymin, zmax - zmin);
509 double rmax2 = rmax * rmax, rmin2 = rmin * rmin;
514 double x = tmp_points[i],
y = tmp_points[i + 1], z = tmp_points[i + 2], v =
516 double r2 =
x *
x +
y *
y + z * z;
517 if (r2 >= rmin2 && r2 <= rmax2) {
520 points[count * 4 + 2] = z;
521 points[count * 4 + 3] = v;
536 if (sym ==
"c1" || sym ==
"C1")
538 double alt0 = 0, alt1 = M_PI, alt2 = M_PI;
539 double az0 = 0, az1 = M_PI;
540 if (sym[0] ==
'c' || sym[0] ==
'C') {
541 int nsym = atoi(sym.c_str() + 1);
542 az1 = 2.0 * M_PI / nsym / 2.0;
544 else if (sym[0] ==
'd' || sym[0] ==
'D') {
545 int nsym = atoi(sym.c_str() + 1);
548 az1 = 2.0 * M_PI / nsym / 2.0;
550 else if (sym ==
"icos" || sym ==
"ICOS") {
551 alt1 = 0.652358139784368185995;
552 alt2 = 0.55357435889704525151;
553 az1 = 2.0 * M_PI / 5 / 2.0;
556 LOGERR(
"PointArray::set_to_asymmetric_unit(): sym = %s is not implemented yet",
561 printf(
"Sym %s: alt0 = %8g\talt1 = %8g\talt2 = %8g\taz0 = %8g\taz1 = %8g\n", sym.c_str(), alt0*180.0/M_PI, alt1*180.0/M_PI, alt2*180.0/M_PI, az0*180.0/M_PI, az1*180.0/M_PI);
568 double x = tmp_points[i],
y = tmp_points[i + 1], z = tmp_points[i + 2], v = tmp_points[i + 3];
569 double az = atan2(
y,
x);
570 double az_abs = fabs(az - az0);
571 if (az_abs < (az1 - az0)) {
572 double alt_max = alt1 + (alt2 - alt1) * az_abs / (az1 - az0);
573 double alt = acos(z /
sqrt(
x *
x +
y *
y + z * z));
574 if (alt < alt_max && alt >= alt0) {
576 printf(
"Point %3lu: x,y,z = %8g,%8g,%8g\taz = %8g\talt = %8g\n",i/4,
x,
y,z,az*180.0/M_PI, alt*180.0/M_PI);
580 points[count * 4 + 2] = z;
581 points[count * 4 + 3] = v;
596for (
unsigned int i=0; i<
n; i++) {
597 ret.push_back((
float)
points[i*4]);
598 ret.push_back((
float)
points[i*4+1]);
599 ret.push_back((
float)
points[i*4+2]);
607 for (
unsigned int i = 0; i < 4 *
n; i += 4) {
618 for (
unsigned int i = 0; i < 4 *
n; i += 4) {
645 for (
int s = 0; s < nsym; s++) {
646 int index = s * 4 * num;
647 for (
int i = 0; i < 4 * num; i += 4, index += 4) {
648 Vec3f v((
float)src[i],(
float)src[i+1],(
float)src[i+2]);
651 target[index+1]=v[1];
652 target[index+2]=v[2];
653 target[index+3]=src[i+3];
660 for (
unsigned int i=0; i<pts.size(); i++)
points[i]=pts[i];
669 int nx =
map->get_xsize(), ny =
map->get_ysize(), nz =
map->get_zsize();
670 size_t size = (size_t)nx * ny * nz;
672 float *pd = tmp_map->get_data();
673 for (
size_t i = 0; i < size; ++i) {
678 double pointvol = double (num_voxels) / double (num);
679 double gauss_real_width = pow(pointvol, 1. / 3.);
681 printf(
"Average point range radius = %g pixels for %d points from %d used voxels\n",
682 gauss_real_width, num, num_voxels);
685 double min_table_val = 1e-4;
686 double max_table_x =
sqrt(-
log(min_table_val));
688 double table_step_size = 1.;
689 double inv_table_step_size = 1.0 / table_step_size;
690 int table_size = int (max_table_x * gauss_real_width / (table_step_size) * 1.25) + 1;
691 double *table = (
double *) malloc(
sizeof(
double) * table_size);
692 for (
int i = 0; i < table_size; i++) {
693 double x = i * table_step_size / gauss_real_width;
694 table[i] = exp(-
x *
x);
697 int gbox = int (max_table_x * gauss_real_width);
702 for (
int count = 0; count < num; count++) {
705 for (
size_t i = 0; i < size; ++i) {
711 int iz = cmaxpos / (nx * ny), iy = (cmaxpos - iz * nx * ny) / nx, ix =
712 cmaxpos - iz * nx * ny - iy * nx;
720 printf(
"Point %d: val = %g\tat %d, %d, %d\n", count, cmax, ix, iy, iz);
723 int imin = ix - gbox, imax = ix + gbox;
724 int jmin = iy - gbox, jmax = iy + gbox;
725 int kmin = iz - gbox, kmax = iz + gbox;
739 for (
int k = kmin; k < kmax; ++k) {
740 int table_index_z = int (fabs(
double (k - iz)) * inv_table_step_size);
741 double zval = table[table_index_z];
742 size_t pd_index_z = k * nx * ny;
744 for (
int j = jmin; j < jmax; ++j) {
745 int table_index_y = int (fabs(
double (j - iy)) * inv_table_step_size);
746 double yval = table[table_index_y];
747 size_t pd_index = pd_index_z + j * nx + imin;
748 for (
int i = imin; i < imax; ++i, ++pd_index) {
749 int table_index_x = int (fabs(
double (i - ix)) * inv_table_step_size);
750 double xval = table[table_index_x];
752 pd[pd_index] -= (float)(cmax * zval * yval * xval);
754 pd[pd_index] *= (float)(1.0 - zval * yval * xval);
767 else if (mode ==
KMEANS) {
775 int nx =
map->get_xsize(), ny =
map->get_ysize(), nz =
map->get_zsize();
776 float *pd =
map->get_data();
780 printf(
"Start initial random seeding\n");
789 v = pd[z * nx * ny +
y * nx +
x];
791 printf(
"Trying Point %lu: val = %g\tat %d, %d, %d\tfrom map (%d,%d,%d)\n", i, v,
x,
794 }
while (v <= thresh);
796 points[4 * i + 1] = (double)
y;
797 points[4 * i + 2] = (double) z;
798 points[4 * i + 3] = (double) v;
800 printf(
"Point %lu: val = %g\tat %g, %g, %g\n", i,
points[4 * i + 3],
points[4 * i],
805 double min_dcen = 1e0;
807 int iter = 0, max_iter = 100;
810 printf(
"Iteration %3d, start\n", iter);
815 for (
int k = 0; k < nz; k++) {
816 for (
int j = 0; j < ny; j++) {
817 for (
int i = 0; i < nx; i++) {
818 size_t idx = k * nx * ny + j * nx + i;
819 if (pd[idx] > thresh) {
820 double min_dist = 1e60;
825 double z =
points[4 * s + 2];
827 (k - z) * (k - z) + (j -
y) * (j -
y) + (i -
x) * (i -
x);
828 if (dist < min_dist) {
833 tmp_points[4 * min_s] += i;
834 tmp_points[4 * min_s + 1] += j;
835 tmp_points[4 * min_s + 2] += k;
836 tmp_points[4 * min_s + 3] += 1.0;
842 printf(
"Iteration %3d, finished reassigning segments\n", iter);
847 if (tmp_points[4 * s + 3]) {
848 tmp_points[4 * s] /= tmp_points[4 * s + 3];
849 tmp_points[4 * s + 1] /= tmp_points[4 * s + 3];
850 tmp_points[4 * s + 2] /= tmp_points[4 * s + 3];
852 printf(
"Iteration %3d, Point %3lu at %8g, %8g, %8g -> %8g, %8g, %8g\n", iter, s,
854 tmp_points[4 * s + 1], tmp_points[4 * s + 2]);
864 v = pd[z * nx * ny +
y * nx +
x];
865 }
while (v <= thresh);
866 tmp_points[4 * s] = (double)
x;
867 tmp_points[4 * s + 1] = (double)
y;
868 tmp_points[4 * s + 2] = (double) z;
869 tmp_points[4 * s + 3] = (double) v;
872 (
"Iteration %3d, Point %3lu reseeded from %8g, %8g, %8g -> %8g, %8g, %8g\n",
874 tmp_points[4 * s], tmp_points[4 * s + 1], tmp_points[4 * s + 2]);
877 double dx = tmp_points[4 * s] -
points[4 * s];
878 double dy = tmp_points[4 * s + 1] -
points[4 * s + 1];
879 double dz = tmp_points[4 * s + 2] -
points[4 * s + 2];
880 dcen += dx * dx + dy * dy + dz * dz;
885 printf(
"before swap: points = %ld\ttmp_points = %ld\n", (
long)
get_points_array(),
893 printf(
"after swap: points = %ld\ttmp_points = %ld\n", (
long)
get_points_array(),
895 printf(
"Iteration %3d, finished updating segment centers with dcen = %g pixels\n", iter,
900 }
while (dcen > min_dcen && iter <= max_iter);
906 LOGERR(
"PointArray::set_from_density_map(): mode = %d is not implemented yet", mode);
909 int nx =
map->get_xsize(), ny =
map->get_ysize(), nz =
map->get_zsize();
910 float origx, origy, origz;
912 origx =
map->get_attr(
"origin_x");
913 origy =
map->get_attr(
"origin_y");
914 origz =
map->get_attr(
"origin_z");
917 origx = -nx / 2 *
apix;
918 origy = -ny / 2 *
apix;
919 origz = -nz / 2 *
apix;
923 printf(
"Apix = %g\torigin x,y,z = %8g,%8g,%8g\n",
apix, origx, origy, origz);
926 float *pd =
map->get_data();
929 printf(
"Point %4lu: x,y,z,v = %8g,%8g,%8g,%8g",i,
points[4 * i],
points[4 * i + 1],
points[4 * i + 2],
points[4 * i + 3]);
932 pd[(int)
points[4 * i + 2] * nx * ny + (
int)
points[4 * i + 1] * nx +
946 if (!
adist)
adist=(
double *)malloc(
sizeof(
double)*
n);
947 if (!
aang)
aang=(
double *)malloc(
sizeof(
double)*
n);
950 for (
size_t ii=0; ii<
n; ii++) {
952 int ib=4*((ii+
n-1)%
n);
953 int ibb=4*((ii+
n-2)%
n);
967 else if (
aang[ii]<=-1.0)
aang[ii]=M_PI;
975 if (denom==0)
adihed[ii]=0;
977 double tmp=cr1.
dot(cr2)/(denom);
1015 int ib=4*((i+
n-1)%
n);
1016 int ibb=4*((i+
n-2)%
n);
1026 double ang=b.
dot(c);
1029 if (ang>1.0) ang=1.0;
1030 if (ang<-1.0) ang=-1.0;
1041 if (denom==0) dihed=
adihed[i];
1043 dihed=cr1.
dot(cr2)/denom;
1044 if (dihed>1.0) dihed=1.0;
1045 if (dihed<-1.0) dihed=-1.0;
1051 double mindist=10000;
1052 for (
size_t j=0;j<
n;j++){
1098 for(
size_t i=0; i<
n; i++){
1110 double pot=0.,potx=0.,poty=0.,potz=0.;
1116 points[i*4]=old[0]+stepsz;
1121 points[i*4+1]=old[1]+stepsz;
1126 points[i*4+2]=old[2]+stepsz;
1136 return Vec3f((pot-potx),(pot-poty),(pot-potz));
1141 vector<Vec3f> shifts;
1145 for (
size_t i=0; i<
n; i++) {
1148 float len=shifts[i].length();
1149 if (len>max) max=len;
1156 for (
size_t i=0; i<
n; i++) {
1158 points[i*4]+=shifts[i][0]*maxshift/max;
1159 points[i*4+1]+=shifts[i][1]*maxshift/max;
1160 points[i*4+2]+=shifts[i][2]*maxshift/max;
1204 for (
int i=0; i<10; i++) {
1210 double stepadj=meanshift/mean;
1218 for (
size_t ii=0; ii<
n; ii++) {
1219 size_t i=2*(ii%(
n/2))+2*ii/
n;
1223 shift=(d+oshifts)/2.0;
1237 points[i*4]+=shift[0]*stepadj;
1238 points[i*4+1]+=shift[1]*stepadj;
1240 points[i*4+2]+=shift[2]*stepadj;
1250 double meandist=0.0;
1251 double max=0.0,min=
dist0*1000.0;
1253 for (
size_t ii=0; ii<
n; ii++) {
1254 int ib=4*((ii+
n-1)%
n);
1260 max=len>max?len:max;
1261 min=len<min?len:min;
1264 double scale=
dist0/meandist;
1266 printf(
"mean = %1.3f rescaled: %1.3f - %1.3f\n",meandist,min*scale,max*scale);
1268 for (
size_t i=0; i<
n; i++) {
1278 double mdist=0.0,mang=0.0,mdihed=0.0;
1279 double midist=1000.0,miang=M_PI*2,midihed=M_PI*2;
1280 double madist=0.0,maang=0.0,madihed=0.0;
1283 for (
size_t i=0; i<
n; i++) {
1290 for (
size_t i=0; i<
n; i++) {
1307 double anorm = 180.0/M_PI;
1308 printf(
" potential: %1.1f\t map: %1.2f\tdist: %1.2f || %1.2f / %1.2f / %1.2f\tang: %1.2f / %1.2f / %1.2f\tdihed: %1.2f / %1.2f / %1.2f ln=%1.1f\n",p,mmap,
dist0,midist,mdist/
n,madist,miang*anorm,mang/
n*anorm,maang*anorm,midihed*anorm,mdihed/
n*anorm,madihed*anorm,mdihed/(M_PI*2.0)-
n/10.0);
1320 if (pmap!=0 && pmap!=
map) {
1328 if (
map->get_zsize()==1)
1350 double* pa2data=(
double *) calloc(4 * nn,
sizeof(
double));
1351 bool *newpt=
new bool[nn];
1352 for (
int i=0;i<nn;i++){
1359 for (
int ii=0;ii<nn;ii++){
1362 pa2data[ii*4]=
points[i*4];
1363 pa2data[ii*4+1]=
points[i*4+1];
1364 pa2data[ii*4+2]=
points[i*4+2];
1397 double maxpot=-1000000,pot,meanpot=0;
1401 for (
size_t i=0; i<
n; i++) {
1411 for (
size_t i=0; i<
n; i++) {
1427 double* pa2data=(
double *) calloc(4 * (
n+1),
sizeof(double));
1428 for (
size_t ii=0; ii<
n+1; ii++) {
1429 if(ii!=ipt && ii!=ipt+1){
1435 pa2data[ii*4]=
points[i*4];
1436 pa2data[ii*4+1]=
points[i*4+1];
1437 pa2data[ii*4+2]=
points[i*4+2];
1446 pa2data[ipt*4]=
points[ipt*4];
1447 pa2data[ipt*4+1]=
points[ipt*4+1];
1448 pa2data[ipt*4+2]=
points[ipt*4+2];
1452 pa2data[(ipt+1)*4+1]=(
points[ipt*4+1]+
points[k1*4+1])/2;
1453 pa2data[(ipt+1)*4+2]=(
points[ipt*4+2]+
points[k1*4+2])/2;
1454 pa2data[(ipt+1)*4+3]=1;
1467 pa2data[(ipt+1)*4+1]=(
points[ipt*4+1]+
points[k1*4+1])/2;
1468 pa2data[(ipt+1)*4+2]=(
points[ipt*4+2]+
points[k1*4+2])/2;
1469 pa2data[(ipt+1)*4+3]=1;
1485 double bestpot=10000,nowpot;
1488 for (
int ii=0;ii<5000;ii++){
1491 boost::normal_distribution<> nd(0.0, 0.0);
1492 boost::variate_generator<boost::mt19937&,boost::normal_distribution<> > var_nor(rng, nd);
1493 points[i*4]=old[0]+var_nor();
1494 points[i*4+1]=old[1]+var_nor();
1495 points[i*4+2]=old[2]+var_nor();
1497 if (nowpot<bestpot) {
1500 newpt[1]=
points[(i+1)*4];
1501 newpt[2]=
points[(i+2)*4];
1513 for (
int i=0; i<3; i++) mean[i]=0;
1514 for (
int i=start; i<end; i++){
1515 for (
int j=0; j<3; j++){
1519 for (
int i=0; i<3; i++) mean[i]/=end-start;
1521 for (
int i=0; i<3; i++){
1522 for (
int j=0; j<3; j++){
1528 for (
int k=start; k<end; k++)
1548 vector<float> result(pts);
1549 for (
size_t i=0; i<pts.size(); i++)
1551 for (
size_t i=(num-1)/2; i<pts.size()-(num-1)/2; i++){
1552 for (
int j=0; j<num; j++){
1553 int k=i+j-(num-1)/2;
1554 result[i]+=pts[k]*ft[j];
1562 vector<float> hlxlen(
n);
1565 float ft[7]={0.0044,0.0540,0.2420,0.3989,0.2420,0.0540,0.0044};
1569 for (
int dir=twodir; dir<2; dir++){
1573 for (
size_t i=0; i<
n; i++){
1574 vector<float> dist(50);
1576 for (
int len=5; len<50; len++){
1580 vector<float> pts((len+1)*3);
1582 for (
int k=0; k<3; k++) mean[k]=0;
1583 for (
size_t k=i; k<pos; k++){
1584 for (
int l=0; l<3; l++){
1586 mean[l]+=pts[(k-i)*3+l];
1589 for (
int k=0; k<3; k++) mean[k]/=len;
1592 for (
int k=0; k<len; k++){
1593 dst+=abs((pts[k*3]-mean[0])*(pts[k*3]-mean[0])+(pts[k*3+1]-mean[1])*(pts[k*3+1]-mean[1]));
1595 dist[len]=1-dst/len/len;
1601 for (
int j=7; j<49; j++){
1602 if(nd[j]>nd[j-1] && nd[j]>nd[j+1]){
1608 if(hlxlen[i]>25) hlxlen[i]=0;
1615 vector<float> ishlx(
n);
1619 for (
size_t i=0; i<
n; i++){
1624 helix.push_back(i+hlxlen[i]-5);
1634 for (
size_t i=0; i<helix.size(); i++) helix[i]=
n-1-helix[i];
1635 for (
size_t i=0; i<helix.size()/2; i++){
1636 int tmp=helix[i*2+1];
1637 helix[i*2+1]=helix[i*2];
1645 printf(
"potential helix counting from both sides: \n");
1646 for (
size_t i=0; i<helix.size()/2; i++){
1647 printf(
"%d\t%d\n",helix[i*2],helix[i*2+1]);
1676 for (
size_t i=0;i<helix.size()/2; i++){
1677 if(helix[i*2]<.1)
continue;
1678 if(helix[i*2]<mins){
1684 allhlx.push_back(helix[minid*2]);
1685 allhlx.push_back(helix[minid*2+1]);
1691 printf(
"combined result: \n");
1692 for (
size_t i=0; i<allhlx.size()/2; i++){
1693 printf(
"%d\t%d\n",allhlx[i*2],allhlx[i*2+1]);
1700 for (
size_t i=0; i<allhlx.size()/2; i++){
1702 size_t start=allhlx[i*2]-sz,end=allhlx[i*2+1]+sz;
1703 start=start>0?start:0;
1705 float minscr=100000;
1708 for (
size_t j=start; j<end; j++){
1709 for (
size_t k=j+6; k<end; k++){
1711 vector<float> pts((k-j)*3);
1713 for (
int u=0; u<3; u++) mean[u]=0;
1714 for (
size_t u=j; u<k; u++){
1715 for (
int v=0; v<3; v++){
1717 mean[v]+=pts[(u-j)*3+v];
1720 for (
size_t u=0; u<3; u++) mean[u]/=(k-j);
1723 for (
size_t u=0; u<k-j; u++){
1724 dst+=
sqrt((pts[u*3]-mean[0])*(pts[u*3]-mean[0])+(pts[u*3+1]-mean[1])*(pts[u*3+1]-mean[1]));
1727 float scr=dst/len/len;
1746 for (
size_t i=0; i<edge.size()/2; i++){
1747 allhlx.push_back(edge[i*2]);
1748 allhlx.push_back(edge[i*2+1]);
1751 vector<int> allhlx2;
1756 for (
size_t i=0;i<allhlx.size()/2; i++){
1757 if(allhlx[i*2]<.1)
continue;
1758 if(allhlx[i*2]<mins){
1764 allhlx2.push_back(allhlx[minid*2]<allhlx[minid*2+1]?allhlx[minid*2]:allhlx[minid*2+1]);
1765 allhlx2.push_back(allhlx[minid*2]>allhlx[minid*2+1]?allhlx[minid*2]:allhlx[minid*2+1]);
1772 printf(
"Fitted helixes: \n");
1773 for (
size_t i=0; i<allhlx.size()/2; i++){
1774 printf(
"%d\t%d\n",allhlx[i*2],allhlx[i*2+1]);
1781 vector<double> finalhlx;
1782 vector<double> hlxid;
1783 printf(
"Confirming helix... \n");
1785 if (
int(ia)==allhlx[ka*2]){
1788 float score=0,maxscr=0;
1789 float bestphs=0,phsscore=0,pscore=0;
1791 for (
int i=0; i<sz; i++){
1792 for (
int j=0; j<sz; j++){
1793 int start=allhlx[ka*2]+i,end=allhlx[ka*2+1]-j;
1794 phsscore=0;bestphs=-1;
1795 for (
float phs=-180; phs<180; phs+=10){
1797 if (pscore>phsscore){
1811 int start=allhlx[ka*2]+mi,end=allhlx[ka*2+1]-mj;
1812 printf(
"%d\t%d\t%f\tden %d\t",start,end,maxscr,maxscr>mindensity);
1813 if (maxscr>mindensity){
1815 for (
float phs=-180; phs<180; phs+=10){
1817 if (pscore>phsscore){
1823 int lendiff=end-start-pts.size()/3-2;
1824 printf(
"dir %d\t",dir);
1825 printf(
"len %lu\t diff %d\t",pts.size()/3-2,lendiff);
1826 if (pts.size()/3-2>minl && abs(lendiff)<15){
1828 for (
int i=0; i<mi; i++){
1829 finalhlx.push_back(
points[(i+ia)*4]);
1830 finalhlx.push_back(
points[(i+ia)*4+1]);
1831 finalhlx.push_back(
points[(i+ia)*4+2]);
1833 hlxid.push_back(finalhlx.size()/3+1);
1834 printf(
"%lu\t",finalhlx.size()/3+1);
1835 for (
size_t j=3; j<pts.size()-3; j++)
1836 finalhlx.push_back(pts[j]);
1837 hlxid.push_back(finalhlx.size()/3-2);
1838 printf(
"%lu\t",finalhlx.size()/3-2);
1839 for (
size_t j=0; j<3; j++)
1840 hlxid.push_back(pts[j]);
1841 for (
size_t j=pts.size()-3; j<pts.size(); j++)
1842 hlxid.push_back(pts[j]);
1853 while(allhlx[ka*2]<
int(ia))
1858 finalhlx.push_back(
points[ia*4]);
1859 finalhlx.push_back(
points[ia*4+1]);
1860 finalhlx.push_back(
points[ia*4+2]);
1867 for (
size_t i=0; i<
n; i++){
1868 for (
size_t j=0; j<3; j++)
1869 points[i*4+j]=finalhlx[i*3+j];
1884 vector<double> helix(nh*3);
1891 for(
int i=0; i<3; i++){
1892 if(abs(
eigval[i])>maxeigv){
1899 vector<double> pts(nh*3);
1900 for (
int dd=0; dd<2; dd++){
1904 helix[0]=0;helix[1]=0;helix[2]=0;
1905 helix[nh*3-3]=.0;helix[nh*3-2]=0;helix[nh*3-1]=len;
1907 for (
int i=0; i<nh-2; i++){
1909 helix[(i+1)*3+0]=cos(((phs+(100*i))*M_PI)/180)*2.3;
1910 helix[(i+1)*3+1]=sin(((phs+(100*i))*M_PI)/180)*2.3;
1913 helix[(i+1)*3+1]=cos(((phs+(100*i))*M_PI)/180)*2.3;
1914 helix[(i+1)*3+0]=sin(((phs+(100*i))*M_PI)/180)*2.3;
1916 helix[(i+1)*3+2]=i*1.54;
1920 for (
int k=0; k<3; k++) mean[k]=0;
1921 for (
int k=0; k<nh; k++){
1922 for (
int l=0; l<3; l++){
1923 pts[k*3+l]=helix[k*3+0]*
eigvec[0*3+l]+helix[k*3+1]*
eigvec[1*3+l]+helix[k*3+2]*
eigvec[2*3+l];
1924 mean[l]+=pts[k*3+l];
1927 for (
int k=0; k<3; k++) mean[k]/=nh;
1928 for (
int k=0; k<nh; k++){
1929 for (
int l=0; l<3; l++){
1930 pts[k*3+l]-=mean[l];
1933 for (
int k=0; k<3; k++) mean[k]=0;
1934 for (
int k=start; k<end; k++){
1935 for (
int l=0; l<3; l++){
1939 for (
int k=0; k<3; k++) mean[k]/=(end-start);
1940 for (
int k=0; k<nh; k++){
1941 for (
int l=0; l<3; l++){
1942 pts[k*3+l]+=mean[l];
1953 for (
int i=0; i<nh/2; i++){
1954 for(
int j=0; j<3; j++){
1956 pts[i*3+j]=pts[(nh-i-1)*3+j];
1957 pts[(nh-i-1)*3+j]=tmp;
1975 float ax=
map->get_attr(
"apix_x"),ay=
map->get_attr(
"apix_y"),az=
map->get_attr(
"apix_z");
1978 for (
int i=1; i<nh-1; i++){
1980 score+=ind*
map->get_value_at(
int(pts[i*3]/ax+sx/2),
int(pts[i*3+1]/ay+sy/2),
int(pts[i*3+2]/az+sz/2));
2003 printf(
"merging\n");
2004 vector<double> result;
2005 for (
size_t i=0; i<pa.
n; i++){
2006 result.push_back(pa.
points[i*4]);
2007 result.push_back(pa.
points[i*4+1]);
2008 result.push_back(pa.
points[i*4+2]);
2010 for (
size_t i=0; i<
n; i++){
2012 for (
size_t j=0; j<pa.
n; j++){
2018 printf(
"%f\n",dist);
2020 result.push_back(
points[i*4]);
2021 result.push_back(
points[i*4+1]);
2022 result.push_back(
points[i*4+2]);
2026 for (
size_t i=0; i<
n; i++){
2027 for (
size_t j=0; j<3; j++)
2028 points[i*4+j]=result[i*3+j];
2037 vector<double> vpoint(npt-3);
2038 for (
int i=0; i<npt-3; i++){
2039 vpoint[i]=pts[i+3]-pts[i];
2041 Vec3f hlxdir(pts[npt-3]-pts[0],pts[npt-2]-pts[1],pts[npt-1]-pts[2]);
2043 for (
int i=0; i<npt/3-2; i++){
2044 Vec3f v0(vpoint[i*3],vpoint[i*3+1],vpoint[i*3+2]);
2045 Vec3f v1(vpoint[i*3+3],vpoint[i*3+4],vpoint[i*3+5]);
2050 return hlxdir.
dot(vcs);
2056 FILE *fp = fopen(file,
"w");
2058 for (
size_t i=0; i<hlxid.size()/8; i++){
2059 fprintf(fp,
"HELIX%5lu A ALA A%5d ALA A%5d 1 %5d\n",
2060 i, (
int)hlxid[i*8], (
int)hlxid[i*8+1],
int(hlxid[i*8+1]-hlxid[i*8]+4));
2063 fprintf(fp,
"ATOM %5lu CA ALA A%4lu %8.3f%8.3f%8.3f%6.2f%6.2f%8s\n", i, i,
2073 int sx=m->get_xsize(),sy=m->get_ysize(),sz=m->get_zsize();
2074 float ax=m->get_attr(
"apix_x"),ay=m->get_attr(
"apix_y"),az=m->get_attr(
"apix_z");
2075 for (
int x=0;
x<sx;
x++){
2076 for (
int y=0;
y<sy;
y++){
2077 for (
int z=0; z<sz; z++){
2078 Vec3f p0((
x)*ax,(
y)*ay,(z)*az);
2080 for (
size_t i=0; i<hlxid.size()/8; i++){
2081 Vec3f p1(hlxid[i*8+2],hlxid[i*8+3],hlxid[i*8+4]),p2(hlxid[i*8+5],hlxid[i*8+6],hlxid[i*8+7]);
2085 float t=-(p1-p0).
dot(p2-p1)/(l*l);
2086 if (d<5 && t>0 && t<1){
2092 m->set_value_at(
x,
y,z,0);
2107 t.
set_trans(c1[0]-c2[0],c1[1]-c2[1],c1[2]-c2[2]);
2123 Vec3f eahatcp(eahat);
2124 Vec3f ebhatcp(ebhat);
2125 Vec3f eAhatcp(eAhat);
2126 Vec3f eBhatcp(eBhat);
2133 Vec3f aMinusA(eahatcp);
2135 Vec3f bMinusB(ebhatcp);
2140 float aAlength = aMinusA.
length();
2141 float bBlength = bMinusB.
length();
2144 }
else if (bBlength==0){
2147 nhat= aMinusA.
cross(bMinusB);
2158 double cosomegaA = (neahat.
dot(neAhat)) / (neahat.
dot(neahat));
2160 double sinomegaA = (neahat.
dot(eAhatcp)) / (neahat.
dot(neahat));
2163 double omegaA = atan2(sinomegaA,cosomegaA);
2166 rotation[
"type"]=
"spin";
2167 rotation[
"n1"]= nhat[0];
2168 rotation[
"n2"]= nhat[1];
2169 rotation[
"n3"]= nhat[2];
2170 rotation[
"omega"] = (float)(omegaA*180.0/M_PI);
2181 for(
size_t i=0; i<
n/2; i++){
2182 for (
size_t j=0; j<4; j++){
2191 for (
size_t i=
id*4; i<
n*4; i++){
2199 struct stat filestat;
2200 stat(file, &filestat);
2204 printf(
"PointArray::read_from_pdb(): try %4lu atoms first\n",
get_number_points());
2207 FILE *fp = fopen(file,
"r");
2209 fprintf(stderr,
"ERROR in PointArray::read_from_pdb(): cannot open file %s\n",file);
2215 while ((fgets(s, 200, fp) != NULL)) {
2216 if (strncmp(s,
"ENDMDL", 6) == 0)
2218 if (strncmp(s,
"ATOM", 4) != 0)
2227 char ctt, ctt2 =
' ';
2230 else if (s[12] ==
' ') {
2238 if (ctt !=
'C' || ctt2 !=
'A')
2242 sscanf(&s[28],
" %f %f %f", &
x, &
y, &z);
2243 sscanf(&s[60],
" %f", &q);
2249 printf(
"Atom %4lu: x,y,z = %8g,%8g,%8g\te = %g\n", count,
x,
y, z, e);
2253 points[4 * count + 2] = z;
2254 points[4 * count + 3] = e;
2279 printf(
"PointArray::pdb2mrc_by_summation(): %lu points\tmapsize = %4d\tapix = %g\tres = %g\n",
get_number_points(),map_size,
apix, res);
2283 double min_table_val = 1e-7;
2284 double max_table_x =
sqrt(-
log(min_table_val));
2286 double table_step_size = 0.001;
2287 double inv_table_step_size = 1.0 / table_step_size;
2292 map->set_size(map_size, map_size, map_size);
2294 float *pd =
map->get_data();
2296 vector<double> table;
2297 double gauss_real_width;
2303 double xc =
points[4 * s] /
apix + map_size / 2;
2304 double yc =
points[4 * s + 1] /
apix + map_size / 2;
2305 double zc =
points[4 * s + 2] /
apix + map_size / 2;
2306 double fval =
points[4 * s + 3];
2310 if(addpdbbfactor==-1){
2311 gauss_real_width = res/M_PI;
2313 gauss_real_width = (
bfactor[s])/(4*
sqrt(2.0)*M_PI);
2316 table_size = int (max_table_x * gauss_real_width / (
apix * table_step_size) * 1.25);
2317 table.resize(table_size);
2318 for (
int i = 0; i < table_size; i++){
2322 for (
int i = 0; i < table_size; i++) {
2323 double x = -i * table_step_size *
apix / gauss_real_width;
2324 if(addpdbbfactor==-1){
2325 table[i] = exp(-
x *
x);
2328 table[i] = exp(-
x *
x)/
sqrt(gauss_real_width * gauss_real_width * 2 * M_PI);
2332 gbox = int (max_table_x * gauss_real_width /
apix);
2336 int imin = int (xc) - gbox, imax = int (xc) + gbox;
2337 int jmin = int (yc) - gbox, jmax = int (yc) + gbox;
2338 int kmin = int (zc) - gbox, kmax = int (zc) + gbox;
2345 if (imax > map_size)
2347 if (jmax > map_size)
2349 if (kmax > map_size)
2352 for (
int k = kmin; k < kmax; k++) {
2353 size_t table_index_z = size_t (fabs(k - zc) * inv_table_step_size);
2354 if ( table_index_z >= table.size() )
continue;
2355 double zval = table[table_index_z];
2356 size_t pd_index_z = k * map_size * map_size;
2358 for (
int j = jmin; j < jmax; j++) {
2359 size_t table_index_y = size_t (fabs(j - yc) * inv_table_step_size);
2360 if ( table_index_y >= table.size() )
continue;
2361 double yval = table[table_index_y];
2362 size_t pd_index = pd_index_z + j * map_size + imin;
2363 for (
int i = imin; i < imax; i++, pd_index++) {
2364 size_t table_index_x = size_t (fabs(i - xc) * inv_table_step_size);
2365 if ( table_index_x >= table.size() )
continue;
2366 double xval = table[table_index_x];
2367 pd[pd_index] += (float) (fval * zval * yval * xval);
2374 map->set_attr(
"apix_x",
apix);
2375 map->set_attr(
"apix_y",
apix);
2376 map->set_attr(
"apix_z",
apix);
2377 map->set_attr(
"origin_x", -map_size/2*
apix);
2378 map->set_attr(
"origin_y", -map_size/2*
apix);
2379 map->set_attr(
"origin_z", -map_size/2*
apix);
2387 double gauss_real_width = res / (M_PI);
2390 double min_table_val = 1e-7;
2391 double max_table_x =
sqrt(-
log(min_table_val));
2398 double table_step_size = 0.001;
2399 double inv_table_step_size = 1.0 / table_step_size;
2400 int table_size = int (max_table_x * gauss_real_width / (
apix * table_step_size) * 1.25);
2401 double *table = (
double *) malloc(
sizeof(
double) * table_size);
2402 for (
int i = 0; i < table_size; i++) {
2403 double x = -i * table_step_size *
apix / gauss_real_width;
2404 table[i] = exp(-
x *
x);
2407 int gbox = int (max_table_x * gauss_real_width /
apix);
2411 proj->set_size(image_size, image_size, 1);
2413 float *pd = proj->get_data();
2415 double xc =
points[4 * s] /
apix + image_size / 2;
2416 double yc =
points[4 * s + 1] /
apix + image_size / 2;
2417 double fval =
points[4 * s + 3];
2418 int imin = int (xc) - gbox, imax = int (xc) + gbox;
2419 int jmin = int (yc) - gbox, jmax = int (yc) + gbox;
2424 if (imax > image_size)
2426 if (jmax > image_size)
2429 for (
int j = jmin; j < jmax; j++) {
2431 int table_index_y = int (fabs(j - yc) * inv_table_step_size);
2432 double yval = table[table_index_y];
2437 int pd_index = j * image_size + imin;
2438 for (
int i = imin; i < imax; i++, pd_index++) {
2440 int table_index_x = int (fabs(i - xc) * inv_table_step_size);
2441 double xval = table[table_index_x];
2446 pd[pd_index] += (float)(fval * yval * xval);
2450 for (
int i = 0; i < image_size * image_size; i++)
2451 pd[i] /=
sqrt(M_PI);
2458 double gauss_real_width = res / (M_PI);
2460 double min_table_val = 1e-7;
2461 double max_table_x =
sqrt(-
log(min_table_val));
2463 double table_step_size = 0.001;
2464 double inv_table_step_size = 1.0 / table_step_size;
2465 int table_size = int (max_table_x * gauss_real_width / (
apix * table_step_size) * 1.25);
2466 double *table = (
double *) malloc(
sizeof(
double) * table_size);
2467 for (
int i = 0; i < table_size; i++) {
2468 double x = -i * table_step_size *
apix / gauss_real_width;
2469 table[i] = exp(-
x *
x)/pow((
float)M_PI,.25f);
2471 int image_size=proj->get_xsize();
2474 int gbox = int (max_table_x * gauss_real_width /
apix);
2477 float *pd = proj->get_data();
2479 double xc =
points[4 * s] /
apix + image_size / 2;
2480 double yc =
points[4 * s + 1] /
apix + image_size / 2;
2481 double fval =
points[4 * s + 3];
2482 int imin = int (xc) - gbox, imax = int (xc) + gbox;
2483 int jmin = int (yc) - gbox, jmax = int (yc) + gbox;
2485 if (imin < 0) imin = 0;
2486 if (jmin < 0) jmin = 0;
2487 if (imax > image_size) imax = image_size;
2488 if (jmax > image_size) jmax = image_size;
2490 for (
int j = jmin; j < jmax; j++) {
2491 int table_index_y = int (fabs(j - yc) * inv_table_step_size);
2492 double yval = table[table_index_y];
2493 int pd_index = j * image_size + imin;
2494 for (
int i = imin; i < imax; i++, pd_index++) {
2495 int table_index_x = int (fabs(i - xc) * inv_table_step_size);
2496 double xval = table[table_index_x];
2497 pd[pd_index] -= (float)(fval * yval * xval);
2502 gbox = int (max_table_x * gauss_real_width /
apix);
2505 pd = proj->get_data();
2507 xc = vec[0] /
apix + image_size / 2;
2508 yc = vec[1] /
apix + image_size / 2;
2510 imin = int (xc) - gbox, imax = int (xc) + gbox;
2511 jmin = int (yc) - gbox, jmax = int (yc) + gbox;
2513 if (imin < 0) imin = 0;
2514 if (jmin < 0) jmin = 0;
2515 if (imax > image_size) imax = image_size;
2516 if (jmax > image_size) jmax = image_size;
2518 for (
int j = jmin; j < jmax; j++) {
2519 int table_index_y = int (fabs(j - yc) * inv_table_step_size);
2520 double yval = table[table_index_y];
2521 int pd_index = j * image_size + imin;
2522 for (
int i = imin; i < imax; i++, pd_index++) {
2523 int table_index_x = int (fabs(i - xc) * inv_table_step_size);
2524 double xval = table[table_index_x];
2525 pd[pd_index] -= (float)(fval * yval * xval);
2537 nfft_3D_plan my_plan;
2543 for (
int j = 0, i = 0; j < my_plan.M; j++, i += 4) {
2545 my_plan.v[3 * j + 2] = (fftw_real) (
points[i] / (
apix * map_size));
2546 my_plan.v[3 * j + 1] = (fftw_real) (
points[i + 1] / (
apix * map_size));
2547 my_plan.v[3 * j] = (fftw_real) (
points[i + 2] / (
apix * map_size));
2548 my_plan.f[j].re = (fftw_real) (
points[i + 3]);
2549 my_plan.f[j].im = 0.0;
2553 if (my_plan.nfft_flags & PRE_PSI) {
2554 nfft_3D_precompute_psi(&my_plan);
2558 nfft_3D_transpose(&my_plan);
2562 fft->set_size(map_size + 2, map_size, map_size);
2563 fft->set_complex(
true);
2566 float *data = fft->get_data();
2567 double norm = 1.0 / (map_size * map_size * map_size);
2568 for (
int k = 0; k < map_size; k++) {
2569 for (
int j = 0; j < map_size; j++) {
2570 for (
int i = 0; i < map_size / 2; i++) {
2571 data[k * map_size * (map_size + 2) + j * (map_size + 2) + 2 * i] =
2573 f_hat[k * map_size * map_size + j * map_size + i +
2574 map_size / 2].re) * norm;
2575 data[k * map_size * (map_size + 2) + j * (map_size + 2) + 2 * i + 1] =
2577 f_hat[k * map_size * map_size + j * map_size + i +
2578 map_size / 2].im) * norm * (-1.0);
2583 nfft_3D_finalize(&my_plan);
2586 double sigma2 = (map_size *
apix / res) * (map_size *
apix / res);
2588 for (
int k = 0; k < map_size; k++) {
2589 double RZ2 = (k - map_size / 2) * (k - map_size / 2);
2590 for (
int j = 0; j < map_size; j++) {
2591 double RY2 = (j - map_size / 2) * (j - map_size / 2);
2592 for (
int i = 0; i < map_size / 2 + 1; i++, index += 2) {
2593 float val = exp(-(i * i + RY2 + RZ2) / sigma2);
2595 data[index + 1] *= val;
2602 fft->process_inplace(
"xform.phaseorigin.tocorner");
2604 map->set_attr(
"apix_x",
apix);
2605 map->set_attr(
"apix_y",
apix);
2606 map->set_attr(
"apix_z",
apix);
2607 map->set_attr(
"origin_x", -map_size/2*
apix);
2608 map->set_attr(
"origin_y", -map_size/2*
apix);
2609 map->set_attr(
"origin_z", -map_size/2*
apix);
2623 for (
int j = 0, i = 0; j < my_plan.M; j++, i += 4) {
2625 my_plan.x[3 * j + 2] = (double) (
points[i] / (
apix * map_size));
2626 my_plan.x[3 * j + 1] = (double) (
points[i + 1] / (
apix * map_size));
2627 my_plan.x[3 * j] = (double) (
points[i + 2] / (
apix * map_size));
2628 my_plan.f[j][0] = (double) (
points[i + 3]);
2629 my_plan.f[j][1] = 0.0;
2633 if (my_plan.nfft_flags & PRE_PSI) {
2634 nfft_precompute_psi(&my_plan);
2635 if (my_plan.nfft_flags & PRE_FULL_PSI)
2636 nfft_full_psi(&my_plan, pow(10, -10));
2640 nfft_transposed(&my_plan);
2644 fft->set_size(map_size + 2, map_size, map_size);
2645 fft->set_complex(
true);
2648 float *data = fft->get_data();
2649 double norm = 1.0 / (map_size * map_size * map_size);
2650 for (
int k = 0; k < map_size; k++) {
2651 for (
int j = 0; j < map_size; j++) {
2652 for (
int i = 0; i < map_size / 2; i++) {
2653 data[k * map_size * (map_size + 2) + j * (map_size + 2) + 2 * i] =
2655 f_hat[k * map_size * map_size + j * map_size + i +
2656 map_size / 2][0]) * norm;
2657 data[k * map_size * (map_size + 2) + j * (map_size + 2) + 2 * i + 1] =
2659 f_hat[k * map_size * map_size + j * map_size + i +
2660 map_size / 2][1]) * norm;
2665 nfft_finalize(&my_plan);
2668 double sigma2 = (map_size *
apix / res) * (map_size *
apix / res);
2670 for (
int k = 0; k < map_size; k++) {
2671 double RZ2 = (k - map_size / 2) * (k - map_size / 2);
2672 for (
int j = 0; j < map_size; j++) {
2673 double RY2 = (j - map_size / 2) * (j - map_size / 2);
2674 for (
int i = 0; i < map_size / 2 + 1; i++, index += 2) {
2675 float val = exp(-(i * i + RY2 + RZ2) / sigma2);
2677 data[index + 1] *= val;
2684 fft->process_inplace(
"xform.phaseorigin.tocenter");
2686 map->set_attr(
"apix_x",
apix);
2687 map->set_attr(
"apix_y",
apix);
2688 map->set_attr(
"apix_z",
apix);
2689 map->set_attr(
"origin_x", -map_size / 2 *
apix);
2690 map->set_attr(
"origin_y", -map_size / 2 *
apix);
2691 map->set_attr(
"origin_z", -map_size / 2 *
apix);
2699 LOGWARN(
"nfft support is not enabled. please recompile with nfft support enabled\n");
2707 nfft_2D_plan my_plan;
2710 n[0] = next_power_of_2(2 * image_size);
2712 n[1] = next_power_of_2(2 * image_size);
2720 for (
int j = 0, i = 0; j < my_plan.M; j++, i += 4) {
2722 my_plan.v[2 * j + 1] = (fftw_real) (
points[i] / (
apix * image_size));
2723 my_plan.v[2 * j] = (fftw_real) (
points[i + 1] / (
apix * image_size));
2724 my_plan.f[j].re = (fftw_real)
points[i + 3];
2725 my_plan.f[j].im = 0.0;
2729 if (my_plan.nfft_flags & PRE_PSI) {
2730 nfft_2D_precompute_psi(&my_plan);
2734 nfft_2D_transpose(&my_plan);
2738 fft->set_size(image_size + 2, image_size, 1);
2739 fft->set_complex(
true);
2742 float *data = fft->get_data();
2743 double norm = 1.0 / (image_size * image_size);
2744 for (
int j = 0; j < image_size; j++) {
2745 for (
int i = 0; i < image_size / 2; i++) {
2746 data[j * (image_size + 2) + 2 * i] =
2747 (
float) (my_plan.f_hat[j * image_size + i + image_size / 2].re) * norm;
2748 data[j * (image_size + 2) + 2 * i + 1] =
2749 (
float) (my_plan.f_hat[j * image_size + i + image_size / 2].im) * norm * (-1.0);
2753 nfft_2D_finalize(&my_plan);
2757 double sigma2 = (image_size *
apix / res) * (image_size *
apix / res);
2759 for (
int j = 0; j < image_size; j++) {
2760 double RY2 = (j - image_size / 2) * (j - image_size / 2);
2761 for (
int i = 0; i < image_size / 2 + 1; i++, index += 2) {
2762 double val = exp(-(i * i + RY2) / sigma2);
2764 data[index + 1] *= val;
2771 fft->process_inplace(
"xform.phaseorigin.tocenter");
2778 n[0] = next_power_of_2(2 * image_size);
2780 n[1] = next_power_of_2(2 * image_size);
2785 PRE_PHI_HUT | PRE_PSI |
2786 MALLOC_X | MALLOC_F_HAT | MALLOC_F, FFTW_ESTIMATE | FFTW_DESTROY_INPUT);
2788 for (
int j = 0, i = 0; j < my_plan.M; j++, i += 4) {
2790 my_plan.x[2 * j + 1] = (double) (
points[i] / (
apix * image_size));
2791 my_plan.x[2 * j] = (double) (
points[i + 1] / (
apix * image_size));
2792 my_plan.f[j][0] = (double)
points[i + 3];
2793 my_plan.f[j][1] = 0.0;
2797 if (my_plan.nfft_flags & PRE_PSI) {
2798 nfft_precompute_psi(&my_plan);
2799 if (my_plan.nfft_flags & PRE_FULL_PSI)
2800 nfft_full_psi(&my_plan, pow(10, -6));
2804 nfft_transposed(&my_plan);
2808 fft->set_size(image_size + 2, image_size, 1);
2809 fft->set_complex(
true);
2812 float *data = fft->get_data();
2813 double norm = 1.0 / (image_size * image_size);
2814 for (
int j = 0; j < image_size; j++) {
2815 for (
int i = 0; i < image_size / 2; i++) {
2816 data[j * (image_size + 2) + 2 * i] =
2817 (
float) (my_plan.f_hat[j * image_size + i + image_size / 2][0]) * norm;
2818 data[j * (image_size + 2) + 2 * i + 1] =
2819 (
float) (my_plan.f_hat[j * image_size + i + image_size / 2][1]) * norm;
2823 nfft_finalize(&my_plan);
2827 double sigma2 = (image_size *
apix / res) * (image_size *
apix / res);
2829 for (
int j = 0; j < image_size; j++) {
2830 double RY2 = (j - image_size / 2) * (j - image_size / 2);
2831 for (
int i = 0; i < image_size / 2 + 1; i++, index += 2) {
2832 double val = exp(-(i * i + RY2) / sigma2);
2834 data[index + 1] *= val;
2841 fft->process_inplace(
"xform.phaseorigin.tocenter");
2845 LOGWARN(
"nfft support is not enabled. please recompile with nfft support enabled\n");
2852#include "BoundConstraint.h"
2855#include "newmatap.h"
2857vector<EMData*> optdata;
2861void init_opt_proj(
int ndim, ColumnVector&
x)
2866for (i=0; i<ndim; i++)
x(i+1)=data[i];
2869void calc_opt_proj(
int n,
const ColumnVector&
x,
double& fx,
int& result)
2874 int size=optdata[0]->get_xsize();
2877 for (i=0; i<optdata.size(); i++) {
2878 xform=(optdata[i]->get_transform());
2879 pa.
set_from((
double *)
x.nric()+1,n/4,std::string(
"c1"),&xform);
2881 p->process_inplace(
"normalize.unitlen");
2887 printf(
"%g\t%1.1f %1.1f %1.1f %g\t%1.1f %1.1f %1.1f %g\t%1.1f %1.1f %1.1f %g\n",fx,
x(1),
x(2),
x(3),
x(4),
x(5),
x(6),
x(7),
x(8),
x(9),
x(10),
x(11),
x(12));
2890void calc_opt_projd(
int mode,
int n,
const ColumnVector&
x,
double& fx, ColumnVector& gx,
int& result)
2893if (mode & NLPFunction) {
2897if (mode & NLPGradient) {
2916 opt.setMaxFeval(2000);
2918 opt.printStatus(
"Done");
2922 LOGWARN(
"OPT++ support not enabled.\n");
2950if (v.size()>=4)
points[i*4+3]=v[3];
Dict is a dictionary to store <string, EMObject> pair.
EMData stores an image's data and defines core image processing routines.
EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
PointArray defines a double array of points with values in a 3D space.
EMData * projection_by_summation(int image_size, float apix, float res)
Transform * align_2d(PointArray *to, float max_dist)
Aligns one PointArray to another in 2 dimensions.
void save_pdb_with_helix(const char *file, vector< float > hlxid)
Save the point array to pdb file, including helices information.
void save_to_pdb(const char *file)
double * get_points_array()
Transform calc_transform(PointArray *p)
Calculate the transform to another identical pointarray.
void sim_add_point_double()
Add more points during the simulation.
EMData * distmx(int sortrows=0)
Calculates a (symmetrized) distance matrix for the current PointArray.
void set_from_density_map(EMData *map, int num, float thresh, float apix, Density2PointsArrayAlgorithm mode=PEAKS_DIV)
vector< double > fit_helix(EMData *pmap, int minlength, float mindensity, vector< int > edge, int twodir, size_t minl)
Fit helix from peptide chains.
double get_value_at(int i)
vector< float > get_points()
Returns all x,y,z triplets packed into a vector<float>
void sim_minstep_seq(double meanshift)
Takes a step to minimize the potential.
void replace_by_summation(EMData *image, int i, Vec3f vec, float amp, float apix, float res)
void sim_updategeom()
Updates the dist, ang, dihed parameters.
bool read_ca_from_pdb(const char *file)
Read only C-alpha atoms from a pdb file.
vector< int > match_points(PointArray *to, float max_miss=-1.0)
Will try to establish a 1-1 correspondence between points in two different PointArray objects (this a...
EMData * projection_by_nfft(int image_size, float apix, float res=0)
void sim_minstep(double maxshift)
Takes a step to minimize the potential.
EMData * pdb2mrc_by_summation(int map_size, float apix, float res, int addpdbbfactor)
vector< double > construct_helix(int start, int end, float phs, float &score, int &dir)
Construct an ideal helix between the start and end points given phase.
vector< float > do_pca(int start, int end)
Do principal component analysis to (a subset of) the point array, used in helix fitting in pathwalker...
void opt_from_proj(const vector< EMData * > &proj, float pixres)
Optimizes a pointarray based on a set of projection images (EMData objects) This is effectively a 3D ...
PointArray & operator=(PointArray &pa)
void merge_to(PointArray &pa, float thr)
Merge to another point array.
Vec3f get_vector_at(int i)
float calc_helicity(vector< double > pts)
Calculate the helicity of some points.
void right_transform(const Transform &transform)
Does Transform*v as opposed to v*Transform (as in the transform function)
EMData * pdb2mrc_by_nfft(int map_size, float apix, float res)
double sim_potentialdxyz(int i, double dx, double dy, double dz)
Compute a potential value for a perturbed point, including +-2 nearest neighbors which will also be i...
void set_from(vector< float >)
Region get_bounding_box()
void mask(double rmax, double rmin=0.0)
void delete_point(int id)
Delete one point in the array.
double dist0
Used for simplistic loop dynamics simulation Assumes all points are connected sequentially in a close...
double sim_potentiald(int ind)
Compute a single point potential value.
void sim_printstat()
prints some statistics to the screen
void set_vector_at(int i, Vec3f vec, double value)
void set_number_points(size_t nn)
void reverse_chain()
Reverse the pointarray chain.
Density2PointsArrayAlgorithm
double calc_total_length()
Calculate total length.
void sort_by_axis(int axis=1)
bool read_from_pdb(const char *file, const vector< int > &lines=vector< int >())
void set_points_array(double *p)
void transform(const Transform &transform)
void sim_set_pot_parms(double pdist0, double pdistc, double pangc, double pdihed0, double pdihedc, double pmapc, EMData *pmap, double pmindistc, double pdistpenc)
Sets the parameters for the energy function.
void remove_helix_from_map(EMData *m, vector< float > hlxid)
Remove the corresponding density of the helix point from a density map.
double sim_potential()
Computes overall potential for the configuration.
void sim_rescale()
rescale the entire set so the mean bond length matches dist0
vector< float > do_filter(vector< float > pts, float *ft, int num)
Filter the point array to smooth the line, used in helix fitting in pathwalker.
double sim_pointpotential(double dist, double ang, double dihed)
Computes a potential value for a single point from a set of angles/distances using current energy set...
Vec3f sim_descent(int i)
returns a vector pointing downhill for a single point
size_t get_number_points() const
vector< Vec3f > oldshifts
void mask_asymmetric_unit(const string &sym)
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
static Vec3f calc_bilinear_least_square(const vector< float > &points)
calculate bilinear least-square fit, z = a + b x + c y Takes a set of x,y,z vectors and produces an a...
static float get_frand(int low, int high)
Get a float random number between low and high, [low, high)
static int round(float x)
Get ceiling round of a float number x.
static int get_irand(int low, int high)
Get an integer random number between low and high, [low, high].
Vec3< Type > cross(const Vec3< Type2 > &v) const
Calculate the cross product of 'this' vector with a second vector.
Type dot(const Vec3< Type2 > &v) const
Calculate the dot product of 'this' vector with a second vector.
float normalize()
Normalize the vector and return its length before the normalization.
float length() const
Calculate its length.
EMData * log() const
return natural logarithm image for a image
EMData * sqrt() const
return square root of current image
Vector3 cross(const Vector3 &w, const Vector3 &v)
double dot(const Vector3 &w, const Vector3 &v)
double length(const Vector3 &v)
int cmp_val(const void *a, const void *b)
int cmp_float(const void *a, const void *b)
int cmp_axis_y(const void *a, const void *b)
int cmp_axis_x(const void *a, const void *b)
int cmp_axis_z(const void *a, const void *b)