Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / gmxlib / mvdata.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,2013, 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 /* This file is completely threadsafe - keep it that way! */
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #include <sysstuff.h>
44 #include <string.h>
45 #include "typedefs.h"
46 #include "main.h"
47 #include "mvdata.h"
48 #include "network.h"
49 #include "smalloc.h"
50 #include "gmx_fatal.h"
51 #include "symtab.h"
52 #include "vec.h"
53 #include "tgroup.h"
54
55 #define   block_bc(cr,   d) gmx_bcast(     sizeof(d),     &(d),(cr))
56 /* Probably the test for (nr) > 0 in the next macro is only needed
57  * on BlueGene(/L), where IBM's MPI_Bcast will segfault after
58  * dereferencing a null pointer, even when no data is to be transferred. */
59 #define  nblock_bc(cr,nr,d) { if ((nr) > 0) gmx_bcast((nr)*sizeof((d)[0]), (d),(cr)); }
60 #define    snew_bc(cr,d,nr) { if (!MASTER(cr)) snew((d),(nr)); }
61 /* Dirty macro with bAlloc not as an argument */
62 #define nblock_abc(cr,nr,d) { if (bAlloc) snew((d),(nr)); nblock_bc(cr,(nr),(d)); }
63
64 static void bc_string(const t_commrec *cr,t_symtab *symtab,char ***s)
65 {
66   int handle;
67   
68   if (MASTER(cr)) {
69     handle = lookup_symtab(symtab,*s);
70   }
71   block_bc(cr,handle);
72   if (!MASTER(cr)) {
73     *s = get_symtab_handle(symtab,handle);
74   }
75 }
76
77 static void bc_strings(const t_commrec *cr,t_symtab *symtab,int nr,char ****nm)
78 {
79   int  i;
80   int  *handle;
81   char ***NM;
82
83   snew(handle,nr);
84   if (MASTER(cr)) {
85     NM = *nm;
86     for(i=0; (i<nr); i++)
87       handle[i] = lookup_symtab(symtab,NM[i]);
88   }
89   nblock_bc(cr,nr,handle);
90
91   if (!MASTER(cr)) {
92     snew_bc(cr,*nm,nr);
93     NM = *nm;
94     for (i=0; (i<nr); i++) 
95       (*nm)[i] = get_symtab_handle(symtab,handle[i]);
96   }
97   sfree(handle);
98 }
99
100 static void bc_strings_resinfo(const t_commrec *cr,t_symtab *symtab,
101                                int nr,t_resinfo *resinfo)
102 {
103   int  i;
104   int  *handle;
105
106   snew(handle,nr);
107   if (MASTER(cr)) {
108     for(i=0; (i<nr); i++)
109       handle[i] = lookup_symtab(symtab,resinfo[i].name);
110   }
111   nblock_bc(cr,nr,handle);
112
113   if (!MASTER(cr)) {
114     for (i=0; (i<nr); i++) 
115       resinfo[i].name = get_symtab_handle(symtab,handle[i]);
116   }
117   sfree(handle);
118 }
119
120 static void bc_symtab(const t_commrec *cr,t_symtab *symtab)
121 {
122   int i,nr,len;
123   t_symbuf *symbuf;
124
125   block_bc(cr,symtab->nr);
126   nr = symtab->nr;
127   snew_bc(cr,symtab->symbuf,1);
128   symbuf = symtab->symbuf;
129   symbuf->bufsize = nr;
130   snew_bc(cr,symbuf->buf,nr);
131   for (i=0; i<nr; i++) {
132     if (MASTER(cr))
133       len = strlen(symbuf->buf[i]) + 1;
134     block_bc(cr,len);
135     snew_bc(cr,symbuf->buf[i],len);
136     nblock_bc(cr,len,symbuf->buf[i]);
137   }
138 }
139
140 static void bc_block(const t_commrec *cr,t_block *block)
141 {
142   block_bc(cr,block->nr);
143   snew_bc(cr,block->index,block->nr+1);
144   nblock_bc(cr,block->nr+1,block->index);
145 }
146
147 static void bc_blocka(const t_commrec *cr,t_blocka *block)
148 {
149   block_bc(cr,block->nr);
150   snew_bc(cr,block->index,block->nr+1);
151   nblock_bc(cr,block->nr+1,block->index);
152   block_bc(cr,block->nra);
153   if (block->nra) {
154     snew_bc(cr,block->a,block->nra);
155     nblock_bc(cr,block->nra,block->a);
156   }
157 }
158
159 static void bc_grps(const t_commrec *cr,t_grps grps[])
160 {
161   int i;
162   
163   for(i=0; (i<egcNR); i++) {
164     block_bc(cr,grps[i].nr);
165     snew_bc(cr,grps[i].nm_ind,grps[i].nr);
166     nblock_bc(cr,grps[i].nr,grps[i].nm_ind);
167   }
168 }
169
170 static void bc_atoms(const t_commrec *cr,t_symtab *symtab,t_atoms *atoms)
171 {
172   int dummy;
173
174   block_bc(cr,atoms->nr);
175   snew_bc(cr,atoms->atom,atoms->nr);
176   nblock_bc(cr,atoms->nr,atoms->atom);
177   bc_strings(cr,symtab,atoms->nr,&atoms->atomname);
178   block_bc(cr,atoms->nres);
179   snew_bc(cr,atoms->resinfo,atoms->nres);
180   nblock_bc(cr,atoms->nres,atoms->resinfo);
181   bc_strings_resinfo(cr,symtab,atoms->nres,atoms->resinfo);
182   /* QMMM requires atomtypes to be known on all nodes as well */
183   bc_strings(cr,symtab,atoms->nr,&atoms->atomtype);
184   bc_strings(cr,symtab,atoms->nr,&atoms->atomtypeB);
185 }
186
187 static void bc_groups(const t_commrec *cr,t_symtab *symtab,
188                       int natoms,gmx_groups_t *groups)
189 {
190   int dummy;
191   int g,n;
192
193   bc_grps(cr,groups->grps);
194   block_bc(cr,groups->ngrpname);
195   bc_strings(cr,symtab,groups->ngrpname,&groups->grpname);
196   for(g=0; g<egcNR; g++) {
197     if (MASTER(cr)) {
198       if (groups->grpnr[g]) {
199         n = natoms;
200       } else {
201         n = 0;
202       }
203     }
204     block_bc(cr,n);
205     if (n == 0) {
206       groups->grpnr[g] = NULL;
207     } else {
208       snew_bc(cr,groups->grpnr[g],n);
209       nblock_bc(cr,n,groups->grpnr[g]);
210     }
211   }
212   if (debug) fprintf(debug,"after bc_groups\n");
213 }
214
215 void bcast_state_setup(const t_commrec *cr,t_state *state)
216 {
217   block_bc(cr,state->natoms);
218   block_bc(cr,state->ngtc);
219   block_bc(cr,state->nnhpres);
220   block_bc(cr,state->nhchainlength);
221   block_bc(cr,state->nrng);
222   block_bc(cr,state->nrngi);
223   block_bc(cr,state->flags);
224   if (state->lambda==NULL)
225   {
226       snew_bc(cr,state->lambda,efptNR)
227   }
228 }
229
230 void bcast_state(const t_commrec *cr,t_state *state,gmx_bool bAlloc)
231 {
232   int i,nnht,nnhtp;
233
234   bcast_state_setup(cr,state);
235
236   nnht = (state->ngtc)*(state->nhchainlength); 
237   nnhtp = (state->nnhpres)*(state->nhchainlength); 
238
239   if (MASTER(cr)) {
240     bAlloc = FALSE;
241   }
242   if (bAlloc) {
243     state->nalloc = state->natoms;
244   }
245   for(i=0; i<estNR; i++) {
246     if (state->flags & (1<<i)) {
247       switch (i) {
248       case estLAMBDA:  nblock_bc(cr,efptNR,state->lambda); break;
249       case estFEPSTATE: block_bc(cr,state->fep_state); break;
250       case estBOX:     block_bc(cr,state->box); break;
251       case estBOX_REL: block_bc(cr,state->box_rel); break;
252       case estBOXV:    block_bc(cr,state->boxv); break;
253       case estPRES_PREV: block_bc(cr,state->pres_prev); break;
254       case estSVIR_PREV: block_bc(cr,state->svir_prev); break;
255       case estFVIR_PREV: block_bc(cr,state->fvir_prev); break;
256       case estNH_XI:   nblock_abc(cr,nnht,state->nosehoover_xi); break;
257       case estNH_VXI:  nblock_abc(cr,nnht,state->nosehoover_vxi); break;
258       case estNHPRES_XI:   nblock_abc(cr,nnhtp,state->nhpres_xi); break;
259       case estNHPRES_VXI:  nblock_abc(cr,nnhtp,state->nhpres_vxi); break;
260       case estTC_INT:  nblock_abc(cr,state->ngtc,state->therm_integral); break;
261       case estVETA:    block_bc(cr,state->veta); break;
262       case estVOL0:    block_bc(cr,state->vol0); break;
263       case estX:       nblock_abc(cr,state->natoms,state->x); break;
264       case estV:       nblock_abc(cr,state->natoms,state->v); break;
265       case estSDX:     nblock_abc(cr,state->natoms,state->sd_X); break;
266       case estCGP:     nblock_abc(cr,state->natoms,state->cg_p); break;
267           case estLD_RNG:  if(state->nrngi == 1) nblock_abc(cr,state->nrng,state->ld_rng); break;
268           case estLD_RNGI: if(state->nrngi == 1) nblock_abc(cr,state->nrngi,state->ld_rngi); break;
269       case estDISRE_INITF: block_bc(cr,state->hist.disre_initf); break;
270       case estDISRE_RM3TAV:
271           block_bc(cr,state->hist.ndisrepairs);
272           nblock_abc(cr,state->hist.ndisrepairs,state->hist.disre_rm3tav);
273           break;
274       case estORIRE_INITF: block_bc(cr,state->hist.orire_initf); break;
275       case estORIRE_DTAV:
276           block_bc(cr,state->hist.norire_Dtav);
277           nblock_abc(cr,state->hist.norire_Dtav,state->hist.orire_Dtav);
278           break;
279       default:
280           gmx_fatal(FARGS,
281                     "Communication is not implemented for %s in bcast_state",
282                     est_names[i]);
283       }
284     }
285   }
286 }
287
288 static void bc_ilists(const t_commrec *cr,t_ilist *ilist)
289 {
290   int ftype;
291
292   /* Here we only communicate the non-zero length ilists */
293   if (MASTER(cr)) {
294     for(ftype=0; ftype<F_NRE; ftype++) {
295       if (ilist[ftype].nr > 0) {
296         block_bc(cr,ftype);
297         block_bc(cr,ilist[ftype].nr);
298         nblock_bc(cr,ilist[ftype].nr,ilist[ftype].iatoms);
299       }
300     }
301     ftype = -1;
302     block_bc(cr,ftype);
303   } else {
304     for(ftype=0; ftype<F_NRE; ftype++) {
305       ilist[ftype].nr = 0;
306     }
307     do {
308       block_bc(cr,ftype);
309       if (ftype >= 0) {
310         block_bc(cr,ilist[ftype].nr);
311         snew_bc(cr,ilist[ftype].iatoms,ilist[ftype].nr);
312         nblock_bc(cr,ilist[ftype].nr,ilist[ftype].iatoms);
313       }
314     } while (ftype >= 0);
315   }
316
317   if (debug) fprintf(debug,"after bc_ilists\n");
318 }
319
320 static void bc_cmap(const t_commrec *cr, gmx_cmap_t *cmap_grid)
321 {
322         int i,j,nelem,ngrid;
323         
324         block_bc(cr,cmap_grid->ngrid);
325         block_bc(cr,cmap_grid->grid_spacing);
326         
327         ngrid = cmap_grid->ngrid;
328         nelem = cmap_grid->grid_spacing * cmap_grid->grid_spacing;
329         
330         if(ngrid>0)
331         {
332                 snew_bc(cr,cmap_grid->cmapdata,ngrid);
333                 
334                 for(i=0;i<ngrid;i++)
335                 {
336                         snew_bc(cr,cmap_grid->cmapdata[i].cmap,4*nelem);
337                         nblock_bc(cr,4*nelem,cmap_grid->cmapdata[i].cmap);
338                 }
339         }
340 }
341
342 static void bc_ffparams(const t_commrec *cr,gmx_ffparams_t *ffp)
343 {
344   int i;
345   
346   block_bc(cr,ffp->ntypes);
347   block_bc(cr,ffp->atnr);
348   snew_bc(cr,ffp->functype,ffp->ntypes);
349   snew_bc(cr,ffp->iparams,ffp->ntypes);
350   nblock_bc(cr,ffp->ntypes,ffp->functype);
351   nblock_bc(cr,ffp->ntypes,ffp->iparams);
352   block_bc(cr,ffp->reppow);
353   block_bc(cr,ffp->fudgeQQ);
354   bc_cmap(cr,&ffp->cmap_grid);
355 }
356
357 static void bc_grpopts(const t_commrec *cr,t_grpopts *g)
358 {
359     int i,n;
360     
361     block_bc(cr,g->ngtc);
362     block_bc(cr,g->ngacc);
363     block_bc(cr,g->ngfrz);
364     block_bc(cr,g->ngener);
365     snew_bc(cr,g->nrdf,g->ngtc);
366     snew_bc(cr,g->tau_t,g->ngtc);
367     snew_bc(cr,g->ref_t,g->ngtc);
368     snew_bc(cr,g->acc,g->ngacc);
369     snew_bc(cr,g->nFreeze,g->ngfrz);
370     snew_bc(cr,g->egp_flags,g->ngener*g->ngener);
371     
372     nblock_bc(cr,g->ngtc,g->nrdf);
373     nblock_bc(cr,g->ngtc,g->tau_t);
374     nblock_bc(cr,g->ngtc,g->ref_t);
375     nblock_bc(cr,g->ngacc,g->acc);
376     nblock_bc(cr,g->ngfrz,g->nFreeze);
377     nblock_bc(cr,g->ngener*g->ngener,g->egp_flags);
378     snew_bc(cr,g->annealing,g->ngtc);
379     snew_bc(cr,g->anneal_npoints,g->ngtc);
380     snew_bc(cr,g->anneal_time,g->ngtc);
381     snew_bc(cr,g->anneal_temp,g->ngtc);
382     nblock_bc(cr,g->ngtc,g->annealing);
383     nblock_bc(cr,g->ngtc,g->anneal_npoints);
384     for(i=0;(i<g->ngtc); i++) {
385         n = g->anneal_npoints[i];
386         if (n > 0) {
387           snew_bc(cr,g->anneal_time[i],n);
388           snew_bc(cr,g->anneal_temp[i],n);
389           nblock_bc(cr,n,g->anneal_time[i]);
390           nblock_bc(cr,n,g->anneal_temp[i]);
391         }
392     }
393     
394     /* QMMM stuff, see inputrec */
395     block_bc(cr,g->ngQM);
396     snew_bc(cr,g->QMmethod,g->ngQM);
397     snew_bc(cr,g->QMbasis,g->ngQM);
398     snew_bc(cr,g->QMcharge,g->ngQM);
399     snew_bc(cr,g->QMmult,g->ngQM);
400     snew_bc(cr,g->bSH,g->ngQM);
401     snew_bc(cr,g->CASorbitals,g->ngQM);
402     snew_bc(cr,g->CASelectrons,g->ngQM);
403     snew_bc(cr,g->SAon,g->ngQM);
404     snew_bc(cr,g->SAoff,g->ngQM);
405     snew_bc(cr,g->SAsteps,g->ngQM);
406     
407     if (g->ngQM)
408     {
409         nblock_bc(cr,g->ngQM,g->QMmethod);
410         nblock_bc(cr,g->ngQM,g->QMbasis);
411         nblock_bc(cr,g->ngQM,g->QMcharge);
412         nblock_bc(cr,g->ngQM,g->QMmult);
413         nblock_bc(cr,g->ngQM,g->bSH);
414         nblock_bc(cr,g->ngQM,g->CASorbitals);
415         nblock_bc(cr,g->ngQM,g->CASelectrons);
416         nblock_bc(cr,g->ngQM,g->SAon);
417         nblock_bc(cr,g->ngQM,g->SAoff);
418         nblock_bc(cr,g->ngQM,g->SAsteps);
419         /* end of QMMM stuff */
420     }
421 }
422
423 static void bc_cosines(const t_commrec *cr,t_cosines *cs)
424 {
425   block_bc(cr,cs->n);
426   snew_bc(cr,cs->a,cs->n);
427   snew_bc(cr,cs->phi,cs->n);
428   if (cs->n > 0) {
429     nblock_bc(cr,cs->n,cs->a);
430     nblock_bc(cr,cs->n,cs->phi);
431   }
432 }
433
434 static void bc_pullgrp(const t_commrec *cr,t_pullgrp *pgrp)
435 {
436   block_bc(cr,*pgrp);
437   if (pgrp->nat > 0) {
438     snew_bc(cr,pgrp->ind,pgrp->nat);
439     nblock_bc(cr,pgrp->nat,pgrp->ind);
440   }
441   if (pgrp->nweight > 0) {
442     snew_bc(cr,pgrp->weight,pgrp->nweight);
443     nblock_bc(cr,pgrp->nweight,pgrp->weight);
444   }
445 }
446
447 static void bc_pull(const t_commrec *cr,t_pull *pull)
448 {
449   int g;
450
451   block_bc(cr,*pull);
452   snew_bc(cr,pull->grp,pull->ngrp+1);
453   for(g=0; g<pull->ngrp+1; g++)
454   {
455       bc_pullgrp(cr,&pull->grp[g]);
456   }
457 }
458
459 static void bc_rotgrp(const t_commrec *cr,t_rotgrp *rotg)
460 {
461   block_bc(cr,*rotg);
462   if (rotg->nat > 0) {
463     snew_bc(cr,rotg->ind,rotg->nat);
464     nblock_bc(cr,rotg->nat,rotg->ind);
465     snew_bc(cr,rotg->x_ref,rotg->nat);
466     nblock_bc(cr,rotg->nat,rotg->x_ref);
467   }
468 }
469
470 static void bc_rot(const t_commrec *cr,t_rot *rot)
471 {
472   int g;
473
474   block_bc(cr,*rot);
475   snew_bc(cr,rot->grp,rot->ngrp);
476   for(g=0; g<rot->ngrp; g++)
477     bc_rotgrp(cr,&rot->grp[g]);
478 }
479
480 static void bc_adress(const t_commrec *cr,t_adress *adress)
481 {
482   block_bc(cr,*adress);
483   if (adress->n_tf_grps > 0) {
484       snew_bc(cr, adress->tf_table_index, adress->n_tf_grps);
485       nblock_bc(cr, adress->n_tf_grps, adress->tf_table_index);
486   }
487   if (adress->n_energy_grps > 0) {
488       snew_bc(cr, adress->group_explicit, adress->n_energy_grps);
489       nblock_bc(cr, adress->n_energy_grps, adress->group_explicit);
490   }
491 }
492 static void bc_fepvals(const t_commrec *cr,t_lambda *fep)
493 {
494     gmx_bool bAlloc=TRUE;
495     int i;
496
497     block_bc(cr,fep->nstdhdl);
498     block_bc(cr,fep->init_lambda);
499     block_bc(cr,fep->init_fep_state);
500     block_bc(cr,fep->delta_lambda);
501     block_bc(cr,fep->bPrintEnergy);
502     block_bc(cr,fep->n_lambda);
503     snew_bc(cr,fep->all_lambda,efptNR);
504     nblock_bc(cr,efptNR,fep->all_lambda);
505     for (i=0;i<efptNR;i++) {
506         snew_bc(cr,fep->all_lambda[i],fep->n_lambda);
507         nblock_bc(cr,fep->n_lambda,fep->all_lambda[i]);
508     }
509     block_bc(cr,fep->sc_alpha);
510     block_bc(cr,fep->sc_power);
511     block_bc(cr,fep->sc_r_power);
512     block_bc(cr,fep->sc_sigma);
513     block_bc(cr,fep->sc_sigma_min);
514     block_bc(cr,fep->bScCoul);
515     nblock_bc(cr,efptNR,&(fep->separate_dvdl[0]));
516     block_bc(cr,fep->dhdl_derivatives);
517     block_bc(cr,fep->dh_hist_size);
518     block_bc(cr,fep->dh_hist_spacing);
519     if (debug)
520     {
521         fprintf(debug,"after bc_fepvals\n");
522     }
523 }
524
525 static void bc_expandedvals(const t_commrec *cr,t_expanded *expand, int n_lambda)
526 {
527     gmx_bool bAlloc=TRUE;
528     int i;
529
530     block_bc(cr,expand->nstexpanded);
531     block_bc(cr,expand->elamstats);
532     block_bc(cr,expand->elmcmove);
533     block_bc(cr,expand->elmceq);
534     block_bc(cr,expand->equil_n_at_lam);
535     block_bc(cr,expand->equil_wl_delta);
536     block_bc(cr,expand->equil_ratio);
537     block_bc(cr,expand->equil_steps);
538     block_bc(cr,expand->equil_samples);
539     block_bc(cr,expand->lmc_seed);
540     block_bc(cr,expand->minvar);
541     block_bc(cr,expand->minvar_const);
542     block_bc(cr,expand->c_range);
543     block_bc(cr,expand->bSymmetrizedTMatrix);
544     block_bc(cr,expand->nstTij);
545     block_bc(cr,expand->lmc_repeats);
546     block_bc(cr,expand->lmc_forced_nstart);
547     block_bc(cr,expand->gibbsdeltalam);
548     block_bc(cr,expand->wl_scale);
549     block_bc(cr,expand->wl_ratio);
550     block_bc(cr,expand->init_wl_delta);
551     block_bc(cr,expand->bInit_weights);
552     snew_bc(cr,expand->init_lambda_weights,n_lambda);
553     nblock_bc(cr,n_lambda,expand->init_lambda_weights);
554     block_bc(cr,expand->mc_temp);
555     if (debug)
556     {
557         fprintf(debug,"after bc_expandedvals\n");
558     }
559 }
560
561 static void bc_simtempvals(const t_commrec *cr,t_simtemp *simtemp, int n_lambda)
562 {
563     gmx_bool bAlloc=TRUE;
564     int i;
565
566     block_bc(cr,simtemp->simtemp_low);
567     block_bc(cr,simtemp->simtemp_high);
568     block_bc(cr,simtemp->eSimTempScale);
569     snew_bc(cr,simtemp->temperatures,n_lambda);
570     nblock_bc(cr,n_lambda,simtemp->temperatures);
571     if (debug)
572     {
573         fprintf(debug,"after bc_simtempvals\n");
574     }
575 }
576
577 static void bc_inputrec(const t_commrec *cr,t_inputrec *inputrec)
578 {
579   gmx_bool bAlloc=TRUE;
580   int i;
581
582   block_bc(cr,*inputrec);
583
584   bc_grpopts(cr,&(inputrec->opts));
585
586   /* even if efep is efepNO, we need to initialize to make sure that
587    * n_lambda is set to zero */
588
589   snew_bc(cr,inputrec->fepvals,1);
590   if (inputrec->efep != efepNO || inputrec->bSimTemp) 
591   {
592       bc_fepvals(cr,inputrec->fepvals);
593   }
594   /* need to initialize this as well because of data checked for in the logic */
595   snew_bc(cr,inputrec->expandedvals,1);
596   if (inputrec->bExpanded)
597   {
598       bc_expandedvals(cr,inputrec->expandedvals,inputrec->fepvals->n_lambda);
599   }
600   snew_bc(cr,inputrec->simtempvals,1);
601   if (inputrec->bSimTemp)
602   {
603       bc_simtempvals(cr,inputrec->simtempvals,inputrec->fepvals->n_lambda);
604   }
605   if (inputrec->ePull != epullNO) {
606     snew_bc(cr,inputrec->pull,1);
607     bc_pull(cr,inputrec->pull);
608   }
609   if (inputrec->bRot) {
610     snew_bc(cr,inputrec->rot,1);
611     bc_rot(cr,inputrec->rot);
612   }
613   for(i=0; (i<DIM); i++) {
614     bc_cosines(cr,&(inputrec->ex[i]));
615     bc_cosines(cr,&(inputrec->et[i]));
616   }
617   if (inputrec->bAdress) {
618       snew_bc(cr,inputrec->adress,1);
619       bc_adress(cr,inputrec->adress);
620   }
621 }
622
623 static void bc_moltype(const t_commrec *cr,t_symtab *symtab,
624                        gmx_moltype_t *moltype)
625 {
626   bc_string(cr,symtab,&moltype->name);
627   bc_atoms(cr,symtab,&moltype->atoms);
628   if (debug) fprintf(debug,"after bc_atoms\n");
629
630   bc_ilists(cr,moltype->ilist);
631   bc_block(cr,&moltype->cgs);
632   bc_blocka(cr,&moltype->excls);
633 }
634
635 static void bc_molblock(const t_commrec *cr,gmx_molblock_t *molb)
636 {
637   gmx_bool bAlloc=TRUE;
638   
639   block_bc(cr,molb->type);
640   block_bc(cr,molb->nmol);
641   block_bc(cr,molb->natoms_mol);
642   block_bc(cr,molb->nposres_xA);
643   if (molb->nposres_xA > 0) {
644     snew_bc(cr,molb->posres_xA,molb->nposres_xA);
645     nblock_bc(cr,molb->nposres_xA*DIM,molb->posres_xA[0]);
646   }
647   block_bc(cr,molb->nposres_xB);
648   if (molb->nposres_xB > 0) {
649     snew_bc(cr,molb->posres_xB,molb->nposres_xB);
650     nblock_bc(cr,molb->nposres_xB*DIM,molb->posres_xB[0]);
651   }
652   if (debug) fprintf(debug,"after bc_molblock\n");
653 }
654
655 static void bc_atomtypes(const t_commrec *cr, t_atomtypes *atomtypes)
656 {
657   int nr;
658
659   block_bc(cr,atomtypes->nr);
660
661   nr = atomtypes->nr;
662
663   snew_bc(cr,atomtypes->radius,nr);
664   snew_bc(cr,atomtypes->vol,nr);
665   snew_bc(cr,atomtypes->surftens,nr);
666   snew_bc(cr,atomtypes->gb_radius,nr);
667   snew_bc(cr,atomtypes->S_hct,nr);
668
669   nblock_bc(cr,nr,atomtypes->radius);
670   nblock_bc(cr,nr,atomtypes->vol);
671   nblock_bc(cr,nr,atomtypes->surftens);
672   nblock_bc(cr,nr,atomtypes->gb_radius);
673   nblock_bc(cr,nr,atomtypes->S_hct);
674 }
675
676
677 void bcast_ir_mtop(const t_commrec *cr,t_inputrec *inputrec,gmx_mtop_t *mtop)
678 {
679   int i; 
680   if (debug) fprintf(debug,"in bc_data\n");
681   bc_inputrec(cr,inputrec);
682   if (debug) fprintf(debug,"after bc_inputrec\n");
683   bc_symtab(cr,&mtop->symtab);
684   if (debug) fprintf(debug,"after bc_symtab\n");
685   bc_string(cr,&mtop->symtab,&mtop->name);
686   if (debug) fprintf(debug,"after bc_name\n");
687
688   bc_ffparams(cr,&mtop->ffparams);
689
690   block_bc(cr,mtop->nmoltype);
691   snew_bc(cr,mtop->moltype,mtop->nmoltype);
692   for(i=0; i<mtop->nmoltype; i++) {
693     bc_moltype(cr,&mtop->symtab,&mtop->moltype[i]);
694   }
695
696   block_bc(cr,mtop->nmolblock);
697   snew_bc(cr,mtop->molblock,mtop->nmolblock);
698   for(i=0; i<mtop->nmolblock; i++) {
699     bc_molblock(cr,&mtop->molblock[i]);
700   }
701
702   block_bc(cr,mtop->natoms);
703
704   bc_atomtypes(cr,&mtop->atomtypes);
705
706   bc_block(cr,&mtop->mols);
707   bc_groups(cr,&mtop->symtab,mtop->natoms,&mtop->groups);
708 }