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/fileio/tpxio.h"
48 #include "gmx_fatal.h"
55 #include "gromacs/random/random.h"
61 #define NOT_FINISHED(l1, l2) \
62 printf("not finished yet: lines %d .. %d in %s\n", l1, l2, __FILE__)
64 void set_state_entries(t_state *state, const t_inputrec *ir, int nnodes)
68 /* The entries in the state in the tpx file might not correspond
69 * with what is needed, so we correct this here.
72 if (ir->efep != efepNO || ir->bExpanded)
74 state->flags |= (1<<estLAMBDA);
75 state->flags |= (1<<estFEPSTATE);
77 state->flags |= (1<<estX);
78 if (state->lambda == NULL)
80 snew(state->lambda, efptNR);
84 snew(state->x, state->nalloc);
86 if (EI_DYNAMICS(ir->eI))
88 state->flags |= (1<<estV);
91 snew(state->v, state->nalloc);
96 state->flags |= (1<<estSDX);
97 if (state->sd_X == NULL)
99 /* sd_X is not stored in the tpx file, so we need to allocate it */
100 snew(state->sd_X, state->nalloc);
105 state->flags |= (1<<estCGP);
106 if (state->cg_p == NULL)
108 /* cg_p is not stored in the tpx file, so we need to allocate it */
109 snew(state->cg_p, state->nalloc);
112 if (EI_SD(ir->eI) || ir->eI == eiBD || ir->etc == etcVRESCALE || ETC_ANDERSEN(ir->etc))
114 state->nrng = gmx_rng_n();
116 if (EI_SD(ir->eI) || ir->eI == eiBD || ETC_ANDERSEN(ir->etc))
118 /* This will be correct later with DD */
119 state->nrng *= nnodes;
120 state->nrngi *= nnodes;
122 state->flags |= ((1<<estLD_RNG) | (1<<estLD_RNGI));
123 snew(state->ld_rng, state->nrng);
124 snew(state->ld_rngi, state->nrngi);
133 state->nmcrng = gmx_rng_n();
134 snew(state->mc_rng, state->nmcrng);
135 snew(state->mc_rngi, 1);
139 if (ir->ePBC != epbcNONE)
141 state->flags |= (1<<estBOX);
142 if (PRESERVE_SHAPE(*ir))
144 state->flags |= (1<<estBOX_REL);
146 if ((ir->epc == epcPARRINELLORAHMAN) || (ir->epc == epcMTTK))
148 state->flags |= (1<<estBOXV);
150 if (ir->epc != epcNO)
152 if (IR_NPT_TROTTER(ir) || (IR_NPH_TROTTER(ir)))
155 state->flags |= (1<<estNHPRES_XI);
156 state->flags |= (1<<estNHPRES_VXI);
157 state->flags |= (1<<estSVIR_PREV);
158 state->flags |= (1<<estFVIR_PREV);
159 state->flags |= (1<<estVETA);
160 state->flags |= (1<<estVOL0);
164 state->flags |= (1<<estPRES_PREV);
169 if (ir->etc == etcNOSEHOOVER)
171 state->flags |= (1<<estNH_XI);
172 state->flags |= (1<<estNH_VXI);
175 if (ir->etc == etcVRESCALE)
177 state->flags |= (1<<estTC_INT);
180 init_gtc_state(state, state->ngtc, state->nnhpres, ir->opts.nhchainlength); /* allocate the space for nose-hoover chains */
181 init_ekinstate(&state->ekinstate, ir);
183 init_energyhistory(&state->enerhist);
184 init_df_history(&state->dfhist, ir->fepvals->n_lambda);
185 state->swapstate.eSwapCoords = ir->eSwapCoords;
189 void init_parallel(t_commrec *cr, t_inputrec *inputrec,
192 bcast_ir_mtop(cr, inputrec, mtop);
194 if (inputrec->eI == eiBD || EI_SD(inputrec->eI) || ETC_ANDERSEN(inputrec->etc))
196 /* Make sure the random seeds are different on each node */
197 inputrec->ld_seed += cr->nodeid;