2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015, 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.
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.
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.
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.
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.
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.
39 /* This file is completely threadsafe - keep it that way! */
46 #include "gromacs/fileio/confio.h"
47 #include "gromacs/fileio/filenm.h"
48 #include "gromacs/fileio/gmxfio.h"
49 #include "gromacs/fileio/gmxfio-xdr.h"
50 #include "gromacs/legacyheaders/copyrite.h"
51 #include "gromacs/legacyheaders/macros.h"
52 #include "gromacs/legacyheaders/names.h"
53 #include "gromacs/legacyheaders/txtdump.h"
54 #include "gromacs/math/vec.h"
55 #include "gromacs/topology/atomprop.h"
56 #include "gromacs/topology/block.h"
57 #include "gromacs/topology/mtop_util.h"
58 #include "gromacs/topology/symtab.h"
59 #include "gromacs/topology/topology.h"
60 #include "gromacs/utility/cstringutil.h"
61 #include "gromacs/utility/fatalerror.h"
62 #include "gromacs/utility/futil.h"
63 #include "gromacs/utility/smalloc.h"
65 #define TPX_TAG_RELEASE "release"
67 /*! \brief Tag string for the file format written to run input files
68 * written by this version of the code.
70 * Change this if you want to change the run input format in a feature
71 * branch. This ensures that there will not be different run input
72 * formats around which cannot be distinguished, while not causing
73 * problems rebasing the feature branch onto upstream changes. When
74 * merging with mainstream GROMACS, set this tag string back to
75 * TPX_TAG_RELEASE, and instead add an element to tpxv and set
76 * tpx_version to that.
78 static const char *tpx_tag = TPX_TAG_RELEASE;
80 /*! \brief Enum of values that describe the contents of a tpr file
81 * whose format matches a version number
83 * The enum helps the code be more self-documenting and ensure merges
84 * do not silently resolve when two patches make the same bump. When
85 * adding new functionality, add a new element to the end of this
86 * enumeration, change the definition of tpx_version, and write code
87 * below that does the right thing according to the value of
90 tpxv_ComputationalElectrophysiology = 96, /**< support for ion/water position swaps (computational electrophysiology) */
91 tpxv_Use64BitRandomSeed, /**< change ld_seed from int to gmx_int64_t */
92 tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, /**< potentials for supporting coarse-grained force fields */
93 tpxv_InteractiveMolecularDynamics, /**< interactive molecular dynamics (IMD) */
94 tpxv_RemoveObsoleteParameters1, /**< remove optimize_fft, dihre_fc, nstcheckpoint */
95 tpxv_PullCoordTypeGeom, /**< add pull type and geometry per group and flat-bottom */
96 tpxv_PullGeomDirRel, /**< add pull geometry direction-relative */
97 tpxv_IntermolecularBondeds /**< permit inter-molecular bonded interactions in the topology */
100 /*! \brief Version number of the file format written to run input
101 * files by this version of the code.
103 * The tpx_version number should be increased whenever the file format
104 * in the main development branch changes, generally to the highest
105 * value present in tpxv. Backward compatibility for reading old run
106 * input files is maintained by checking this version number against
107 * that of the file and then using the correct code path.
109 * When developing a feature branch that needs to change the run input
110 * file format, change tpx_tag instead. */
111 static const int tpx_version = tpxv_IntermolecularBondeds;
114 /* This number should only be increased when you edit the TOPOLOGY section
115 * or the HEADER of the tpx format.
116 * This way we can maintain forward compatibility too for all analysis tools
117 * and/or external programs that only need to know the atom/residue names,
118 * charges, and bond connectivity.
120 * It first appeared in tpx version 26, when I also moved the inputrecord
121 * to the end of the tpx file, so we can just skip it if we only
124 * In particular, it must be increased when adding new elements to
125 * ftupd, so that old code can read new .tpr files.
127 static const int tpx_generation = 26;
129 /* This number should be the most recent backwards incompatible version
130 * I.e., if this number is 9, we cannot read tpx version 9 with this code.
132 static const int tpx_incompatible_version = 9;
136 /* Struct used to maintain tpx compatibility when function types are added */
138 int fvnr; /* file version number in which the function type first appeared */
139 int ftype; /* function type */
143 * The entries should be ordered in:
144 * 1. ascending file version number
145 * 2. ascending function type number
147 /*static const t_ftupd ftupd[] = {
148 { 20, F_CUBICBONDS },
152 { 22, F_DISRESVIOL },
158 { 26, F_DIHRESVIOL },
159 { 30, F_CROSS_BOND_BONDS },
160 { 30, F_CROSS_BOND_ANGLES },
161 { 30, F_UREY_BRADLEY },
162 { 30, F_POLARIZATION },
166 * The entries should be ordered in:
167 * 1. ascending function type number
168 * 2. ascending file version number
170 /* question; what is the purpose of the commented code above? */
171 static const t_ftupd ftupd[] = {
172 { 20, F_CUBICBONDS },
177 { 43, F_TABBONDSNC },
178 { 70, F_RESTRBONDS },
179 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_RESTRANGLES },
180 { 76, F_LINEAR_ANGLES },
181 { 30, F_CROSS_BOND_BONDS },
182 { 30, F_CROSS_BOND_ANGLES },
183 { 30, F_UREY_BRADLEY },
184 { 34, F_QUARTIC_ANGLES },
186 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_RESTRDIHS },
187 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_CBTDIHS },
196 { 72, F_NPSOLVATION },
198 { 41, F_LJC_PAIRS_NB },
201 { 32, F_COUL_RECIP },
204 { 30, F_POLARIZATION },
207 { 22, F_DISRESVIOL },
211 { 26, F_DIHRESVIOL },
216 { 46, F_ECONSERVED },
217 { 69, F_VTEMP_NOLONGERUSED},
219 { 54, F_DVDL_CONSTR },
220 { 76, F_ANHARM_POL },
223 { 79, F_DVDL_BONDED, },
224 { 79, F_DVDL_RESTRAINT },
225 { 79, F_DVDL_TEMPERATURE },
227 #define NFTUPD asize(ftupd)
229 /* Needed for backward compatibility */
232 /**************************************************************
234 * Now the higer level routines that do io of the structures and arrays
236 **************************************************************/
237 static void do_pullgrp_tpx_pre95(t_fileio *fio,
246 gmx_fio_do_int(fio, pgrp->nat);
249 snew(pgrp->ind, pgrp->nat);
251 gmx_fio_ndo_int(fio, pgrp->ind, pgrp->nat);
252 gmx_fio_do_int(fio, pgrp->nweight);
255 snew(pgrp->weight, pgrp->nweight);
257 gmx_fio_ndo_real(fio, pgrp->weight, pgrp->nweight);
258 gmx_fio_do_int(fio, pgrp->pbcatom);
259 gmx_fio_do_rvec(fio, pcrd->vec);
260 clear_rvec(pcrd->origin);
261 gmx_fio_do_rvec(fio, tmp);
263 gmx_fio_do_real(fio, pcrd->rate);
264 gmx_fio_do_real(fio, pcrd->k);
265 if (file_version >= 56)
267 gmx_fio_do_real(fio, pcrd->kB);
275 static void do_pull_group(t_fileio *fio, t_pull_group *pgrp, gmx_bool bRead)
279 gmx_fio_do_int(fio, pgrp->nat);
282 snew(pgrp->ind, pgrp->nat);
284 gmx_fio_ndo_int(fio, pgrp->ind, pgrp->nat);
285 gmx_fio_do_int(fio, pgrp->nweight);
288 snew(pgrp->weight, pgrp->nweight);
290 gmx_fio_ndo_real(fio, pgrp->weight, pgrp->nweight);
291 gmx_fio_do_int(fio, pgrp->pbcatom);
294 static void do_pull_coord(t_fileio *fio, t_pull_coord *pcrd, int file_version,
295 int ePullOld, int eGeomOld, ivec dimOld)
299 gmx_fio_do_int(fio, pcrd->group[0]);
300 gmx_fio_do_int(fio, pcrd->group[1]);
301 if (file_version >= tpxv_PullCoordTypeGeom)
303 gmx_fio_do_int(fio, pcrd->eType);
304 gmx_fio_do_int(fio, pcrd->eGeom);
305 if (pcrd->eGeom == epullgDIRRELATIVE)
307 gmx_fio_do_int(fio, pcrd->group[2]);
308 gmx_fio_do_int(fio, pcrd->group[3]);
310 gmx_fio_do_ivec(fio, pcrd->dim);
314 pcrd->eType = ePullOld;
315 pcrd->eGeom = eGeomOld;
316 copy_ivec(dimOld, pcrd->dim);
318 gmx_fio_do_rvec(fio, pcrd->origin);
319 gmx_fio_do_rvec(fio, pcrd->vec);
320 if (file_version >= tpxv_PullCoordTypeGeom)
322 gmx_fio_do_gmx_bool(fio, pcrd->bStart);
326 /* This parameter is only printed, but not actually used by mdrun */
327 pcrd->bStart = FALSE;
329 gmx_fio_do_real(fio, pcrd->init);
330 gmx_fio_do_real(fio, pcrd->rate);
331 gmx_fio_do_real(fio, pcrd->k);
332 gmx_fio_do_real(fio, pcrd->kB);
335 static void do_expandedvals(t_fileio *fio, t_expanded *expand, t_lambda *fepvals, gmx_bool bRead, int file_version)
337 /* i is used in the ndo_double macro*/
341 int n_lambda = fepvals->n_lambda;
343 /* reset the lambda calculation window */
344 fepvals->lambda_start_n = 0;
345 fepvals->lambda_stop_n = n_lambda;
346 if (file_version >= 79)
352 snew(expand->init_lambda_weights, n_lambda);
354 gmx_fio_ndo_real(fio, expand->init_lambda_weights, n_lambda);
355 gmx_fio_do_gmx_bool(fio, expand->bInit_weights);
358 gmx_fio_do_int(fio, expand->nstexpanded);
359 gmx_fio_do_int(fio, expand->elmcmove);
360 gmx_fio_do_int(fio, expand->elamstats);
361 gmx_fio_do_int(fio, expand->lmc_repeats);
362 gmx_fio_do_int(fio, expand->gibbsdeltalam);
363 gmx_fio_do_int(fio, expand->lmc_forced_nstart);
364 gmx_fio_do_int(fio, expand->lmc_seed);
365 gmx_fio_do_real(fio, expand->mc_temp);
366 gmx_fio_do_int(fio, expand->bSymmetrizedTMatrix);
367 gmx_fio_do_int(fio, expand->nstTij);
368 gmx_fio_do_int(fio, expand->minvarmin);
369 gmx_fio_do_int(fio, expand->c_range);
370 gmx_fio_do_real(fio, expand->wl_scale);
371 gmx_fio_do_real(fio, expand->wl_ratio);
372 gmx_fio_do_real(fio, expand->init_wl_delta);
373 gmx_fio_do_gmx_bool(fio, expand->bWLoneovert);
374 gmx_fio_do_int(fio, expand->elmceq);
375 gmx_fio_do_int(fio, expand->equil_steps);
376 gmx_fio_do_int(fio, expand->equil_samples);
377 gmx_fio_do_int(fio, expand->equil_n_at_lam);
378 gmx_fio_do_real(fio, expand->equil_wl_delta);
379 gmx_fio_do_real(fio, expand->equil_ratio);
383 static void do_simtempvals(t_fileio *fio, t_simtemp *simtemp, int n_lambda, gmx_bool bRead,
386 if (file_version >= 79)
388 gmx_fio_do_int(fio, simtemp->eSimTempScale);
389 gmx_fio_do_real(fio, simtemp->simtemp_high);
390 gmx_fio_do_real(fio, simtemp->simtemp_low);
395 snew(simtemp->temperatures, n_lambda);
397 gmx_fio_ndo_real(fio, simtemp->temperatures, n_lambda);
402 static void do_imd(t_fileio *fio, t_IMD *imd, gmx_bool bRead)
404 gmx_fio_do_int(fio, imd->nat);
407 snew(imd->ind, imd->nat);
409 gmx_fio_ndo_int(fio, imd->ind, imd->nat);
412 static void do_fepvals(t_fileio *fio, t_lambda *fepvals, gmx_bool bRead, int file_version)
414 /* i is defined in the ndo_double macro; use g to iterate. */
419 /* free energy values */
421 if (file_version >= 79)
423 gmx_fio_do_int(fio, fepvals->init_fep_state);
424 gmx_fio_do_double(fio, fepvals->init_lambda);
425 gmx_fio_do_double(fio, fepvals->delta_lambda);
427 else if (file_version >= 59)
429 gmx_fio_do_double(fio, fepvals->init_lambda);
430 gmx_fio_do_double(fio, fepvals->delta_lambda);
434 gmx_fio_do_real(fio, rdum);
435 fepvals->init_lambda = rdum;
436 gmx_fio_do_real(fio, rdum);
437 fepvals->delta_lambda = rdum;
439 if (file_version >= 79)
441 gmx_fio_do_int(fio, fepvals->n_lambda);
444 snew(fepvals->all_lambda, efptNR);
446 for (g = 0; g < efptNR; g++)
448 if (fepvals->n_lambda > 0)
452 snew(fepvals->all_lambda[g], fepvals->n_lambda);
454 gmx_fio_ndo_double(fio, fepvals->all_lambda[g], fepvals->n_lambda);
455 gmx_fio_ndo_int(fio, fepvals->separate_dvdl, efptNR);
457 else if (fepvals->init_lambda >= 0)
459 fepvals->separate_dvdl[efptFEP] = TRUE;
463 else if (file_version >= 64)
465 gmx_fio_do_int(fio, fepvals->n_lambda);
470 snew(fepvals->all_lambda, efptNR);
471 /* still allocate the all_lambda array's contents. */
472 for (g = 0; g < efptNR; g++)
474 if (fepvals->n_lambda > 0)
476 snew(fepvals->all_lambda[g], fepvals->n_lambda);
480 gmx_fio_ndo_double(fio, fepvals->all_lambda[efptFEP],
482 if (fepvals->init_lambda >= 0)
486 fepvals->separate_dvdl[efptFEP] = TRUE;
490 /* copy the contents of the efptFEP lambda component to all
491 the other components */
492 for (g = 0; g < efptNR; g++)
494 for (h = 0; h < fepvals->n_lambda; h++)
498 fepvals->all_lambda[g][h] =
499 fepvals->all_lambda[efptFEP][h];
508 fepvals->n_lambda = 0;
509 fepvals->all_lambda = NULL;
510 if (fepvals->init_lambda >= 0)
512 fepvals->separate_dvdl[efptFEP] = TRUE;
515 if (file_version >= 13)
517 gmx_fio_do_real(fio, fepvals->sc_alpha);
521 fepvals->sc_alpha = 0;
523 if (file_version >= 38)
525 gmx_fio_do_int(fio, fepvals->sc_power);
529 fepvals->sc_power = 2;
531 if (file_version >= 79)
533 gmx_fio_do_real(fio, fepvals->sc_r_power);
537 fepvals->sc_r_power = 6.0;
539 if (file_version >= 15)
541 gmx_fio_do_real(fio, fepvals->sc_sigma);
545 fepvals->sc_sigma = 0.3;
549 if (file_version >= 71)
551 fepvals->sc_sigma_min = fepvals->sc_sigma;
555 fepvals->sc_sigma_min = 0;
558 if (file_version >= 79)
560 gmx_fio_do_int(fio, fepvals->bScCoul);
564 fepvals->bScCoul = TRUE;
566 if (file_version >= 64)
568 gmx_fio_do_int(fio, fepvals->nstdhdl);
572 fepvals->nstdhdl = 1;
575 if (file_version >= 73)
577 gmx_fio_do_int(fio, fepvals->separate_dhdl_file);
578 gmx_fio_do_int(fio, fepvals->dhdl_derivatives);
582 fepvals->separate_dhdl_file = esepdhdlfileYES;
583 fepvals->dhdl_derivatives = edhdlderivativesYES;
585 if (file_version >= 71)
587 gmx_fio_do_int(fio, fepvals->dh_hist_size);
588 gmx_fio_do_double(fio, fepvals->dh_hist_spacing);
592 fepvals->dh_hist_size = 0;
593 fepvals->dh_hist_spacing = 0.1;
595 if (file_version >= 79)
597 gmx_fio_do_int(fio, fepvals->edHdLPrintEnergy);
601 fepvals->edHdLPrintEnergy = edHdLPrintEnergyNO;
604 /* handle lambda_neighbors */
605 if ((file_version >= 83 && file_version < 90) || file_version >= 92)
607 gmx_fio_do_int(fio, fepvals->lambda_neighbors);
608 if ( (fepvals->lambda_neighbors >= 0) && (fepvals->init_fep_state >= 0) &&
609 (fepvals->init_lambda < 0) )
611 fepvals->lambda_start_n = (fepvals->init_fep_state -
612 fepvals->lambda_neighbors);
613 fepvals->lambda_stop_n = (fepvals->init_fep_state +
614 fepvals->lambda_neighbors + 1);
615 if (fepvals->lambda_start_n < 0)
617 fepvals->lambda_start_n = 0;;
619 if (fepvals->lambda_stop_n >= fepvals->n_lambda)
621 fepvals->lambda_stop_n = fepvals->n_lambda;
626 fepvals->lambda_start_n = 0;
627 fepvals->lambda_stop_n = fepvals->n_lambda;
632 fepvals->lambda_start_n = 0;
633 fepvals->lambda_stop_n = fepvals->n_lambda;
637 static void do_pull(t_fileio *fio, pull_params_t *pull, gmx_bool bRead,
638 int file_version, int ePullOld)
644 if (file_version >= 95)
646 gmx_fio_do_int(fio, pull->ngroup);
648 gmx_fio_do_int(fio, pull->ncoord);
649 if (file_version < 95)
651 pull->ngroup = pull->ncoord + 1;
653 if (file_version < tpxv_PullCoordTypeGeom)
657 gmx_fio_do_int(fio, eGeomOld);
658 gmx_fio_do_ivec(fio, dimOld);
659 /* The inner cylinder radius, now removed */
660 gmx_fio_do_real(fio, dum);
662 gmx_fio_do_real(fio, pull->cylinder_r);
663 gmx_fio_do_real(fio, pull->constr_tol);
664 if (file_version >= 95)
666 gmx_fio_do_int(fio, pull->bPrintCOM1);
667 /* With file_version < 95 this value is set below */
669 if (file_version >= tpxv_PullCoordTypeGeom)
671 gmx_fio_do_int(fio, pull->bPrintCOM2);
672 gmx_fio_do_int(fio, pull->bPrintRefValue);
673 gmx_fio_do_int(fio, pull->bPrintComp);
677 pull->bPrintCOM2 = FALSE;
678 pull->bPrintRefValue = FALSE;
679 pull->bPrintComp = TRUE;
681 gmx_fio_do_int(fio, pull->nstxout);
682 gmx_fio_do_int(fio, pull->nstfout);
685 snew(pull->group, pull->ngroup);
686 snew(pull->coord, pull->ncoord);
688 if (file_version < 95)
690 /* epullgPOS for position pulling, before epullgDIRPBC was removed */
691 if (eGeomOld == epullgDIRPBC)
693 gmx_fatal(FARGS, "pull-geometry=position is no longer supported");
695 if (eGeomOld > epullgDIRPBC)
700 for (g = 0; g < pull->ngroup; g++)
702 /* We read and ignore a pull coordinate for group 0 */
703 do_pullgrp_tpx_pre95(fio, &pull->group[g], &pull->coord[max(g-1, 0)],
704 bRead, file_version);
707 pull->coord[g-1].group[0] = 0;
708 pull->coord[g-1].group[1] = g;
712 pull->bPrintCOM1 = (pull->group[0].nat > 0);
716 for (g = 0; g < pull->ngroup; g++)
718 do_pull_group(fio, &pull->group[g], bRead);
720 for (g = 0; g < pull->ncoord; g++)
722 do_pull_coord(fio, &pull->coord[g],
723 file_version, ePullOld, eGeomOld, dimOld);
729 static void do_rotgrp(t_fileio *fio, t_rotgrp *rotg, gmx_bool bRead)
733 gmx_fio_do_int(fio, rotg->eType);
734 gmx_fio_do_int(fio, rotg->bMassW);
735 gmx_fio_do_int(fio, rotg->nat);
738 snew(rotg->ind, rotg->nat);
740 gmx_fio_ndo_int(fio, rotg->ind, rotg->nat);
743 snew(rotg->x_ref, rotg->nat);
745 gmx_fio_ndo_rvec(fio, rotg->x_ref, rotg->nat);
746 gmx_fio_do_rvec(fio, rotg->vec);
747 gmx_fio_do_rvec(fio, rotg->pivot);
748 gmx_fio_do_real(fio, rotg->rate);
749 gmx_fio_do_real(fio, rotg->k);
750 gmx_fio_do_real(fio, rotg->slab_dist);
751 gmx_fio_do_real(fio, rotg->min_gaussian);
752 gmx_fio_do_real(fio, rotg->eps);
753 gmx_fio_do_int(fio, rotg->eFittype);
754 gmx_fio_do_int(fio, rotg->PotAngle_nstep);
755 gmx_fio_do_real(fio, rotg->PotAngle_step);
758 static void do_rot(t_fileio *fio, t_rot *rot, gmx_bool bRead)
762 gmx_fio_do_int(fio, rot->ngrp);
763 gmx_fio_do_int(fio, rot->nstrout);
764 gmx_fio_do_int(fio, rot->nstsout);
767 snew(rot->grp, rot->ngrp);
769 for (g = 0; g < rot->ngrp; g++)
771 do_rotgrp(fio, &rot->grp[g], bRead);
776 static void do_swapcoords(t_fileio *fio, t_swapcoords *swap, gmx_bool bRead)
781 gmx_fio_do_int(fio, swap->nat);
782 gmx_fio_do_int(fio, swap->nat_sol);
783 for (j = 0; j < 2; j++)
785 gmx_fio_do_int(fio, swap->nat_split[j]);
786 gmx_fio_do_int(fio, swap->massw_split[j]);
788 gmx_fio_do_int(fio, swap->nstswap);
789 gmx_fio_do_int(fio, swap->nAverage);
790 gmx_fio_do_real(fio, swap->threshold);
791 gmx_fio_do_real(fio, swap->cyl0r);
792 gmx_fio_do_real(fio, swap->cyl0u);
793 gmx_fio_do_real(fio, swap->cyl0l);
794 gmx_fio_do_real(fio, swap->cyl1r);
795 gmx_fio_do_real(fio, swap->cyl1u);
796 gmx_fio_do_real(fio, swap->cyl1l);
800 snew(swap->ind, swap->nat);
801 snew(swap->ind_sol, swap->nat_sol);
802 for (j = 0; j < 2; j++)
804 snew(swap->ind_split[j], swap->nat_split[j]);
808 gmx_fio_ndo_int(fio, swap->ind, swap->nat);
809 gmx_fio_ndo_int(fio, swap->ind_sol, swap->nat_sol);
810 for (j = 0; j < 2; j++)
812 gmx_fio_ndo_int(fio, swap->ind_split[j], swap->nat_split[j]);
815 for (j = 0; j < eCompNR; j++)
817 gmx_fio_do_int(fio, swap->nanions[j]);
818 gmx_fio_do_int(fio, swap->ncations[j]);
824 static void do_inputrec(t_fileio *fio, t_inputrec *ir, gmx_bool bRead,
825 int file_version, real *fudgeQQ)
827 int i, j, k, *tmp, idum = 0;
830 gmx_bool bSimAnn, bdum = 0;
831 real zerotemptime, finish_t, init_temp, finish_temp;
833 if (file_version != tpx_version)
835 /* Give a warning about features that are not accessible */
836 fprintf(stderr, "Note: file tpx version %d, software tpx version %d\n",
837 file_version, tpx_version);
845 if (file_version == 0)
850 /* Basic inputrec stuff */
851 gmx_fio_do_int(fio, ir->eI);
852 if (file_version >= 62)
854 gmx_fio_do_int64(fio, ir->nsteps);
858 gmx_fio_do_int(fio, idum);
862 if (file_version > 25)
864 if (file_version >= 62)
866 gmx_fio_do_int64(fio, ir->init_step);
870 gmx_fio_do_int(fio, idum);
871 ir->init_step = idum;
879 if (file_version >= 58)
881 gmx_fio_do_int(fio, ir->simulation_part);
885 ir->simulation_part = 1;
888 if (file_version >= 67)
890 gmx_fio_do_int(fio, ir->nstcalcenergy);
894 ir->nstcalcenergy = 1;
896 if (file_version < 53)
898 /* The pbc info has been moved out of do_inputrec,
899 * since we always want it, also without reading the inputrec.
901 gmx_fio_do_int(fio, ir->ePBC);
902 if ((file_version <= 15) && (ir->ePBC == 2))
906 if (file_version >= 45)
908 gmx_fio_do_int(fio, ir->bPeriodicMols);
915 ir->bPeriodicMols = TRUE;
919 ir->bPeriodicMols = FALSE;
923 if (file_version >= 81)
925 gmx_fio_do_int(fio, ir->cutoff_scheme);
926 if (file_version < 94)
928 ir->cutoff_scheme = 1 - ir->cutoff_scheme;
933 ir->cutoff_scheme = ecutsGROUP;
935 gmx_fio_do_int(fio, ir->ns_type);
936 gmx_fio_do_int(fio, ir->nstlist);
937 gmx_fio_do_int(fio, idum); /* used to be ndelta; not used anymore */
938 if (file_version < 41)
940 gmx_fio_do_int(fio, idum);
941 gmx_fio_do_int(fio, idum);
943 if (file_version >= 45)
945 gmx_fio_do_real(fio, ir->rtpi);
951 gmx_fio_do_int(fio, ir->nstcomm);
952 if (file_version > 34)
954 gmx_fio_do_int(fio, ir->comm_mode);
956 else if (ir->nstcomm < 0)
958 ir->comm_mode = ecmANGULAR;
962 ir->comm_mode = ecmLINEAR;
964 ir->nstcomm = abs(ir->nstcomm);
966 /* ignore nstcheckpoint */
967 if (file_version > 25 && file_version < tpxv_RemoveObsoleteParameters1)
969 gmx_fio_do_int(fio, idum);
972 gmx_fio_do_int(fio, ir->nstcgsteep);
974 if (file_version >= 30)
976 gmx_fio_do_int(fio, ir->nbfgscorr);
983 gmx_fio_do_int(fio, ir->nstlog);
984 gmx_fio_do_int(fio, ir->nstxout);
985 gmx_fio_do_int(fio, ir->nstvout);
986 gmx_fio_do_int(fio, ir->nstfout);
987 gmx_fio_do_int(fio, ir->nstenergy);
988 gmx_fio_do_int(fio, ir->nstxout_compressed);
989 if (file_version >= 59)
991 gmx_fio_do_double(fio, ir->init_t);
992 gmx_fio_do_double(fio, ir->delta_t);
996 gmx_fio_do_real(fio, rdum);
998 gmx_fio_do_real(fio, rdum);
1001 gmx_fio_do_real(fio, ir->x_compression_precision);
1002 if (file_version < 19)
1004 gmx_fio_do_int(fio, idum);
1005 gmx_fio_do_int(fio, idum);
1007 if (file_version < 18)
1009 gmx_fio_do_int(fio, idum);
1011 if (file_version >= 81)
1013 gmx_fio_do_real(fio, ir->verletbuf_tol);
1017 ir->verletbuf_tol = 0;
1019 gmx_fio_do_real(fio, ir->rlist);
1020 if (file_version >= 67)
1022 gmx_fio_do_real(fio, ir->rlistlong);
1024 if (file_version >= 82 && file_version != 90)
1026 gmx_fio_do_int(fio, ir->nstcalclr);
1030 /* Calculate at NS steps */
1031 ir->nstcalclr = ir->nstlist;
1033 gmx_fio_do_int(fio, ir->coulombtype);
1034 if (file_version < 32 && ir->coulombtype == eelRF)
1036 ir->coulombtype = eelRF_NEC;
1038 if (file_version >= 81)
1040 gmx_fio_do_int(fio, ir->coulomb_modifier);
1044 ir->coulomb_modifier = (ir->cutoff_scheme == ecutsVERLET ? eintmodPOTSHIFT : eintmodNONE);
1046 gmx_fio_do_real(fio, ir->rcoulomb_switch);
1047 gmx_fio_do_real(fio, ir->rcoulomb);
1048 gmx_fio_do_int(fio, ir->vdwtype);
1049 if (file_version >= 81)
1051 gmx_fio_do_int(fio, ir->vdw_modifier);
1055 ir->vdw_modifier = (ir->cutoff_scheme == ecutsVERLET ? eintmodPOTSHIFT : eintmodNONE);
1057 gmx_fio_do_real(fio, ir->rvdw_switch);
1058 gmx_fio_do_real(fio, ir->rvdw);
1059 if (file_version < 67)
1061 ir->rlistlong = max_cutoff(ir->rlist, max_cutoff(ir->rvdw, ir->rcoulomb));
1063 gmx_fio_do_int(fio, ir->eDispCorr);
1064 gmx_fio_do_real(fio, ir->epsilon_r);
1065 if (file_version >= 37)
1067 gmx_fio_do_real(fio, ir->epsilon_rf);
1071 if (EEL_RF(ir->coulombtype))
1073 ir->epsilon_rf = ir->epsilon_r;
1074 ir->epsilon_r = 1.0;
1078 ir->epsilon_rf = 1.0;
1081 if (file_version >= 29)
1083 gmx_fio_do_real(fio, ir->tabext);
1090 if (file_version > 25)
1092 gmx_fio_do_int(fio, ir->gb_algorithm);
1093 gmx_fio_do_int(fio, ir->nstgbradii);
1094 gmx_fio_do_real(fio, ir->rgbradii);
1095 gmx_fio_do_real(fio, ir->gb_saltconc);
1096 gmx_fio_do_int(fio, ir->implicit_solvent);
1100 ir->gb_algorithm = egbSTILL;
1103 ir->gb_saltconc = 0;
1104 ir->implicit_solvent = eisNO;
1106 if (file_version >= 55)
1108 gmx_fio_do_real(fio, ir->gb_epsilon_solvent);
1109 gmx_fio_do_real(fio, ir->gb_obc_alpha);
1110 gmx_fio_do_real(fio, ir->gb_obc_beta);
1111 gmx_fio_do_real(fio, ir->gb_obc_gamma);
1112 if (file_version >= 60)
1114 gmx_fio_do_real(fio, ir->gb_dielectric_offset);
1115 gmx_fio_do_int(fio, ir->sa_algorithm);
1119 ir->gb_dielectric_offset = 0.009;
1120 ir->sa_algorithm = esaAPPROX;
1122 gmx_fio_do_real(fio, ir->sa_surface_tension);
1124 /* Override sa_surface_tension if it is not changed in the mpd-file */
1125 if (ir->sa_surface_tension < 0)
1127 if (ir->gb_algorithm == egbSTILL)
1129 ir->sa_surface_tension = 0.0049 * 100 * CAL2JOULE;
1131 else if (ir->gb_algorithm == egbHCT || ir->gb_algorithm == egbOBC)
1133 ir->sa_surface_tension = 0.0054 * 100 * CAL2JOULE;
1140 /* Better use sensible values than insane (0.0) ones... */
1141 ir->gb_epsilon_solvent = 80;
1142 ir->gb_obc_alpha = 1.0;
1143 ir->gb_obc_beta = 0.8;
1144 ir->gb_obc_gamma = 4.85;
1145 ir->sa_surface_tension = 2.092;
1149 if (file_version >= 81)
1151 gmx_fio_do_real(fio, ir->fourier_spacing);
1155 ir->fourier_spacing = 0.0;
1157 gmx_fio_do_int(fio, ir->nkx);
1158 gmx_fio_do_int(fio, ir->nky);
1159 gmx_fio_do_int(fio, ir->nkz);
1160 gmx_fio_do_int(fio, ir->pme_order);
1161 gmx_fio_do_real(fio, ir->ewald_rtol);
1163 if (file_version >= 93)
1165 gmx_fio_do_real(fio, ir->ewald_rtol_lj);
1169 ir->ewald_rtol_lj = ir->ewald_rtol;
1172 if (file_version >= 24)
1174 gmx_fio_do_int(fio, ir->ewald_geometry);
1178 ir->ewald_geometry = eewg3D;
1181 if (file_version <= 17)
1183 ir->epsilon_surface = 0;
1184 if (file_version == 17)
1186 gmx_fio_do_int(fio, idum);
1191 gmx_fio_do_real(fio, ir->epsilon_surface);
1194 /* ignore bOptFFT */
1195 if (file_version < tpxv_RemoveObsoleteParameters1)
1197 gmx_fio_do_gmx_bool(fio, bdum);
1200 if (file_version >= 93)
1202 gmx_fio_do_int(fio, ir->ljpme_combination_rule);
1204 gmx_fio_do_gmx_bool(fio, ir->bContinuation);
1205 gmx_fio_do_int(fio, ir->etc);
1206 /* before version 18, ir->etc was a gmx_bool (ir->btc),
1207 * but the values 0 and 1 still mean no and
1208 * berendsen temperature coupling, respectively.
1210 if (file_version >= 79)
1212 gmx_fio_do_gmx_bool(fio, ir->bPrintNHChains);
1214 if (file_version >= 71)
1216 gmx_fio_do_int(fio, ir->nsttcouple);
1220 ir->nsttcouple = ir->nstcalcenergy;
1222 if (file_version <= 15)
1224 gmx_fio_do_int(fio, idum);
1226 if (file_version <= 17)
1228 gmx_fio_do_int(fio, ir->epct);
1229 if (file_version <= 15)
1233 ir->epct = epctSURFACETENSION;
1235 gmx_fio_do_int(fio, idum);
1238 /* we have removed the NO alternative at the beginning */
1242 ir->epct = epctISOTROPIC;
1246 ir->epc = epcBERENDSEN;
1251 gmx_fio_do_int(fio, ir->epc);
1252 gmx_fio_do_int(fio, ir->epct);
1254 if (file_version >= 71)
1256 gmx_fio_do_int(fio, ir->nstpcouple);
1260 ir->nstpcouple = ir->nstcalcenergy;
1262 gmx_fio_do_real(fio, ir->tau_p);
1263 if (file_version <= 15)
1265 gmx_fio_do_rvec(fio, vdum);
1266 clear_mat(ir->ref_p);
1267 for (i = 0; i < DIM; i++)
1269 ir->ref_p[i][i] = vdum[i];
1274 gmx_fio_do_rvec(fio, ir->ref_p[XX]);
1275 gmx_fio_do_rvec(fio, ir->ref_p[YY]);
1276 gmx_fio_do_rvec(fio, ir->ref_p[ZZ]);
1278 if (file_version <= 15)
1280 gmx_fio_do_rvec(fio, vdum);
1281 clear_mat(ir->compress);
1282 for (i = 0; i < DIM; i++)
1284 ir->compress[i][i] = vdum[i];
1289 gmx_fio_do_rvec(fio, ir->compress[XX]);
1290 gmx_fio_do_rvec(fio, ir->compress[YY]);
1291 gmx_fio_do_rvec(fio, ir->compress[ZZ]);
1293 if (file_version >= 47)
1295 gmx_fio_do_int(fio, ir->refcoord_scaling);
1296 gmx_fio_do_rvec(fio, ir->posres_com);
1297 gmx_fio_do_rvec(fio, ir->posres_comB);
1301 ir->refcoord_scaling = erscNO;
1302 clear_rvec(ir->posres_com);
1303 clear_rvec(ir->posres_comB);
1305 if ((file_version > 25) && (file_version < 79))
1307 gmx_fio_do_int(fio, ir->andersen_seed);
1311 ir->andersen_seed = 0;
1313 if (file_version < 26)
1315 gmx_fio_do_gmx_bool(fio, bSimAnn);
1316 gmx_fio_do_real(fio, zerotemptime);
1319 if (file_version < 37)
1321 gmx_fio_do_real(fio, rdum);
1324 gmx_fio_do_real(fio, ir->shake_tol);
1325 if (file_version < 54)
1327 gmx_fio_do_real(fio, *fudgeQQ);
1330 gmx_fio_do_int(fio, ir->efep);
1331 if (file_version <= 14 && ir->efep != efepNO)
1335 do_fepvals(fio, ir->fepvals, bRead, file_version);
1337 if (file_version >= 79)
1339 gmx_fio_do_gmx_bool(fio, ir->bSimTemp);
1342 ir->bSimTemp = TRUE;
1347 ir->bSimTemp = FALSE;
1351 do_simtempvals(fio, ir->simtempvals, ir->fepvals->n_lambda, bRead, file_version);
1354 if (file_version >= 79)
1356 gmx_fio_do_gmx_bool(fio, ir->bExpanded);
1359 ir->bExpanded = TRUE;
1363 ir->bExpanded = FALSE;
1368 do_expandedvals(fio, ir->expandedvals, ir->fepvals, bRead, file_version);
1370 if (file_version >= 57)
1372 gmx_fio_do_int(fio, ir->eDisre);
1374 gmx_fio_do_int(fio, ir->eDisreWeighting);
1375 if (file_version < 22)
1377 if (ir->eDisreWeighting == 0)
1379 ir->eDisreWeighting = edrwEqual;
1383 ir->eDisreWeighting = edrwConservative;
1386 gmx_fio_do_gmx_bool(fio, ir->bDisreMixed);
1387 gmx_fio_do_real(fio, ir->dr_fc);
1388 gmx_fio_do_real(fio, ir->dr_tau);
1389 gmx_fio_do_int(fio, ir->nstdisreout);
1390 if (file_version >= 22)
1392 gmx_fio_do_real(fio, ir->orires_fc);
1393 gmx_fio_do_real(fio, ir->orires_tau);
1394 gmx_fio_do_int(fio, ir->nstorireout);
1400 ir->nstorireout = 0;
1403 /* ignore dihre_fc */
1404 if (file_version >= 26 && file_version < 79)
1406 gmx_fio_do_real(fio, rdum);
1407 if (file_version < 56)
1409 gmx_fio_do_real(fio, rdum);
1410 gmx_fio_do_int(fio, idum);
1414 gmx_fio_do_real(fio, ir->em_stepsize);
1415 gmx_fio_do_real(fio, ir->em_tol);
1416 if (file_version >= 22)
1418 gmx_fio_do_gmx_bool(fio, ir->bShakeSOR);
1422 ir->bShakeSOR = TRUE;
1424 if (file_version >= 11)
1426 gmx_fio_do_int(fio, ir->niter);
1431 fprintf(stderr, "Note: niter not in run input file, setting it to %d\n",
1434 if (file_version >= 21)
1436 gmx_fio_do_real(fio, ir->fc_stepsize);
1440 ir->fc_stepsize = 0;
1442 gmx_fio_do_int(fio, ir->eConstrAlg);
1443 gmx_fio_do_int(fio, ir->nProjOrder);
1444 gmx_fio_do_real(fio, ir->LincsWarnAngle);
1445 if (file_version <= 14)
1447 gmx_fio_do_int(fio, idum);
1449 if (file_version >= 26)
1451 gmx_fio_do_int(fio, ir->nLincsIter);
1456 fprintf(stderr, "Note: nLincsIter not in run input file, setting it to %d\n",
1459 if (file_version < 33)
1461 gmx_fio_do_real(fio, bd_temp);
1463 gmx_fio_do_real(fio, ir->bd_fric);
1464 if (file_version >= tpxv_Use64BitRandomSeed)
1466 gmx_fio_do_int64(fio, ir->ld_seed);
1470 gmx_fio_do_int(fio, idum);
1473 if (file_version >= 33)
1475 for (i = 0; i < DIM; i++)
1477 gmx_fio_do_rvec(fio, ir->deform[i]);
1482 for (i = 0; i < DIM; i++)
1484 clear_rvec(ir->deform[i]);
1487 if (file_version >= 14)
1489 gmx_fio_do_real(fio, ir->cos_accel);
1495 gmx_fio_do_int(fio, ir->userint1);
1496 gmx_fio_do_int(fio, ir->userint2);
1497 gmx_fio_do_int(fio, ir->userint3);
1498 gmx_fio_do_int(fio, ir->userint4);
1499 gmx_fio_do_real(fio, ir->userreal1);
1500 gmx_fio_do_real(fio, ir->userreal2);
1501 gmx_fio_do_real(fio, ir->userreal3);
1502 gmx_fio_do_real(fio, ir->userreal4);
1505 if (file_version >= 77)
1507 gmx_fio_do_gmx_bool(fio, ir->bAdress);
1512 snew(ir->adress, 1);
1514 gmx_fio_do_int(fio, ir->adress->type);
1515 gmx_fio_do_real(fio, ir->adress->const_wf);
1516 gmx_fio_do_real(fio, ir->adress->ex_width);
1517 gmx_fio_do_real(fio, ir->adress->hy_width);
1518 gmx_fio_do_int(fio, ir->adress->icor);
1519 gmx_fio_do_int(fio, ir->adress->site);
1520 gmx_fio_do_rvec(fio, ir->adress->refs);
1521 gmx_fio_do_int(fio, ir->adress->n_tf_grps);
1522 gmx_fio_do_real(fio, ir->adress->ex_forcecap);
1523 gmx_fio_do_int(fio, ir->adress->n_energy_grps);
1524 gmx_fio_do_int(fio, ir->adress->do_hybridpairs);
1528 snew(ir->adress->tf_table_index, ir->adress->n_tf_grps);
1530 if (ir->adress->n_tf_grps > 0)
1532 gmx_fio_ndo_int(fio, ir->adress->tf_table_index, ir->adress->n_tf_grps);
1536 snew(ir->adress->group_explicit, ir->adress->n_energy_grps);
1538 if (ir->adress->n_energy_grps > 0)
1540 gmx_fio_ndo_int(fio, ir->adress->group_explicit, ir->adress->n_energy_grps);
1546 ir->bAdress = FALSE;
1550 if (file_version >= 48)
1554 if (file_version >= tpxv_PullCoordTypeGeom)
1556 gmx_fio_do_gmx_bool(fio, ir->bPull);
1560 gmx_fio_do_int(fio, ePullOld);
1561 ir->bPull = (ePullOld > 0);
1562 /* We removed the first ePull=ePullNo for the enum */
1571 do_pull(fio, ir->pull, bRead, file_version, ePullOld);
1579 /* Enforced rotation */
1580 if (file_version >= 74)
1582 gmx_fio_do_int(fio, ir->bRot);
1583 if (ir->bRot == TRUE)
1589 do_rot(fio, ir->rot, bRead);
1597 /* Interactive molecular dynamics */
1598 if (file_version >= tpxv_InteractiveMolecularDynamics)
1600 gmx_fio_do_int(fio, ir->bIMD);
1601 if (TRUE == ir->bIMD)
1607 do_imd(fio, ir->imd, bRead);
1612 /* We don't support IMD sessions for old .tpr files */
1617 gmx_fio_do_int(fio, ir->opts.ngtc);
1618 if (file_version >= 69)
1620 gmx_fio_do_int(fio, ir->opts.nhchainlength);
1624 ir->opts.nhchainlength = 1;
1626 gmx_fio_do_int(fio, ir->opts.ngacc);
1627 gmx_fio_do_int(fio, ir->opts.ngfrz);
1628 gmx_fio_do_int(fio, ir->opts.ngener);
1632 snew(ir->opts.nrdf, ir->opts.ngtc);
1633 snew(ir->opts.ref_t, ir->opts.ngtc);
1634 snew(ir->opts.annealing, ir->opts.ngtc);
1635 snew(ir->opts.anneal_npoints, ir->opts.ngtc);
1636 snew(ir->opts.anneal_time, ir->opts.ngtc);
1637 snew(ir->opts.anneal_temp, ir->opts.ngtc);
1638 snew(ir->opts.tau_t, ir->opts.ngtc);
1639 snew(ir->opts.nFreeze, ir->opts.ngfrz);
1640 snew(ir->opts.acc, ir->opts.ngacc);
1641 snew(ir->opts.egp_flags, ir->opts.ngener*ir->opts.ngener);
1643 if (ir->opts.ngtc > 0)
1645 if (bRead && file_version < 13)
1647 snew(tmp, ir->opts.ngtc);
1648 gmx_fio_ndo_int(fio, tmp, ir->opts.ngtc);
1649 for (i = 0; i < ir->opts.ngtc; i++)
1651 ir->opts.nrdf[i] = tmp[i];
1657 gmx_fio_ndo_real(fio, ir->opts.nrdf, ir->opts.ngtc);
1659 gmx_fio_ndo_real(fio, ir->opts.ref_t, ir->opts.ngtc);
1660 gmx_fio_ndo_real(fio, ir->opts.tau_t, ir->opts.ngtc);
1661 if (file_version < 33 && ir->eI == eiBD)
1663 for (i = 0; i < ir->opts.ngtc; i++)
1665 ir->opts.tau_t[i] = bd_temp;
1669 if (ir->opts.ngfrz > 0)
1671 gmx_fio_ndo_ivec(fio, ir->opts.nFreeze, ir->opts.ngfrz);
1673 if (ir->opts.ngacc > 0)
1675 gmx_fio_ndo_rvec(fio, ir->opts.acc, ir->opts.ngacc);
1677 if (file_version >= 12)
1679 gmx_fio_ndo_int(fio, ir->opts.egp_flags,
1680 ir->opts.ngener*ir->opts.ngener);
1683 if (bRead && file_version < 26)
1685 for (i = 0; i < ir->opts.ngtc; i++)
1689 ir->opts.annealing[i] = eannSINGLE;
1690 ir->opts.anneal_npoints[i] = 2;
1691 snew(ir->opts.anneal_time[i], 2);
1692 snew(ir->opts.anneal_temp[i], 2);
1693 /* calculate the starting/ending temperatures from reft, zerotemptime, and nsteps */
1694 finish_t = ir->init_t + ir->nsteps * ir->delta_t;
1695 init_temp = ir->opts.ref_t[i]*(1-ir->init_t/zerotemptime);
1696 finish_temp = ir->opts.ref_t[i]*(1-finish_t/zerotemptime);
1697 ir->opts.anneal_time[i][0] = ir->init_t;
1698 ir->opts.anneal_time[i][1] = finish_t;
1699 ir->opts.anneal_temp[i][0] = init_temp;
1700 ir->opts.anneal_temp[i][1] = finish_temp;
1704 ir->opts.annealing[i] = eannNO;
1705 ir->opts.anneal_npoints[i] = 0;
1711 /* file version 26 or later */
1712 /* First read the lists with annealing and npoints for each group */
1713 gmx_fio_ndo_int(fio, ir->opts.annealing, ir->opts.ngtc);
1714 gmx_fio_ndo_int(fio, ir->opts.anneal_npoints, ir->opts.ngtc);
1715 for (j = 0; j < (ir->opts.ngtc); j++)
1717 k = ir->opts.anneal_npoints[j];
1720 snew(ir->opts.anneal_time[j], k);
1721 snew(ir->opts.anneal_temp[j], k);
1723 gmx_fio_ndo_real(fio, ir->opts.anneal_time[j], k);
1724 gmx_fio_ndo_real(fio, ir->opts.anneal_temp[j], k);
1728 if (file_version >= 45)
1730 gmx_fio_do_int(fio, ir->nwall);
1731 gmx_fio_do_int(fio, ir->wall_type);
1732 if (file_version >= 50)
1734 gmx_fio_do_real(fio, ir->wall_r_linpot);
1738 ir->wall_r_linpot = -1;
1740 gmx_fio_do_int(fio, ir->wall_atomtype[0]);
1741 gmx_fio_do_int(fio, ir->wall_atomtype[1]);
1742 gmx_fio_do_real(fio, ir->wall_density[0]);
1743 gmx_fio_do_real(fio, ir->wall_density[1]);
1744 gmx_fio_do_real(fio, ir->wall_ewald_zfac);
1750 ir->wall_atomtype[0] = -1;
1751 ir->wall_atomtype[1] = -1;
1752 ir->wall_density[0] = 0;
1753 ir->wall_density[1] = 0;
1754 ir->wall_ewald_zfac = 3;
1756 /* Cosine stuff for electric fields */
1757 for (j = 0; (j < DIM); j++)
1759 gmx_fio_do_int(fio, ir->ex[j].n);
1760 gmx_fio_do_int(fio, ir->et[j].n);
1763 snew(ir->ex[j].a, ir->ex[j].n);
1764 snew(ir->ex[j].phi, ir->ex[j].n);
1765 snew(ir->et[j].a, ir->et[j].n);
1766 snew(ir->et[j].phi, ir->et[j].n);
1768 gmx_fio_ndo_real(fio, ir->ex[j].a, ir->ex[j].n);
1769 gmx_fio_ndo_real(fio, ir->ex[j].phi, ir->ex[j].n);
1770 gmx_fio_ndo_real(fio, ir->et[j].a, ir->et[j].n);
1771 gmx_fio_ndo_real(fio, ir->et[j].phi, ir->et[j].n);
1775 if (file_version >= tpxv_ComputationalElectrophysiology)
1777 gmx_fio_do_int(fio, ir->eSwapCoords);
1778 if (ir->eSwapCoords != eswapNO)
1784 do_swapcoords(fio, ir->swap, bRead);
1789 if (file_version >= 39)
1791 gmx_fio_do_gmx_bool(fio, ir->bQMMM);
1792 gmx_fio_do_int(fio, ir->QMMMscheme);
1793 gmx_fio_do_real(fio, ir->scalefactor);
1794 gmx_fio_do_int(fio, ir->opts.ngQM);
1797 snew(ir->opts.QMmethod, ir->opts.ngQM);
1798 snew(ir->opts.QMbasis, ir->opts.ngQM);
1799 snew(ir->opts.QMcharge, ir->opts.ngQM);
1800 snew(ir->opts.QMmult, ir->opts.ngQM);
1801 snew(ir->opts.bSH, ir->opts.ngQM);
1802 snew(ir->opts.CASorbitals, ir->opts.ngQM);
1803 snew(ir->opts.CASelectrons, ir->opts.ngQM);
1804 snew(ir->opts.SAon, ir->opts.ngQM);
1805 snew(ir->opts.SAoff, ir->opts.ngQM);
1806 snew(ir->opts.SAsteps, ir->opts.ngQM);
1807 snew(ir->opts.bOPT, ir->opts.ngQM);
1808 snew(ir->opts.bTS, ir->opts.ngQM);
1810 if (ir->opts.ngQM > 0)
1812 gmx_fio_ndo_int(fio, ir->opts.QMmethod, ir->opts.ngQM);
1813 gmx_fio_ndo_int(fio, ir->opts.QMbasis, ir->opts.ngQM);
1814 gmx_fio_ndo_int(fio, ir->opts.QMcharge, ir->opts.ngQM);
1815 gmx_fio_ndo_int(fio, ir->opts.QMmult, ir->opts.ngQM);
1816 gmx_fio_ndo_gmx_bool(fio, ir->opts.bSH, ir->opts.ngQM);
1817 gmx_fio_ndo_int(fio, ir->opts.CASorbitals, ir->opts.ngQM);
1818 gmx_fio_ndo_int(fio, ir->opts.CASelectrons, ir->opts.ngQM);
1819 gmx_fio_ndo_real(fio, ir->opts.SAon, ir->opts.ngQM);
1820 gmx_fio_ndo_real(fio, ir->opts.SAoff, ir->opts.ngQM);
1821 gmx_fio_ndo_int(fio, ir->opts.SAsteps, ir->opts.ngQM);
1822 gmx_fio_ndo_gmx_bool(fio, ir->opts.bOPT, ir->opts.ngQM);
1823 gmx_fio_ndo_gmx_bool(fio, ir->opts.bTS, ir->opts.ngQM);
1825 /* end of QMMM stuff */
1830 static void do_harm(t_fileio *fio, t_iparams *iparams)
1832 gmx_fio_do_real(fio, iparams->harmonic.rA);
1833 gmx_fio_do_real(fio, iparams->harmonic.krA);
1834 gmx_fio_do_real(fio, iparams->harmonic.rB);
1835 gmx_fio_do_real(fio, iparams->harmonic.krB);
1838 void do_iparams(t_fileio *fio, t_functype ftype, t_iparams *iparams,
1839 gmx_bool bRead, int file_version)
1852 do_harm(fio, iparams);
1853 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && bRead)
1855 /* Correct incorrect storage of parameters */
1856 iparams->pdihs.phiB = iparams->pdihs.phiA;
1857 iparams->pdihs.cpB = iparams->pdihs.cpA;
1861 gmx_fio_do_real(fio, iparams->harmonic.rA);
1862 gmx_fio_do_real(fio, iparams->harmonic.krA);
1864 case F_LINEAR_ANGLES:
1865 gmx_fio_do_real(fio, iparams->linangle.klinA);
1866 gmx_fio_do_real(fio, iparams->linangle.aA);
1867 gmx_fio_do_real(fio, iparams->linangle.klinB);
1868 gmx_fio_do_real(fio, iparams->linangle.aB);
1871 gmx_fio_do_real(fio, iparams->fene.bm);
1872 gmx_fio_do_real(fio, iparams->fene.kb);
1876 gmx_fio_do_real(fio, iparams->restraint.lowA);
1877 gmx_fio_do_real(fio, iparams->restraint.up1A);
1878 gmx_fio_do_real(fio, iparams->restraint.up2A);
1879 gmx_fio_do_real(fio, iparams->restraint.kA);
1880 gmx_fio_do_real(fio, iparams->restraint.lowB);
1881 gmx_fio_do_real(fio, iparams->restraint.up1B);
1882 gmx_fio_do_real(fio, iparams->restraint.up2B);
1883 gmx_fio_do_real(fio, iparams->restraint.kB);
1889 gmx_fio_do_real(fio, iparams->tab.kA);
1890 gmx_fio_do_int(fio, iparams->tab.table);
1891 gmx_fio_do_real(fio, iparams->tab.kB);
1893 case F_CROSS_BOND_BONDS:
1894 gmx_fio_do_real(fio, iparams->cross_bb.r1e);
1895 gmx_fio_do_real(fio, iparams->cross_bb.r2e);
1896 gmx_fio_do_real(fio, iparams->cross_bb.krr);
1898 case F_CROSS_BOND_ANGLES:
1899 gmx_fio_do_real(fio, iparams->cross_ba.r1e);
1900 gmx_fio_do_real(fio, iparams->cross_ba.r2e);
1901 gmx_fio_do_real(fio, iparams->cross_ba.r3e);
1902 gmx_fio_do_real(fio, iparams->cross_ba.krt);
1904 case F_UREY_BRADLEY:
1905 gmx_fio_do_real(fio, iparams->u_b.thetaA);
1906 gmx_fio_do_real(fio, iparams->u_b.kthetaA);
1907 gmx_fio_do_real(fio, iparams->u_b.r13A);
1908 gmx_fio_do_real(fio, iparams->u_b.kUBA);
1909 if (file_version >= 79)
1911 gmx_fio_do_real(fio, iparams->u_b.thetaB);
1912 gmx_fio_do_real(fio, iparams->u_b.kthetaB);
1913 gmx_fio_do_real(fio, iparams->u_b.r13B);
1914 gmx_fio_do_real(fio, iparams->u_b.kUBB);
1918 iparams->u_b.thetaB = iparams->u_b.thetaA;
1919 iparams->u_b.kthetaB = iparams->u_b.kthetaA;
1920 iparams->u_b.r13B = iparams->u_b.r13A;
1921 iparams->u_b.kUBB = iparams->u_b.kUBA;
1924 case F_QUARTIC_ANGLES:
1925 gmx_fio_do_real(fio, iparams->qangle.theta);
1926 gmx_fio_ndo_real(fio, iparams->qangle.c, 5);
1929 gmx_fio_do_real(fio, iparams->bham.a);
1930 gmx_fio_do_real(fio, iparams->bham.b);
1931 gmx_fio_do_real(fio, iparams->bham.c);
1934 gmx_fio_do_real(fio, iparams->morse.b0A);
1935 gmx_fio_do_real(fio, iparams->morse.cbA);
1936 gmx_fio_do_real(fio, iparams->morse.betaA);
1937 if (file_version >= 79)
1939 gmx_fio_do_real(fio, iparams->morse.b0B);
1940 gmx_fio_do_real(fio, iparams->morse.cbB);
1941 gmx_fio_do_real(fio, iparams->morse.betaB);
1945 iparams->morse.b0B = iparams->morse.b0A;
1946 iparams->morse.cbB = iparams->morse.cbA;
1947 iparams->morse.betaB = iparams->morse.betaA;
1951 gmx_fio_do_real(fio, iparams->cubic.b0);
1952 gmx_fio_do_real(fio, iparams->cubic.kb);
1953 gmx_fio_do_real(fio, iparams->cubic.kcub);
1957 case F_POLARIZATION:
1958 gmx_fio_do_real(fio, iparams->polarize.alpha);
1961 gmx_fio_do_real(fio, iparams->anharm_polarize.alpha);
1962 gmx_fio_do_real(fio, iparams->anharm_polarize.drcut);
1963 gmx_fio_do_real(fio, iparams->anharm_polarize.khyp);
1966 if (file_version < 31)
1968 gmx_fatal(FARGS, "Old tpr files with water_polarization not supported. Make a new.");
1970 gmx_fio_do_real(fio, iparams->wpol.al_x);
1971 gmx_fio_do_real(fio, iparams->wpol.al_y);
1972 gmx_fio_do_real(fio, iparams->wpol.al_z);
1973 gmx_fio_do_real(fio, iparams->wpol.rOH);
1974 gmx_fio_do_real(fio, iparams->wpol.rHH);
1975 gmx_fio_do_real(fio, iparams->wpol.rOD);
1978 gmx_fio_do_real(fio, iparams->thole.a);
1979 gmx_fio_do_real(fio, iparams->thole.alpha1);
1980 gmx_fio_do_real(fio, iparams->thole.alpha2);
1981 gmx_fio_do_real(fio, iparams->thole.rfac);
1984 gmx_fio_do_real(fio, iparams->lj.c6);
1985 gmx_fio_do_real(fio, iparams->lj.c12);
1988 gmx_fio_do_real(fio, iparams->lj14.c6A);
1989 gmx_fio_do_real(fio, iparams->lj14.c12A);
1990 gmx_fio_do_real(fio, iparams->lj14.c6B);
1991 gmx_fio_do_real(fio, iparams->lj14.c12B);
1994 gmx_fio_do_real(fio, iparams->ljc14.fqq);
1995 gmx_fio_do_real(fio, iparams->ljc14.qi);
1996 gmx_fio_do_real(fio, iparams->ljc14.qj);
1997 gmx_fio_do_real(fio, iparams->ljc14.c6);
1998 gmx_fio_do_real(fio, iparams->ljc14.c12);
2000 case F_LJC_PAIRS_NB:
2001 gmx_fio_do_real(fio, iparams->ljcnb.qi);
2002 gmx_fio_do_real(fio, iparams->ljcnb.qj);
2003 gmx_fio_do_real(fio, iparams->ljcnb.c6);
2004 gmx_fio_do_real(fio, iparams->ljcnb.c12);
2010 gmx_fio_do_real(fio, iparams->pdihs.phiA);
2011 gmx_fio_do_real(fio, iparams->pdihs.cpA);
2012 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && file_version < 42)
2014 /* Read the incorrectly stored multiplicity */
2015 gmx_fio_do_real(fio, iparams->harmonic.rB);
2016 gmx_fio_do_real(fio, iparams->harmonic.krB);
2017 iparams->pdihs.phiB = iparams->pdihs.phiA;
2018 iparams->pdihs.cpB = iparams->pdihs.cpA;
2022 gmx_fio_do_real(fio, iparams->pdihs.phiB);
2023 gmx_fio_do_real(fio, iparams->pdihs.cpB);
2024 gmx_fio_do_int(fio, iparams->pdihs.mult);
2028 gmx_fio_do_real(fio, iparams->pdihs.phiA);
2029 gmx_fio_do_real(fio, iparams->pdihs.cpA);
2032 gmx_fio_do_int(fio, iparams->disres.label);
2033 gmx_fio_do_int(fio, iparams->disres.type);
2034 gmx_fio_do_real(fio, iparams->disres.low);
2035 gmx_fio_do_real(fio, iparams->disres.up1);
2036 gmx_fio_do_real(fio, iparams->disres.up2);
2037 gmx_fio_do_real(fio, iparams->disres.kfac);
2040 gmx_fio_do_int(fio, iparams->orires.ex);
2041 gmx_fio_do_int(fio, iparams->orires.label);
2042 gmx_fio_do_int(fio, iparams->orires.power);
2043 gmx_fio_do_real(fio, iparams->orires.c);
2044 gmx_fio_do_real(fio, iparams->orires.obs);
2045 gmx_fio_do_real(fio, iparams->orires.kfac);
2048 if (file_version < 82)
2050 gmx_fio_do_int(fio, idum);
2051 gmx_fio_do_int(fio, idum);
2053 gmx_fio_do_real(fio, iparams->dihres.phiA);
2054 gmx_fio_do_real(fio, iparams->dihres.dphiA);
2055 gmx_fio_do_real(fio, iparams->dihres.kfacA);
2056 if (file_version >= 82)
2058 gmx_fio_do_real(fio, iparams->dihres.phiB);
2059 gmx_fio_do_real(fio, iparams->dihres.dphiB);
2060 gmx_fio_do_real(fio, iparams->dihres.kfacB);
2064 iparams->dihres.phiB = iparams->dihres.phiA;
2065 iparams->dihres.dphiB = iparams->dihres.dphiA;
2066 iparams->dihres.kfacB = iparams->dihres.kfacA;
2070 gmx_fio_do_rvec(fio, iparams->posres.pos0A);
2071 gmx_fio_do_rvec(fio, iparams->posres.fcA);
2072 if (bRead && file_version < 27)
2074 copy_rvec(iparams->posres.pos0A, iparams->posres.pos0B);
2075 copy_rvec(iparams->posres.fcA, iparams->posres.fcB);
2079 gmx_fio_do_rvec(fio, iparams->posres.pos0B);
2080 gmx_fio_do_rvec(fio, iparams->posres.fcB);
2084 gmx_fio_do_int(fio, iparams->fbposres.geom);
2085 gmx_fio_do_rvec(fio, iparams->fbposres.pos0);
2086 gmx_fio_do_real(fio, iparams->fbposres.r);
2087 gmx_fio_do_real(fio, iparams->fbposres.k);
2090 gmx_fio_ndo_real(fio, iparams->cbtdihs.cbtcA, NR_CBTDIHS);
2093 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcA, NR_RBDIHS);
2094 if (file_version >= 25)
2096 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcB, NR_RBDIHS);
2100 /* Fourier dihedrals are internally represented
2101 * as Ryckaert-Bellemans since those are faster to compute.
2103 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcA, NR_RBDIHS);
2104 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcB, NR_RBDIHS);
2108 gmx_fio_do_real(fio, iparams->constr.dA);
2109 gmx_fio_do_real(fio, iparams->constr.dB);
2112 gmx_fio_do_real(fio, iparams->settle.doh);
2113 gmx_fio_do_real(fio, iparams->settle.dhh);
2116 gmx_fio_do_real(fio, iparams->vsite.a);
2121 gmx_fio_do_real(fio, iparams->vsite.a);
2122 gmx_fio_do_real(fio, iparams->vsite.b);
2127 gmx_fio_do_real(fio, iparams->vsite.a);
2128 gmx_fio_do_real(fio, iparams->vsite.b);
2129 gmx_fio_do_real(fio, iparams->vsite.c);
2132 gmx_fio_do_int(fio, iparams->vsiten.n);
2133 gmx_fio_do_real(fio, iparams->vsiten.a);
2138 /* We got rid of some parameters in version 68 */
2139 if (bRead && file_version < 68)
2141 gmx_fio_do_real(fio, rdum);
2142 gmx_fio_do_real(fio, rdum);
2143 gmx_fio_do_real(fio, rdum);
2144 gmx_fio_do_real(fio, rdum);
2146 gmx_fio_do_real(fio, iparams->gb.sar);
2147 gmx_fio_do_real(fio, iparams->gb.st);
2148 gmx_fio_do_real(fio, iparams->gb.pi);
2149 gmx_fio_do_real(fio, iparams->gb.gbr);
2150 gmx_fio_do_real(fio, iparams->gb.bmlt);
2153 gmx_fio_do_int(fio, iparams->cmap.cmapA);
2154 gmx_fio_do_int(fio, iparams->cmap.cmapB);
2157 gmx_fatal(FARGS, "unknown function type %d (%s) in %s line %d",
2158 ftype, interaction_function[ftype].name, __FILE__, __LINE__);
2162 static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_version)
2166 if (file_version < 44)
2168 for (i = 0; i < MAXNODES; i++)
2170 gmx_fio_do_int(fio, idum);
2173 gmx_fio_do_int(fio, ilist->nr);
2176 snew(ilist->iatoms, ilist->nr);
2178 gmx_fio_ndo_int(fio, ilist->iatoms, ilist->nr);
2181 static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
2182 gmx_bool bRead, int file_version)
2187 gmx_fio_do_int(fio, ffparams->atnr);
2188 if (file_version < 57)
2190 gmx_fio_do_int(fio, idum);
2192 gmx_fio_do_int(fio, ffparams->ntypes);
2195 fprintf(debug, "ffparams->atnr = %d, ntypes = %d\n",
2196 ffparams->atnr, ffparams->ntypes);
2200 snew(ffparams->functype, ffparams->ntypes);
2201 snew(ffparams->iparams, ffparams->ntypes);
2203 /* Read/write all the function types */
2204 gmx_fio_ndo_int(fio, ffparams->functype, ffparams->ntypes);
2207 pr_ivec(debug, 0, "functype", ffparams->functype, ffparams->ntypes, TRUE);
2210 if (file_version >= 66)
2212 gmx_fio_do_double(fio, ffparams->reppow);
2216 ffparams->reppow = 12.0;
2219 if (file_version >= 57)
2221 gmx_fio_do_real(fio, ffparams->fudgeQQ);
2224 /* Check whether all these function types are supported by the code.
2225 * In practice the code is backwards compatible, which means that the
2226 * numbering may have to be altered from old numbering to new numbering
2228 for (i = 0; (i < ffparams->ntypes); i++)
2232 /* Loop over file versions */
2233 for (k = 0; (k < NFTUPD); k++)
2235 /* Compare the read file_version to the update table */
2236 if ((file_version < ftupd[k].fvnr) &&
2237 (ffparams->functype[i] >= ftupd[k].ftype))
2239 ffparams->functype[i] += 1;
2242 fprintf(debug, "Incrementing function type %d to %d (due to %s)\n",
2243 i, ffparams->functype[i],
2244 interaction_function[ftupd[k].ftype].longname);
2251 do_iparams(fio, ffparams->functype[i], &ffparams->iparams[i], bRead,
2255 pr_iparams(debug, ffparams->functype[i], &ffparams->iparams[i]);
2260 static void add_settle_atoms(t_ilist *ilist)
2264 /* Settle used to only store the first atom: add the other two */
2265 srenew(ilist->iatoms, 2*ilist->nr);
2266 for (i = ilist->nr/2-1; i >= 0; i--)
2268 ilist->iatoms[4*i+0] = ilist->iatoms[2*i+0];
2269 ilist->iatoms[4*i+1] = ilist->iatoms[2*i+1];
2270 ilist->iatoms[4*i+2] = ilist->iatoms[2*i+1] + 1;
2271 ilist->iatoms[4*i+3] = ilist->iatoms[2*i+1] + 2;
2273 ilist->nr = 2*ilist->nr;
2276 static void do_ilists(t_fileio *fio, t_ilist *ilist, gmx_bool bRead,
2279 int i, j, renum[F_NRE];
2283 for (j = 0; (j < F_NRE); j++)
2288 for (k = 0; k < NFTUPD; k++)
2290 if ((file_version < ftupd[k].fvnr) && (j == ftupd[k].ftype))
2299 ilist[j].iatoms = NULL;
2303 do_ilist(fio, &ilist[j], bRead, file_version);
2304 if (file_version < 78 && j == F_SETTLE && ilist[j].nr > 0)
2306 add_settle_atoms(&ilist[j]);
2310 if (bRead && gmx_debug_at)
2311 pr_ilist(debug,0,interaction_function[j].longname,
2312 functype,&ilist[j],TRUE);
2317 static void do_idef(t_fileio *fio, gmx_ffparams_t *ffparams, gmx_moltype_t *molt,
2318 gmx_bool bRead, int file_version)
2320 do_ffparams(fio, ffparams, bRead, file_version);
2322 if (file_version >= 54)
2324 gmx_fio_do_real(fio, ffparams->fudgeQQ);
2327 do_ilists(fio, molt->ilist, bRead, file_version);
2330 static void do_block(t_fileio *fio, t_block *block, gmx_bool bRead, int file_version)
2332 int i, idum, dum_nra, *dum_a;
2334 if (file_version < 44)
2336 for (i = 0; i < MAXNODES; i++)
2338 gmx_fio_do_int(fio, idum);
2341 gmx_fio_do_int(fio, block->nr);
2342 if (file_version < 51)
2344 gmx_fio_do_int(fio, dum_nra);
2348 if ((block->nalloc_index > 0) && (NULL != block->index))
2350 sfree(block->index);
2352 block->nalloc_index = block->nr+1;
2353 snew(block->index, block->nalloc_index);
2355 gmx_fio_ndo_int(fio, block->index, block->nr+1);
2357 if (file_version < 51 && dum_nra > 0)
2359 snew(dum_a, dum_nra);
2360 gmx_fio_ndo_int(fio, dum_a, dum_nra);
2365 static void do_blocka(t_fileio *fio, t_blocka *block, gmx_bool bRead,
2370 if (file_version < 44)
2372 for (i = 0; i < MAXNODES; i++)
2374 gmx_fio_do_int(fio, idum);
2377 gmx_fio_do_int(fio, block->nr);
2378 gmx_fio_do_int(fio, block->nra);
2381 block->nalloc_index = block->nr+1;
2382 snew(block->index, block->nalloc_index);
2383 block->nalloc_a = block->nra;
2384 snew(block->a, block->nalloc_a);
2386 gmx_fio_ndo_int(fio, block->index, block->nr+1);
2387 gmx_fio_ndo_int(fio, block->a, block->nra);
2390 /* This is a primitive routine to make it possible to translate atomic numbers
2391 * to element names when reading TPR files, without making the Gromacs library
2392 * directory a dependency on mdrun (which is the case if we need elements.dat).
2395 atomicnumber_to_element(int atomicnumber)
2399 /* This does not have to be complete, so we only include elements likely
2400 * to occur in PDB files.
2402 switch (atomicnumber)
2404 case 1: p = "H"; break;
2405 case 5: p = "B"; break;
2406 case 6: p = "C"; break;
2407 case 7: p = "N"; break;
2408 case 8: p = "O"; break;
2409 case 9: p = "F"; break;
2410 case 11: p = "Na"; break;
2411 case 12: p = "Mg"; break;
2412 case 15: p = "P"; break;
2413 case 16: p = "S"; break;
2414 case 17: p = "Cl"; break;
2415 case 18: p = "Ar"; break;
2416 case 19: p = "K"; break;
2417 case 20: p = "Ca"; break;
2418 case 25: p = "Mn"; break;
2419 case 26: p = "Fe"; break;
2420 case 28: p = "Ni"; break;
2421 case 29: p = "Cu"; break;
2422 case 30: p = "Zn"; break;
2423 case 35: p = "Br"; break;
2424 case 47: p = "Ag"; break;
2425 default: p = ""; break;
2431 static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead,
2432 int file_version, gmx_groups_t *groups, int atnr)
2437 gmx_fio_do_real(fio, atom->m);
2438 gmx_fio_do_real(fio, atom->q);
2439 gmx_fio_do_real(fio, atom->mB);
2440 gmx_fio_do_real(fio, atom->qB);
2441 gmx_fio_do_ushort(fio, atom->type);
2442 gmx_fio_do_ushort(fio, atom->typeB);
2443 gmx_fio_do_int(fio, atom->ptype);
2444 gmx_fio_do_int(fio, atom->resind);
2445 if (file_version >= 52)
2447 gmx_fio_do_int(fio, atom->atomnumber);
2450 /* Set element string from atomic number if present.
2451 * This routine returns an empty string if the name is not found.
2453 strncpy(atom->elem, atomicnumber_to_element(atom->atomnumber), 4);
2454 /* avoid warnings about potentially unterminated string */
2455 atom->elem[3] = '\0';
2460 atom->atomnumber = NOTSET;
2462 if (file_version < 23)
2466 else if (file_version < 39)
2475 if (file_version < 57)
2477 unsigned char uchar[egcNR];
2478 gmx_fio_ndo_uchar(fio, uchar, myngrp);
2479 for (i = myngrp; (i < ngrp); i++)
2483 /* Copy the old data format to the groups struct */
2484 for (i = 0; i < ngrp; i++)
2486 groups->grpnr[i][atnr] = uchar[i];
2491 static void do_grps(t_fileio *fio, int ngrp, t_grps grps[], gmx_bool bRead,
2496 if (file_version < 23)
2500 else if (file_version < 39)
2509 for (j = 0; (j < ngrp); j++)
2513 gmx_fio_do_int(fio, grps[j].nr);
2516 snew(grps[j].nm_ind, grps[j].nr);
2518 gmx_fio_ndo_int(fio, grps[j].nm_ind, grps[j].nr);
2523 snew(grps[j].nm_ind, grps[j].nr);
2528 static void do_symstr(t_fileio *fio, char ***nm, gmx_bool bRead, t_symtab *symtab)
2534 gmx_fio_do_int(fio, ls);
2535 *nm = get_symtab_handle(symtab, ls);
2539 ls = lookup_symtab(symtab, *nm);
2540 gmx_fio_do_int(fio, ls);
2544 static void do_strstr(t_fileio *fio, int nstr, char ***nm, gmx_bool bRead,
2549 for (j = 0; (j < nstr); j++)
2551 do_symstr(fio, &(nm[j]), bRead, symtab);
2555 static void do_resinfo(t_fileio *fio, int n, t_resinfo *ri, gmx_bool bRead,
2556 t_symtab *symtab, int file_version)
2560 for (j = 0; (j < n); j++)
2562 do_symstr(fio, &(ri[j].name), bRead, symtab);
2563 if (file_version >= 63)
2565 gmx_fio_do_int(fio, ri[j].nr);
2566 gmx_fio_do_uchar(fio, ri[j].ic);
2576 static void do_atoms(t_fileio *fio, t_atoms *atoms, gmx_bool bRead, t_symtab *symtab,
2578 gmx_groups_t *groups)
2582 gmx_fio_do_int(fio, atoms->nr);
2583 gmx_fio_do_int(fio, atoms->nres);
2584 if (file_version < 57)
2586 gmx_fio_do_int(fio, groups->ngrpname);
2587 for (i = 0; i < egcNR; i++)
2589 groups->ngrpnr[i] = atoms->nr;
2590 snew(groups->grpnr[i], groups->ngrpnr[i]);
2595 snew(atoms->atom, atoms->nr);
2596 snew(atoms->atomname, atoms->nr);
2597 snew(atoms->atomtype, atoms->nr);
2598 snew(atoms->atomtypeB, atoms->nr);
2599 snew(atoms->resinfo, atoms->nres);
2600 if (file_version < 57)
2602 snew(groups->grpname, groups->ngrpname);
2604 atoms->pdbinfo = NULL;
2606 for (i = 0; (i < atoms->nr); i++)
2608 do_atom(fio, &atoms->atom[i], egcNR, bRead, file_version, groups, i);
2610 do_strstr(fio, atoms->nr, atoms->atomname, bRead, symtab);
2611 if (bRead && (file_version <= 20))
2613 for (i = 0; i < atoms->nr; i++)
2615 atoms->atomtype[i] = put_symtab(symtab, "?");
2616 atoms->atomtypeB[i] = put_symtab(symtab, "?");
2621 do_strstr(fio, atoms->nr, atoms->atomtype, bRead, symtab);
2622 do_strstr(fio, atoms->nr, atoms->atomtypeB, bRead, symtab);
2624 do_resinfo(fio, atoms->nres, atoms->resinfo, bRead, symtab, file_version);
2626 if (file_version < 57)
2628 do_strstr(fio, groups->ngrpname, groups->grpname, bRead, symtab);
2630 do_grps(fio, egcNR, groups->grps, bRead, file_version);
2634 static void do_groups(t_fileio *fio, gmx_groups_t *groups,
2635 gmx_bool bRead, t_symtab *symtab,
2640 do_grps(fio, egcNR, groups->grps, bRead, file_version);
2641 gmx_fio_do_int(fio, groups->ngrpname);
2644 snew(groups->grpname, groups->ngrpname);
2646 do_strstr(fio, groups->ngrpname, groups->grpname, bRead, symtab);
2647 for (g = 0; g < egcNR; g++)
2649 gmx_fio_do_int(fio, groups->ngrpnr[g]);
2650 if (groups->ngrpnr[g] == 0)
2654 groups->grpnr[g] = NULL;
2661 snew(groups->grpnr[g], groups->ngrpnr[g]);
2663 gmx_fio_ndo_uchar(fio, groups->grpnr[g], groups->ngrpnr[g]);
2668 static void do_atomtypes(t_fileio *fio, t_atomtypes *atomtypes, gmx_bool bRead,
2673 if (file_version > 25)
2675 gmx_fio_do_int(fio, atomtypes->nr);
2679 snew(atomtypes->radius, j);
2680 snew(atomtypes->vol, j);
2681 snew(atomtypes->surftens, j);
2682 snew(atomtypes->atomnumber, j);
2683 snew(atomtypes->gb_radius, j);
2684 snew(atomtypes->S_hct, j);
2686 gmx_fio_ndo_real(fio, atomtypes->radius, j);
2687 gmx_fio_ndo_real(fio, atomtypes->vol, j);
2688 gmx_fio_ndo_real(fio, atomtypes->surftens, j);
2689 if (file_version >= 40)
2691 gmx_fio_ndo_int(fio, atomtypes->atomnumber, j);
2693 if (file_version >= 60)
2695 gmx_fio_ndo_real(fio, atomtypes->gb_radius, j);
2696 gmx_fio_ndo_real(fio, atomtypes->S_hct, j);
2701 /* File versions prior to 26 cannot do GBSA,
2702 * so they dont use this structure
2705 atomtypes->radius = NULL;
2706 atomtypes->vol = NULL;
2707 atomtypes->surftens = NULL;
2708 atomtypes->atomnumber = NULL;
2709 atomtypes->gb_radius = NULL;
2710 atomtypes->S_hct = NULL;
2714 static void do_symtab(t_fileio *fio, t_symtab *symtab, gmx_bool bRead)
2720 gmx_fio_do_int(fio, symtab->nr);
2724 snew(symtab->symbuf, 1);
2725 symbuf = symtab->symbuf;
2726 symbuf->bufsize = nr;
2727 snew(symbuf->buf, nr);
2728 for (i = 0; (i < nr); i++)
2730 gmx_fio_do_string(fio, buf);
2731 symbuf->buf[i] = gmx_strdup(buf);
2736 symbuf = symtab->symbuf;
2737 while (symbuf != NULL)
2739 for (i = 0; (i < symbuf->bufsize) && (i < nr); i++)
2741 gmx_fio_do_string(fio, symbuf->buf[i]);
2744 symbuf = symbuf->next;
2748 gmx_fatal(FARGS, "nr of symtab strings left: %d", nr);
2753 static void do_cmap(t_fileio *fio, gmx_cmap_t *cmap_grid, gmx_bool bRead)
2755 int i, j, ngrid, gs, nelem;
2757 gmx_fio_do_int(fio, cmap_grid->ngrid);
2758 gmx_fio_do_int(fio, cmap_grid->grid_spacing);
2760 ngrid = cmap_grid->ngrid;
2761 gs = cmap_grid->grid_spacing;
2766 snew(cmap_grid->cmapdata, ngrid);
2768 for (i = 0; i < cmap_grid->ngrid; i++)
2770 snew(cmap_grid->cmapdata[i].cmap, 4*nelem);
2774 for (i = 0; i < cmap_grid->ngrid; i++)
2776 for (j = 0; j < nelem; j++)
2778 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4]);
2779 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+1]);
2780 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+2]);
2781 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+3]);
2787 void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols)
2789 int m, a, a0, a1, r;
2793 /* We always assign a new chain number, but save the chain id characters
2794 * for larger molecules.
2796 #define CHAIN_MIN_ATOMS 15
2800 for (m = 0; m < mols->nr; m++)
2802 a0 = mols->index[m];
2803 a1 = mols->index[m+1];
2804 if ((a1-a0 >= CHAIN_MIN_ATOMS) && (chainid <= 'Z'))
2813 for (a = a0; a < a1; a++)
2815 atoms->resinfo[atoms->atom[a].resind].chainnum = chainnum;
2816 atoms->resinfo[atoms->atom[a].resind].chainid = c;
2821 /* Blank out the chain id if there was only one chain */
2824 for (r = 0; r < atoms->nres; r++)
2826 atoms->resinfo[r].chainid = ' ';
2831 static void do_moltype(t_fileio *fio, gmx_moltype_t *molt, gmx_bool bRead,
2832 t_symtab *symtab, int file_version,
2833 gmx_groups_t *groups)
2837 if (file_version >= 57)
2839 do_symstr(fio, &(molt->name), bRead, symtab);
2842 do_atoms(fio, &molt->atoms, bRead, symtab, file_version, groups);
2844 if (bRead && gmx_debug_at)
2846 pr_atoms(debug, 0, "atoms", &molt->atoms, TRUE);
2849 if (file_version >= 57)
2851 do_ilists(fio, molt->ilist, bRead, file_version);
2853 do_block(fio, &molt->cgs, bRead, file_version);
2854 if (bRead && gmx_debug_at)
2856 pr_block(debug, 0, "cgs", &molt->cgs, TRUE);
2860 /* This used to be in the atoms struct */
2861 do_blocka(fio, &molt->excls, bRead, file_version);
2864 static void do_molblock(t_fileio *fio, gmx_molblock_t *molb, gmx_bool bRead)
2868 gmx_fio_do_int(fio, molb->type);
2869 gmx_fio_do_int(fio, molb->nmol);
2870 gmx_fio_do_int(fio, molb->natoms_mol);
2871 /* Position restraint coordinates */
2872 gmx_fio_do_int(fio, molb->nposres_xA);
2873 if (molb->nposres_xA > 0)
2877 snew(molb->posres_xA, molb->nposres_xA);
2879 gmx_fio_ndo_rvec(fio, molb->posres_xA, molb->nposres_xA);
2881 gmx_fio_do_int(fio, molb->nposres_xB);
2882 if (molb->nposres_xB > 0)
2886 snew(molb->posres_xB, molb->nposres_xB);
2888 gmx_fio_ndo_rvec(fio, molb->posres_xB, molb->nposres_xB);
2893 static t_block mtop_mols(gmx_mtop_t *mtop)
2899 for (mb = 0; mb < mtop->nmolblock; mb++)
2901 mols.nr += mtop->molblock[mb].nmol;
2903 mols.nalloc_index = mols.nr + 1;
2904 snew(mols.index, mols.nalloc_index);
2909 for (mb = 0; mb < mtop->nmolblock; mb++)
2911 for (mol = 0; mol < mtop->molblock[mb].nmol; mol++)
2913 a += mtop->molblock[mb].natoms_mol;
2922 static void add_posres_molblock(gmx_mtop_t *mtop)
2927 gmx_molblock_t *molb;
2930 /* posres reference positions are stored in ip->posres (if present) and
2931 in ip->fbposres (if present). If normal and flat-bottomed posres are present,
2932 posres.pos0A are identical to fbposres.pos0. */
2933 il = &mtop->moltype[0].ilist[F_POSRES];
2934 ilfb = &mtop->moltype[0].ilist[F_FBPOSRES];
2935 if (il->nr == 0 && ilfb->nr == 0)
2941 for (i = 0; i < il->nr; i += 2)
2943 ip = &mtop->ffparams.iparams[il->iatoms[i]];
2944 am = max(am, il->iatoms[i+1]);
2945 if (ip->posres.pos0B[XX] != ip->posres.pos0A[XX] ||
2946 ip->posres.pos0B[YY] != ip->posres.pos0A[YY] ||
2947 ip->posres.pos0B[ZZ] != ip->posres.pos0A[ZZ])
2952 /* This loop is required if we have only flat-bottomed posres:
2954 - bFE == FALSE (no B-state for flat-bottomed posres) */
2957 for (i = 0; i < ilfb->nr; i += 2)
2959 ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
2960 am = max(am, ilfb->iatoms[i+1]);
2963 /* Make the posres coordinate block end at a molecule end */
2965 while (am >= mtop->mols.index[mol+1])
2969 molb = &mtop->molblock[0];
2970 molb->nposres_xA = mtop->mols.index[mol+1];
2971 snew(molb->posres_xA, molb->nposres_xA);
2974 molb->nposres_xB = molb->nposres_xA;
2975 snew(molb->posres_xB, molb->nposres_xB);
2979 molb->nposres_xB = 0;
2981 for (i = 0; i < il->nr; i += 2)
2983 ip = &mtop->ffparams.iparams[il->iatoms[i]];
2984 a = il->iatoms[i+1];
2985 molb->posres_xA[a][XX] = ip->posres.pos0A[XX];
2986 molb->posres_xA[a][YY] = ip->posres.pos0A[YY];
2987 molb->posres_xA[a][ZZ] = ip->posres.pos0A[ZZ];
2990 molb->posres_xB[a][XX] = ip->posres.pos0B[XX];
2991 molb->posres_xB[a][YY] = ip->posres.pos0B[YY];
2992 molb->posres_xB[a][ZZ] = ip->posres.pos0B[ZZ];
2997 /* If only flat-bottomed posres are present, take reference pos from them.
2998 Here: bFE == FALSE */
2999 for (i = 0; i < ilfb->nr; i += 2)
3001 ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
3002 a = ilfb->iatoms[i+1];
3003 molb->posres_xA[a][XX] = ip->fbposres.pos0[XX];
3004 molb->posres_xA[a][YY] = ip->fbposres.pos0[YY];
3005 molb->posres_xA[a][ZZ] = ip->fbposres.pos0[ZZ];
3010 static void set_disres_npair(gmx_mtop_t *mtop)
3013 gmx_mtop_ilistloop_t iloop;
3014 t_ilist *ilist, *il;
3018 ip = mtop->ffparams.iparams;
3020 iloop = gmx_mtop_ilistloop_init(mtop);
3021 while (gmx_mtop_ilistloop_next(iloop, &ilist, &nmol))
3023 il = &ilist[F_DISRES];
3029 for (i = 0; i < il->nr; i += 3)
3032 if (i+3 == il->nr || ip[a[i]].disres.label != ip[a[i+3]].disres.label)
3034 ip[a[i]].disres.npair = npair;
3042 static void do_mtop(t_fileio *fio, gmx_mtop_t *mtop, gmx_bool bRead,
3052 do_symtab(fio, &(mtop->symtab), bRead);
3055 pr_symtab(debug, 0, "symtab", &mtop->symtab);
3058 do_symstr(fio, &(mtop->name), bRead, &(mtop->symtab));
3060 if (file_version >= 57)
3062 do_ffparams(fio, &mtop->ffparams, bRead, file_version);
3064 gmx_fio_do_int(fio, mtop->nmoltype);
3072 snew(mtop->moltype, mtop->nmoltype);
3073 if (file_version < 57)
3075 mtop->moltype[0].name = mtop->name;
3078 for (mt = 0; mt < mtop->nmoltype; mt++)
3080 do_moltype(fio, &mtop->moltype[mt], bRead, &mtop->symtab, file_version,
3084 if (file_version >= 57)
3086 gmx_fio_do_int(fio, mtop->nmolblock);
3090 mtop->nmolblock = 1;
3094 snew(mtop->molblock, mtop->nmolblock);
3096 if (file_version >= 57)
3098 for (mb = 0; mb < mtop->nmolblock; mb++)
3100 do_molblock(fio, &mtop->molblock[mb], bRead);
3102 gmx_fio_do_int(fio, mtop->natoms);
3106 mtop->molblock[0].type = 0;
3107 mtop->molblock[0].nmol = 1;
3108 mtop->molblock[0].natoms_mol = mtop->moltype[0].atoms.nr;
3109 mtop->molblock[0].nposres_xA = 0;
3110 mtop->molblock[0].nposres_xB = 0;
3113 if (file_version >= tpxv_IntermolecularBondeds)
3115 gmx_fio_do_gmx_bool(fio, mtop->bIntermolecularInteractions);
3116 if (mtop->bIntermolecularInteractions)
3120 snew(mtop->intermolecular_ilist, F_NRE);
3122 do_ilists(fio, mtop->intermolecular_ilist, bRead, file_version);
3127 mtop->bIntermolecularInteractions = FALSE;
3130 do_atomtypes (fio, &(mtop->atomtypes), bRead, file_version);
3133 pr_atomtypes(debug, 0, "atomtypes", &mtop->atomtypes, TRUE);
3136 if (file_version < 57)
3138 /* Debug statements are inside do_idef */
3139 do_idef (fio, &mtop->ffparams, &mtop->moltype[0], bRead, file_version);
3140 mtop->natoms = mtop->moltype[0].atoms.nr;
3143 if (file_version >= 65)
3145 do_cmap(fio, &mtop->ffparams.cmap_grid, bRead);
3149 mtop->ffparams.cmap_grid.ngrid = 0;
3150 mtop->ffparams.cmap_grid.grid_spacing = 0;
3151 mtop->ffparams.cmap_grid.cmapdata = NULL;
3154 if (file_version >= 57)
3156 do_groups(fio, &mtop->groups, bRead, &(mtop->symtab), file_version);
3159 if (file_version < 57)
3161 do_block(fio, &mtop->moltype[0].cgs, bRead, file_version);
3162 if (bRead && gmx_debug_at)
3164 pr_block(debug, 0, "cgs", &mtop->moltype[0].cgs, TRUE);
3166 do_block(fio, &mtop->mols, bRead, file_version);
3167 /* Add the posres coordinates to the molblock */
3168 add_posres_molblock(mtop);
3172 if (file_version >= 57)
3174 done_block(&mtop->mols);
3175 mtop->mols = mtop_mols(mtop);
3179 pr_block(debug, 0, "mols", &mtop->mols, TRUE);
3183 if (file_version < 51)
3185 /* Here used to be the shake blocks */
3186 do_blocka(fio, &dumb, bRead, file_version);
3199 close_symtab(&(mtop->symtab));
3203 /* If TopOnlyOK is TRUE then we can read even future versions
3204 * of tpx files, provided the file_generation hasn't changed.
3205 * If it is FALSE, we need the inputrecord too, and bail out
3206 * if the file is newer than the program.
3208 * The version and generation if the topology (see top of this file)
3209 * are returned in the two last arguments.
3211 * If possible, we will read the inputrec even when TopOnlyOK is TRUE.
3213 static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx,
3214 gmx_bool TopOnlyOK, int *file_version,
3215 int *file_generation)
3218 char file_tag[STRLEN];
3225 /* XDR binary topology file */
3226 precision = sizeof(real);
3229 gmx_fio_do_string(fio, buf);
3230 if (strncmp(buf, "VERSION", 7))
3232 gmx_fatal(FARGS, "Can not read file %s,\n"
3233 " this file is from a GROMACS version which is older than 2.0\n"
3234 " Make a new one with grompp or use a gro or pdb file, if possible",
3235 gmx_fio_getname(fio));
3237 gmx_fio_do_int(fio, precision);
3238 bDouble = (precision == sizeof(double));
3239 if ((precision != sizeof(float)) && !bDouble)
3241 gmx_fatal(FARGS, "Unknown precision in file %s: real is %d bytes "
3242 "instead of %d or %d",
3243 gmx_fio_getname(fio), precision, sizeof(float), sizeof(double));
3245 gmx_fio_setprecision(fio, bDouble);
3246 fprintf(stderr, "Reading file %s, %s (%s precision)\n",
3247 gmx_fio_getname(fio), buf, bDouble ? "double" : "single");
3251 gmx_fio_write_string(fio, GromacsVersion());
3252 bDouble = (precision == sizeof(double));
3253 gmx_fio_setprecision(fio, bDouble);
3254 gmx_fio_do_int(fio, precision);
3256 sprintf(file_tag, "%s", tpx_tag);
3257 fgen = tpx_generation;
3260 /* Check versions! */
3261 gmx_fio_do_int(fio, fver);
3263 /* This is for backward compatibility with development versions 77-79
3264 * where the tag was, mistakenly, placed before the generation,
3265 * which would cause a segv instead of a proper error message
3266 * when reading the topology only from tpx with <77 code.
3268 if (fver >= 77 && fver <= 79)
3270 gmx_fio_do_string(fio, file_tag);
3275 gmx_fio_do_int(fio, fgen);
3284 gmx_fio_do_string(fio, file_tag);
3290 /* Versions before 77 don't have the tag, set it to release */
3291 sprintf(file_tag, "%s", TPX_TAG_RELEASE);
3294 if (strcmp(file_tag, tpx_tag) != 0)
3296 fprintf(stderr, "Note: file tpx tag '%s', software tpx tag '%s'\n",
3299 /* We only support reading tpx files with the same tag as the code
3300 * or tpx files with the release tag and with lower version number.
3302 if (strcmp(file_tag, TPX_TAG_RELEASE) != 0 && fver < tpx_version)
3304 gmx_fatal(FARGS, "tpx tag/version mismatch: reading tpx file (%s) version %d, tag '%s' with program for tpx version %d, tag '%s'",
3305 gmx_fio_getname(fio), fver, file_tag,
3306 tpx_version, tpx_tag);
3311 if (file_version != NULL)
3313 *file_version = fver;
3315 if (file_generation != NULL)
3317 *file_generation = fgen;
3321 if ((fver <= tpx_incompatible_version) ||
3322 ((fver > tpx_version) && !TopOnlyOK) ||
3323 (fgen > tpx_generation) ||
3324 tpx_version == 80) /*80 was used by both 5.0-dev and 4.6-dev*/
3326 gmx_fatal(FARGS, "reading tpx file (%s) version %d with version %d program",
3327 gmx_fio_getname(fio), fver, tpx_version);
3330 gmx_fio_do_int(fio, tpx->natoms);
3333 gmx_fio_do_int(fio, tpx->ngtc);
3341 gmx_fio_do_int(fio, idum);
3342 gmx_fio_do_real(fio, rdum);
3344 /*a better decision will eventually (5.0 or later) need to be made
3345 on how to treat the alchemical state of the system, which can now
3346 vary through a simulation, and cannot be completely described
3347 though a single lambda variable, or even a single state
3348 index. Eventually, should probably be a vector. MRS*/
3351 gmx_fio_do_int(fio, tpx->fep_state);
3353 gmx_fio_do_real(fio, tpx->lambda);
3354 gmx_fio_do_int(fio, tpx->bIr);
3355 gmx_fio_do_int(fio, tpx->bTop);
3356 gmx_fio_do_int(fio, tpx->bX);
3357 gmx_fio_do_int(fio, tpx->bV);
3358 gmx_fio_do_int(fio, tpx->bF);
3359 gmx_fio_do_int(fio, tpx->bBox);
3361 if ((fgen > tpx_generation))
3363 /* This can only happen if TopOnlyOK=TRUE */
3368 static int do_tpx(t_fileio *fio, gmx_bool bRead,
3369 t_inputrec *ir, t_state *state, rvec *f, gmx_mtop_t *mtop,
3370 gmx_bool bXVallocated)
3376 int file_version, file_generation;
3380 gmx_bool bPeriodicMols;
3384 tpx.natoms = state->natoms;
3385 tpx.ngtc = state->ngtc; /* need to add nnhpres here? */
3386 tpx.fep_state = state->fep_state;
3387 tpx.lambda = state->lambda[efptFEP];
3388 tpx.bIr = (ir != NULL);
3389 tpx.bTop = (mtop != NULL);
3390 tpx.bX = (state->x != NULL);
3391 tpx.bV = (state->v != NULL);
3392 tpx.bF = (f != NULL);
3396 TopOnlyOK = (ir == NULL);
3398 do_tpxheader(fio, bRead, &tpx, TopOnlyOK, &file_version, &file_generation);
3403 /* state->lambda = tpx.lambda;*/ /*remove this eventually? */
3404 /* The init_state calls initialize the Nose-Hoover xi integrals to zero */
3409 init_state(state, 0, tpx.ngtc, 0, 0, 0); /* nose-hoover chains */ /* eventually, need to add nnhpres here? */
3410 state->natoms = tpx.natoms;
3411 state->nalloc = tpx.natoms;
3417 init_state(state, tpx.natoms, tpx.ngtc, 0, 0, 0); /* nose-hoover chains */
3421 #define do_test(fio, b, p) if (bRead && (p != NULL) && !b) gmx_fatal(FARGS, "No %s in %s",#p, gmx_fio_getname(fio))
3423 do_test(fio, tpx.bBox, state->box);
3426 gmx_fio_ndo_rvec(fio, state->box, DIM);
3427 if (file_version >= 51)
3429 gmx_fio_ndo_rvec(fio, state->box_rel, DIM);
3433 /* We initialize box_rel after reading the inputrec */
3434 clear_mat(state->box_rel);
3436 if (file_version >= 28)
3438 gmx_fio_ndo_rvec(fio, state->boxv, DIM);
3439 if (file_version < 56)
3442 gmx_fio_ndo_rvec(fio, mdum, DIM);
3447 if (state->ngtc > 0 && file_version >= 28)
3450 /*ndo_double(state->nosehoover_xi,state->ngtc,bDum);*/
3451 /*ndo_double(state->nosehoover_vxi,state->ngtc,bDum);*/
3452 /*ndo_double(state->therm_integral,state->ngtc,bDum);*/
3453 snew(dumv, state->ngtc);
3454 if (file_version < 69)
3456 gmx_fio_ndo_real(fio, dumv, state->ngtc);
3458 /* These used to be the Berendsen tcoupl_lambda's */
3459 gmx_fio_ndo_real(fio, dumv, state->ngtc);
3463 /* Prior to tpx version 26, the inputrec was here.
3464 * I moved it to enable partial forward-compatibility
3465 * for analysis/viewer programs.
3467 if (file_version < 26)
3469 do_test(fio, tpx.bIr, ir);
3474 do_inputrec(fio, ir, bRead, file_version,
3475 mtop ? &mtop->ffparams.fudgeQQ : NULL);
3478 pr_inputrec(debug, 0, "inputrec", ir, FALSE);
3483 do_inputrec(fio, &dum_ir, bRead, file_version,
3484 mtop ? &mtop->ffparams.fudgeQQ : NULL);
3487 pr_inputrec(debug, 0, "inputrec", &dum_ir, FALSE);
3489 done_inputrec(&dum_ir);
3495 do_test(fio, tpx.bTop, mtop);
3500 do_mtop(fio, mtop, bRead, file_version);
3504 do_mtop(fio, &dum_top, bRead, file_version);
3505 done_mtop(&dum_top, TRUE);
3508 do_test(fio, tpx.bX, state->x);
3513 state->flags |= (1<<estX);
3515 gmx_fio_ndo_rvec(fio, state->x, state->natoms);
3518 do_test(fio, tpx.bV, state->v);
3523 state->flags |= (1<<estV);
3525 gmx_fio_ndo_rvec(fio, state->v, state->natoms);
3528 do_test(fio, tpx.bF, f);
3531 gmx_fio_ndo_rvec(fio, f, state->natoms);
3534 /* Starting with tpx version 26, we have the inputrec
3535 * at the end of the file, so we can ignore it
3536 * if the file is never than the software (but still the
3537 * same generation - see comments at the top of this file.
3542 bPeriodicMols = FALSE;
3543 if (file_version >= 26)
3545 do_test(fio, tpx.bIr, ir);
3548 if (file_version >= 53)
3550 /* Removed the pbc info from do_inputrec, since we always want it */
3554 bPeriodicMols = ir->bPeriodicMols;
3556 gmx_fio_do_int(fio, ePBC);
3557 gmx_fio_do_gmx_bool(fio, bPeriodicMols);
3559 if (file_generation <= tpx_generation && ir)
3561 do_inputrec(fio, ir, bRead, file_version, mtop ? &mtop->ffparams.fudgeQQ : NULL);
3564 pr_inputrec(debug, 0, "inputrec", ir, FALSE);
3566 if (file_version < 51)
3568 set_box_rel(ir, state);
3570 if (file_version < 53)
3573 bPeriodicMols = ir->bPeriodicMols;
3576 if (bRead && ir && file_version >= 53)
3578 /* We need to do this after do_inputrec, since that initializes ir */
3580 ir->bPeriodicMols = bPeriodicMols;
3589 if (state->ngtc == 0)
3591 /* Reading old version without tcoupl state data: set it */
3592 init_gtc_state(state, ir->opts.ngtc, 0, ir->opts.nhchainlength);
3594 if (tpx.bTop && mtop)
3596 if (file_version < 57)
3598 if (mtop->moltype[0].ilist[F_DISRES].nr > 0)
3600 ir->eDisre = edrSimple;
3604 ir->eDisre = edrNone;
3607 set_disres_npair(mtop);
3611 if (tpx.bTop && mtop)
3613 gmx_mtop_finalize(mtop);
3616 if (file_version >= 57)
3620 env = getenv("GMX_NOCHARGEGROUPS");
3623 sscanf(env, "%d", &ienv);
3624 fprintf(stderr, "\nFound env.var. GMX_NOCHARGEGROUPS = %d\n",
3629 "Will make single atomic charge groups in non-solvent%s\n",
3630 ienv > 1 ? " and solvent" : "");
3631 gmx_mtop_make_atomic_charge_groups(mtop, ienv == 1);
3633 fprintf(stderr, "\n");
3641 static t_fileio *open_tpx(const char *fn, const char *mode)
3643 return gmx_fio_open(fn, mode);
3646 static void close_tpx(t_fileio *fio)
3651 /************************************************************
3653 * The following routines are the exported ones
3655 ************************************************************/
3657 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
3658 int *file_version, int *file_generation)
3662 fio = open_tpx(fn, "r");
3663 do_tpxheader(fio, TRUE, tpx, TopOnlyOK, file_version, file_generation);
3667 void write_tpx_state(const char *fn,
3668 t_inputrec *ir, t_state *state, gmx_mtop_t *mtop)
3672 fio = open_tpx(fn, "w");
3673 do_tpx(fio, FALSE, ir, state, NULL, mtop, FALSE);
3677 void read_tpx_state(const char *fn,
3678 t_inputrec *ir, t_state *state, rvec *f, gmx_mtop_t *mtop)
3682 fio = open_tpx(fn, "r");
3683 do_tpx(fio, TRUE, ir, state, f, mtop, FALSE);
3687 int read_tpx(const char *fn,
3688 t_inputrec *ir, matrix box, int *natoms,
3689 rvec *x, rvec *v, rvec *f, gmx_mtop_t *mtop)
3697 fio = open_tpx(fn, "r");
3698 ePBC = do_tpx(fio, TRUE, ir, &state, f, mtop, TRUE);
3700 *natoms = state.natoms;
3703 copy_mat(state.box, box);
3712 int read_tpx_top(const char *fn,
3713 t_inputrec *ir, matrix box, int *natoms,
3714 rvec *x, rvec *v, rvec *f, t_topology *top)
3720 ePBC = read_tpx(fn, ir, box, natoms, x, v, f, &mtop);
3722 *top = gmx_mtop_t_to_t_topology(&mtop);
3727 gmx_bool fn2bTPX(const char *file)
3729 return (efTPR == fn2ftp(file));
3732 static void done_gmx_groups_t(gmx_groups_t *g)
3736 for (i = 0; (i < egcNR); i++)
3738 if (NULL != g->grps[i].nm_ind)
3740 sfree(g->grps[i].nm_ind);
3741 g->grps[i].nm_ind = NULL;
3743 if (NULL != g->grpnr[i])
3749 /* The contents of this array is in symtab, don't free it here */
3753 gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *ePBC,
3754 rvec **x, rvec **v, matrix box, gmx_bool bMass)
3757 int natoms, i, version, generation;
3758 gmx_bool bTop, bXNULL = FALSE;
3760 t_topology *topconv;
3763 bTop = fn2bTPX(infile);
3767 read_tpxheader(infile, &header, TRUE, &version, &generation);
3770 snew(*x, header.natoms);
3774 snew(*v, header.natoms);
3777 *ePBC = read_tpx(infile, NULL, box, &natoms,
3778 (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
3779 *top = gmx_mtop_t_to_t_topology(mtop);
3780 /* In this case we need to throw away the group data too */
3781 done_gmx_groups_t(&mtop->groups);
3783 strcpy(title, *top->name);
3784 tpx_make_chain_identifiers(&top->atoms, &top->mols);
3788 get_stx_coordnum(infile, &natoms);
3789 init_t_atoms(&top->atoms, natoms, (fn2ftp(infile) == efPDB));
3800 read_stx_conf(infile, title, &top->atoms, *x, (v == NULL) ? NULL : *v, ePBC, box);
3808 aps = gmx_atomprop_init();
3809 for (i = 0; (i < natoms); i++)
3811 if (!gmx_atomprop_query(aps, epropMass,
3812 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
3813 *top->atoms.atomname[i],
3814 &(top->atoms.atom[i].m)))
3818 fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
3819 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
3820 top->atoms.resinfo[top->atoms.atom[i].resind].nr,
3821 *top->atoms.atomname[i]);
3825 gmx_atomprop_destroy(aps);
3827 top->idef.ntypes = -1;