// Calculate secondary structure prediction with PSIPRED void CalculateSS(char *ss_pred, char *ss_conf, char *tmpfile) { // Initialize std::string command; char line[LINELEN]=""; char filename[NAMELEN]; strcpy(ss_pred,"-"); strcpy(ss_conf,"-"); // Run PSIPRED // Check for PSIPRED ver >= 3.0 (weights.dat4 doesn't exists anymore) strcpy(filename,par.psipred_data); strcat(filename,"/weights.dat4"); FILE* check_exists = fopen(filename,"r"); if (check_exists) { // Psipred version < 3.0 command = (std::string)par.psipred + "/psipred " + (std::string)tmpfile + ".mtx " + (std::string)par.psipred_data + "/weights.dat " + (std::string)par.psipred_data + "/weights.dat2 " + (std::string)par.psipred_data + "/weights.dat3 " + (std::string)par.psipred_data + "/weights.dat4 > " + (std::string)tmpfile + ".ss"; } else { command = (std::string)par.psipred + "/psipred " + (std::string)tmpfile + ".mtx " + (std::string)par.psipred_data + "/weights.dat " + (std::string)par.psipred_data + "/weights.dat2 " + (std::string)par.psipred_data + "/weights.dat3 > " + (std::string)tmpfile + ".ss"; } runSystem(command,v); command = (std::string)par.psipred + "/psipass2 " + (std::string)par.psipred_data + "/weights_p2.dat 1 0.98 1.09 " + (std::string)tmpfile + ".ss2 " + (std::string)tmpfile + ".ss > " + (std::string)tmpfile + ".horiz"; runSystem(command,v); // Read results strcpy(filename,tmpfile); strcat(filename,".horiz"); FILE* horizf = fopen(filename,"r"); if (!horizf) return; while (fgets(line,LINELEN,horizf)) { char tmp_seq[NAMELEN]=""; char* ptr=line; if (!strncmp(line,"Conf:",5)) { ptr+=5; strwrd(tmp_seq,ptr); strcat(ss_conf,tmp_seq); } if (!strncmp(line,"Pred:",5)) { ptr+=5; strwrd(tmp_seq,ptr); strcat(ss_pred,tmp_seq); } } fclose(horizf); if (v>3) { printf("SS-pred: %s\n",ss_pred); printf("SS-conf: %s\n",ss_conf); } }
// Create deformed PDB ===================================================== FileName ProgNmaAlignment::createDeformedPDB(int pyramidLevel) const { String program; String arguments; FileName fnRandom; fnRandom.initUniqueName(nameTemplate,fnOutDir); const char * randStr = fnRandom.c_str(); program = "xmipp_pdb_nma_deform"; arguments = formatString( "--pdb %s -o %s_deformedPDB.pdb --nma %s --deformations ", fnPDB.c_str(), randStr, fnModeList.c_str()); for (size_t i = 0; i < VEC_XSIZE(trial) - 5; ++i) arguments += floatToString(trial(i)) + " "; runSystem(program, arguments, false); program = "xmipp_volume_from_pdb"; arguments = formatString( "-i %s_deformedPDB.pdb --size %i --sampling %f -v 0", randStr, imgSize, sampling_rate); if (do_centerPDB) arguments.append(" --centerPDB "); if (useFixedGaussian) { arguments.append(" --intensityColumn Bfactor --fixed_Gaussian "); if (sigmaGaussian >= 0) arguments += formatString("%f",sigmaGaussian); } //else //arguments +=" --poor_Gaussian"; // Otherwise, a detailed conversion of the atoms takes too long in this context progVolumeFromPDB->read(arguments); progVolumeFromPDB->tryRun(); if (do_FilterPDBVol) { program = "xmipp_transform_filter"; arguments = formatString( "-i %s_deformedPDB.vol --sampling %f --fourier low_pass %f -v 0", randStr, sampling_rate, cutoff_LPfilter); runSystem(program, arguments, false); } if (pyramidLevel != 0) { Image<double> I; FileName fnDeformed = formatString("%s_deformedPDB.vol",randStr); I.read(fnDeformed); selfPyramidReduce(BSPLINE3, I(), pyramidLevel); I.write(fnDeformed); } return fnRandom; }
// Continuous assignment =================================================== double ProgNmaAlignment::performContinuousAssignment(const FileName &fnRandom, int pyramidLevel) const { // Perform alignment const char * randStr = fnRandom.c_str(); String fnResults=formatString("%s_anglecont.xmd", randStr); bool costSource=true; String program = "xmipp_angular_continuous_assign"; String arguments = formatString( "-i %s_angledisc.xmd --ref %s_deformedPDB.vol -o %s --gaussian_Fourier %f --gaussian_Real %f --zerofreq_weight %f -v 0", randStr, randStr, fnResults.c_str(), gaussian_DFT_sigma, gaussian_Real_sigma, weight_zero_freq); runSystem(program, arguments, false); // Pick up results MetaData DF(fnResults); MDRow row; DF.getRow(row, DF.firstObject()); row.getValue(MDL_ANGLE_ROT, trial(VEC_XSIZE(trial) - 5)); row.getValue(MDL_ANGLE_TILT, trial(VEC_XSIZE(trial) - 4)); row.getValue(MDL_ANGLE_PSI, trial(VEC_XSIZE(trial) - 3)); row.getValue(MDL_SHIFT_X, trial(VEC_XSIZE(trial) - 2)); trial(VEC_XSIZE(trial) - 2) *= pow(2.0, (double) pyramidLevel); row.getValue(MDL_SHIFT_Y, trial(VEC_XSIZE(trial) - 1)); trial(VEC_XSIZE(trial) - 1) *= pow(2.0, (double) pyramidLevel); double tempvar; if (!costSource) { row.getValue(MDL_MAXCC, tempvar); tempvar = -tempvar; } else row.getValue(MDL_COST, tempvar); return tempvar; }
// Compute fitness ========================================================= double ObjFunc_nma_alignment::eval(Vector X, int *nerror) { int dim = global_nma_prog->numberOfModes; for (int i = 0; i < dim; i++) { global_nma_prog->trial(i) = X[i]; } int pyramidLevelDisc = 1; int pyramidLevelCont = (global_nma_prog->currentStage == 1) ? 1 : 0; FileName fnRandom = global_nma_prog->createDeformedPDB(pyramidLevelCont); const char * randStr = fnRandom.c_str(); if (global_nma_prog->currentStage == 1) { global_nma_prog->performCompleteSearch(fnRandom, pyramidLevelDisc); } else { double rot, tilt, psi, xshift, yshift; MetaData DF; rot = global_nma_prog->bestStage1( VEC_XSIZE(global_nma_prog->bestStage1) - 5); tilt = global_nma_prog->bestStage1( VEC_XSIZE(global_nma_prog->bestStage1) - 4); psi = global_nma_prog->bestStage1( VEC_XSIZE(global_nma_prog->bestStage1) - 3); xshift = global_nma_prog->bestStage1( VEC_XSIZE(global_nma_prog->bestStage1) - 2); yshift = global_nma_prog->bestStage1( VEC_XSIZE(global_nma_prog->bestStage1) - 1); size_t objId = DF.addObject(); FileName fnDown = formatString("%s_downimg.xmp", randStr); DF.setValue(MDL_IMAGE, fnDown, objId); DF.setValue(MDL_ENABLED, 1, objId); DF.setValue(MDL_ANGLE_ROT, rot, objId); DF.setValue(MDL_ANGLE_TILT, tilt, objId); DF.setValue(MDL_ANGLE_PSI, psi, objId); DF.setValue(MDL_SHIFT_X, xshift, objId); DF.setValue(MDL_SHIFT_Y, yshift, objId); DF.write(formatString("%s_angledisc.xmd", randStr)); copyImage(global_nma_prog->currentImgName.c_str(), fnDown.c_str()); } double fitness = global_nma_prog->performContinuousAssignment(fnRandom, pyramidLevelCont); runSystem("rm", formatString("-rf %s* &", randStr)); global_nma_prog->updateBestFit(fitness, dim); return fitness; }
// Calculate secondary structure for given HMM and return prediction void CalculateSS(HMM& q, char *ss_pred, char *ss_conf) { char tmpfile[]="/tmp/hhCalcSSXXXXXX"; if (mkstemp(tmpfile) == -1) { cerr << "ERROR! Could not create tmp-file!\n"; exit(4); } // Write log-odds matrix from q to tmpfile.mtx char filename[NAMELEN]; FILE* mtxf = NULL; strcpy(filename,tmpfile); strcat(filename,".mtx"); mtxf = fopen(filename,"w"); if (!mtxf) OpenFileError(filename); fprintf(mtxf,"%i\n",q.L); fprintf(mtxf,"%s\n",q.seq[q.nfirst]+1); fprintf(mtxf,"2.670000e-03\n4.100000e-02\n-3.194183e+00\n1.400000e-01\n2.670000e-03\n4.420198e-02\n-3.118986e+00\n1.400000e-01\n3.176060e-03\n1.339561e-01\n-2.010243e+00\n4.012145e-01\n"); for (int i = 1; i <= q.L; ++i) { fprintf(mtxf,"-32768 "); for (int a = 0; a < 20; ++a) { int tmp = iround(50*flog2(q.p[i][s2a[a]]/pb[s2a[a]])); fprintf(mtxf,"%5i ",tmp); if (a == 0) { // insert logodds value for B fprintf(mtxf,"%5i ",-32768); } else if (a == 18) { // insert logodds value for X fprintf(mtxf,"%5i ",-100); } else if (a == 19) { // insert logodds value for Z fprintf(mtxf,"%5i ",-32768); } } fprintf(mtxf,"-32768 -400\n"); } fclose(mtxf); // Calculate secondary structure CalculateSS(ss_pred, ss_conf, tmpfile); q.AddSSPrediction(ss_pred, ss_conf); // Remove temp-files std::string command = "rm " + (std::string)tmpfile + "*"; runSystem(command,v); }
int runNBodySimulation(const NBodyFlags* nbf) { NBodyCtx* ctx = &_ctx; NBodyState* st = &_st; int rc = 0; real chisq; double ts = 0.0, te = 0.0; nbodySetCtxFromFlags(ctx, nbf); if (setupRun(ctx, st, &ctx->histogramParams, nbf)) { return warn1("Failed to setup run\n"); } if (initOutput(st, nbf)) { return warn1("Failed to open output files\n"); } if (createSharedScene(st, ctx, nbf->inputFile)) { return warn1("Failed to create shared scene\n"); } ts = mwGetTime(); rc = runSystem(ctx, st, nbf); if (rc) return warn1("Error running system\n"); te = mwGetTime(); if (nbf->printTiming) { printf("<run_time> %f </run_time>\n", te - ts); } /* Get the likelihood */ chisq = nbodyChisq(ctx, st, nbf, &ctx->histogramParams); if (isnan(chisq)) { warn("Failed to calculate chisq\n"); rc = 1; } finalOutput(ctx, st, nbf, chisq); destroyNBodyState(st); return rc; }
// Perform complete search ================================================= void ProgNmaAlignment::performCompleteSearch(const FileName &fnRandom, int pyramidLevel) const { String program; String arguments; const char * randStr = fnRandom.c_str(); // Reduce the image FileName fnDown = formatString("%s_downimg.xmp", fnRandom.c_str()); if (pyramidLevel != 0) { Image<double> I; I.read(currentImgName); selfPyramidReduce(BSPLINE3, I(), pyramidLevel); I.write(fnDown); } else copyImage(currentImgName.c_str(), fnDown.c_str()); mkdir((fnRandom+"_ref").c_str(), S_IRWXU); double angSampling=2*RAD2DEG(atan(1.0/((double) imgSize / pow(2.0, (double) pyramidLevel+1)))); angSampling=std::max(angSampling,discrAngStep); program = "xmipp_angular_project_library"; arguments = formatString( "-i %s_deformedPDB.vol -o %s_ref/ref.stk --sampling_rate %f -v 0", randStr, randStr, angSampling); if (projMatch) arguments +=formatString( " --compute_neighbors --angular_distance -1 --experimental_images %s_downimg.xmp", randStr); runSystem(program, arguments, false); String refSelStr = formatString("%s_ref/ref.doc", randStr); if (fnmask != "") { program = "xmipp_transform_mask"; arguments = formatString("-i %s --mask binary_file %s", refSelStr.c_str(), fnmask.c_str()); runSystem(program, arguments, false); } // Perform alignment String fnOut=formatString("%s_angledisc.xmd",randStr); if (!projMatch) { program = "xmipp_angular_discrete_assign"; arguments = formatString( "-i %s_downimg.xmp --ref %s -o %s --psi_step 5 --max_shift_change %d --search5D -v 0", randStr, refSelStr.c_str(), fnOut.c_str(), (int)round((double) imgSize / (10.0 * pow(2.0, (double) pyramidLevel)))); } else { String refStkStr = formatString("%s_ref/ref.stk", randStr); program = "xmipp_angular_projection_matching"; arguments = formatString( "-i %s_downimg.xmp --ref %s -o %s --search5d_step 1 --max_shift %d -v 0", randStr, refStkStr.c_str(), fnOut.c_str(), (int)round((double) imgSize / (10.0 * pow(2.0, (double) pyramidLevel)))); } runSystem(program, arguments, false); if (projMatch) { MetaData MD; MD.read(fnOut); bool flip; size_t id=MD.firstObject(); MD.getValue(MDL_FLIP,flip,id); if (flip) { // This is because continuous assignment does not understand flips double shiftX, rot, tilt, psi, newrot, newtilt, newpsi; // Change sign in shiftX MD.getValue(MDL_SHIFT_X,shiftX,id); MD.setValue(MDL_SHIFT_X,-shiftX,id); // Change Euler angles MD.getValue(MDL_ANGLE_ROT,rot,id); MD.getValue(MDL_ANGLE_TILT,tilt,id); MD.getValue(MDL_ANGLE_PSI,psi,id); Euler_mirrorY(rot,tilt,psi,newrot,newtilt,newpsi); MD.setValue(MDL_ANGLE_ROT,newrot,id); MD.setValue(MDL_ANGLE_TILT,newtilt,id); MD.setValue(MDL_ANGLE_PSI,newpsi,id); MD.write(fnOut); } } }
int main(int argc, char **argv) { clock_t tic = clock(); FILE *fp; int i, choice, err; long numBytes; long Inpt= 0; int rem = 0; pid_t pid[NUM_THR_PROC]; struct primeArr *primeArray; int object_size = 1024 * 1024 * 600; sigset_t blockMask, origMask; struct sigaction saIgnore, saOrigQuit, saOrigInt, saDefault; printf("Please enter the max integer to search through for primes: ----> "); scanf("%ld",&Inpt); // derp(Inpt); // Used this function to initially get my numbers into a BITMAP // primeArray = crinit_primeArr(Inpt); // IgnorePts(primeArray); // p_primeArr(primeArray); //<<<------------------------- // mapPrimes(primeArray->num, Inpt); // freeArr(primeArray); //The number of bytes we want to pull in numBytes = Inpt / 4; //4 numbers are kept per char. // printf("ERROR\n"); if (Inpt % 4 > 0) { numBytes++;} // printf("ERROR\n"); unsigned char *myPrimes = malloc(sizeof(unsigned char*) * numBytes); //char myPrimes[numBytes]; //So we get an array of that many chars(x4 numbers) // printf("ERRORhelp\n"); //We open our bitmap(hashed in chars) and set it in the global list array fp = fopen("bitMap", "r"); fread(List, sizeof(myPrimes[0]), numBytes, fp ); //printf("ERROR\n"); Inpt = numBytes / NUM_THR_PROC; rem = numBytes % NUM_THR_PROC; printf("Would you like to run threads or system? 1 for threads, 2 for system, anything else to quit"); scanf("%d",&choice); //SIGNAL DEALING sigemptyset(&blockMask); /* Block SIGCHLD */ sigaddset(&blockMask, SIGCHLD); sigprocmask(SIG_BLOCK, &blockMask, &origMask); saIgnore.sa_handler = SIG_IGN; /* Ignore SIGINT and SIGQUIT */ saIgnore.sa_flags = 0; sigemptyset(&saIgnore.sa_mask); sigaction(SIGINT, &saIgnore, &saOrigInt); sigaction(SIGQUIT, &saIgnore, &saOrigQuit); if(choice == 1) runThreads(numBytes, Inpt, rem); if(choice == 2) { void *myAddr = mount_shmem("/shProc", object_size); myAddr = List; for(i = 0; i < NUM_THR_PROC; i++) { for(i=0; i<NUM_THR_PROC; ++i) { d[i].Depth = numBytes; int j = 0; int k = 0; d[i].offset = i; d[i].sliceSt = (Inpt * i); d[i].sliceEnd = Inpt * (i + 1); //If it is our last fork or thread... if(i == NUM_THR_PROC - 1) { d[i].sliceEnd = d[i].sliceEnd + rem; } } } for(i = 0; i < NUM_THR_PROC; i++) { switch(pid[i] = fork()) { case -1: fprintf(stderr, "Fork failed"); case 0: //child process saDefault.sa_handler = SIG_DFL; saDefault.sa_flags = 0; sigemptyset(&saDefault.sa_mask); if (saOrigInt.sa_handler != SIG_IGN) sigaction(SIGINT, &saDefault, NULL); if (saOrigQuit.sa_handler != SIG_IGN) sigaction(SIGQUIT, &saDefault, NULL); sigprocmask(SIG_SETMASK, &origMask, NULL); printf("%d start: \n", d[i].sliceSt); printf("%d end: \n", d->sliceEnd); runSystem(d[i].sliceSt, d[i].sliceEnd, d[i].offset); exit(EXIT_SUCCESS); default: break; } } } //Parse the char array and extract all happy primes with this FUNCtion. mapTurnin(numBytes); while(wait(NULL) != -1); shm_unlink("/shProc"); clock_t toc = clock(); printf("Elapsed: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC); return EXIT_SUCCESS; }