Merge branch 'master' of git://git.gromacs.org/gromacs
[gromacs/rigid-bodies.git] / src / mdlib / init.c
blob23f54b57b072934291ee3829c8af8cb3d3db4622
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * GROwing Monsters And Cloning Shrimps
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include <stdio.h>
40 #include "typedefs.h"
41 #include "tpxio.h"
42 #include "smalloc.h"
43 #include "vec.h"
44 #include "main.h"
45 #include "mvdata.h"
46 #include "gmx_fatal.h"
47 #include "symtab.h"
48 #include "txtdump.h"
49 #include "mdatoms.h"
50 #include "mdrun.h"
51 #include "statutil.h"
52 #include "names.h"
53 #include "calcgrid.h"
54 #include "gmx_random.h"
55 #include "update.h"
56 #include "mdebin.h"
58 #define BUFSIZE 256
60 #define NOT_FINISHED(l1,l2) \
61 printf("not finished yet: lines %d .. %d in %s\n",l1,l2,__FILE__)
63 static char *int_title(const char *title,int nodeid,char buf[], int size)
65 sprintf(buf,"%s (%d)",title,nodeid);
67 return buf;
70 static void set_state_entries(t_state *state,t_inputrec *ir,int nnodes)
72 /* The entries in the state in the tpx file might not correspond
73 * with what is needed, so we correct this here.
75 state->flags = 0;
76 if (ir->efep != efepNO)
77 state->flags |= (1<<estLAMBDA);
78 state->flags |= (1<<estX);
79 if (state->x == NULL)
80 snew(state->x,state->nalloc);
81 if (EI_DYNAMICS(ir->eI)) {
82 state->flags |= (1<<estV);
83 if (state->v == NULL)
84 snew(state->v,state->nalloc);
86 if (ir->eI == eiSD2) {
87 state->flags |= (1<<estSDX);
88 if (state->sd_X == NULL) {
89 /* sd_X is not stored in the tpx file, so we need to allocate it */
90 snew(state->sd_X,state->nalloc);
93 if (ir->eI == eiCG) {
94 state->flags |= (1<<estCGP);
96 if (EI_SD(ir->eI) || ir->eI == eiBD || ir->etc == etcVRESCALE) {
97 state->nrng = gmx_rng_n();
98 state->nrngi = 1;
99 if (EI_SD(ir->eI) || ir->eI == eiBD) {
100 /* This will be correct later with DD */
101 state->nrng *= nnodes;
102 state->nrngi *= nnodes;
104 state->flags |= ((1<<estLD_RNG) | (1<<estLD_RNGI));
105 snew(state->ld_rng, state->nrng);
106 snew(state->ld_rngi,state->nrngi);
107 } else {
108 state->nrng = 0;
110 if (ir->ePBC != epbcNONE) {
111 state->flags |= (1<<estBOX);
112 if (PRESERVE_SHAPE(*ir)) {
113 state->flags |= (1<<estBOX_REL);
115 if ((ir->epc == epcPARRINELLORAHMAN) || (ir->epc == epcTROTTER)) {
116 state->flags |= (1<<estBOXV);
118 if (ir->epc != epcNO) {
119 state->flags |= (1<<estPRES_PREV);
123 if ((ir->etc == etcNOSEHOOVER) || (ir->etc == etcTROTTER)) {
124 state->flags |= (1<<estNH_XI);
125 state->flags |= (1<<estNH_VXI);
128 if (ir->etc == etcVRESCALE) {
129 state->flags |= (1<<estTC_INT);
132 init_ekinstate(&state->ekinstate,ir);
134 init_energyhistory(&state->enerhist);
137 void init_single(FILE *fplog,t_inputrec *inputrec,
138 const char *tpxfile,gmx_mtop_t *mtop,
139 t_state *state)
141 read_tpx_state(tpxfile,inputrec,state,NULL,mtop);
142 set_state_entries(state,inputrec,1);
144 if (fplog)
145 pr_inputrec(fplog,0,"Input Parameters",inputrec,FALSE);
148 void init_parallel(FILE *log,const char *tpxfile,t_commrec *cr,
149 t_inputrec *inputrec,gmx_mtop_t *mtop,
150 t_state *state,
151 int list)
153 char buf[256];
155 if (MASTER(cr)) {
156 init_inputrec(inputrec);
157 read_tpx_state(tpxfile,inputrec,state,NULL,mtop);
158 /* When we will be doing domain decomposition with separate PME nodes
159 * the rng entries will be too large, we correct for this later.
161 set_state_entries(state,inputrec,cr->nnodes);
163 bcast_ir_mtop(cr,inputrec,mtop);
165 if (inputrec->eI == eiBD || EI_SD(inputrec->eI)) {
166 /* Make sure the random seeds are different on each node */
167 inputrec->ld_seed += cr->nodeid;
170 /* Printing */
171 if (list!=0 && log!=NULL)
173 if (list&LIST_INPUTREC)
174 pr_inputrec(log,0,"parameters of the run",inputrec,FALSE);
175 if (list&LIST_X)
176 pr_rvecs(log,0,"box",state->box,DIM);
177 if (list&LIST_X)
178 pr_rvecs(log,0,"box_rel",state->box_rel,DIM);
179 if (list&LIST_V)
180 pr_rvecs(log,0,"boxv",state->boxv,DIM);
181 if (list&LIST_X)
182 pr_rvecs(log,0,int_title("x",0,buf,255),state->x,state->natoms);
183 if (list&LIST_V)
184 pr_rvecs(log,0,int_title("v",0,buf,255),state->v,state->natoms);
185 if (list&LIST_TOP)
186 pr_mtop(log,0,int_title("topology",cr->nodeid,buf,255),mtop,TRUE);
187 fflush(log);