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 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
43 #include "gromacs/commandline/pargs.h"
48 #include "gmx_fatal.h"
51 #include "gromacs/fileio/futil.h"
60 epAuf, epEuf, epAfu, epEfu, epNR
63 eqAif, eqEif, eqAfi, eqEfi, eqAui, eqEui, eqAiu, eqEiu, eqNR
65 static char *eep[epNR] = { "Af", "Ef", "Au", "Eu" };
66 static char *eeq[eqNR] = { "Aif", "Eif", "Afi", "Efi", "Aui", "Eui", "Aiu", "Eiu" };
69 int nreplica; /* Number of replicas in the calculation */
70 int nframe; /* Number of time frames */
71 int nstate; /* Number of states the system can be in, e.g. F,I,U */
72 int nparams; /* Is 2, 4 or 8 */
73 gmx_bool *bMask; /* Determine whether this replica is part of the d2 comp. */
75 gmx_bool bDiscrete; /* Use either discrete folding (0/1) or a continuous */
77 int nmask; /* Number of replicas taken into account */
78 real dt; /* Timestep between frames */
79 int j0, j1; /* Range of frames used in calculating delta */
80 real **temp, **data, **data2;
81 int **state; /* State index running from 0 (F) to nstate-1 (U) */
82 real **beta, **fcalt, **icalt;
83 real *time, *sumft, *sumit, *sumfct, *sumict;
89 #include <gsl/gsl_multimin.h>
91 static char *itoa(int i)
95 sprintf(ptr, "%d", i);
99 static char *epnm(int nparams, int index)
101 static char buf[32], from[8], to[8];
104 range_check(index, 0, nparams);
105 if ((nparams == 2) || (nparams == 4))
109 else if ((nparams > 4) && (nparams % 4 == 0))
115 gmx_fatal(FARGS, "Don't know how to handle %d parameters", nparams);
121 static gmx_bool bBack(t_remd_data *d)
123 return (d->nparams > 2);
126 static real is_folded(t_remd_data *d, int irep, int jframe)
128 if (d->state[irep][jframe] == 0)
138 static real is_unfolded(t_remd_data *d, int irep, int jframe)
140 if (d->state[irep][jframe] == d->nstate-1)
150 static real is_intermediate(t_remd_data *d, int irep, int jframe)
152 if ((d->state[irep][jframe] == 1) && (d->nstate > 2))
162 static void integrate_dfdt(t_remd_data *d)
165 double beta, ddf, ddi, df, db, fac, sumf, sumi, area;
169 for (i = 0; (i < d->nreplica); i++)
175 ddf = 0.5*d->dt*is_folded(d, i, 0);
176 ddi = 0.5*d->dt*is_intermediate(d, i, 0);
180 ddf = 0.5*d->dt*d->state[i][0];
183 d->fcalt[i][0] = ddf;
184 d->icalt[i][0] = ddi;
189 for (j = 1; (j < d->nframe); j++)
191 if (j == d->nframe-1)
200 for (i = 0; (i < d->nreplica); i++)
204 beta = d->beta[i][j];
205 if ((d->nstate <= 2) || d->bDiscrete)
209 df = (d->params[epAuf]*exp(-beta*d->params[epEuf])*
210 is_unfolded(d, i, j));
214 area = (d->data2 ? d->data2[i][j] : 1.0);
215 df = area*d->params[epAuf]*exp(-beta*d->params[epEuf]);
222 db = (d->params[epAfu]*exp(-beta*d->params[epEfu])*
227 gmx_fatal(FARGS, "Back reaction not implemented with continuous");
235 d->fcalt[i][j] = d->fcalt[i][j-1] + ddf;
240 ddf = fac*((d->params[eqAif]*exp(-beta*d->params[eqEif])*
241 is_intermediate(d, i, j)) -
242 (d->params[eqAfi]*exp(-beta*d->params[eqEfi])*
243 is_folded(d, i, j)));
244 ddi = fac*((d->params[eqAui]*exp(-beta*d->params[eqEui])*
245 is_unfolded(d, i, j)) -
246 (d->params[eqAiu]*exp(-beta*d->params[eqEiu])*
247 is_intermediate(d, i, j)));
248 d->fcalt[i][j] = d->fcalt[i][j-1] + ddf;
249 d->icalt[i][j] = d->icalt[i][j-1] + ddi;
255 d->sumfct[j] = d->sumfct[j-1] + sumf;
256 d->sumict[j] = d->sumict[j-1] + sumi;
260 fprintf(debug, "@type xy\n");
261 for (j = 0; (j < d->nframe); j++)
263 fprintf(debug, "%8.3f %12.5e\n", d->time[j], d->sumfct[j]);
265 fprintf(debug, "&\n");
269 static void sum_ft(t_remd_data *d)
274 for (j = 0; (j < d->nframe); j++)
278 if ((j == 0) || (j == d->nframe-1))
286 for (i = 0; (i < d->nreplica); i++)
292 d->sumft[j] += fac*is_folded(d, i, j);
293 d->sumit[j] += fac*is_intermediate(d, i, j);
297 d->sumft[j] += fac*d->state[i][j];
304 static double calc_d2(t_remd_data *d)
307 double dd2, d2 = 0, dr2, tmp;
313 for (j = d->j0; (j < d->j1); j++)
317 d2 += sqr(d->sumft[j]-d->sumfct[j]);
320 d2 += sqr(d->sumit[j]-d->sumict[j]);
325 d2 += sqr(d->sumft[j]-d->sumfct[j]);
331 for (i = 0; (i < d->nreplica); i++)
336 for (j = d->j0; (j < d->j1); j++)
338 tmp = sqr(is_folded(d, i, j)-d->fcalt[i][j]);
343 tmp = sqr(is_intermediate(d, i, j)-d->icalt[i][j]);
348 d->d2_replica[i] = dr2/(d->j1-d->j0);
352 dd2 = (d2/(d->j1-d->j0))/(d->bDiscrete ? d->nmask : 1);
357 static double my_f(const gsl_vector *v, void *params)
359 t_remd_data *d = (t_remd_data *) params;
363 for (i = 0; (i < d->nparams); i++)
365 d->params[i] = gsl_vector_get(v, i);
366 if (d->params[i] < 0)
381 static void optimize_remd_parameters(t_remd_data *d, int maxiter,
389 const gsl_multimin_fminimizer_type *T;
390 gsl_multimin_fminimizer *s;
393 gsl_multimin_function my_func;
396 my_func.n = d->nparams;
397 my_func.params = (void *) d;
400 x = gsl_vector_alloc (my_func.n);
401 for (i = 0; (i < my_func.n); i++)
403 gsl_vector_set (x, i, d->params[i]);
406 /* Step size, different for each of the parameters */
407 dx = gsl_vector_alloc (my_func.n);
408 for (i = 0; (i < my_func.n); i++)
410 gsl_vector_set (dx, i, 0.1*d->params[i]);
413 T = gsl_multimin_fminimizer_nmsimplex;
414 s = gsl_multimin_fminimizer_alloc (T, my_func.n);
416 gsl_multimin_fminimizer_set (s, &my_func, x, dx);
418 gsl_vector_free (dx);
420 printf ("%5s", "Iter");
421 for (i = 0; (i < my_func.n); i++)
423 printf(" %12s", epnm(my_func.n, i));
425 printf (" %12s %12s\n", "NM Size", "Chi2");
430 status = gsl_multimin_fminimizer_iterate (s);
434 gmx_fatal(FARGS, "Something went wrong in the iteration in minimizer %s",
435 gsl_multimin_fminimizer_name(s));
438 d2 = gsl_multimin_fminimizer_minimum(s);
439 size = gsl_multimin_fminimizer_size(s);
440 status = gsl_multimin_test_size(size, tol);
442 if (status == GSL_SUCCESS)
444 printf ("Minimum found using %s at:\n",
445 gsl_multimin_fminimizer_name(s));
448 printf ("%5d", iter);
449 for (i = 0; (i < my_func.n); i++)
451 printf(" %12.4e", gsl_vector_get (s->x, i));
453 printf (" %12.4e %12.4e\n", size, d2);
455 while ((status == GSL_CONTINUE) && (iter < maxiter));
457 gsl_multimin_fminimizer_free (s);
460 static void preprocess_remd(FILE *fp, t_remd_data *d, real cutoff, real tref,
461 real ucut, gmx_bool bBack, real Euf, real Efu,
462 real Ei, real t0, real t1, gmx_bool bSum, gmx_bool bDiscrete,
466 real dd, tau_f, tau_u;
468 ninter = (ucut > cutoff) ? 1 : 0;
469 if (ninter && (ucut <= cutoff))
471 gmx_fatal(FARGS, "You have requested an intermediate but the cutoff for intermediates %f is smaller than the normal cutoff(%f)", ucut, cutoff);
481 d->nparams = 4*(1+ninter);
482 d->nstate = 2+ninter;
485 d->bDiscrete = bDiscrete;
486 snew(d->beta, d->nreplica);
487 snew(d->state, d->nreplica);
488 snew(d->bMask, d->nreplica);
489 snew(d->d2_replica, d->nreplica);
490 snew(d->sumft, d->nframe);
491 snew(d->sumit, d->nframe);
492 snew(d->sumfct, d->nframe);
493 snew(d->sumict, d->nframe);
494 snew(d->params, d->nparams);
495 snew(d->fcalt, d->nreplica);
496 snew(d->icalt, d->nreplica);
498 /* convert_times(d->nframe,d->time); */
506 for (d->j0 = 0; (d->j0 < d->nframe) && (d->time[d->j0] < t0); d->j0++)
517 for (d->j1 = 0; (d->j1 < d->nframe) && (d->time[d->j1] < t1); d->j1++)
522 if ((d->j1-d->j0) < d->nparams+2)
524 gmx_fatal(FARGS, "Start (%f) or end time (%f) for fitting inconsistent. Reduce t0, increase t1 or supply more data", t0, t1);
526 fprintf(fp, "Will optimize from %g to %g\n",
527 d->time[d->j0], d->time[d->j1-1]);
528 d->nmask = d->nreplica;
529 for (i = 0; (i < d->nreplica); i++)
531 snew(d->beta[i], d->nframe);
532 snew(d->state[i], d->nframe);
533 snew(d->fcalt[i], d->nframe);
534 snew(d->icalt[i], d->nframe);
536 for (j = 0; (j < d->nframe); j++)
538 d->beta[i][j] = 1.0/(BOLTZ*d->temp[i][j]);
546 else if ((ucut > cutoff) && (dd <= ucut))
552 d->state[i][j] = d->nstate-1;
557 d->state[i][j] = dd*nmult;
563 /* Assume forward rate constant is half the total time in this
564 * simulation and backward is ten times as long */
567 tau_f = d->time[d->nframe-1];
569 d->params[epEuf] = Euf;
570 d->params[epAuf] = exp(d->params[epEuf]/(BOLTZ*tref))/tau_f;
573 d->params[epEfu] = Efu;
574 d->params[epAfu] = exp(d->params[epEfu]/(BOLTZ*tref))/tau_u;
577 d->params[eqEui] = Ei;
578 d->params[eqAui] = exp(d->params[eqEui]/(BOLTZ*tref))/tau_u;
579 d->params[eqEiu] = Ei;
580 d->params[eqAiu] = exp(d->params[eqEiu]/(BOLTZ*tref))/tau_u;
585 d->params[epAfu] = 0;
586 d->params[epEfu] = 0;
591 d->params[epEuf] = Euf;
594 d->params[epAuf] = 0.1;
598 d->params[epAuf] = 20.0;
603 static real tau(real A, real E, real T)
605 return exp(E/(BOLTZ*T))/A;
608 static real folded_fraction(t_remd_data *d, real tref)
612 tauf = tau(d->params[epAuf], d->params[epEuf], tref);
613 taub = tau(d->params[epAfu], d->params[epEfu], tref);
615 return (taub/(tauf+taub));
618 static void print_tau(FILE *gp, t_remd_data *d, real tref)
620 real tauf, taub, ddd, fff, DG, DH, TDS, Tm, Tb, Te, Fb, Fe, Fm;
621 int i, np = d->nparams;
624 fprintf(gp, "Final value for Chi2 = %12.5e (%d replicas)\n", ddd, d->nmask);
625 tauf = tau(d->params[epAuf], d->params[epEuf], tref);
626 fprintf(gp, "%s = %12.5e %s = %12.5e (kJ/mole)\n",
627 epnm(np, epAuf), d->params[epAuf],
628 epnm(np, epEuf), d->params[epEuf]);
631 taub = tau(d->params[epAfu], d->params[epEfu], tref);
632 fprintf(gp, "%s = %12.5e %s = %12.5e (kJ/mole)\n",
633 epnm(np, epAfu), d->params[epAfu],
634 epnm(np, epEfu), d->params[epEfu]);
635 fprintf(gp, "Equilibrium properties at T = %g\n", tref);
636 fprintf(gp, "tau_f = %8.3f ns, tau_b = %8.3f ns\n", tauf/1000, taub/1000);
637 fff = taub/(tauf+taub);
638 DG = BOLTZ*tref*log(fff/(1-fff));
639 DH = d->params[epEfu]-d->params[epEuf];
641 fprintf(gp, "Folded fraction F = %8.3f\n", fff);
642 fprintf(gp, "Unfolding energies: DG = %8.3f DH = %8.3f TDS = %8.3f\n",
648 Fb = folded_fraction(d, Tb);
649 Fe = folded_fraction(d, Te);
650 while ((Te-Tb > 0.001) && (Fm != 0.5))
653 Fm = folded_fraction(d, Tm);
665 if ((Fb-0.5)*(Fe-0.5) <= 0)
667 fprintf(gp, "Melting temperature Tm = %8.3f K\n", Tm);
671 fprintf(gp, "No melting temperature detected between 260 and 420K\n");
676 fprintf(gp, "Data for intermediates at T = %g\n", tref);
677 fprintf(gp, "%8s %10s %10s %10s\n", "Name", "A", "E", "tau");
678 for (i = 0; (i < np/2); i++)
680 tauf = tau(d->params[2*i], d->params[2*i+1], tref);
681 ptr = epnm(d->nparams, 2*i);
682 fprintf(gp, "%8s %10.3e %10.3e %10.3e\n", ptr+1,
683 d->params[2*i], d->params[2*i+1], tauf/1000);
689 fprintf(gp, "Equilibrium properties at T = %g\n", tref);
690 fprintf(gp, "tau_f = %8.3f\n", tauf);
694 static void dump_remd_parameters(FILE *gp, t_remd_data *d, const char *fn,
695 const char *fn2, const char *rfn,
696 const char *efn, const char *mfn, int skip, real tref,
700 int i, j, np = d->nparams;
701 real rhs, tauf, taub, fff, DG;
703 const char *leg[] = { "Measured", "Fit", "Difference" };
704 const char *mleg[] = { "Folded fraction", "DG (kJ/mole)"};
706 real fac[] = { 0.97, 0.98, 0.99, 1.0, 1.01, 1.02, 1.03 };
707 #define NFAC asize(fac)
712 print_tau(gp, d, tref);
713 norm = (d->bDiscrete ? 1.0/d->nmask : 1.0);
717 fp = xvgropen(fn, "Optimized fit to data", "Time (ps)", "Fraction Folded", oenv);
718 xvgr_legend(fp, asize(leg), leg, oenv);
719 for (i = 0; (i < d->nframe); i++)
721 if ((skip <= 0) || ((i % skip) == 0))
723 fprintf(fp, "%12.5e %12.5e %12.5e %12.5e\n", d->time[i],
724 d->sumft[i]*norm, d->sumfct[i]*norm,
725 (d->sumft[i]-d->sumfct[i])*norm);
732 snew(rleg, d->nreplica*2);
733 for (i = 0; (i < d->nreplica); i++)
736 snew(rleg[2*i+1], 32);
737 sprintf(rleg[2*i], "\\f{4}F(t) %d", i);
738 sprintf(rleg[2*i+1], "\\f{12}F \\f{4}(t) %d", i);
740 fp = xvgropen(rfn, "Optimized fit to data", "Time (ps)", "Fraction Folded", oenv);
741 xvgr_legend(fp, d->nreplica*2, (const char**)rleg, oenv);
742 for (j = 0; (j < d->nframe); j++)
744 if ((skip <= 0) || ((j % skip) == 0))
746 fprintf(fp, "%12.5e", d->time[j]);
747 for (i = 0; (i < d->nreplica); i++)
749 fprintf(fp, " %5f %9.2e", is_folded(d, i, j), d->fcalt[i][j]);
757 if (fn2 && (d->nstate > 2))
759 fp = xvgropen(fn2, "Optimized fit to data", "Time (ps)",
760 "Fraction Intermediate", oenv);
761 xvgr_legend(fp, asize(leg), leg, oenv);
762 for (i = 0; (i < d->nframe); i++)
764 if ((skip <= 0) || ((i % skip) == 0))
766 fprintf(fp, "%12.5e %12.5e %12.5e %12.5e\n", d->time[i],
767 d->sumit[i]*norm, d->sumict[i]*norm,
768 (d->sumit[i]-d->sumict[i])*norm);
777 fp = xvgropen(mfn, "Melting curve", "T (K)", "", oenv);
778 xvgr_legend(fp, asize(mleg), mleg, oenv);
779 for (i = 260; (i <= 420); i++)
781 tauf = tau(d->params[epAuf], d->params[epEuf], 1.0*i);
782 taub = tau(d->params[epAfu], d->params[epEfu], 1.0*i);
783 fff = taub/(tauf+taub);
784 DG = BOLTZ*i*log(fff/(1-fff));
785 fprintf(fp, "%5d %8.3f %8.3f\n", i, fff, DG);
793 snew(params, d->nparams);
794 for (i = 0; (i < d->nparams); i++)
796 params[i] = d->params[i];
799 hp = xvgropen(efn, "Chi2 as a function of relative parameter",
800 "Fraction", "Chi2", oenv);
801 for (j = 0; (j < d->nparams); j++)
803 /* Reset all parameters to optimized values */
804 fprintf(hp, "@type xy\n");
805 for (i = 0; (i < d->nparams); i++)
807 d->params[i] = params[i];
809 /* Now modify one of them */
810 for (i = 0; (i < NFAC); i++)
812 d->params[j] = fac[i]*params[j];
814 fprintf(gp, "%s = %12g d2 = %12g\n", epnm(np, j), d->params[j], d2[i]);
815 fprintf(hp, "%12g %12g\n", fac[i], d2[i]);
820 for (i = 0; (i < d->nparams); i++)
822 d->params[i] = params[i];
828 for (i = 0; (i < d->nreplica); i++)
830 fprintf(gp, "Chi2[%3d] = %8.2e\n", i, d->d2_replica[i]);
834 #endif /*HAVE_LIBGSL*/
836 int gmx_kinetics(int argc, char *argv[])
838 const char *desc[] = {
839 "[THISMODULE] reads two [TT].xvg[tt] files, each one containing data for N replicas.",
840 "The first file contains the temperature of each replica at each timestep,",
841 "and the second contains real values that can be interpreted as",
842 "an indicator for folding. If the value in the file is larger than",
843 "the cutoff it is taken to be unfolded and the other way around.[PAR]",
844 "From these data an estimate of the forward and backward rate constants",
845 "for folding is made at a reference temperature. In addition,",
846 "a theoretical melting curve and free energy as a function of temperature",
847 "are printed in an [TT].xvg[tt] file.[PAR]",
848 "The user can give a max value to be regarded as intermediate",
849 "([TT]-ucut[tt]), which, when given will trigger the use of an intermediate state",
850 "in the algorithm to be defined as those structures that have",
851 "cutoff < DATA < ucut. Structures with DATA values larger than ucut will",
852 "not be regarded as potential folders. In this case 8 parameters are optimized.[PAR]",
853 "The average fraction foled is printed in an [TT].xvg[tt] file together with the fit to it.",
854 "If an intermediate is used a further file will show the build of the intermediate and the fit to that process.[PAR]",
855 "The program can also be used with continuous variables (by setting",
856 "[TT]-nodiscrete[tt]). In this case kinetics of other processes can be",
857 "studied. This is very much a work in progress and hence the manual",
858 "(this information) is lagging behind somewhat.[PAR]",
859 "In order to run [THISMODULE], GROMACS must be compiled with the GNU",
860 "scientific library."
862 static int nreplica = 1;
863 static real tref = 298.15;
864 static real cutoff = 0.2;
865 static real ucut = 0.0;
866 static real Euf = 10;
867 static real Efu = 30;
869 static gmx_bool bHaveT = TRUE;
874 static real tol = 1e-3;
875 static int maxiter = 100;
877 static int nmult = 1;
878 static gmx_bool bBack = TRUE;
879 static gmx_bool bSplit = TRUE;
880 static gmx_bool bSum = TRUE;
881 static gmx_bool bDiscrete = TRUE;
883 { "-time", FALSE, etBOOL, {&bHaveT},
884 "Expect a time in the input" },
885 { "-b", FALSE, etREAL, {&tb},
886 "First time to read from set" },
887 { "-e", FALSE, etREAL, {&te},
888 "Last time to read from set" },
889 { "-bfit", FALSE, etREAL, {&t0},
890 "Time to start the fit from" },
891 { "-efit", FALSE, etREAL, {&t1},
892 "Time to end the fit" },
893 { "-T", FALSE, etREAL, {&tref},
894 "Reference temperature for computing rate constants" },
895 { "-n", FALSE, etINT, {&nreplica},
896 "Read data for this number of replicas. Only necessary when files are written in xmgrace format using @type and & as delimiters." },
897 { "-cut", FALSE, etREAL, {&cutoff},
898 "Cut-off (max) value for regarding a structure as folded" },
899 { "-ucut", FALSE, etREAL, {&ucut},
900 "Cut-off (max) value for regarding a structure as intermediate (if not folded)" },
901 { "-euf", FALSE, etREAL, {&Euf},
902 "Initial guess for energy of activation for folding (kJ/mol)" },
903 { "-efu", FALSE, etREAL, {&Efu},
904 "Initial guess for energy of activation for unfolding (kJ/mol)" },
905 { "-ei", FALSE, etREAL, {&Ei},
906 "Initial guess for energy of activation for intermediates (kJ/mol)" },
907 { "-maxiter", FALSE, etINT, {&maxiter},
908 "Max number of iterations" },
909 { "-back", FALSE, etBOOL, {&bBack},
910 "Take the back reaction into account" },
911 { "-tol", FALSE, etREAL, {&tol},
912 "Absolute tolerance for convergence of the Nelder and Mead simplex algorithm" },
913 { "-skip", FALSE, etINT, {&skip},
914 "Skip points in the output [TT].xvg[tt] file" },
915 { "-split", FALSE, etBOOL, {&bSplit},
916 "Estimate error by splitting the number of replicas in two and refitting" },
917 { "-sum", FALSE, etBOOL, {&bSum},
918 "Average folding before computing [GRK]chi[grk]^2" },
919 { "-discrete", FALSE, etBOOL, {&bDiscrete},
920 "Use a discrete folding criterion (F <-> U) or a continuous one" },
921 { "-mult", FALSE, etINT, {&nmult},
922 "Factor to multiply the data with before discretization" }
924 #define NPA asize(pa)
927 real dt_t, dt_d, dt_d2;
928 int nset_t, nset_d, nset_d2, n_t, n_d, n_d2, i;
929 const char *tfile, *dfile, *dfile2;
934 { efXVG, "-f", "temp", ffREAD },
935 { efXVG, "-d", "data", ffREAD },
936 { efXVG, "-d2", "data2", ffOPTRD },
937 { efXVG, "-o", "ft_all", ffWRITE },
938 { efXVG, "-o2", "it_all", ffOPTWR },
939 { efXVG, "-o3", "ft_repl", ffOPTWR },
940 { efXVG, "-ee", "err_est", ffOPTWR },
941 { efLOG, "-g", "remd", ffWRITE },
942 { efXVG, "-m", "melt", ffWRITE }
944 #define NFILE asize(fnm)
946 if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_BE_NICE | PCA_TIME_UNIT,
947 NFILE, fnm, NPA, pa, asize(desc), desc, 0, NULL, &oenv))
953 please_cite(stdout, "Spoel2006d");
956 gmx_fatal(FARGS, "cutoff should be >= 0 (rather than %f)", cutoff);
959 tfile = opt2fn("-f", NFILE, fnm);
960 dfile = opt2fn("-d", NFILE, fnm);
961 dfile2 = opt2fn_null("-d2", NFILE, fnm);
963 fp = gmx_ffopen(opt2fn("-g", NFILE, fnm), "w");
965 remd.temp = read_xvg_time(tfile, bHaveT,
966 opt2parg_bSet("-b", NPA, pa), tb,
967 opt2parg_bSet("-e", NPA, pa), te,
968 nreplica, &nset_t, &n_t, &dt_t, &remd.time);
969 printf("Read %d sets of %d points in %s, dt = %g\n\n", nset_t, n_t, tfile, dt_t);
972 remd.data = read_xvg_time(dfile, bHaveT,
973 opt2parg_bSet("-b", NPA, pa), tb,
974 opt2parg_bSet("-e", NPA, pa), te,
975 nreplica, &nset_d, &n_d, &dt_d, &remd.time);
976 printf("Read %d sets of %d points in %s, dt = %g\n\n", nset_d, n_d, dfile, dt_d);
978 if ((nset_t != nset_d) || (n_t != n_d) || (dt_t != dt_d))
980 gmx_fatal(FARGS, "Files %s and %s are inconsistent. Check log file",
986 remd.data2 = read_xvg_time(dfile2, bHaveT,
987 opt2parg_bSet("-b", NPA, pa), tb,
988 opt2parg_bSet("-e", NPA, pa), te,
989 nreplica, &nset_d2, &n_d2, &dt_d2, &remd.time);
990 printf("Read %d sets of %d points in %s, dt = %g\n\n",
991 nset_d2, n_d2, dfile2, dt_d2);
992 if ((nset_d2 != nset_d) || (n_d != n_d2) || (dt_d != dt_d2))
994 gmx_fatal(FARGS, "Files %s and %s are inconsistent. Check log file",
1003 remd.nreplica = nset_d;
1006 preprocess_remd(fp, &remd, cutoff, tref, ucut, bBack, Euf, Efu, Ei, t0, t1,
1007 bSum, bDiscrete, nmult);
1009 optimize_remd_parameters(&remd, maxiter, tol);
1011 dump_remd_parameters(fp, &remd, opt2fn("-o", NFILE, fnm),
1012 opt2fn_null("-o2", NFILE, fnm),
1013 opt2fn_null("-o3", NFILE, fnm),
1014 opt2fn_null("-ee", NFILE, fnm),
1015 opt2fn("-m", NFILE, fnm), skip, tref, oenv);
1019 printf("Splitting set of replicas in two halves\n");
1020 for (i = 0; (i < remd.nreplica); i++)
1022 remd.bMask[i] = FALSE;
1025 for (i = 0; (i < remd.nreplica); i += 2)
1027 remd.bMask[i] = TRUE;
1031 optimize_remd_parameters(&remd, maxiter, tol);
1032 dump_remd_parameters(fp, &remd, "test1.xvg", NULL, NULL, NULL, NULL, skip, tref, oenv);
1034 for (i = 0; (i < remd.nreplica); i++)
1036 remd.bMask[i] = !remd.bMask[i];
1038 remd.nmask = remd.nreplica - remd.nmask;
1041 optimize_remd_parameters(&remd, maxiter, tol);
1042 dump_remd_parameters(fp, &remd, "test2.xvg", NULL, NULL, NULL, NULL, skip, tref, oenv);
1044 for (i = 0; (i < remd.nreplica); i++)
1046 remd.bMask[i] = FALSE;
1049 for (i = 0; (i < remd.nreplica/2); i++)
1051 remd.bMask[i] = TRUE;
1055 optimize_remd_parameters(&remd, maxiter, tol);
1056 dump_remd_parameters(fp, &remd, "test1.xvg", NULL, NULL, NULL, NULL, skip, tref, oenv);
1058 for (i = 0; (i < remd.nreplica); i++)
1060 remd.bMask[i] = FALSE;
1063 for (i = remd.nreplica/2; (i < remd.nreplica); i++)
1065 remd.bMask[i] = TRUE;
1069 optimize_remd_parameters(&remd, maxiter, tol);
1070 dump_remd_parameters(fp, &remd, "test1.xvg", NULL, NULL, NULL, NULL, skip, tref, oenv);
1074 view_all(oenv, NFILE, fnm);
1077 fprintf(stderr, "This program should be compiled with the GNU scientific library. Please install the library and reinstall GROMACS.\n");
1078 #endif /*HAVE_LIBGSL*/