Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / tpxio.c
index dc6eebf60822c24d9f34aa7953ce415190c589a4..bd7a9698afe4f265c61695a90ad992274d383814 100644 (file)
@@ -73,7 +73,7 @@
 static const char *tpx_tag = TPX_TAG_RELEASE;
 
 /* This number should be increased whenever the file format changes! */
-static const int tpx_version = 91;
+static const int tpx_version = 92;
 
 /* This number should only be increased when you edit the TOPOLOGY section
  * or the HEADER of the tpx format.
@@ -251,14 +251,18 @@ static void do_pullgrp(t_fileio *fio, t_pullgrp *pgrp, gmx_bool bRead,
   }
 }
 
-static void do_expandedvals(t_fileio *fio,t_expanded *expand,int n_lambda, gmx_bool bRead, int file_version)
+static void do_expandedvals(t_fileio *fio,t_expanded *expand,t_lambda *fepvals, gmx_bool bRead, int file_version)
 {
   /* i is used in the ndo_double macro*/
   int i;
   real fv;
   gmx_bool bDum=TRUE;
   real rdum;
+  int n_lambda=fepvals->n_lambda;
 
+  /* reset the lambda calculation window */
+  fepvals->lambda_start_n = 0;
+  fepvals->lambda_stop_n = n_lambda;
   if (file_version >= 79)
   {
       if (n_lambda>0)
@@ -326,6 +330,7 @@ static void do_fepvals(t_fileio *fio,t_lambda *fepvals,gmx_bool bRead, int file_
   real rdum;
 
   /* free energy values */
+
   if (file_version >= 79)
   {
       gmx_fio_do_int(fio,fepvals->init_fep_state);
@@ -367,23 +372,41 @@ static void do_fepvals(t_fileio *fio,t_lambda *fepvals,gmx_bool bRead, int file_
   else if (file_version >= 64)
   {
       gmx_fio_do_int(fio,fepvals->n_lambda);
-      snew(fepvals->all_lambda,efptNR);
       if (bRead)
       {
-          snew(fepvals->all_lambda[efptFEP],fepvals->n_lambda);
+          int g;
+
+          snew(fepvals->all_lambda,efptNR);
+          /* still allocate the all_lambda array's contents. */
+          for(g=0;g<efptNR;g++)
+          {
+              if (fepvals->n_lambda > 0) {
+                  snew(fepvals->all_lambda[g],fepvals->n_lambda);
+              }
+          }
       }
-      bDum=gmx_fio_ndo_double(fio,fepvals->all_lambda[efptFEP],fepvals->n_lambda);
+      bDum=gmx_fio_ndo_double(fio,fepvals->all_lambda[efptFEP],
+                              fepvals->n_lambda);
       if (fepvals->init_lambda >= 0)
       {
+          int g,h;
+
           fepvals->separate_dvdl[efptFEP] = TRUE;
-      }
-      /* still allocate the all_lambda array's contents. */
-      for (g=0;g<efptNR;g++)
-      {
-          if (fepvals->n_lambda > 0) {
-              if (bRead)
+
+          if (bRead)
+          {
+              /* copy the contents of the efptFEP lambda component to all
+                 the other components */
+              for(g=0;g<efptNR;g++)
               {
-                  snew(fepvals->all_lambda[g],fepvals->n_lambda);
+                  for(h=0;h<fepvals->n_lambda;h++)
+                  {
+                      if (g!=efptFEP)
+                      {
+                          fepvals->all_lambda[g][h] =
+                                    fepvals->all_lambda[efptFEP][h];
+                      }
+                  }
               }
           }
       }
@@ -482,6 +505,38 @@ static void do_fepvals(t_fileio *fio,t_lambda *fepvals,gmx_bool bRead, int file_
   {
       fepvals->bPrintEnergy = FALSE;
   }
+
+  /* handle lambda_neighbors */
+  if ((file_version >= 83 && file_version < 90) || file_version >= 92 )
+  {
+      gmx_fio_do_int(fio,fepvals->lambda_neighbors);
+      if ( (fepvals->lambda_neighbors >= 0) && (fepvals->init_fep_state>=0) &&
+           (fepvals->init_lambda < 0) )
+      {
+          fepvals->lambda_start_n = (fepvals->init_fep_state -
+                                     fepvals->lambda_neighbors);
+          fepvals->lambda_stop_n = (fepvals->init_fep_state +
+                                    fepvals->lambda_neighbors + 1);
+          if (fepvals->lambda_start_n < 0)
+          {
+              fepvals->lambda_start_n = 0;;
+          }
+          if (fepvals->lambda_stop_n >= fepvals->n_lambda)
+          {
+              fepvals->lambda_stop_n = fepvals->n_lambda;
+          }
+      }
+      else
+      {
+          fepvals->lambda_start_n = 0;
+          fepvals->lambda_stop_n = fepvals->n_lambda;
+      }
+  }
+  else
+  {
+      fepvals->lambda_start_n = 0;
+      fepvals->lambda_stop_n = fepvals->n_lambda;
+  }
 }
 
 static void do_pull(t_fileio *fio, t_pull *pull,gmx_bool bRead, int file_version)
@@ -968,7 +1023,7 @@ static void do_inputrec(t_fileio *fio, t_inputrec *ir,gmx_bool bRead,
     }
     if (ir->bExpanded)
     {
-        do_expandedvals(fio,ir->expandedvals,ir->fepvals->n_lambda,bRead,file_version);
+        do_expandedvals(fio,ir->expandedvals,ir->fepvals,bRead,file_version);
     }
     if (file_version >= 57) {
       gmx_fio_do_int(fio,ir->eDisre);