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 */
97 /*! \brief Version number of the file format written to run input
98 * files by this version of the code.
100 * The tpx_version number should be increased whenever the file format
101 * in the main development branch changes, generally to the highest
102 * value present in tpxv. Backward compatibility for reading old run
103 * input files is maintained by checking this version number against
104 * that of the file and then using the correct code path.
106 * When developing a feature branch that needs to change the run input
107 * file format, change tpx_tag instead. */
108 static const int tpx_version = tpxv_PullCoordTypeGeom;
111 /* This number should only be increased when you edit the TOPOLOGY section
112 * or the HEADER of the tpx format.
113 * This way we can maintain forward compatibility too for all analysis tools
114 * and/or external programs that only need to know the atom/residue names,
115 * charges, and bond connectivity.
117 * It first appeared in tpx version 26, when I also moved the inputrecord
118 * to the end of the tpx file, so we can just skip it if we only
121 * In particular, it must be increased when adding new elements to
122 * ftupd, so that old code can read new .tpr files.
124 static const int tpx_generation = 26;
126 /* This number should be the most recent backwards incompatible version
127 * I.e., if this number is 9, we cannot read tpx version 9 with this code.
129 static const int tpx_incompatible_version = 9;
133 /* Struct used to maintain tpx compatibility when function types are added */
135 int fvnr; /* file version number in which the function type first appeared */
136 int ftype; /* function type */
140 * The entries should be ordered in:
141 * 1. ascending file version number
142 * 2. ascending function type number
144 /*static const t_ftupd ftupd[] = {
145 { 20, F_CUBICBONDS },
149 { 22, F_DISRESVIOL },
155 { 26, F_DIHRESVIOL },
156 { 30, F_CROSS_BOND_BONDS },
157 { 30, F_CROSS_BOND_ANGLES },
158 { 30, F_UREY_BRADLEY },
159 { 30, F_POLARIZATION },
163 * The entries should be ordered in:
164 * 1. ascending function type number
165 * 2. ascending file version number
167 /* question; what is the purpose of the commented code above? */
168 static const t_ftupd ftupd[] = {
169 { 20, F_CUBICBONDS },
174 { 43, F_TABBONDSNC },
175 { 70, F_RESTRBONDS },
176 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_RESTRANGLES },
177 { 76, F_LINEAR_ANGLES },
178 { 30, F_CROSS_BOND_BONDS },
179 { 30, F_CROSS_BOND_ANGLES },
180 { 30, F_UREY_BRADLEY },
181 { 34, F_QUARTIC_ANGLES },
183 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_RESTRDIHS },
184 { tpxv_RestrictedBendingAndCombinedAngleTorsionPotentials, F_CBTDIHS },
193 { 72, F_NPSOLVATION },
195 { 41, F_LJC_PAIRS_NB },
198 { 32, F_COUL_RECIP },
201 { 30, F_POLARIZATION },
204 { 22, F_DISRESVIOL },
208 { 26, F_DIHRESVIOL },
213 { 46, F_ECONSERVED },
214 { 69, F_VTEMP_NOLONGERUSED},
216 { 54, F_DVDL_CONSTR },
217 { 76, F_ANHARM_POL },
220 { 79, F_DVDL_BONDED, },
221 { 79, F_DVDL_RESTRAINT },
222 { 79, F_DVDL_TEMPERATURE },
224 #define NFTUPD asize(ftupd)
226 /* Needed for backward compatibility */
229 /**************************************************************
231 * Now the higer level routines that do io of the structures and arrays
233 **************************************************************/
234 static void do_pullgrp_tpx_pre95(t_fileio *fio,
243 gmx_fio_do_int(fio, pgrp->nat);
246 snew(pgrp->ind, pgrp->nat);
248 gmx_fio_ndo_int(fio, pgrp->ind, pgrp->nat);
249 gmx_fio_do_int(fio, pgrp->nweight);
252 snew(pgrp->weight, pgrp->nweight);
254 gmx_fio_ndo_real(fio, pgrp->weight, pgrp->nweight);
255 gmx_fio_do_int(fio, pgrp->pbcatom);
256 gmx_fio_do_rvec(fio, pcrd->vec);
257 clear_rvec(pcrd->origin);
258 gmx_fio_do_rvec(fio, tmp);
260 gmx_fio_do_real(fio, pcrd->rate);
261 gmx_fio_do_real(fio, pcrd->k);
262 if (file_version >= 56)
264 gmx_fio_do_real(fio, pcrd->kB);
272 static void do_pull_group(t_fileio *fio, t_pull_group *pgrp, gmx_bool bRead)
276 gmx_fio_do_int(fio, pgrp->nat);
279 snew(pgrp->ind, pgrp->nat);
281 gmx_fio_ndo_int(fio, pgrp->ind, pgrp->nat);
282 gmx_fio_do_int(fio, pgrp->nweight);
285 snew(pgrp->weight, pgrp->nweight);
287 gmx_fio_ndo_real(fio, pgrp->weight, pgrp->nweight);
288 gmx_fio_do_int(fio, pgrp->pbcatom);
291 static void do_pull_coord(t_fileio *fio, t_pull_coord *pcrd, int file_version,
292 int ePullOld, int eGeomOld, ivec dimOld)
296 gmx_fio_do_int(fio, pcrd->group[0]);
297 gmx_fio_do_int(fio, pcrd->group[1]);
298 if (file_version >= tpxv_PullCoordTypeGeom)
300 gmx_fio_do_int(fio, pcrd->eType);
301 gmx_fio_do_int(fio, pcrd->eGeom);
302 gmx_fio_do_ivec(fio, pcrd->dim);
306 pcrd->eType = ePullOld;
307 pcrd->eGeom = eGeomOld;
308 copy_ivec(dimOld, pcrd->dim);
310 gmx_fio_do_rvec(fio, pcrd->origin);
311 gmx_fio_do_rvec(fio, pcrd->vec);
312 if (file_version >= tpxv_PullCoordTypeGeom)
314 gmx_fio_do_gmx_bool(fio, pcrd->bStart);
318 /* This parameter is only printed, but not actually used by mdrun */
319 pcrd->bStart = FALSE;
321 gmx_fio_do_real(fio, pcrd->init);
322 gmx_fio_do_real(fio, pcrd->rate);
323 gmx_fio_do_real(fio, pcrd->k);
324 gmx_fio_do_real(fio, pcrd->kB);
327 static void do_expandedvals(t_fileio *fio, t_expanded *expand, t_lambda *fepvals, gmx_bool bRead, int file_version)
329 /* i is used in the ndo_double macro*/
333 int n_lambda = fepvals->n_lambda;
335 /* reset the lambda calculation window */
336 fepvals->lambda_start_n = 0;
337 fepvals->lambda_stop_n = n_lambda;
338 if (file_version >= 79)
344 snew(expand->init_lambda_weights, n_lambda);
346 gmx_fio_ndo_real(fio, expand->init_lambda_weights, n_lambda);
347 gmx_fio_do_gmx_bool(fio, expand->bInit_weights);
350 gmx_fio_do_int(fio, expand->nstexpanded);
351 gmx_fio_do_int(fio, expand->elmcmove);
352 gmx_fio_do_int(fio, expand->elamstats);
353 gmx_fio_do_int(fio, expand->lmc_repeats);
354 gmx_fio_do_int(fio, expand->gibbsdeltalam);
355 gmx_fio_do_int(fio, expand->lmc_forced_nstart);
356 gmx_fio_do_int(fio, expand->lmc_seed);
357 gmx_fio_do_real(fio, expand->mc_temp);
358 gmx_fio_do_int(fio, expand->bSymmetrizedTMatrix);
359 gmx_fio_do_int(fio, expand->nstTij);
360 gmx_fio_do_int(fio, expand->minvarmin);
361 gmx_fio_do_int(fio, expand->c_range);
362 gmx_fio_do_real(fio, expand->wl_scale);
363 gmx_fio_do_real(fio, expand->wl_ratio);
364 gmx_fio_do_real(fio, expand->init_wl_delta);
365 gmx_fio_do_gmx_bool(fio, expand->bWLoneovert);
366 gmx_fio_do_int(fio, expand->elmceq);
367 gmx_fio_do_int(fio, expand->equil_steps);
368 gmx_fio_do_int(fio, expand->equil_samples);
369 gmx_fio_do_int(fio, expand->equil_n_at_lam);
370 gmx_fio_do_real(fio, expand->equil_wl_delta);
371 gmx_fio_do_real(fio, expand->equil_ratio);
375 static void do_simtempvals(t_fileio *fio, t_simtemp *simtemp, int n_lambda, gmx_bool bRead,
378 if (file_version >= 79)
380 gmx_fio_do_int(fio, simtemp->eSimTempScale);
381 gmx_fio_do_real(fio, simtemp->simtemp_high);
382 gmx_fio_do_real(fio, simtemp->simtemp_low);
387 snew(simtemp->temperatures, n_lambda);
389 gmx_fio_ndo_real(fio, simtemp->temperatures, n_lambda);
394 static void do_imd(t_fileio *fio, t_IMD *imd, gmx_bool bRead)
396 gmx_fio_do_int(fio, imd->nat);
399 snew(imd->ind, imd->nat);
401 gmx_fio_ndo_int(fio, imd->ind, imd->nat);
404 static void do_fepvals(t_fileio *fio, t_lambda *fepvals, gmx_bool bRead, int file_version)
406 /* i is defined in the ndo_double macro; use g to iterate. */
411 /* free energy values */
413 if (file_version >= 79)
415 gmx_fio_do_int(fio, fepvals->init_fep_state);
416 gmx_fio_do_double(fio, fepvals->init_lambda);
417 gmx_fio_do_double(fio, fepvals->delta_lambda);
419 else if (file_version >= 59)
421 gmx_fio_do_double(fio, fepvals->init_lambda);
422 gmx_fio_do_double(fio, fepvals->delta_lambda);
426 gmx_fio_do_real(fio, rdum);
427 fepvals->init_lambda = rdum;
428 gmx_fio_do_real(fio, rdum);
429 fepvals->delta_lambda = rdum;
431 if (file_version >= 79)
433 gmx_fio_do_int(fio, fepvals->n_lambda);
436 snew(fepvals->all_lambda, efptNR);
438 for (g = 0; g < efptNR; g++)
440 if (fepvals->n_lambda > 0)
444 snew(fepvals->all_lambda[g], fepvals->n_lambda);
446 gmx_fio_ndo_double(fio, fepvals->all_lambda[g], fepvals->n_lambda);
447 gmx_fio_ndo_int(fio, fepvals->separate_dvdl, efptNR);
449 else if (fepvals->init_lambda >= 0)
451 fepvals->separate_dvdl[efptFEP] = TRUE;
455 else if (file_version >= 64)
457 gmx_fio_do_int(fio, fepvals->n_lambda);
462 snew(fepvals->all_lambda, efptNR);
463 /* still allocate the all_lambda array's contents. */
464 for (g = 0; g < efptNR; g++)
466 if (fepvals->n_lambda > 0)
468 snew(fepvals->all_lambda[g], fepvals->n_lambda);
472 gmx_fio_ndo_double(fio, fepvals->all_lambda[efptFEP],
474 if (fepvals->init_lambda >= 0)
478 fepvals->separate_dvdl[efptFEP] = TRUE;
482 /* copy the contents of the efptFEP lambda component to all
483 the other components */
484 for (g = 0; g < efptNR; g++)
486 for (h = 0; h < fepvals->n_lambda; h++)
490 fepvals->all_lambda[g][h] =
491 fepvals->all_lambda[efptFEP][h];
500 fepvals->n_lambda = 0;
501 fepvals->all_lambda = NULL;
502 if (fepvals->init_lambda >= 0)
504 fepvals->separate_dvdl[efptFEP] = TRUE;
507 if (file_version >= 13)
509 gmx_fio_do_real(fio, fepvals->sc_alpha);
513 fepvals->sc_alpha = 0;
515 if (file_version >= 38)
517 gmx_fio_do_int(fio, fepvals->sc_power);
521 fepvals->sc_power = 2;
523 if (file_version >= 79)
525 gmx_fio_do_real(fio, fepvals->sc_r_power);
529 fepvals->sc_r_power = 6.0;
531 if (file_version >= 15)
533 gmx_fio_do_real(fio, fepvals->sc_sigma);
537 fepvals->sc_sigma = 0.3;
541 if (file_version >= 71)
543 fepvals->sc_sigma_min = fepvals->sc_sigma;
547 fepvals->sc_sigma_min = 0;
550 if (file_version >= 79)
552 gmx_fio_do_int(fio, fepvals->bScCoul);
556 fepvals->bScCoul = TRUE;
558 if (file_version >= 64)
560 gmx_fio_do_int(fio, fepvals->nstdhdl);
564 fepvals->nstdhdl = 1;
567 if (file_version >= 73)
569 gmx_fio_do_int(fio, fepvals->separate_dhdl_file);
570 gmx_fio_do_int(fio, fepvals->dhdl_derivatives);
574 fepvals->separate_dhdl_file = esepdhdlfileYES;
575 fepvals->dhdl_derivatives = edhdlderivativesYES;
577 if (file_version >= 71)
579 gmx_fio_do_int(fio, fepvals->dh_hist_size);
580 gmx_fio_do_double(fio, fepvals->dh_hist_spacing);
584 fepvals->dh_hist_size = 0;
585 fepvals->dh_hist_spacing = 0.1;
587 if (file_version >= 79)
589 gmx_fio_do_int(fio, fepvals->edHdLPrintEnergy);
593 fepvals->edHdLPrintEnergy = edHdLPrintEnergyNO;
596 /* handle lambda_neighbors */
597 if ((file_version >= 83 && file_version < 90) || file_version >= 92)
599 gmx_fio_do_int(fio, fepvals->lambda_neighbors);
600 if ( (fepvals->lambda_neighbors >= 0) && (fepvals->init_fep_state >= 0) &&
601 (fepvals->init_lambda < 0) )
603 fepvals->lambda_start_n = (fepvals->init_fep_state -
604 fepvals->lambda_neighbors);
605 fepvals->lambda_stop_n = (fepvals->init_fep_state +
606 fepvals->lambda_neighbors + 1);
607 if (fepvals->lambda_start_n < 0)
609 fepvals->lambda_start_n = 0;;
611 if (fepvals->lambda_stop_n >= fepvals->n_lambda)
613 fepvals->lambda_stop_n = fepvals->n_lambda;
618 fepvals->lambda_start_n = 0;
619 fepvals->lambda_stop_n = fepvals->n_lambda;
624 fepvals->lambda_start_n = 0;
625 fepvals->lambda_stop_n = fepvals->n_lambda;
629 static void do_pull(t_fileio *fio, t_pull *pull, gmx_bool bRead,
630 int file_version, int ePullOld)
636 if (file_version >= 95)
638 gmx_fio_do_int(fio, pull->ngroup);
640 gmx_fio_do_int(fio, pull->ncoord);
641 if (file_version < 95)
643 pull->ngroup = pull->ncoord + 1;
645 if (file_version < tpxv_PullCoordTypeGeom)
649 gmx_fio_do_int(fio, eGeomOld);
650 gmx_fio_do_ivec(fio, dimOld);
651 /* The inner cylinder radius, now removed */
652 gmx_fio_do_real(fio, dum);
654 gmx_fio_do_real(fio, pull->cylinder_r);
655 gmx_fio_do_real(fio, pull->constr_tol);
656 if (file_version >= 95)
658 gmx_fio_do_int(fio, pull->bPrintCOM1);
659 /* With file_version < 95 this value is set below */
661 if (file_version >= tpxv_PullCoordTypeGeom)
663 gmx_fio_do_int(fio, pull->bPrintCOM2);
664 gmx_fio_do_int(fio, pull->bPrintRefValue);
665 gmx_fio_do_int(fio, pull->bPrintComp);
669 pull->bPrintCOM2 = FALSE;
670 pull->bPrintRefValue = FALSE;
671 pull->bPrintComp = TRUE;
673 gmx_fio_do_int(fio, pull->nstxout);
674 gmx_fio_do_int(fio, pull->nstfout);
677 snew(pull->group, pull->ngroup);
678 snew(pull->coord, pull->ncoord);
680 if (file_version < 95)
682 /* epullgPOS for position pulling, before epullgDIRPBC was removed */
683 if (eGeomOld == epullgDIRPBC)
685 gmx_fatal(FARGS, "pull-geometry=position is no longer supported");
687 if (eGeomOld > epullgDIRPBC)
692 for (g = 0; g < pull->ngroup; g++)
694 /* We read and ignore a pull coordinate for group 0 */
695 do_pullgrp_tpx_pre95(fio, &pull->group[g], &pull->coord[max(g-1, 0)],
696 bRead, file_version);
699 pull->coord[g-1].group[0] = 0;
700 pull->coord[g-1].group[1] = g;
704 pull->bPrintCOM1 = (pull->group[0].nat > 0);
708 for (g = 0; g < pull->ngroup; g++)
710 do_pull_group(fio, &pull->group[g], bRead);
712 for (g = 0; g < pull->ncoord; g++)
714 do_pull_coord(fio, &pull->coord[g],
715 file_version, ePullOld, eGeomOld, dimOld);
721 static void do_rotgrp(t_fileio *fio, t_rotgrp *rotg, gmx_bool bRead)
725 gmx_fio_do_int(fio, rotg->eType);
726 gmx_fio_do_int(fio, rotg->bMassW);
727 gmx_fio_do_int(fio, rotg->nat);
730 snew(rotg->ind, rotg->nat);
732 gmx_fio_ndo_int(fio, rotg->ind, rotg->nat);
735 snew(rotg->x_ref, rotg->nat);
737 gmx_fio_ndo_rvec(fio, rotg->x_ref, rotg->nat);
738 gmx_fio_do_rvec(fio, rotg->vec);
739 gmx_fio_do_rvec(fio, rotg->pivot);
740 gmx_fio_do_real(fio, rotg->rate);
741 gmx_fio_do_real(fio, rotg->k);
742 gmx_fio_do_real(fio, rotg->slab_dist);
743 gmx_fio_do_real(fio, rotg->min_gaussian);
744 gmx_fio_do_real(fio, rotg->eps);
745 gmx_fio_do_int(fio, rotg->eFittype);
746 gmx_fio_do_int(fio, rotg->PotAngle_nstep);
747 gmx_fio_do_real(fio, rotg->PotAngle_step);
750 static void do_rot(t_fileio *fio, t_rot *rot, gmx_bool bRead)
754 gmx_fio_do_int(fio, rot->ngrp);
755 gmx_fio_do_int(fio, rot->nstrout);
756 gmx_fio_do_int(fio, rot->nstsout);
759 snew(rot->grp, rot->ngrp);
761 for (g = 0; g < rot->ngrp; g++)
763 do_rotgrp(fio, &rot->grp[g], bRead);
768 static void do_swapcoords(t_fileio *fio, t_swapcoords *swap, gmx_bool bRead)
773 gmx_fio_do_int(fio, swap->nat);
774 gmx_fio_do_int(fio, swap->nat_sol);
775 for (j = 0; j < 2; j++)
777 gmx_fio_do_int(fio, swap->nat_split[j]);
778 gmx_fio_do_int(fio, swap->massw_split[j]);
780 gmx_fio_do_int(fio, swap->nstswap);
781 gmx_fio_do_int(fio, swap->nAverage);
782 gmx_fio_do_real(fio, swap->threshold);
783 gmx_fio_do_real(fio, swap->cyl0r);
784 gmx_fio_do_real(fio, swap->cyl0u);
785 gmx_fio_do_real(fio, swap->cyl0l);
786 gmx_fio_do_real(fio, swap->cyl1r);
787 gmx_fio_do_real(fio, swap->cyl1u);
788 gmx_fio_do_real(fio, swap->cyl1l);
792 snew(swap->ind, swap->nat);
793 snew(swap->ind_sol, swap->nat_sol);
794 for (j = 0; j < 2; j++)
796 snew(swap->ind_split[j], swap->nat_split[j]);
800 gmx_fio_ndo_int(fio, swap->ind, swap->nat);
801 gmx_fio_ndo_int(fio, swap->ind_sol, swap->nat_sol);
802 for (j = 0; j < 2; j++)
804 gmx_fio_ndo_int(fio, swap->ind_split[j], swap->nat_split[j]);
807 for (j = 0; j < eCompNR; j++)
809 gmx_fio_do_int(fio, swap->nanions[j]);
810 gmx_fio_do_int(fio, swap->ncations[j]);
816 static void do_inputrec(t_fileio *fio, t_inputrec *ir, gmx_bool bRead,
817 int file_version, real *fudgeQQ)
819 int i, j, k, *tmp, idum = 0;
822 gmx_bool bSimAnn, bdum = 0;
823 real zerotemptime, finish_t, init_temp, finish_temp;
825 if (file_version != tpx_version)
827 /* Give a warning about features that are not accessible */
828 fprintf(stderr, "Note: file tpx version %d, software tpx version %d\n",
829 file_version, tpx_version);
837 if (file_version == 0)
842 /* Basic inputrec stuff */
843 gmx_fio_do_int(fio, ir->eI);
844 if (file_version >= 62)
846 gmx_fio_do_int64(fio, ir->nsteps);
850 gmx_fio_do_int(fio, idum);
854 if (file_version > 25)
856 if (file_version >= 62)
858 gmx_fio_do_int64(fio, ir->init_step);
862 gmx_fio_do_int(fio, idum);
863 ir->init_step = idum;
871 if (file_version >= 58)
873 gmx_fio_do_int(fio, ir->simulation_part);
877 ir->simulation_part = 1;
880 if (file_version >= 67)
882 gmx_fio_do_int(fio, ir->nstcalcenergy);
886 ir->nstcalcenergy = 1;
888 if (file_version < 53)
890 /* The pbc info has been moved out of do_inputrec,
891 * since we always want it, also without reading the inputrec.
893 gmx_fio_do_int(fio, ir->ePBC);
894 if ((file_version <= 15) && (ir->ePBC == 2))
898 if (file_version >= 45)
900 gmx_fio_do_int(fio, ir->bPeriodicMols);
907 ir->bPeriodicMols = TRUE;
911 ir->bPeriodicMols = FALSE;
915 if (file_version >= 81)
917 gmx_fio_do_int(fio, ir->cutoff_scheme);
918 if (file_version < 94)
920 ir->cutoff_scheme = 1 - ir->cutoff_scheme;
925 ir->cutoff_scheme = ecutsGROUP;
927 gmx_fio_do_int(fio, ir->ns_type);
928 gmx_fio_do_int(fio, ir->nstlist);
929 gmx_fio_do_int(fio, idum); /* used to be ndelta; not used anymore */
930 if (file_version < 41)
932 gmx_fio_do_int(fio, idum);
933 gmx_fio_do_int(fio, idum);
935 if (file_version >= 45)
937 gmx_fio_do_real(fio, ir->rtpi);
943 gmx_fio_do_int(fio, ir->nstcomm);
944 if (file_version > 34)
946 gmx_fio_do_int(fio, ir->comm_mode);
948 else if (ir->nstcomm < 0)
950 ir->comm_mode = ecmANGULAR;
954 ir->comm_mode = ecmLINEAR;
956 ir->nstcomm = abs(ir->nstcomm);
958 /* ignore nstcheckpoint */
959 if (file_version > 25 && file_version < tpxv_RemoveObsoleteParameters1)
961 gmx_fio_do_int(fio, idum);
964 gmx_fio_do_int(fio, ir->nstcgsteep);
966 if (file_version >= 30)
968 gmx_fio_do_int(fio, ir->nbfgscorr);
975 gmx_fio_do_int(fio, ir->nstlog);
976 gmx_fio_do_int(fio, ir->nstxout);
977 gmx_fio_do_int(fio, ir->nstvout);
978 gmx_fio_do_int(fio, ir->nstfout);
979 gmx_fio_do_int(fio, ir->nstenergy);
980 gmx_fio_do_int(fio, ir->nstxout_compressed);
981 if (file_version >= 59)
983 gmx_fio_do_double(fio, ir->init_t);
984 gmx_fio_do_double(fio, ir->delta_t);
988 gmx_fio_do_real(fio, rdum);
990 gmx_fio_do_real(fio, rdum);
993 gmx_fio_do_real(fio, ir->x_compression_precision);
994 if (file_version < 19)
996 gmx_fio_do_int(fio, idum);
997 gmx_fio_do_int(fio, idum);
999 if (file_version < 18)
1001 gmx_fio_do_int(fio, idum);
1003 if (file_version >= 81)
1005 gmx_fio_do_real(fio, ir->verletbuf_tol);
1009 ir->verletbuf_tol = 0;
1011 gmx_fio_do_real(fio, ir->rlist);
1012 if (file_version >= 67)
1014 gmx_fio_do_real(fio, ir->rlistlong);
1016 if (file_version >= 82 && file_version != 90)
1018 gmx_fio_do_int(fio, ir->nstcalclr);
1022 /* Calculate at NS steps */
1023 ir->nstcalclr = ir->nstlist;
1025 gmx_fio_do_int(fio, ir->coulombtype);
1026 if (file_version < 32 && ir->coulombtype == eelRF)
1028 ir->coulombtype = eelRF_NEC;
1030 if (file_version >= 81)
1032 gmx_fio_do_int(fio, ir->coulomb_modifier);
1036 ir->coulomb_modifier = (ir->cutoff_scheme == ecutsVERLET ? eintmodPOTSHIFT : eintmodNONE);
1038 gmx_fio_do_real(fio, ir->rcoulomb_switch);
1039 gmx_fio_do_real(fio, ir->rcoulomb);
1040 gmx_fio_do_int(fio, ir->vdwtype);
1041 if (file_version >= 81)
1043 gmx_fio_do_int(fio, ir->vdw_modifier);
1047 ir->vdw_modifier = (ir->cutoff_scheme == ecutsVERLET ? eintmodPOTSHIFT : eintmodNONE);
1049 gmx_fio_do_real(fio, ir->rvdw_switch);
1050 gmx_fio_do_real(fio, ir->rvdw);
1051 if (file_version < 67)
1053 ir->rlistlong = max_cutoff(ir->rlist, max_cutoff(ir->rvdw, ir->rcoulomb));
1055 gmx_fio_do_int(fio, ir->eDispCorr);
1056 gmx_fio_do_real(fio, ir->epsilon_r);
1057 if (file_version >= 37)
1059 gmx_fio_do_real(fio, ir->epsilon_rf);
1063 if (EEL_RF(ir->coulombtype))
1065 ir->epsilon_rf = ir->epsilon_r;
1066 ir->epsilon_r = 1.0;
1070 ir->epsilon_rf = 1.0;
1073 if (file_version >= 29)
1075 gmx_fio_do_real(fio, ir->tabext);
1082 if (file_version > 25)
1084 gmx_fio_do_int(fio, ir->gb_algorithm);
1085 gmx_fio_do_int(fio, ir->nstgbradii);
1086 gmx_fio_do_real(fio, ir->rgbradii);
1087 gmx_fio_do_real(fio, ir->gb_saltconc);
1088 gmx_fio_do_int(fio, ir->implicit_solvent);
1092 ir->gb_algorithm = egbSTILL;
1095 ir->gb_saltconc = 0;
1096 ir->implicit_solvent = eisNO;
1098 if (file_version >= 55)
1100 gmx_fio_do_real(fio, ir->gb_epsilon_solvent);
1101 gmx_fio_do_real(fio, ir->gb_obc_alpha);
1102 gmx_fio_do_real(fio, ir->gb_obc_beta);
1103 gmx_fio_do_real(fio, ir->gb_obc_gamma);
1104 if (file_version >= 60)
1106 gmx_fio_do_real(fio, ir->gb_dielectric_offset);
1107 gmx_fio_do_int(fio, ir->sa_algorithm);
1111 ir->gb_dielectric_offset = 0.009;
1112 ir->sa_algorithm = esaAPPROX;
1114 gmx_fio_do_real(fio, ir->sa_surface_tension);
1116 /* Override sa_surface_tension if it is not changed in the mpd-file */
1117 if (ir->sa_surface_tension < 0)
1119 if (ir->gb_algorithm == egbSTILL)
1121 ir->sa_surface_tension = 0.0049 * 100 * CAL2JOULE;
1123 else if (ir->gb_algorithm == egbHCT || ir->gb_algorithm == egbOBC)
1125 ir->sa_surface_tension = 0.0054 * 100 * CAL2JOULE;
1132 /* Better use sensible values than insane (0.0) ones... */
1133 ir->gb_epsilon_solvent = 80;
1134 ir->gb_obc_alpha = 1.0;
1135 ir->gb_obc_beta = 0.8;
1136 ir->gb_obc_gamma = 4.85;
1137 ir->sa_surface_tension = 2.092;
1141 if (file_version >= 81)
1143 gmx_fio_do_real(fio, ir->fourier_spacing);
1147 ir->fourier_spacing = 0.0;
1149 gmx_fio_do_int(fio, ir->nkx);
1150 gmx_fio_do_int(fio, ir->nky);
1151 gmx_fio_do_int(fio, ir->nkz);
1152 gmx_fio_do_int(fio, ir->pme_order);
1153 gmx_fio_do_real(fio, ir->ewald_rtol);
1155 if (file_version >= 93)
1157 gmx_fio_do_real(fio, ir->ewald_rtol_lj);
1161 ir->ewald_rtol_lj = ir->ewald_rtol;
1164 if (file_version >= 24)
1166 gmx_fio_do_int(fio, ir->ewald_geometry);
1170 ir->ewald_geometry = eewg3D;
1173 if (file_version <= 17)
1175 ir->epsilon_surface = 0;
1176 if (file_version == 17)
1178 gmx_fio_do_int(fio, idum);
1183 gmx_fio_do_real(fio, ir->epsilon_surface);
1186 /* ignore bOptFFT */
1187 if (file_version < tpxv_RemoveObsoleteParameters1)
1189 gmx_fio_do_gmx_bool(fio, bdum);
1192 if (file_version >= 93)
1194 gmx_fio_do_int(fio, ir->ljpme_combination_rule);
1196 gmx_fio_do_gmx_bool(fio, ir->bContinuation);
1197 gmx_fio_do_int(fio, ir->etc);
1198 /* before version 18, ir->etc was a gmx_bool (ir->btc),
1199 * but the values 0 and 1 still mean no and
1200 * berendsen temperature coupling, respectively.
1202 if (file_version >= 79)
1204 gmx_fio_do_gmx_bool(fio, ir->bPrintNHChains);
1206 if (file_version >= 71)
1208 gmx_fio_do_int(fio, ir->nsttcouple);
1212 ir->nsttcouple = ir->nstcalcenergy;
1214 if (file_version <= 15)
1216 gmx_fio_do_int(fio, idum);
1218 if (file_version <= 17)
1220 gmx_fio_do_int(fio, ir->epct);
1221 if (file_version <= 15)
1225 ir->epct = epctSURFACETENSION;
1227 gmx_fio_do_int(fio, idum);
1230 /* we have removed the NO alternative at the beginning */
1234 ir->epct = epctISOTROPIC;
1238 ir->epc = epcBERENDSEN;
1243 gmx_fio_do_int(fio, ir->epc);
1244 gmx_fio_do_int(fio, ir->epct);
1246 if (file_version >= 71)
1248 gmx_fio_do_int(fio, ir->nstpcouple);
1252 ir->nstpcouple = ir->nstcalcenergy;
1254 gmx_fio_do_real(fio, ir->tau_p);
1255 if (file_version <= 15)
1257 gmx_fio_do_rvec(fio, vdum);
1258 clear_mat(ir->ref_p);
1259 for (i = 0; i < DIM; i++)
1261 ir->ref_p[i][i] = vdum[i];
1266 gmx_fio_do_rvec(fio, ir->ref_p[XX]);
1267 gmx_fio_do_rvec(fio, ir->ref_p[YY]);
1268 gmx_fio_do_rvec(fio, ir->ref_p[ZZ]);
1270 if (file_version <= 15)
1272 gmx_fio_do_rvec(fio, vdum);
1273 clear_mat(ir->compress);
1274 for (i = 0; i < DIM; i++)
1276 ir->compress[i][i] = vdum[i];
1281 gmx_fio_do_rvec(fio, ir->compress[XX]);
1282 gmx_fio_do_rvec(fio, ir->compress[YY]);
1283 gmx_fio_do_rvec(fio, ir->compress[ZZ]);
1285 if (file_version >= 47)
1287 gmx_fio_do_int(fio, ir->refcoord_scaling);
1288 gmx_fio_do_rvec(fio, ir->posres_com);
1289 gmx_fio_do_rvec(fio, ir->posres_comB);
1293 ir->refcoord_scaling = erscNO;
1294 clear_rvec(ir->posres_com);
1295 clear_rvec(ir->posres_comB);
1297 if ((file_version > 25) && (file_version < 79))
1299 gmx_fio_do_int(fio, ir->andersen_seed);
1303 ir->andersen_seed = 0;
1305 if (file_version < 26)
1307 gmx_fio_do_gmx_bool(fio, bSimAnn);
1308 gmx_fio_do_real(fio, zerotemptime);
1311 if (file_version < 37)
1313 gmx_fio_do_real(fio, rdum);
1316 gmx_fio_do_real(fio, ir->shake_tol);
1317 if (file_version < 54)
1319 gmx_fio_do_real(fio, *fudgeQQ);
1322 gmx_fio_do_int(fio, ir->efep);
1323 if (file_version <= 14 && ir->efep != efepNO)
1327 do_fepvals(fio, ir->fepvals, bRead, file_version);
1329 if (file_version >= 79)
1331 gmx_fio_do_gmx_bool(fio, ir->bSimTemp);
1334 ir->bSimTemp = TRUE;
1339 ir->bSimTemp = FALSE;
1343 do_simtempvals(fio, ir->simtempvals, ir->fepvals->n_lambda, bRead, file_version);
1346 if (file_version >= 79)
1348 gmx_fio_do_gmx_bool(fio, ir->bExpanded);
1351 ir->bExpanded = TRUE;
1355 ir->bExpanded = FALSE;
1360 do_expandedvals(fio, ir->expandedvals, ir->fepvals, bRead, file_version);
1362 if (file_version >= 57)
1364 gmx_fio_do_int(fio, ir->eDisre);
1366 gmx_fio_do_int(fio, ir->eDisreWeighting);
1367 if (file_version < 22)
1369 if (ir->eDisreWeighting == 0)
1371 ir->eDisreWeighting = edrwEqual;
1375 ir->eDisreWeighting = edrwConservative;
1378 gmx_fio_do_gmx_bool(fio, ir->bDisreMixed);
1379 gmx_fio_do_real(fio, ir->dr_fc);
1380 gmx_fio_do_real(fio, ir->dr_tau);
1381 gmx_fio_do_int(fio, ir->nstdisreout);
1382 if (file_version >= 22)
1384 gmx_fio_do_real(fio, ir->orires_fc);
1385 gmx_fio_do_real(fio, ir->orires_tau);
1386 gmx_fio_do_int(fio, ir->nstorireout);
1392 ir->nstorireout = 0;
1395 /* ignore dihre_fc */
1396 if (file_version >= 26 && file_version < 79)
1398 gmx_fio_do_real(fio, rdum);
1399 if (file_version < 56)
1401 gmx_fio_do_real(fio, rdum);
1402 gmx_fio_do_int(fio, idum);
1406 gmx_fio_do_real(fio, ir->em_stepsize);
1407 gmx_fio_do_real(fio, ir->em_tol);
1408 if (file_version >= 22)
1410 gmx_fio_do_gmx_bool(fio, ir->bShakeSOR);
1414 ir->bShakeSOR = TRUE;
1416 if (file_version >= 11)
1418 gmx_fio_do_int(fio, ir->niter);
1423 fprintf(stderr, "Note: niter not in run input file, setting it to %d\n",
1426 if (file_version >= 21)
1428 gmx_fio_do_real(fio, ir->fc_stepsize);
1432 ir->fc_stepsize = 0;
1434 gmx_fio_do_int(fio, ir->eConstrAlg);
1435 gmx_fio_do_int(fio, ir->nProjOrder);
1436 gmx_fio_do_real(fio, ir->LincsWarnAngle);
1437 if (file_version <= 14)
1439 gmx_fio_do_int(fio, idum);
1441 if (file_version >= 26)
1443 gmx_fio_do_int(fio, ir->nLincsIter);
1448 fprintf(stderr, "Note: nLincsIter not in run input file, setting it to %d\n",
1451 if (file_version < 33)
1453 gmx_fio_do_real(fio, bd_temp);
1455 gmx_fio_do_real(fio, ir->bd_fric);
1456 if (file_version >= tpxv_Use64BitRandomSeed)
1458 gmx_fio_do_int64(fio, ir->ld_seed);
1462 gmx_fio_do_int(fio, idum);
1465 if (file_version >= 33)
1467 for (i = 0; i < DIM; i++)
1469 gmx_fio_do_rvec(fio, ir->deform[i]);
1474 for (i = 0; i < DIM; i++)
1476 clear_rvec(ir->deform[i]);
1479 if (file_version >= 14)
1481 gmx_fio_do_real(fio, ir->cos_accel);
1487 gmx_fio_do_int(fio, ir->userint1);
1488 gmx_fio_do_int(fio, ir->userint2);
1489 gmx_fio_do_int(fio, ir->userint3);
1490 gmx_fio_do_int(fio, ir->userint4);
1491 gmx_fio_do_real(fio, ir->userreal1);
1492 gmx_fio_do_real(fio, ir->userreal2);
1493 gmx_fio_do_real(fio, ir->userreal3);
1494 gmx_fio_do_real(fio, ir->userreal4);
1497 if (file_version >= 77)
1499 gmx_fio_do_gmx_bool(fio, ir->bAdress);
1504 snew(ir->adress, 1);
1506 gmx_fio_do_int(fio, ir->adress->type);
1507 gmx_fio_do_real(fio, ir->adress->const_wf);
1508 gmx_fio_do_real(fio, ir->adress->ex_width);
1509 gmx_fio_do_real(fio, ir->adress->hy_width);
1510 gmx_fio_do_int(fio, ir->adress->icor);
1511 gmx_fio_do_int(fio, ir->adress->site);
1512 gmx_fio_do_rvec(fio, ir->adress->refs);
1513 gmx_fio_do_int(fio, ir->adress->n_tf_grps);
1514 gmx_fio_do_real(fio, ir->adress->ex_forcecap);
1515 gmx_fio_do_int(fio, ir->adress->n_energy_grps);
1516 gmx_fio_do_int(fio, ir->adress->do_hybridpairs);
1520 snew(ir->adress->tf_table_index, ir->adress->n_tf_grps);
1522 if (ir->adress->n_tf_grps > 0)
1524 gmx_fio_ndo_int(fio, ir->adress->tf_table_index, ir->adress->n_tf_grps);
1528 snew(ir->adress->group_explicit, ir->adress->n_energy_grps);
1530 if (ir->adress->n_energy_grps > 0)
1532 gmx_fio_ndo_int(fio, ir->adress->group_explicit, ir->adress->n_energy_grps);
1538 ir->bAdress = FALSE;
1542 if (file_version >= 48)
1546 if (file_version >= tpxv_PullCoordTypeGeom)
1548 gmx_fio_do_gmx_bool(fio, ir->bPull);
1552 gmx_fio_do_int(fio, ePullOld);
1553 ir->bPull = (ePullOld > 0);
1554 /* We removed the first ePull=ePullNo for the enum */
1563 do_pull(fio, ir->pull, bRead, file_version, ePullOld);
1571 /* Enforced rotation */
1572 if (file_version >= 74)
1574 gmx_fio_do_int(fio, ir->bRot);
1575 if (ir->bRot == TRUE)
1581 do_rot(fio, ir->rot, bRead);
1589 /* Interactive molecular dynamics */
1590 if (file_version >= tpxv_InteractiveMolecularDynamics)
1592 gmx_fio_do_int(fio, ir->bIMD);
1593 if (TRUE == ir->bIMD)
1599 do_imd(fio, ir->imd, bRead);
1604 /* We don't support IMD sessions for old .tpr files */
1609 gmx_fio_do_int(fio, ir->opts.ngtc);
1610 if (file_version >= 69)
1612 gmx_fio_do_int(fio, ir->opts.nhchainlength);
1616 ir->opts.nhchainlength = 1;
1618 gmx_fio_do_int(fio, ir->opts.ngacc);
1619 gmx_fio_do_int(fio, ir->opts.ngfrz);
1620 gmx_fio_do_int(fio, ir->opts.ngener);
1624 snew(ir->opts.nrdf, ir->opts.ngtc);
1625 snew(ir->opts.ref_t, ir->opts.ngtc);
1626 snew(ir->opts.annealing, ir->opts.ngtc);
1627 snew(ir->opts.anneal_npoints, ir->opts.ngtc);
1628 snew(ir->opts.anneal_time, ir->opts.ngtc);
1629 snew(ir->opts.anneal_temp, ir->opts.ngtc);
1630 snew(ir->opts.tau_t, ir->opts.ngtc);
1631 snew(ir->opts.nFreeze, ir->opts.ngfrz);
1632 snew(ir->opts.acc, ir->opts.ngacc);
1633 snew(ir->opts.egp_flags, ir->opts.ngener*ir->opts.ngener);
1635 if (ir->opts.ngtc > 0)
1637 if (bRead && file_version < 13)
1639 snew(tmp, ir->opts.ngtc);
1640 gmx_fio_ndo_int(fio, tmp, ir->opts.ngtc);
1641 for (i = 0; i < ir->opts.ngtc; i++)
1643 ir->opts.nrdf[i] = tmp[i];
1649 gmx_fio_ndo_real(fio, ir->opts.nrdf, ir->opts.ngtc);
1651 gmx_fio_ndo_real(fio, ir->opts.ref_t, ir->opts.ngtc);
1652 gmx_fio_ndo_real(fio, ir->opts.tau_t, ir->opts.ngtc);
1653 if (file_version < 33 && ir->eI == eiBD)
1655 for (i = 0; i < ir->opts.ngtc; i++)
1657 ir->opts.tau_t[i] = bd_temp;
1661 if (ir->opts.ngfrz > 0)
1663 gmx_fio_ndo_ivec(fio, ir->opts.nFreeze, ir->opts.ngfrz);
1665 if (ir->opts.ngacc > 0)
1667 gmx_fio_ndo_rvec(fio, ir->opts.acc, ir->opts.ngacc);
1669 if (file_version >= 12)
1671 gmx_fio_ndo_int(fio, ir->opts.egp_flags,
1672 ir->opts.ngener*ir->opts.ngener);
1675 if (bRead && file_version < 26)
1677 for (i = 0; i < ir->opts.ngtc; i++)
1681 ir->opts.annealing[i] = eannSINGLE;
1682 ir->opts.anneal_npoints[i] = 2;
1683 snew(ir->opts.anneal_time[i], 2);
1684 snew(ir->opts.anneal_temp[i], 2);
1685 /* calculate the starting/ending temperatures from reft, zerotemptime, and nsteps */
1686 finish_t = ir->init_t + ir->nsteps * ir->delta_t;
1687 init_temp = ir->opts.ref_t[i]*(1-ir->init_t/zerotemptime);
1688 finish_temp = ir->opts.ref_t[i]*(1-finish_t/zerotemptime);
1689 ir->opts.anneal_time[i][0] = ir->init_t;
1690 ir->opts.anneal_time[i][1] = finish_t;
1691 ir->opts.anneal_temp[i][0] = init_temp;
1692 ir->opts.anneal_temp[i][1] = finish_temp;
1696 ir->opts.annealing[i] = eannNO;
1697 ir->opts.anneal_npoints[i] = 0;
1703 /* file version 26 or later */
1704 /* First read the lists with annealing and npoints for each group */
1705 gmx_fio_ndo_int(fio, ir->opts.annealing, ir->opts.ngtc);
1706 gmx_fio_ndo_int(fio, ir->opts.anneal_npoints, ir->opts.ngtc);
1707 for (j = 0; j < (ir->opts.ngtc); j++)
1709 k = ir->opts.anneal_npoints[j];
1712 snew(ir->opts.anneal_time[j], k);
1713 snew(ir->opts.anneal_temp[j], k);
1715 gmx_fio_ndo_real(fio, ir->opts.anneal_time[j], k);
1716 gmx_fio_ndo_real(fio, ir->opts.anneal_temp[j], k);
1720 if (file_version >= 45)
1722 gmx_fio_do_int(fio, ir->nwall);
1723 gmx_fio_do_int(fio, ir->wall_type);
1724 if (file_version >= 50)
1726 gmx_fio_do_real(fio, ir->wall_r_linpot);
1730 ir->wall_r_linpot = -1;
1732 gmx_fio_do_int(fio, ir->wall_atomtype[0]);
1733 gmx_fio_do_int(fio, ir->wall_atomtype[1]);
1734 gmx_fio_do_real(fio, ir->wall_density[0]);
1735 gmx_fio_do_real(fio, ir->wall_density[1]);
1736 gmx_fio_do_real(fio, ir->wall_ewald_zfac);
1742 ir->wall_atomtype[0] = -1;
1743 ir->wall_atomtype[1] = -1;
1744 ir->wall_density[0] = 0;
1745 ir->wall_density[1] = 0;
1746 ir->wall_ewald_zfac = 3;
1748 /* Cosine stuff for electric fields */
1749 for (j = 0; (j < DIM); j++)
1751 gmx_fio_do_int(fio, ir->ex[j].n);
1752 gmx_fio_do_int(fio, ir->et[j].n);
1755 snew(ir->ex[j].a, ir->ex[j].n);
1756 snew(ir->ex[j].phi, ir->ex[j].n);
1757 snew(ir->et[j].a, ir->et[j].n);
1758 snew(ir->et[j].phi, ir->et[j].n);
1760 gmx_fio_ndo_real(fio, ir->ex[j].a, ir->ex[j].n);
1761 gmx_fio_ndo_real(fio, ir->ex[j].phi, ir->ex[j].n);
1762 gmx_fio_ndo_real(fio, ir->et[j].a, ir->et[j].n);
1763 gmx_fio_ndo_real(fio, ir->et[j].phi, ir->et[j].n);
1767 if (file_version >= tpxv_ComputationalElectrophysiology)
1769 gmx_fio_do_int(fio, ir->eSwapCoords);
1770 if (ir->eSwapCoords != eswapNO)
1776 do_swapcoords(fio, ir->swap, bRead);
1781 if (file_version >= 39)
1783 gmx_fio_do_gmx_bool(fio, ir->bQMMM);
1784 gmx_fio_do_int(fio, ir->QMMMscheme);
1785 gmx_fio_do_real(fio, ir->scalefactor);
1786 gmx_fio_do_int(fio, ir->opts.ngQM);
1789 snew(ir->opts.QMmethod, ir->opts.ngQM);
1790 snew(ir->opts.QMbasis, ir->opts.ngQM);
1791 snew(ir->opts.QMcharge, ir->opts.ngQM);
1792 snew(ir->opts.QMmult, ir->opts.ngQM);
1793 snew(ir->opts.bSH, ir->opts.ngQM);
1794 snew(ir->opts.CASorbitals, ir->opts.ngQM);
1795 snew(ir->opts.CASelectrons, ir->opts.ngQM);
1796 snew(ir->opts.SAon, ir->opts.ngQM);
1797 snew(ir->opts.SAoff, ir->opts.ngQM);
1798 snew(ir->opts.SAsteps, ir->opts.ngQM);
1799 snew(ir->opts.bOPT, ir->opts.ngQM);
1800 snew(ir->opts.bTS, ir->opts.ngQM);
1802 if (ir->opts.ngQM > 0)
1804 gmx_fio_ndo_int(fio, ir->opts.QMmethod, ir->opts.ngQM);
1805 gmx_fio_ndo_int(fio, ir->opts.QMbasis, ir->opts.ngQM);
1806 gmx_fio_ndo_int(fio, ir->opts.QMcharge, ir->opts.ngQM);
1807 gmx_fio_ndo_int(fio, ir->opts.QMmult, ir->opts.ngQM);
1808 gmx_fio_ndo_gmx_bool(fio, ir->opts.bSH, ir->opts.ngQM);
1809 gmx_fio_ndo_int(fio, ir->opts.CASorbitals, ir->opts.ngQM);
1810 gmx_fio_ndo_int(fio, ir->opts.CASelectrons, ir->opts.ngQM);
1811 gmx_fio_ndo_real(fio, ir->opts.SAon, ir->opts.ngQM);
1812 gmx_fio_ndo_real(fio, ir->opts.SAoff, ir->opts.ngQM);
1813 gmx_fio_ndo_int(fio, ir->opts.SAsteps, ir->opts.ngQM);
1814 gmx_fio_ndo_gmx_bool(fio, ir->opts.bOPT, ir->opts.ngQM);
1815 gmx_fio_ndo_gmx_bool(fio, ir->opts.bTS, ir->opts.ngQM);
1817 /* end of QMMM stuff */
1822 static void do_harm(t_fileio *fio, t_iparams *iparams)
1824 gmx_fio_do_real(fio, iparams->harmonic.rA);
1825 gmx_fio_do_real(fio, iparams->harmonic.krA);
1826 gmx_fio_do_real(fio, iparams->harmonic.rB);
1827 gmx_fio_do_real(fio, iparams->harmonic.krB);
1830 void do_iparams(t_fileio *fio, t_functype ftype, t_iparams *iparams,
1831 gmx_bool bRead, int file_version)
1838 gmx_fio_set_comment(fio, interaction_function[ftype].name);
1848 do_harm(fio, iparams);
1849 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && bRead)
1851 /* Correct incorrect storage of parameters */
1852 iparams->pdihs.phiB = iparams->pdihs.phiA;
1853 iparams->pdihs.cpB = iparams->pdihs.cpA;
1857 gmx_fio_do_real(fio, iparams->harmonic.rA);
1858 gmx_fio_do_real(fio, iparams->harmonic.krA);
1860 case F_LINEAR_ANGLES:
1861 gmx_fio_do_real(fio, iparams->linangle.klinA);
1862 gmx_fio_do_real(fio, iparams->linangle.aA);
1863 gmx_fio_do_real(fio, iparams->linangle.klinB);
1864 gmx_fio_do_real(fio, iparams->linangle.aB);
1867 gmx_fio_do_real(fio, iparams->fene.bm);
1868 gmx_fio_do_real(fio, iparams->fene.kb);
1872 gmx_fio_do_real(fio, iparams->restraint.lowA);
1873 gmx_fio_do_real(fio, iparams->restraint.up1A);
1874 gmx_fio_do_real(fio, iparams->restraint.up2A);
1875 gmx_fio_do_real(fio, iparams->restraint.kA);
1876 gmx_fio_do_real(fio, iparams->restraint.lowB);
1877 gmx_fio_do_real(fio, iparams->restraint.up1B);
1878 gmx_fio_do_real(fio, iparams->restraint.up2B);
1879 gmx_fio_do_real(fio, iparams->restraint.kB);
1885 gmx_fio_do_real(fio, iparams->tab.kA);
1886 gmx_fio_do_int(fio, iparams->tab.table);
1887 gmx_fio_do_real(fio, iparams->tab.kB);
1889 case F_CROSS_BOND_BONDS:
1890 gmx_fio_do_real(fio, iparams->cross_bb.r1e);
1891 gmx_fio_do_real(fio, iparams->cross_bb.r2e);
1892 gmx_fio_do_real(fio, iparams->cross_bb.krr);
1894 case F_CROSS_BOND_ANGLES:
1895 gmx_fio_do_real(fio, iparams->cross_ba.r1e);
1896 gmx_fio_do_real(fio, iparams->cross_ba.r2e);
1897 gmx_fio_do_real(fio, iparams->cross_ba.r3e);
1898 gmx_fio_do_real(fio, iparams->cross_ba.krt);
1900 case F_UREY_BRADLEY:
1901 gmx_fio_do_real(fio, iparams->u_b.thetaA);
1902 gmx_fio_do_real(fio, iparams->u_b.kthetaA);
1903 gmx_fio_do_real(fio, iparams->u_b.r13A);
1904 gmx_fio_do_real(fio, iparams->u_b.kUBA);
1905 if (file_version >= 79)
1907 gmx_fio_do_real(fio, iparams->u_b.thetaB);
1908 gmx_fio_do_real(fio, iparams->u_b.kthetaB);
1909 gmx_fio_do_real(fio, iparams->u_b.r13B);
1910 gmx_fio_do_real(fio, iparams->u_b.kUBB);
1914 iparams->u_b.thetaB = iparams->u_b.thetaA;
1915 iparams->u_b.kthetaB = iparams->u_b.kthetaA;
1916 iparams->u_b.r13B = iparams->u_b.r13A;
1917 iparams->u_b.kUBB = iparams->u_b.kUBA;
1920 case F_QUARTIC_ANGLES:
1921 gmx_fio_do_real(fio, iparams->qangle.theta);
1922 gmx_fio_ndo_real(fio, iparams->qangle.c, 5);
1925 gmx_fio_do_real(fio, iparams->bham.a);
1926 gmx_fio_do_real(fio, iparams->bham.b);
1927 gmx_fio_do_real(fio, iparams->bham.c);
1930 gmx_fio_do_real(fio, iparams->morse.b0A);
1931 gmx_fio_do_real(fio, iparams->morse.cbA);
1932 gmx_fio_do_real(fio, iparams->morse.betaA);
1933 if (file_version >= 79)
1935 gmx_fio_do_real(fio, iparams->morse.b0B);
1936 gmx_fio_do_real(fio, iparams->morse.cbB);
1937 gmx_fio_do_real(fio, iparams->morse.betaB);
1941 iparams->morse.b0B = iparams->morse.b0A;
1942 iparams->morse.cbB = iparams->morse.cbA;
1943 iparams->morse.betaB = iparams->morse.betaA;
1947 gmx_fio_do_real(fio, iparams->cubic.b0);
1948 gmx_fio_do_real(fio, iparams->cubic.kb);
1949 gmx_fio_do_real(fio, iparams->cubic.kcub);
1953 case F_POLARIZATION:
1954 gmx_fio_do_real(fio, iparams->polarize.alpha);
1957 gmx_fio_do_real(fio, iparams->anharm_polarize.alpha);
1958 gmx_fio_do_real(fio, iparams->anharm_polarize.drcut);
1959 gmx_fio_do_real(fio, iparams->anharm_polarize.khyp);
1962 if (file_version < 31)
1964 gmx_fatal(FARGS, "Old tpr files with water_polarization not supported. Make a new.");
1966 gmx_fio_do_real(fio, iparams->wpol.al_x);
1967 gmx_fio_do_real(fio, iparams->wpol.al_y);
1968 gmx_fio_do_real(fio, iparams->wpol.al_z);
1969 gmx_fio_do_real(fio, iparams->wpol.rOH);
1970 gmx_fio_do_real(fio, iparams->wpol.rHH);
1971 gmx_fio_do_real(fio, iparams->wpol.rOD);
1974 gmx_fio_do_real(fio, iparams->thole.a);
1975 gmx_fio_do_real(fio, iparams->thole.alpha1);
1976 gmx_fio_do_real(fio, iparams->thole.alpha2);
1977 gmx_fio_do_real(fio, iparams->thole.rfac);
1980 gmx_fio_do_real(fio, iparams->lj.c6);
1981 gmx_fio_do_real(fio, iparams->lj.c12);
1984 gmx_fio_do_real(fio, iparams->lj14.c6A);
1985 gmx_fio_do_real(fio, iparams->lj14.c12A);
1986 gmx_fio_do_real(fio, iparams->lj14.c6B);
1987 gmx_fio_do_real(fio, iparams->lj14.c12B);
1990 gmx_fio_do_real(fio, iparams->ljc14.fqq);
1991 gmx_fio_do_real(fio, iparams->ljc14.qi);
1992 gmx_fio_do_real(fio, iparams->ljc14.qj);
1993 gmx_fio_do_real(fio, iparams->ljc14.c6);
1994 gmx_fio_do_real(fio, iparams->ljc14.c12);
1996 case F_LJC_PAIRS_NB:
1997 gmx_fio_do_real(fio, iparams->ljcnb.qi);
1998 gmx_fio_do_real(fio, iparams->ljcnb.qj);
1999 gmx_fio_do_real(fio, iparams->ljcnb.c6);
2000 gmx_fio_do_real(fio, iparams->ljcnb.c12);
2006 gmx_fio_do_real(fio, iparams->pdihs.phiA);
2007 gmx_fio_do_real(fio, iparams->pdihs.cpA);
2008 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && file_version < 42)
2010 /* Read the incorrectly stored multiplicity */
2011 gmx_fio_do_real(fio, iparams->harmonic.rB);
2012 gmx_fio_do_real(fio, iparams->harmonic.krB);
2013 iparams->pdihs.phiB = iparams->pdihs.phiA;
2014 iparams->pdihs.cpB = iparams->pdihs.cpA;
2018 gmx_fio_do_real(fio, iparams->pdihs.phiB);
2019 gmx_fio_do_real(fio, iparams->pdihs.cpB);
2020 gmx_fio_do_int(fio, iparams->pdihs.mult);
2024 gmx_fio_do_real(fio, iparams->pdihs.phiA);
2025 gmx_fio_do_real(fio, iparams->pdihs.cpA);
2028 gmx_fio_do_int(fio, iparams->disres.label);
2029 gmx_fio_do_int(fio, iparams->disres.type);
2030 gmx_fio_do_real(fio, iparams->disres.low);
2031 gmx_fio_do_real(fio, iparams->disres.up1);
2032 gmx_fio_do_real(fio, iparams->disres.up2);
2033 gmx_fio_do_real(fio, iparams->disres.kfac);
2036 gmx_fio_do_int(fio, iparams->orires.ex);
2037 gmx_fio_do_int(fio, iparams->orires.label);
2038 gmx_fio_do_int(fio, iparams->orires.power);
2039 gmx_fio_do_real(fio, iparams->orires.c);
2040 gmx_fio_do_real(fio, iparams->orires.obs);
2041 gmx_fio_do_real(fio, iparams->orires.kfac);
2044 if (file_version < 82)
2046 gmx_fio_do_int(fio, idum);
2047 gmx_fio_do_int(fio, idum);
2049 gmx_fio_do_real(fio, iparams->dihres.phiA);
2050 gmx_fio_do_real(fio, iparams->dihres.dphiA);
2051 gmx_fio_do_real(fio, iparams->dihres.kfacA);
2052 if (file_version >= 82)
2054 gmx_fio_do_real(fio, iparams->dihres.phiB);
2055 gmx_fio_do_real(fio, iparams->dihres.dphiB);
2056 gmx_fio_do_real(fio, iparams->dihres.kfacB);
2060 iparams->dihres.phiB = iparams->dihres.phiA;
2061 iparams->dihres.dphiB = iparams->dihres.dphiA;
2062 iparams->dihres.kfacB = iparams->dihres.kfacA;
2066 gmx_fio_do_rvec(fio, iparams->posres.pos0A);
2067 gmx_fio_do_rvec(fio, iparams->posres.fcA);
2068 if (bRead && file_version < 27)
2070 copy_rvec(iparams->posres.pos0A, iparams->posres.pos0B);
2071 copy_rvec(iparams->posres.fcA, iparams->posres.fcB);
2075 gmx_fio_do_rvec(fio, iparams->posres.pos0B);
2076 gmx_fio_do_rvec(fio, iparams->posres.fcB);
2080 gmx_fio_do_int(fio, iparams->fbposres.geom);
2081 gmx_fio_do_rvec(fio, iparams->fbposres.pos0);
2082 gmx_fio_do_real(fio, iparams->fbposres.r);
2083 gmx_fio_do_real(fio, iparams->fbposres.k);
2086 gmx_fio_ndo_real(fio, iparams->cbtdihs.cbtcA, NR_CBTDIHS);
2089 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcA, NR_RBDIHS);
2090 if (file_version >= 25)
2092 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcB, NR_RBDIHS);
2096 /* Fourier dihedrals are internally represented
2097 * as Ryckaert-Bellemans since those are faster to compute.
2099 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcA, NR_RBDIHS);
2100 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcB, NR_RBDIHS);
2104 gmx_fio_do_real(fio, iparams->constr.dA);
2105 gmx_fio_do_real(fio, iparams->constr.dB);
2108 gmx_fio_do_real(fio, iparams->settle.doh);
2109 gmx_fio_do_real(fio, iparams->settle.dhh);
2112 gmx_fio_do_real(fio, iparams->vsite.a);
2117 gmx_fio_do_real(fio, iparams->vsite.a);
2118 gmx_fio_do_real(fio, iparams->vsite.b);
2123 gmx_fio_do_real(fio, iparams->vsite.a);
2124 gmx_fio_do_real(fio, iparams->vsite.b);
2125 gmx_fio_do_real(fio, iparams->vsite.c);
2128 gmx_fio_do_int(fio, iparams->vsiten.n);
2129 gmx_fio_do_real(fio, iparams->vsiten.a);
2134 /* We got rid of some parameters in version 68 */
2135 if (bRead && file_version < 68)
2137 gmx_fio_do_real(fio, rdum);
2138 gmx_fio_do_real(fio, rdum);
2139 gmx_fio_do_real(fio, rdum);
2140 gmx_fio_do_real(fio, rdum);
2142 gmx_fio_do_real(fio, iparams->gb.sar);
2143 gmx_fio_do_real(fio, iparams->gb.st);
2144 gmx_fio_do_real(fio, iparams->gb.pi);
2145 gmx_fio_do_real(fio, iparams->gb.gbr);
2146 gmx_fio_do_real(fio, iparams->gb.bmlt);
2149 gmx_fio_do_int(fio, iparams->cmap.cmapA);
2150 gmx_fio_do_int(fio, iparams->cmap.cmapB);
2153 gmx_fatal(FARGS, "unknown function type %d (%s) in %s line %d",
2154 ftype, interaction_function[ftype].name, __FILE__, __LINE__);
2158 gmx_fio_unset_comment(fio);
2162 static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_version,
2169 gmx_fio_set_comment(fio, interaction_function[ftype].name);
2171 if (file_version < 44)
2173 for (i = 0; i < MAXNODES; i++)
2175 gmx_fio_do_int(fio, idum);
2178 gmx_fio_do_int(fio, ilist->nr);
2181 snew(ilist->iatoms, ilist->nr);
2183 gmx_fio_ndo_int(fio, ilist->iatoms, ilist->nr);
2186 gmx_fio_unset_comment(fio);
2190 static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
2191 gmx_bool bRead, int file_version)
2196 gmx_fio_do_int(fio, ffparams->atnr);
2197 if (file_version < 57)
2199 gmx_fio_do_int(fio, idum);
2201 gmx_fio_do_int(fio, ffparams->ntypes);
2204 fprintf(debug, "ffparams->atnr = %d, ntypes = %d\n",
2205 ffparams->atnr, ffparams->ntypes);
2209 snew(ffparams->functype, ffparams->ntypes);
2210 snew(ffparams->iparams, ffparams->ntypes);
2212 /* Read/write all the function types */
2213 gmx_fio_ndo_int(fio, ffparams->functype, ffparams->ntypes);
2216 pr_ivec(debug, 0, "functype", ffparams->functype, ffparams->ntypes, TRUE);
2219 if (file_version >= 66)
2221 gmx_fio_do_double(fio, ffparams->reppow);
2225 ffparams->reppow = 12.0;
2228 if (file_version >= 57)
2230 gmx_fio_do_real(fio, ffparams->fudgeQQ);
2233 /* Check whether all these function types are supported by the code.
2234 * In practice the code is backwards compatible, which means that the
2235 * numbering may have to be altered from old numbering to new numbering
2237 for (i = 0; (i < ffparams->ntypes); i++)
2241 /* Loop over file versions */
2242 for (k = 0; (k < NFTUPD); k++)
2244 /* Compare the read file_version to the update table */
2245 if ((file_version < ftupd[k].fvnr) &&
2246 (ffparams->functype[i] >= ftupd[k].ftype))
2248 ffparams->functype[i] += 1;
2251 fprintf(debug, "Incrementing function type %d to %d (due to %s)\n",
2252 i, ffparams->functype[i],
2253 interaction_function[ftupd[k].ftype].longname);
2260 do_iparams(fio, ffparams->functype[i], &ffparams->iparams[i], bRead,
2264 pr_iparams(debug, ffparams->functype[i], &ffparams->iparams[i]);
2269 static void add_settle_atoms(t_ilist *ilist)
2273 /* Settle used to only store the first atom: add the other two */
2274 srenew(ilist->iatoms, 2*ilist->nr);
2275 for (i = ilist->nr/2-1; i >= 0; i--)
2277 ilist->iatoms[4*i+0] = ilist->iatoms[2*i+0];
2278 ilist->iatoms[4*i+1] = ilist->iatoms[2*i+1];
2279 ilist->iatoms[4*i+2] = ilist->iatoms[2*i+1] + 1;
2280 ilist->iatoms[4*i+3] = ilist->iatoms[2*i+1] + 2;
2282 ilist->nr = 2*ilist->nr;
2285 static void do_ilists(t_fileio *fio, t_ilist *ilist, gmx_bool bRead,
2288 int i, j, renum[F_NRE];
2292 for (j = 0; (j < F_NRE); j++)
2297 for (k = 0; k < NFTUPD; k++)
2299 if ((file_version < ftupd[k].fvnr) && (j == ftupd[k].ftype))
2308 ilist[j].iatoms = NULL;
2312 do_ilist(fio, &ilist[j], bRead, file_version, j);
2313 if (file_version < 78 && j == F_SETTLE && ilist[j].nr > 0)
2315 add_settle_atoms(&ilist[j]);
2319 if (bRead && gmx_debug_at)
2320 pr_ilist(debug,0,interaction_function[j].longname,
2321 functype,&ilist[j],TRUE);
2326 static void do_idef(t_fileio *fio, gmx_ffparams_t *ffparams, gmx_moltype_t *molt,
2327 gmx_bool bRead, int file_version)
2329 do_ffparams(fio, ffparams, bRead, file_version);
2331 if (file_version >= 54)
2333 gmx_fio_do_real(fio, ffparams->fudgeQQ);
2336 do_ilists(fio, molt->ilist, bRead, file_version);
2339 static void do_block(t_fileio *fio, t_block *block, gmx_bool bRead, int file_version)
2341 int i, idum, dum_nra, *dum_a;
2343 if (file_version < 44)
2345 for (i = 0; i < MAXNODES; i++)
2347 gmx_fio_do_int(fio, idum);
2350 gmx_fio_do_int(fio, block->nr);
2351 if (file_version < 51)
2353 gmx_fio_do_int(fio, dum_nra);
2357 if ((block->nalloc_index > 0) && (NULL != block->index))
2359 sfree(block->index);
2361 block->nalloc_index = block->nr+1;
2362 snew(block->index, block->nalloc_index);
2364 gmx_fio_ndo_int(fio, block->index, block->nr+1);
2366 if (file_version < 51 && dum_nra > 0)
2368 snew(dum_a, dum_nra);
2369 gmx_fio_ndo_int(fio, dum_a, dum_nra);
2374 static void do_blocka(t_fileio *fio, t_blocka *block, gmx_bool bRead,
2379 if (file_version < 44)
2381 for (i = 0; i < MAXNODES; i++)
2383 gmx_fio_do_int(fio, idum);
2386 gmx_fio_do_int(fio, block->nr);
2387 gmx_fio_do_int(fio, block->nra);
2390 block->nalloc_index = block->nr+1;
2391 snew(block->index, block->nalloc_index);
2392 block->nalloc_a = block->nra;
2393 snew(block->a, block->nalloc_a);
2395 gmx_fio_ndo_int(fio, block->index, block->nr+1);
2396 gmx_fio_ndo_int(fio, block->a, block->nra);
2399 /* This is a primitive routine to make it possible to translate atomic numbers
2400 * to element names when reading TPR files, without making the Gromacs library
2401 * directory a dependency on mdrun (which is the case if we need elements.dat).
2404 atomicnumber_to_element(int atomicnumber)
2408 /* This does not have to be complete, so we only include elements likely
2409 * to occur in PDB files.
2411 switch (atomicnumber)
2413 case 1: p = "H"; break;
2414 case 5: p = "B"; break;
2415 case 6: p = "C"; break;
2416 case 7: p = "N"; break;
2417 case 8: p = "O"; break;
2418 case 9: p = "F"; break;
2419 case 11: p = "Na"; break;
2420 case 12: p = "Mg"; break;
2421 case 15: p = "P"; break;
2422 case 16: p = "S"; break;
2423 case 17: p = "Cl"; break;
2424 case 18: p = "Ar"; break;
2425 case 19: p = "K"; break;
2426 case 20: p = "Ca"; break;
2427 case 25: p = "Mn"; break;
2428 case 26: p = "Fe"; break;
2429 case 28: p = "Ni"; break;
2430 case 29: p = "Cu"; break;
2431 case 30: p = "Zn"; break;
2432 case 35: p = "Br"; break;
2433 case 47: p = "Ag"; break;
2434 default: p = ""; break;
2440 static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead,
2441 int file_version, gmx_groups_t *groups, int atnr)
2446 gmx_fio_do_real(fio, atom->m);
2447 gmx_fio_do_real(fio, atom->q);
2448 gmx_fio_do_real(fio, atom->mB);
2449 gmx_fio_do_real(fio, atom->qB);
2450 gmx_fio_do_ushort(fio, atom->type);
2451 gmx_fio_do_ushort(fio, atom->typeB);
2452 gmx_fio_do_int(fio, atom->ptype);
2453 gmx_fio_do_int(fio, atom->resind);
2454 if (file_version >= 52)
2456 gmx_fio_do_int(fio, atom->atomnumber);
2459 /* Set element string from atomic number if present.
2460 * This routine returns an empty string if the name is not found.
2462 strncpy(atom->elem, atomicnumber_to_element(atom->atomnumber), 4);
2463 /* avoid warnings about potentially unterminated string */
2464 atom->elem[3] = '\0';
2469 atom->atomnumber = NOTSET;
2471 if (file_version < 23)
2475 else if (file_version < 39)
2484 if (file_version < 57)
2486 unsigned char uchar[egcNR];
2487 gmx_fio_ndo_uchar(fio, uchar, myngrp);
2488 for (i = myngrp; (i < ngrp); i++)
2492 /* Copy the old data format to the groups struct */
2493 for (i = 0; i < ngrp; i++)
2495 groups->grpnr[i][atnr] = uchar[i];
2500 static void do_grps(t_fileio *fio, int ngrp, t_grps grps[], gmx_bool bRead,
2505 if (file_version < 23)
2509 else if (file_version < 39)
2518 for (j = 0; (j < ngrp); j++)
2522 gmx_fio_do_int(fio, grps[j].nr);
2525 snew(grps[j].nm_ind, grps[j].nr);
2527 gmx_fio_ndo_int(fio, grps[j].nm_ind, grps[j].nr);
2532 snew(grps[j].nm_ind, grps[j].nr);
2537 static void do_symstr(t_fileio *fio, char ***nm, gmx_bool bRead, t_symtab *symtab)
2543 gmx_fio_do_int(fio, ls);
2544 *nm = get_symtab_handle(symtab, ls);
2548 ls = lookup_symtab(symtab, *nm);
2549 gmx_fio_do_int(fio, ls);
2553 static void do_strstr(t_fileio *fio, int nstr, char ***nm, gmx_bool bRead,
2558 for (j = 0; (j < nstr); j++)
2560 do_symstr(fio, &(nm[j]), bRead, symtab);
2564 static void do_resinfo(t_fileio *fio, int n, t_resinfo *ri, gmx_bool bRead,
2565 t_symtab *symtab, int file_version)
2569 for (j = 0; (j < n); j++)
2571 do_symstr(fio, &(ri[j].name), bRead, symtab);
2572 if (file_version >= 63)
2574 gmx_fio_do_int(fio, ri[j].nr);
2575 gmx_fio_do_uchar(fio, ri[j].ic);
2585 static void do_atoms(t_fileio *fio, t_atoms *atoms, gmx_bool bRead, t_symtab *symtab,
2587 gmx_groups_t *groups)
2591 gmx_fio_do_int(fio, atoms->nr);
2592 gmx_fio_do_int(fio, atoms->nres);
2593 if (file_version < 57)
2595 gmx_fio_do_int(fio, groups->ngrpname);
2596 for (i = 0; i < egcNR; i++)
2598 groups->ngrpnr[i] = atoms->nr;
2599 snew(groups->grpnr[i], groups->ngrpnr[i]);
2604 snew(atoms->atom, atoms->nr);
2605 snew(atoms->atomname, atoms->nr);
2606 snew(atoms->atomtype, atoms->nr);
2607 snew(atoms->atomtypeB, atoms->nr);
2608 snew(atoms->resinfo, atoms->nres);
2609 if (file_version < 57)
2611 snew(groups->grpname, groups->ngrpname);
2613 atoms->pdbinfo = NULL;
2615 for (i = 0; (i < atoms->nr); i++)
2617 do_atom(fio, &atoms->atom[i], egcNR, bRead, file_version, groups, i);
2619 do_strstr(fio, atoms->nr, atoms->atomname, bRead, symtab);
2620 if (bRead && (file_version <= 20))
2622 for (i = 0; i < atoms->nr; i++)
2624 atoms->atomtype[i] = put_symtab(symtab, "?");
2625 atoms->atomtypeB[i] = put_symtab(symtab, "?");
2630 do_strstr(fio, atoms->nr, atoms->atomtype, bRead, symtab);
2631 do_strstr(fio, atoms->nr, atoms->atomtypeB, bRead, symtab);
2633 do_resinfo(fio, atoms->nres, atoms->resinfo, bRead, symtab, file_version);
2635 if (file_version < 57)
2637 do_strstr(fio, groups->ngrpname, groups->grpname, bRead, symtab);
2639 do_grps(fio, egcNR, groups->grps, bRead, file_version);
2643 static void do_groups(t_fileio *fio, gmx_groups_t *groups,
2644 gmx_bool bRead, t_symtab *symtab,
2649 do_grps(fio, egcNR, groups->grps, bRead, file_version);
2650 gmx_fio_do_int(fio, groups->ngrpname);
2653 snew(groups->grpname, groups->ngrpname);
2655 do_strstr(fio, groups->ngrpname, groups->grpname, bRead, symtab);
2656 for (g = 0; g < egcNR; g++)
2658 gmx_fio_do_int(fio, groups->ngrpnr[g]);
2659 if (groups->ngrpnr[g] == 0)
2663 groups->grpnr[g] = NULL;
2670 snew(groups->grpnr[g], groups->ngrpnr[g]);
2672 gmx_fio_ndo_uchar(fio, groups->grpnr[g], groups->ngrpnr[g]);
2677 static void do_atomtypes(t_fileio *fio, t_atomtypes *atomtypes, gmx_bool bRead,
2682 if (file_version > 25)
2684 gmx_fio_do_int(fio, atomtypes->nr);
2688 snew(atomtypes->radius, j);
2689 snew(atomtypes->vol, j);
2690 snew(atomtypes->surftens, j);
2691 snew(atomtypes->atomnumber, j);
2692 snew(atomtypes->gb_radius, j);
2693 snew(atomtypes->S_hct, j);
2695 gmx_fio_ndo_real(fio, atomtypes->radius, j);
2696 gmx_fio_ndo_real(fio, atomtypes->vol, j);
2697 gmx_fio_ndo_real(fio, atomtypes->surftens, j);
2698 if (file_version >= 40)
2700 gmx_fio_ndo_int(fio, atomtypes->atomnumber, j);
2702 if (file_version >= 60)
2704 gmx_fio_ndo_real(fio, atomtypes->gb_radius, j);
2705 gmx_fio_ndo_real(fio, atomtypes->S_hct, j);
2710 /* File versions prior to 26 cannot do GBSA,
2711 * so they dont use this structure
2714 atomtypes->radius = NULL;
2715 atomtypes->vol = NULL;
2716 atomtypes->surftens = NULL;
2717 atomtypes->atomnumber = NULL;
2718 atomtypes->gb_radius = NULL;
2719 atomtypes->S_hct = NULL;
2723 static void do_symtab(t_fileio *fio, t_symtab *symtab, gmx_bool bRead)
2729 gmx_fio_do_int(fio, symtab->nr);
2733 snew(symtab->symbuf, 1);
2734 symbuf = symtab->symbuf;
2735 symbuf->bufsize = nr;
2736 snew(symbuf->buf, nr);
2737 for (i = 0; (i < nr); i++)
2739 gmx_fio_do_string(fio, buf);
2740 symbuf->buf[i] = gmx_strdup(buf);
2745 symbuf = symtab->symbuf;
2746 while (symbuf != NULL)
2748 for (i = 0; (i < symbuf->bufsize) && (i < nr); i++)
2750 gmx_fio_do_string(fio, symbuf->buf[i]);
2753 symbuf = symbuf->next;
2757 gmx_fatal(FARGS, "nr of symtab strings left: %d", nr);
2762 static void do_cmap(t_fileio *fio, gmx_cmap_t *cmap_grid, gmx_bool bRead)
2764 int i, j, ngrid, gs, nelem;
2766 gmx_fio_do_int(fio, cmap_grid->ngrid);
2767 gmx_fio_do_int(fio, cmap_grid->grid_spacing);
2769 ngrid = cmap_grid->ngrid;
2770 gs = cmap_grid->grid_spacing;
2775 snew(cmap_grid->cmapdata, ngrid);
2777 for (i = 0; i < cmap_grid->ngrid; i++)
2779 snew(cmap_grid->cmapdata[i].cmap, 4*nelem);
2783 for (i = 0; i < cmap_grid->ngrid; i++)
2785 for (j = 0; j < nelem; j++)
2787 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4]);
2788 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+1]);
2789 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+2]);
2790 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+3]);
2796 void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols)
2798 int m, a, a0, a1, r;
2802 /* We always assign a new chain number, but save the chain id characters
2803 * for larger molecules.
2805 #define CHAIN_MIN_ATOMS 15
2809 for (m = 0; m < mols->nr; m++)
2811 a0 = mols->index[m];
2812 a1 = mols->index[m+1];
2813 if ((a1-a0 >= CHAIN_MIN_ATOMS) && (chainid <= 'Z'))
2822 for (a = a0; a < a1; a++)
2824 atoms->resinfo[atoms->atom[a].resind].chainnum = chainnum;
2825 atoms->resinfo[atoms->atom[a].resind].chainid = c;
2830 /* Blank out the chain id if there was only one chain */
2833 for (r = 0; r < atoms->nres; r++)
2835 atoms->resinfo[r].chainid = ' ';
2840 static void do_moltype(t_fileio *fio, gmx_moltype_t *molt, gmx_bool bRead,
2841 t_symtab *symtab, int file_version,
2842 gmx_groups_t *groups)
2846 if (file_version >= 57)
2848 do_symstr(fio, &(molt->name), bRead, symtab);
2851 do_atoms(fio, &molt->atoms, bRead, symtab, file_version, groups);
2853 if (bRead && gmx_debug_at)
2855 pr_atoms(debug, 0, "atoms", &molt->atoms, TRUE);
2858 if (file_version >= 57)
2860 do_ilists(fio, molt->ilist, bRead, file_version);
2862 do_block(fio, &molt->cgs, bRead, file_version);
2863 if (bRead && gmx_debug_at)
2865 pr_block(debug, 0, "cgs", &molt->cgs, TRUE);
2869 /* This used to be in the atoms struct */
2870 do_blocka(fio, &molt->excls, bRead, file_version);
2873 static void do_molblock(t_fileio *fio, gmx_molblock_t *molb, gmx_bool bRead)
2877 gmx_fio_do_int(fio, molb->type);
2878 gmx_fio_do_int(fio, molb->nmol);
2879 gmx_fio_do_int(fio, molb->natoms_mol);
2880 /* Position restraint coordinates */
2881 gmx_fio_do_int(fio, molb->nposres_xA);
2882 if (molb->nposres_xA > 0)
2886 snew(molb->posres_xA, molb->nposres_xA);
2888 gmx_fio_ndo_rvec(fio, molb->posres_xA, molb->nposres_xA);
2890 gmx_fio_do_int(fio, molb->nposres_xB);
2891 if (molb->nposres_xB > 0)
2895 snew(molb->posres_xB, molb->nposres_xB);
2897 gmx_fio_ndo_rvec(fio, molb->posres_xB, molb->nposres_xB);
2902 static t_block mtop_mols(gmx_mtop_t *mtop)
2908 for (mb = 0; mb < mtop->nmolblock; mb++)
2910 mols.nr += mtop->molblock[mb].nmol;
2912 mols.nalloc_index = mols.nr + 1;
2913 snew(mols.index, mols.nalloc_index);
2918 for (mb = 0; mb < mtop->nmolblock; mb++)
2920 for (mol = 0; mol < mtop->molblock[mb].nmol; mol++)
2922 a += mtop->molblock[mb].natoms_mol;
2931 static void add_posres_molblock(gmx_mtop_t *mtop)
2936 gmx_molblock_t *molb;
2939 /* posres reference positions are stored in ip->posres (if present) and
2940 in ip->fbposres (if present). If normal and flat-bottomed posres are present,
2941 posres.pos0A are identical to fbposres.pos0. */
2942 il = &mtop->moltype[0].ilist[F_POSRES];
2943 ilfb = &mtop->moltype[0].ilist[F_FBPOSRES];
2944 if (il->nr == 0 && ilfb->nr == 0)
2950 for (i = 0; i < il->nr; i += 2)
2952 ip = &mtop->ffparams.iparams[il->iatoms[i]];
2953 am = max(am, il->iatoms[i+1]);
2954 if (ip->posres.pos0B[XX] != ip->posres.pos0A[XX] ||
2955 ip->posres.pos0B[YY] != ip->posres.pos0A[YY] ||
2956 ip->posres.pos0B[ZZ] != ip->posres.pos0A[ZZ])
2961 /* This loop is required if we have only flat-bottomed posres:
2963 - bFE == FALSE (no B-state for flat-bottomed posres) */
2966 for (i = 0; i < ilfb->nr; i += 2)
2968 ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
2969 am = max(am, ilfb->iatoms[i+1]);
2972 /* Make the posres coordinate block end at a molecule end */
2974 while (am >= mtop->mols.index[mol+1])
2978 molb = &mtop->molblock[0];
2979 molb->nposres_xA = mtop->mols.index[mol+1];
2980 snew(molb->posres_xA, molb->nposres_xA);
2983 molb->nposres_xB = molb->nposres_xA;
2984 snew(molb->posres_xB, molb->nposres_xB);
2988 molb->nposres_xB = 0;
2990 for (i = 0; i < il->nr; i += 2)
2992 ip = &mtop->ffparams.iparams[il->iatoms[i]];
2993 a = il->iatoms[i+1];
2994 molb->posres_xA[a][XX] = ip->posres.pos0A[XX];
2995 molb->posres_xA[a][YY] = ip->posres.pos0A[YY];
2996 molb->posres_xA[a][ZZ] = ip->posres.pos0A[ZZ];
2999 molb->posres_xB[a][XX] = ip->posres.pos0B[XX];
3000 molb->posres_xB[a][YY] = ip->posres.pos0B[YY];
3001 molb->posres_xB[a][ZZ] = ip->posres.pos0B[ZZ];
3006 /* If only flat-bottomed posres are present, take reference pos from them.
3007 Here: bFE == FALSE */
3008 for (i = 0; i < ilfb->nr; i += 2)
3010 ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
3011 a = ilfb->iatoms[i+1];
3012 molb->posres_xA[a][XX] = ip->fbposres.pos0[XX];
3013 molb->posres_xA[a][YY] = ip->fbposres.pos0[YY];
3014 molb->posres_xA[a][ZZ] = ip->fbposres.pos0[ZZ];
3019 static void set_disres_npair(gmx_mtop_t *mtop)
3026 ip = mtop->ffparams.iparams;
3028 for (mt = 0; mt < mtop->nmoltype; mt++)
3030 il = &mtop->moltype[mt].ilist[F_DISRES];
3035 for (i = 0; i < il->nr; i += 3)
3038 if (i+3 == il->nr || ip[a[i]].disres.label != ip[a[i+3]].disres.label)
3040 ip[a[i]].disres.npair = npair;
3048 static void do_mtop(t_fileio *fio, gmx_mtop_t *mtop, gmx_bool bRead,
3058 do_symtab(fio, &(mtop->symtab), bRead);
3061 pr_symtab(debug, 0, "symtab", &mtop->symtab);
3064 do_symstr(fio, &(mtop->name), bRead, &(mtop->symtab));
3066 if (file_version >= 57)
3068 do_ffparams(fio, &mtop->ffparams, bRead, file_version);
3070 gmx_fio_do_int(fio, mtop->nmoltype);
3078 snew(mtop->moltype, mtop->nmoltype);
3079 if (file_version < 57)
3081 mtop->moltype[0].name = mtop->name;
3084 for (mt = 0; mt < mtop->nmoltype; mt++)
3086 do_moltype(fio, &mtop->moltype[mt], bRead, &mtop->symtab, file_version,
3090 if (file_version >= 57)
3092 gmx_fio_do_int(fio, mtop->nmolblock);
3096 mtop->nmolblock = 1;
3100 snew(mtop->molblock, mtop->nmolblock);
3102 if (file_version >= 57)
3104 for (mb = 0; mb < mtop->nmolblock; mb++)
3106 do_molblock(fio, &mtop->molblock[mb], bRead);
3108 gmx_fio_do_int(fio, mtop->natoms);
3112 mtop->molblock[0].type = 0;
3113 mtop->molblock[0].nmol = 1;
3114 mtop->molblock[0].natoms_mol = mtop->moltype[0].atoms.nr;
3115 mtop->molblock[0].nposres_xA = 0;
3116 mtop->molblock[0].nposres_xB = 0;
3119 do_atomtypes (fio, &(mtop->atomtypes), bRead, file_version);
3122 pr_atomtypes(debug, 0, "atomtypes", &mtop->atomtypes, TRUE);
3125 if (file_version < 57)
3127 /* Debug statements are inside do_idef */
3128 do_idef (fio, &mtop->ffparams, &mtop->moltype[0], bRead, file_version);
3129 mtop->natoms = mtop->moltype[0].atoms.nr;
3132 if (file_version >= 65)
3134 do_cmap(fio, &mtop->ffparams.cmap_grid, bRead);
3138 mtop->ffparams.cmap_grid.ngrid = 0;
3139 mtop->ffparams.cmap_grid.grid_spacing = 0;
3140 mtop->ffparams.cmap_grid.cmapdata = NULL;
3143 if (file_version >= 57)
3145 do_groups(fio, &mtop->groups, bRead, &(mtop->symtab), file_version);
3148 if (file_version < 57)
3150 do_block(fio, &mtop->moltype[0].cgs, bRead, file_version);
3151 if (bRead && gmx_debug_at)
3153 pr_block(debug, 0, "cgs", &mtop->moltype[0].cgs, TRUE);
3155 do_block(fio, &mtop->mols, bRead, file_version);
3156 /* Add the posres coordinates to the molblock */
3157 add_posres_molblock(mtop);
3161 if (file_version >= 57)
3163 done_block(&mtop->mols);
3164 mtop->mols = mtop_mols(mtop);
3168 pr_block(debug, 0, "mols", &mtop->mols, TRUE);
3172 if (file_version < 51)
3174 /* Here used to be the shake blocks */
3175 do_blocka(fio, &dumb, bRead, file_version);
3188 close_symtab(&(mtop->symtab));
3192 /* If TopOnlyOK is TRUE then we can read even future versions
3193 * of tpx files, provided the file_generation hasn't changed.
3194 * If it is FALSE, we need the inputrecord too, and bail out
3195 * if the file is newer than the program.
3197 * The version and generation if the topology (see top of this file)
3198 * are returned in the two last arguments.
3200 * If possible, we will read the inputrec even when TopOnlyOK is TRUE.
3202 static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx,
3203 gmx_bool TopOnlyOK, int *file_version,
3204 int *file_generation)
3207 char file_tag[STRLEN];
3214 gmx_fio_checktype(fio);
3215 gmx_fio_setdebug(fio, bDebugMode());
3217 /* XDR binary topology file */
3218 precision = sizeof(real);
3221 gmx_fio_do_string(fio, buf);
3222 if (strncmp(buf, "VERSION", 7))
3224 gmx_fatal(FARGS, "Can not read file %s,\n"
3225 " this file is from a Gromacs version which is older than 2.0\n"
3226 " Make a new one with grompp or use a gro or pdb file, if possible",
3227 gmx_fio_getname(fio));
3229 gmx_fio_do_int(fio, precision);
3230 bDouble = (precision == sizeof(double));
3231 if ((precision != sizeof(float)) && !bDouble)
3233 gmx_fatal(FARGS, "Unknown precision in file %s: real is %d bytes "
3234 "instead of %d or %d",
3235 gmx_fio_getname(fio), precision, sizeof(float), sizeof(double));
3237 gmx_fio_setprecision(fio, bDouble);
3238 fprintf(stderr, "Reading file %s, %s (%s precision)\n",
3239 gmx_fio_getname(fio), buf, bDouble ? "double" : "single");
3243 gmx_fio_write_string(fio, GromacsVersion());
3244 bDouble = (precision == sizeof(double));
3245 gmx_fio_setprecision(fio, bDouble);
3246 gmx_fio_do_int(fio, precision);
3248 sprintf(file_tag, "%s", tpx_tag);
3249 fgen = tpx_generation;
3252 /* Check versions! */
3253 gmx_fio_do_int(fio, fver);
3255 /* This is for backward compatibility with development versions 77-79
3256 * where the tag was, mistakenly, placed before the generation,
3257 * which would cause a segv instead of a proper error message
3258 * when reading the topology only from tpx with <77 code.
3260 if (fver >= 77 && fver <= 79)
3262 gmx_fio_do_string(fio, file_tag);
3267 gmx_fio_do_int(fio, fgen);
3276 gmx_fio_do_string(fio, file_tag);
3282 /* Versions before 77 don't have the tag, set it to release */
3283 sprintf(file_tag, "%s", TPX_TAG_RELEASE);
3286 if (strcmp(file_tag, tpx_tag) != 0)
3288 fprintf(stderr, "Note: file tpx tag '%s', software tpx tag '%s'\n",
3291 /* We only support reading tpx files with the same tag as the code
3292 * or tpx files with the release tag and with lower version number.
3294 if (strcmp(file_tag, TPX_TAG_RELEASE) != 0 && fver < tpx_version)
3296 gmx_fatal(FARGS, "tpx tag/version mismatch: reading tpx file (%s) version %d, tag '%s' with program for tpx version %d, tag '%s'",
3297 gmx_fio_getname(fio), fver, file_tag,
3298 tpx_version, tpx_tag);
3303 if (file_version != NULL)
3305 *file_version = fver;
3307 if (file_generation != NULL)
3309 *file_generation = fgen;
3313 if ((fver <= tpx_incompatible_version) ||
3314 ((fver > tpx_version) && !TopOnlyOK) ||
3315 (fgen > tpx_generation) ||
3316 tpx_version == 80) /*80 was used by both 5.0-dev and 4.6-dev*/
3318 gmx_fatal(FARGS, "reading tpx file (%s) version %d with version %d program",
3319 gmx_fio_getname(fio), fver, tpx_version);
3322 gmx_fio_do_int(fio, tpx->natoms);
3325 gmx_fio_do_int(fio, tpx->ngtc);
3333 gmx_fio_do_int(fio, idum);
3334 gmx_fio_do_real(fio, rdum);
3336 /*a better decision will eventually (5.0 or later) need to be made
3337 on how to treat the alchemical state of the system, which can now
3338 vary through a simulation, and cannot be completely described
3339 though a single lambda variable, or even a single state
3340 index. Eventually, should probably be a vector. MRS*/
3343 gmx_fio_do_int(fio, tpx->fep_state);
3345 gmx_fio_do_real(fio, tpx->lambda);
3346 gmx_fio_do_int(fio, tpx->bIr);
3347 gmx_fio_do_int(fio, tpx->bTop);
3348 gmx_fio_do_int(fio, tpx->bX);
3349 gmx_fio_do_int(fio, tpx->bV);
3350 gmx_fio_do_int(fio, tpx->bF);
3351 gmx_fio_do_int(fio, tpx->bBox);
3353 if ((fgen > tpx_generation))
3355 /* This can only happen if TopOnlyOK=TRUE */
3360 static int do_tpx(t_fileio *fio, gmx_bool bRead,
3361 t_inputrec *ir, t_state *state, rvec *f, gmx_mtop_t *mtop,
3362 gmx_bool bXVallocated)
3368 int file_version, file_generation;
3372 gmx_bool bPeriodicMols;
3376 tpx.natoms = state->natoms;
3377 tpx.ngtc = state->ngtc; /* need to add nnhpres here? */
3378 tpx.fep_state = state->fep_state;
3379 tpx.lambda = state->lambda[efptFEP];
3380 tpx.bIr = (ir != NULL);
3381 tpx.bTop = (mtop != NULL);
3382 tpx.bX = (state->x != NULL);
3383 tpx.bV = (state->v != NULL);
3384 tpx.bF = (f != NULL);
3388 TopOnlyOK = (ir == NULL);
3390 do_tpxheader(fio, bRead, &tpx, TopOnlyOK, &file_version, &file_generation);
3395 /* state->lambda = tpx.lambda;*/ /*remove this eventually? */
3396 /* The init_state calls initialize the Nose-Hoover xi integrals to zero */
3401 init_state(state, 0, tpx.ngtc, 0, 0, 0); /* nose-hoover chains */ /* eventually, need to add nnhpres here? */
3402 state->natoms = tpx.natoms;
3403 state->nalloc = tpx.natoms;
3409 init_state(state, tpx.natoms, tpx.ngtc, 0, 0, 0); /* nose-hoover chains */
3413 #define do_test(fio, b, p) if (bRead && (p != NULL) && !b) gmx_fatal(FARGS, "No %s in %s",#p, gmx_fio_getname(fio))
3415 do_test(fio, tpx.bBox, state->box);
3418 gmx_fio_ndo_rvec(fio, state->box, DIM);
3419 if (file_version >= 51)
3421 gmx_fio_ndo_rvec(fio, state->box_rel, DIM);
3425 /* We initialize box_rel after reading the inputrec */
3426 clear_mat(state->box_rel);
3428 if (file_version >= 28)
3430 gmx_fio_ndo_rvec(fio, state->boxv, DIM);
3431 if (file_version < 56)
3434 gmx_fio_ndo_rvec(fio, mdum, DIM);
3439 if (state->ngtc > 0 && file_version >= 28)
3442 /*ndo_double(state->nosehoover_xi,state->ngtc,bDum);*/
3443 /*ndo_double(state->nosehoover_vxi,state->ngtc,bDum);*/
3444 /*ndo_double(state->therm_integral,state->ngtc,bDum);*/
3445 snew(dumv, state->ngtc);
3446 if (file_version < 69)
3448 gmx_fio_ndo_real(fio, dumv, state->ngtc);
3450 /* These used to be the Berendsen tcoupl_lambda's */
3451 gmx_fio_ndo_real(fio, dumv, state->ngtc);
3455 /* Prior to tpx version 26, the inputrec was here.
3456 * I moved it to enable partial forward-compatibility
3457 * for analysis/viewer programs.
3459 if (file_version < 26)
3461 do_test(fio, tpx.bIr, ir);
3466 do_inputrec(fio, ir, bRead, file_version,
3467 mtop ? &mtop->ffparams.fudgeQQ : NULL);
3470 pr_inputrec(debug, 0, "inputrec", ir, FALSE);
3475 do_inputrec(fio, &dum_ir, bRead, file_version,
3476 mtop ? &mtop->ffparams.fudgeQQ : NULL);
3479 pr_inputrec(debug, 0, "inputrec", &dum_ir, FALSE);
3481 done_inputrec(&dum_ir);
3487 do_test(fio, tpx.bTop, mtop);
3492 do_mtop(fio, mtop, bRead, file_version);
3496 do_mtop(fio, &dum_top, bRead, file_version);
3497 done_mtop(&dum_top, TRUE);
3500 do_test(fio, tpx.bX, state->x);
3505 state->flags |= (1<<estX);
3507 gmx_fio_ndo_rvec(fio, state->x, state->natoms);
3510 do_test(fio, tpx.bV, state->v);
3515 state->flags |= (1<<estV);
3517 gmx_fio_ndo_rvec(fio, state->v, state->natoms);
3520 do_test(fio, tpx.bF, f);
3523 gmx_fio_ndo_rvec(fio, f, state->natoms);
3526 /* Starting with tpx version 26, we have the inputrec
3527 * at the end of the file, so we can ignore it
3528 * if the file is never than the software (but still the
3529 * same generation - see comments at the top of this file.
3534 bPeriodicMols = FALSE;
3535 if (file_version >= 26)
3537 do_test(fio, tpx.bIr, ir);
3540 if (file_version >= 53)
3542 /* Removed the pbc info from do_inputrec, since we always want it */
3546 bPeriodicMols = ir->bPeriodicMols;
3548 gmx_fio_do_int(fio, ePBC);
3549 gmx_fio_do_gmx_bool(fio, bPeriodicMols);
3551 if (file_generation <= tpx_generation && ir)
3553 do_inputrec(fio, ir, bRead, file_version, mtop ? &mtop->ffparams.fudgeQQ : NULL);
3556 pr_inputrec(debug, 0, "inputrec", ir, FALSE);
3558 if (file_version < 51)
3560 set_box_rel(ir, state);
3562 if (file_version < 53)
3565 bPeriodicMols = ir->bPeriodicMols;
3568 if (bRead && ir && file_version >= 53)
3570 /* We need to do this after do_inputrec, since that initializes ir */
3572 ir->bPeriodicMols = bPeriodicMols;
3581 if (state->ngtc == 0)
3583 /* Reading old version without tcoupl state data: set it */
3584 init_gtc_state(state, ir->opts.ngtc, 0, ir->opts.nhchainlength);
3586 if (tpx.bTop && mtop)
3588 if (file_version < 57)
3590 if (mtop->moltype[0].ilist[F_DISRES].nr > 0)
3592 ir->eDisre = edrSimple;
3596 ir->eDisre = edrNone;
3599 set_disres_npair(mtop);
3603 if (tpx.bTop && mtop)
3605 gmx_mtop_finalize(mtop);
3608 if (file_version >= 57)
3612 env = getenv("GMX_NOCHARGEGROUPS");
3615 sscanf(env, "%d", &ienv);
3616 fprintf(stderr, "\nFound env.var. GMX_NOCHARGEGROUPS = %d\n",
3621 "Will make single atomic charge groups in non-solvent%s\n",
3622 ienv > 1 ? " and solvent" : "");
3623 gmx_mtop_make_atomic_charge_groups(mtop, ienv == 1);
3625 fprintf(stderr, "\n");
3633 /************************************************************
3635 * The following routines are the exported ones
3637 ************************************************************/
3639 t_fileio *open_tpx(const char *fn, const char *mode)
3641 return gmx_fio_open(fn, mode);
3644 void close_tpx(t_fileio *fio)
3649 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
3650 int *file_version, int *file_generation)
3654 fio = open_tpx(fn, "r");
3655 do_tpxheader(fio, TRUE, tpx, TopOnlyOK, file_version, file_generation);
3659 void write_tpx_state(const char *fn,
3660 t_inputrec *ir, t_state *state, gmx_mtop_t *mtop)
3664 fio = open_tpx(fn, "w");
3665 do_tpx(fio, FALSE, ir, state, NULL, mtop, FALSE);
3669 void read_tpx_state(const char *fn,
3670 t_inputrec *ir, t_state *state, rvec *f, gmx_mtop_t *mtop)
3674 fio = open_tpx(fn, "r");
3675 do_tpx(fio, TRUE, ir, state, f, mtop, FALSE);
3679 int read_tpx(const char *fn,
3680 t_inputrec *ir, matrix box, int *natoms,
3681 rvec *x, rvec *v, rvec *f, gmx_mtop_t *mtop)
3689 fio = open_tpx(fn, "r");
3690 ePBC = do_tpx(fio, TRUE, ir, &state, f, mtop, TRUE);
3692 *natoms = state.natoms;
3695 copy_mat(state.box, box);
3704 int read_tpx_top(const char *fn,
3705 t_inputrec *ir, matrix box, int *natoms,
3706 rvec *x, rvec *v, rvec *f, t_topology *top)
3712 ePBC = read_tpx(fn, ir, box, natoms, x, v, f, &mtop);
3714 *top = gmx_mtop_t_to_t_topology(&mtop);
3719 gmx_bool fn2bTPX(const char *file)
3721 return (efTPR == fn2ftp(file));
3724 static void done_gmx_groups_t(gmx_groups_t *g)
3728 for (i = 0; (i < egcNR); i++)
3730 if (NULL != g->grps[i].nm_ind)
3732 sfree(g->grps[i].nm_ind);
3733 g->grps[i].nm_ind = NULL;
3735 if (NULL != g->grpnr[i])
3741 /* The contents of this array is in symtab, don't free it here */
3745 gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *ePBC,
3746 rvec **x, rvec **v, matrix box, gmx_bool bMass)
3749 int natoms, i, version, generation;
3750 gmx_bool bTop, bXNULL = FALSE;
3752 t_topology *topconv;
3755 bTop = fn2bTPX(infile);
3759 read_tpxheader(infile, &header, TRUE, &version, &generation);
3762 snew(*x, header.natoms);
3766 snew(*v, header.natoms);
3769 *ePBC = read_tpx(infile, NULL, box, &natoms,
3770 (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
3771 *top = gmx_mtop_t_to_t_topology(mtop);
3772 /* In this case we need to throw away the group data too */
3773 done_gmx_groups_t(&mtop->groups);
3775 strcpy(title, *top->name);
3776 tpx_make_chain_identifiers(&top->atoms, &top->mols);
3780 get_stx_coordnum(infile, &natoms);
3781 init_t_atoms(&top->atoms, natoms, (fn2ftp(infile) == efPDB));
3792 read_stx_conf(infile, title, &top->atoms, *x, (v == NULL) ? NULL : *v, ePBC, box);
3800 aps = gmx_atomprop_init();
3801 for (i = 0; (i < natoms); i++)
3803 if (!gmx_atomprop_query(aps, epropMass,
3804 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
3805 *top->atoms.atomname[i],
3806 &(top->atoms.atom[i].m)))
3810 fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
3811 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
3812 top->atoms.resinfo[top->atoms.atom[i].resind].nr,
3813 *top->atoms.atomname[i]);
3817 gmx_atomprop_destroy(aps);
3819 top->idef.ntypes = -1;