static void writeraw(t_interf ***int1, t_interf ***int2, int tblocks, int xbins, int ybins, char **fnms) { FILE *raw1, *raw2; int i, j, n; raw1 = gmx_ffopen(fnms[0], "w"); raw2 = gmx_ffopen(fnms[1], "w"); try { gmx::BinaryInformationSettings settings; settings.generatedByHeader(true); settings.linePrefix("# "); gmx::printBinaryInformation(raw1, gmx::getProgramContext(), settings); gmx::printBinaryInformation(raw2, gmx::getProgramContext(), settings); } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; fprintf(raw1, "# Legend: nt nx ny\n# Xbin Ybin Z t\n"); fprintf(raw2, "# Legend: nt nx ny\n# Xbin Ybin Z t\n"); fprintf(raw1, "%i %i %i\n", tblocks, xbins, ybins); fprintf(raw2, "%i %i %i\n", tblocks, xbins, ybins); for (n = 0; n < tblocks; n++) { for (i = 0; i < xbins; i++) { for (j = 0; j < ybins; j++) { fprintf(raw1, "%i %i %8.5f %6.4f\n", i, j, (int1[n][j+ybins*i])->Z, (int1[n][j+ybins*i])->t); fprintf(raw2, "%i %i %8.5f %6.4f\n", i, j, (int2[n][j+ybins*i])->Z, (int2[n][j+ybins*i])->t); } } } gmx_ffclose(raw1); gmx_ffclose(raw2); }
static int gmx_fio_close_locked(t_fileio *fio) { int rc = 0; if (!fio->bOpen) { gmx_fatal(FARGS, "File %s closed twice!\n", fio->fn); } if (in_ftpset(fio->iFTP, asize(ftpXDR), ftpXDR)) { xdr_destroy(fio->xdr); sfree(fio->xdr); } /* Don't close stdin and stdout! */ if (!fio->bStdio && fio->fp != NULL) { rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */ } fio->bOpen = FALSE; return rc; }
static void pukeit(const char *db, const char *defstring, char *retstring, int retsize, int *cqnum) { FILE *fp; char **help; int i, nhlp; gmx_rng_t rng; if (be_cool() && ((fp = low_libopen(db, FALSE)) != NULL)) { nhlp = fget_lines(fp, &help); /* for libraries we can use the low-level close routines */ gmx_ffclose(fp); rng = gmx_rng_init(gmx_rng_make_seed()); *cqnum = static_cast<int>(nhlp*gmx_rng_uniform_real(rng)); gmx_rng_destroy(rng); if (strlen(help[*cqnum]) >= STRLEN) { help[*cqnum][STRLEN-1] = '\0'; } strncpy(retstring, help[*cqnum], retsize); for (i = 0; (i < nhlp); i++) { sfree(help[i]); } sfree(help); } else { *cqnum = -1; strncpy(retstring, defstring, retsize); } }
void dump_histo(t_histo *h,char *fn,char *title,char *xaxis,char *yaxis, int enorm,real norm_fac) { FILE *fp; int i,nn; for(nn=h->np; (nn > 0); nn--) if (h->nh[nn] != 0) break; for(i=0; (i<nn); i++) if (h->nh[i] > 0) break; fp = xvgropen(fn,title,xaxis,yaxis); for( ; (i<nn); i++) { switch (enorm) { case enormNO: fprintf(fp,"%12f %12f %d\n",h->minx+h->dx*i,h->y[i],h->nh[i]); break; case enormFAC: fprintf(fp,"%12f %12f %d\n",h->minx+h->dx*i,h->y[i]*norm_fac,h->nh[i]); break; case enormNP: if (h->nh[i] > 0) fprintf(fp,"%12f %12f %d\n", h->minx+h->dx*i,h->y[i]*norm_fac/h->nh[i],h->nh[i]); break; default: gmx_fatal(FARGS,"Wrong value for enorm (%d)",enorm); } } gmx_ffclose(fp); }
static void outputfield(const char *fldfn, real ****Densmap, int xslices, int yslices, int zslices, int tdim) { /*Debug-filename and filehandle*/ FILE *fldH; int n, i, j, k; int dim[4]; real totdens = 0; dim[0] = tdim; dim[1] = xslices; dim[2] = yslices; dim[3] = zslices; fldH = gmx_ffopen(fldfn, "w"); fwrite(dim, sizeof(int), 4, fldH); for (n = 0; n < tdim; n++) { for (i = 0; i < xslices; i++) { for (j = 0; j < yslices; j++) { for (k = 0; k < zslices; k++) { fwrite(&(Densmap[n][i][j][k]), sizeof(real), 1, fldH); totdens += (Densmap[n][i][j][k]); } } } } totdens /= (xslices*yslices*zslices*tdim); fprintf(stderr, "Total density [kg/m^3] %8f", totdens); gmx_ffclose(fldH); }
void low_rmsd_dist(const char *fn, real maxrms, int nn, real **mat, const output_env_t oenv) { FILE *fp; int i, j, *histo, x; real fac; fac = 100/maxrms; snew(histo, 101); for (i = 0; i < nn; i++) { for (j = i+1; j < nn; j++) { x = (int)(fac*mat[i][j]+0.5); if (x <= 100) { histo[x]++; } } } fp = xvgropen(fn, "RMS Distribution", "RMS (nm)", "a.u.", oenv); for (i = 0; (i < 101); i++) { fprintf(fp, "%10g %10d\n", i/fac, histo[i]); } gmx_ffclose(fp); sfree(histo); }
static void read_prop(gmx_atomprop_t aps, int eprop, double factor) { gmx_atomprop *ap2 = (gmx_atomprop*) aps; FILE *fp; char line[STRLEN], resnm[32], atomnm[32]; double pp; int line_no; aprop_t *ap; ap = &ap2->prop[eprop]; fp = libopen(ap->db); line_no = 0; while (get_a_line(fp, line, STRLEN)) { line_no++; if (sscanf(line, "%31s %31s %20lf", resnm, atomnm, &pp) == 3) { pp *= factor; add_prop(ap, aps->restype, resnm, atomnm, pp, line_no); } else { fprintf(stderr, "WARNING: Error in file %s at line %d ignored\n", ap->db, line_no); } } /* for libraries we can use the low-level close routines */ gmx_ffclose(fp); ap->bSet = TRUE; }
void write_sas_mat(const char *fn, real **accr, int nframe, int nres, t_matrix *mat) { real lo, hi; int i, j, nlev; t_rgb rlo = {1, 1, 1}, rhi = {0, 0, 0}; FILE *fp; if (fn) { hi = lo = accr[0][0]; for (i = 0; i < nframe; i++) { for (j = 0; j < nres; j++) { lo = min(lo, accr[i][j]); hi = max(hi, accr[i][j]); } } fp = gmx_ffopen(fn, "w"); nlev = hi-lo+1; write_xpm(fp, 0, "Solvent Accessible Surface", "Surface (A^2)", "Time", "Residue Index", nframe, nres, mat->axis_x, mat->axis_y, accr, lo, hi, rlo, rhi, &nlev); gmx_ffclose(fp); } }
static t_pdbfile *read_pdbf(const char *fn) { t_pdbfile *pdbf; double e; FILE *fp; snew(pdbf, 1); t_topology top; read_tps_conf(fn, &top, &pdbf->ePBC, &pdbf->x, NULL, pdbf->box, FALSE); pdbf->atoms = top.atoms; fp = gmx_ffopen(fn, "r"); char buf[256], *ptr; while ((ptr = fgets2(buf, 255, fp)) != NULL) { if (std::strstr(buf, "Intermolecular") != NULL) { ptr = std::strchr(buf, '='); sscanf(ptr+1, "%lf", &e); pdbf->edocked = e; } else if (std::strstr(buf, "Estimated Free") != NULL) { ptr = std::strchr(buf, '='); sscanf(ptr+1, "%lf", &e); pdbf->efree = e; } } gmx_ffclose(fp); return pdbf; }
void histogram(const char *distfile, real binwidth, int n, int nset, real **val, const output_env_t oenv) { FILE *fp; int i, s; double min, max; int nbin; gmx_int64_t *histo; min = val[0][0]; max = val[0][0]; for (s = 0; s < nset; s++) { for (i = 0; i < n; i++) { if (val[s][i] < min) { min = val[s][i]; } else if (val[s][i] > max) { max = val[s][i]; } } } min = binwidth*floor(min/binwidth); max = binwidth*ceil(max/binwidth); if (min != 0) { min -= binwidth; } max += binwidth; nbin = (int)((max - min)/binwidth + 0.5) + 1; fprintf(stderr, "Making distributions with %d bins\n", nbin); snew(histo, nbin); fp = xvgropen(distfile, "Distribution", "", "", oenv); for (s = 0; s < nset; s++) { for (i = 0; i < nbin; i++) { histo[i] = 0; } for (i = 0; i < n; i++) { histo[(int)((val[s][i] - min)/binwidth + 0.5)]++; } for (i = 0; i < nbin; i++) { fprintf(fp, " %g %g\n", min+i*binwidth, (double)histo[i]/(n*binwidth)); } if (s < nset-1) { fprintf(fp, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : ""); } } gmx_ffclose(fp); }
int gmx_anadock(int argc, char *argv[]) { const char *desc[] = { "[THISMODULE] analyses the results of an Autodock run and clusters the", "structures together, based on distance or RMSD. The docked energy", "and free energy estimates are analysed, and for each cluster the", "energy statistics are printed.[PAR]", "An alternative approach to this is to cluster the structures first", "using [gmx-cluster] and then sort the clusters on either lowest", "energy or average energy." }; t_filenm fnm[] = { { efPDB, "-f", NULL, ffREAD }, { efXVG, "-od", "edocked", ffWRITE }, { efXVG, "-of", "efree", ffWRITE }, { efLOG, "-g", "anadock", ffWRITE } }; output_env_t oenv; #define NFILE asize(fnm) static gmx_bool bFree = FALSE, bRMS = TRUE; static real cutoff = 0.2; t_pargs pa[] = { { "-free", FALSE, etBOOL, {&bFree}, "Use Free energy estimate from autodock for sorting the classes" }, { "-rms", FALSE, etBOOL, {&bRMS}, "Cluster on RMS or distance" }, { "-cutoff", FALSE, etREAL, {&cutoff}, "Maximum RMSD/distance for belonging to the same cluster" } }; #define NPA asize(pa) FILE *fp; t_pdbfile **pdbf = NULL; int npdbf; if (!parse_common_args(&argc, argv, 0, NFILE, fnm, NPA, pa, asize(desc), desc, 0, NULL, &oenv)) { return 0; } fp = gmx_ffopen(opt2fn("-g", NFILE, fnm), "w"); please_cite(stdout, "Hetenyi2002b"); please_cite(fp, "Hetenyi2002b"); pdbf = read_em_all(opt2fn("-f", NFILE, fnm), &npdbf); analyse_em_all(npdbf, pdbf, opt2fn("-od", NFILE, fnm), opt2fn("-of", NFILE, fnm), oenv); cluster_em_all(fp, npdbf, pdbf, bFree, bRMS, cutoff); gmx_thanx(fp); gmx_ffclose(fp); return 0; }
static t_pq_inel *read_pq(char *fn) { FILE *fp; t_pq_inel *pq; int i,j,k; double e,p,o,t; fprintf(stdout,"Going to read %s\n",fn); fp = gmx_ffopen(fn,"r"); /* Allocate memory and set constants */ snew(pq,1); if (fscanf(fp,"%d%d%d",&pq->nener,&pq->nomega,&pq->nq) != 3) gmx_fatal(FARGS,"I need three integers: nener, nomega, nq in file %s",fn); snew(pq->ener,pq->nener); snew(pq->omega,pq->nener); snew(pq->prob,pq->nener); snew(pq->q,pq->nener); /* Triple loop to read data */ for(i=0; (i<pq->nener); i++) { fprintf(stderr,"\rEnergy %d/%d",i+1,pq->nener); snew(pq->prob[i],pq->nomega); snew(pq->q[i],pq->nomega); snew(pq->omega[i],pq->nomega); for(j=0; (j<pq->nomega); j++) { snew(pq->prob[i][j],pq->nq); snew(pq->q[i][j],pq->nq); for(k=0; (k<pq->nq); k++) { fscanf(fp,"%lf%lf%lf%lf",&e,&o,&p,&t); /* Consistency check */ if ((j == 0) && (k == 0)) pq->ener[i] = e; else if (fabs(pq->ener[i]-e) > 1e-6*e) gmx_fatal(FARGS,"Inconsistent energy %f i=%d j=%d k=%d",e,i,j,k); if (k == 0) pq->omega[i][j] = o; else if (fabs(pq->omega[i][j]-o) > 1e-6*o) gmx_fatal(FARGS,"Inconsistent omega %f i=%d j=%d k=%d",o,i,j,k); pq->prob[i][j][k] = p; pq->q[i][j][k] = t; } } } fprintf(stderr,"\n"); gmx_ffclose(fp); return pq; }
static void ehisto(const char *fh, int n, real **enerT, const output_env_t oenv) { FILE *fp; int i, j, k, nbin, blength; int *bindex; real *T, bmin, bmax, bwidth; int **histo; bmin = 1e8; bmax = -1e8; snew(bindex, n); snew(T, n); nbin = 0; for (j = 1; (j < n); j++) { for (k = 0; (k < nbin); k++) { if (T[k] == enerT[1][j]) { bindex[j] = k; break; } } if (k == nbin) { bindex[j] = nbin; T[nbin] = enerT[1][j]; nbin++; } bmin = min(enerT[0][j], bmin); bmax = max(enerT[0][j], bmax); } bwidth = 1.0; blength = (bmax - bmin)/bwidth + 2; snew(histo, nbin); for (i = 0; (i < nbin); i++) { snew(histo[i], blength); } for (j = 0; (j < n); j++) { k = (enerT[0][j]-bmin)/bwidth; histo[bindex[j]][k]++; } fp = xvgropen(fh, "Energy distribution", "E (kJ/mol)", "", oenv); for (j = 0; (j < blength); j++) { fprintf(fp, "%8.3f", bmin+j*bwidth); for (k = 0; (k < nbin); k++) { fprintf(fp, " %6d", histo[k][j]); } fprintf(fp, "\n"); } gmx_ffclose(fp); }
void plot_potential(double *potential[], double *charge[], double *field[], const char *afile, const char *bfile, const char *cfile, int nslices, int nr_grps, const char *grpname[], double slWidth, const output_env_t oenv) { FILE *pot, /* xvgr file with potential */ *cha, /* xvgr file with charges */ *fie; /* xvgr files with fields */ char buf[256]; /* for xvgr title */ int slice, n; sprintf(buf, "Electrostatic Potential"); pot = xvgropen(afile, buf, "Box (nm)", "Potential (V)", oenv); xvgr_legend(pot, nr_grps, grpname, oenv); sprintf(buf, "Charge Distribution"); cha = xvgropen(bfile, buf, "Box (nm)", "Charge density (q/nm\\S3\\N)", oenv); xvgr_legend(cha, nr_grps, grpname, oenv); sprintf(buf, "Electric Field"); fie = xvgropen(cfile, buf, "Box (nm)", "Field (V/nm)", oenv); xvgr_legend(fie, nr_grps, grpname, oenv); for (slice = cb; slice < (nslices - ce); slice++) { fprintf(pot, "%20.16g ", slice * slWidth); fprintf(cha, "%20.16g ", slice * slWidth); fprintf(fie, "%20.16g ", slice * slWidth); for (n = 0; n < nr_grps; n++) { fprintf(pot, " %20.16g", potential[n][slice]); fprintf(fie, " %20.16g", field[n][slice]/1e9); /* convert to V/nm */ fprintf(cha, " %20.16g", charge[n][slice]); } fprintf(pot, "\n"); fprintf(cha, "\n"); fprintf(fie, "\n"); } gmx_ffclose(pot); gmx_ffclose(cha); gmx_ffclose(fie); }
static int read_equiv(const char *eq_fn, t_equiv ***equivptr) { FILE *fp; char line[STRLEN], resname[10], atomname[10], *lp; int neq, na, n, resnr; t_equiv **equiv; fp = gmx_ffopen(eq_fn, "r"); neq = 0; equiv = NULL; while (get_a_line(fp, line, STRLEN)) { lp = line; /* this is not efficient, but I'm lazy */ srenew(equiv, neq+1); equiv[neq] = NULL; na = 0; if (sscanf(lp, "%s %n", atomname, &n) == 1) { lp += n; snew(equiv[neq], 1); equiv[neq][0].nname = gmx_strdup(atomname); while (sscanf(lp, "%d %s %s %n", &resnr, resname, atomname, &n) == 3) { /* this is not efficient, but I'm lazy (again) */ srenew(equiv[neq], na+1); equiv[neq][na].set = true; equiv[neq][na].rnr = resnr-1; equiv[neq][na].rname = gmx_strdup(resname); equiv[neq][na].aname = gmx_strdup(atomname); if (na > 0) { equiv[neq][na].nname = NULL; } na++; lp += n; } } /* make empty element as flag for end of array */ srenew(equiv[neq], na+1); equiv[neq][na].set = false; equiv[neq][na].rnr = 0; equiv[neq][na].rname = NULL; equiv[neq][na].aname = NULL; /* next */ neq++; } gmx_ffclose(fp); *equivptr = equiv; return neq; }
/*! \brief Debugging */ static void dump_tmp(char *s, int n, real c[]) { FILE *fp; int i; fp = gmx_ffopen(s, "w"); for (i = 0; (i < n); i++) { fprintf(fp, "%10d %10g\n", i, c[i]); } gmx_ffclose(fp); }
gpp_atomtype_t read_atype(const char *ffdir, t_symtab *tab) { int nfile, f; char **file; FILE *in; char buf[STRLEN], name[STRLEN]; double m; int nratt = 0; gpp_atomtype_t at; t_atom *a; t_param *nb; nfile = fflib_search_file_end(ffdir, ".atp", TRUE, &file); at = init_atomtype(); snew(a, 1); snew(nb, 1); for (f = 0; f < nfile; f++) { in = fflib_open(file[f]); while (!feof(in)) { /* Skip blank or comment-only lines */ do { if (fgets2(buf, STRLEN, in) != NULL) { strip_comment(buf); trim(buf); } } while (!feof(in) && strlen(buf) == 0); if (sscanf(buf, "%s%lf", name, &m) == 2) { a->m = m; add_atomtype(at, tab, a, name, nb, 0, 0.0, 0.0, 0.0, 0, 0.0, 0.0 ); fprintf(stderr, "\rAtomtype %d", ++nratt); fflush(stderr); } else { fprintf(stderr, "\nInvalid format: %s\n", buf); } } gmx_ffclose(in); sfree(file[f]); } fprintf(stderr, "\n"); sfree(file); return at; }
/* close only fp but keep FIO entry. */ int gmx_fio_fp_close(t_fileio *fio) { int rc = 0; gmx_fio_lock(fio); if (!in_ftpset(fio->iFTP, asize(ftpXDR), ftpXDR) && !fio->bStdio) { rc = gmx_ffclose(fio->fp); /* fclose returns 0 if happy */ fio->fp = NULL; } gmx_fio_unlock(fio); return rc; }
void dump_ana_struct(char *rmax,char *nion,char *gyr_com,char *gyr_origin, t_ana_struct *anal,int nsim) { FILE *fp,*gp,*hp,*kp; int i,j; real t,d2; char *legend[] = { "Rg", "RgX", "RgY", "RgZ" }; fp = xvgropen(rmax,"rmax","Time (fs)","r (nm)"); gp = xvgropen(nion,"N ion","Time (fs)","N ions"); hp = xvgropen(gyr_com,"Radius of gyration wrt. C.O.M.", "Time (fs)","Rg (nm)"); xvgr_legend(hp,asize(legend),legend); kp = xvgropen(gyr_origin,"Radius of gyration wrt. Origin", "Time (fs)","Rg (nm)"); xvgr_legend(kp,asize(legend),legend); for(i=0; (i<anal->index); i++) { t = 1000*anal->t[i]; fprintf(fp,"%12g %10.3f\n",t,anal->maxdist[i]); fprintf(gp,"%12g %10.3f\n",t,(1.0*anal->nion[i])/nsim-1); d2 = anal->d2_com[i][XX] + anal->d2_com[i][YY] + anal->d2_com[i][ZZ]; fprintf(hp,"%12g %10.3f %10.3f %10.3f %10.3f\n", t,sqrt(d2/nsim), sqrt(anal->d2_com[i][XX]/nsim), sqrt(anal->d2_com[i][YY]/nsim), sqrt(anal->d2_com[i][ZZ]/nsim)); d2 = anal->d2_origin[i][XX] + anal->d2_origin[i][YY] + anal->d2_origin[i][ZZ]; fprintf(kp,"%12g %10.3f %10.3f %10.3f %10.3f\n", t,sqrt(d2/nsim), sqrt(anal->d2_origin[i][XX]/nsim), sqrt(anal->d2_origin[i][YY]/nsim), sqrt(anal->d2_origin[i][ZZ]/nsim)); } gmx_ffclose(hp); gmx_ffclose(gp); gmx_ffclose(fp); gmx_ffclose(kp); }
static t_p2Ddata *read_p2Ddata(char *fn) { FILE *fp; t_p2Ddata *p2Ddata; int i,j; double e,p,o; fprintf(stdout,"Going to read %s\n",fn); fp = gmx_ffopen(fn,"r"); /* Allocate memory and set constants */ snew(p2Ddata,1); if (fscanf(fp,"%d%d",&p2Ddata->nener,&p2Ddata->n2Ddata) != 2) gmx_fatal(FARGS,"I need two integers: nener, n in file %s",fn); snew(p2Ddata->ener,p2Ddata->nener); snew(p2Ddata->prob,p2Ddata->nener); snew(p2Ddata->data,p2Ddata->nener); /* Double loop to read data */ for(i=0; (i<p2Ddata->nener); i++) { fprintf(stderr,"\rEnergy %d/%d",i+1,p2Ddata->nener); snew(p2Ddata->prob[i],p2Ddata->n2Ddata); snew(p2Ddata->data[i],p2Ddata->n2Ddata); for(j=0; (j<p2Ddata->n2Ddata); j++) { fscanf(fp,"%lf%lf%lf",&e,&p,&o); /* Consistency check */ if (j==0) p2Ddata->ener[i] = e; else if (fabs(p2Ddata->ener[i]-e) > 1e-6*e) gmx_fatal(FARGS,"Inconsistent energy %f i=%d j=%d",e,i,j); p2Ddata->prob[i][j] = p; p2Ddata->data[i][j] = o; } /* There is some noise on the data, take it away by sorting, * because otherwise binary search does not work. * This is equivalent to shifting in the data slightly along the X-axis * but better than linear search with the "real" data. */ qsort(p2Ddata->data[i],p2Ddata->n2Ddata,sizeof(p2Ddata->data[0][0]), realcomp); } fprintf(stderr,"\n"); gmx_ffclose(fp); return p2Ddata; }
int get_electrons(t_electron **eltab, const char *fn) { char buffer[256]; /* to read in a line */ char tempname[80]; /* buffer to hold name */ int tempnr; FILE *in; int nr; /* number of atomstypes to read */ int i; if (!(in = gmx_ffopen(fn, "r"))) { gmx_fatal(FARGS, "Couldn't open %s. Exiting.\n", fn); } if (NULL == fgets(buffer, 255, in)) { gmx_fatal(FARGS, "Error reading from file %s", fn); } if (sscanf(buffer, "%d", &nr) != 1) { gmx_fatal(FARGS, "Invalid number of atomtypes in datafile\n"); } snew(*eltab, nr); for (i = 0; i < nr; i++) { if (fgets(buffer, 255, in) == NULL) { gmx_fatal(FARGS, "reading datafile. Check your datafile.\n"); } if (sscanf(buffer, "%s = %d", tempname, &tempnr) != 2) { gmx_fatal(FARGS, "Invalid line in datafile at line %d\n", i+1); } (*eltab)[i].nr_el = tempnr; (*eltab)[i].atomname = gmx_strdup(tempname); } gmx_ffclose(in); /* sort the list */ fprintf(stderr, "Sorting list..\n"); qsort ((void*)*eltab, nr, sizeof(t_electron), (int(*)(const void*, const void*))compare); return nr; }
extern void save_data (structure_factor_t *sft, const char *file, int ngrps, real start_q, real end_q, const output_env_t oenv) { FILE *fp; int i, g = 0; double *tmp, polarization_factor, A; structure_factor *sf = (structure_factor *)sft; fp = xvgropen (file, "Scattering Intensity", "q (1/nm)", "Intensity (a.u.)", oenv); snew (tmp, ngrps); for (g = 0; g < ngrps; g++) { for (i = 0; i < sf->n_angles; i++) { /* * theta is half the angle between incoming and scattered vectors. * * polar. fact. = 0.5*(1+cos^2(2*theta)) = 1 - 0.5 * sin^2(2*theta) * * sin(theta) = q/(2k) := A -> sin^2(theta) = 4*A^2 (1-A^2) -> * -> 0.5*(1+cos^2(2*theta)) = 1 - 2 A^2 (1-A^2) */ A = (double) (i * sf->ref_k) / (2.0 * sf->momentum); polarization_factor = 1 - 2.0 * sqr (A) * (1 - sqr (A)); sf->F[g][i] *= polarization_factor; } } for (i = 0; i < sf->n_angles; i++) { if (i * sf->ref_k >= start_q && i * sf->ref_k <= end_q) { fprintf (fp, "%10.5f ", i * sf->ref_k); for (g = 0; g < ngrps; g++) { fprintf (fp, " %10.5f ", (sf->F[g][i]) /( sf->total_n_atoms* sf->nSteps)); } fprintf (fp, "\n"); } } gmx_ffclose (fp); }
void print_one(const output_env_t oenv, const char *base, const char *name, const char *title, const char *ylabel, int nf, real time[], real data[]) { FILE *fp; char buf[256], t2[256]; int k; sprintf(buf, "%s%s.xvg", base, name); fprintf(stderr, "\rPrinting %s ", buf); sprintf(t2, "%s %s", title, name); fp = xvgropen(buf, t2, "Time (ps)", ylabel, oenv); for (k = 0; (k < nf); k++) { fprintf(fp, "%10g %10g\n", time[k], data[k]); } gmx_ffclose(fp); }
static void analyse_em_all(int npdb, t_pdbfile *pdbf[], const char *edocked, const char *efree, const output_env_t oenv) { FILE *fp; int i; for (bFreeSort = FALSE; (bFreeSort <= TRUE); bFreeSort++) { qsort(pdbf, npdb, sizeof(pdbf[0]), pdbf_comp); fp = xvgropen(bFreeSort ? efree : edocked, etitles[bFreeSort], "()", "E (kJ/mol)", oenv); for (i = 0; (i < npdb); i++) { fprintf(fp, "%12lf\n", bFreeSort ? pdbf[i]->efree : pdbf[i]->edocked); } gmx_ffclose(fp); } }
static void print_fitted_function(const char *fitfile, const char *fn_fitted, gmx_bool bXYdy, int nset, int n, real *t, real **val, int npargs, t_pargs *ppa, gmx_output_env_t *oenv) { FILE *out_fit = gmx_ffopen(fitfile, "w"); if (bXYdy && nset >= 2) { do_fit(out_fit, 0, TRUE, n, t, val, npargs, ppa, oenv, fn_fitted); } else { char *buf2 = NULL; int s, buflen = 0; if (NULL != fn_fitted) { buflen = std::strlen(fn_fitted)+32; snew(buf2, buflen); std::strncpy(buf2, fn_fitted, buflen); buf2[std::strlen(buf2)-4] = '\0'; } for (s = 0; s < nset; s++) { char *buf = NULL; if (NULL != fn_fitted) { snew(buf, buflen); snprintf(buf, n, "%s_%d.xvg", buf2, s); } do_fit(out_fit, s, FALSE, n, t, val, npargs, ppa, oenv, buf); sfree(buf); } sfree(buf2); } gmx_ffclose(out_fit); }
static t_2morse *read_dissociation_energies(int *n2morse) { FILE *fp; char ai[32], aj[32]; double e_diss; const char *fn = "edissoc.dat"; t_2morse *t2m = NULL; int maxn2m = 0, n2m = 0; int nread; /* Open the file with dissociation energies */ fp = libopen(fn); do { /* Try and read two atom names and an energy term from it */ nread = fscanf(fp, "%s%s%lf", ai, aj, &e_diss); if (nread == 3) { /* If we got three terms, it probably was OK, no further checking */ if (n2m >= maxn2m) { /* Increase memory for 16 at once, some mallocs are stupid */ maxn2m += 16; srenew(t2m, maxn2m); } /* Copy the values */ t2m[n2m].ai = gmx_strdup(ai); t2m[n2m].aj = gmx_strdup(aj); t2m[n2m].e_diss = e_diss; /* Increment counter */ n2m++; } /* If we did not read three items, quit reading */ } while (nread == 3); gmx_ffclose(fp); /* Set the return values */ *n2morse = n2m; return t2m; }
void cat(FILE *out,char *fn,real t) { FILE *in; char *ptr,buf[256]; int anr,rnr; char anm[24],rnm[24]; double f1,f2,f3,f4,f5,f6; in=gmx_ffopen(fn,"r"); while ((ptr=fgets2(buf,255,in)) != NULL) { sscanf(buf,"%d%d%s%s%lf%lf%lf%lf%lf%lf", &anr,&rnr,rnm,anm,&f1,&f2,&f3,&f4,&f5,&f6); fprintf(out,"%8g %10g %10g %10g %10g %10g %10g %s%d-%s%d\n", t,f6,f1,f2,f3,f4,f5,rnm,rnr,anm,anr); } /*if ((int)strlen(buf) > 0) fprintf(out,"%s\n",buf);*/ fflush(out); gmx_ffclose(in); }
void correlate_aniso(const char *fn, t_atoms *ref, t_atoms *calc, const output_env_t oenv) { FILE *fp; int i, j; fp = xvgropen(fn, "Correlation between X-Ray and Computed Uij", "X-Ray", "Computed", oenv); for (i = 0; (i < ref->nr); i++) { if (ref->pdbinfo[i].bAnisotropic) { for (j = U11; (j <= U23); j++) { fprintf(fp, "%10d %10d\n", ref->pdbinfo[i].uij[j], calc->pdbinfo[i].uij[j]); } } } gmx_ffclose(fp); }
void dump_ana_ener(t_ana_ener *ae,int nsim,real dt,char *edump, t_ana_struct *total) { FILE *fp; int i,j; real fac; fac = 1.0/(nsim*ELECTRONVOLT); fp=xvgropen(edump,"Energies","Time (fs)","E (eV)"); xvgr_legend(fp,eNR,enms); fprintf(fp,"@ s%d legend \"Ek/Nelec\"\n",eNR); fprintf(fp,"@ type nxy\n"); for(i=0; (i<ae->nx); i++) { fprintf(fp,"%10f",1000.0*dt*i); for(j=0; (j<eNR); j++) fprintf(fp," %8.3f",ae->e[i][j]*fac); fprintf(fp," %8.3f\n",ae->e[i][eELECTRON]/(ELECTRONVOLT*total->nion[i])); } fprintf(fp,"&\n"); gmx_ffclose(fp); }
static void plot_coscont(const char *ccfile, int n, int nset, real **val, const output_env_t oenv) { FILE *fp; int s; real cc; fp = xvgropen(ccfile, "Cosine content", "set / half periods", "cosine content", oenv); for (s = 0; s < nset; s++) { cc = cosine_content(s+1, n, val[s]); fprintf(fp, " %d %g\n", s+1, cc); fprintf(stdout, "Cosine content of set %d with %.1f periods: %g\n", s+1, 0.5*(s+1), cc); } fprintf(stdout, "\n"); gmx_ffclose(fp); }