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/legacyheaders/copyrite.h"
50 #include "gromacs/legacyheaders/macros.h"
51 #include "gromacs/legacyheaders/names.h"
52 #include "gromacs/legacyheaders/txtdump.h"
53 #include "gromacs/math/vec.h"
54 #include "gromacs/topology/atomprop.h"
55 #include "gromacs/topology/block.h"
56 #include "gromacs/topology/mtop_util.h"
57 #include "gromacs/topology/symtab.h"
58 #include "gromacs/topology/topology.h"
59 #include "gromacs/utility/cstringutil.h"
60 #include "gromacs/utility/fatalerror.h"
61 #include "gromacs/utility/futil.h"
62 #include "gromacs/utility/smalloc.h"
64 #define TPX_TAG_RELEASE "release"
66 /*! \brief Tag string for the file format written to run input files
67 * written by this version of the code.
69 * Change this if you want to change the run input format in a feature
70 * branch. This ensures that there will not be different run input
71 * formats around which cannot be distinguished, while not causing
72 * problems rebasing the feature branch onto upstream changes. When
73 * merging with mainstream GROMACS, set this tag string back to
74 * TPX_TAG_RELEASE, and instead add an element to tpxv and set
75 * tpx_version to that.
77 static const char *tpx_tag = TPX_TAG_RELEASE;
79 /*! \brief Enum of values that describe the contents of a tpr file
80 * whose format matches a version number
82 * The enum helps the code be more self-documenting and ensure merges
83 * do not silently resolve when two patches make the same bump. When
84 * adding new functionality, add a new element to the end of this
85 * enumeration, change the definition of tpx_version, and write code
86 * below that does the right thing according to the value of
89 tpxv_ComputationalElectrophysiology = 96, /**< support for ion/water position swaps (computational electrophysiology) */
90 tpxv_Use64BitRandomSeed, /**< change ld_seed from int to gmx_int64_t */
91 tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, /**< potentials for supporting coarse-grained force fields */
92 tpxv_InteractiveMolecularDynamics, /**< interactive molecular dynamics (IMD) */
93 tpxv_RemoveObsoleteParameters1, /**< remove optimize_fft, dihre_fc, nstcheckpoint */
94 tpxv_PullCoordTypeGeom, /**< add pull type and geometry per group and flat-bottom */
95 tpxv_PullGeomDirRel /**< add pull geometry direction-relative */
98 /*! \brief Version number of the file format written to run input
99 * files by this version of the code.
101 * The tpx_version number should be increased whenever the file format
102 * in the main development branch changes, generally to the highest
103 * value present in tpxv. Backward compatibility for reading old run
104 * input files is maintained by checking this version number against
105 * that of the file and then using the correct code path.
107 * When developing a feature branch that needs to change the run input
108 * file format, change tpx_tag instead. */
109 static const int tpx_version = tpxv_PullGeomDirRel;
112 /* This number should only be increased when you edit the TOPOLOGY section
113 * or the HEADER of the tpx format.
114 * This way we can maintain forward compatibility too for all analysis tools
115 * and/or external programs that only need to know the atom/residue names,
116 * charges, and bond connectivity.
118 * It first appeared in tpx version 26, when I also moved the inputrecord
119 * to the end of the tpx file, so we can just skip it if we only
122 * In particular, it must be increased when adding new elements to
123 * ftupd, so that old code can read new .tpr files.
125 static const int tpx_generation = 26;
127 /* This number should be the most recent backwards incompatible version
128 * I.e., if this number is 9, we cannot read tpx version 9 with this code.
130 static const int tpx_incompatible_version = 9;
134 /* Struct used to maintain tpx compatibility when function types are added */
136 int fvnr; /* file version number in which the function type first appeared */
137 int ftype; /* function type */
141 * The entries should be ordered in:
142 * 1. ascending file version number
143 * 2. ascending function type number
145 /*static const t_ftupd ftupd[] = {
146 { 20, F_CUBICBONDS },
150 { 22, F_DISRESVIOL },
156 { 26, F_DIHRESVIOL },
157 { 30, F_CROSS_BOND_BONDS },
158 { 30, F_CROSS_BOND_ANGLES },
159 { 30, F_UREY_BRADLEY },
160 { 30, F_POLARIZATION },
164 * The entries should be ordered in:
165 * 1. ascending function type number
166 * 2. ascending file version number
168 /* question; what is the purpose of the commented code above? */
169 static const t_ftupd ftupd[] = {
170 { 20, F_CUBICBONDS },
175 { 43, F_TABBONDSNC },
176 { 70, F_RESTRBONDS },
177 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_RESTRANGLES },
178 { 76, F_LINEAR_ANGLES },
179 { 30, F_CROSS_BOND_BONDS },
180 { 30, F_CROSS_BOND_ANGLES },
181 { 30, F_UREY_BRADLEY },
182 { 34, F_QUARTIC_ANGLES },
184 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_RESTRDIHS },
185 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_CBTDIHS },
194 { 72, F_NPSOLVATION },
196 { 41, F_LJC_PAIRS_NB },
199 { 32, F_COUL_RECIP },
202 { 30, F_POLARIZATION },
205 { 22, F_DISRESVIOL },
209 { 26, F_DIHRESVIOL },
214 { 46, F_ECONSERVED },
215 { 69, F_VTEMP_NOLONGERUSED},
217 { 54, F_DVDL_CONSTR },
218 { 76, F_ANHARM_POL },
221 { 79, F_DVDL_BONDED, },
222 { 79, F_DVDL_RESTRAINT },
223 { 79, F_DVDL_TEMPERATURE },
225 #define NFTUPD asize(ftupd)
227 /* Needed for backward compatibility */
230 /**************************************************************
232 * Now the higer level routines that do io of the structures and arrays
234 **************************************************************/
235 static void do_pullgrp_tpx_pre95(t_fileio *fio,
244 gmx_fio_do_int(fio, pgrp->nat);
247 snew(pgrp->ind, pgrp->nat);
249 gmx_fio_ndo_int(fio, pgrp->ind, pgrp->nat);
250 gmx_fio_do_int(fio, pgrp->nweight);
253 snew(pgrp->weight, pgrp->nweight);
255 gmx_fio_ndo_real(fio, pgrp->weight, pgrp->nweight);
256 gmx_fio_do_int(fio, pgrp->pbcatom);
257 gmx_fio_do_rvec(fio, pcrd->vec);
258 clear_rvec(pcrd->origin);
259 gmx_fio_do_rvec(fio, tmp);
261 gmx_fio_do_real(fio, pcrd->rate);
262 gmx_fio_do_real(fio, pcrd->k);
263 if (file_version >= 56)
265 gmx_fio_do_real(fio, pcrd->kB);
273 static void do_pull_group(t_fileio *fio, t_pull_group *pgrp, gmx_bool bRead)
277 gmx_fio_do_int(fio, pgrp->nat);
280 snew(pgrp->ind, pgrp->nat);
282 gmx_fio_ndo_int(fio, pgrp->ind, pgrp->nat);
283 gmx_fio_do_int(fio, pgrp->nweight);
286 snew(pgrp->weight, pgrp->nweight);
288 gmx_fio_ndo_real(fio, pgrp->weight, pgrp->nweight);
289 gmx_fio_do_int(fio, pgrp->pbcatom);
292 static void do_pull_coord(t_fileio *fio, t_pull_coord *pcrd, int file_version,
293 int ePullOld, int eGeomOld, ivec dimOld)
297 gmx_fio_do_int(fio, pcrd->group[0]);
298 gmx_fio_do_int(fio, pcrd->group[1]);
299 if (file_version >= tpxv_PullCoordTypeGeom)
301 gmx_fio_do_int(fio, pcrd->eType);
302 gmx_fio_do_int(fio, pcrd->eGeom);
303 if (pcrd->eGeom == epullgDIRRELATIVE)
305 gmx_fio_do_int(fio, pcrd->group[2]);
306 gmx_fio_do_int(fio, pcrd->group[3]);
308 gmx_fio_do_ivec(fio, pcrd->dim);
312 pcrd->eType = ePullOld;
313 pcrd->eGeom = eGeomOld;
314 copy_ivec(dimOld, pcrd->dim);
316 gmx_fio_do_rvec(fio, pcrd->origin);
317 gmx_fio_do_rvec(fio, pcrd->vec);
318 if (file_version >= tpxv_PullCoordTypeGeom)
320 gmx_fio_do_gmx_bool(fio, pcrd->bStart);
324 /* This parameter is only printed, but not actually used by mdrun */
325 pcrd->bStart = FALSE;
327 gmx_fio_do_real(fio, pcrd->init);
328 gmx_fio_do_real(fio, pcrd->rate);
329 gmx_fio_do_real(fio, pcrd->k);
330 gmx_fio_do_real(fio, pcrd->kB);
333 static void do_expandedvals(t_fileio *fio, t_expanded *expand, t_lambda *fepvals, gmx_bool bRead, int file_version)
335 /* i is used in the ndo_double macro*/
339 int n_lambda = fepvals->n_lambda;
341 /* reset the lambda calculation window */
342 fepvals->lambda_start_n = 0;
343 fepvals->lambda_stop_n = n_lambda;
344 if (file_version >= 79)
350 snew(expand->init_lambda_weights, n_lambda);
352 gmx_fio_ndo_real(fio, expand->init_lambda_weights, n_lambda);
353 gmx_fio_do_gmx_bool(fio, expand->bInit_weights);
356 gmx_fio_do_int(fio, expand->nstexpanded);
357 gmx_fio_do_int(fio, expand->elmcmove);
358 gmx_fio_do_int(fio, expand->elamstats);
359 gmx_fio_do_int(fio, expand->lmc_repeats);
360 gmx_fio_do_int(fio, expand->gibbsdeltalam);
361 gmx_fio_do_int(fio, expand->lmc_forced_nstart);
362 gmx_fio_do_int(fio, expand->lmc_seed);
363 gmx_fio_do_real(fio, expand->mc_temp);
364 gmx_fio_do_int(fio, expand->bSymmetrizedTMatrix);
365 gmx_fio_do_int(fio, expand->nstTij);
366 gmx_fio_do_int(fio, expand->minvarmin);
367 gmx_fio_do_int(fio, expand->c_range);
368 gmx_fio_do_real(fio, expand->wl_scale);
369 gmx_fio_do_real(fio, expand->wl_ratio);
370 gmx_fio_do_real(fio, expand->init_wl_delta);
371 gmx_fio_do_gmx_bool(fio, expand->bWLoneovert);
372 gmx_fio_do_int(fio, expand->elmceq);
373 gmx_fio_do_int(fio, expand->equil_steps);
374 gmx_fio_do_int(fio, expand->equil_samples);
375 gmx_fio_do_int(fio, expand->equil_n_at_lam);
376 gmx_fio_do_real(fio, expand->equil_wl_delta);
377 gmx_fio_do_real(fio, expand->equil_ratio);
381 static void do_simtempvals(t_fileio *fio, t_simtemp *simtemp, int n_lambda, gmx_bool bRead,
384 if (file_version >= 79)
386 gmx_fio_do_int(fio, simtemp->eSimTempScale);
387 gmx_fio_do_real(fio, simtemp->simtemp_high);
388 gmx_fio_do_real(fio, simtemp->simtemp_low);
393 snew(simtemp->temperatures, n_lambda);
395 gmx_fio_ndo_real(fio, simtemp->temperatures, n_lambda);
400 static void do_imd(t_fileio *fio, t_IMD *imd, gmx_bool bRead)
402 gmx_fio_do_int(fio, imd->nat);
405 snew(imd->ind, imd->nat);
407 gmx_fio_ndo_int(fio, imd->ind, imd->nat);
410 static void do_fepvals(t_fileio *fio, t_lambda *fepvals, gmx_bool bRead, int file_version)
412 /* i is defined in the ndo_double macro; use g to iterate. */
417 /* free energy values */
419 if (file_version >= 79)
421 gmx_fio_do_int(fio, fepvals->init_fep_state);
422 gmx_fio_do_double(fio, fepvals->init_lambda);
423 gmx_fio_do_double(fio, fepvals->delta_lambda);
425 else if (file_version >= 59)
427 gmx_fio_do_double(fio, fepvals->init_lambda);
428 gmx_fio_do_double(fio, fepvals->delta_lambda);
432 gmx_fio_do_real(fio, rdum);
433 fepvals->init_lambda = rdum;
434 gmx_fio_do_real(fio, rdum);
435 fepvals->delta_lambda = rdum;
437 if (file_version >= 79)
439 gmx_fio_do_int(fio, fepvals->n_lambda);
442 snew(fepvals->all_lambda, efptNR);
444 for (g = 0; g < efptNR; g++)
446 if (fepvals->n_lambda > 0)
450 snew(fepvals->all_lambda[g], fepvals->n_lambda);
452 gmx_fio_ndo_double(fio, fepvals->all_lambda[g], fepvals->n_lambda);
453 gmx_fio_ndo_int(fio, fepvals->separate_dvdl, efptNR);
455 else if (fepvals->init_lambda >= 0)
457 fepvals->separate_dvdl[efptFEP] = TRUE;
461 else if (file_version >= 64)
463 gmx_fio_do_int(fio, fepvals->n_lambda);
468 snew(fepvals->all_lambda, efptNR);
469 /* still allocate the all_lambda array's contents. */
470 for (g = 0; g < efptNR; g++)
472 if (fepvals->n_lambda > 0)
474 snew(fepvals->all_lambda[g], fepvals->n_lambda);
478 gmx_fio_ndo_double(fio, fepvals->all_lambda[efptFEP],
480 if (fepvals->init_lambda >= 0)
484 fepvals->separate_dvdl[efptFEP] = TRUE;
488 /* copy the contents of the efptFEP lambda component to all
489 the other components */
490 for (g = 0; g < efptNR; g++)
492 for (h = 0; h < fepvals->n_lambda; h++)
496 fepvals->all_lambda[g][h] =
497 fepvals->all_lambda[efptFEP][h];
506 fepvals->n_lambda = 0;
507 fepvals->all_lambda = NULL;
508 if (fepvals->init_lambda >= 0)
510 fepvals->separate_dvdl[efptFEP] = TRUE;
513 if (file_version >= 13)
515 gmx_fio_do_real(fio, fepvals->sc_alpha);
519 fepvals->sc_alpha = 0;
521 if (file_version >= 38)
523 gmx_fio_do_int(fio, fepvals->sc_power);
527 fepvals->sc_power = 2;
529 if (file_version >= 79)
531 gmx_fio_do_real(fio, fepvals->sc_r_power);
535 fepvals->sc_r_power = 6.0;
537 if (file_version >= 15)
539 gmx_fio_do_real(fio, fepvals->sc_sigma);
543 fepvals->sc_sigma = 0.3;
547 if (file_version >= 71)
549 fepvals->sc_sigma_min = fepvals->sc_sigma;
553 fepvals->sc_sigma_min = 0;
556 if (file_version >= 79)
558 gmx_fio_do_int(fio, fepvals->bScCoul);
562 fepvals->bScCoul = TRUE;
564 if (file_version >= 64)
566 gmx_fio_do_int(fio, fepvals->nstdhdl);
570 fepvals->nstdhdl = 1;
573 if (file_version >= 73)
575 gmx_fio_do_int(fio, fepvals->separate_dhdl_file);
576 gmx_fio_do_int(fio, fepvals->dhdl_derivatives);
580 fepvals->separate_dhdl_file = esepdhdlfileYES;
581 fepvals->dhdl_derivatives = edhdlderivativesYES;
583 if (file_version >= 71)
585 gmx_fio_do_int(fio, fepvals->dh_hist_size);
586 gmx_fio_do_double(fio, fepvals->dh_hist_spacing);
590 fepvals->dh_hist_size = 0;
591 fepvals->dh_hist_spacing = 0.1;
593 if (file_version >= 79)
595 gmx_fio_do_int(fio, fepvals->edHdLPrintEnergy);
599 fepvals->edHdLPrintEnergy = edHdLPrintEnergyNO;
602 /* handle lambda_neighbors */
603 if ((file_version >= 83 && file_version < 90) || file_version >= 92)
605 gmx_fio_do_int(fio, fepvals->lambda_neighbors);
606 if ( (fepvals->lambda_neighbors >= 0) && (fepvals->init_fep_state >= 0) &&
607 (fepvals->init_lambda < 0) )
609 fepvals->lambda_start_n = (fepvals->init_fep_state -
610 fepvals->lambda_neighbors);
611 fepvals->lambda_stop_n = (fepvals->init_fep_state +
612 fepvals->lambda_neighbors + 1);
613 if (fepvals->lambda_start_n < 0)
615 fepvals->lambda_start_n = 0;;
617 if (fepvals->lambda_stop_n >= fepvals->n_lambda)
619 fepvals->lambda_stop_n = fepvals->n_lambda;
624 fepvals->lambda_start_n = 0;
625 fepvals->lambda_stop_n = fepvals->n_lambda;
630 fepvals->lambda_start_n = 0;
631 fepvals->lambda_stop_n = fepvals->n_lambda;
635 static void do_pull(t_fileio *fio, pull_params_t *pull, gmx_bool bRead,
636 int file_version, int ePullOld)
642 if (file_version >= 95)
644 gmx_fio_do_int(fio, pull->ngroup);
646 gmx_fio_do_int(fio, pull->ncoord);
647 if (file_version < 95)
649 pull->ngroup = pull->ncoord + 1;
651 if (file_version < tpxv_PullCoordTypeGeom)
655 gmx_fio_do_int(fio, eGeomOld);
656 gmx_fio_do_ivec(fio, dimOld);
657 /* The inner cylinder radius, now removed */
658 gmx_fio_do_real(fio, dum);
660 gmx_fio_do_real(fio, pull->cylinder_r);
661 gmx_fio_do_real(fio, pull->constr_tol);
662 if (file_version >= 95)
664 gmx_fio_do_int(fio, pull->bPrintCOM1);
665 /* With file_version < 95 this value is set below */
667 if (file_version >= tpxv_PullCoordTypeGeom)
669 gmx_fio_do_int(fio, pull->bPrintCOM2);
670 gmx_fio_do_int(fio, pull->bPrintRefValue);
671 gmx_fio_do_int(fio, pull->bPrintComp);
675 pull->bPrintCOM2 = FALSE;
676 pull->bPrintRefValue = FALSE;
677 pull->bPrintComp = TRUE;
679 gmx_fio_do_int(fio, pull->nstxout);
680 gmx_fio_do_int(fio, pull->nstfout);
683 snew(pull->group, pull->ngroup);
684 snew(pull->coord, pull->ncoord);
686 if (file_version < 95)
688 /* epullgPOS for position pulling, before epullgDIRPBC was removed */
689 if (eGeomOld == epullgDIRPBC)
691 gmx_fatal(FARGS, "pull-geometry=position is no longer supported");
693 if (eGeomOld > epullgDIRPBC)
698 for (g = 0; g < pull->ngroup; g++)
700 /* We read and ignore a pull coordinate for group 0 */
701 do_pullgrp_tpx_pre95(fio, &pull->group[g], &pull->coord[max(g-1, 0)],
702 bRead, file_version);
705 pull->coord[g-1].group[0] = 0;
706 pull->coord[g-1].group[1] = g;
710 pull->bPrintCOM1 = (pull->group[0].nat > 0);
714 for (g = 0; g < pull->ngroup; g++)
716 do_pull_group(fio, &pull->group[g], bRead);
718 for (g = 0; g < pull->ncoord; g++)
720 do_pull_coord(fio, &pull->coord[g],
721 file_version, ePullOld, eGeomOld, dimOld);
727 static void do_rotgrp(t_fileio *fio, t_rotgrp *rotg, gmx_bool bRead)
731 gmx_fio_do_int(fio, rotg->eType);
732 gmx_fio_do_int(fio, rotg->bMassW);
733 gmx_fio_do_int(fio, rotg->nat);
736 snew(rotg->ind, rotg->nat);
738 gmx_fio_ndo_int(fio, rotg->ind, rotg->nat);
741 snew(rotg->x_ref, rotg->nat);
743 gmx_fio_ndo_rvec(fio, rotg->x_ref, rotg->nat);
744 gmx_fio_do_rvec(fio, rotg->vec);
745 gmx_fio_do_rvec(fio, rotg->pivot);
746 gmx_fio_do_real(fio, rotg->rate);
747 gmx_fio_do_real(fio, rotg->k);
748 gmx_fio_do_real(fio, rotg->slab_dist);
749 gmx_fio_do_real(fio, rotg->min_gaussian);
750 gmx_fio_do_real(fio, rotg->eps);
751 gmx_fio_do_int(fio, rotg->eFittype);
752 gmx_fio_do_int(fio, rotg->PotAngle_nstep);
753 gmx_fio_do_real(fio, rotg->PotAngle_step);
756 static void do_rot(t_fileio *fio, t_rot *rot, gmx_bool bRead)
760 gmx_fio_do_int(fio, rot->ngrp);
761 gmx_fio_do_int(fio, rot->nstrout);
762 gmx_fio_do_int(fio, rot->nstsout);
765 snew(rot->grp, rot->ngrp);
767 for (g = 0; g < rot->ngrp; g++)
769 do_rotgrp(fio, &rot->grp[g], bRead);
774 static void do_swapcoords(t_fileio *fio, t_swapcoords *swap, gmx_bool bRead)
779 gmx_fio_do_int(fio, swap->nat);
780 gmx_fio_do_int(fio, swap->nat_sol);
781 for (j = 0; j < 2; j++)
783 gmx_fio_do_int(fio, swap->nat_split[j]);
784 gmx_fio_do_int(fio, swap->massw_split[j]);
786 gmx_fio_do_int(fio, swap->nstswap);
787 gmx_fio_do_int(fio, swap->nAverage);
788 gmx_fio_do_real(fio, swap->threshold);
789 gmx_fio_do_real(fio, swap->cyl0r);
790 gmx_fio_do_real(fio, swap->cyl0u);
791 gmx_fio_do_real(fio, swap->cyl0l);
792 gmx_fio_do_real(fio, swap->cyl1r);
793 gmx_fio_do_real(fio, swap->cyl1u);
794 gmx_fio_do_real(fio, swap->cyl1l);
798 snew(swap->ind, swap->nat);
799 snew(swap->ind_sol, swap->nat_sol);
800 for (j = 0; j < 2; j++)
802 snew(swap->ind_split[j], swap->nat_split[j]);
806 gmx_fio_ndo_int(fio, swap->ind, swap->nat);
807 gmx_fio_ndo_int(fio, swap->ind_sol, swap->nat_sol);
808 for (j = 0; j < 2; j++)
810 gmx_fio_ndo_int(fio, swap->ind_split[j], swap->nat_split[j]);
813 for (j = 0; j < eCompNR; j++)
815 gmx_fio_do_int(fio, swap->nanions[j]);
816 gmx_fio_do_int(fio, swap->ncations[j]);
822 static void do_inputrec(t_fileio *fio, t_inputrec *ir, gmx_bool bRead,
823 int file_version, real *fudgeQQ)
825 int i, j, k, *tmp, idum = 0;
828 gmx_bool bSimAnn, bdum = 0;
829 real zerotemptime, finish_t, init_temp, finish_temp;
831 if (file_version != tpx_version)
833 /* Give a warning about features that are not accessible */
834 fprintf(stderr, "Note: file tpx version %d, software tpx version %d\n",
835 file_version, tpx_version);
843 if (file_version == 0)
848 /* Basic inputrec stuff */
849 gmx_fio_do_int(fio, ir->eI);
850 if (file_version >= 62)
852 gmx_fio_do_int64(fio, ir->nsteps);
856 gmx_fio_do_int(fio, idum);
860 if (file_version > 25)
862 if (file_version >= 62)
864 gmx_fio_do_int64(fio, ir->init_step);
868 gmx_fio_do_int(fio, idum);
869 ir->init_step = idum;
877 if (file_version >= 58)
879 gmx_fio_do_int(fio, ir->simulation_part);
883 ir->simulation_part = 1;
886 if (file_version >= 67)
888 gmx_fio_do_int(fio, ir->nstcalcenergy);
892 ir->nstcalcenergy = 1;
894 if (file_version < 53)
896 /* The pbc info has been moved out of do_inputrec,
897 * since we always want it, also without reading the inputrec.
899 gmx_fio_do_int(fio, ir->ePBC);
900 if ((file_version <= 15) && (ir->ePBC == 2))
904 if (file_version >= 45)
906 gmx_fio_do_int(fio, ir->bPeriodicMols);
913 ir->bPeriodicMols = TRUE;
917 ir->bPeriodicMols = FALSE;
921 if (file_version >= 81)
923 gmx_fio_do_int(fio, ir->cutoff_scheme);
924 if (file_version < 94)
926 ir->cutoff_scheme = 1 - ir->cutoff_scheme;
931 ir->cutoff_scheme = ecutsGROUP;
933 gmx_fio_do_int(fio, ir->ns_type);
934 gmx_fio_do_int(fio, ir->nstlist);
935 gmx_fio_do_int(fio, idum); /* used to be ndelta; not used anymore */
936 if (file_version < 41)
938 gmx_fio_do_int(fio, idum);
939 gmx_fio_do_int(fio, idum);
941 if (file_version >= 45)
943 gmx_fio_do_real(fio, ir->rtpi);
949 gmx_fio_do_int(fio, ir->nstcomm);
950 if (file_version > 34)
952 gmx_fio_do_int(fio, ir->comm_mode);
954 else if (ir->nstcomm < 0)
956 ir->comm_mode = ecmANGULAR;
960 ir->comm_mode = ecmLINEAR;
962 ir->nstcomm = abs(ir->nstcomm);
964 /* ignore nstcheckpoint */
965 if (file_version > 25 && file_version < tpxv_RemoveObsoleteParameters1)
967 gmx_fio_do_int(fio, idum);
970 gmx_fio_do_int(fio, ir->nstcgsteep);
972 if (file_version >= 30)
974 gmx_fio_do_int(fio, ir->nbfgscorr);
981 gmx_fio_do_int(fio, ir->nstlog);
982 gmx_fio_do_int(fio, ir->nstxout);
983 gmx_fio_do_int(fio, ir->nstvout);
984 gmx_fio_do_int(fio, ir->nstfout);
985 gmx_fio_do_int(fio, ir->nstenergy);
986 gmx_fio_do_int(fio, ir->nstxout_compressed);
987 if (file_version >= 59)
989 gmx_fio_do_double(fio, ir->init_t);
990 gmx_fio_do_double(fio, ir->delta_t);
994 gmx_fio_do_real(fio, rdum);
996 gmx_fio_do_real(fio, rdum);
999 gmx_fio_do_real(fio, ir->x_compression_precision);
1000 if (file_version < 19)
1002 gmx_fio_do_int(fio, idum);
1003 gmx_fio_do_int(fio, idum);
1005 if (file_version < 18)
1007 gmx_fio_do_int(fio, idum);
1009 if (file_version >= 81)
1011 gmx_fio_do_real(fio, ir->verletbuf_tol);
1015 ir->verletbuf_tol = 0;
1017 gmx_fio_do_real(fio, ir->rlist);
1018 if (file_version >= 67)
1020 gmx_fio_do_real(fio, ir->rlistlong);
1022 if (file_version >= 82 && file_version != 90)
1024 gmx_fio_do_int(fio, ir->nstcalclr);
1028 /* Calculate at NS steps */
1029 ir->nstcalclr = ir->nstlist;
1031 gmx_fio_do_int(fio, ir->coulombtype);
1032 if (file_version < 32 && ir->coulombtype == eelRF)
1034 ir->coulombtype = eelRF_NEC;
1036 if (file_version >= 81)
1038 gmx_fio_do_int(fio, ir->coulomb_modifier);
1042 ir->coulomb_modifier = (ir->cutoff_scheme == ecutsVERLET ? eintmodPOTSHIFT : eintmodNONE);
1044 gmx_fio_do_real(fio, ir->rcoulomb_switch);
1045 gmx_fio_do_real(fio, ir->rcoulomb);
1046 gmx_fio_do_int(fio, ir->vdwtype);
1047 if (file_version >= 81)
1049 gmx_fio_do_int(fio, ir->vdw_modifier);
1053 ir->vdw_modifier = (ir->cutoff_scheme == ecutsVERLET ? eintmodPOTSHIFT : eintmodNONE);
1055 gmx_fio_do_real(fio, ir->rvdw_switch);
1056 gmx_fio_do_real(fio, ir->rvdw);
1057 if (file_version < 67)
1059 ir->rlistlong = max_cutoff(ir->rlist, max_cutoff(ir->rvdw, ir->rcoulomb));
1061 gmx_fio_do_int(fio, ir->eDispCorr);
1062 gmx_fio_do_real(fio, ir->epsilon_r);
1063 if (file_version >= 37)
1065 gmx_fio_do_real(fio, ir->epsilon_rf);
1069 if (EEL_RF(ir->coulombtype))
1071 ir->epsilon_rf = ir->epsilon_r;
1072 ir->epsilon_r = 1.0;
1076 ir->epsilon_rf = 1.0;
1079 if (file_version >= 29)
1081 gmx_fio_do_real(fio, ir->tabext);
1088 if (file_version > 25)
1090 gmx_fio_do_int(fio, ir->gb_algorithm);
1091 gmx_fio_do_int(fio, ir->nstgbradii);
1092 gmx_fio_do_real(fio, ir->rgbradii);
1093 gmx_fio_do_real(fio, ir->gb_saltconc);
1094 gmx_fio_do_int(fio, ir->implicit_solvent);
1098 ir->gb_algorithm = egbSTILL;
1101 ir->gb_saltconc = 0;
1102 ir->implicit_solvent = eisNO;
1104 if (file_version >= 55)
1106 gmx_fio_do_real(fio, ir->gb_epsilon_solvent);
1107 gmx_fio_do_real(fio, ir->gb_obc_alpha);
1108 gmx_fio_do_real(fio, ir->gb_obc_beta);
1109 gmx_fio_do_real(fio, ir->gb_obc_gamma);
1110 if (file_version >= 60)
1112 gmx_fio_do_real(fio, ir->gb_dielectric_offset);
1113 gmx_fio_do_int(fio, ir->sa_algorithm);
1117 ir->gb_dielectric_offset = 0.009;
1118 ir->sa_algorithm = esaAPPROX;
1120 gmx_fio_do_real(fio, ir->sa_surface_tension);
1122 /* Override sa_surface_tension if it is not changed in the mpd-file */
1123 if (ir->sa_surface_tension < 0)
1125 if (ir->gb_algorithm == egbSTILL)
1127 ir->sa_surface_tension = 0.0049 * 100 * CAL2JOULE;
1129 else if (ir->gb_algorithm == egbHCT || ir->gb_algorithm == egbOBC)
1131 ir->sa_surface_tension = 0.0054 * 100 * CAL2JOULE;
1138 /* Better use sensible values than insane (0.0) ones... */
1139 ir->gb_epsilon_solvent = 80;
1140 ir->gb_obc_alpha = 1.0;
1141 ir->gb_obc_beta = 0.8;
1142 ir->gb_obc_gamma = 4.85;
1143 ir->sa_surface_tension = 2.092;
1147 if (file_version >= 81)
1149 gmx_fio_do_real(fio, ir->fourier_spacing);
1153 ir->fourier_spacing = 0.0;
1155 gmx_fio_do_int(fio, ir->nkx);
1156 gmx_fio_do_int(fio, ir->nky);
1157 gmx_fio_do_int(fio, ir->nkz);
1158 gmx_fio_do_int(fio, ir->pme_order);
1159 gmx_fio_do_real(fio, ir->ewald_rtol);
1161 if (file_version >= 93)
1163 gmx_fio_do_real(fio, ir->ewald_rtol_lj);
1167 ir->ewald_rtol_lj = ir->ewald_rtol;
1170 if (file_version >= 24)
1172 gmx_fio_do_int(fio, ir->ewald_geometry);
1176 ir->ewald_geometry = eewg3D;
1179 if (file_version <= 17)
1181 ir->epsilon_surface = 0;
1182 if (file_version == 17)
1184 gmx_fio_do_int(fio, idum);
1189 gmx_fio_do_real(fio, ir->epsilon_surface);
1192 /* ignore bOptFFT */
1193 if (file_version < tpxv_RemoveObsoleteParameters1)
1195 gmx_fio_do_gmx_bool(fio, bdum);
1198 if (file_version >= 93)
1200 gmx_fio_do_int(fio, ir->ljpme_combination_rule);
1202 gmx_fio_do_gmx_bool(fio, ir->bContinuation);
1203 gmx_fio_do_int(fio, ir->etc);
1204 /* before version 18, ir->etc was a gmx_bool (ir->btc),
1205 * but the values 0 and 1 still mean no and
1206 * berendsen temperature coupling, respectively.
1208 if (file_version >= 79)
1210 gmx_fio_do_gmx_bool(fio, ir->bPrintNHChains);
1212 if (file_version >= 71)
1214 gmx_fio_do_int(fio, ir->nsttcouple);
1218 ir->nsttcouple = ir->nstcalcenergy;
1220 if (file_version <= 15)
1222 gmx_fio_do_int(fio, idum);
1224 if (file_version <= 17)
1226 gmx_fio_do_int(fio, ir->epct);
1227 if (file_version <= 15)
1231 ir->epct = epctSURFACETENSION;
1233 gmx_fio_do_int(fio, idum);
1236 /* we have removed the NO alternative at the beginning */
1240 ir->epct = epctISOTROPIC;
1244 ir->epc = epcBERENDSEN;
1249 gmx_fio_do_int(fio, ir->epc);
1250 gmx_fio_do_int(fio, ir->epct);
1252 if (file_version >= 71)
1254 gmx_fio_do_int(fio, ir->nstpcouple);
1258 ir->nstpcouple = ir->nstcalcenergy;
1260 gmx_fio_do_real(fio, ir->tau_p);
1261 if (file_version <= 15)
1263 gmx_fio_do_rvec(fio, vdum);
1264 clear_mat(ir->ref_p);
1265 for (i = 0; i < DIM; i++)
1267 ir->ref_p[i][i] = vdum[i];
1272 gmx_fio_do_rvec(fio, ir->ref_p[XX]);
1273 gmx_fio_do_rvec(fio, ir->ref_p[YY]);
1274 gmx_fio_do_rvec(fio, ir->ref_p[ZZ]);
1276 if (file_version <= 15)
1278 gmx_fio_do_rvec(fio, vdum);
1279 clear_mat(ir->compress);
1280 for (i = 0; i < DIM; i++)
1282 ir->compress[i][i] = vdum[i];
1287 gmx_fio_do_rvec(fio, ir->compress[XX]);
1288 gmx_fio_do_rvec(fio, ir->compress[YY]);
1289 gmx_fio_do_rvec(fio, ir->compress[ZZ]);
1291 if (file_version >= 47)
1293 gmx_fio_do_int(fio, ir->refcoord_scaling);
1294 gmx_fio_do_rvec(fio, ir->posres_com);
1295 gmx_fio_do_rvec(fio, ir->posres_comB);
1299 ir->refcoord_scaling = erscNO;
1300 clear_rvec(ir->posres_com);
1301 clear_rvec(ir->posres_comB);
1303 if ((file_version > 25) && (file_version < 79))
1305 gmx_fio_do_int(fio, ir->andersen_seed);
1309 ir->andersen_seed = 0;
1311 if (file_version < 26)
1313 gmx_fio_do_gmx_bool(fio, bSimAnn);
1314 gmx_fio_do_real(fio, zerotemptime);
1317 if (file_version < 37)
1319 gmx_fio_do_real(fio, rdum);
1322 gmx_fio_do_real(fio, ir->shake_tol);
1323 if (file_version < 54)
1325 gmx_fio_do_real(fio, *fudgeQQ);
1328 gmx_fio_do_int(fio, ir->efep);
1329 if (file_version <= 14 && ir->efep != efepNO)
1333 do_fepvals(fio, ir->fepvals, bRead, file_version);
1335 if (file_version >= 79)
1337 gmx_fio_do_gmx_bool(fio, ir->bSimTemp);
1340 ir->bSimTemp = TRUE;
1345 ir->bSimTemp = FALSE;
1349 do_simtempvals(fio, ir->simtempvals, ir->fepvals->n_lambda, bRead, file_version);
1352 if (file_version >= 79)
1354 gmx_fio_do_gmx_bool(fio, ir->bExpanded);
1357 ir->bExpanded = TRUE;
1361 ir->bExpanded = FALSE;
1366 do_expandedvals(fio, ir->expandedvals, ir->fepvals, bRead, file_version);
1368 if (file_version >= 57)
1370 gmx_fio_do_int(fio, ir->eDisre);
1372 gmx_fio_do_int(fio, ir->eDisreWeighting);
1373 if (file_version < 22)
1375 if (ir->eDisreWeighting == 0)
1377 ir->eDisreWeighting = edrwEqual;
1381 ir->eDisreWeighting = edrwConservative;
1384 gmx_fio_do_gmx_bool(fio, ir->bDisreMixed);
1385 gmx_fio_do_real(fio, ir->dr_fc);
1386 gmx_fio_do_real(fio, ir->dr_tau);
1387 gmx_fio_do_int(fio, ir->nstdisreout);
1388 if (file_version >= 22)
1390 gmx_fio_do_real(fio, ir->orires_fc);
1391 gmx_fio_do_real(fio, ir->orires_tau);
1392 gmx_fio_do_int(fio, ir->nstorireout);
1398 ir->nstorireout = 0;
1401 /* ignore dihre_fc */
1402 if (file_version >= 26 && file_version < 79)
1404 gmx_fio_do_real(fio, rdum);
1405 if (file_version < 56)
1407 gmx_fio_do_real(fio, rdum);
1408 gmx_fio_do_int(fio, idum);
1412 gmx_fio_do_real(fio, ir->em_stepsize);
1413 gmx_fio_do_real(fio, ir->em_tol);
1414 if (file_version >= 22)
1416 gmx_fio_do_gmx_bool(fio, ir->bShakeSOR);
1420 ir->bShakeSOR = TRUE;
1422 if (file_version >= 11)
1424 gmx_fio_do_int(fio, ir->niter);
1429 fprintf(stderr, "Note: niter not in run input file, setting it to %d\n",
1432 if (file_version >= 21)
1434 gmx_fio_do_real(fio, ir->fc_stepsize);
1438 ir->fc_stepsize = 0;
1440 gmx_fio_do_int(fio, ir->eConstrAlg);
1441 gmx_fio_do_int(fio, ir->nProjOrder);
1442 gmx_fio_do_real(fio, ir->LincsWarnAngle);
1443 if (file_version <= 14)
1445 gmx_fio_do_int(fio, idum);
1447 if (file_version >= 26)
1449 gmx_fio_do_int(fio, ir->nLincsIter);
1454 fprintf(stderr, "Note: nLincsIter not in run input file, setting it to %d\n",
1457 if (file_version < 33)
1459 gmx_fio_do_real(fio, bd_temp);
1461 gmx_fio_do_real(fio, ir->bd_fric);
1462 if (file_version >= tpxv_Use64BitRandomSeed)
1464 gmx_fio_do_int64(fio, ir->ld_seed);
1468 gmx_fio_do_int(fio, idum);
1471 if (file_version >= 33)
1473 for (i = 0; i < DIM; i++)
1475 gmx_fio_do_rvec(fio, ir->deform[i]);
1480 for (i = 0; i < DIM; i++)
1482 clear_rvec(ir->deform[i]);
1485 if (file_version >= 14)
1487 gmx_fio_do_real(fio, ir->cos_accel);
1493 gmx_fio_do_int(fio, ir->userint1);
1494 gmx_fio_do_int(fio, ir->userint2);
1495 gmx_fio_do_int(fio, ir->userint3);
1496 gmx_fio_do_int(fio, ir->userint4);
1497 gmx_fio_do_real(fio, ir->userreal1);
1498 gmx_fio_do_real(fio, ir->userreal2);
1499 gmx_fio_do_real(fio, ir->userreal3);
1500 gmx_fio_do_real(fio, ir->userreal4);
1503 if (file_version >= 77)
1505 gmx_fio_do_gmx_bool(fio, ir->bAdress);
1510 snew(ir->adress, 1);
1512 gmx_fio_do_int(fio, ir->adress->type);
1513 gmx_fio_do_real(fio, ir->adress->const_wf);
1514 gmx_fio_do_real(fio, ir->adress->ex_width);
1515 gmx_fio_do_real(fio, ir->adress->hy_width);
1516 gmx_fio_do_int(fio, ir->adress->icor);
1517 gmx_fio_do_int(fio, ir->adress->site);
1518 gmx_fio_do_rvec(fio, ir->adress->refs);
1519 gmx_fio_do_int(fio, ir->adress->n_tf_grps);
1520 gmx_fio_do_real(fio, ir->adress->ex_forcecap);
1521 gmx_fio_do_int(fio, ir->adress->n_energy_grps);
1522 gmx_fio_do_int(fio, ir->adress->do_hybridpairs);
1526 snew(ir->adress->tf_table_index, ir->adress->n_tf_grps);
1528 if (ir->adress->n_tf_grps > 0)
1530 gmx_fio_ndo_int(fio, ir->adress->tf_table_index, ir->adress->n_tf_grps);
1534 snew(ir->adress->group_explicit, ir->adress->n_energy_grps);
1536 if (ir->adress->n_energy_grps > 0)
1538 gmx_fio_ndo_int(fio, ir->adress->group_explicit, ir->adress->n_energy_grps);
1544 ir->bAdress = FALSE;
1548 if (file_version >= 48)
1552 if (file_version >= tpxv_PullCoordTypeGeom)
1554 gmx_fio_do_gmx_bool(fio, ir->bPull);
1558 gmx_fio_do_int(fio, ePullOld);
1559 ir->bPull = (ePullOld > 0);
1560 /* We removed the first ePull=ePullNo for the enum */
1569 do_pull(fio, ir->pull, bRead, file_version, ePullOld);
1577 /* Enforced rotation */
1578 if (file_version >= 74)
1580 gmx_fio_do_int(fio, ir->bRot);
1581 if (ir->bRot == TRUE)
1587 do_rot(fio, ir->rot, bRead);
1595 /* Interactive molecular dynamics */
1596 if (file_version >= tpxv_InteractiveMolecularDynamics)
1598 gmx_fio_do_int(fio, ir->bIMD);
1599 if (TRUE == ir->bIMD)
1605 do_imd(fio, ir->imd, bRead);
1610 /* We don't support IMD sessions for old .tpr files */
1615 gmx_fio_do_int(fio, ir->opts.ngtc);
1616 if (file_version >= 69)
1618 gmx_fio_do_int(fio, ir->opts.nhchainlength);
1622 ir->opts.nhchainlength = 1;
1624 gmx_fio_do_int(fio, ir->opts.ngacc);
1625 gmx_fio_do_int(fio, ir->opts.ngfrz);
1626 gmx_fio_do_int(fio, ir->opts.ngener);
1630 snew(ir->opts.nrdf, ir->opts.ngtc);
1631 snew(ir->opts.ref_t, ir->opts.ngtc);
1632 snew(ir->opts.annealing, ir->opts.ngtc);
1633 snew(ir->opts.anneal_npoints, ir->opts.ngtc);
1634 snew(ir->opts.anneal_time, ir->opts.ngtc);
1635 snew(ir->opts.anneal_temp, ir->opts.ngtc);
1636 snew(ir->opts.tau_t, ir->opts.ngtc);
1637 snew(ir->opts.nFreeze, ir->opts.ngfrz);
1638 snew(ir->opts.acc, ir->opts.ngacc);
1639 snew(ir->opts.egp_flags, ir->opts.ngener*ir->opts.ngener);
1641 if (ir->opts.ngtc > 0)
1643 if (bRead && file_version < 13)
1645 snew(tmp, ir->opts.ngtc);
1646 gmx_fio_ndo_int(fio, tmp, ir->opts.ngtc);
1647 for (i = 0; i < ir->opts.ngtc; i++)
1649 ir->opts.nrdf[i] = tmp[i];
1655 gmx_fio_ndo_real(fio, ir->opts.nrdf, ir->opts.ngtc);
1657 gmx_fio_ndo_real(fio, ir->opts.ref_t, ir->opts.ngtc);
1658 gmx_fio_ndo_real(fio, ir->opts.tau_t, ir->opts.ngtc);
1659 if (file_version < 33 && ir->eI == eiBD)
1661 for (i = 0; i < ir->opts.ngtc; i++)
1663 ir->opts.tau_t[i] = bd_temp;
1667 if (ir->opts.ngfrz > 0)
1669 gmx_fio_ndo_ivec(fio, ir->opts.nFreeze, ir->opts.ngfrz);
1671 if (ir->opts.ngacc > 0)
1673 gmx_fio_ndo_rvec(fio, ir->opts.acc, ir->opts.ngacc);
1675 if (file_version >= 12)
1677 gmx_fio_ndo_int(fio, ir->opts.egp_flags,
1678 ir->opts.ngener*ir->opts.ngener);
1681 if (bRead && file_version < 26)
1683 for (i = 0; i < ir->opts.ngtc; i++)
1687 ir->opts.annealing[i] = eannSINGLE;
1688 ir->opts.anneal_npoints[i] = 2;
1689 snew(ir->opts.anneal_time[i], 2);
1690 snew(ir->opts.anneal_temp[i], 2);
1691 /* calculate the starting/ending temperatures from reft, zerotemptime, and nsteps */
1692 finish_t = ir->init_t + ir->nsteps * ir->delta_t;
1693 init_temp = ir->opts.ref_t[i]*(1-ir->init_t/zerotemptime);
1694 finish_temp = ir->opts.ref_t[i]*(1-finish_t/zerotemptime);
1695 ir->opts.anneal_time[i][0] = ir->init_t;
1696 ir->opts.anneal_time[i][1] = finish_t;
1697 ir->opts.anneal_temp[i][0] = init_temp;
1698 ir->opts.anneal_temp[i][1] = finish_temp;
1702 ir->opts.annealing[i] = eannNO;
1703 ir->opts.anneal_npoints[i] = 0;
1709 /* file version 26 or later */
1710 /* First read the lists with annealing and npoints for each group */
1711 gmx_fio_ndo_int(fio, ir->opts.annealing, ir->opts.ngtc);
1712 gmx_fio_ndo_int(fio, ir->opts.anneal_npoints, ir->opts.ngtc);
1713 for (j = 0; j < (ir->opts.ngtc); j++)
1715 k = ir->opts.anneal_npoints[j];
1718 snew(ir->opts.anneal_time[j], k);
1719 snew(ir->opts.anneal_temp[j], k);
1721 gmx_fio_ndo_real(fio, ir->opts.anneal_time[j], k);
1722 gmx_fio_ndo_real(fio, ir->opts.anneal_temp[j], k);
1726 if (file_version >= 45)
1728 gmx_fio_do_int(fio, ir->nwall);
1729 gmx_fio_do_int(fio, ir->wall_type);
1730 if (file_version >= 50)
1732 gmx_fio_do_real(fio, ir->wall_r_linpot);
1736 ir->wall_r_linpot = -1;
1738 gmx_fio_do_int(fio, ir->wall_atomtype[0]);
1739 gmx_fio_do_int(fio, ir->wall_atomtype[1]);
1740 gmx_fio_do_real(fio, ir->wall_density[0]);
1741 gmx_fio_do_real(fio, ir->wall_density[1]);
1742 gmx_fio_do_real(fio, ir->wall_ewald_zfac);
1748 ir->wall_atomtype[0] = -1;
1749 ir->wall_atomtype[1] = -1;
1750 ir->wall_density[0] = 0;
1751 ir->wall_density[1] = 0;
1752 ir->wall_ewald_zfac = 3;
1754 /* Cosine stuff for electric fields */
1755 for (j = 0; (j < DIM); j++)
1757 gmx_fio_do_int(fio, ir->ex[j].n);
1758 gmx_fio_do_int(fio, ir->et[j].n);
1761 snew(ir->ex[j].a, ir->ex[j].n);
1762 snew(ir->ex[j].phi, ir->ex[j].n);
1763 snew(ir->et[j].a, ir->et[j].n);
1764 snew(ir->et[j].phi, ir->et[j].n);
1766 gmx_fio_ndo_real(fio, ir->ex[j].a, ir->ex[j].n);
1767 gmx_fio_ndo_real(fio, ir->ex[j].phi, ir->ex[j].n);
1768 gmx_fio_ndo_real(fio, ir->et[j].a, ir->et[j].n);
1769 gmx_fio_ndo_real(fio, ir->et[j].phi, ir->et[j].n);
1773 if (file_version >= tpxv_ComputationalElectrophysiology)
1775 gmx_fio_do_int(fio, ir->eSwapCoords);
1776 if (ir->eSwapCoords != eswapNO)
1782 do_swapcoords(fio, ir->swap, bRead);
1787 if (file_version >= 39)
1789 gmx_fio_do_gmx_bool(fio, ir->bQMMM);
1790 gmx_fio_do_int(fio, ir->QMMMscheme);
1791 gmx_fio_do_real(fio, ir->scalefactor);
1792 gmx_fio_do_int(fio, ir->opts.ngQM);
1795 snew(ir->opts.QMmethod, ir->opts.ngQM);
1796 snew(ir->opts.QMbasis, ir->opts.ngQM);
1797 snew(ir->opts.QMcharge, ir->opts.ngQM);
1798 snew(ir->opts.QMmult, ir->opts.ngQM);
1799 snew(ir->opts.bSH, ir->opts.ngQM);
1800 snew(ir->opts.CASorbitals, ir->opts.ngQM);
1801 snew(ir->opts.CASelectrons, ir->opts.ngQM);
1802 snew(ir->opts.SAon, ir->opts.ngQM);
1803 snew(ir->opts.SAoff, ir->opts.ngQM);
1804 snew(ir->opts.SAsteps, ir->opts.ngQM);
1805 snew(ir->opts.bOPT, ir->opts.ngQM);
1806 snew(ir->opts.bTS, ir->opts.ngQM);
1808 if (ir->opts.ngQM > 0)
1810 gmx_fio_ndo_int(fio, ir->opts.QMmethod, ir->opts.ngQM);
1811 gmx_fio_ndo_int(fio, ir->opts.QMbasis, ir->opts.ngQM);
1812 gmx_fio_ndo_int(fio, ir->opts.QMcharge, ir->opts.ngQM);
1813 gmx_fio_ndo_int(fio, ir->opts.QMmult, ir->opts.ngQM);
1814 gmx_fio_ndo_gmx_bool(fio, ir->opts.bSH, ir->opts.ngQM);
1815 gmx_fio_ndo_int(fio, ir->opts.CASorbitals, ir->opts.ngQM);
1816 gmx_fio_ndo_int(fio, ir->opts.CASelectrons, ir->opts.ngQM);
1817 gmx_fio_ndo_real(fio, ir->opts.SAon, ir->opts.ngQM);
1818 gmx_fio_ndo_real(fio, ir->opts.SAoff, ir->opts.ngQM);
1819 gmx_fio_ndo_int(fio, ir->opts.SAsteps, ir->opts.ngQM);
1820 gmx_fio_ndo_gmx_bool(fio, ir->opts.bOPT, ir->opts.ngQM);
1821 gmx_fio_ndo_gmx_bool(fio, ir->opts.bTS, ir->opts.ngQM);
1823 /* end of QMMM stuff */
1828 static void do_harm(t_fileio *fio, t_iparams *iparams)
1830 gmx_fio_do_real(fio, iparams->harmonic.rA);
1831 gmx_fio_do_real(fio, iparams->harmonic.krA);
1832 gmx_fio_do_real(fio, iparams->harmonic.rB);
1833 gmx_fio_do_real(fio, iparams->harmonic.krB);
1836 void do_iparams(t_fileio *fio, t_functype ftype, t_iparams *iparams,
1837 gmx_bool bRead, int file_version)
1844 gmx_fio_set_comment(fio, interaction_function[ftype].name);
1854 do_harm(fio, iparams);
1855 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && bRead)
1857 /* Correct incorrect storage of parameters */
1858 iparams->pdihs.phiB = iparams->pdihs.phiA;
1859 iparams->pdihs.cpB = iparams->pdihs.cpA;
1863 gmx_fio_do_real(fio, iparams->harmonic.rA);
1864 gmx_fio_do_real(fio, iparams->harmonic.krA);
1866 case F_LINEAR_ANGLES:
1867 gmx_fio_do_real(fio, iparams->linangle.klinA);
1868 gmx_fio_do_real(fio, iparams->linangle.aA);
1869 gmx_fio_do_real(fio, iparams->linangle.klinB);
1870 gmx_fio_do_real(fio, iparams->linangle.aB);
1873 gmx_fio_do_real(fio, iparams->fene.bm);
1874 gmx_fio_do_real(fio, iparams->fene.kb);
1878 gmx_fio_do_real(fio, iparams->restraint.lowA);
1879 gmx_fio_do_real(fio, iparams->restraint.up1A);
1880 gmx_fio_do_real(fio, iparams->restraint.up2A);
1881 gmx_fio_do_real(fio, iparams->restraint.kA);
1882 gmx_fio_do_real(fio, iparams->restraint.lowB);
1883 gmx_fio_do_real(fio, iparams->restraint.up1B);
1884 gmx_fio_do_real(fio, iparams->restraint.up2B);
1885 gmx_fio_do_real(fio, iparams->restraint.kB);
1891 gmx_fio_do_real(fio, iparams->tab.kA);
1892 gmx_fio_do_int(fio, iparams->tab.table);
1893 gmx_fio_do_real(fio, iparams->tab.kB);
1895 case F_CROSS_BOND_BONDS:
1896 gmx_fio_do_real(fio, iparams->cross_bb.r1e);
1897 gmx_fio_do_real(fio, iparams->cross_bb.r2e);
1898 gmx_fio_do_real(fio, iparams->cross_bb.krr);
1900 case F_CROSS_BOND_ANGLES:
1901 gmx_fio_do_real(fio, iparams->cross_ba.r1e);
1902 gmx_fio_do_real(fio, iparams->cross_ba.r2e);
1903 gmx_fio_do_real(fio, iparams->cross_ba.r3e);
1904 gmx_fio_do_real(fio, iparams->cross_ba.krt);
1906 case F_UREY_BRADLEY:
1907 gmx_fio_do_real(fio, iparams->u_b.thetaA);
1908 gmx_fio_do_real(fio, iparams->u_b.kthetaA);
1909 gmx_fio_do_real(fio, iparams->u_b.r13A);
1910 gmx_fio_do_real(fio, iparams->u_b.kUBA);
1911 if (file_version >= 79)
1913 gmx_fio_do_real(fio, iparams->u_b.thetaB);
1914 gmx_fio_do_real(fio, iparams->u_b.kthetaB);
1915 gmx_fio_do_real(fio, iparams->u_b.r13B);
1916 gmx_fio_do_real(fio, iparams->u_b.kUBB);
1920 iparams->u_b.thetaB = iparams->u_b.thetaA;
1921 iparams->u_b.kthetaB = iparams->u_b.kthetaA;
1922 iparams->u_b.r13B = iparams->u_b.r13A;
1923 iparams->u_b.kUBB = iparams->u_b.kUBA;
1926 case F_QUARTIC_ANGLES:
1927 gmx_fio_do_real(fio, iparams->qangle.theta);
1928 gmx_fio_ndo_real(fio, iparams->qangle.c, 5);
1931 gmx_fio_do_real(fio, iparams->bham.a);
1932 gmx_fio_do_real(fio, iparams->bham.b);
1933 gmx_fio_do_real(fio, iparams->bham.c);
1936 gmx_fio_do_real(fio, iparams->morse.b0A);
1937 gmx_fio_do_real(fio, iparams->morse.cbA);
1938 gmx_fio_do_real(fio, iparams->morse.betaA);
1939 if (file_version >= 79)
1941 gmx_fio_do_real(fio, iparams->morse.b0B);
1942 gmx_fio_do_real(fio, iparams->morse.cbB);
1943 gmx_fio_do_real(fio, iparams->morse.betaB);
1947 iparams->morse.b0B = iparams->morse.b0A;
1948 iparams->morse.cbB = iparams->morse.cbA;
1949 iparams->morse.betaB = iparams->morse.betaA;
1953 gmx_fio_do_real(fio, iparams->cubic.b0);
1954 gmx_fio_do_real(fio, iparams->cubic.kb);
1955 gmx_fio_do_real(fio, iparams->cubic.kcub);
1959 case F_POLARIZATION:
1960 gmx_fio_do_real(fio, iparams->polarize.alpha);
1963 gmx_fio_do_real(fio, iparams->anharm_polarize.alpha);
1964 gmx_fio_do_real(fio, iparams->anharm_polarize.drcut);
1965 gmx_fio_do_real(fio, iparams->anharm_polarize.khyp);
1968 if (file_version < 31)
1970 gmx_fatal(FARGS, "Old tpr files with water_polarization not supported. Make a new.");
1972 gmx_fio_do_real(fio, iparams->wpol.al_x);
1973 gmx_fio_do_real(fio, iparams->wpol.al_y);
1974 gmx_fio_do_real(fio, iparams->wpol.al_z);
1975 gmx_fio_do_real(fio, iparams->wpol.rOH);
1976 gmx_fio_do_real(fio, iparams->wpol.rHH);
1977 gmx_fio_do_real(fio, iparams->wpol.rOD);
1980 gmx_fio_do_real(fio, iparams->thole.a);
1981 gmx_fio_do_real(fio, iparams->thole.alpha1);
1982 gmx_fio_do_real(fio, iparams->thole.alpha2);
1983 gmx_fio_do_real(fio, iparams->thole.rfac);
1986 gmx_fio_do_real(fio, iparams->lj.c6);
1987 gmx_fio_do_real(fio, iparams->lj.c12);
1990 gmx_fio_do_real(fio, iparams->lj14.c6A);
1991 gmx_fio_do_real(fio, iparams->lj14.c12A);
1992 gmx_fio_do_real(fio, iparams->lj14.c6B);
1993 gmx_fio_do_real(fio, iparams->lj14.c12B);
1996 gmx_fio_do_real(fio, iparams->ljc14.fqq);
1997 gmx_fio_do_real(fio, iparams->ljc14.qi);
1998 gmx_fio_do_real(fio, iparams->ljc14.qj);
1999 gmx_fio_do_real(fio, iparams->ljc14.c6);
2000 gmx_fio_do_real(fio, iparams->ljc14.c12);
2002 case F_LJC_PAIRS_NB:
2003 gmx_fio_do_real(fio, iparams->ljcnb.qi);
2004 gmx_fio_do_real(fio, iparams->ljcnb.qj);
2005 gmx_fio_do_real(fio, iparams->ljcnb.c6);
2006 gmx_fio_do_real(fio, iparams->ljcnb.c12);
2012 gmx_fio_do_real(fio, iparams->pdihs.phiA);
2013 gmx_fio_do_real(fio, iparams->pdihs.cpA);
2014 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && file_version < 42)
2016 /* Read the incorrectly stored multiplicity */
2017 gmx_fio_do_real(fio, iparams->harmonic.rB);
2018 gmx_fio_do_real(fio, iparams->harmonic.krB);
2019 iparams->pdihs.phiB = iparams->pdihs.phiA;
2020 iparams->pdihs.cpB = iparams->pdihs.cpA;
2024 gmx_fio_do_real(fio, iparams->pdihs.phiB);
2025 gmx_fio_do_real(fio, iparams->pdihs.cpB);
2026 gmx_fio_do_int(fio, iparams->pdihs.mult);
2030 gmx_fio_do_real(fio, iparams->pdihs.phiA);
2031 gmx_fio_do_real(fio, iparams->pdihs.cpA);
2034 gmx_fio_do_int(fio, iparams->disres.label);
2035 gmx_fio_do_int(fio, iparams->disres.type);
2036 gmx_fio_do_real(fio, iparams->disres.low);
2037 gmx_fio_do_real(fio, iparams->disres.up1);
2038 gmx_fio_do_real(fio, iparams->disres.up2);
2039 gmx_fio_do_real(fio, iparams->disres.kfac);
2042 gmx_fio_do_int(fio, iparams->orires.ex);
2043 gmx_fio_do_int(fio, iparams->orires.label);
2044 gmx_fio_do_int(fio, iparams->orires.power);
2045 gmx_fio_do_real(fio, iparams->orires.c);
2046 gmx_fio_do_real(fio, iparams->orires.obs);
2047 gmx_fio_do_real(fio, iparams->orires.kfac);
2050 if (file_version < 82)
2052 gmx_fio_do_int(fio, idum);
2053 gmx_fio_do_int(fio, idum);
2055 gmx_fio_do_real(fio, iparams->dihres.phiA);
2056 gmx_fio_do_real(fio, iparams->dihres.dphiA);
2057 gmx_fio_do_real(fio, iparams->dihres.kfacA);
2058 if (file_version >= 82)
2060 gmx_fio_do_real(fio, iparams->dihres.phiB);
2061 gmx_fio_do_real(fio, iparams->dihres.dphiB);
2062 gmx_fio_do_real(fio, iparams->dihres.kfacB);
2066 iparams->dihres.phiB = iparams->dihres.phiA;
2067 iparams->dihres.dphiB = iparams->dihres.dphiA;
2068 iparams->dihres.kfacB = iparams->dihres.kfacA;
2072 gmx_fio_do_rvec(fio, iparams->posres.pos0A);
2073 gmx_fio_do_rvec(fio, iparams->posres.fcA);
2074 if (bRead && file_version < 27)
2076 copy_rvec(iparams->posres.pos0A, iparams->posres.pos0B);
2077 copy_rvec(iparams->posres.fcA, iparams->posres.fcB);
2081 gmx_fio_do_rvec(fio, iparams->posres.pos0B);
2082 gmx_fio_do_rvec(fio, iparams->posres.fcB);
2086 gmx_fio_do_int(fio, iparams->fbposres.geom);
2087 gmx_fio_do_rvec(fio, iparams->fbposres.pos0);
2088 gmx_fio_do_real(fio, iparams->fbposres.r);
2089 gmx_fio_do_real(fio, iparams->fbposres.k);
2092 gmx_fio_ndo_real(fio, iparams->cbtdihs.cbtcA, NR_CBTDIHS);
2095 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcA, NR_RBDIHS);
2096 if (file_version >= 25)
2098 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcB, NR_RBDIHS);
2102 /* Fourier dihedrals are internally represented
2103 * as Ryckaert-Bellemans since those are faster to compute.
2105 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcA, NR_RBDIHS);
2106 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcB, NR_RBDIHS);
2110 gmx_fio_do_real(fio, iparams->constr.dA);
2111 gmx_fio_do_real(fio, iparams->constr.dB);
2114 gmx_fio_do_real(fio, iparams->settle.doh);
2115 gmx_fio_do_real(fio, iparams->settle.dhh);
2118 gmx_fio_do_real(fio, iparams->vsite.a);
2123 gmx_fio_do_real(fio, iparams->vsite.a);
2124 gmx_fio_do_real(fio, iparams->vsite.b);
2129 gmx_fio_do_real(fio, iparams->vsite.a);
2130 gmx_fio_do_real(fio, iparams->vsite.b);
2131 gmx_fio_do_real(fio, iparams->vsite.c);
2134 gmx_fio_do_int(fio, iparams->vsiten.n);
2135 gmx_fio_do_real(fio, iparams->vsiten.a);
2140 /* We got rid of some parameters in version 68 */
2141 if (bRead && file_version < 68)
2143 gmx_fio_do_real(fio, rdum);
2144 gmx_fio_do_real(fio, rdum);
2145 gmx_fio_do_real(fio, rdum);
2146 gmx_fio_do_real(fio, rdum);
2148 gmx_fio_do_real(fio, iparams->gb.sar);
2149 gmx_fio_do_real(fio, iparams->gb.st);
2150 gmx_fio_do_real(fio, iparams->gb.pi);
2151 gmx_fio_do_real(fio, iparams->gb.gbr);
2152 gmx_fio_do_real(fio, iparams->gb.bmlt);
2155 gmx_fio_do_int(fio, iparams->cmap.cmapA);
2156 gmx_fio_do_int(fio, iparams->cmap.cmapB);
2159 gmx_fatal(FARGS, "unknown function type %d (%s) in %s line %d",
2160 ftype, interaction_function[ftype].name, __FILE__, __LINE__);
2164 gmx_fio_unset_comment(fio);
2168 static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_version,
2175 gmx_fio_set_comment(fio, interaction_function[ftype].name);
2177 if (file_version < 44)
2179 for (i = 0; i < MAXNODES; i++)
2181 gmx_fio_do_int(fio, idum);
2184 gmx_fio_do_int(fio, ilist->nr);
2187 snew(ilist->iatoms, ilist->nr);
2189 gmx_fio_ndo_int(fio, ilist->iatoms, ilist->nr);
2192 gmx_fio_unset_comment(fio);
2196 static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
2197 gmx_bool bRead, int file_version)
2202 gmx_fio_do_int(fio, ffparams->atnr);
2203 if (file_version < 57)
2205 gmx_fio_do_int(fio, idum);
2207 gmx_fio_do_int(fio, ffparams->ntypes);
2210 fprintf(debug, "ffparams->atnr = %d, ntypes = %d\n",
2211 ffparams->atnr, ffparams->ntypes);
2215 snew(ffparams->functype, ffparams->ntypes);
2216 snew(ffparams->iparams, ffparams->ntypes);
2218 /* Read/write all the function types */
2219 gmx_fio_ndo_int(fio, ffparams->functype, ffparams->ntypes);
2222 pr_ivec(debug, 0, "functype", ffparams->functype, ffparams->ntypes, TRUE);
2225 if (file_version >= 66)
2227 gmx_fio_do_double(fio, ffparams->reppow);
2231 ffparams->reppow = 12.0;
2234 if (file_version >= 57)
2236 gmx_fio_do_real(fio, ffparams->fudgeQQ);
2239 /* Check whether all these function types are supported by the code.
2240 * In practice the code is backwards compatible, which means that the
2241 * numbering may have to be altered from old numbering to new numbering
2243 for (i = 0; (i < ffparams->ntypes); i++)
2247 /* Loop over file versions */
2248 for (k = 0; (k < NFTUPD); k++)
2250 /* Compare the read file_version to the update table */
2251 if ((file_version < ftupd[k].fvnr) &&
2252 (ffparams->functype[i] >= ftupd[k].ftype))
2254 ffparams->functype[i] += 1;
2257 fprintf(debug, "Incrementing function type %d to %d (due to %s)\n",
2258 i, ffparams->functype[i],
2259 interaction_function[ftupd[k].ftype].longname);
2266 do_iparams(fio, ffparams->functype[i], &ffparams->iparams[i], bRead,
2270 pr_iparams(debug, ffparams->functype[i], &ffparams->iparams[i]);
2275 static void add_settle_atoms(t_ilist *ilist)
2279 /* Settle used to only store the first atom: add the other two */
2280 srenew(ilist->iatoms, 2*ilist->nr);
2281 for (i = ilist->nr/2-1; i >= 0; i--)
2283 ilist->iatoms[4*i+0] = ilist->iatoms[2*i+0];
2284 ilist->iatoms[4*i+1] = ilist->iatoms[2*i+1];
2285 ilist->iatoms[4*i+2] = ilist->iatoms[2*i+1] + 1;
2286 ilist->iatoms[4*i+3] = ilist->iatoms[2*i+1] + 2;
2288 ilist->nr = 2*ilist->nr;
2291 static void do_ilists(t_fileio *fio, t_ilist *ilist, gmx_bool bRead,
2294 int i, j, renum[F_NRE];
2298 for (j = 0; (j < F_NRE); j++)
2303 for (k = 0; k < NFTUPD; k++)
2305 if ((file_version < ftupd[k].fvnr) && (j == ftupd[k].ftype))
2314 ilist[j].iatoms = NULL;
2318 do_ilist(fio, &ilist[j], bRead, file_version, j);
2319 if (file_version < 78 && j == F_SETTLE && ilist[j].nr > 0)
2321 add_settle_atoms(&ilist[j]);
2325 if (bRead && gmx_debug_at)
2326 pr_ilist(debug,0,interaction_function[j].longname,
2327 functype,&ilist[j],TRUE);
2332 static void do_idef(t_fileio *fio, gmx_ffparams_t *ffparams, gmx_moltype_t *molt,
2333 gmx_bool bRead, int file_version)
2335 do_ffparams(fio, ffparams, bRead, file_version);
2337 if (file_version >= 54)
2339 gmx_fio_do_real(fio, ffparams->fudgeQQ);
2342 do_ilists(fio, molt->ilist, bRead, file_version);
2345 static void do_block(t_fileio *fio, t_block *block, gmx_bool bRead, int file_version)
2347 int i, idum, dum_nra, *dum_a;
2349 if (file_version < 44)
2351 for (i = 0; i < MAXNODES; i++)
2353 gmx_fio_do_int(fio, idum);
2356 gmx_fio_do_int(fio, block->nr);
2357 if (file_version < 51)
2359 gmx_fio_do_int(fio, dum_nra);
2363 if ((block->nalloc_index > 0) && (NULL != block->index))
2365 sfree(block->index);
2367 block->nalloc_index = block->nr+1;
2368 snew(block->index, block->nalloc_index);
2370 gmx_fio_ndo_int(fio, block->index, block->nr+1);
2372 if (file_version < 51 && dum_nra > 0)
2374 snew(dum_a, dum_nra);
2375 gmx_fio_ndo_int(fio, dum_a, dum_nra);
2380 static void do_blocka(t_fileio *fio, t_blocka *block, gmx_bool bRead,
2385 if (file_version < 44)
2387 for (i = 0; i < MAXNODES; i++)
2389 gmx_fio_do_int(fio, idum);
2392 gmx_fio_do_int(fio, block->nr);
2393 gmx_fio_do_int(fio, block->nra);
2396 block->nalloc_index = block->nr+1;
2397 snew(block->index, block->nalloc_index);
2398 block->nalloc_a = block->nra;
2399 snew(block->a, block->nalloc_a);
2401 gmx_fio_ndo_int(fio, block->index, block->nr+1);
2402 gmx_fio_ndo_int(fio, block->a, block->nra);
2405 /* This is a primitive routine to make it possible to translate atomic numbers
2406 * to element names when reading TPR files, without making the Gromacs library
2407 * directory a dependency on mdrun (which is the case if we need elements.dat).
2410 atomicnumber_to_element(int atomicnumber)
2414 /* This does not have to be complete, so we only include elements likely
2415 * to occur in PDB files.
2417 switch (atomicnumber)
2419 case 1: p = "H"; break;
2420 case 5: p = "B"; break;
2421 case 6: p = "C"; break;
2422 case 7: p = "N"; break;
2423 case 8: p = "O"; break;
2424 case 9: p = "F"; break;
2425 case 11: p = "Na"; break;
2426 case 12: p = "Mg"; break;
2427 case 15: p = "P"; break;
2428 case 16: p = "S"; break;
2429 case 17: p = "Cl"; break;
2430 case 18: p = "Ar"; break;
2431 case 19: p = "K"; break;
2432 case 20: p = "Ca"; break;
2433 case 25: p = "Mn"; break;
2434 case 26: p = "Fe"; break;
2435 case 28: p = "Ni"; break;
2436 case 29: p = "Cu"; break;
2437 case 30: p = "Zn"; break;
2438 case 35: p = "Br"; break;
2439 case 47: p = "Ag"; break;
2440 default: p = ""; break;
2446 static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead,
2447 int file_version, gmx_groups_t *groups, int atnr)
2452 gmx_fio_do_real(fio, atom->m);
2453 gmx_fio_do_real(fio, atom->q);
2454 gmx_fio_do_real(fio, atom->mB);
2455 gmx_fio_do_real(fio, atom->qB);
2456 gmx_fio_do_ushort(fio, atom->type);
2457 gmx_fio_do_ushort(fio, atom->typeB);
2458 gmx_fio_do_int(fio, atom->ptype);
2459 gmx_fio_do_int(fio, atom->resind);
2460 if (file_version >= 52)
2462 gmx_fio_do_int(fio, atom->atomnumber);
2465 /* Set element string from atomic number if present.
2466 * This routine returns an empty string if the name is not found.
2468 strncpy(atom->elem, atomicnumber_to_element(atom->atomnumber), 4);
2469 /* avoid warnings about potentially unterminated string */
2470 atom->elem[3] = '\0';
2475 atom->atomnumber = NOTSET;
2477 if (file_version < 23)
2481 else if (file_version < 39)
2490 if (file_version < 57)
2492 unsigned char uchar[egcNR];
2493 gmx_fio_ndo_uchar(fio, uchar, myngrp);
2494 for (i = myngrp; (i < ngrp); i++)
2498 /* Copy the old data format to the groups struct */
2499 for (i = 0; i < ngrp; i++)
2501 groups->grpnr[i][atnr] = uchar[i];
2506 static void do_grps(t_fileio *fio, int ngrp, t_grps grps[], gmx_bool bRead,
2511 if (file_version < 23)
2515 else if (file_version < 39)
2524 for (j = 0; (j < ngrp); j++)
2528 gmx_fio_do_int(fio, grps[j].nr);
2531 snew(grps[j].nm_ind, grps[j].nr);
2533 gmx_fio_ndo_int(fio, grps[j].nm_ind, grps[j].nr);
2538 snew(grps[j].nm_ind, grps[j].nr);
2543 static void do_symstr(t_fileio *fio, char ***nm, gmx_bool bRead, t_symtab *symtab)
2549 gmx_fio_do_int(fio, ls);
2550 *nm = get_symtab_handle(symtab, ls);
2554 ls = lookup_symtab(symtab, *nm);
2555 gmx_fio_do_int(fio, ls);
2559 static void do_strstr(t_fileio *fio, int nstr, char ***nm, gmx_bool bRead,
2564 for (j = 0; (j < nstr); j++)
2566 do_symstr(fio, &(nm[j]), bRead, symtab);
2570 static void do_resinfo(t_fileio *fio, int n, t_resinfo *ri, gmx_bool bRead,
2571 t_symtab *symtab, int file_version)
2575 for (j = 0; (j < n); j++)
2577 do_symstr(fio, &(ri[j].name), bRead, symtab);
2578 if (file_version >= 63)
2580 gmx_fio_do_int(fio, ri[j].nr);
2581 gmx_fio_do_uchar(fio, ri[j].ic);
2591 static void do_atoms(t_fileio *fio, t_atoms *atoms, gmx_bool bRead, t_symtab *symtab,
2593 gmx_groups_t *groups)
2597 gmx_fio_do_int(fio, atoms->nr);
2598 gmx_fio_do_int(fio, atoms->nres);
2599 if (file_version < 57)
2601 gmx_fio_do_int(fio, groups->ngrpname);
2602 for (i = 0; i < egcNR; i++)
2604 groups->ngrpnr[i] = atoms->nr;
2605 snew(groups->grpnr[i], groups->ngrpnr[i]);
2610 snew(atoms->atom, atoms->nr);
2611 snew(atoms->atomname, atoms->nr);
2612 snew(atoms->atomtype, atoms->nr);
2613 snew(atoms->atomtypeB, atoms->nr);
2614 snew(atoms->resinfo, atoms->nres);
2615 if (file_version < 57)
2617 snew(groups->grpname, groups->ngrpname);
2619 atoms->pdbinfo = NULL;
2621 for (i = 0; (i < atoms->nr); i++)
2623 do_atom(fio, &atoms->atom[i], egcNR, bRead, file_version, groups, i);
2625 do_strstr(fio, atoms->nr, atoms->atomname, bRead, symtab);
2626 if (bRead && (file_version <= 20))
2628 for (i = 0; i < atoms->nr; i++)
2630 atoms->atomtype[i] = put_symtab(symtab, "?");
2631 atoms->atomtypeB[i] = put_symtab(symtab, "?");
2636 do_strstr(fio, atoms->nr, atoms->atomtype, bRead, symtab);
2637 do_strstr(fio, atoms->nr, atoms->atomtypeB, bRead, symtab);
2639 do_resinfo(fio, atoms->nres, atoms->resinfo, bRead, symtab, file_version);
2641 if (file_version < 57)
2643 do_strstr(fio, groups->ngrpname, groups->grpname, bRead, symtab);
2645 do_grps(fio, egcNR, groups->grps, bRead, file_version);
2649 static void do_groups(t_fileio *fio, gmx_groups_t *groups,
2650 gmx_bool bRead, t_symtab *symtab,
2655 do_grps(fio, egcNR, groups->grps, bRead, file_version);
2656 gmx_fio_do_int(fio, groups->ngrpname);
2659 snew(groups->grpname, groups->ngrpname);
2661 do_strstr(fio, groups->ngrpname, groups->grpname, bRead, symtab);
2662 for (g = 0; g < egcNR; g++)
2664 gmx_fio_do_int(fio, groups->ngrpnr[g]);
2665 if (groups->ngrpnr[g] == 0)
2669 groups->grpnr[g] = NULL;
2676 snew(groups->grpnr[g], groups->ngrpnr[g]);
2678 gmx_fio_ndo_uchar(fio, groups->grpnr[g], groups->ngrpnr[g]);
2683 static void do_atomtypes(t_fileio *fio, t_atomtypes *atomtypes, gmx_bool bRead,
2688 if (file_version > 25)
2690 gmx_fio_do_int(fio, atomtypes->nr);
2694 snew(atomtypes->radius, j);
2695 snew(atomtypes->vol, j);
2696 snew(atomtypes->surftens, j);
2697 snew(atomtypes->atomnumber, j);
2698 snew(atomtypes->gb_radius, j);
2699 snew(atomtypes->S_hct, j);
2701 gmx_fio_ndo_real(fio, atomtypes->radius, j);
2702 gmx_fio_ndo_real(fio, atomtypes->vol, j);
2703 gmx_fio_ndo_real(fio, atomtypes->surftens, j);
2704 if (file_version >= 40)
2706 gmx_fio_ndo_int(fio, atomtypes->atomnumber, j);
2708 if (file_version >= 60)
2710 gmx_fio_ndo_real(fio, atomtypes->gb_radius, j);
2711 gmx_fio_ndo_real(fio, atomtypes->S_hct, j);
2716 /* File versions prior to 26 cannot do GBSA,
2717 * so they dont use this structure
2720 atomtypes->radius = NULL;
2721 atomtypes->vol = NULL;
2722 atomtypes->surftens = NULL;
2723 atomtypes->atomnumber = NULL;
2724 atomtypes->gb_radius = NULL;
2725 atomtypes->S_hct = NULL;
2729 static void do_symtab(t_fileio *fio, t_symtab *symtab, gmx_bool bRead)
2735 gmx_fio_do_int(fio, symtab->nr);
2739 snew(symtab->symbuf, 1);
2740 symbuf = symtab->symbuf;
2741 symbuf->bufsize = nr;
2742 snew(symbuf->buf, nr);
2743 for (i = 0; (i < nr); i++)
2745 gmx_fio_do_string(fio, buf);
2746 symbuf->buf[i] = gmx_strdup(buf);
2751 symbuf = symtab->symbuf;
2752 while (symbuf != NULL)
2754 for (i = 0; (i < symbuf->bufsize) && (i < nr); i++)
2756 gmx_fio_do_string(fio, symbuf->buf[i]);
2759 symbuf = symbuf->next;
2763 gmx_fatal(FARGS, "nr of symtab strings left: %d", nr);
2768 static void do_cmap(t_fileio *fio, gmx_cmap_t *cmap_grid, gmx_bool bRead)
2770 int i, j, ngrid, gs, nelem;
2772 gmx_fio_do_int(fio, cmap_grid->ngrid);
2773 gmx_fio_do_int(fio, cmap_grid->grid_spacing);
2775 ngrid = cmap_grid->ngrid;
2776 gs = cmap_grid->grid_spacing;
2781 snew(cmap_grid->cmapdata, ngrid);
2783 for (i = 0; i < cmap_grid->ngrid; i++)
2785 snew(cmap_grid->cmapdata[i].cmap, 4*nelem);
2789 for (i = 0; i < cmap_grid->ngrid; i++)
2791 for (j = 0; j < nelem; j++)
2793 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4]);
2794 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+1]);
2795 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+2]);
2796 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+3]);
2802 void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols)
2804 int m, a, a0, a1, r;
2808 /* We always assign a new chain number, but save the chain id characters
2809 * for larger molecules.
2811 #define CHAIN_MIN_ATOMS 15
2815 for (m = 0; m < mols->nr; m++)
2817 a0 = mols->index[m];
2818 a1 = mols->index[m+1];
2819 if ((a1-a0 >= CHAIN_MIN_ATOMS) && (chainid <= 'Z'))
2828 for (a = a0; a < a1; a++)
2830 atoms->resinfo[atoms->atom[a].resind].chainnum = chainnum;
2831 atoms->resinfo[atoms->atom[a].resind].chainid = c;
2836 /* Blank out the chain id if there was only one chain */
2839 for (r = 0; r < atoms->nres; r++)
2841 atoms->resinfo[r].chainid = ' ';
2846 static void do_moltype(t_fileio *fio, gmx_moltype_t *molt, gmx_bool bRead,
2847 t_symtab *symtab, int file_version,
2848 gmx_groups_t *groups)
2852 if (file_version >= 57)
2854 do_symstr(fio, &(molt->name), bRead, symtab);
2857 do_atoms(fio, &molt->atoms, bRead, symtab, file_version, groups);
2859 if (bRead && gmx_debug_at)
2861 pr_atoms(debug, 0, "atoms", &molt->atoms, TRUE);
2864 if (file_version >= 57)
2866 do_ilists(fio, molt->ilist, bRead, file_version);
2868 do_block(fio, &molt->cgs, bRead, file_version);
2869 if (bRead && gmx_debug_at)
2871 pr_block(debug, 0, "cgs", &molt->cgs, TRUE);
2875 /* This used to be in the atoms struct */
2876 do_blocka(fio, &molt->excls, bRead, file_version);
2879 static void do_molblock(t_fileio *fio, gmx_molblock_t *molb, gmx_bool bRead)
2883 gmx_fio_do_int(fio, molb->type);
2884 gmx_fio_do_int(fio, molb->nmol);
2885 gmx_fio_do_int(fio, molb->natoms_mol);
2886 /* Position restraint coordinates */
2887 gmx_fio_do_int(fio, molb->nposres_xA);
2888 if (molb->nposres_xA > 0)
2892 snew(molb->posres_xA, molb->nposres_xA);
2894 gmx_fio_ndo_rvec(fio, molb->posres_xA, molb->nposres_xA);
2896 gmx_fio_do_int(fio, molb->nposres_xB);
2897 if (molb->nposres_xB > 0)
2901 snew(molb->posres_xB, molb->nposres_xB);
2903 gmx_fio_ndo_rvec(fio, molb->posres_xB, molb->nposres_xB);
2908 static t_block mtop_mols(gmx_mtop_t *mtop)
2914 for (mb = 0; mb < mtop->nmolblock; mb++)
2916 mols.nr += mtop->molblock[mb].nmol;
2918 mols.nalloc_index = mols.nr + 1;
2919 snew(mols.index, mols.nalloc_index);
2924 for (mb = 0; mb < mtop->nmolblock; mb++)
2926 for (mol = 0; mol < mtop->molblock[mb].nmol; mol++)
2928 a += mtop->molblock[mb].natoms_mol;
2937 static void add_posres_molblock(gmx_mtop_t *mtop)
2942 gmx_molblock_t *molb;
2945 /* posres reference positions are stored in ip->posres (if present) and
2946 in ip->fbposres (if present). If normal and flat-bottomed posres are present,
2947 posres.pos0A are identical to fbposres.pos0. */
2948 il = &mtop->moltype[0].ilist[F_POSRES];
2949 ilfb = &mtop->moltype[0].ilist[F_FBPOSRES];
2950 if (il->nr == 0 && ilfb->nr == 0)
2956 for (i = 0; i < il->nr; i += 2)
2958 ip = &mtop->ffparams.iparams[il->iatoms[i]];
2959 am = max(am, il->iatoms[i+1]);
2960 if (ip->posres.pos0B[XX] != ip->posres.pos0A[XX] ||
2961 ip->posres.pos0B[YY] != ip->posres.pos0A[YY] ||
2962 ip->posres.pos0B[ZZ] != ip->posres.pos0A[ZZ])
2967 /* This loop is required if we have only flat-bottomed posres:
2969 - bFE == FALSE (no B-state for flat-bottomed posres) */
2972 for (i = 0; i < ilfb->nr; i += 2)
2974 ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
2975 am = max(am, ilfb->iatoms[i+1]);
2978 /* Make the posres coordinate block end at a molecule end */
2980 while (am >= mtop->mols.index[mol+1])
2984 molb = &mtop->molblock[0];
2985 molb->nposres_xA = mtop->mols.index[mol+1];
2986 snew(molb->posres_xA, molb->nposres_xA);
2989 molb->nposres_xB = molb->nposres_xA;
2990 snew(molb->posres_xB, molb->nposres_xB);
2994 molb->nposres_xB = 0;
2996 for (i = 0; i < il->nr; i += 2)
2998 ip = &mtop->ffparams.iparams[il->iatoms[i]];
2999 a = il->iatoms[i+1];
3000 molb->posres_xA[a][XX] = ip->posres.pos0A[XX];
3001 molb->posres_xA[a][YY] = ip->posres.pos0A[YY];
3002 molb->posres_xA[a][ZZ] = ip->posres.pos0A[ZZ];
3005 molb->posres_xB[a][XX] = ip->posres.pos0B[XX];
3006 molb->posres_xB[a][YY] = ip->posres.pos0B[YY];
3007 molb->posres_xB[a][ZZ] = ip->posres.pos0B[ZZ];
3012 /* If only flat-bottomed posres are present, take reference pos from them.
3013 Here: bFE == FALSE */
3014 for (i = 0; i < ilfb->nr; i += 2)
3016 ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
3017 a = ilfb->iatoms[i+1];
3018 molb->posres_xA[a][XX] = ip->fbposres.pos0[XX];
3019 molb->posres_xA[a][YY] = ip->fbposres.pos0[YY];
3020 molb->posres_xA[a][ZZ] = ip->fbposres.pos0[ZZ];
3025 static void set_disres_npair(gmx_mtop_t *mtop)
3032 ip = mtop->ffparams.iparams;
3034 for (mt = 0; mt < mtop->nmoltype; mt++)
3036 il = &mtop->moltype[mt].ilist[F_DISRES];
3041 for (i = 0; i < il->nr; i += 3)
3044 if (i+3 == il->nr || ip[a[i]].disres.label != ip[a[i+3]].disres.label)
3046 ip[a[i]].disres.npair = npair;
3054 static void do_mtop(t_fileio *fio, gmx_mtop_t *mtop, gmx_bool bRead,
3064 do_symtab(fio, &(mtop->symtab), bRead);
3067 pr_symtab(debug, 0, "symtab", &mtop->symtab);
3070 do_symstr(fio, &(mtop->name), bRead, &(mtop->symtab));
3072 if (file_version >= 57)
3074 do_ffparams(fio, &mtop->ffparams, bRead, file_version);
3076 gmx_fio_do_int(fio, mtop->nmoltype);
3084 snew(mtop->moltype, mtop->nmoltype);
3085 if (file_version < 57)
3087 mtop->moltype[0].name = mtop->name;
3090 for (mt = 0; mt < mtop->nmoltype; mt++)
3092 do_moltype(fio, &mtop->moltype[mt], bRead, &mtop->symtab, file_version,
3096 if (file_version >= 57)
3098 gmx_fio_do_int(fio, mtop->nmolblock);
3102 mtop->nmolblock = 1;
3106 snew(mtop->molblock, mtop->nmolblock);
3108 if (file_version >= 57)
3110 for (mb = 0; mb < mtop->nmolblock; mb++)
3112 do_molblock(fio, &mtop->molblock[mb], bRead);
3114 gmx_fio_do_int(fio, mtop->natoms);
3118 mtop->molblock[0].type = 0;
3119 mtop->molblock[0].nmol = 1;
3120 mtop->molblock[0].natoms_mol = mtop->moltype[0].atoms.nr;
3121 mtop->molblock[0].nposres_xA = 0;
3122 mtop->molblock[0].nposres_xB = 0;
3125 do_atomtypes (fio, &(mtop->atomtypes), bRead, file_version);
3128 pr_atomtypes(debug, 0, "atomtypes", &mtop->atomtypes, TRUE);
3131 if (file_version < 57)
3133 /* Debug statements are inside do_idef */
3134 do_idef (fio, &mtop->ffparams, &mtop->moltype[0], bRead, file_version);
3135 mtop->natoms = mtop->moltype[0].atoms.nr;
3138 if (file_version >= 65)
3140 do_cmap(fio, &mtop->ffparams.cmap_grid, bRead);
3144 mtop->ffparams.cmap_grid.ngrid = 0;
3145 mtop->ffparams.cmap_grid.grid_spacing = 0;
3146 mtop->ffparams.cmap_grid.cmapdata = NULL;
3149 if (file_version >= 57)
3151 do_groups(fio, &mtop->groups, bRead, &(mtop->symtab), file_version);
3154 if (file_version < 57)
3156 do_block(fio, &mtop->moltype[0].cgs, bRead, file_version);
3157 if (bRead && gmx_debug_at)
3159 pr_block(debug, 0, "cgs", &mtop->moltype[0].cgs, TRUE);
3161 do_block(fio, &mtop->mols, bRead, file_version);
3162 /* Add the posres coordinates to the molblock */
3163 add_posres_molblock(mtop);
3167 if (file_version >= 57)
3169 done_block(&mtop->mols);
3170 mtop->mols = mtop_mols(mtop);
3174 pr_block(debug, 0, "mols", &mtop->mols, TRUE);
3178 if (file_version < 51)
3180 /* Here used to be the shake blocks */
3181 do_blocka(fio, &dumb, bRead, file_version);
3194 close_symtab(&(mtop->symtab));
3198 /* If TopOnlyOK is TRUE then we can read even future versions
3199 * of tpx files, provided the file_generation hasn't changed.
3200 * If it is FALSE, we need the inputrecord too, and bail out
3201 * if the file is newer than the program.
3203 * The version and generation if the topology (see top of this file)
3204 * are returned in the two last arguments.
3206 * If possible, we will read the inputrec even when TopOnlyOK is TRUE.
3208 static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx,
3209 gmx_bool TopOnlyOK, int *file_version,
3210 int *file_generation)
3213 char file_tag[STRLEN];
3220 gmx_fio_checktype(fio);
3221 gmx_fio_setdebug(fio, bDebugMode());
3223 /* XDR binary topology file */
3224 precision = sizeof(real);
3227 gmx_fio_do_string(fio, buf);
3228 if (strncmp(buf, "VERSION", 7))
3230 gmx_fatal(FARGS, "Can not read file %s,\n"
3231 " this file is from a GROMACS version which is older than 2.0\n"
3232 " Make a new one with grompp or use a gro or pdb file, if possible",
3233 gmx_fio_getname(fio));
3235 gmx_fio_do_int(fio, precision);
3236 bDouble = (precision == sizeof(double));
3237 if ((precision != sizeof(float)) && !bDouble)
3239 gmx_fatal(FARGS, "Unknown precision in file %s: real is %d bytes "
3240 "instead of %d or %d",
3241 gmx_fio_getname(fio), precision, sizeof(float), sizeof(double));
3243 gmx_fio_setprecision(fio, bDouble);
3244 fprintf(stderr, "Reading file %s, %s (%s precision)\n",
3245 gmx_fio_getname(fio), buf, bDouble ? "double" : "single");
3249 gmx_fio_write_string(fio, GromacsVersion());
3250 bDouble = (precision == sizeof(double));
3251 gmx_fio_setprecision(fio, bDouble);
3252 gmx_fio_do_int(fio, precision);
3254 sprintf(file_tag, "%s", tpx_tag);
3255 fgen = tpx_generation;
3258 /* Check versions! */
3259 gmx_fio_do_int(fio, fver);
3261 /* This is for backward compatibility with development versions 77-79
3262 * where the tag was, mistakenly, placed before the generation,
3263 * which would cause a segv instead of a proper error message
3264 * when reading the topology only from tpx with <77 code.
3266 if (fver >= 77 && fver <= 79)
3268 gmx_fio_do_string(fio, file_tag);
3273 gmx_fio_do_int(fio, fgen);
3282 gmx_fio_do_string(fio, file_tag);
3288 /* Versions before 77 don't have the tag, set it to release */
3289 sprintf(file_tag, "%s", TPX_TAG_RELEASE);
3292 if (strcmp(file_tag, tpx_tag) != 0)
3294 fprintf(stderr, "Note: file tpx tag '%s', software tpx tag '%s'\n",
3297 /* We only support reading tpx files with the same tag as the code
3298 * or tpx files with the release tag and with lower version number.
3300 if (strcmp(file_tag, TPX_TAG_RELEASE) != 0 && fver < tpx_version)
3302 gmx_fatal(FARGS, "tpx tag/version mismatch: reading tpx file (%s) version %d, tag '%s' with program for tpx version %d, tag '%s'",
3303 gmx_fio_getname(fio), fver, file_tag,
3304 tpx_version, tpx_tag);
3309 if (file_version != NULL)
3311 *file_version = fver;
3313 if (file_generation != NULL)
3315 *file_generation = fgen;
3319 if ((fver <= tpx_incompatible_version) ||
3320 ((fver > tpx_version) && !TopOnlyOK) ||
3321 (fgen > tpx_generation) ||
3322 tpx_version == 80) /*80 was used by both 5.0-dev and 4.6-dev*/
3324 gmx_fatal(FARGS, "reading tpx file (%s) version %d with version %d program",
3325 gmx_fio_getname(fio), fver, tpx_version);
3328 gmx_fio_do_int(fio, tpx->natoms);
3331 gmx_fio_do_int(fio, tpx->ngtc);
3339 gmx_fio_do_int(fio, idum);
3340 gmx_fio_do_real(fio, rdum);
3342 /*a better decision will eventually (5.0 or later) need to be made
3343 on how to treat the alchemical state of the system, which can now
3344 vary through a simulation, and cannot be completely described
3345 though a single lambda variable, or even a single state
3346 index. Eventually, should probably be a vector. MRS*/
3349 gmx_fio_do_int(fio, tpx->fep_state);
3351 gmx_fio_do_real(fio, tpx->lambda);
3352 gmx_fio_do_int(fio, tpx->bIr);
3353 gmx_fio_do_int(fio, tpx->bTop);
3354 gmx_fio_do_int(fio, tpx->bX);
3355 gmx_fio_do_int(fio, tpx->bV);
3356 gmx_fio_do_int(fio, tpx->bF);
3357 gmx_fio_do_int(fio, tpx->bBox);
3359 if ((fgen > tpx_generation))
3361 /* This can only happen if TopOnlyOK=TRUE */
3366 static int do_tpx(t_fileio *fio, gmx_bool bRead,
3367 t_inputrec *ir, t_state *state, rvec *f, gmx_mtop_t *mtop,
3368 gmx_bool bXVallocated)
3374 int file_version, file_generation;
3378 gmx_bool bPeriodicMols;
3382 tpx.natoms = state->natoms;
3383 tpx.ngtc = state->ngtc; /* need to add nnhpres here? */
3384 tpx.fep_state = state->fep_state;
3385 tpx.lambda = state->lambda[efptFEP];
3386 tpx.bIr = (ir != NULL);
3387 tpx.bTop = (mtop != NULL);
3388 tpx.bX = (state->x != NULL);
3389 tpx.bV = (state->v != NULL);
3390 tpx.bF = (f != NULL);
3394 TopOnlyOK = (ir == NULL);
3396 do_tpxheader(fio, bRead, &tpx, TopOnlyOK, &file_version, &file_generation);
3401 /* state->lambda = tpx.lambda;*/ /*remove this eventually? */
3402 /* The init_state calls initialize the Nose-Hoover xi integrals to zero */
3407 init_state(state, 0, tpx.ngtc, 0, 0, 0); /* nose-hoover chains */ /* eventually, need to add nnhpres here? */
3408 state->natoms = tpx.natoms;
3409 state->nalloc = tpx.natoms;
3415 init_state(state, tpx.natoms, tpx.ngtc, 0, 0, 0); /* nose-hoover chains */
3419 #define do_test(fio, b, p) if (bRead && (p != NULL) && !b) gmx_fatal(FARGS, "No %s in %s",#p, gmx_fio_getname(fio))
3421 do_test(fio, tpx.bBox, state->box);
3424 gmx_fio_ndo_rvec(fio, state->box, DIM);
3425 if (file_version >= 51)
3427 gmx_fio_ndo_rvec(fio, state->box_rel, DIM);
3431 /* We initialize box_rel after reading the inputrec */
3432 clear_mat(state->box_rel);
3434 if (file_version >= 28)
3436 gmx_fio_ndo_rvec(fio, state->boxv, DIM);
3437 if (file_version < 56)
3440 gmx_fio_ndo_rvec(fio, mdum, DIM);
3445 if (state->ngtc > 0 && file_version >= 28)
3448 /*ndo_double(state->nosehoover_xi,state->ngtc,bDum);*/
3449 /*ndo_double(state->nosehoover_vxi,state->ngtc,bDum);*/
3450 /*ndo_double(state->therm_integral,state->ngtc,bDum);*/
3451 snew(dumv, state->ngtc);
3452 if (file_version < 69)
3454 gmx_fio_ndo_real(fio, dumv, state->ngtc);
3456 /* These used to be the Berendsen tcoupl_lambda's */
3457 gmx_fio_ndo_real(fio, dumv, state->ngtc);
3461 /* Prior to tpx version 26, the inputrec was here.
3462 * I moved it to enable partial forward-compatibility
3463 * for analysis/viewer programs.
3465 if (file_version < 26)
3467 do_test(fio, tpx.bIr, ir);
3472 do_inputrec(fio, ir, bRead, file_version,
3473 mtop ? &mtop->ffparams.fudgeQQ : NULL);
3476 pr_inputrec(debug, 0, "inputrec", ir, FALSE);
3481 do_inputrec(fio, &dum_ir, bRead, file_version,
3482 mtop ? &mtop->ffparams.fudgeQQ : NULL);
3485 pr_inputrec(debug, 0, "inputrec", &dum_ir, FALSE);
3487 done_inputrec(&dum_ir);
3493 do_test(fio, tpx.bTop, mtop);
3498 do_mtop(fio, mtop, bRead, file_version);
3502 do_mtop(fio, &dum_top, bRead, file_version);
3503 done_mtop(&dum_top, TRUE);
3506 do_test(fio, tpx.bX, state->x);
3511 state->flags |= (1<<estX);
3513 gmx_fio_ndo_rvec(fio, state->x, state->natoms);
3516 do_test(fio, tpx.bV, state->v);
3521 state->flags |= (1<<estV);
3523 gmx_fio_ndo_rvec(fio, state->v, state->natoms);
3526 do_test(fio, tpx.bF, f);
3529 gmx_fio_ndo_rvec(fio, f, state->natoms);
3532 /* Starting with tpx version 26, we have the inputrec
3533 * at the end of the file, so we can ignore it
3534 * if the file is never than the software (but still the
3535 * same generation - see comments at the top of this file.
3540 bPeriodicMols = FALSE;
3541 if (file_version >= 26)
3543 do_test(fio, tpx.bIr, ir);
3546 if (file_version >= 53)
3548 /* Removed the pbc info from do_inputrec, since we always want it */
3552 bPeriodicMols = ir->bPeriodicMols;
3554 gmx_fio_do_int(fio, ePBC);
3555 gmx_fio_do_gmx_bool(fio, bPeriodicMols);
3557 if (file_generation <= tpx_generation && ir)
3559 do_inputrec(fio, ir, bRead, file_version, mtop ? &mtop->ffparams.fudgeQQ : NULL);
3562 pr_inputrec(debug, 0, "inputrec", ir, FALSE);
3564 if (file_version < 51)
3566 set_box_rel(ir, state);
3568 if (file_version < 53)
3571 bPeriodicMols = ir->bPeriodicMols;
3574 if (bRead && ir && file_version >= 53)
3576 /* We need to do this after do_inputrec, since that initializes ir */
3578 ir->bPeriodicMols = bPeriodicMols;
3587 if (state->ngtc == 0)
3589 /* Reading old version without tcoupl state data: set it */
3590 init_gtc_state(state, ir->opts.ngtc, 0, ir->opts.nhchainlength);
3592 if (tpx.bTop && mtop)
3594 if (file_version < 57)
3596 if (mtop->moltype[0].ilist[F_DISRES].nr > 0)
3598 ir->eDisre = edrSimple;
3602 ir->eDisre = edrNone;
3605 set_disres_npair(mtop);
3609 if (tpx.bTop && mtop)
3611 gmx_mtop_finalize(mtop);
3614 if (file_version >= 57)
3618 env = getenv("GMX_NOCHARGEGROUPS");
3621 sscanf(env, "%d", &ienv);
3622 fprintf(stderr, "\nFound env.var. GMX_NOCHARGEGROUPS = %d\n",
3627 "Will make single atomic charge groups in non-solvent%s\n",
3628 ienv > 1 ? " and solvent" : "");
3629 gmx_mtop_make_atomic_charge_groups(mtop, ienv == 1);
3631 fprintf(stderr, "\n");
3639 /************************************************************
3641 * The following routines are the exported ones
3643 ************************************************************/
3645 t_fileio *open_tpx(const char *fn, const char *mode)
3647 return gmx_fio_open(fn, mode);
3650 void close_tpx(t_fileio *fio)
3655 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
3656 int *file_version, int *file_generation)
3660 fio = open_tpx(fn, "r");
3661 do_tpxheader(fio, TRUE, tpx, TopOnlyOK, file_version, file_generation);
3665 void write_tpx_state(const char *fn,
3666 t_inputrec *ir, t_state *state, gmx_mtop_t *mtop)
3670 fio = open_tpx(fn, "w");
3671 do_tpx(fio, FALSE, ir, state, NULL, mtop, FALSE);
3675 void read_tpx_state(const char *fn,
3676 t_inputrec *ir, t_state *state, rvec *f, gmx_mtop_t *mtop)
3680 fio = open_tpx(fn, "r");
3681 do_tpx(fio, TRUE, ir, state, f, mtop, FALSE);
3685 int read_tpx(const char *fn,
3686 t_inputrec *ir, matrix box, int *natoms,
3687 rvec *x, rvec *v, rvec *f, gmx_mtop_t *mtop)
3695 fio = open_tpx(fn, "r");
3696 ePBC = do_tpx(fio, TRUE, ir, &state, f, mtop, TRUE);
3698 *natoms = state.natoms;
3701 copy_mat(state.box, box);
3710 int read_tpx_top(const char *fn,
3711 t_inputrec *ir, matrix box, int *natoms,
3712 rvec *x, rvec *v, rvec *f, t_topology *top)
3718 ePBC = read_tpx(fn, ir, box, natoms, x, v, f, &mtop);
3720 *top = gmx_mtop_t_to_t_topology(&mtop);
3725 gmx_bool fn2bTPX(const char *file)
3727 return (efTPR == fn2ftp(file));
3730 static void done_gmx_groups_t(gmx_groups_t *g)
3734 for (i = 0; (i < egcNR); i++)
3736 if (NULL != g->grps[i].nm_ind)
3738 sfree(g->grps[i].nm_ind);
3739 g->grps[i].nm_ind = NULL;
3741 if (NULL != g->grpnr[i])
3747 /* The contents of this array is in symtab, don't free it here */
3751 gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *ePBC,
3752 rvec **x, rvec **v, matrix box, gmx_bool bMass)
3755 int natoms, i, version, generation;
3756 gmx_bool bTop, bXNULL = FALSE;
3758 t_topology *topconv;
3761 bTop = fn2bTPX(infile);
3765 read_tpxheader(infile, &header, TRUE, &version, &generation);
3768 snew(*x, header.natoms);
3772 snew(*v, header.natoms);
3775 *ePBC = read_tpx(infile, NULL, box, &natoms,
3776 (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
3777 *top = gmx_mtop_t_to_t_topology(mtop);
3778 /* In this case we need to throw away the group data too */
3779 done_gmx_groups_t(&mtop->groups);
3781 strcpy(title, *top->name);
3782 tpx_make_chain_identifiers(&top->atoms, &top->mols);
3786 get_stx_coordnum(infile, &natoms);
3787 init_t_atoms(&top->atoms, natoms, (fn2ftp(infile) == efPDB));
3798 read_stx_conf(infile, title, &top->atoms, *x, (v == NULL) ? NULL : *v, ePBC, box);
3806 aps = gmx_atomprop_init();
3807 for (i = 0; (i < natoms); i++)
3809 if (!gmx_atomprop_query(aps, epropMass,
3810 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
3811 *top->atoms.atomname[i],
3812 &(top->atoms.atom[i].m)))
3816 fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
3817 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
3818 top->atoms.resinfo[top->atoms.atom[i].resind].nr,
3819 *top->atoms.atomname[i]);
3823 gmx_atomprop_destroy(aps);
3825 top->idef.ntypes = -1;