Move gmx_fatal.* to utility/fatalerror.*
[alexxy/gromacs.git] / src / gromacs / 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  * 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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 #include <stdio.h>
42 #include "typedefs.h"
43 #include "gromacs/fileio/tpxio.h"
44 #include "gromacs/utility/smalloc.h"
45 #include "vec.h"
46 #include "main.h"
47 #include "mvdata.h"
48 #include "gromacs/utility/fatalerror.h"
49 #include "symtab.h"
50 #include "txtdump.h"
51 #include "mdatoms.h"
52 #include "mdrun.h"
53 #include "names.h"
54 #include "calcgrid.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)
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
112     state->nnhpres = 0;
113     if (ir->ePBC != epbcNONE)
114     {
115         state->flags |= (1<<estBOX);
116         if (PRESERVE_SHAPE(*ir))
117         {
118             state->flags |= (1<<estBOX_REL);
119         }
120         if ((ir->epc == epcPARRINELLORAHMAN) || (ir->epc == epcMTTK))
121         {
122             state->flags |= (1<<estBOXV);
123         }
124         if (ir->epc != epcNO)
125         {
126             if (IR_NPT_TROTTER(ir) || (IR_NPH_TROTTER(ir)))
127             {
128                 state->nnhpres = 1;
129                 state->flags  |= (1<<estNHPRES_XI);
130                 state->flags  |= (1<<estNHPRES_VXI);
131                 state->flags  |= (1<<estSVIR_PREV);
132                 state->flags  |= (1<<estFVIR_PREV);
133                 state->flags  |= (1<<estVETA);
134                 state->flags  |= (1<<estVOL0);
135             }
136             else
137             {
138                 state->flags |= (1<<estPRES_PREV);
139             }
140         }
141     }
142
143     if (ir->etc == etcNOSEHOOVER)
144     {
145         state->flags |= (1<<estNH_XI);
146         state->flags |= (1<<estNH_VXI);
147     }
148
149     if (ir->etc == etcVRESCALE)
150     {
151         state->flags |= (1<<estTC_INT);
152     }
153
154     init_gtc_state(state, state->ngtc, state->nnhpres, ir->opts.nhchainlength); /* allocate the space for nose-hoover chains */
155     init_ekinstate(&state->ekinstate, ir);
156
157     init_energyhistory(&state->enerhist);
158     init_df_history(&state->dfhist, ir->fepvals->n_lambda);
159     state->swapstate.eSwapCoords = ir->eSwapCoords;
160 }
161
162
163 void init_parallel(t_commrec *cr, t_inputrec *inputrec,
164                    gmx_mtop_t *mtop)
165 {
166     bcast_ir_mtop(cr, inputrec, mtop);
167 }