/* mark the calling thread as done and alert join_all() */ local void reenter(void *dummy) { thread *match, **prior; pthread_t me; (void)dummy; /* find this thread in the threads list by matching the thread id */ me = pthread_self(); possess(&(threads_lock)); prior = &(threads); while ((match = *prior) != NULL) { if (pthread_equal(match->id, me)) break; prior = &(match->next); } if (match == NULL) fail(EINVAL); /* mark this thread as done and move it to the head of the list */ match->done = 1; if (threads != match) { *prior = match->next; match->next = threads; threads = match; } /* update the count of threads to be joined and alert join_all() */ twist(&(threads_lock), BY, +1); }
void mkptrj(char *prop,int nSel, int natoms,rvec xav[],int nframes, int nev,rvec **EV,real **evprj, int nca,atom_id ca_index[],atom_id bb_index[], t_atom atom[],matrix box) { FILE *out; char buf[256]; double propje,*pav,*pav2; int i,j; rvec *xxx; snew(pav,nev); snew(pav2,nev); snew(xxx,natoms); sprintf(buf,"%s.trj1",prop); out=ffopen(buf,"w"); fprintf(out,"Projection of %s on EigenVectors\n",prop); for(j=0; (j<nframes); j++) { if ((j % 10) == 0) fprintf(stderr,"\rFrame %d",j); for(i=0; (i<nev); i++) { calc_prj(natoms,xav,xxx,EV[i],evprj[i][j]); switch (nSel) { case efhRAD: propje=radius(NULL,nca,ca_index,xxx); break; case efhLEN: propje=ahx_len(nca,ca_index,xxx,box); break; case efhTWIST: propje=twist(NULL,nca,ca_index,xxx); break; case efhCPHI: propje=ca_phi(nca,ca_index,xxx); break; case efhDIP: propje=dip(natoms,bb_index,xxx,atom); break; default: gmx_fatal(FARGS,"Not implemented"); } pav[i]+=propje; pav2[i]+=propje*propje; fprintf(out,"%8.3f",propje); } fprintf(out,"\n"); } ffclose(out); fprintf(stderr,"\n"); for(i=0; (i<nev); i++) { printf("ev %2d, average: %8.3f rms: %8.3f\n", i+1,pav[i]/nframes,sqrt(pav2[i]/nframes-sqr(pav[i]/nframes))); } sfree(pav); sfree(pav2); sfree(xxx); }
void operator()(const float vec[3]) { geometry_msgs::TwistStamped::Ptr twist( new geometry_msgs::TwistStamped()); twist->header.stamp=ros::Time(); twist->header.frame_id=frame_id; //Condition speed mm/s -> m/s float cond_vec[3]; for (int i=0; i<3;++i) cond_vec[i]=vec[i]/1000; labust::tools::vectorToPoint(cond_vec,twist->twist.linear); pub.publish(twist); }
//! return a random integer in the [0,0xffffffff]-interval unsigned long nextInt32() const { if (mti==N) twist(); /* generate N words at a time */ unsigned long y = mt[mti++]; /* Tempering */ y ^= (y >> 11); y ^= (y << 7) & 0x9d2c5680UL; y ^= (y << 15) & 0xefc60000UL; y ^= (y >> 18); return y; }
void Box::transformVertex(QVector3D v, float animationFrame) { switch (m_globalDefMode) { case Pinch: pinch(v, 1.0f - animationFrame); break; case Mold: mold(v, 1.0f - animationFrame); break; case Twist: twist(v, animationFrame*360.0f); break; case Bend: bend(v, animationFrame*90.0f); break; default: glVertex3fv(&v[0]); } }
void Camera::motion(int x, int y) { if (!moving) return; currPos[0] = (float) x / (float) width; currPos[1] = (float) y / (float) height; float dx = currPos[0] - prevPos[0]; float dy = currPos[1] - prevPos[1]; float mag = sqrtf(dx * dx + dy * dy); if (mag < 1.0e-6f) return; switch (mode) { case ROTATE: rotate(dx, dy); break; case ZOOM: zoom(dx, dy); break; case TWIST: twist(dx, dy); break; case PAN: pan(dx, dy); break; } prevPos[0] = currPos[0]; prevPos[1] = currPos[1]; }
bool ElectronGasOrbitalBuilder::put(xmlNodePtr cur){ int nc=0; PosType twist(0.0); OhmmsAttributeSet aAttrib; aAttrib.add(nc,"shell"); aAttrib.add(twist,"twist"); aAttrib.put(cur); typedef DiracDeterminant<RealEGOSet> Det_t; typedef SlaterDeterminant<RealEGOSet> SlaterDeterminant_t; int nat=targetPtcl.getTotalNum(); int nup=nat/2; HEGGrid<RealType,OHMMS_DIM> egGrid(targetPtcl.Lattice); if(nc == 0) nc = egGrid.getShellIndex(nup); if(nc<0) { app_error() << " HEG Invalid Shell." << endl; APP_ABORT("ElectronGasOrbitalBuilder::put"); } if(nup!=egGrid.getNumberOfKpoints(nc)) { app_error() << " The number of particles does not match to the shell." << endl; app_error() << " Suggested values for the number of particles " << endl; app_error() << " " << 2*egGrid.getNumberOfKpoints(nc) << " for shell "<< nc << endl; app_error() << " " << 2*egGrid.getNumberOfKpoints(nc-1) << " for shell "<< nc-1 << endl; APP_ABORT("ElectronGasOrbitalBuilder::put"); return false; } int nkpts=(nup-1)/2; //create a E(lectron)G(as)O(rbital)Set egGrid.createGrid(nc,nkpts); RealEGOSet* psi=new RealEGOSet(egGrid.kpt,egGrid.mk2); //create up determinant Det_t *updet = new Det_t(psi,0); updet->set(0,nup); //create down determinant Det_t *downdet = new Det_t(psi,nup); downdet->set(nup,nup); //create a Slater determinant SlaterDeterminant_t *sdet = new SlaterDeterminant_t; sdet->add(updet); sdet->add(downdet); //add a DummyBasisSet sdet->setBasisSet(new DummyBasisSet); //add Slater determinant to targetPsi targetPsi.addOrbital(sdet,"SlaterDet"); return true; }
//==== Generate Fuse Component ====// void PropGeom::generate() { int i, j; //==== Copy Current Section Data into SectVec ====// sectVec[currSectID].chord = chord(); sectVec[currSectID].twist = twist(); sectVec[currSectID].x_off = loc(); sectVec[currSectID].y_off = offset(); Xsec_surf surf; surf.set_num_pnts( numPnts.iget() ); surf.set_num_xsecs( sectVec.size()+2 ); //==== Load Up Airfoil ====// for ( int ip = 0 ; ip < surf.get_num_pnts() ; ip++ ) surf.set_pnt(0, ip, sectVec[0].foil->get_end_cap(ip) ); int numxs = sectVec.size(); for ( i = 0 ; i < numxs ; i++ ) { for ( j = 0 ; j < surf.get_num_pnts() ; j++ ) { surf.set_pnt( i+1, j, sectVec[i].foil->get_pnt(j) ); } } for ( int ip = 0 ; ip < surf.get_num_pnts() ; ip++ ) surf.set_pnt(numxs+1, ip, sectVec[numxs-1].foil->get_end_cap(ip) ); //==== Build Up One Blade ====// double rad = diameter()/2.0; for ( i = 0 ; i < surf.get_num_xsecs() ; i++ ) { int sid = i; if ( i > 0 ) sid = i-1; if ( i > (int)sectVec.size()-1 ) sid = (int)sectVec.size()-1; Section* sPtr = &(sectVec[sid]); surf.scale_xsec_x( i, sPtr->chord()*rad ); surf.scale_xsec_z( i, sPtr->chord()*rad ); surf.offset_xsec_x( i, -0.5*(sPtr->chord()*rad) ); surf.rotate_xsec_y( i, 90.0 ); surf.rotate_xsec_y( i, -sPtr->twist() - pitch() ); surf.offset_xsec_y( i, sPtr->x_off()*rad ); surf.offset_xsec_z( i, -sPtr->y_off()*rad ); } //==== Set Flags So Trailing Edge Remains Sharp ====// surf.set_pnt_tan_flag( 0, Bezier_curve::SHARP ); surf.set_pnt_tan_flag( 1, Bezier_curve::SHARP ); int num_pnts = surf.get_num_pnts(); surf.set_pnt_tan_flag( num_pnts-1, Bezier_curve::SHARP ); if ( !smoothFlag ) { for ( i = 0 ; i < surf.get_num_xsecs() ; i++ ) { surf.set_xsec_tan_flag( i, Bezier_curve::SHARP ); } } else // Sharpen End Caps { surf.set_xsec_tan_flag( surf.get_num_xsecs()-2, Bezier_curve::SHARP ); } bezier_surf besurf; surf.load_bezier_surface( &besurf ); int umax = besurf.get_u_max(); int wmax = besurf.get_w_max(); Xsec_surf smooth_surf; smooth_surf.set_num_pnts( (surf.get_num_pnts()-1)*numW + 1 ); smooth_surf.set_num_xsecs( (surf.get_num_xsecs()-1)*numU + 1 ); for ( i = 0 ; i < smooth_surf.get_num_xsecs() ; i++ ) { double fu = (double)i/(double)(smooth_surf.get_num_xsecs()-1); double u = fu*(double)umax; for ( j = 0 ; j < smooth_surf.get_num_pnts() ; j++ ) { double fw = (double)j/(double)(smooth_surf.get_num_pnts()-1); double w = fw*(double)wmax; vec3d p = besurf.comp_pnt( u, w ); smooth_surf.set_pnt( i, j, p ); } } //==== Load Blades into bladeVec ====// for ( int nb = 0 ; nb < (int)bladeVec.size() ; nb++ ) { bladeVec[nb].set_num_pnts( smooth_surf.get_num_pnts() ); bladeVec[nb].set_num_xsecs( smooth_surf.get_num_xsecs() ); //==== Load Points ====// for ( i = 0 ; i < smooth_surf.get_num_xsecs() ; i++ ) for ( j = 0 ; j < smooth_surf.get_num_pnts() ; j++ ) bladeVec[nb].set_pnt( i, j, smooth_surf.get_pnt( i, j ) ); double xang = 360.0*(double)nb/(double)(bladeVec.size()); for ( i = 0 ; i < bladeVec[nb].get_num_xsecs() ; i++ ) { bladeVec[nb].rotate_xsec_z( i, cone_angle() ); bladeVec[nb].rotate_xsec_x( i, xang ); } bladeVec[nb].load_refl_pnts_xsecs(); bladeVec[nb].load_hidden_surf(); bladeVec[nb].load_normals(); bladeVec[nb].load_uw(); } for ( int i = 0 ; i < (int)sectVec.size() ; i++ ) sectVec[i].SetGeomPtr( this ); update_bbox(); }
void Rubik3D::rotate() { for(int x=-isZero(axisX);x<=isZero(axisX);++x) { for(int y=-isZero(axisY);y<=isZero(axisY);++y) { for(int z=-isZero(axisZ);z<=isZero(axisZ);++z) { const int X_from=axisX+x; const int Y_from=axisY+y; const int Z_from=axisZ+z; ; int X_to,Y_to,Z_to; if(twist(axisX, inverse)==1) { X_to = X_from; Y_to = Z_from; Z_to = - Y_from; } else if(twist(axisY, inverse)==1) { X_to = - Z_from; Y_to = Y_from; Z_to = X_from; } else if(twist(axisZ, inverse)==1) { X_to = Y_from; Y_to = - X_from; Z_to = Z_from; }else if(twist(axisX, inverse)==-1) { X_to = X_from; Y_to = - Z_from; Z_to = Y_from; } else if(twist(axisY, inverse)==-1) { X_to = Z_from; Y_to = Y_from; Z_to = - X_from; } else if(twist(axisZ, inverse)==-1) { X_to = - Y_from; Y_to = X_from; Z_to = Z_from; } // swap cube colors if(axisX) { MOVE_TO->left = FROM->Left; MOVE_TO->right = FROM->Right; MOVE_TO->up = MOVE_TO->down = FROM->Front + FROM->Back ; MOVE_TO->front = MOVE_TO->back = FROM->Up + FROM->Down ; } else if(axisY) { MOVE_TO->down = FROM->Down; MOVE_TO->up = FROM->Up; MOVE_TO->left = MOVE_TO->right = FROM->Front + FROM->Back ; MOVE_TO->back = MOVE_TO->front = FROM->Left + FROM->Right ; } else if(axisZ) { MOVE_TO->back = FROM->Back; MOVE_TO->front = FROM->Front; MOVE_TO->right = MOVE_TO->left = FROM->Up + FROM->Down ; MOVE_TO->up = MOVE_TO->down = FROM->Right + FROM->Left ; } } } } setColors(); }
void nextgalaxy(seedtype *s) /* Apply to base seed; once for galaxy 2 */ { (*s).w0 = twist((*s).w0); /* twice for galaxy 3, etc. */ (*s).w1 = twist((*s).w1); /* Eighth application gives galaxy 1 again*/ (*s).w2 = twist((*s).w2); }
int gmx_helix(int argc, char *argv[]) { const char *desc[] = { "[THISMODULE] computes all kinds of helix properties. First, the peptide", "is checked to find the longest helical part, as determined by", "hydrogen bonds and [GRK]phi[grk]/[GRK]psi[grk] angles.", "That bit is fitted", "to an ideal helix around the [IT]z[it]-axis and centered around the origin.", "Then the following properties are computed:[PAR]", "[BB]1.[bb] Helix radius (file [TT]radius.xvg[tt]). This is merely the", "RMS deviation in two dimensions for all C[GRK]alpha[grk] atoms.", "it is calculated as [SQRT]([SUM][sum][SUB]i[sub] (x^2(i)+y^2(i)))/N[sqrt] where N is the number", "of backbone atoms. For an ideal helix the radius is 0.23 nm[BR]", "[BB]2.[bb] Twist (file [TT]twist.xvg[tt]). The average helical angle per", "residue is calculated. For an [GRK]alpha[grk]-helix it is 100 degrees,", "for 3-10 helices it will be smaller, and ", "for 5-helices it will be larger.[BR]", "[BB]3.[bb] Rise per residue (file [TT]rise.xvg[tt]). The helical rise per", "residue is plotted as the difference in [IT]z[it]-coordinate between C[GRK]alpha[grk]", "atoms. For an ideal helix, this is 0.15 nm[BR]", "[BB]4.[bb] Total helix length (file [TT]len-ahx.xvg[tt]). The total length", "of the", "helix in nm. This is simply the average rise (see above) times the", "number of helical residues (see below).[BR]", "[BB]5.[bb] Helix dipole, backbone only (file [TT]dip-ahx.xvg[tt]).[BR]", "[BB]6.[bb] RMS deviation from ideal helix, calculated for the C[GRK]alpha[grk]", "atoms only (file [TT]rms-ahx.xvg[tt]).[BR]", "[BB]7.[bb] Average C[GRK]alpha[grk] - C[GRK]alpha[grk] dihedral angle (file [TT]phi-ahx.xvg[tt]).[BR]", "[BB]8.[bb] Average [GRK]phi[grk] and [GRK]psi[grk] angles (file [TT]phipsi.xvg[tt]).[BR]", "[BB]9.[bb] Ellipticity at 222 nm according to Hirst and Brooks.", "[PAR]" }; static gmx_bool bCheck = FALSE, bFit = TRUE, bDBG = FALSE, bEV = FALSE; static int rStart = 0, rEnd = 0, r0 = 1; t_pargs pa [] = { { "-r0", FALSE, etINT, {&r0}, "The first residue number in the sequence" }, { "-q", FALSE, etBOOL, {&bCheck}, "Check at every step which part of the sequence is helical" }, { "-F", FALSE, etBOOL, {&bFit}, "Toggle fit to a perfect helix" }, { "-db", FALSE, etBOOL, {&bDBG}, "Print debug info" }, { "-ev", FALSE, etBOOL, {&bEV}, "Write a new 'trajectory' file for ED" }, { "-ahxstart", FALSE, etINT, {&rStart}, "First residue in helix" }, { "-ahxend", FALSE, etINT, {&rEnd}, "Last residue in helix" } }; typedef struct { FILE *fp, *fp2; gmx_bool bfp2; const char *filenm; const char *title; const char *xaxis; const char *yaxis; real val; } t_xvgrfile; t_xvgrfile xf[efhNR] = { { NULL, NULL, TRUE, "radius", "Helix radius", NULL, "r (nm)", 0.0 }, { NULL, NULL, TRUE, "twist", "Twist per residue", NULL, "Angle (deg)", 0.0 }, { NULL, NULL, TRUE, "rise", "Rise per residue", NULL, "Rise (nm)", 0.0 }, { NULL, NULL, FALSE, "len-ahx", "Length of the Helix", NULL, "Length (nm)", 0.0 }, { NULL, NULL, FALSE, "dip-ahx", "Helix Backbone Dipole", NULL, "rq (nm e)", 0.0 }, { NULL, NULL, TRUE, "rms-ahx", "RMS Deviation from Ideal Helix", NULL, "RMS (nm)", 0.0 }, { NULL, NULL, FALSE, "rmsa-ahx", "Average RMSD per Residue", "Residue", "RMS (nm)", 0.0 }, { NULL, NULL, FALSE, "cd222", "Ellipticity at 222 nm", NULL, "nm", 0.0 }, { NULL, NULL, TRUE, "pprms", "RMS Distance from \\8a\\4-helix", NULL, "deg", 0.0 }, { NULL, NULL, TRUE, "caphi", "Average Ca-Ca Dihedral", NULL, "\\8F\\4(deg)", 0.0 }, { NULL, NULL, TRUE, "phi", "Average \\8F\\4 angles", NULL, "deg", 0.0 }, { NULL, NULL, TRUE, "psi", "Average \\8Y\\4 angles", NULL, "deg", 0.0 }, { NULL, NULL, TRUE, "hb3", "Average n-n+3 hbond length", NULL, "nm", 0.0 }, { NULL, NULL, TRUE, "hb4", "Average n-n+4 hbond length", NULL, "nm", 0.0 }, { NULL, NULL, TRUE, "hb5", "Average n-n+5 hbond length", NULL, "nm", 0.0 }, { NULL, NULL, FALSE, "JCaHa", "J-Coupling Values", "Residue", "Hz", 0.0 }, { NULL, NULL, FALSE, "helicity", "Helicity per Residue", "Residue", "% of time", 0.0 } }; output_env_t oenv; char buf[54]; t_trxstatus *status; int natoms, nre, nres; t_bb *bb; int i, j, m, nall, nbb, nca, teller, nSel = 0; atom_id *bbindex, *caindex, *allindex; t_topology *top; int ePBC; rvec *x, *xref; real t; real rms; matrix box; gmx_rmpbc_t gpbc = NULL; gmx_bool bRange; t_filenm fnm[] = { { efTPX, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffREAD }, { efTRX, "-f", NULL, ffREAD }, { efSTO, "-cz", "zconf", ffWRITE }, }; #define NFILE asize(fnm) if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv)) { return 0; } bRange = (opt2parg_bSet("-ahxstart", asize(pa), pa) && opt2parg_bSet("-ahxend", asize(pa), pa)); top = read_top(ftp2fn(efTPX, NFILE, fnm), &ePBC); natoms = read_first_x(oenv, &status, opt2fn("-f", NFILE, fnm), &t, &x, box); if (natoms != top->atoms.nr) { gmx_fatal(FARGS, "Sorry can only run when the number of atoms in the run input file (%d) is equal to the number in the trajectory (%d)", top->atoms.nr, natoms); } bb = mkbbind(ftp2fn(efNDX, NFILE, fnm), &nres, &nbb, r0, &nall, &allindex, top->atoms.atomname, top->atoms.atom, top->atoms.resinfo); snew(bbindex, natoms); snew(caindex, nres); fprintf(stderr, "nall=%d\n", nall); /* Open output files, default x-axis is time */ for (i = 0; (i < efhNR); i++) { sprintf(buf, "%s.xvg", xf[i].filenm); remove(buf); xf[i].fp = xvgropen(buf, xf[i].title, xf[i].xaxis ? xf[i].xaxis : "Time (ps)", xf[i].yaxis, oenv); if (xf[i].bfp2) { sprintf(buf, "%s.out", xf[i].filenm); remove(buf); xf[i].fp2 = gmx_ffopen(buf, "w"); } } /* Read reference frame from tpx file to compute helix length */ snew(xref, top->atoms.nr); read_tpx(ftp2fn(efTPX, NFILE, fnm), NULL, NULL, &natoms, xref, NULL, NULL, NULL); calc_hxprops(nres, bb, xref); do_start_end(nres, bb, &nbb, bbindex, &nca, caindex, bRange, rStart, rEnd); sfree(xref); if (bDBG) { fprintf(stderr, "nca=%d, nbb=%d\n", nca, nbb); pr_bb(stdout, nres, bb); } gpbc = gmx_rmpbc_init(&top->idef, ePBC, natoms); teller = 0; do { if ((teller++ % 10) == 0) { fprintf(stderr, "\rt=%.2f", t); } gmx_rmpbc(gpbc, natoms, box, x); calc_hxprops(nres, bb, x); if (bCheck) { do_start_end(nres, bb, &nbb, bbindex, &nca, caindex, FALSE, 0, 0); } if (nca >= 5) { rms = fit_ahx(nres, bb, natoms, nall, allindex, x, nca, caindex, bFit); if (teller == 1) { write_sto_conf(opt2fn("-cz", NFILE, fnm), "Helix fitted to Z-Axis", &(top->atoms), x, NULL, ePBC, box); } xf[efhRAD].val = radius(xf[efhRAD].fp2, nca, caindex, x); xf[efhTWIST].val = twist(nca, caindex, x); xf[efhRISE].val = rise(nca, caindex, x); xf[efhLEN].val = ahx_len(nca, caindex, x); xf[efhCD222].val = ellipticity(nres, bb); xf[efhDIP].val = dip(nbb, bbindex, x, top->atoms.atom); xf[efhRMS].val = rms; xf[efhCPHI].val = ca_phi(nca, caindex, x); xf[efhPPRMS].val = pprms(xf[efhPPRMS].fp2, nres, bb); for (j = 0; (j <= efhCPHI); j++) { fprintf(xf[j].fp, "%10g %10g\n", t, xf[j].val); } av_phipsi(xf[efhPHI].fp, xf[efhPSI].fp, xf[efhPHI].fp2, xf[efhPSI].fp2, t, nres, bb); av_hblen(xf[efhHB3].fp, xf[efhHB3].fp2, xf[efhHB4].fp, xf[efhHB4].fp2, xf[efhHB5].fp, xf[efhHB5].fp2, t, nres, bb); } } while (read_next_x(oenv, status, &t, x, box)); fprintf(stderr, "\n"); gmx_rmpbc_done(gpbc); close_trj(status); for (i = 0; (i < nres); i++) { if (bb[i].nrms > 0) { fprintf(xf[efhRMSA].fp, "%10d %10g\n", r0+i, bb[i].rmsa/bb[i].nrms); } fprintf(xf[efhAHX].fp, "%10d %10g\n", r0+i, (bb[i].nhx*100.0)/(real )teller); fprintf(xf[efhJCA].fp, "%10d %10g\n", r0+i, 140.3+(bb[i].jcaha/(double)teller)); } for (i = 0; (i < efhNR); i++) { gmx_ffclose(xf[i].fp); if (xf[i].bfp2) { gmx_ffclose(xf[i].fp2); } do_view(oenv, xf[i].filenm, "-nxy"); } return 0; }
PxU32 RevoluteJointSolverPrep(Px1DConstraint* constraints, PxVec3& body0WorldOffset, PxU32 /*maxConstraints*/, PxConstraintInvMassScale &invMassScale, const void* constantBlock, const PxTransform& bA2w, const PxTransform& bB2w) { const RevoluteJointData& data = *reinterpret_cast<const RevoluteJointData*>(constantBlock); invMassScale = data.invMassScale; const PxJointAngularLimitPair& limit = data.limit; bool limitEnabled = data.jointFlags & PxRevoluteJointFlag::eLIMIT_ENABLED; bool limitIsLocked = limitEnabled && limit.lower >= limit.upper; PxTransform cA2w = bA2w * data.c2b[0]; PxTransform cB2w = bB2w * data.c2b[1]; if(cB2w.q.dot(cA2w.q)<0.f) cB2w.q = -cB2w.q; body0WorldOffset = cB2w.p-bA2w.p; Ext::joint::ConstraintHelper ch(constraints, cB2w.p - bA2w.p, cB2w.p - bB2w.p); ch.prepareLockedAxes(cA2w.q, cB2w.q, cA2w.transformInv(cB2w.p), 7, PxU32(limitIsLocked ? 7 : 6)); if(limitIsLocked) return ch.getCount(); PxVec3 axis = cA2w.rotate(PxVec3(1.f,0,0)); if(data.jointFlags & PxRevoluteJointFlag::eDRIVE_ENABLED) { Px1DConstraint *c = ch.getConstraintRow(); c->solveHint = PxConstraintSolveHint::eNONE; c->linear0 = PxVec3(0); c->angular0 = -axis; c->linear1 = PxVec3(0); c->angular1 = -axis * data.driveGearRatio; c->velocityTarget = data.driveVelocity; c->minImpulse = -data.driveForceLimit; c->maxImpulse = data.driveForceLimit; if(data.jointFlags & PxRevoluteJointFlag::eDRIVE_FREESPIN) { if(data.driveVelocity > 0) c->minImpulse = 0; if(data.driveVelocity < 0) c->maxImpulse = 0; } c->flags |= Px1DConstraintFlag::eHAS_DRIVE_LIMIT; } if(limitEnabled) { PxQuat cB2cAq = cA2w.q.getConjugate() * cB2w.q; PxQuat twist(cB2cAq.x,0,0,cB2cAq.w); PxReal magnitude = twist.normalize(); PxReal tqPhi = physx::intrinsics::fsel(magnitude - 1e-6f, twist.x / (1.0f + twist.w), 0.f); ch.quarterAnglePair(tqPhi, data.tqLow, data.tqHigh, data.tqPad, axis, limit); } return ch.getCount(); }
int gmx_helix(int argc,char *argv[]) { const char *desc[] = { "g_helix computes all kind of helix properties. First, the peptide", "is checked to find the longest helical part. This is determined by", "Hydrogen bonds and Phi/Psi angles.", "That bit is fitted", "to an ideal helix around the Z-axis and centered around the origin.", "Then the following properties are computed:[PAR]", "[BB]1.[bb] Helix radius (file radius.xvg). This is merely the", "RMS deviation in two dimensions for all Calpha atoms.", "it is calced as sqrt((SUM i(x^2(i)+y^2(i)))/N), where N is the number", "of backbone atoms. For an ideal helix the radius is 0.23 nm[BR]", "[BB]2.[bb] Twist (file twist.xvg). The average helical angle per", "residue is calculated. For alpha helix it is 100 degrees,", "for 3-10 helices it will be smaller,", "for 5-helices it will be larger.[BR]", "[BB]3.[bb] Rise per residue (file rise.xvg). The helical rise per", "residue is plotted as the difference in Z-coordinate between Ca", "atoms. For an ideal helix this is 0.15 nm[BR]", "[BB]4.[bb] Total helix length (file len-ahx.xvg). The total length", "of the", "helix in nm. This is simply the average rise (see above) times the", "number of helical residues (see below).[BR]", "[BB]5.[bb] Number of helical residues (file n-ahx.xvg). The title says", "it all.[BR]", "[BB]6.[bb] Helix Dipole, backbone only (file dip-ahx.xvg).[BR]", "[BB]7.[bb] RMS deviation from ideal helix, calculated for the Calpha", "atoms only (file rms-ahx.xvg).[BR]", "[BB]8.[bb] Average Calpha-Calpha dihedral angle (file phi-ahx.xvg).[BR]", "[BB]9.[bb] Average Phi and Psi angles (file phipsi.xvg).[BR]", "[BB]10.[bb] Ellipticity at 222 nm according to [IT]Hirst and Brooks[it]", "[PAR]" }; static const char *ppp[efhNR+2] = { NULL, "RAD", "TWIST", "RISE", "LEN", "NHX", "DIP", "RMS", "CPHI", "RMSA", "PHI", "PSI", "HB3", "HB4", "HB5", "CD222", NULL }; static gmx_bool bCheck=FALSE,bFit=TRUE,bDBG=FALSE,bEV=FALSE; static int rStart=0,rEnd=0,r0=1; t_pargs pa [] = { { "-r0", FALSE, etINT, {&r0}, "The first residue number in the sequence" }, { "-q", FALSE, etBOOL,{&bCheck}, "Check at every step which part of the sequence is helical" }, { "-F", FALSE, etBOOL,{&bFit}, "Toggle fit to a perfect helix" }, { "-db", FALSE, etBOOL,{&bDBG}, "Print debug info" }, { "-prop", FALSE, etENUM, {ppp}, "Select property to weight eigenvectors with. WARNING experimental stuff" }, { "-ev", FALSE, etBOOL,{&bEV}, "Write a new 'trajectory' file for ED" }, { "-ahxstart", FALSE, etINT, {&rStart}, "First residue in helix" }, { "-ahxend", FALSE, etINT, {&rEnd}, "Last residue in helix" } }; typedef struct { FILE *fp,*fp2; gmx_bool bfp2; const char *filenm; const char *title; const char *xaxis; const char *yaxis; real val; } t_xvgrfile; t_xvgrfile xf[efhNR] = { { NULL, NULL, TRUE, "radius", "Helix radius", NULL, "r (nm)" , 0.0 }, { NULL, NULL, TRUE, "twist", "Twist per residue", NULL, "Angle (deg)", 0.0 }, { NULL, NULL, TRUE, "rise", "Rise per residue", NULL, "Rise (nm)", 0.0 }, { NULL, NULL, FALSE, "len-ahx", "Length of the Helix", NULL, "Length (nm)", 0.0 }, { NULL, NULL, FALSE, "dip-ahx", "Helix Backbone Dipole", NULL, "rq (nm e)", 0.0 }, { NULL, NULL, TRUE, "rms-ahx", "RMS Deviation from Ideal Helix", NULL, "RMS (nm)", 0.0 }, { NULL, NULL, FALSE, "rmsa-ahx","Average RMSD per Residue", "Residue", "RMS (nm)", 0.0 }, { NULL, NULL,FALSE, "cd222", "Ellipticity at 222 nm", NULL, "nm", 0.0 }, { NULL, NULL, TRUE, "pprms", "RMS Distance from \\8a\\4-helix", NULL, "deg" , 0.0 }, { NULL, NULL, TRUE, "caphi", "Average Ca-Ca Dihedral", NULL, "\\8F\\4(deg)", 0.0 }, { NULL, NULL, TRUE, "phi", "Average \\8F\\4 angles", NULL, "deg" , 0.0 }, { NULL, NULL, TRUE, "psi", "Average \\8Y\\4 angles", NULL, "deg" , 0.0 }, { NULL, NULL, TRUE, "hb3", "Average n-n+3 hbond length", NULL, "nm" , 0.0 }, { NULL, NULL, TRUE, "hb4", "Average n-n+4 hbond length", NULL, "nm" , 0.0 }, { NULL, NULL, TRUE, "hb5", "Average n-n+5 hbond length", NULL, "nm" , 0.0 }, { NULL, NULL,FALSE, "JCaHa", "J-Coupling Values", "Residue", "Hz" , 0.0 }, { NULL, NULL,FALSE, "helicity","Helicity per Residue", "Residue", "% of time" , 0.0 } }; output_env_t oenv; FILE *otrj; char buf[54],prop[256]; t_trxstatus *status; int natoms,nre,nres; t_bb *bb; int i,j,ai,m,nall,nbb,nca,teller,nSel=0; atom_id *bbindex,*caindex,*allindex; t_topology *top; int ePBC; rvec *x,*xref,*xav; real t; real rms,fac; matrix box; gmx_rmpbc_t gpbc=NULL; gmx_bool bRange; t_filenm fnm[] = { { efTPX, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffREAD }, { efTRX, "-f", NULL, ffREAD }, { efG87, "-to", NULL, ffOPTWR }, { efSTO, "-cz", "zconf",ffWRITE }, { efSTO, "-co", "waver",ffWRITE } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE, NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL,&oenv); bRange=(opt2parg_bSet("-ahxstart",asize(pa),pa) && opt2parg_bSet("-ahxend",asize(pa),pa)); top=read_top(ftp2fn(efTPX,NFILE,fnm),&ePBC); natoms=read_first_x(oenv,&status,opt2fn("-f",NFILE,fnm),&t,&x,box); if (opt2bSet("-to",NFILE,fnm)) { otrj=opt2FILE("-to",NFILE,fnm,"w"); strcpy(prop,ppp[0]); fprintf(otrj,"%s Weighted Trajectory: %d atoms, NO box\n",prop,natoms); } else otrj=NULL; if (natoms != top->atoms.nr) gmx_fatal(FARGS,"Sorry can only run when the number of atoms in the run input file (%d) is equal to the number in the trajectory (%d)", top->atoms.nr,natoms); bb=mkbbind(ftp2fn(efNDX,NFILE,fnm),&nres,&nbb,r0,&nall,&allindex, top->atoms.atomname,top->atoms.atom,top->atoms.resinfo); snew(bbindex,natoms); snew(caindex,nres); fprintf(stderr,"nall=%d\n",nall); /* Open output files, default x-axis is time */ for(i=0; (i<efhNR); i++) { sprintf(buf,"%s.xvg",xf[i].filenm); remove(buf); xf[i].fp=xvgropen(buf,xf[i].title, xf[i].xaxis ? xf[i].xaxis : "Time (ps)", xf[i].yaxis,oenv); if (xf[i].bfp2) { sprintf(buf,"%s.out",xf[i].filenm); remove(buf); xf[i].fp2=ffopen(buf,"w"); } } /* Read reference frame from tpx file to compute helix length */ snew(xref,top->atoms.nr); read_tpx(ftp2fn(efTPX,NFILE,fnm), NULL,NULL,&natoms,xref,NULL,NULL,NULL); calc_hxprops(nres,bb,xref,box); do_start_end(nres,bb,xref,&nbb,bbindex,&nca,caindex,bRange,rStart,rEnd); sfree(xref); if (bDBG) { fprintf(stderr,"nca=%d, nbb=%d\n",nca,nbb); pr_bb(stdout,nres,bb); } gpbc = gmx_rmpbc_init(&top->idef,ePBC,natoms,box); snew(xav,natoms); teller=0; do { if ((teller++ % 10) == 0) fprintf(stderr,"\rt=%.2f",t); gmx_rmpbc(gpbc,natoms,box,x); calc_hxprops(nres,bb,x,box); if (bCheck) do_start_end(nres,bb,x,&nbb,bbindex,&nca,caindex,FALSE,0,0); if (nca >= 5) { rms=fit_ahx(nres,bb,natoms,nall,allindex,x,nca,caindex,box,bFit); if (teller == 1) { write_sto_conf(opt2fn("-cz",NFILE,fnm),"Helix fitted to Z-Axis", &(top->atoms),x,NULL,ePBC,box); } xf[efhRAD].val = radius(xf[efhRAD].fp2,nca,caindex,x); xf[efhTWIST].val = twist(xf[efhTWIST].fp2,nca,caindex,x); xf[efhRISE].val = rise(nca,caindex,x); xf[efhLEN].val = ahx_len(nca,caindex,x,box); xf[efhCD222].val = ellipticity(nres,bb); xf[efhDIP].val = dip(nbb,bbindex,x,top->atoms.atom); xf[efhRMS].val = rms; xf[efhCPHI].val = ca_phi(nca,caindex,x,box); xf[efhPPRMS].val = pprms(xf[efhPPRMS].fp2,nres,bb); for(j=0; (j<=efhCPHI); j++) fprintf(xf[j].fp, "%10g %10g\n",t,xf[j].val); av_phipsi(xf[efhPHI].fp,xf[efhPSI].fp,xf[efhPHI].fp2,xf[efhPSI].fp2, t,nres,bb); av_hblen(xf[efhHB3].fp,xf[efhHB3].fp2, xf[efhHB4].fp,xf[efhHB4].fp2, xf[efhHB5].fp,xf[efhHB5].fp2, t,nres,bb); if (otrj) dump_otrj(otrj,nall,allindex,x,xf[nSel].val,xav); } } while (read_next_x(oenv,status,&t,natoms,x,box)); fprintf(stderr,"\n"); gmx_rmpbc_done(gpbc); close_trj(status); if (otrj) { ffclose(otrj); fac=1.0/teller; for(i=0; (i<nall); i++) { ai=allindex[i]; for(m=0; (m<DIM); m++) xav[ai][m]*=fac; } write_sto_conf_indexed(opt2fn("-co",NFILE,fnm), "Weighted and Averaged conformation", &(top->atoms),xav,NULL,ePBC,box,nall,allindex); } for(i=0; (i<nres); i++) { if (bb[i].nrms > 0) { fprintf(xf[efhRMSA].fp,"%10d %10g\n",r0+i,bb[i].rmsa/bb[i].nrms); } fprintf(xf[efhAHX].fp,"%10d %10g\n",r0+i,(bb[i].nhx*100.0)/(real )teller); fprintf(xf[efhJCA].fp,"%10d %10g\n", r0+i,140.3+(bb[i].jcaha/(double)teller)); } for(i=0; (i<efhNR); i++) { ffclose(xf[i].fp); if (xf[i].bfp2) ffclose(xf[i].fp2); do_view(oenv,xf[i].filenm,"-nxy"); } thanx(stderr); return 0; }
virtual void MySendCommands() { ScopedLock lock(mutex); double dt = t - last_t; //advance limbs if(robotState.leftLimb.sendCommand) { if(robotState.leftLimb.controlMode == LimbState::POSITION || robotState.leftLimb.controlMode == LimbState::RAW_POSITION) robotState.leftLimb.sendCommand = false; else if(robotState.leftLimb.controlMode == LimbState::VELOCITY) robotState.leftLimb.commandedConfig.madd(robotState.leftLimb.commandedVelocity,dt); else //effort mode not supported robotState.leftLimb.sendCommand = false; //handle joint limits if(robotModel) { for(size_t i=0;i<leftKlamptIndices.size();i++) { if(robotState.leftLimb.commandedConfig[i] < robotModel->qMin[leftKlamptIndices[i]] || robotState.leftLimb.commandedConfig[i] > robotModel->qMax[leftKlamptIndices[i]]) { robotState.leftLimb.commandedConfig[i] = Clamp(robotState.leftLimb.commandedConfig[i],robotModel->qMin[leftKlamptIndices[i]],robotModel->qMax[leftKlamptIndices[i]]); robotState.leftLimb.commandedVelocity[i] = 0; } } } } if(robotState.rightLimb.sendCommand) { if(robotState.rightLimb.controlMode == LimbState::POSITION || robotState.rightLimb.controlMode == LimbState::RAW_POSITION) robotState.rightLimb.sendCommand = false; else if(robotState.rightLimb.controlMode == LimbState::VELOCITY) robotState.rightLimb.commandedConfig.madd(robotState.rightLimb.commandedVelocity,dt); else //effort mode not supported robotState.rightLimb.sendCommand = false; //handle joint limits if(robotModel) { for(size_t i=0;i<rightKlamptIndices.size();i++) { if(robotState.rightLimb.commandedConfig[i] < robotModel->qMin[rightKlamptIndices[i]] || robotState.rightLimb.commandedConfig[i] > robotModel->qMax[rightKlamptIndices[i]]) { robotState.rightLimb.commandedConfig[i] = Clamp(robotState.rightLimb.commandedConfig[i],robotModel->qMin[rightKlamptIndices[i]],robotModel->qMax[rightKlamptIndices[i]]); robotState.rightLimb.commandedVelocity[i] = 0; } } } } //advance grippers if(robotState.leftGripper.sendCommand) robotState.leftGripper.sendCommand = false; robotState.leftGripper.moving = false; for(int i=0;i<robotState.leftGripper.position.n;i++) { double pdes = Clamp(robotState.leftGripper.positionCommand[i],0.0,1.0); double v = Clamp(robotState.leftGripper.speedCommand[i],0.0,1.0); double old = robotState.leftGripper.position[i]; robotState.leftGripper.position[i] += dt*Sign(pdes-robotState.leftGripper.position[i])*v; if(Sign(old-pdes) != Sign(robotState.leftGripper.position[i]-pdes)) //stop robotState.leftGripper.position[i] = pdes; if(robotState.leftGripper.position[i] != pdes) robotState.leftGripper.moving=true; } if(robotState.rightGripper.sendCommand) robotState.rightGripper.sendCommand = false; robotState.rightGripper.moving = false; for(int i=0;i<robotState.leftGripper.position.n;i++) { double pdes = Clamp(robotState.rightGripper.positionCommand[i],0.0,1.0); double v = Clamp(robotState.leftGripper.speedCommand[i],0.0,1.0); double old = robotState.rightGripper.position[i]; robotState.rightGripper.position[i] += dt*Sign(pdes-robotState.rightGripper.position[i])*v; if(Sign(old-pdes) != Sign(robotState.rightGripper.position[i]-pdes)) //stop robotState.rightGripper.position[i] = pdes; if(robotState.rightGripper.position[i] != pdes) robotState.rightGripper.moving = true; } //process base commands if(robotState.base.sendCommand) { Assert(robotState.base.command.size()==3); if(robotState.base.controlMode == BaseState::NONE) { robotState.base.sendCommand = false; robotState.base.moving = false; robotState.base.velocity.set(0.0); } else if(robotState.base.controlMode == BaseState::RELATIVE_POSITION || robotState.base.controlMode == BaseState::ODOMETRY_POSITION) { if(robotState.base.controlMode == BaseState::RELATIVE_POSITION) { //first transform to global odometry robotState.base.controlMode = BaseState::ODOMETRY_POSITION; Vector newCommand(3); robotState.base.ToOdometry(robotState.base.command,newCommand); robotState.base.command = newCommand; } } else if(robotState.base.controlMode == BaseState::RELATIVE_VELOCITY) { //physical mode latches the command ... kinematic mode doesnt //robotState.base.sendCommand = false; if(robotState.base.command.norm() < 1e-3) { //done! robotState.base.sendCommand = false; robotState.base.moving = false; robotState.base.velocity.set(0.0); } } robotState.base.IntegrateCommand(baseCalibration,dt); //cout<<"Desired twist "<<robotState.base.commandedVelocity<<endl; if(robotState.base.controlMode == BaseState::RELATIVE_POSITION || robotState.base.controlMode == BaseState::ODOMETRY_POSITION) { if(robotState.base.commandedPosition.distance(robotState.base.command)<1e-3 && robotState.base.commandedVelocity.norm() < 1e-3) { printf("Arrived, setting sendCommand/moving = false\n"); robotState.base.sendCommand = false; robotState.base.moving = false; robotState.base.velocity.set(0.0); } } } //simulate base if(robotState.base.enabled && robotState.base.sendCommand) { //simulate friction Vector twist(3,0.0); robotState.base.DesiredToLowLevelCommand(baseCalibration,dt,twist); cout<<"Commanded twist "<<twist<<", dt "<<endl; if(Abs(twist(0)) < baseCalibration.xFriction) twist(0) = 0; else twist(0) -= Sign(twist(0))*baseCalibration.xFriction; if(Abs(twist(1)) < baseCalibration.yFriction) twist(1) = 0; else twist(1) -= Sign(twist(1))*baseCalibration.yFriction; if(Abs(twist(2)) < baseCalibration.angFriction) twist(2) = 0; else twist(2) -= Sign(twist(2))*baseCalibration.angFriction; cout<<"Friction changed twist to "<<twist<<endl; robotState.base.velocity = twist; Matrix2 R; R.setRotate(robotState.base.odometry(2)); Vector2 vworld = R*Vector2(twist(0),twist(1)); robotState.base.odometry(0) += vworld.x*dt; robotState.base.odometry(1) += vworld.y*dt; robotState.base.odometry(2) += twist(2)*dt; robotState.base.senseUpdateTime = t; assert(robotState.base.sendCommand == true); } }