Move parse_common_args() into commandline/pargs.*
[alexxy/gromacs.git] / src / gromacs / mdlib / init.c
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2  *
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  *          GROningen MAchine for Chemical Simulations
9  *
10  *                        VERSION 3.2.0
11  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13  * Copyright (c) 2001-2004, The GROMACS development team,
14  * check out http://www.gromacs.org for more information.
15
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  *
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  *
31  * For more info, check our website at http://www.gromacs.org
32  *
33  * And Hey:
34  * GROwing Monsters And Cloning Shrimps
35  */
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #include <stdio.h>
41 #include "typedefs.h"
42 #include "gromacs/fileio/tpxio.h"
43 #include "smalloc.h"
44 #include "vec.h"
45 #include "main.h"
46 #include "mvdata.h"
47 #include "gmx_fatal.h"
48 #include "symtab.h"
49 #include "txtdump.h"
50 #include "mdatoms.h"
51 #include "mdrun.h"
52 #include "names.h"
53 #include "calcgrid.h"
54 #include "gmx_random.h"
55 #include "update.h"
56 #include "mdebin.h"
57
58 #define BUFSIZE 256
59
60 #define NOT_FINISHED(l1, l2) \
61     printf("not finished yet: lines %d .. %d in %s\n", l1, l2, __FILE__)
62
63 void set_state_entries(t_state *state, const t_inputrec *ir, int nnodes)
64 {
65     int nnhpres;
66
67     /* The entries in the state in the tpx file might not correspond
68      * with what is needed, so we correct this here.
69      */
70     state->flags = 0;
71     if (ir->efep != efepNO || ir->bExpanded)
72     {
73         state->flags |= (1<<estLAMBDA);
74         state->flags |= (1<<estFEPSTATE);
75     }
76     state->flags |= (1<<estX);
77     if (state->lambda == NULL)
78     {
79         snew(state->lambda, efptNR);
80     }
81     if (state->x == NULL)
82     {
83         snew(state->x, state->nalloc);
84     }
85     if (EI_DYNAMICS(ir->eI))
86     {
87         state->flags |= (1<<estV);
88         if (state->v == NULL)
89         {
90             snew(state->v, state->nalloc);
91         }
92     }
93     if (ir->eI == eiSD2)
94     {
95         state->flags |= (1<<estSDX);
96         if (state->sd_X == NULL)
97         {
98             /* sd_X is not stored in the tpx file, so we need to allocate it */
99             snew(state->sd_X, state->nalloc);
100         }
101     }
102     if (ir->eI == eiCG)
103     {
104         state->flags |= (1<<estCGP);
105         if (state->cg_p == NULL)
106         {
107             /* cg_p is not stored in the tpx file, so we need to allocate it */
108             snew(state->cg_p, state->nalloc);
109         }
110     }
111     if (EI_SD(ir->eI) || ir->eI == eiBD || ir->etc == etcVRESCALE || ETC_ANDERSEN(ir->etc))
112     {
113         state->nrng  = gmx_rng_n();
114         state->nrngi = 1;
115         if (EI_SD(ir->eI) || ir->eI == eiBD || ETC_ANDERSEN(ir->etc))
116         {
117             /* This will be correct later with DD */
118             state->nrng  *= nnodes;
119             state->nrngi *= nnodes;
120         }
121         state->flags |= ((1<<estLD_RNG) | (1<<estLD_RNGI));
122         snew(state->ld_rng, state->nrng);
123         snew(state->ld_rngi, state->nrngi);
124     }
125     else
126     {
127         state->nrng = 0;
128     }
129
130     if (ir->bExpanded)
131     {
132         state->nmcrng  = gmx_rng_n();
133         snew(state->mc_rng, state->nmcrng);
134         snew(state->mc_rngi, 1);
135     }
136
137     state->nnhpres = 0;
138     if (ir->ePBC != epbcNONE)
139     {
140         state->flags |= (1<<estBOX);
141         if (PRESERVE_SHAPE(*ir))
142         {
143             state->flags |= (1<<estBOX_REL);
144         }
145         if ((ir->epc == epcPARRINELLORAHMAN) || (ir->epc == epcMTTK))
146         {
147             state->flags |= (1<<estBOXV);
148         }
149         if (ir->epc != epcNO)
150         {
151             if (IR_NPT_TROTTER(ir) || (IR_NPH_TROTTER(ir)))
152             {
153                 state->nnhpres = 1;
154                 state->flags  |= (1<<estNHPRES_XI);
155                 state->flags  |= (1<<estNHPRES_VXI);
156                 state->flags  |= (1<<estSVIR_PREV);
157                 state->flags  |= (1<<estFVIR_PREV);
158                 state->flags  |= (1<<estVETA);
159                 state->flags  |= (1<<estVOL0);
160             }
161             else
162             {
163                 state->flags |= (1<<estPRES_PREV);
164             }
165         }
166     }
167
168     if (ir->etc == etcNOSEHOOVER)
169     {
170         state->flags |= (1<<estNH_XI);
171         state->flags |= (1<<estNH_VXI);
172     }
173
174     if (ir->etc == etcVRESCALE)
175     {
176         state->flags |= (1<<estTC_INT);
177     }
178
179     init_gtc_state(state, state->ngtc, state->nnhpres, ir->opts.nhchainlength); /* allocate the space for nose-hoover chains */
180     init_ekinstate(&state->ekinstate, ir);
181
182     init_energyhistory(&state->enerhist);
183     init_df_history(&state->dfhist, ir->fepvals->n_lambda);
184 }
185
186
187 void init_parallel(t_commrec *cr, t_inputrec *inputrec,
188                    gmx_mtop_t *mtop)
189 {
190     bcast_ir_mtop(cr, inputrec, mtop);
191
192     if (inputrec->eI == eiBD || EI_SD(inputrec->eI) || ETC_ANDERSEN(inputrec->etc))
193     {
194         /* Make sure the random seeds are different on each node */
195         inputrec->ld_seed += cr->nodeid;
196     }
197 }