void test_orientation(long i, long j, long **seidx, char **AtomName, double **xyz, long *nn1, long *nn2) { long k, k1, n1=0, n2=0; double dx[4]; for(k=seidx[i][1]; k<=seidx[i][2]; k++){ if(!strcmp(AtomName[k], " O2'")){ for(k1=seidx[j][1]; k1<=seidx[j][2]; k1++){ if(AtomName[k1][1] !='N' && AtomName[k1][1] !='O') continue; dx[1] = xyz[k][1]-xyz[k1][1]; dx[2] = xyz[k][2]-xyz[k1][2]; dx[3] = xyz[k][3]-xyz[k1][3]; if(!strcmp(AtomName[k1], " O2'")){ if(veclen(dx)<3.8){ n1++; } } if((AtomName[k1][1] =='N' || AtomName[k1][1] =='O')&& AtomName[k1][3] !='\'' ) { if(veclen(dx)<3.8){ n2++; } } } /* printf("atom1-2 = %s-%s %d %d %d %d\n", AtomName[k],AtomName[k1],n1,n2, i, j);*/ break; } } *nn1=n1; *nn2=n2; }
void BumpMapper::input( const Data &d ) { int w = d.width(), h = d.height(); int lz = 260; int a, b; double nx, ny, nz, nl; double dx, dy, dz, dl, dot; Data out( w, h ); if( smooth == 0 ) smooth = 1; for( int y=1; y<h-1; y++ ) { for( int x=1; x<w-1; x++ ) { // Calculate the the normal vector.. a = d.value( x, y+1 ) - d.value( x, y-1 ); b = d.value( x+1, y ) - d.value( x-1, y ); nx = -2*b; ny = -2*a; nz = smooth; nl = veclen( nx, ny, nz ); nx /= nl; ny /= nl; nz /= nl; dx = lp.x()-x; dy = lp.y()-y; dz = lz-d.value( x, y ); dl = veclen( dx, dy, dz ); if( dl>rad ) { out.setValue( x, y, 0 ); continue; } dx /= dl; dy /= dl; dz /= dl; dot = dx*nx + dy*ny + dz*nz; dl = (rad-dl)/(float)rad; if( dot<0 || dl<0 ) { out.setValue( x, y, 0 ); continue; } out.setValue( x, y, (int)(dl*dot*255) ); } } qApp->processEvents(); emit output( out ); }
/*-- Cat lbxgl;Entity;Query Form double LBXGL_Entity_GetRadius(LBXGL_Entity *ent); Description Get the radius associated with an entity. The radius is computed via the bounding boxes, and will fully \ enclose the box. --*/ double LBXGL_Entity_GetRadius(LBXGL_Entity *ent) { double *cmins, *cmaxs; double crad; crad=0; cmins=LBXGL_Entity_GetProperty(ent, "mins"); cmaxs=LBXGL_Entity_GetProperty(ent, "maxs"); if(cmins)if(veclen(cmins)>crad)crad=veclen(cmins); if(cmaxs)if(veclen(cmaxs)>crad)crad=veclen(cmaxs); return(crad); }
double torsion(double **d) /* get torsion angle a-b-c-d in degrees */ { double ang_deg, dij; double **vec3; long i, j; vec3 = dmatrix(1, 3, 1, 3); for (i = 1; i <= 3; i++) { for (j = 1; j <= 3; j++) if (i == 1) vec3[i][j] = d[i][j] - d[i + 1][j]; /* b-->a */ else vec3[i][j] = d[i + 1][j] - d[i][j]; dij = veclen(vec3[i]); if (dij > BOND_UPPER_LIMIT) { free_dmatrix(vec3, 1, 3, 1, 3); return EMPTY_NUMBER; } } ang_deg = vec_ang(vec3[1], vec3[3], vec3[2]); free_dmatrix(vec3, 1, 3, 1, 3); return ang_deg; }
static inline double vecdist(double *avec, double *bvec) { double cvec[3]; cvec[0]=bvec[0]-avec[0]; cvec[1]=bvec[1]-avec[1]; cvec[2]=bvec[2]-avec[2]; return(veclen(cvec)); }
// calculate a normalized vector pointint from one vector to another void pointat(const GLfloat *from, const GLfloat *to, float *result){ int i=0; float dist; assert(NULL != from); assert(NULL != to); assert(NULL != result); vecdiff(from,to,result); dist = veclen(result); assert(dist > 0); for(;i<3;i++){ result[i] /= dist; } }
/*============================================================================ * Test routines. *==========================================================================*/ int main(int argc, char **argv) { /*======================================================================= * Vector operation tests *=====================================================================*/ { /* vecdot */ float X[3] = {1.0, 2.0, 3.0}; float Y[3] = {3.0, 2.0, 1.0}; assert(vecdot(X, Y, 3) == 10.0); } { /* vecdot */ float X[3] = {10.0}; float Y[3] = {13.0}; assert(vecdot(X, Y, 1) == 130.0); } { /* veclen */ float X[3] = {3.0, 4.0}; assert(veclen(X, 2) == 5.0); } { /* vecmul */ float X[5] = {1.0, 2.0, 3.0, 4.0, 5.0}; float Y[5] = {2.0, 4.0, 6.0, 8.0, 10.0}; vecmul(X, 2, 5, X); assert(vecveceq(X, Y, 5)); } { /* vecdiv */ float X[5] = {2.0, 4.0, 6.0, 8.0, 10.0}; float Y[5] = {1.0, 2.0, 3.0, 4.0, 5.0}; vecdiv(X, 2, 5, X); assert(vecveceq(X, Y, 5)); } { /* vecvecsub */ float X[5] = {1.0, 2.0, 3.0, 4.0, 5.0}; float Y[5] = {2.0, 4.0, 6.0, 8.0, 10.0}; float Z[5] = {-1.0, -2.0, -3.0, -4.0, -5.0}; vecvecsub(X, Y, 5, X); assert(vecveceq(X, Z, 5)); } { /* vecvecadd */ float X[5] = {1.0, 2.0, 3.0, 4.0, 5.0}; float Y[5] = {2.0, 4.0, 6.0, 8.0, 10.0}; float Z[5] = {3.0, 6.0, 9.0, 12.0, 15.0}; vecvecadd(X, Y, 5, X); assert(vecveceq(X, Z, 5)); } return 0; }
void do_eigen_projections(int nev, float *M, float **models, float *mean, int num_models, eigen_t *eigen, int dim) { int i, m; struct { float *proj; float best_dot; float best_dot_index; char symbol; } proj_model[2]; assert(models != NULL); assert(mean != NULL); assert(eigen != NULL); assert(dim > 0); assert(num_models > 0); assert(0 < nev && nev <= dim); proj_model[0].proj = (float *)malloc(dim * sizeof(float)); proj_model[1].proj = (float *)malloc(dim * sizeof(float)); proj_model[0].symbol = '+'; proj_model[1].symbol = '-'; if (!opt_multi_out) fprintf(out, "#BEGIN ENSEM\n"); for (i=0; i < nev; i++) { /*================================================================ * Find the models that have the largest and smallest projections * onto the current eigenvector. *==============================================================*/ proj_model[0].best_dot = 0; proj_model[0].best_dot_index = -1; proj_model[1].best_dot = 0; proj_model[1].best_dot_index = -1; for (m=0; m < num_models; m++) { float dot = vecdot(models[m], eigen[i].rvec, dim); if (dot >= 0 && dot >= proj_model[0].best_dot) { proj_model[0].best_dot = dot; proj_model[0].best_dot_index = m; vecmul(eigen[i].rvec, dot, dim, proj_model[0].proj); } if (dot <= 0 && dot <= proj_model[1].best_dot) { proj_model[1].best_dot = dot; proj_model[1].best_dot_index = m; vecmul(eigen[i].rvec, dot, dim, proj_model[1].proj); } } if (opt_interp_proj) { if (proj_model[0].best_dot_index != -1 && proj_model[1].best_dot_index != -1) { int j; float *newp = (float *)malloc(dim * sizeof(float)); float *step = (float *)malloc(dim * sizeof(float)); #define NSTEPS 20 #define OVERSHOOT 20 vecvecsub(proj_model[1].proj, proj_model[0].proj, dim, step); vecdiv(step, NSTEPS, dim, step); for (j=0; j < NSTEPS+OVERSHOOT; j++) { vecmul(step, j, dim, newp); vecvecadd(proj_model[0].proj, newp, dim, newp); undo_scale(newp, dim, M); vecvecadd(newp, mean, dim, newp); multi_out_write_ev_model((i+1)*100 + j, 'p', 0, 0, newp, dim); } free(newp); free(step); #undef NSTEPS #undef OVERSHOOT } } else { /*================================================================ * Write out the new models *==============================================================*/ for (m=0; m < 2; m++) { if (proj_model[m].best_dot_index != -1) { float proj_len_before_scale = veclen(proj_model[m].proj, dim); undo_scale(proj_model[m].proj, dim, M); /* add back mean */ vecvecadd(proj_model[m].proj,mean, dim, proj_model[m].proj); multi_out_write_ev_model(i, proj_model[m].symbol, proj_len_before_scale, proj_model[m].best_dot, proj_model[m].proj, dim); } } } } if (!opt_multi_out) fprintf(out, "#END ENSEM\n"); free(proj_model[0].proj); free(proj_model[1].proj); }