static int test_utime(void) { struct utimbuf utm; time_t atime = 987631200; time_t mtime = 123116400; int res; start_test("utime"); res = create_file(testfile, NULL, 0); if (res == -1) return -1; utm.actime = atime; utm.modtime = mtime; res = utime(testfile, &utm); if (res == -1) { PERROR("utime"); return -1; } res = check_times(testfile, atime, mtime); if (res == -1) { return -1; } res = unlink(testfile); if (res == -1) { PERROR("unlink"); return -1; } res = check_nonexist(testfile); if (res == -1) return -1; success(); return 0; }
void finish_mpg(multiplex_t *mx) { int start=0; int video_ok = 0; int ext_ok[N_AUDIO]; int n,nn,old,i; uint8_t mpeg_end[4] = { 0x00, 0x00, 0x01, 0xB9 }; memset(ext_ok, 0, N_AUDIO*sizeof(int)); mx->finish = 1; old = 0;nn=0; while ((n=buffers_filled(mx)) && nn<1000 ){ if (n== old) nn++; else nn=0; old = n; check_times( mx, &video_ok, ext_ok, &start); write_out_packs( mx, video_ok, ext_ok); } old = 0;nn=0; while ((n=ring_avail(mx->index_vrbuffer)/sizeof(index_unit)) && nn<1000){ if (n== old) nn++; else nn= 0; old = n; writeout_video(mx); } // flush the rest mx->finish = 2; old = 0;nn=0; for (i = 0; i < mx->extcnt; i++){ while ((n=ring_avail(&mx->index_extrbuffer[i])/ sizeof(index_unit)) && nn <100){ if (n== old) nn++; else nn = 0; old = n; writeout_ext(mx, i); } } if (mx->otype == REPLEX_MPEG2) write(mx->fd_out, mpeg_end,4); dummy_destroy(&mx->vdbuf); for (i=0; i<mx->extcnt;i++) dummy_destroy(&mx->ext[i].dbuf); }
void run_order (rule_t * rule_x ) { if(queue_size(rule_x->deps)==0){ // run only when no dependency run_rule(rule_x); return; } int res,res1,res2; res=all_file(rule_x); if(res==1){ //all dependencies are files res1 = is_file(rule_x->target); if(res1==0){ // name of rule doesn't exist as file run_rule(rule_x); } else if (res1==1){ //name of rule exists as file on disk res2=check_times(rule_x->target , rule_x->deps ); //checks if time of rule is newer than all deps if(res2==1){ //if rule has newer mod time than any dep if(is_dep(rule_x->target)==1){ pthread_mutex_lock(&mutex2); //LOCK queue_enqueue(&has_ran,rule_x->target); remove_dep(rule_x->target); remain_size--; pthread_mutex_unlock(&mutex2); //UNLOCK } } else{ run_rule(rule_x); } }//else-if }//if }
int gmx_lie(int argc,char *argv[]) { const char *desc[] = { "g_lie computes a free energy estimate based on an energy analysis", "from. One needs an energy file with the following components:", "Coul (A-B) LJ-SR (A-B) etc." }; static real lie_lj=0,lie_qq=0,fac_lj=0.181,fac_qq=0.5; static const char *ligand="none"; t_pargs pa[] = { { "-Elj", FALSE, etREAL, {&lie_lj}, "Lennard-Jones interaction between ligand and solvent" }, { "-Eqq", FALSE, etREAL, {&lie_qq}, "Coulomb interaction between ligand and solvent" }, { "-Clj", FALSE, etREAL, {&fac_lj}, "Factor in the LIE equation for Lennard-Jones component of energy" }, { "-Cqq", FALSE, etREAL, {&fac_qq}, "Factor in the LIE equation for Coulomb component of energy" }, { "-ligand", FALSE, etSTR, {&ligand}, "Name of the ligand in the energy file" } }; #define NPA asize(pa) FILE *out; int nre,nframes=0,ct=0; ener_file_t fp; gmx_bool bCont; t_liedata *ld; gmx_enxnm_t *enm=NULL; t_enxframe *fr; real lie; double lieaver=0,lieav2=0; output_env_t oenv; t_filenm fnm[] = { { efEDR, "-f", "ener", ffREAD }, { efXVG, "-o", "lie", 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,NPA,pa,asize(desc),desc,0,NULL,&oenv); fp = open_enx(ftp2fn(efEDR,NFILE,fnm),"r"); do_enxnms(fp,&nre,&enm); ld = analyze_names(nre,enm,ligand); snew(fr,1); out = xvgropen(ftp2fn(efXVG,NFILE,fnm),"LIE free energy estimate", "Time (ps)","DGbind (kJ/mol)",oenv); do { bCont = do_enx(fp,fr); ct = check_times(fr->t); if (ct == 0) { lie = calc_lie(ld,fr->ener,lie_lj,lie_qq,fac_lj,fac_qq); lieaver += lie; lieav2 += lie*lie; nframes ++; fprintf(out,"%10g %10g\n",fr->t,lie); } } while (bCont); close_enx(fp); ffclose(out); fprintf(stderr,"\n"); if (nframes > 0) printf("DGbind = %.3f (%.3f)\n",lieaver/nframes, sqrt(lieav2/nframes-sqr(lieaver/nframes))); do_view(oenv,ftp2fn(efXVG,NFILE,fnm),"-nxy"); thanx(stderr); return 0; }
bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status, const char *fn, t_trxframe *fr, int flags) { t_fileio *fio = nullptr; gmx_bool bFirst, bOK; int ftp = fn2ftp(fn); clear_trxframe(fr, TRUE); bFirst = TRUE; snew((*status), 1); status_init( *status ); initcount(*status); (*status)->flags = flags; if (efTNG == ftp) { /* Special treatment for TNG files */ gmx_tng_open(fn, 'r', &(*status)->tng); } else { fio = (*status)->fio = gmx_fio_open(fn, "r"); } switch (ftp) { case efTRR: break; case efCPT: read_checkpoint_trxframe(fio, fr); bFirst = FALSE; break; case efG96: { /* Can not rewind a compressed file, so open it twice */ if (!(*status)->persistent_line) { /* allocate the persistent line */ snew((*status)->persistent_line, STRLEN+1); } t_symtab *symtab = nullptr; read_g96_conf(gmx_fio_getfp(fio), fn, nullptr, fr, symtab, (*status)->persistent_line); gmx_fio_close(fio); clear_trxframe(fr, FALSE); if (flags & (TRX_READ_X | TRX_NEED_X)) { snew(fr->x, fr->natoms); } if (flags & (TRX_READ_V | TRX_NEED_V)) { snew(fr->v, fr->natoms); } (*status)->fio = gmx_fio_open(fn, "r"); break; } case efXTC: if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x, &fr->prec, &bOK) == 0) { GMX_RELEASE_ASSERT(!bOK, "Inconsistent results - OK status from read_first_xtc, but 0 atom coords read"); fr->not_ok = DATA_NOT_OK; } if (fr->not_ok) { fr->natoms = 0; printincomp(*status, fr); } else { fr->bPrec = (fr->prec > 0); fr->bStep = TRUE; fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efTNG: fr->step = -1; if (!gmx_read_next_tng_frame((*status)->tng, fr, nullptr, 0)) { fr->not_ok = DATA_NOT_OK; fr->natoms = 0; printincomp(*status, fr); } else { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efPDB: pdb_first_x(*status, gmx_fio_getfp(fio), fr); if (fr->natoms) { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efGRO: if (gro_first_x_or_v(gmx_fio_getfp(fio), fr)) { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; default: #if GMX_USE_PLUGINS fprintf(stderr, "The file format of %s is not a known trajectory format to GROMACS.\n" "Please make sure that the file is a trajectory!\n" "GROMACS will now assume it to be a trajectory and will try to open it using the VMD plug-ins.\n" "This will only work in case the VMD plugins are found and it is a trajectory format supported by VMD.\n", fn); gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/ if (!read_first_vmd_frame(fn, &(*status)->vmdplugin, fr)) { gmx_fatal(FARGS, "Not supported in read_first_frame: %s", fn); } #else gmx_fatal(FARGS, "Not supported in read_first_frame: %s. Please make sure that the file is a trajectory.\n" "GROMACS is not compiled with plug-in support. Thus it cannot read non-GROMACS trajectory formats using the VMD plug-ins.\n" "Please compile with plug-in support if you want to read non-GROMACS trajectory formats.\n", fn); #endif break; } (*status)->tf = fr->time; /* Return FALSE if we read a frame that's past the set ending time. */ if (!bFirst && (!(flags & TRX_DONT_SKIP) && check_times(fr->time) > 0)) { (*status)->t0 = fr->time; return FALSE; } if (bFirst || (!(flags & TRX_DONT_SKIP) && check_times(fr->time) < 0)) { /* Read a frame when no frame was read or the first was skipped */ if (!read_next_frame(oenv, *status, fr)) { return FALSE; } } (*status)->t0 = fr->time; /* We need the number of atoms for random-access XTC searching, even when * we don't have access to the actual frame data. */ (*status)->natoms = fr->natoms; return (fr->natoms > 0); }
int main (int argc, char **argv) { pthread_t *threads; long i; int ret; struct timespec intv; struct sched_param param; parse_options(argc, argv); signal(SIGINT, stop_log); if (argc >= (optind + 1)) nr_tasks = atoi(argv[optind]); else nr_tasks = count_cpus() + 1; threads = malloc(sizeof(*threads) * nr_tasks); if (!threads) perr("malloc"); memset(threads, 0, sizeof(*threads) * nr_tasks); ret = pthread_barrier_init(&start_barrier, NULL, nr_tasks + 1); ret = pthread_barrier_init(&end_barrier, NULL, nr_tasks + 1); if (ret < 0) perr("pthread_barrier_init"); intervals = malloc(sizeof(void*) * nr_runs); if (!intervals) perr("malloc intervals array"); intervals_length = malloc(sizeof(void*) * nr_runs); if (!intervals_length) perr("malloc intervals length array"); intervals_loops = malloc(sizeof(void*) * nr_runs); if (!intervals_loops) perr("malloc intervals loops array"); thread_pids = malloc(sizeof(long) * nr_tasks); if (!thread_pids) perr("malloc thread_pids"); for (i=0; i < nr_runs; i++) { intervals[i] = malloc(sizeof(unsigned long long)*nr_tasks); if (!intervals[i]) perr("malloc intervals"); memset(intervals[i], 0, sizeof(unsigned long long)*nr_tasks); intervals_length[i] = malloc(sizeof(unsigned long long)*nr_tasks); if (!intervals_length[i]) perr("malloc length intervals"); memset(intervals_length[i], 0, sizeof(unsigned long long)*nr_tasks); intervals_loops[i] = malloc(sizeof(unsigned long)*nr_tasks); if (!intervals_loops[i]) perr("malloc loops intervals"); memset(intervals_loops[i], 0, sizeof(unsigned long)*nr_tasks); } for (i=0; i < nr_tasks; i++) { if (pthread_create(&threads[i], NULL, start_task, (void *)i)) perr("pthread_create"); } /* * Progress bar uses stderr to let users see it when * redirecting output. So we convert stderr to use line * buffering so the progress bar doesn't flicker. */ setlinebuf(stderr); /* up our prio above all tasks */ memset(¶m, 0, sizeof(param)); param.sched_priority = nr_tasks + prio_start; if (sched_setscheduler(0, SCHED_FIFO, ¶m)) fprintf(stderr, "Warning, can't set priority of main thread!\n"); intv.tv_sec = nano2sec(INTERVAL); intv.tv_nsec = INTERVAL % sec2nano(1); print_progress_bar(0); lfd = do_logdev_open(); logdev_print_set(1); logdev_switch_set(1); for (loop=0; loop < nr_runs; loop++) { unsigned long long end; now = get_time(); lgprint(lfd, "Loop %d now=%lld\n", loop, now); pthread_barrier_wait(&start_barrier); lgprint(lfd, "All running!!!\n"); nanosleep(&intv, NULL); print_progress_bar((loop * 100)/ nr_runs); end = get_time(); lgprint(lfd, "Loop %d end now=%lld diff=%lld\n", loop, end, end - now); pthread_barrier_wait(&end_barrier); if (stop || (check && check_times(loop))) { loop++; nr_runs = loop; break; } } do_logdev_close(lfd); putc('\n', stderr); pthread_barrier_wait(&start_barrier); done = 1; pthread_barrier_wait(&end_barrier); for (i=0; i < nr_tasks; i++) pthread_join(threads[i], (void*)&thread_pids[i]); logdev_print_set(0); logdev_switch_set(0); print_results(); if (stop) { /* * We use this test in bash while loops * So if we hit Ctrl-C then let the while * loop know to break. */ if (check < 0) exit(-1); else exit(1); } if (check < 0) exit(-1); else exit(0); return 0; }
int read_first_frame(const output_env_t oenv, t_trxstatus **status, const char *fn, t_trxframe *fr, int flags) { t_fileio *fio; gmx_bool bFirst, bOK; int dummy = 0; clear_trxframe(fr, TRUE); fr->flags = flags; bFirst = TRUE; snew((*status), 1); status_init( *status ); (*status)->nxframe = 1; initcount(*status); fio = (*status)->fio = gmx_fio_open(fn, "r"); switch (gmx_fio_getftp(fio)) { case efTRJ: case efTRR: break; case efCPT: read_checkpoint_trxframe(fio, fr); bFirst = FALSE; break; case efG96: /* Can not rewind a compressed file, so open it twice */ if (!(*status)->persistent_line) { /* allocate the persistent line */ snew((*status)->persistent_line, STRLEN+1); } read_g96_conf(gmx_fio_getfp(fio), fn, fr, (*status)->persistent_line); gmx_fio_close(fio); clear_trxframe(fr, FALSE); if (flags & (TRX_READ_X | TRX_NEED_X)) { snew(fr->x, fr->natoms); } if (flags & (TRX_READ_V | TRX_NEED_V)) { snew(fr->v, fr->natoms); } fio = (*status)->fio = gmx_fio_open(fn, "r"); break; case efG87: fr->natoms = xyz_first_x(*status, gmx_fio_getfp(fio), oenv, &fr->time, &fr->x, fr->box); if (fr->natoms) { fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efXTC: if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x, &fr->prec, &bOK) == 0) { if (bOK) { gmx_fatal(FARGS, "No XTC!\n"); } else { fr->not_ok = DATA_NOT_OK; } } if (fr->not_ok) { fr->natoms = 0; printincomp(*status, fr); } else { fr->bPrec = (fr->prec > 0); fr->bStep = TRUE; fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efPDB: pdb_first_x(*status, gmx_fio_getfp(fio), fr); if (fr->natoms) { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efGRO: if (gro_first_x_or_v(gmx_fio_getfp(fio), fr)) { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; default: #ifdef GMX_USE_PLUGINS fprintf(stderr, "The file format of %s is not a known trajectory format to GROMACS.\n" "Please make sure that the file is a trajectory!\n" "GROMACS will now assume it to be a trajectory and will try to open it using the VMD plug-ins.\n" "This will only work in case the VMD plugins are found and it is a trajectory format supported by VMD.\n", fn); gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/ if (!read_first_vmd_frame(fn, fr)) { gmx_fatal(FARGS, "Not supported in read_first_frame: %s", fn); } #else gmx_fatal(FARGS, "Not supported in read_first_frame: %s. Please make sure that the file is a trajectory.\n" "GROMACS is not compiled with plug-in support. Thus it cannot read non-GROMACS trajectory formats using the VMD plug-ins.\n" "Please compile with plug-in support if you want to read non-GROMACS trajectory formats.\n", fn); #endif break; } /* Return FALSE if we read a frame that's past the set ending time. */ if (!bFirst && (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) > 0)) { fr->t0 = fr->time; return FALSE; } if (bFirst || (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) < 0)) { /* Read a frame when no frame was read or the first was skipped */ if (!read_next_frame(oenv, *status, fr)) { return FALSE; } } fr->t0 = fr->time; return (fr->natoms > 0); }
int gmx_enemat(int argc, char *argv[]) { const char *desc[] = { "[THISMODULE] extracts an energy matrix from the energy file ([TT]-f[tt]).", "With [TT]-groups[tt] a file must be supplied with on each", "line a group of atoms to be used. For these groups matrix of", "interaction energies will be extracted from the energy file", "by looking for energy groups with names corresponding to pairs", "of groups of atoms, e.g. if your [TT]-groups[tt] file contains::", "", " 2", " Protein", " SOL", "", "then energy groups with names like 'Coul-SR:Protein-SOL' and ", "'LJ:Protein-SOL' are expected in the energy file (although", "[THISMODULE] is most useful if many groups are analyzed", "simultaneously). Matrices for different energy types are written", "out separately, as controlled by the", "[TT]-[no]coul[tt], [TT]-[no]coulr[tt], [TT]-[no]coul14[tt], ", "[TT]-[no]lj[tt], [TT]-[no]lj14[tt], ", "[TT]-[no]bham[tt] and [TT]-[no]free[tt] options.", "Finally, the total interaction energy energy per group can be ", "calculated ([TT]-etot[tt]).[PAR]", "An approximation of the free energy can be calculated using:", "[MATH]E[SUB]free[sub] = E[SUB]0[sub] + kT [LOG][CHEVRON][EXP](E-E[SUB]0[sub])/kT[exp][chevron][log][math], where '[MATH][CHEVRON][chevron][math]'", "stands for time-average. A file with reference free energies", "can be supplied to calculate the free energy difference", "with some reference state. Group names (e.g. residue names)", "in the reference file should correspond to the group names", "as used in the [TT]-groups[tt] file, but a appended number", "(e.g. residue number) in the [TT]-groups[tt] will be ignored", "in the comparison." }; static gmx_bool bSum = FALSE; static gmx_bool bMeanEmtx = TRUE; static int skip = 0, nlevels = 20; static real cutmax = 1e20, cutmin = -1e20, reftemp = 300.0; static gmx_bool bCoulSR = TRUE, bCoul14 = FALSE; static gmx_bool bLJSR = TRUE, bLJ14 = FALSE, bBhamSR = FALSE, bFree = TRUE; t_pargs pa[] = { { "-sum", FALSE, etBOOL, {&bSum}, "Sum the energy terms selected rather than display them all" }, { "-skip", FALSE, etINT, {&skip}, "Skip number of frames between data points" }, { "-mean", FALSE, etBOOL, {&bMeanEmtx}, "with [TT]-groups[tt] extracts matrix of mean energies instead of " "matrix for each timestep" }, { "-nlevels", FALSE, etINT, {&nlevels}, "number of levels for matrix colors"}, { "-max", FALSE, etREAL, {&cutmax}, "max value for energies"}, { "-min", FALSE, etREAL, {&cutmin}, "min value for energies"}, { "-coulsr", FALSE, etBOOL, {&bCoulSR}, "extract Coulomb SR energies"}, { "-coul14", FALSE, etBOOL, {&bCoul14}, "extract Coulomb 1-4 energies"}, { "-ljsr", FALSE, etBOOL, {&bLJSR}, "extract Lennard-Jones SR energies"}, { "-lj14", FALSE, etBOOL, {&bLJ14}, "extract Lennard-Jones 1-4 energies"}, { "-bhamsr", FALSE, etBOOL, {&bBhamSR}, "extract Buckingham SR energies"}, { "-free", FALSE, etBOOL, {&bFree}, "calculate free energy"}, { "-temp", FALSE, etREAL, {&reftemp}, "reference temperature for free energy calculation"} }; /* We will define egSP more energy-groups: egTotal (total energy) */ #define egTotal egNR #define egSP 1 gmx_bool egrp_use[egNR+egSP]; ener_file_t in; FILE *out; int timecheck = 0; gmx_enxnm_t *enm = NULL; t_enxframe *fr; int teller = 0; real sum; gmx_bool bCont, bRef; gmx_bool bCutmax, bCutmin; real **eneset, *time = NULL; int *set, i, j, k, prevk, m = 0, n, nre, nset, nenergy; char **groups = NULL; char groupname[255], fn[255]; int ngroups; t_rgb rlo, rhi, rmid; real emax, emid, emin; real ***emat, **etot, *groupnr; double beta, expE, **e, *eaver, *efree = NULL, edum; char label[234]; char **ereflines, **erefres = NULL; real *eref = NULL, *edif = NULL; int neref = 0; gmx_output_env_t *oenv; t_filenm fnm[] = { { efEDR, "-f", NULL, ffOPTRD }, { efDAT, "-groups", "groups", ffREAD }, { efDAT, "-eref", "eref", ffOPTRD }, { efXPM, "-emat", "emat", ffWRITE }, { efXVG, "-etot", "energy", ffWRITE } }; #define NFILE asize(fnm) if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv)) { return 0; } for (i = 0; (i < egNR+egSP); i++) { egrp_use[i] = FALSE; } egrp_use[egCOULSR] = bCoulSR; egrp_use[egLJSR] = bLJSR; egrp_use[egBHAMSR] = bBhamSR; egrp_use[egCOUL14] = bCoul14; egrp_use[egLJ14] = bLJ14; egrp_use[egTotal] = TRUE; bRef = opt2bSet("-eref", NFILE, fnm); in = open_enx(ftp2fn(efEDR, NFILE, fnm), "r"); do_enxnms(in, &nre, &enm); if (nre == 0) { gmx_fatal(FARGS, "No energies!\n"); } bCutmax = opt2parg_bSet("-max", asize(pa), pa); bCutmin = opt2parg_bSet("-min", asize(pa), pa); nenergy = 0; /* Read groupnames from input file and construct selection of energy groups from it*/ fprintf(stderr, "Will read groupnames from inputfile\n"); ngroups = get_lines(opt2fn("-groups", NFILE, fnm), &groups); fprintf(stderr, "Read %d groups\n", ngroups); snew(set, static_cast<size_t>(gmx::square(ngroups)*egNR/2)); n = 0; prevk = 0; for (i = 0; (i < ngroups); i++) { fprintf(stderr, "\rgroup %d", i); for (j = i; (j < ngroups); j++) { for (m = 0; (m < egNR); m++) { if (egrp_use[m]) { sprintf(groupname, "%s:%s-%s", egrp_nm[m], groups[i], groups[j]); #ifdef DEBUG fprintf(stderr, "\r%-15s %5d", groupname, n); #endif for (k = prevk; (k < prevk+nre); k++) { if (std::strcmp(enm[k%nre].name, groupname) == 0) { set[n++] = k; break; } } if (k == prevk+nre) { fprintf(stderr, "WARNING! could not find group %s (%d,%d)" "in energy file\n", groupname, i, j); } else { prevk = k; } } } } } fprintf(stderr, "\n"); nset = n; snew(eneset, nset+1); fprintf(stderr, "Will select half-matrix of energies with %d elements\n", n); /* Start reading energy frames */ snew(fr, 1); do { do { bCont = do_enx(in, fr); if (bCont) { timecheck = check_times(fr->t); } } while (bCont && (timecheck < 0)); if (timecheck == 0) { #define DONTSKIP(cnt) (skip) ? ((cnt % skip) == 0) : TRUE if (bCont) { fprintf(stderr, "\rRead frame: %d, Time: %.3f", teller, fr->t); if ((nenergy % 1000) == 0) { srenew(time, nenergy+1000); for (i = 0; (i <= nset); i++) { srenew(eneset[i], nenergy+1000); } } time[nenergy] = fr->t; sum = 0; for (i = 0; (i < nset); i++) { eneset[i][nenergy] = fr->ener[set[i]].e; sum += fr->ener[set[i]].e; } if (bSum) { eneset[nset][nenergy] = sum; } nenergy++; } teller++; } } while (bCont && (timecheck == 0)); fprintf(stderr, "\n"); fprintf(stderr, "Will build energy half-matrix of %d groups, %d elements, " "over %d frames\n", ngroups, nset, nenergy); snew(emat, egNR+egSP); for (j = 0; (j < egNR+egSP); j++) { if (egrp_use[m]) { snew(emat[j], ngroups); for (i = 0; (i < ngroups); i++) { snew(emat[j][i], ngroups); } } } snew(groupnr, ngroups); for (i = 0; (i < ngroups); i++) { groupnr[i] = i+1; } rlo.r = 1.0, rlo.g = 0.0, rlo.b = 0.0; rmid.r = 1.0, rmid.g = 1.0, rmid.b = 1.0; rhi.r = 0.0, rhi.g = 0.0, rhi.b = 1.0; if (bMeanEmtx) { snew(e, ngroups); for (i = 0; (i < ngroups); i++) { snew(e[i], nenergy); } n = 0; for (i = 0; (i < ngroups); i++) { for (j = i; (j < ngroups); j++) { for (m = 0; (m < egNR); m++) { if (egrp_use[m]) { for (k = 0; (k < nenergy); k++) { emat[m][i][j] += eneset[n][k]; e[i][k] += eneset[n][k]; /* *0.5; */ e[j][k] += eneset[n][k]; /* *0.5; */ } n++; emat[egTotal][i][j] += emat[m][i][j]; emat[m][i][j] /= nenergy; emat[m][j][i] = emat[m][i][j]; } } emat[egTotal][i][j] /= nenergy; emat[egTotal][j][i] = emat[egTotal][i][j]; } } if (bFree) { if (bRef) { fprintf(stderr, "Will read reference energies from inputfile\n"); neref = get_lines(opt2fn("-eref", NFILE, fnm), &ereflines); fprintf(stderr, "Read %d reference energies\n", neref); snew(eref, neref); snew(erefres, neref); for (i = 0; (i < neref); i++) { snew(erefres[i], 5); sscanf(ereflines[i], "%s %lf", erefres[i], &edum); eref[i] = edum; } } snew(eaver, ngroups); for (i = 0; (i < ngroups); i++) { for (k = 0; (k < nenergy); k++) { eaver[i] += e[i][k]; } eaver[i] /= nenergy; } beta = 1.0/(BOLTZ*reftemp); snew(efree, ngroups); snew(edif, ngroups); for (i = 0; (i < ngroups); i++) { expE = 0; for (k = 0; (k < nenergy); k++) { expE += std::exp(beta*(e[i][k]-eaver[i])); } efree[i] = std::log(expE/nenergy)/beta + eaver[i]; if (bRef) { n = search_str2(neref, erefres, groups[i]); if (n != -1) { edif[i] = efree[i]-eref[n]; } else { edif[i] = efree[i]; fprintf(stderr, "WARNING: group %s not found " "in reference energies.\n", groups[i]); } } else { edif[i] = 0; } } } emid = 0.0; /*(emin+emax)*0.5;*/ egrp_nm[egTotal] = "total"; for (m = 0; (m < egNR+egSP); m++) { if (egrp_use[m]) { emin = 1e10; emax = -1e10; for (i = 0; (i < ngroups); i++) { for (j = i; (j < ngroups); j++) { if (emat[m][i][j] > emax) { emax = emat[m][i][j]; } else if (emat[m][i][j] < emin) { emin = emat[m][i][j]; } } } if (emax == emin) { fprintf(stderr, "Matrix of %s energy is uniform at %f " "(will not produce output).\n", egrp_nm[m], emax); } else { fprintf(stderr, "Matrix of %s energy ranges from %f to %f\n", egrp_nm[m], emin, emax); if ((bCutmax) || (emax > cutmax)) { emax = cutmax; } if ((bCutmin) || (emin < cutmin)) { emin = cutmin; } if ((emax == cutmax) || (emin == cutmin)) { fprintf(stderr, "Energy range adjusted: %f to %f\n", emin, emax); } sprintf(fn, "%s%s", egrp_nm[m], ftp2fn(efXPM, NFILE, fnm)); sprintf(label, "%s Interaction Energies", egrp_nm[m]); out = gmx_ffopen(fn, "w"); if (emin >= emid) { write_xpm(out, 0, label, "Energy (kJ/mol)", "Residue Index", "Residue Index", ngroups, ngroups, groupnr, groupnr, emat[m], emid, emax, rmid, rhi, &nlevels); } else if (emax <= emid) { write_xpm(out, 0, label, "Energy (kJ/mol)", "Residue Index", "Residue Index", ngroups, ngroups, groupnr, groupnr, emat[m], emin, emid, rlo, rmid, &nlevels); } else { write_xpm3(out, 0, label, "Energy (kJ/mol)", "Residue Index", "Residue Index", ngroups, ngroups, groupnr, groupnr, emat[m], emin, emid, emax, rlo, rmid, rhi, &nlevels); } gmx_ffclose(out); } } } snew(etot, egNR+egSP); for (m = 0; (m < egNR+egSP); m++) { snew(etot[m], ngroups); for (i = 0; (i < ngroups); i++) { for (j = 0; (j < ngroups); j++) { etot[m][i] += emat[m][i][j]; } } } out = xvgropen(ftp2fn(efXVG, NFILE, fnm), "Mean Energy", "Residue", "kJ/mol", oenv); xvgr_legend(out, 0, NULL, oenv); j = 0; if (output_env_get_print_xvgr_codes(oenv)) { char str1[STRLEN], str2[STRLEN]; if (output_env_get_xvg_format(oenv) == exvgXMGR) { sprintf(str1, "@ legend string "); sprintf(str2, " "); } else { sprintf(str1, "@ s"); sprintf(str2, " legend "); } for (m = 0; (m < egNR+egSP); m++) { if (egrp_use[m]) { fprintf(out, "%s%d%s \"%s\"\n", str1, j++, str2, egrp_nm[m]); } } if (bFree) { fprintf(out, "%s%d%s \"%s\"\n", str1, j++, str2, "Free"); } if (bFree) { fprintf(out, "%s%d%s \"%s\"\n", str1, j++, str2, "Diff"); } fprintf(out, "@TYPE xy\n"); fprintf(out, "#%3s", "grp"); for (m = 0; (m < egNR+egSP); m++) { if (egrp_use[m]) { fprintf(out, " %9s", egrp_nm[m]); } } if (bFree) { fprintf(out, " %9s", "Free"); } if (bFree) { fprintf(out, " %9s", "Diff"); } fprintf(out, "\n"); } for (i = 0; (i < ngroups); i++) { fprintf(out, "%3.0f", groupnr[i]); for (m = 0; (m < egNR+egSP); m++) { if (egrp_use[m]) { fprintf(out, " %9.5g", etot[m][i]); } } if (bFree) { fprintf(out, " %9.5g", efree[i]); } if (bRef) { fprintf(out, " %9.5g", edif[i]); } fprintf(out, "\n"); } xvgrclose(out); } else { fprintf(stderr, "While typing at your keyboard, suddenly...\n" "...nothing happens.\nWARNING: Not Implemented Yet\n"); /* out=ftp2FILE(efMAT,NFILE,fnm,"w"); n=0; emin=emax=0.0; for (k=0; (k<nenergy); k++) { for (i=0; (i<ngroups); i++) for (j=i+1; (j<ngroups); j++) emat[i][j]=eneset[n][k]; sprintf(label,"t=%.0f ps",time[k]); write_matrix(out,ngroups,1,ngroups,groupnr,emat,label,emin,emax,nlevels); n++; } gmx_ffclose(out); */ } close_enx(in); return 0; }
int gmx_lie(int argc, char *argv[]) { const char *desc[] = { "[THISMODULE] computes a free energy estimate based on an energy analysis", "from nonbonded energies. One needs an energy file with the following components:", "Coul-(A-B) LJ-SR (A-B) etc.[PAR]", "To utilize [TT]g_lie[tt] correctly, two simulations are required: one with the", "molecule of interest bound to its receptor and one with the molecule in water.", "Both need to utilize [TT]energygrps[tt] such that Coul-SR(A-B), LJ-SR(A-B), etc. terms", "are written to the [REF].edr[ref] file. Values from the molecule-in-water simulation", "are necessary for supplying suitable values for -Elj and -Eqq." }; static real lie_lj = 0, lie_qq = 0, fac_lj = 0.181, fac_qq = 0.5; static const char *ligand = "none"; t_pargs pa[] = { { "-Elj", FALSE, etREAL, {&lie_lj}, "Lennard-Jones interaction between ligand and solvent" }, { "-Eqq", FALSE, etREAL, {&lie_qq}, "Coulomb interaction between ligand and solvent" }, { "-Clj", FALSE, etREAL, {&fac_lj}, "Factor in the LIE equation for Lennard-Jones component of energy" }, { "-Cqq", FALSE, etREAL, {&fac_qq}, "Factor in the LIE equation for Coulomb component of energy" }, { "-ligand", FALSE, etSTR, {&ligand}, "Name of the ligand in the energy file" } }; #define NPA asize(pa) FILE *out; int nre, nframes = 0, ct = 0; ener_file_t fp; t_liedata *ld; gmx_enxnm_t *enm = NULL; t_enxframe *fr; real lie; double lieaver = 0, lieav2 = 0; gmx_output_env_t *oenv; t_filenm fnm[] = { { efEDR, "-f", "ener", ffREAD }, { efXVG, "-o", "lie", ffWRITE } }; #define NFILE asize(fnm) if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME, NFILE, fnm, NPA, pa, asize(desc), desc, 0, NULL, &oenv)) { return 0; } fp = open_enx(ftp2fn(efEDR, NFILE, fnm), "r"); do_enxnms(fp, &nre, &enm); ld = analyze_names(nre, enm, ligand); snew(fr, 1); out = xvgropen(ftp2fn(efXVG, NFILE, fnm), "LIE free energy estimate", "Time (ps)", "DGbind (kJ/mol)", oenv); while (do_enx(fp, fr)) { ct = check_times(fr->t); if (ct == 0) { lie = calc_lie(ld, fr->ener, lie_lj, lie_qq, fac_lj, fac_qq); lieaver += lie; lieav2 += lie*lie; nframes++; fprintf(out, "%10g %10g\n", fr->t, lie); } } close_enx(fp); xvgrclose(out); fprintf(stderr, "\n"); if (nframes > 0) { printf("DGbind = %.3f (%.3f)\n", lieaver/nframes, std::sqrt(lieav2/nframes-sqr(lieaver/nframes))); } do_view(oenv, ftp2fn(efXVG, NFILE, fnm), "-nxy"); return 0; }
//aux to call stats functions void statistics(char stat) { if(stopApp==1)main(); char tmp[1024]= {0x0}; int fldcnt=0; char arr[MAXFLDS][MAXFLDSIZE]= {0x0}; int recordcnt=0; if(stat=='a') strcpy(filename,""); if (!strcmp(filename,"")) { printf("Enter key [d] to assume defaults [logcsv.csv],\n"); printf("or insert the name of the CSV file [file.csv]: "); scanf("%s", filename); } if (!strcmp(filename,"d")) strcpy(filename,"logcsv.csv"); in = fopen(filename,"r");/* open file on command line */ if(checkFileIn()==-1) { optionSaveStats='3'; printf("Error loading file...[%s]\n\n", filename); statistics('a'); } if(checkFileIn()==0) { if(stat=='a')printf("Loading file...[%s]\n\n", filename); fgets(tmp,sizeof(tmp),in); /*jump over header*/ while(fgets(tmp,sizeof(tmp),in)!=0) /* read a record */ { i=0; j=0; recordcnt++; parse(tmp,",",arr,&fldcnt); /* whack record into fields */ for(i; i<fldcnt; i++) { //copy all records to strs strcpy(strs[recordcnt-1][i],arr[i]); } } if(stat=='a')printf("Done!!!\n", filename); if(stat=='a')PressEnterToReturn(); } if (stat=='b') { system("clear"); print_all_macip(recordcnt, 2,"Source devices:\n"); //list of all source devices - print mac and ip PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='c') { system("clear"); print_all(recordcnt, 8, "Source ports:\n"); //list of all source ports PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='d') { system("clear"); print_all_macip(recordcnt, 3,"\nDestination devices:\n"); //list of all destination devices - print mac and ip PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='e') { system("clear"); print_all(recordcnt, 9, "Destination ports:\n"); //list of all destination ports PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='f') { system("clear"); rep_count(recordcnt, 12, "0", "\nNº of Queries: "); //count number of queries, verifying the flag response=o PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='g') { system("clear"); rep_count(recordcnt, 12, "1", "\nNº of Responses: "); //count number of responses, verifying the flag response=1 PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='h') { system("clear"); rep_count(recordcnt, 13, "3", "\nNº of Rcodes: "); //count number of Rcodes errors PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='i') { system("clear"); check_times(recordcnt, 10); //verify delay between question and answer PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='j') { system("clear"); print_all_stats(recordcnt, 2, "\nMAC source:"); //stats MAC Source PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='k') { system("clear"); print_all_stats(recordcnt, 3, "\nMAC destination:");//stats MAC destination PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='l') { system("clear"); print_all_stats(recordcnt, 18, "\nNames:");//stats Name PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='m') { system("clear"); string keyword; printf("Insert the keyword to search in all queries: "); scanf("%s", keyword); count_occurrences(recordcnt, 18, "\nThe selected keyword:", keyword); PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } if (stat=='n') { system("clear"); check_blacklisted(recordcnt, 21, "\nCheck queries responses:\n");//Check queries responses PressEnterToReturn(); fclose(in); optionSaveStats='3'; system("clear"); statsMenu(); } statsMenu(); }
static void do_dip(t_topology *top,int ePBC,real volume, const char *fn, const char *out_mtot,const char *out_eps, const char *out_aver, const char *dipdist, const char *cosaver, const char *fndip3d, const char *fnadip, gmx_bool bPairs, const char *corrtype,const char *corf, gmx_bool bGkr, const char *gkrfn, gmx_bool bPhi, int *nlevels, int ndegrees, int ncos, const char *cmap, real rcmax, gmx_bool bQuad, const char *quadfn, gmx_bool bMU, const char *mufn, int *gnx, int *molindex[], real mu_max, real mu_aver, real epsilonRF,real temp, int *gkatom, int skip, gmx_bool bSlab, int nslices, const char *axtitle, const char *slabfn, const output_env_t oenv) { const char *leg_mtot[] = { "M\\sx \\N", "M\\sy \\N", "M\\sz \\N", "|M\\stot \\N|" }; #define NLEGMTOT asize(leg_mtot) const char *leg_eps[] = { "epsilon", "G\\sk", "g\\sk" }; #define NLEGEPS asize(leg_eps) const char *leg_aver[] = { "< |M|\\S2\\N >", "< |M| >\\S2\\N", "< |M|\\S2\\N > - < |M| >\\S2\\N", "< |M| >\\S2\\N / < |M|\\S2\\N >" }; #define NLEGAVER asize(leg_aver) const char *leg_cosaver[] = { "\\f{4}<|cos\\f{12}q\\f{4}\\sij\\N|>", "RMSD cos", "\\f{4}<|cos\\f{12}q\\f{4}\\siX\\N|>", "\\f{4}<|cos\\f{12}q\\f{4}\\siY\\N|>", "\\f{4}<|cos\\f{12}q\\f{4}\\siZ\\N|>" }; #define NLEGCOSAVER asize(leg_cosaver) const char *leg_adip[] = { "<mu>", "Std. Dev.", "Error" }; #define NLEGADIP asize(leg_adip) FILE *outdd,*outmtot,*outaver,*outeps,*caver=NULL; FILE *dip3d=NULL,*adip=NULL; rvec *x,*dipole=NULL,mu_t,quad,*dipsp=NULL; t_gkrbin *gkrbin = NULL; gmx_enxnm_t *enm=NULL; t_enxframe *fr; int nframes=1000,nre,timecheck=0,ncolour=0; ener_file_t fmu=NULL; int i,j,k,n,m,natom=0,nmol,gnx_tot,teller,tel3; t_trxstatus *status; int *dipole_bin,ndipbin,ibin,iVol,step,idim=-1; unsigned long mode; char buf[STRLEN]; real rcut=0,t,t0,t1,dt,lambda,dd,rms_cos; rvec dipaxis; matrix box; gmx_bool bCorr,bTotal,bCont; double M_diff=0,epsilon,invtel,vol_aver; double mu_ave,mu_mol,M2_ave=0,M_ave2=0,M_av[DIM],M_av2[DIM]; double M[3],M2[3],M4[3],Gk=0,g_k=0; gmx_stats_t Mx,My,Mz,Msq,Vol,*Qlsq,mulsq,muframelsq=NULL; ivec iMu; real **muall=NULL; rvec *slab_dipoles=NULL; t_atom *atom=NULL; t_block *mols=NULL; gmx_rmpbc_t gpbc=NULL; gnx_tot = gnx[0]; if (ncos > 1) { gnx_tot += gnx[1]; } vol_aver = 0.0; iVol=-1; if (bMU) { fmu = open_enx(mufn,"r"); do_enxnms(fmu,&nre,&enm); /* Determine the indexes of the energy grps we need */ for (i=0; (i<nre); i++) { if (strstr(enm[i].name,"Volume")) iVol=i; else if (strstr(enm[i].name,"Mu-X")) iMu[XX]=i; else if (strstr(enm[i].name,"Mu-Y")) iMu[YY]=i; else if (strstr(enm[i].name,"Mu-Z")) iMu[ZZ]=i; } } else { atom = top->atoms.atom; mols = &(top->mols); } if ((iVol == -1) && bMU) printf("Using Volume from topology: %g nm^3\n",volume); /* Correlation stuff */ bCorr = (corrtype[0] != 'n'); bTotal = (corrtype[0] == 't'); if (bCorr) { if (bTotal) { snew(muall,1); snew(muall[0],nframes*DIM); } else { snew(muall,gnx[0]); for(i=0; (i<gnx[0]); i++) snew(muall[i],nframes*DIM); } } /* Allocate array which contains for every molecule in a frame the * dipole moment. */ if (!bMU) snew(dipole,gnx_tot); /* Statistics */ snew(Qlsq,DIM); for(i=0; (i<DIM); i++) Qlsq[i] = gmx_stats_init(); mulsq = gmx_stats_init(); /* Open all the files */ outmtot = xvgropen(out_mtot, "Total dipole moment of the simulation box vs. time", "Time (ps)","Total Dipole Moment (Debye)",oenv); outeps = xvgropen(out_eps,"Epsilon and Kirkwood factors", "Time (ps)","",oenv); outaver = xvgropen(out_aver,"Total dipole moment", "Time (ps)","D",oenv); if (bSlab) { idim = axtitle[0] - 'X'; if ((idim < 0) || (idim >= DIM)) idim = axtitle[0] - 'x'; if ((idim < 0) || (idim >= DIM)) bSlab = FALSE; if (nslices < 2) bSlab = FALSE; fprintf(stderr,"axtitle = %s, nslices = %d, idim = %d\n", axtitle,nslices,idim); if (bSlab) { snew(slab_dipoles,nslices); fprintf(stderr,"Doing slab analysis\n"); } } if (fnadip) { adip = xvgropen(fnadip, "Average molecular dipole","Dipole (D)","",oenv); xvgr_legend(adip,NLEGADIP,leg_adip, oenv); } if (cosaver) { caver = xvgropen(cosaver,bPairs ? "Average pair orientation" : "Average absolute dipole orientation","Time (ps)","",oenv); xvgr_legend(caver,NLEGCOSAVER,bPairs ? leg_cosaver : &(leg_cosaver[1]), oenv); } if (fndip3d) { snew(dipsp,gnx_tot); /* we need a dummy file for gnuplot */ dip3d = (FILE *)ffopen("dummy.dat","w"); fprintf(dip3d,"%f %f %f", 0.0,0.0,0.0); ffclose(dip3d); dip3d = (FILE *)ffopen(fndip3d,"w"); fprintf(dip3d,"# This file was created by %s\n",Program()); fprintf(dip3d,"# which is part of G R O M A C S:\n"); fprintf(dip3d,"#\n"); } /* Write legends to all the files */ xvgr_legend(outmtot,NLEGMTOT,leg_mtot,oenv); xvgr_legend(outaver,NLEGAVER,leg_aver,oenv); if (bMU && (mu_aver == -1)) xvgr_legend(outeps,NLEGEPS-2,leg_eps,oenv); else xvgr_legend(outeps,NLEGEPS,leg_eps,oenv); snew(fr,1); clear_rvec(mu_t); teller = 0; /* Read the first frame from energy or traj file */ if (bMU) do { bCont = read_mu_from_enx(fmu,iVol,iMu,mu_t,&volume,&t,nre,fr); if (bCont) { timecheck=check_times(t); if (timecheck < 0) teller++; if ((teller % 10) == 0) fprintf(stderr,"\r Skipping Frame %6d, time: %8.3f", teller, t); } else { printf("End of %s reached\n",mufn); break; } } while (bCont && (timecheck < 0)); else natom = read_first_x(oenv,&status,fn,&t,&x,box); /* Calculate spacing for dipole bin (simple histogram) */ ndipbin = 1+(mu_max/0.01); snew(dipole_bin, ndipbin); epsilon = 0.0; mu_ave = 0.0; for(m=0; (m<DIM); m++) { M[m] = M2[m] = M4[m] = 0.0; } if (bGkr) { /* Use 0.7 iso 0.5 to account for pressure scaling */ /* rcut = 0.7*sqrt(max_cutoff2(box)); */ rcut = 0.7*sqrt(sqr(box[XX][XX])+sqr(box[YY][YY])+sqr(box[ZZ][ZZ])); gkrbin = mk_gkrbin(rcut,rcmax,bPhi,ndegrees); } gpbc = gmx_rmpbc_init(&top->idef,ePBC,natom,box); /* Start while loop over frames */ t1 = t0 = t; teller = 0; do { if (bCorr && (teller >= nframes)) { nframes += 1000; if (bTotal) { srenew(muall[0],nframes*DIM); } else { for(i=0; (i<gnx_tot); i++) srenew(muall[i],nframes*DIM); } } t1 = t; muframelsq = gmx_stats_init(); /* Initialise */ for(m=0; (m<DIM); m++) M_av2[m] = 0; if (bMU) { /* Copy rvec into double precision local variable */ for(m=0; (m<DIM); m++) M_av[m] = mu_t[m]; } else { /* Initialise */ for(m=0; (m<DIM); m++) M_av[m] = 0; gmx_rmpbc(gpbc,natom,box,x); /* Begin loop of all molecules in frame */ for(n=0; (n<ncos); n++) { for(i=0; (i<gnx[n]); i++) { int gi,ind0,ind1; ind0 = mols->index[molindex[n][i]]; ind1 = mols->index[molindex[n][i]+1]; mol_dip(ind0,ind1,x,atom,dipole[i]); gmx_stats_add_point(mulsq,0,norm(dipole[i]),0,0); gmx_stats_add_point(muframelsq,0,norm(dipole[i]),0,0); if (bSlab) update_slab_dipoles(ind0,ind1,x, dipole[i],idim,nslices,slab_dipoles,box); if (bQuad) { mol_quad(ind0,ind1,x,atom,quad); for(m=0; (m<DIM); m++) gmx_stats_add_point(Qlsq[m],0,quad[m],0,0); } if (bCorr && !bTotal) { tel3=DIM*teller; muall[i][tel3+XX] = dipole[i][XX]; muall[i][tel3+YY] = dipole[i][YY]; muall[i][tel3+ZZ] = dipole[i][ZZ]; } mu_mol = 0.0; for(m=0; (m<DIM); m++) { M_av[m] += dipole[i][m]; /* M per frame */ mu_mol += dipole[i][m]*dipole[i][m]; /* calc. mu for distribution */ } mu_mol = sqrt(mu_mol); mu_ave += mu_mol; /* calc. the average mu */ /* Update the dipole distribution */ ibin = (int)(ndipbin*mu_mol/mu_max + 0.5); if (ibin < ndipbin) dipole_bin[ibin]++; if (fndip3d) { rvec2sprvec(dipole[i],dipsp[i]); if (dipsp[i][YY] > -M_PI && dipsp[i][YY] < -0.5*M_PI) { if (dipsp[i][ZZ] < 0.5 * M_PI) { ncolour = 1; } else { ncolour = 2; } } else if (dipsp[i][YY] > -0.5*M_PI && dipsp[i][YY] < 0.0*M_PI) { if (dipsp[i][ZZ] < 0.5 * M_PI) { ncolour = 3; } else { ncolour = 4; } }else if (dipsp[i][YY] > 0.0 && dipsp[i][YY] < 0.5*M_PI) { if (dipsp[i][ZZ] < 0.5 * M_PI) { ncolour = 5; } else { ncolour = 6; } } else if (dipsp[i][YY] > 0.5*M_PI && dipsp[i][YY] < M_PI) { if (dipsp[i][ZZ] < 0.5 * M_PI) { ncolour = 7; } else { ncolour = 8; } } if (dip3d) fprintf(dip3d,"set arrow %d from %f, %f, %f to %f, %f, %f lt %d # %d %d\n", i+1, x[ind0][XX], x[ind0][YY], x[ind0][ZZ], x[ind0][XX]+dipole[i][XX]/25, x[ind0][YY]+dipole[i][YY]/25, x[ind0][ZZ]+dipole[i][ZZ]/25, ncolour, ind0, i); } } /* End loop of all molecules in frame */ if (dip3d) { fprintf(dip3d,"set title \"t = %4.3f\"\n",t); fprintf(dip3d,"set xrange [0.0:%4.2f]\n",box[XX][XX]); fprintf(dip3d,"set yrange [0.0:%4.2f]\n",box[YY][YY]); fprintf(dip3d,"set zrange [0.0:%4.2f]\n\n",box[ZZ][ZZ]); fprintf(dip3d,"splot 'dummy.dat' using 1:2:3 w vec\n"); fprintf(dip3d,"pause -1 'Hit return to continue'\n"); } } } /* Compute square of total dipole */ for(m=0; (m<DIM); m++) M_av2[m] = M_av[m]*M_av[m]; if (cosaver) { compute_avercos(gnx_tot,dipole,&dd,dipaxis,bPairs); rms_cos = sqrt(sqr(dipaxis[XX]-0.5)+ sqr(dipaxis[YY]-0.5)+ sqr(dipaxis[ZZ]-0.5)); if (bPairs) fprintf(caver,"%10.3e %10.3e %10.3e %10.3e %10.3e %10.3e\n", t,dd,rms_cos,dipaxis[XX],dipaxis[YY],dipaxis[ZZ]); else fprintf(caver,"%10.3e %10.3e %10.3e %10.3e %10.3e\n", t,rms_cos,dipaxis[XX],dipaxis[YY],dipaxis[ZZ]); } if (bGkr) { do_gkr(gkrbin,ncos,gnx,molindex,mols->index,x,dipole,ePBC,box, atom,gkatom); } if (bTotal) { tel3 = DIM*teller; muall[0][tel3+XX] = M_av[XX]; muall[0][tel3+YY] = M_av[YY]; muall[0][tel3+ZZ] = M_av[ZZ]; } /* Write to file the total dipole moment of the box, and its components * for this frame. */ if ((skip == 0) || ((teller % skip) == 0)) fprintf(outmtot,"%10g %12.8e %12.8e %12.8e %12.8e\n", t,M_av[XX],M_av[YY],M_av[ZZ], sqrt(M_av2[XX]+M_av2[YY]+M_av2[ZZ])); for(m=0; (m<DIM); m++) { M[m] += M_av[m]; M2[m] += M_av2[m]; M4[m] += sqr(M_av2[m]); } /* Increment loop counter */ teller++; /* Calculate for output the running averages */ invtel = 1.0/teller; M2_ave = (M2[XX]+M2[YY]+M2[ZZ])*invtel; M_ave2 = invtel*(invtel*(M[XX]*M[XX] + M[YY]*M[YY] + M[ZZ]*M[ZZ])); M_diff = M2_ave - M_ave2; /* Compute volume from box in traj, else we use the one from above */ if (!bMU) volume = det(box); vol_aver += volume; epsilon = calc_eps(M_diff,(vol_aver/teller),epsilonRF,temp); /* Calculate running average for dipole */ if (mu_ave != 0) mu_aver = (mu_ave/gnx_tot)*invtel; if ((skip == 0) || ((teller % skip) == 0)) { /* Write to file < |M|^2 >, |< M >|^2. And the difference between * the two. Here M is sum mu_i. Further write the finite system * Kirkwood G factor and epsilon. */ fprintf(outaver,"%10g %10.3e %10.3e %10.3e %10.3e\n", t,M2_ave,M_ave2,M_diff,M_ave2/M2_ave); if (fnadip) { real aver; gmx_stats_get_average(muframelsq,&aver); fprintf(adip, "%10g %f \n", t,aver); } /*if (dipole) printf("%f %f\n", norm(dipole[0]), norm(dipole[1])); */ if (!bMU || (mu_aver != -1)) { /* Finite system Kirkwood G-factor */ Gk = M_diff/(gnx_tot*mu_aver*mu_aver); /* Infinite system Kirkwood G-factor */ if (epsilonRF == 0.0) g_k = ((2*epsilon+1)*Gk/(3*epsilon)); else g_k = ((2*epsilonRF+epsilon)*(2*epsilon+1)* Gk/(3*epsilon*(2*epsilonRF+1))); fprintf(outeps,"%10g %10.3e %10.3e %10.3e\n",t,epsilon,Gk,g_k); } else fprintf(outeps,"%10g %12.8e\n",t,epsilon); } gmx_stats_done(muframelsq); if (bMU) bCont = read_mu_from_enx(fmu,iVol,iMu,mu_t,&volume,&t,nre,fr); else bCont = read_next_x(oenv,status,&t,natom,x,box); timecheck=check_times(t); } while (bCont && (timecheck == 0) ); gmx_rmpbc_done(gpbc); if (!bMU) close_trj(status); ffclose(outmtot); ffclose(outaver); ffclose(outeps); if (fnadip) ffclose(adip); if (cosaver) ffclose(caver); if (dip3d) { fprintf(dip3d,"set xrange [0.0:%4.2f]\n",box[XX][XX]); fprintf(dip3d,"set yrange [0.0:%4.2f]\n",box[YY][YY]); fprintf(dip3d,"set zrange [0.0:%4.2f]\n\n",box[ZZ][ZZ]); fprintf(dip3d,"splot 'dummy.dat' using 1:2:3 w vec\n"); fprintf(dip3d,"pause -1 'Hit return to continue'\n"); ffclose(dip3d); } if (bSlab) { dump_slab_dipoles(slabfn,idim,nslices,slab_dipoles,box,teller,oenv); sfree(slab_dipoles); } vol_aver /= teller; printf("Average volume over run is %g\n",vol_aver); if (bGkr) { print_gkrbin(gkrfn,gkrbin,gnx[0],teller,vol_aver,oenv); print_cmap(cmap,gkrbin,nlevels); } /* Autocorrelation function */ if (bCorr) { if (teller < 2) { printf("Not enough frames for autocorrelation\n"); } else { dt=(t1 - t0)/(teller-1); printf("t0 %g, t %g, teller %d\n", t0,t,teller); mode = eacVector; if (bTotal) do_autocorr(corf,oenv,"Autocorrelation Function of Total Dipole", teller,1,muall,dt,mode,TRUE); else do_autocorr(corf,oenv,"Dipole Autocorrelation Function", teller,gnx_tot,muall,dt, mode,strcmp(corrtype,"molsep")); } } if (!bMU) { real aver,sigma,error,lsq; gmx_stats_get_ase(mulsq,&aver,&sigma,&error); printf("\nDipole moment (Debye)\n"); printf("---------------------\n"); printf("Average = %8.4f Std. Dev. = %8.4f Error = %8.4f\n", aver,sigma,error); if (bQuad) { rvec a,s,e; int mm; for(m=0; (m<DIM); m++) gmx_stats_get_ase(mulsq,&(a[m]),&(s[m]),&(e[m])); printf("\nQuadrupole moment (Debye-Ang)\n"); printf("-----------------------------\n"); printf("Averages = %8.4f %8.4f %8.4f\n",a[XX],a[YY],a[ZZ]); printf("Std. Dev. = %8.4f %8.4f %8.4f\n",s[XX],s[YY],s[ZZ]); printf("Error = %8.4f %8.4f %8.4f\n",e[XX],e[YY],e[ZZ]); } printf("\n"); } printf("The following averages for the complete trajectory have been calculated:\n\n"); printf(" Total < M_x > = %g Debye\n", M[XX]/teller); printf(" Total < M_y > = %g Debye\n", M[YY]/teller); printf(" Total < M_z > = %g Debye\n\n", M[ZZ]/teller); printf(" Total < M_x^2 > = %g Debye^2\n", M2[XX]/teller); printf(" Total < M_y^2 > = %g Debye^2\n", M2[YY]/teller); printf(" Total < M_z^2 > = %g Debye^2\n\n", M2[ZZ]/teller); printf(" Total < |M|^2 > = %g Debye^2\n", M2_ave); printf(" Total |< M >|^2 = %g Debye^2\n\n", M_ave2); printf(" < |M|^2 > - |< M >|^2 = %g Debye^2\n\n", M_diff); if (!bMU || (mu_aver != -1)) { printf("Finite system Kirkwood g factor G_k = %g\n", Gk); printf("Infinite system Kirkwood g factor g_k = %g\n\n", g_k); } printf("Epsilon = %g\n", epsilon); if (!bMU) { /* Write to file the dipole moment distibution during the simulation. */ outdd=xvgropen(dipdist,"Dipole Moment Distribution","mu (Debye)","",oenv); for(i=0; (i<ndipbin); i++) fprintf(outdd,"%10g %10f\n", (i*mu_max)/ndipbin,dipole_bin[i]/(double)teller); ffclose(outdd); sfree(dipole_bin); } if (bGkr) done_gkrbin(&gkrbin); }
int read_first_frame(const output_env_t oenv,t_trxstatus **status, const char *fn,t_trxframe *fr,int flags) { t_fileio *fio; gmx_bool bFirst,bOK; int dummy=0; clear_trxframe(fr,TRUE); fr->flags = flags; bFirst = TRUE; snew((*status), 1); status_init( *status ); (*status)->nxframe=1; initcount(*status); fio = (*status)->fio =gmx_fio_open(fn,"r"); switch (gmx_fio_getftp(fio)) { case efTRJ: case efTRR: break; case efCPT: read_checkpoint_trxframe(fio,fr); bFirst = FALSE; break; case efG96: /* Can not rewind a compressed file, so open it twice */ read_g96_conf(gmx_fio_getfp(fio),fn,fr); gmx_fio_close(fio); clear_trxframe(fr,FALSE); if (flags & (TRX_READ_X | TRX_NEED_X)) snew(fr->x,fr->natoms); if (flags & (TRX_READ_V | TRX_NEED_V)) snew(fr->v,fr->natoms); fio = (*status)->fio =gmx_fio_open(fn,"r"); break; case efG87: fr->natoms=xyz_first_x(*status, gmx_fio_getfp(fio),oenv,&fr->time, &fr->x,fr->box); if (fr->natoms) { fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status,oenv,fr->time,FALSE); } bFirst = FALSE; break; case efXTC: if (read_first_xtc(fio,&fr->natoms,&fr->step,&fr->time,fr->box,&fr->x, &fr->prec,&bOK) == 0) { if (bOK) { gmx_fatal(FARGS,"No XTC!\n"); } else { fr->not_ok = DATA_NOT_OK; } } if (fr->not_ok) { fr->natoms = 0; printincomp(*status,fr); } else { fr->bPrec = (fr->prec > 0); fr->bStep = TRUE; fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status,oenv,fr->time,FALSE); } bFirst = FALSE; break; case efPDB: pdb_first_x(*status, gmx_fio_getfp(fio),fr); if (fr->natoms) printcount(*status,oenv,fr->time,FALSE); bFirst = FALSE; break; case efGRO: if (gro_first_x_or_v(gmx_fio_getfp(fio),fr)) printcount(*status,oenv,fr->time,FALSE); bFirst = FALSE; break; default: #ifdef GMX_DLOPEN gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/ if (!read_first_vmd_frame(&dummy,fn,fr,flags)) { gmx_fatal(FARGS,"Not supported in read_first_frame: %s",fn); } #else gmx_fatal(FARGS,"Not supported in read_first_frame: %s",fn); #endif break; } /* Return FALSE if we read a frame that's past the set ending time. */ if (!bFirst && (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) > 0)) { fr->t0 = fr->time; return FALSE; } if (bFirst || (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) < 0)) /* Read a frame when no frame was read or the first was skipped */ if (!read_next_frame(oenv,*status,fr)) return FALSE; fr->t0 = fr->time; return (fr->natoms > 0); }
int main(int argc, char **argv) { pthread_t *threads; long i; int ret; struct timespec intv; struct sched_param param; rt_init("a:r:t:e:l:h:", parse_args, argc, argv); signal(SIGINT, stop_log); if (argc >= (optind + 1)) nr_tasks = atoi(argv[optind]); else { numcpus = sysconf(_SC_NPROCESSORS_ONLN); nr_tasks = numcpus + 1; } intervals = malloc(sizeof(stats_container_t) * nr_tasks); if (!intervals) debug(DBG_ERR, "malloc failed\n"); memset(intervals, 0, sizeof(stats_container_t) * nr_tasks); intervals_length = malloc(sizeof(stats_container_t) * nr_tasks); if (!intervals_length) debug(DBG_ERR, "malloc failed\n"); memset(intervals_length, 0, sizeof(stats_container_t) * nr_tasks); if (!intervals_loops) debug(DBG_ERR, "malloc failed\n"); intervals_loops = malloc(sizeof(stats_container_t) * nr_tasks); memset(intervals_loops, 0, sizeof(stats_container_t) * nr_tasks); threads = malloc(sizeof(*threads) * nr_tasks); if (!threads) debug(DBG_ERR, "malloc failed\n"); memset(threads, 0, sizeof(*threads) * nr_tasks); ret = pthread_barrier_init(&start_barrier, NULL, nr_tasks + 1); ret = pthread_barrier_init(&end_barrier, NULL, nr_tasks + 1); if (ret < 0) debug(DBG_ERR, "pthread_barrier_init failed: %s\n", strerror(ret)); for (i = 0; i < nr_tasks; i++) { stats_container_init(&intervals[i], nr_runs); stats_container_init(&intervals_length[i], nr_runs); stats_container_init(&intervals_loops[i], nr_runs); } thread_pids = malloc(sizeof(long) * nr_tasks); if (!thread_pids) debug(DBG_ERR, "malloc thread_pids failed\n"); for (i = 0; i < nr_tasks; i++) { threads[i] = create_fifo_thread(start_task, (void *)i, prio_start + i); } /* * Progress bar uses stderr to let users see it when * redirecting output. So we convert stderr to use line * buffering so the progress bar doesn't flicker. */ setlinebuf(stderr); /* up our prio above all tasks */ memset(¶m, 0, sizeof(param)); param.sched_priority = nr_tasks + prio_start; if (sched_setscheduler(0, SCHED_FIFO, ¶m)) debug(DBG_WARN, "Warning, can't set priority of" "main thread !\n"); intv.tv_sec = INTERVAL / NS_PER_SEC; intv.tv_nsec = INTERVAL % (1 * NS_PER_SEC); print_progress_bar(0); setup_ftrace_marker(); for (loop = 0; loop < nr_runs; loop++) { unsigned long long end; now = rt_gettime() / NS_PER_US; ftrace_write("Loop %d now=%lld\n", loop, now); pthread_barrier_wait(&start_barrier); ftrace_write("All running!!!\n"); rt_nanosleep(intv.tv_nsec); print_progress_bar((loop * 100) / nr_runs); end = rt_gettime() / NS_PER_US; ftrace_write("Loop %d end now=%lld diff=%lld\n", loop, end, end - now); ret = pthread_barrier_wait(&end_barrier); if (stop || (check && check_times(loop))) { loop++; nr_runs = loop; break; } } putc('\n', stderr); pthread_barrier_wait(&start_barrier); done = 1; pthread_barrier_wait(&end_barrier); join_threads(); print_results(); if (stop) { /* * We use this test in bash while loops * So if we hit Ctrl-C then let the while * loop know to break. */ if (check < 0) exit(-1); else exit(1); } if (check < 0) exit(-1); else exit(0); return 0; }