Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / mdlib / init.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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, 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.
11  *
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.
16  *
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.
21  *
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.
26  *
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.
34  *
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.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <stdio.h>
43 #include "typedefs.h"
44 #include "tpxio.h"
45 #include "smalloc.h"
46 #include "vec.h"
47 #include "main.h"
48 #include "mvdata.h"
49 #include "gmx_fatal.h"
50 #include "symtab.h"
51 #include "txtdump.h"
52 #include "mdatoms.h"
53 #include "mdrun.h"
54 #include "statutil.h"
55 #include "names.h"
56 #include "calcgrid.h"
57 #include "gmx_random.h"
58 #include "update.h"
59 #include "mdebin.h"
60
61 #define BUFSIZE 256
62
63 #define NOT_FINISHED(l1,l2) \
64   printf("not finished yet: lines %d .. %d in %s\n",l1,l2,__FILE__)
65
66 static char *int_title(const char *title,int nodeid,char buf[], int size)
67 {
68   sprintf(buf,"%s (%d)",title,nodeid);
69
70   return buf;
71 }
72
73 void set_state_entries(t_state *state,const t_inputrec *ir,int nnodes)
74 {
75   int nnhpres;
76
77   /* The entries in the state in the tpx file might not correspond
78    * with what is needed, so we correct this here.
79    */
80   state->flags = 0;
81   if (ir->efep != efepNO || ir->bExpanded)
82   {
83       state->flags |= (1<<estLAMBDA);
84       state->flags |= (1<<estFEPSTATE);
85   }
86   state->flags |= (1<<estX);
87   if (state->lambda==NULL)
88     {
89       snew(state->lambda,efptNR);
90     }
91   if (state->x == NULL)
92     snew(state->x,state->nalloc);
93   if (EI_DYNAMICS(ir->eI)) {
94     state->flags |= (1<<estV);
95     if (state->v == NULL)
96       snew(state->v,state->nalloc);
97   }
98   if (ir->eI == eiSD2) {
99     state->flags |= (1<<estSDX);
100     if (state->sd_X == NULL) {
101       /* sd_X is not stored in the tpx file, so we need to allocate it */
102       snew(state->sd_X,state->nalloc);
103     }
104   }
105     if (ir->eI == eiCG)
106     {
107         state->flags |= (1<<estCGP);
108         if (state->cg_p == NULL)
109         {
110             /* cg_p is not stored in the tpx file, so we need to allocate it */
111             snew(state->cg_p,state->nalloc);
112         }
113     }
114   if (EI_SD(ir->eI) || ir->eI == eiBD || ir->etc == etcVRESCALE) {
115     state->nrng  = gmx_rng_n();
116     state->nrngi = 1;
117     if (EI_SD(ir->eI) || ir->eI == eiBD) {
118       /* This will be correct later with DD */
119       state->nrng  *= nnodes;
120       state->nrngi *= nnodes;
121     }
122     state->flags |= ((1<<estLD_RNG) | (1<<estLD_RNGI));
123     snew(state->ld_rng, state->nrng);
124     snew(state->ld_rngi,state->nrngi);
125   } else {
126     state->nrng = 0;
127   }
128
129   if (ir->bExpanded)
130   {
131       state->nmcrng  = gmx_rng_n();
132       snew(state->mc_rng,state->nmcrng);
133       snew(state->mc_rngi,1);
134   }
135
136   state->nnhpres = 0;
137   if (ir->ePBC != epbcNONE) {
138       state->flags |= (1<<estBOX);
139       if (PRESERVE_SHAPE(*ir)) {
140           state->flags |= (1<<estBOX_REL);
141       }
142       if ((ir->epc == epcPARRINELLORAHMAN) || (ir->epc == epcMTTK))
143       {
144           state->flags |= (1<<estBOXV);
145       }
146       if (ir->epc != epcNO)
147       {
148           if (IR_NPT_TROTTER(ir) || (IR_NPH_TROTTER(ir)))
149           {
150               state->nnhpres = 1;
151               state->flags |= (1<<estNHPRES_XI);
152               state->flags |= (1<<estNHPRES_VXI);
153               state->flags |= (1<<estSVIR_PREV);
154               state->flags |= (1<<estFVIR_PREV);
155               state->flags |= (1<<estVETA);
156               state->flags |= (1<<estVOL0);
157           }
158           else
159           {
160               state->flags |= (1<<estPRES_PREV);
161           }
162       }
163   }
164
165   if (ir->etc == etcNOSEHOOVER) {
166     state->flags |= (1<<estNH_XI);
167     state->flags |= (1<<estNH_VXI);
168   }
169
170   if (ir->etc == etcVRESCALE) {
171     state->flags |= (1<<estTC_INT);
172   }
173
174   init_gtc_state(state,state->ngtc,state->nnhpres,ir->opts.nhchainlength); /* allocate the space for nose-hoover chains */
175   init_ekinstate(&state->ekinstate,ir);
176
177   init_energyhistory(&state->enerhist);
178   init_df_history(&state->dfhist,ir->fepvals->n_lambda,ir->expandedvals->init_wl_delta);
179 }
180
181
182 void init_parallel(FILE *log, t_commrec *cr, t_inputrec *inputrec,
183                    gmx_mtop_t *mtop)
184 {
185     bcast_ir_mtop(cr,inputrec,mtop);
186
187     if (inputrec->eI == eiBD || EI_SD(inputrec->eI)) {
188         /* Make sure the random seeds are different on each node */
189         inputrec->ld_seed += cr->nodeid;
190     }
191 }
192
193