2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
49 #include "gmx_fatal.h"
62 epAuf, epEuf, epAfu, epEfu, epNR
65 eqAif, eqEif, eqAfi, eqEfi, eqAui, eqEui, eqAiu, eqEiu, eqNR
67 static char *eep[epNR] = { "Af", "Ef", "Au", "Eu" };
68 static char *eeq[eqNR] = { "Aif", "Eif", "Afi", "Efi", "Aui", "Eui", "Aiu", "Eiu" };
71 int nreplica; /* Number of replicas in the calculation */
72 int nframe; /* Number of time frames */
73 int nstate; /* Number of states the system can be in, e.g. F,I,U */
74 int nparams; /* Is 2, 4 or 8 */
75 gmx_bool *bMask; /* Determine whether this replica is part of the d2 comp. */
77 gmx_bool bDiscrete; /* Use either discrete folding (0/1) or a continuous */
79 int nmask; /* Number of replicas taken into account */
80 real dt; /* Timestep between frames */
81 int j0, j1; /* Range of frames used in calculating delta */
82 real **temp, **data, **data2;
83 int **state; /* State index running from 0 (F) to nstate-1 (U) */
84 real **beta, **fcalt, **icalt;
85 real *time, *sumft, *sumit, *sumfct, *sumict;
91 #include <gsl/gsl_multimin.h>
93 static char *itoa(int i)
97 sprintf(ptr, "%d", i);
101 static char *epnm(int nparams, int index)
103 static char buf[32], from[8], to[8];
106 range_check(index, 0, nparams);
107 if ((nparams == 2) || (nparams == 4))
111 else if ((nparams > 4) && (nparams % 4 == 0))
117 gmx_fatal(FARGS, "Don't know how to handle %d parameters", nparams);
123 static gmx_bool bBack(t_remd_data *d)
125 return (d->nparams > 2);
128 static real is_folded(t_remd_data *d, int irep, int jframe)
130 if (d->state[irep][jframe] == 0)
140 static real is_unfolded(t_remd_data *d, int irep, int jframe)
142 if (d->state[irep][jframe] == d->nstate-1)
152 static real is_intermediate(t_remd_data *d, int irep, int jframe)
154 if ((d->state[irep][jframe] == 1) && (d->nstate > 2))
164 static void integrate_dfdt(t_remd_data *d)
167 double beta, ddf, ddi, df, db, fac, sumf, sumi, area;
171 for (i = 0; (i < d->nreplica); i++)
177 ddf = 0.5*d->dt*is_folded(d, i, 0);
178 ddi = 0.5*d->dt*is_intermediate(d, i, 0);
182 ddf = 0.5*d->dt*d->state[i][0];
185 d->fcalt[i][0] = ddf;
186 d->icalt[i][0] = ddi;
191 for (j = 1; (j < d->nframe); j++)
193 if (j == d->nframe-1)
202 for (i = 0; (i < d->nreplica); i++)
206 beta = d->beta[i][j];
207 if ((d->nstate <= 2) || d->bDiscrete)
211 df = (d->params[epAuf]*exp(-beta*d->params[epEuf])*
212 is_unfolded(d, i, j));
216 area = (d->data2 ? d->data2[i][j] : 1.0);
217 df = area*d->params[epAuf]*exp(-beta*d->params[epEuf]);
224 db = (d->params[epAfu]*exp(-beta*d->params[epEfu])*
229 gmx_fatal(FARGS, "Back reaction not implemented with continuous");
237 d->fcalt[i][j] = d->fcalt[i][j-1] + ddf;
242 ddf = fac*((d->params[eqAif]*exp(-beta*d->params[eqEif])*
243 is_intermediate(d, i, j)) -
244 (d->params[eqAfi]*exp(-beta*d->params[eqEfi])*
245 is_folded(d, i, j)));
246 ddi = fac*((d->params[eqAui]*exp(-beta*d->params[eqEui])*
247 is_unfolded(d, i, j)) -
248 (d->params[eqAiu]*exp(-beta*d->params[eqEiu])*
249 is_intermediate(d, i, j)));
250 d->fcalt[i][j] = d->fcalt[i][j-1] + ddf;
251 d->icalt[i][j] = d->icalt[i][j-1] + ddi;
257 d->sumfct[j] = d->sumfct[j-1] + sumf;
258 d->sumict[j] = d->sumict[j-1] + sumi;
262 fprintf(debug, "@type xy\n");
263 for (j = 0; (j < d->nframe); j++)
265 fprintf(debug, "%8.3f %12.5e\n", d->time[j], d->sumfct[j]);
267 fprintf(debug, "&\n");
271 static void sum_ft(t_remd_data *d)
276 for (j = 0; (j < d->nframe); j++)
280 if ((j == 0) || (j == d->nframe-1))
288 for (i = 0; (i < d->nreplica); i++)
294 d->sumft[j] += fac*is_folded(d, i, j);
295 d->sumit[j] += fac*is_intermediate(d, i, j);
299 d->sumft[j] += fac*d->state[i][j];
306 static double calc_d2(t_remd_data *d)
309 double dd2, d2 = 0, dr2, tmp;
315 for (j = d->j0; (j < d->j1); j++)
319 d2 += sqr(d->sumft[j]-d->sumfct[j]);
322 d2 += sqr(d->sumit[j]-d->sumict[j]);
327 d2 += sqr(d->sumft[j]-d->sumfct[j]);
333 for (i = 0; (i < d->nreplica); i++)
338 for (j = d->j0; (j < d->j1); j++)
340 tmp = sqr(is_folded(d, i, j)-d->fcalt[i][j]);
345 tmp = sqr(is_intermediate(d, i, j)-d->icalt[i][j]);
350 d->d2_replica[i] = dr2/(d->j1-d->j0);
354 dd2 = (d2/(d->j1-d->j0))/(d->bDiscrete ? d->nmask : 1);
359 static double my_f(const gsl_vector *v, void *params)
361 t_remd_data *d = (t_remd_data *) params;
365 for (i = 0; (i < d->nparams); i++)
367 d->params[i] = gsl_vector_get(v, i);
368 if (d->params[i] < 0)
383 static void optimize_remd_parameters(FILE *fp, t_remd_data *d, int maxiter,
391 const gsl_multimin_fminimizer_type *T;
392 gsl_multimin_fminimizer *s;
395 gsl_multimin_function my_func;
398 my_func.n = d->nparams;
399 my_func.params = (void *) d;
402 x = gsl_vector_alloc (my_func.n);
403 for (i = 0; (i < my_func.n); i++)
405 gsl_vector_set (x, i, d->params[i]);
408 /* Step size, different for each of the parameters */
409 dx = gsl_vector_alloc (my_func.n);
410 for (i = 0; (i < my_func.n); i++)
412 gsl_vector_set (dx, i, 0.1*d->params[i]);
415 T = gsl_multimin_fminimizer_nmsimplex;
416 s = gsl_multimin_fminimizer_alloc (T, my_func.n);
418 gsl_multimin_fminimizer_set (s, &my_func, x, dx);
420 gsl_vector_free (dx);
422 printf ("%5s", "Iter");
423 for (i = 0; (i < my_func.n); i++)
425 printf(" %12s", epnm(my_func.n, i));
427 printf (" %12s %12s\n", "NM Size", "Chi2");
432 status = gsl_multimin_fminimizer_iterate (s);
436 gmx_fatal(FARGS, "Something went wrong in the iteration in minimizer %s",
437 gsl_multimin_fminimizer_name(s));
440 d2 = gsl_multimin_fminimizer_minimum(s);
441 size = gsl_multimin_fminimizer_size(s);
442 status = gsl_multimin_test_size(size, tol);
444 if (status == GSL_SUCCESS)
446 printf ("Minimum found using %s at:\n",
447 gsl_multimin_fminimizer_name(s));
450 printf ("%5d", iter);
451 for (i = 0; (i < my_func.n); i++)
453 printf(" %12.4e", gsl_vector_get (s->x, i));
455 printf (" %12.4e %12.4e\n", size, d2);
457 while ((status == GSL_CONTINUE) && (iter < maxiter));
459 gsl_multimin_fminimizer_free (s);
462 static void preprocess_remd(FILE *fp, t_remd_data *d, real cutoff, real tref,
463 real ucut, gmx_bool bBack, real Euf, real Efu,
464 real Ei, real t0, real t1, gmx_bool bSum, gmx_bool bDiscrete,
468 real dd, tau_f, tau_u;
470 ninter = (ucut > cutoff) ? 1 : 0;
471 if (ninter && (ucut <= cutoff))
473 gmx_fatal(FARGS, "You have requested an intermediate but the cutoff for intermediates %f is smaller than the normal cutoff(%f)", ucut, cutoff);
483 d->nparams = 4*(1+ninter);
484 d->nstate = 2+ninter;
487 d->bDiscrete = bDiscrete;
488 snew(d->beta, d->nreplica);
489 snew(d->state, d->nreplica);
490 snew(d->bMask, d->nreplica);
491 snew(d->d2_replica, d->nreplica);
492 snew(d->sumft, d->nframe);
493 snew(d->sumit, d->nframe);
494 snew(d->sumfct, d->nframe);
495 snew(d->sumict, d->nframe);
496 snew(d->params, d->nparams);
497 snew(d->fcalt, d->nreplica);
498 snew(d->icalt, d->nreplica);
500 /* convert_times(d->nframe,d->time); */
508 for (d->j0 = 0; (d->j0 < d->nframe) && (d->time[d->j0] < t0); d->j0++)
519 for (d->j1 = 0; (d->j1 < d->nframe) && (d->time[d->j1] < t1); d->j1++)
524 if ((d->j1-d->j0) < d->nparams+2)
526 gmx_fatal(FARGS, "Start (%f) or end time (%f) for fitting inconsistent. Reduce t0, increase t1 or supply more data", t0, t1);
528 fprintf(fp, "Will optimize from %g to %g\n",
529 d->time[d->j0], d->time[d->j1-1]);
530 d->nmask = d->nreplica;
531 for (i = 0; (i < d->nreplica); i++)
533 snew(d->beta[i], d->nframe);
534 snew(d->state[i], d->nframe);
535 snew(d->fcalt[i], d->nframe);
536 snew(d->icalt[i], d->nframe);
538 for (j = 0; (j < d->nframe); j++)
540 d->beta[i][j] = 1.0/(BOLTZ*d->temp[i][j]);
548 else if ((ucut > cutoff) && (dd <= ucut))
554 d->state[i][j] = d->nstate-1;
559 d->state[i][j] = dd*nmult;
565 /* Assume forward rate constant is half the total time in this
566 * simulation and backward is ten times as long */
569 tau_f = d->time[d->nframe-1];
571 d->params[epEuf] = Euf;
572 d->params[epAuf] = exp(d->params[epEuf]/(BOLTZ*tref))/tau_f;
575 d->params[epEfu] = Efu;
576 d->params[epAfu] = exp(d->params[epEfu]/(BOLTZ*tref))/tau_u;
579 d->params[eqEui] = Ei;
580 d->params[eqAui] = exp(d->params[eqEui]/(BOLTZ*tref))/tau_u;
581 d->params[eqEiu] = Ei;
582 d->params[eqAiu] = exp(d->params[eqEiu]/(BOLTZ*tref))/tau_u;
587 d->params[epAfu] = 0;
588 d->params[epEfu] = 0;
593 d->params[epEuf] = Euf;
596 d->params[epAuf] = 0.1;
600 d->params[epAuf] = 20.0;
605 static real tau(real A, real E, real T)
607 return exp(E/(BOLTZ*T))/A;
610 static real folded_fraction(t_remd_data *d, real tref)
614 tauf = tau(d->params[epAuf], d->params[epEuf], tref);
615 taub = tau(d->params[epAfu], d->params[epEfu], tref);
617 return (taub/(tauf+taub));
620 static void print_tau(FILE *gp, t_remd_data *d, real tref)
622 real tauf, taub, ddd, fff, DG, DH, TDS, Tm, Tb, Te, Fb, Fe, Fm;
623 int i, np = d->nparams;
626 fprintf(gp, "Final value for Chi2 = %12.5e (%d replicas)\n", ddd, d->nmask);
627 tauf = tau(d->params[epAuf], d->params[epEuf], tref);
628 fprintf(gp, "%s = %12.5e %s = %12.5e (kJ/mole)\n",
629 epnm(np, epAuf), d->params[epAuf],
630 epnm(np, epEuf), d->params[epEuf]);
633 taub = tau(d->params[epAfu], d->params[epEfu], tref);
634 fprintf(gp, "%s = %12.5e %s = %12.5e (kJ/mole)\n",
635 epnm(np, epAfu), d->params[epAfu],
636 epnm(np, epEfu), d->params[epEfu]);
637 fprintf(gp, "Equilibrium properties at T = %g\n", tref);
638 fprintf(gp, "tau_f = %8.3f ns, tau_b = %8.3f ns\n", tauf/1000, taub/1000);
639 fff = taub/(tauf+taub);
640 DG = BOLTZ*tref*log(fff/(1-fff));
641 DH = d->params[epEfu]-d->params[epEuf];
643 fprintf(gp, "Folded fraction F = %8.3f\n", fff);
644 fprintf(gp, "Unfolding energies: DG = %8.3f DH = %8.3f TDS = %8.3f\n",
650 Fb = folded_fraction(d, Tb);
651 Fe = folded_fraction(d, Te);
652 while ((Te-Tb > 0.001) && (Fm != 0.5))
655 Fm = folded_fraction(d, Tm);
667 if ((Fb-0.5)*(Fe-0.5) <= 0)
669 fprintf(gp, "Melting temperature Tm = %8.3f K\n", Tm);
673 fprintf(gp, "No melting temperature detected between 260 and 420K\n");
678 fprintf(gp, "Data for intermediates at T = %g\n", tref);
679 fprintf(gp, "%8s %10s %10s %10s\n", "Name", "A", "E", "tau");
680 for (i = 0; (i < np/2); i++)
682 tauf = tau(d->params[2*i], d->params[2*i+1], tref);
683 ptr = epnm(d->nparams, 2*i);
684 fprintf(gp, "%8s %10.3e %10.3e %10.3e\n", ptr+1,
685 d->params[2*i], d->params[2*i+1], tauf/1000);
691 fprintf(gp, "Equilibrium properties at T = %g\n", tref);
692 fprintf(gp, "tau_f = %8.3f\n", tauf);
696 static void dump_remd_parameters(FILE *gp, t_remd_data *d, const char *fn,
697 const char *fn2, const char *rfn,
698 const char *efn, const char *mfn, int skip, real tref,
702 int i, j, np = d->nparams;
703 real rhs, tauf, taub, fff, DG;
705 const char *leg[] = { "Measured", "Fit", "Difference" };
706 const char *mleg[] = { "Folded fraction", "DG (kJ/mole)"};
708 real fac[] = { 0.97, 0.98, 0.99, 1.0, 1.01, 1.02, 1.03 };
709 #define NFAC asize(fac)
714 print_tau(gp, d, tref);
715 norm = (d->bDiscrete ? 1.0/d->nmask : 1.0);
719 fp = xvgropen(fn, "Optimized fit to data", "Time (ps)", "Fraction Folded", oenv);
720 xvgr_legend(fp, asize(leg), leg, oenv);
721 for (i = 0; (i < d->nframe); i++)
723 if ((skip <= 0) || ((i % skip) == 0))
725 fprintf(fp, "%12.5e %12.5e %12.5e %12.5e\n", d->time[i],
726 d->sumft[i]*norm, d->sumfct[i]*norm,
727 (d->sumft[i]-d->sumfct[i])*norm);
734 snew(rleg, d->nreplica*2);
735 for (i = 0; (i < d->nreplica); i++)
738 snew(rleg[2*i+1], 32);
739 sprintf(rleg[2*i], "\\f{4}F(t) %d", i);
740 sprintf(rleg[2*i+1], "\\f{12}F \\f{4}(t) %d", i);
742 fp = xvgropen(rfn, "Optimized fit to data", "Time (ps)", "Fraction Folded", oenv);
743 xvgr_legend(fp, d->nreplica*2, (const char**)rleg, oenv);
744 for (j = 0; (j < d->nframe); j++)
746 if ((skip <= 0) || ((j % skip) == 0))
748 fprintf(fp, "%12.5e", d->time[j]);
749 for (i = 0; (i < d->nreplica); i++)
751 fprintf(fp, " %5f %9.2e", is_folded(d, i, j), d->fcalt[i][j]);
759 if (fn2 && (d->nstate > 2))
761 fp = xvgropen(fn2, "Optimized fit to data", "Time (ps)",
762 "Fraction Intermediate", oenv);
763 xvgr_legend(fp, asize(leg), leg, oenv);
764 for (i = 0; (i < d->nframe); i++)
766 if ((skip <= 0) || ((i % skip) == 0))
768 fprintf(fp, "%12.5e %12.5e %12.5e %12.5e\n", d->time[i],
769 d->sumit[i]*norm, d->sumict[i]*norm,
770 (d->sumit[i]-d->sumict[i])*norm);
779 fp = xvgropen(mfn, "Melting curve", "T (K)", "", oenv);
780 xvgr_legend(fp, asize(mleg), mleg, oenv);
781 for (i = 260; (i <= 420); i++)
783 tauf = tau(d->params[epAuf], d->params[epEuf], 1.0*i);
784 taub = tau(d->params[epAfu], d->params[epEfu], 1.0*i);
785 fff = taub/(tauf+taub);
786 DG = BOLTZ*i*log(fff/(1-fff));
787 fprintf(fp, "%5d %8.3f %8.3f\n", i, fff, DG);
795 snew(params, d->nparams);
796 for (i = 0; (i < d->nparams); i++)
798 params[i] = d->params[i];
801 hp = xvgropen(efn, "Chi2 as a function of relative parameter",
802 "Fraction", "Chi2", oenv);
803 for (j = 0; (j < d->nparams); j++)
805 /* Reset all parameters to optimized values */
806 if(output_env_get_print_xvgr_codes(oenv))
808 fprintf(hp, "@type xy\n");
810 for (i = 0; (i < d->nparams); i++)
812 d->params[i] = params[i];
814 /* Now modify one of them */
815 for (i = 0; (i < NFAC); i++)
817 d->params[j] = fac[i]*params[j];
819 fprintf(gp, "%s = %12g d2 = %12g\n", epnm(np, j), d->params[j], d2[i]);
820 fprintf(hp, "%12g %12g\n", fac[i], d2[i]);
822 fprintf(hp, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
825 for (i = 0; (i < d->nparams); i++)
827 d->params[i] = params[i];
833 for (i = 0; (i < d->nreplica); i++)
835 fprintf(gp, "Chi2[%3d] = %8.2e\n", i, d->d2_replica[i]);
839 #endif /*HAVE_LIBGSL*/
841 int gmx_kinetics(int argc, char *argv[])
843 const char *desc[] = {
844 "[TT]g_kinetics[tt] reads two [TT].xvg[tt] files, each one containing data for N replicas.",
845 "The first file contains the temperature of each replica at each timestep,",
846 "and the second contains real values that can be interpreted as",
847 "an indicator for folding. If the value in the file is larger than",
848 "the cutoff it is taken to be unfolded and the other way around.[PAR]",
849 "From these data an estimate of the forward and backward rate constants",
850 "for folding is made at a reference temperature. In addition,",
851 "a theoretical melting curve and free energy as a function of temperature",
852 "are printed in an [TT].xvg[tt] file.[PAR]",
853 "The user can give a max value to be regarded as intermediate",
854 "([TT]-ucut[tt]), which, when given will trigger the use of an intermediate state",
855 "in the algorithm to be defined as those structures that have",
856 "cutoff < DATA < ucut. Structures with DATA values larger than ucut will",
857 "not be regarded as potential folders. In this case 8 parameters are optimized.[PAR]",
858 "The average fraction foled is printed in an [TT].xvg[tt] file together with the fit to it.",
859 "If an intermediate is used a further file will show the build of the intermediate and the fit to that process.[PAR]",
860 "The program can also be used with continuous variables (by setting",
861 "[TT]-nodiscrete[tt]). In this case kinetics of other processes can be",
862 "studied. This is very much a work in progress and hence the manual",
863 "(this information) is lagging behind somewhat.[PAR]",
864 "In order to compile this program you need access to the GNU",
865 "scientific library."
867 static int nreplica = 1;
868 static real tref = 298.15;
869 static real cutoff = 0.2;
870 static real ucut = 0.0;
871 static real Euf = 10;
872 static real Efu = 30;
874 static gmx_bool bHaveT = TRUE;
879 static real tol = 1e-3;
880 static int maxiter = 100;
882 static int nmult = 1;
883 static gmx_bool bBack = TRUE;
884 static gmx_bool bSplit = TRUE;
885 static gmx_bool bSum = TRUE;
886 static gmx_bool bDiscrete = TRUE;
888 { "-time", FALSE, etBOOL, {&bHaveT},
889 "Expect a time in the input" },
890 { "-b", FALSE, etREAL, {&tb},
891 "First time to read from set" },
892 { "-e", FALSE, etREAL, {&te},
893 "Last time to read from set" },
894 { "-bfit", FALSE, etREAL, {&t0},
895 "Time to start the fit from" },
896 { "-efit", FALSE, etREAL, {&t1},
897 "Time to end the fit" },
898 { "-T", FALSE, etREAL, {&tref},
899 "Reference temperature for computing rate constants" },
900 { "-n", FALSE, etINT, {&nreplica},
901 "Read data for this number of replicas. Only necessary when files are written in xmgrace format using @type and & as delimiters." },
902 { "-cut", FALSE, etREAL, {&cutoff},
903 "Cut-off (max) value for regarding a structure as folded" },
904 { "-ucut", FALSE, etREAL, {&ucut},
905 "Cut-off (max) value for regarding a structure as intermediate (if not folded)" },
906 { "-euf", FALSE, etREAL, {&Euf},
907 "Initial guess for energy of activation for folding (kJ/mol)" },
908 { "-efu", FALSE, etREAL, {&Efu},
909 "Initial guess for energy of activation for unfolding (kJ/mol)" },
910 { "-ei", FALSE, etREAL, {&Ei},
911 "Initial guess for energy of activation for intermediates (kJ/mol)" },
912 { "-maxiter", FALSE, etINT, {&maxiter},
913 "Max number of iterations" },
914 { "-back", FALSE, etBOOL, {&bBack},
915 "Take the back reaction into account" },
916 { "-tol", FALSE, etREAL, {&tol},
917 "Absolute tolerance for convergence of the Nelder and Mead simplex algorithm" },
918 { "-skip", FALSE, etINT, {&skip},
919 "Skip points in the output [TT].xvg[tt] file" },
920 { "-split", FALSE, etBOOL, {&bSplit},
921 "Estimate error by splitting the number of replicas in two and refitting" },
922 { "-sum", FALSE, etBOOL, {&bSum},
923 "Average folding before computing [GRK]chi[grk]^2" },
924 { "-discrete", FALSE, etBOOL, {&bDiscrete},
925 "Use a discrete folding criterion (F <-> U) or a continuous one" },
926 { "-mult", FALSE, etINT, {&nmult},
927 "Factor to multiply the data with before discretization" }
929 #define NPA asize(pa)
932 real dt_t, dt_d, dt_d2;
933 int nset_t, nset_d, nset_d2, n_t, n_d, n_d2, i;
934 const char *tfile, *dfile, *dfile2;
939 { efXVG, "-f", "temp", ffREAD },
940 { efXVG, "-d", "data", ffREAD },
941 { efXVG, "-d2", "data2", ffOPTRD },
942 { efXVG, "-o", "ft_all", ffWRITE },
943 { efXVG, "-o2", "it_all", ffOPTWR },
944 { efXVG, "-o3", "ft_repl", ffOPTWR },
945 { efXVG, "-ee", "err_est", ffOPTWR },
946 { efLOG, "-g", "remd", ffWRITE },
947 { efXVG, "-m", "melt", ffWRITE }
949 #define NFILE asize(fnm)
951 CopyRight(stderr, argv[0]);
952 parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_BE_NICE | PCA_TIME_UNIT,
953 NFILE, fnm, NPA, pa, asize(desc), desc, 0, NULL, &oenv);
956 please_cite(stdout, "Spoel2006d");
959 gmx_fatal(FARGS, "cutoff should be >= 0 (rather than %f)", cutoff);
962 tfile = opt2fn("-f", NFILE, fnm);
963 dfile = opt2fn("-d", NFILE, fnm);
964 dfile2 = opt2fn_null("-d2", NFILE, fnm);
966 fp = ffopen(opt2fn("-g", NFILE, fnm), "w");
968 remd.temp = read_xvg_time(tfile, bHaveT,
969 opt2parg_bSet("-b", NPA, pa), tb,
970 opt2parg_bSet("-e", NPA, pa), te,
971 nreplica, &nset_t, &n_t, &dt_t, &remd.time);
972 printf("Read %d sets of %d points in %s, dt = %g\n\n", nset_t, n_t, tfile, dt_t);
975 remd.data = read_xvg_time(dfile, bHaveT,
976 opt2parg_bSet("-b", NPA, pa), tb,
977 opt2parg_bSet("-e", NPA, pa), te,
978 nreplica, &nset_d, &n_d, &dt_d, &remd.time);
979 printf("Read %d sets of %d points in %s, dt = %g\n\n", nset_d, n_d, dfile, dt_d);
981 if ((nset_t != nset_d) || (n_t != n_d) || (dt_t != dt_d))
983 gmx_fatal(FARGS, "Files %s and %s are inconsistent. Check log file",
989 remd.data2 = read_xvg_time(dfile2, bHaveT,
990 opt2parg_bSet("-b", NPA, pa), tb,
991 opt2parg_bSet("-e", NPA, pa), te,
992 nreplica, &nset_d2, &n_d2, &dt_d2, &remd.time);
993 printf("Read %d sets of %d points in %s, dt = %g\n\n",
994 nset_d2, n_d2, dfile2, dt_d2);
995 if ((nset_d2 != nset_d) || (n_d != n_d2) || (dt_d != dt_d2))
997 gmx_fatal(FARGS, "Files %s and %s are inconsistent. Check log file",
1006 remd.nreplica = nset_d;
1009 preprocess_remd(fp, &remd, cutoff, tref, ucut, bBack, Euf, Efu, Ei, t0, t1,
1010 bSum, bDiscrete, nmult);
1012 optimize_remd_parameters(fp, &remd, maxiter, tol);
1014 dump_remd_parameters(fp, &remd, opt2fn("-o", NFILE, fnm),
1015 opt2fn_null("-o2", NFILE, fnm),
1016 opt2fn_null("-o3", NFILE, fnm),
1017 opt2fn_null("-ee", NFILE, fnm),
1018 opt2fn("-m", NFILE, fnm), skip, tref, oenv);
1022 printf("Splitting set of replicas in two halves\n");
1023 for (i = 0; (i < remd.nreplica); i++)
1025 remd.bMask[i] = FALSE;
1028 for (i = 0; (i < remd.nreplica); i += 2)
1030 remd.bMask[i] = TRUE;
1034 optimize_remd_parameters(fp, &remd, maxiter, tol);
1035 dump_remd_parameters(fp, &remd, "test1.xvg", NULL, NULL, NULL, NULL, skip, tref, oenv);
1037 for (i = 0; (i < remd.nreplica); i++)
1039 remd.bMask[i] = !remd.bMask[i];
1041 remd.nmask = remd.nreplica - remd.nmask;
1044 optimize_remd_parameters(fp, &remd, maxiter, tol);
1045 dump_remd_parameters(fp, &remd, "test2.xvg", NULL, NULL, NULL, NULL, skip, tref, oenv);
1047 for (i = 0; (i < remd.nreplica); i++)
1049 remd.bMask[i] = FALSE;
1052 for (i = 0; (i < remd.nreplica/2); i++)
1054 remd.bMask[i] = TRUE;
1058 optimize_remd_parameters(fp, &remd, maxiter, tol);
1059 dump_remd_parameters(fp, &remd, "test1.xvg", NULL, NULL, NULL, NULL, skip, tref, oenv);
1061 for (i = 0; (i < remd.nreplica); i++)
1063 remd.bMask[i] = FALSE;
1066 for (i = remd.nreplica/2; (i < remd.nreplica); i++)
1068 remd.bMask[i] = TRUE;
1072 optimize_remd_parameters(fp, &remd, maxiter, tol);
1073 dump_remd_parameters(fp, &remd, "test1.xvg", NULL, NULL, NULL, NULL, skip, tref, oenv);
1077 view_all(oenv, NFILE, fnm);
1081 fprintf(stderr, "This program should be compiled with the GNU scientific library. Please install the library and reinstall GROMACS.\n");
1082 #endif /*HAVE_LIBGSL*/