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, 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.
41 /* This file is completely threadsafe - keep it that way! */
47 #include "gmx_fatal.h"
60 #include "mtop_util.h"
62 #define TPX_TAG_RELEASE "release"
64 /* This is the tag string which is stored in the tpx file.
65 * Change this if you want to change the tpx format in a feature branch.
66 * This ensures that there will not be different tpx formats around which
67 * can not be distinguished.
69 static const char *tpx_tag = TPX_TAG_RELEASE;
72 /* The tpx_version number should be increased whenever the file format changes!
74 * The following comment section helps to keep track of which feature has been
75 * added in which version.
77 * version feature added
78 * 96 support for ion/water position swaps (computational electrophysiology)
79 * 97 switch ld_seed from int to gmx_int64_t
81 * The following macros help the code be more self-documenting and
82 * ensure merges do not silently resolve when two patches make the
83 * same bump to the number. Unfortunately, compilers don't like
84 * initializing a const int with a const int, so we have to be a bit
85 * dirty and use a macro.
87 #define tpx_version_use_64_bit_random_seed 97
88 static const int tpx_version = tpx_version_use_64_bit_random_seed;
91 /* This number should only be increased when you edit the TOPOLOGY section
92 * or the HEADER of the tpx format.
93 * This way we can maintain forward compatibility too for all analysis tools
94 * and/or external programs that only need to know the atom/residue names,
95 * charges, and bond connectivity.
97 * It first appeared in tpx version 26, when I also moved the inputrecord
98 * to the end of the tpx file, so we can just skip it if we only
101 static const int tpx_generation = 25;
103 /* This number should be the most recent backwards incompatible version
104 * I.e., if this number is 9, we cannot read tpx version 9 with this code.
106 static const int tpx_incompatible_version = 9;
110 /* Struct used to maintain tpx compatibility when function types are added */
112 int fvnr; /* file version number in which the function type first appeared */
113 int ftype; /* function type */
117 * The entries should be ordered in:
118 * 1. ascending file version number
119 * 2. ascending function type number
121 /*static const t_ftupd ftupd[] = {
122 { 20, F_CUBICBONDS },
126 { 22, F_DISRESVIOL },
132 { 26, F_DIHRESVIOL },
133 { 30, F_CROSS_BOND_BONDS },
134 { 30, F_CROSS_BOND_ANGLES },
135 { 30, F_UREY_BRADLEY },
136 { 30, F_POLARIZATION },
140 * The entries should be ordered in:
141 * 1. ascending function type number
142 * 2. ascending file version number
144 /* question; what is the purpose of the commented code above? */
145 static const t_ftupd ftupd[] = {
146 { 20, F_CUBICBONDS },
151 { 43, F_TABBONDSNC },
152 { 70, F_RESTRBONDS },
153 { 76, F_LINEAR_ANGLES },
154 { 30, F_CROSS_BOND_BONDS },
155 { 30, F_CROSS_BOND_ANGLES },
156 { 30, F_UREY_BRADLEY },
157 { 34, F_QUARTIC_ANGLES },
167 { 72, F_NPSOLVATION },
169 { 41, F_LJC_PAIRS_NB },
172 { 32, F_COUL_RECIP },
175 { 30, F_POLARIZATION },
178 { 22, F_DISRESVIOL },
182 { 26, F_DIHRESVIOL },
187 { 46, F_ECONSERVED },
188 { 69, F_VTEMP_NOLONGERUSED},
190 { 54, F_DVDL_CONSTR },
191 { 76, F_ANHARM_POL },
194 { 79, F_DVDL_BONDED, },
195 { 79, F_DVDL_RESTRAINT },
196 { 79, F_DVDL_TEMPERATURE },
198 #define NFTUPD asize(ftupd)
200 /* Needed for backward compatibility */
203 static void _do_section(t_fileio *fio, int key, gmx_bool bRead, const char *src,
209 if (gmx_fio_getftp(fio) == efTPA)
213 gmx_fio_write_string(fio, itemstr[key]);
214 bDbg = gmx_fio_getdebug(fio);
215 gmx_fio_setdebug(fio, FALSE);
216 gmx_fio_write_string(fio, comment_str[key]);
217 gmx_fio_setdebug(fio, bDbg);
221 if (gmx_fio_getdebug(fio))
223 fprintf(stderr, "Looking for section %s (%s, %d)",
224 itemstr[key], src, line);
229 gmx_fio_do_string(fio, buf);
231 while ((gmx_strcasecmp(buf, itemstr[key]) != 0));
233 if (gmx_strcasecmp(buf, itemstr[key]) != 0)
235 gmx_fatal(FARGS, "\nCould not find section heading %s", itemstr[key]);
237 else if (gmx_fio_getdebug(fio))
239 fprintf(stderr, " and found it\n");
245 #define do_section(fio, key, bRead) _do_section(fio, key, bRead, __FILE__, __LINE__)
247 /**************************************************************
249 * Now the higer level routines that do io of the structures and arrays
251 **************************************************************/
252 static void do_pullgrp_tpx_pre95(t_fileio *fio,
261 gmx_fio_do_int(fio, pgrp->nat);
264 snew(pgrp->ind, pgrp->nat);
266 gmx_fio_ndo_int(fio, pgrp->ind, pgrp->nat);
267 gmx_fio_do_int(fio, pgrp->nweight);
270 snew(pgrp->weight, pgrp->nweight);
272 gmx_fio_ndo_real(fio, pgrp->weight, pgrp->nweight);
273 gmx_fio_do_int(fio, pgrp->pbcatom);
274 gmx_fio_do_rvec(fio, pcrd->vec);
275 clear_rvec(pcrd->origin);
276 gmx_fio_do_rvec(fio, tmp);
278 gmx_fio_do_real(fio, pcrd->rate);
279 gmx_fio_do_real(fio, pcrd->k);
280 if (file_version >= 56)
282 gmx_fio_do_real(fio, pcrd->kB);
290 static void do_pull_group(t_fileio *fio, t_pull_group *pgrp, gmx_bool bRead)
294 gmx_fio_do_int(fio, pgrp->nat);
297 snew(pgrp->ind, pgrp->nat);
299 gmx_fio_ndo_int(fio, pgrp->ind, pgrp->nat);
300 gmx_fio_do_int(fio, pgrp->nweight);
303 snew(pgrp->weight, pgrp->nweight);
305 gmx_fio_ndo_real(fio, pgrp->weight, pgrp->nweight);
306 gmx_fio_do_int(fio, pgrp->pbcatom);
309 static void do_pull_coord(t_fileio *fio, t_pull_coord *pcrd)
313 gmx_fio_do_int(fio, pcrd->group[0]);
314 gmx_fio_do_int(fio, pcrd->group[1]);
315 gmx_fio_do_rvec(fio, pcrd->origin);
316 gmx_fio_do_rvec(fio, pcrd->vec);
317 gmx_fio_do_real(fio, pcrd->init);
318 gmx_fio_do_real(fio, pcrd->rate);
319 gmx_fio_do_real(fio, pcrd->k);
320 gmx_fio_do_real(fio, pcrd->kB);
323 static void do_expandedvals(t_fileio *fio, t_expanded *expand, t_lambda *fepvals, gmx_bool bRead, int file_version)
325 /* i is used in the ndo_double macro*/
329 int n_lambda = fepvals->n_lambda;
331 /* reset the lambda calculation window */
332 fepvals->lambda_start_n = 0;
333 fepvals->lambda_stop_n = n_lambda;
334 if (file_version >= 79)
340 snew(expand->init_lambda_weights, n_lambda);
342 gmx_fio_ndo_real(fio, expand->init_lambda_weights, n_lambda);
343 gmx_fio_do_gmx_bool(fio, expand->bInit_weights);
346 gmx_fio_do_int(fio, expand->nstexpanded);
347 gmx_fio_do_int(fio, expand->elmcmove);
348 gmx_fio_do_int(fio, expand->elamstats);
349 gmx_fio_do_int(fio, expand->lmc_repeats);
350 gmx_fio_do_int(fio, expand->gibbsdeltalam);
351 gmx_fio_do_int(fio, expand->lmc_forced_nstart);
352 gmx_fio_do_int(fio, expand->lmc_seed);
353 gmx_fio_do_real(fio, expand->mc_temp);
354 gmx_fio_do_int(fio, expand->bSymmetrizedTMatrix);
355 gmx_fio_do_int(fio, expand->nstTij);
356 gmx_fio_do_int(fio, expand->minvarmin);
357 gmx_fio_do_int(fio, expand->c_range);
358 gmx_fio_do_real(fio, expand->wl_scale);
359 gmx_fio_do_real(fio, expand->wl_ratio);
360 gmx_fio_do_real(fio, expand->init_wl_delta);
361 gmx_fio_do_gmx_bool(fio, expand->bWLoneovert);
362 gmx_fio_do_int(fio, expand->elmceq);
363 gmx_fio_do_int(fio, expand->equil_steps);
364 gmx_fio_do_int(fio, expand->equil_samples);
365 gmx_fio_do_int(fio, expand->equil_n_at_lam);
366 gmx_fio_do_real(fio, expand->equil_wl_delta);
367 gmx_fio_do_real(fio, expand->equil_ratio);
371 static void do_simtempvals(t_fileio *fio, t_simtemp *simtemp, int n_lambda, gmx_bool bRead,
374 if (file_version >= 79)
376 gmx_fio_do_int(fio, simtemp->eSimTempScale);
377 gmx_fio_do_real(fio, simtemp->simtemp_high);
378 gmx_fio_do_real(fio, simtemp->simtemp_low);
383 snew(simtemp->temperatures, n_lambda);
385 gmx_fio_ndo_real(fio, simtemp->temperatures, n_lambda);
390 static void do_fepvals(t_fileio *fio, t_lambda *fepvals, gmx_bool bRead, int file_version)
392 /* i is defined in the ndo_double macro; use g to iterate. */
397 /* free energy values */
399 if (file_version >= 79)
401 gmx_fio_do_int(fio, fepvals->init_fep_state);
402 gmx_fio_do_double(fio, fepvals->init_lambda);
403 gmx_fio_do_double(fio, fepvals->delta_lambda);
405 else if (file_version >= 59)
407 gmx_fio_do_double(fio, fepvals->init_lambda);
408 gmx_fio_do_double(fio, fepvals->delta_lambda);
412 gmx_fio_do_real(fio, rdum);
413 fepvals->init_lambda = rdum;
414 gmx_fio_do_real(fio, rdum);
415 fepvals->delta_lambda = rdum;
417 if (file_version >= 79)
419 gmx_fio_do_int(fio, fepvals->n_lambda);
422 snew(fepvals->all_lambda, efptNR);
424 for (g = 0; g < efptNR; g++)
426 if (fepvals->n_lambda > 0)
430 snew(fepvals->all_lambda[g], fepvals->n_lambda);
432 gmx_fio_ndo_double(fio, fepvals->all_lambda[g], fepvals->n_lambda);
433 gmx_fio_ndo_int(fio, fepvals->separate_dvdl, efptNR);
435 else if (fepvals->init_lambda >= 0)
437 fepvals->separate_dvdl[efptFEP] = TRUE;
441 else if (file_version >= 64)
443 gmx_fio_do_int(fio, fepvals->n_lambda);
448 snew(fepvals->all_lambda, efptNR);
449 /* still allocate the all_lambda array's contents. */
450 for (g = 0; g < efptNR; g++)
452 if (fepvals->n_lambda > 0)
454 snew(fepvals->all_lambda[g], fepvals->n_lambda);
458 gmx_fio_ndo_double(fio, fepvals->all_lambda[efptFEP],
460 if (fepvals->init_lambda >= 0)
464 fepvals->separate_dvdl[efptFEP] = TRUE;
468 /* copy the contents of the efptFEP lambda component to all
469 the other components */
470 for (g = 0; g < efptNR; g++)
472 for (h = 0; h < fepvals->n_lambda; h++)
476 fepvals->all_lambda[g][h] =
477 fepvals->all_lambda[efptFEP][h];
486 fepvals->n_lambda = 0;
487 fepvals->all_lambda = NULL;
488 if (fepvals->init_lambda >= 0)
490 fepvals->separate_dvdl[efptFEP] = TRUE;
493 if (file_version >= 13)
495 gmx_fio_do_real(fio, fepvals->sc_alpha);
499 fepvals->sc_alpha = 0;
501 if (file_version >= 38)
503 gmx_fio_do_int(fio, fepvals->sc_power);
507 fepvals->sc_power = 2;
509 if (file_version >= 79)
511 gmx_fio_do_real(fio, fepvals->sc_r_power);
515 fepvals->sc_r_power = 6.0;
517 if (file_version >= 15)
519 gmx_fio_do_real(fio, fepvals->sc_sigma);
523 fepvals->sc_sigma = 0.3;
527 if (file_version >= 71)
529 fepvals->sc_sigma_min = fepvals->sc_sigma;
533 fepvals->sc_sigma_min = 0;
536 if (file_version >= 79)
538 gmx_fio_do_int(fio, fepvals->bScCoul);
542 fepvals->bScCoul = TRUE;
544 if (file_version >= 64)
546 gmx_fio_do_int(fio, fepvals->nstdhdl);
550 fepvals->nstdhdl = 1;
553 if (file_version >= 73)
555 gmx_fio_do_int(fio, fepvals->separate_dhdl_file);
556 gmx_fio_do_int(fio, fepvals->dhdl_derivatives);
560 fepvals->separate_dhdl_file = esepdhdlfileYES;
561 fepvals->dhdl_derivatives = edhdlderivativesYES;
563 if (file_version >= 71)
565 gmx_fio_do_int(fio, fepvals->dh_hist_size);
566 gmx_fio_do_double(fio, fepvals->dh_hist_spacing);
570 fepvals->dh_hist_size = 0;
571 fepvals->dh_hist_spacing = 0.1;
573 if (file_version >= 79)
575 gmx_fio_do_int(fio, fepvals->bPrintEnergy);
579 fepvals->bPrintEnergy = FALSE;
582 /* handle lambda_neighbors */
583 if ((file_version >= 83 && file_version < 90) || file_version >= 92)
585 gmx_fio_do_int(fio, fepvals->lambda_neighbors);
586 if ( (fepvals->lambda_neighbors >= 0) && (fepvals->init_fep_state >= 0) &&
587 (fepvals->init_lambda < 0) )
589 fepvals->lambda_start_n = (fepvals->init_fep_state -
590 fepvals->lambda_neighbors);
591 fepvals->lambda_stop_n = (fepvals->init_fep_state +
592 fepvals->lambda_neighbors + 1);
593 if (fepvals->lambda_start_n < 0)
595 fepvals->lambda_start_n = 0;;
597 if (fepvals->lambda_stop_n >= fepvals->n_lambda)
599 fepvals->lambda_stop_n = fepvals->n_lambda;
604 fepvals->lambda_start_n = 0;
605 fepvals->lambda_stop_n = fepvals->n_lambda;
610 fepvals->lambda_start_n = 0;
611 fepvals->lambda_stop_n = fepvals->n_lambda;
615 static void do_pull(t_fileio *fio, t_pull *pull, gmx_bool bRead, int file_version)
619 if (file_version >= 95)
621 gmx_fio_do_int(fio, pull->ngroup);
623 gmx_fio_do_int(fio, pull->ncoord);
624 if (file_version < 95)
626 pull->ngroup = pull->ncoord + 1;
628 gmx_fio_do_int(fio, pull->eGeom);
629 gmx_fio_do_ivec(fio, pull->dim);
630 gmx_fio_do_real(fio, pull->cyl_r1);
631 gmx_fio_do_real(fio, pull->cyl_r0);
632 gmx_fio_do_real(fio, pull->constr_tol);
633 if (file_version >= 95)
635 gmx_fio_do_int(fio, pull->bPrintRef);
637 gmx_fio_do_int(fio, pull->nstxout);
638 gmx_fio_do_int(fio, pull->nstfout);
641 snew(pull->group, pull->ngroup);
642 snew(pull->coord, pull->ncoord);
644 if (file_version < 95)
646 /* epullgPOS for position pulling, before epullgDIRPBC was removed */
647 if (pull->eGeom == epullgDIRPBC)
649 gmx_fatal(FARGS, "pull-geometry=position is no longer supported");
651 if (pull->eGeom > epullgDIRPBC)
656 for (g = 0; g < pull->ngroup; g++)
658 /* We read and ignore a pull coordinate for group 0 */
659 do_pullgrp_tpx_pre95(fio, &pull->group[g], &pull->coord[max(g-1, 0)],
660 bRead, file_version);
663 pull->coord[g-1].group[0] = 0;
664 pull->coord[g-1].group[1] = g;
668 pull->bPrintRef = (pull->group[0].nat > 0);
672 for (g = 0; g < pull->ngroup; g++)
674 do_pull_group(fio, &pull->group[g], bRead);
676 for (g = 0; g < pull->ncoord; g++)
678 do_pull_coord(fio, &pull->coord[g]);
684 static void do_rotgrp(t_fileio *fio, t_rotgrp *rotg, gmx_bool bRead)
688 gmx_fio_do_int(fio, rotg->eType);
689 gmx_fio_do_int(fio, rotg->bMassW);
690 gmx_fio_do_int(fio, rotg->nat);
693 snew(rotg->ind, rotg->nat);
695 gmx_fio_ndo_int(fio, rotg->ind, rotg->nat);
698 snew(rotg->x_ref, rotg->nat);
700 gmx_fio_ndo_rvec(fio, rotg->x_ref, rotg->nat);
701 gmx_fio_do_rvec(fio, rotg->vec);
702 gmx_fio_do_rvec(fio, rotg->pivot);
703 gmx_fio_do_real(fio, rotg->rate);
704 gmx_fio_do_real(fio, rotg->k);
705 gmx_fio_do_real(fio, rotg->slab_dist);
706 gmx_fio_do_real(fio, rotg->min_gaussian);
707 gmx_fio_do_real(fio, rotg->eps);
708 gmx_fio_do_int(fio, rotg->eFittype);
709 gmx_fio_do_int(fio, rotg->PotAngle_nstep);
710 gmx_fio_do_real(fio, rotg->PotAngle_step);
713 static void do_rot(t_fileio *fio, t_rot *rot, gmx_bool bRead)
717 gmx_fio_do_int(fio, rot->ngrp);
718 gmx_fio_do_int(fio, rot->nstrout);
719 gmx_fio_do_int(fio, rot->nstsout);
722 snew(rot->grp, rot->ngrp);
724 for (g = 0; g < rot->ngrp; g++)
726 do_rotgrp(fio, &rot->grp[g], bRead);
731 static void do_swapcoords(t_fileio *fio, t_swapcoords *swap, gmx_bool bRead)
736 gmx_fio_do_int(fio, swap->nat);
737 gmx_fio_do_int(fio, swap->nat_sol);
738 for (j = 0; j < 2; j++)
740 gmx_fio_do_int(fio, swap->nat_split[j]);
741 gmx_fio_do_int(fio, swap->massw_split[j]);
743 gmx_fio_do_int(fio, swap->nstswap);
744 gmx_fio_do_int(fio, swap->nAverage);
745 gmx_fio_do_real(fio, swap->threshold);
746 gmx_fio_do_real(fio, swap->cyl0r);
747 gmx_fio_do_real(fio, swap->cyl0u);
748 gmx_fio_do_real(fio, swap->cyl0l);
749 gmx_fio_do_real(fio, swap->cyl1r);
750 gmx_fio_do_real(fio, swap->cyl1u);
751 gmx_fio_do_real(fio, swap->cyl1l);
755 snew(swap->ind, swap->nat);
756 snew(swap->ind_sol, swap->nat_sol);
757 for (j = 0; j < 2; j++)
759 snew(swap->ind_split[j], swap->nat_split[j]);
763 gmx_fio_ndo_int(fio, swap->ind, swap->nat);
764 gmx_fio_ndo_int(fio, swap->ind_sol, swap->nat_sol);
765 for (j = 0; j < 2; j++)
767 gmx_fio_ndo_int(fio, swap->ind_split[j], swap->nat_split[j]);
770 for (j = 0; j < eCompNR; j++)
772 gmx_fio_do_int(fio, swap->nanions[j]);
773 gmx_fio_do_int(fio, swap->ncations[j]);
779 static void do_inputrec(t_fileio *fio, t_inputrec *ir, gmx_bool bRead,
780 int file_version, real *fudgeQQ)
782 int i, j, k, *tmp, idum = 0;
786 real zerotemptime, finish_t, init_temp, finish_temp;
788 if (file_version != tpx_version)
790 /* Give a warning about features that are not accessible */
791 fprintf(stderr, "Note: file tpx version %d, software tpx version %d\n",
792 file_version, tpx_version);
800 if (file_version == 0)
805 /* Basic inputrec stuff */
806 gmx_fio_do_int(fio, ir->eI);
807 if (file_version >= 62)
809 gmx_fio_do_int64(fio, ir->nsteps);
813 gmx_fio_do_int(fio, idum);
816 if (file_version > 25)
818 if (file_version >= 62)
820 gmx_fio_do_int64(fio, ir->init_step);
824 gmx_fio_do_int(fio, idum);
825 ir->init_step = idum;
833 if (file_version >= 58)
835 gmx_fio_do_int(fio, ir->simulation_part);
839 ir->simulation_part = 1;
842 if (file_version >= 67)
844 gmx_fio_do_int(fio, ir->nstcalcenergy);
848 ir->nstcalcenergy = 1;
850 if (file_version < 53)
852 /* The pbc info has been moved out of do_inputrec,
853 * since we always want it, also without reading the inputrec.
855 gmx_fio_do_int(fio, ir->ePBC);
856 if ((file_version <= 15) && (ir->ePBC == 2))
860 if (file_version >= 45)
862 gmx_fio_do_int(fio, ir->bPeriodicMols);
869 ir->bPeriodicMols = TRUE;
873 ir->bPeriodicMols = FALSE;
877 if (file_version >= 81)
879 gmx_fio_do_int(fio, ir->cutoff_scheme);
880 if (file_version < 94)
882 ir->cutoff_scheme = 1 - ir->cutoff_scheme;
887 ir->cutoff_scheme = ecutsGROUP;
889 gmx_fio_do_int(fio, ir->ns_type);
890 gmx_fio_do_int(fio, ir->nstlist);
891 gmx_fio_do_int(fio, ir->ndelta);
892 if (file_version < 41)
894 gmx_fio_do_int(fio, idum);
895 gmx_fio_do_int(fio, idum);
897 if (file_version >= 45)
899 gmx_fio_do_real(fio, ir->rtpi);
905 gmx_fio_do_int(fio, ir->nstcomm);
906 if (file_version > 34)
908 gmx_fio_do_int(fio, ir->comm_mode);
910 else if (ir->nstcomm < 0)
912 ir->comm_mode = ecmANGULAR;
916 ir->comm_mode = ecmLINEAR;
918 ir->nstcomm = abs(ir->nstcomm);
920 if (file_version > 25)
922 gmx_fio_do_int(fio, ir->nstcheckpoint);
926 ir->nstcheckpoint = 0;
929 gmx_fio_do_int(fio, ir->nstcgsteep);
931 if (file_version >= 30)
933 gmx_fio_do_int(fio, ir->nbfgscorr);
940 gmx_fio_do_int(fio, ir->nstlog);
941 gmx_fio_do_int(fio, ir->nstxout);
942 gmx_fio_do_int(fio, ir->nstvout);
943 gmx_fio_do_int(fio, ir->nstfout);
944 gmx_fio_do_int(fio, ir->nstenergy);
945 gmx_fio_do_int(fio, ir->nstxout_compressed);
946 if (file_version >= 59)
948 gmx_fio_do_double(fio, ir->init_t);
949 gmx_fio_do_double(fio, ir->delta_t);
953 gmx_fio_do_real(fio, rdum);
955 gmx_fio_do_real(fio, rdum);
958 gmx_fio_do_real(fio, ir->x_compression_precision);
959 if (file_version < 19)
961 gmx_fio_do_int(fio, idum);
962 gmx_fio_do_int(fio, idum);
964 if (file_version < 18)
966 gmx_fio_do_int(fio, idum);
968 if (file_version >= 81)
970 gmx_fio_do_real(fio, ir->verletbuf_tol);
974 ir->verletbuf_tol = 0;
976 gmx_fio_do_real(fio, ir->rlist);
977 if (file_version >= 67)
979 gmx_fio_do_real(fio, ir->rlistlong);
981 if (file_version >= 82 && file_version != 90)
983 gmx_fio_do_int(fio, ir->nstcalclr);
987 /* Calculate at NS steps */
988 ir->nstcalclr = ir->nstlist;
990 gmx_fio_do_int(fio, ir->coulombtype);
991 if (file_version < 32 && ir->coulombtype == eelRF)
993 ir->coulombtype = eelRF_NEC;
995 if (file_version >= 81)
997 gmx_fio_do_int(fio, ir->coulomb_modifier);
1001 ir->coulomb_modifier = (ir->cutoff_scheme == ecutsVERLET ? eintmodPOTSHIFT : eintmodNONE);
1003 gmx_fio_do_real(fio, ir->rcoulomb_switch);
1004 gmx_fio_do_real(fio, ir->rcoulomb);
1005 gmx_fio_do_int(fio, ir->vdwtype);
1006 if (file_version >= 81)
1008 gmx_fio_do_int(fio, ir->vdw_modifier);
1012 ir->vdw_modifier = (ir->cutoff_scheme == ecutsVERLET ? eintmodPOTSHIFT : eintmodNONE);
1014 gmx_fio_do_real(fio, ir->rvdw_switch);
1015 gmx_fio_do_real(fio, ir->rvdw);
1016 if (file_version < 67)
1018 ir->rlistlong = max_cutoff(ir->rlist, max_cutoff(ir->rvdw, ir->rcoulomb));
1020 gmx_fio_do_int(fio, ir->eDispCorr);
1021 gmx_fio_do_real(fio, ir->epsilon_r);
1022 if (file_version >= 37)
1024 gmx_fio_do_real(fio, ir->epsilon_rf);
1028 if (EEL_RF(ir->coulombtype))
1030 ir->epsilon_rf = ir->epsilon_r;
1031 ir->epsilon_r = 1.0;
1035 ir->epsilon_rf = 1.0;
1038 if (file_version >= 29)
1040 gmx_fio_do_real(fio, ir->tabext);
1047 if (file_version > 25)
1049 gmx_fio_do_int(fio, ir->gb_algorithm);
1050 gmx_fio_do_int(fio, ir->nstgbradii);
1051 gmx_fio_do_real(fio, ir->rgbradii);
1052 gmx_fio_do_real(fio, ir->gb_saltconc);
1053 gmx_fio_do_int(fio, ir->implicit_solvent);
1057 ir->gb_algorithm = egbSTILL;
1060 ir->gb_saltconc = 0;
1061 ir->implicit_solvent = eisNO;
1063 if (file_version >= 55)
1065 gmx_fio_do_real(fio, ir->gb_epsilon_solvent);
1066 gmx_fio_do_real(fio, ir->gb_obc_alpha);
1067 gmx_fio_do_real(fio, ir->gb_obc_beta);
1068 gmx_fio_do_real(fio, ir->gb_obc_gamma);
1069 if (file_version >= 60)
1071 gmx_fio_do_real(fio, ir->gb_dielectric_offset);
1072 gmx_fio_do_int(fio, ir->sa_algorithm);
1076 ir->gb_dielectric_offset = 0.009;
1077 ir->sa_algorithm = esaAPPROX;
1079 gmx_fio_do_real(fio, ir->sa_surface_tension);
1081 /* Override sa_surface_tension if it is not changed in the mpd-file */
1082 if (ir->sa_surface_tension < 0)
1084 if (ir->gb_algorithm == egbSTILL)
1086 ir->sa_surface_tension = 0.0049 * 100 * CAL2JOULE;
1088 else if (ir->gb_algorithm == egbHCT || ir->gb_algorithm == egbOBC)
1090 ir->sa_surface_tension = 0.0054 * 100 * CAL2JOULE;
1097 /* Better use sensible values than insane (0.0) ones... */
1098 ir->gb_epsilon_solvent = 80;
1099 ir->gb_obc_alpha = 1.0;
1100 ir->gb_obc_beta = 0.8;
1101 ir->gb_obc_gamma = 4.85;
1102 ir->sa_surface_tension = 2.092;
1106 if (file_version >= 81)
1108 gmx_fio_do_real(fio, ir->fourier_spacing);
1112 ir->fourier_spacing = 0.0;
1114 gmx_fio_do_int(fio, ir->nkx);
1115 gmx_fio_do_int(fio, ir->nky);
1116 gmx_fio_do_int(fio, ir->nkz);
1117 gmx_fio_do_int(fio, ir->pme_order);
1118 gmx_fio_do_real(fio, ir->ewald_rtol);
1120 if (file_version >= 93)
1122 gmx_fio_do_real(fio, ir->ewald_rtol_lj);
1126 ir->ewald_rtol_lj = ir->ewald_rtol;
1129 if (file_version >= 24)
1131 gmx_fio_do_int(fio, ir->ewald_geometry);
1135 ir->ewald_geometry = eewg3D;
1138 if (file_version <= 17)
1140 ir->epsilon_surface = 0;
1141 if (file_version == 17)
1143 gmx_fio_do_int(fio, idum);
1148 gmx_fio_do_real(fio, ir->epsilon_surface);
1151 gmx_fio_do_gmx_bool(fio, ir->bOptFFT);
1153 if (file_version >= 93)
1155 gmx_fio_do_int(fio, ir->ljpme_combination_rule);
1157 gmx_fio_do_gmx_bool(fio, ir->bContinuation);
1158 gmx_fio_do_int(fio, ir->etc);
1159 /* before version 18, ir->etc was a gmx_bool (ir->btc),
1160 * but the values 0 and 1 still mean no and
1161 * berendsen temperature coupling, respectively.
1163 if (file_version >= 79)
1165 gmx_fio_do_gmx_bool(fio, ir->bPrintNHChains);
1167 if (file_version >= 71)
1169 gmx_fio_do_int(fio, ir->nsttcouple);
1173 ir->nsttcouple = ir->nstcalcenergy;
1175 if (file_version <= 15)
1177 gmx_fio_do_int(fio, idum);
1179 if (file_version <= 17)
1181 gmx_fio_do_int(fio, ir->epct);
1182 if (file_version <= 15)
1186 ir->epct = epctSURFACETENSION;
1188 gmx_fio_do_int(fio, idum);
1191 /* we have removed the NO alternative at the beginning */
1195 ir->epct = epctISOTROPIC;
1199 ir->epc = epcBERENDSEN;
1204 gmx_fio_do_int(fio, ir->epc);
1205 gmx_fio_do_int(fio, ir->epct);
1207 if (file_version >= 71)
1209 gmx_fio_do_int(fio, ir->nstpcouple);
1213 ir->nstpcouple = ir->nstcalcenergy;
1215 gmx_fio_do_real(fio, ir->tau_p);
1216 if (file_version <= 15)
1218 gmx_fio_do_rvec(fio, vdum);
1219 clear_mat(ir->ref_p);
1220 for (i = 0; i < DIM; i++)
1222 ir->ref_p[i][i] = vdum[i];
1227 gmx_fio_do_rvec(fio, ir->ref_p[XX]);
1228 gmx_fio_do_rvec(fio, ir->ref_p[YY]);
1229 gmx_fio_do_rvec(fio, ir->ref_p[ZZ]);
1231 if (file_version <= 15)
1233 gmx_fio_do_rvec(fio, vdum);
1234 clear_mat(ir->compress);
1235 for (i = 0; i < DIM; i++)
1237 ir->compress[i][i] = vdum[i];
1242 gmx_fio_do_rvec(fio, ir->compress[XX]);
1243 gmx_fio_do_rvec(fio, ir->compress[YY]);
1244 gmx_fio_do_rvec(fio, ir->compress[ZZ]);
1246 if (file_version >= 47)
1248 gmx_fio_do_int(fio, ir->refcoord_scaling);
1249 gmx_fio_do_rvec(fio, ir->posres_com);
1250 gmx_fio_do_rvec(fio, ir->posres_comB);
1254 ir->refcoord_scaling = erscNO;
1255 clear_rvec(ir->posres_com);
1256 clear_rvec(ir->posres_comB);
1258 if ((file_version > 25) && (file_version < 79))
1260 gmx_fio_do_int(fio, ir->andersen_seed);
1264 ir->andersen_seed = 0;
1266 if (file_version < 26)
1268 gmx_fio_do_gmx_bool(fio, bSimAnn);
1269 gmx_fio_do_real(fio, zerotemptime);
1272 if (file_version < 37)
1274 gmx_fio_do_real(fio, rdum);
1277 gmx_fio_do_real(fio, ir->shake_tol);
1278 if (file_version < 54)
1280 gmx_fio_do_real(fio, *fudgeQQ);
1283 gmx_fio_do_int(fio, ir->efep);
1284 if (file_version <= 14 && ir->efep != efepNO)
1288 do_fepvals(fio, ir->fepvals, bRead, file_version);
1290 if (file_version >= 79)
1292 gmx_fio_do_gmx_bool(fio, ir->bSimTemp);
1295 ir->bSimTemp = TRUE;
1300 ir->bSimTemp = FALSE;
1304 do_simtempvals(fio, ir->simtempvals, ir->fepvals->n_lambda, bRead, file_version);
1307 if (file_version >= 79)
1309 gmx_fio_do_gmx_bool(fio, ir->bExpanded);
1312 ir->bExpanded = TRUE;
1316 ir->bExpanded = FALSE;
1321 do_expandedvals(fio, ir->expandedvals, ir->fepvals, bRead, file_version);
1323 if (file_version >= 57)
1325 gmx_fio_do_int(fio, ir->eDisre);
1327 gmx_fio_do_int(fio, ir->eDisreWeighting);
1328 if (file_version < 22)
1330 if (ir->eDisreWeighting == 0)
1332 ir->eDisreWeighting = edrwEqual;
1336 ir->eDisreWeighting = edrwConservative;
1339 gmx_fio_do_gmx_bool(fio, ir->bDisreMixed);
1340 gmx_fio_do_real(fio, ir->dr_fc);
1341 gmx_fio_do_real(fio, ir->dr_tau);
1342 gmx_fio_do_int(fio, ir->nstdisreout);
1343 if (file_version >= 22)
1345 gmx_fio_do_real(fio, ir->orires_fc);
1346 gmx_fio_do_real(fio, ir->orires_tau);
1347 gmx_fio_do_int(fio, ir->nstorireout);
1353 ir->nstorireout = 0;
1355 if (file_version >= 26 && file_version < 79)
1357 gmx_fio_do_real(fio, ir->dihre_fc);
1358 if (file_version < 56)
1360 gmx_fio_do_real(fio, rdum);
1361 gmx_fio_do_int(fio, idum);
1369 gmx_fio_do_real(fio, ir->em_stepsize);
1370 gmx_fio_do_real(fio, ir->em_tol);
1371 if (file_version >= 22)
1373 gmx_fio_do_gmx_bool(fio, ir->bShakeSOR);
1377 ir->bShakeSOR = TRUE;
1379 if (file_version >= 11)
1381 gmx_fio_do_int(fio, ir->niter);
1386 fprintf(stderr, "Note: niter not in run input file, setting it to %d\n",
1389 if (file_version >= 21)
1391 gmx_fio_do_real(fio, ir->fc_stepsize);
1395 ir->fc_stepsize = 0;
1397 gmx_fio_do_int(fio, ir->eConstrAlg);
1398 gmx_fio_do_int(fio, ir->nProjOrder);
1399 gmx_fio_do_real(fio, ir->LincsWarnAngle);
1400 if (file_version <= 14)
1402 gmx_fio_do_int(fio, idum);
1404 if (file_version >= 26)
1406 gmx_fio_do_int(fio, ir->nLincsIter);
1411 fprintf(stderr, "Note: nLincsIter not in run input file, setting it to %d\n",
1414 if (file_version < 33)
1416 gmx_fio_do_real(fio, bd_temp);
1418 gmx_fio_do_real(fio, ir->bd_fric);
1419 if (file_version >= tpx_version_use_64_bit_random_seed)
1421 gmx_fio_do_int64(fio, ir->ld_seed);
1425 gmx_fio_do_int(fio, idum);
1428 if (file_version >= 33)
1430 for (i = 0; i < DIM; i++)
1432 gmx_fio_do_rvec(fio, ir->deform[i]);
1437 for (i = 0; i < DIM; i++)
1439 clear_rvec(ir->deform[i]);
1442 if (file_version >= 14)
1444 gmx_fio_do_real(fio, ir->cos_accel);
1450 gmx_fio_do_int(fio, ir->userint1);
1451 gmx_fio_do_int(fio, ir->userint2);
1452 gmx_fio_do_int(fio, ir->userint3);
1453 gmx_fio_do_int(fio, ir->userint4);
1454 gmx_fio_do_real(fio, ir->userreal1);
1455 gmx_fio_do_real(fio, ir->userreal2);
1456 gmx_fio_do_real(fio, ir->userreal3);
1457 gmx_fio_do_real(fio, ir->userreal4);
1460 if (file_version >= 77)
1462 gmx_fio_do_gmx_bool(fio, ir->bAdress);
1467 snew(ir->adress, 1);
1469 gmx_fio_do_int(fio, ir->adress->type);
1470 gmx_fio_do_real(fio, ir->adress->const_wf);
1471 gmx_fio_do_real(fio, ir->adress->ex_width);
1472 gmx_fio_do_real(fio, ir->adress->hy_width);
1473 gmx_fio_do_int(fio, ir->adress->icor);
1474 gmx_fio_do_int(fio, ir->adress->site);
1475 gmx_fio_do_rvec(fio, ir->adress->refs);
1476 gmx_fio_do_int(fio, ir->adress->n_tf_grps);
1477 gmx_fio_do_real(fio, ir->adress->ex_forcecap);
1478 gmx_fio_do_int(fio, ir->adress->n_energy_grps);
1479 gmx_fio_do_int(fio, ir->adress->do_hybridpairs);
1483 snew(ir->adress->tf_table_index, ir->adress->n_tf_grps);
1485 if (ir->adress->n_tf_grps > 0)
1487 gmx_fio_ndo_int(fio, ir->adress->tf_table_index, ir->adress->n_tf_grps);
1491 snew(ir->adress->group_explicit, ir->adress->n_energy_grps);
1493 if (ir->adress->n_energy_grps > 0)
1495 gmx_fio_ndo_int(fio, ir->adress->group_explicit, ir->adress->n_energy_grps);
1501 ir->bAdress = FALSE;
1505 if (file_version >= 48)
1507 gmx_fio_do_int(fio, ir->ePull);
1508 if (ir->ePull != epullNO)
1514 do_pull(fio, ir->pull, bRead, file_version);
1519 ir->ePull = epullNO;
1522 /* Enforced rotation */
1523 if (file_version >= 74)
1525 gmx_fio_do_int(fio, ir->bRot);
1526 if (ir->bRot == TRUE)
1532 do_rot(fio, ir->rot, bRead);
1541 gmx_fio_do_int(fio, ir->opts.ngtc);
1542 if (file_version >= 69)
1544 gmx_fio_do_int(fio, ir->opts.nhchainlength);
1548 ir->opts.nhchainlength = 1;
1550 gmx_fio_do_int(fio, ir->opts.ngacc);
1551 gmx_fio_do_int(fio, ir->opts.ngfrz);
1552 gmx_fio_do_int(fio, ir->opts.ngener);
1556 snew(ir->opts.nrdf, ir->opts.ngtc);
1557 snew(ir->opts.ref_t, ir->opts.ngtc);
1558 snew(ir->opts.annealing, ir->opts.ngtc);
1559 snew(ir->opts.anneal_npoints, ir->opts.ngtc);
1560 snew(ir->opts.anneal_time, ir->opts.ngtc);
1561 snew(ir->opts.anneal_temp, ir->opts.ngtc);
1562 snew(ir->opts.tau_t, ir->opts.ngtc);
1563 snew(ir->opts.nFreeze, ir->opts.ngfrz);
1564 snew(ir->opts.acc, ir->opts.ngacc);
1565 snew(ir->opts.egp_flags, ir->opts.ngener*ir->opts.ngener);
1567 if (ir->opts.ngtc > 0)
1569 if (bRead && file_version < 13)
1571 snew(tmp, ir->opts.ngtc);
1572 gmx_fio_ndo_int(fio, tmp, ir->opts.ngtc);
1573 for (i = 0; i < ir->opts.ngtc; i++)
1575 ir->opts.nrdf[i] = tmp[i];
1581 gmx_fio_ndo_real(fio, ir->opts.nrdf, ir->opts.ngtc);
1583 gmx_fio_ndo_real(fio, ir->opts.ref_t, ir->opts.ngtc);
1584 gmx_fio_ndo_real(fio, ir->opts.tau_t, ir->opts.ngtc);
1585 if (file_version < 33 && ir->eI == eiBD)
1587 for (i = 0; i < ir->opts.ngtc; i++)
1589 ir->opts.tau_t[i] = bd_temp;
1593 if (ir->opts.ngfrz > 0)
1595 gmx_fio_ndo_ivec(fio, ir->opts.nFreeze, ir->opts.ngfrz);
1597 if (ir->opts.ngacc > 0)
1599 gmx_fio_ndo_rvec(fio, ir->opts.acc, ir->opts.ngacc);
1601 if (file_version >= 12)
1603 gmx_fio_ndo_int(fio, ir->opts.egp_flags,
1604 ir->opts.ngener*ir->opts.ngener);
1607 if (bRead && file_version < 26)
1609 for (i = 0; i < ir->opts.ngtc; i++)
1613 ir->opts.annealing[i] = eannSINGLE;
1614 ir->opts.anneal_npoints[i] = 2;
1615 snew(ir->opts.anneal_time[i], 2);
1616 snew(ir->opts.anneal_temp[i], 2);
1617 /* calculate the starting/ending temperatures from reft, zerotemptime, and nsteps */
1618 finish_t = ir->init_t + ir->nsteps * ir->delta_t;
1619 init_temp = ir->opts.ref_t[i]*(1-ir->init_t/zerotemptime);
1620 finish_temp = ir->opts.ref_t[i]*(1-finish_t/zerotemptime);
1621 ir->opts.anneal_time[i][0] = ir->init_t;
1622 ir->opts.anneal_time[i][1] = finish_t;
1623 ir->opts.anneal_temp[i][0] = init_temp;
1624 ir->opts.anneal_temp[i][1] = finish_temp;
1628 ir->opts.annealing[i] = eannNO;
1629 ir->opts.anneal_npoints[i] = 0;
1635 /* file version 26 or later */
1636 /* First read the lists with annealing and npoints for each group */
1637 gmx_fio_ndo_int(fio, ir->opts.annealing, ir->opts.ngtc);
1638 gmx_fio_ndo_int(fio, ir->opts.anneal_npoints, ir->opts.ngtc);
1639 for (j = 0; j < (ir->opts.ngtc); j++)
1641 k = ir->opts.anneal_npoints[j];
1644 snew(ir->opts.anneal_time[j], k);
1645 snew(ir->opts.anneal_temp[j], k);
1647 gmx_fio_ndo_real(fio, ir->opts.anneal_time[j], k);
1648 gmx_fio_ndo_real(fio, ir->opts.anneal_temp[j], k);
1652 if (file_version >= 45)
1654 gmx_fio_do_int(fio, ir->nwall);
1655 gmx_fio_do_int(fio, ir->wall_type);
1656 if (file_version >= 50)
1658 gmx_fio_do_real(fio, ir->wall_r_linpot);
1662 ir->wall_r_linpot = -1;
1664 gmx_fio_do_int(fio, ir->wall_atomtype[0]);
1665 gmx_fio_do_int(fio, ir->wall_atomtype[1]);
1666 gmx_fio_do_real(fio, ir->wall_density[0]);
1667 gmx_fio_do_real(fio, ir->wall_density[1]);
1668 gmx_fio_do_real(fio, ir->wall_ewald_zfac);
1674 ir->wall_atomtype[0] = -1;
1675 ir->wall_atomtype[1] = -1;
1676 ir->wall_density[0] = 0;
1677 ir->wall_density[1] = 0;
1678 ir->wall_ewald_zfac = 3;
1680 /* Cosine stuff for electric fields */
1681 for (j = 0; (j < DIM); j++)
1683 gmx_fio_do_int(fio, ir->ex[j].n);
1684 gmx_fio_do_int(fio, ir->et[j].n);
1687 snew(ir->ex[j].a, ir->ex[j].n);
1688 snew(ir->ex[j].phi, ir->ex[j].n);
1689 snew(ir->et[j].a, ir->et[j].n);
1690 snew(ir->et[j].phi, ir->et[j].n);
1692 gmx_fio_ndo_real(fio, ir->ex[j].a, ir->ex[j].n);
1693 gmx_fio_ndo_real(fio, ir->ex[j].phi, ir->ex[j].n);
1694 gmx_fio_ndo_real(fio, ir->et[j].a, ir->et[j].n);
1695 gmx_fio_ndo_real(fio, ir->et[j].phi, ir->et[j].n);
1699 if (file_version >= 96)
1701 gmx_fio_do_int(fio, ir->eSwapCoords);
1702 if (ir->eSwapCoords != eswapNO)
1708 do_swapcoords(fio, ir->swap, bRead);
1713 if (file_version >= 39)
1715 gmx_fio_do_gmx_bool(fio, ir->bQMMM);
1716 gmx_fio_do_int(fio, ir->QMMMscheme);
1717 gmx_fio_do_real(fio, ir->scalefactor);
1718 gmx_fio_do_int(fio, ir->opts.ngQM);
1721 snew(ir->opts.QMmethod, ir->opts.ngQM);
1722 snew(ir->opts.QMbasis, ir->opts.ngQM);
1723 snew(ir->opts.QMcharge, ir->opts.ngQM);
1724 snew(ir->opts.QMmult, ir->opts.ngQM);
1725 snew(ir->opts.bSH, ir->opts.ngQM);
1726 snew(ir->opts.CASorbitals, ir->opts.ngQM);
1727 snew(ir->opts.CASelectrons, ir->opts.ngQM);
1728 snew(ir->opts.SAon, ir->opts.ngQM);
1729 snew(ir->opts.SAoff, ir->opts.ngQM);
1730 snew(ir->opts.SAsteps, ir->opts.ngQM);
1731 snew(ir->opts.bOPT, ir->opts.ngQM);
1732 snew(ir->opts.bTS, ir->opts.ngQM);
1734 if (ir->opts.ngQM > 0)
1736 gmx_fio_ndo_int(fio, ir->opts.QMmethod, ir->opts.ngQM);
1737 gmx_fio_ndo_int(fio, ir->opts.QMbasis, ir->opts.ngQM);
1738 gmx_fio_ndo_int(fio, ir->opts.QMcharge, ir->opts.ngQM);
1739 gmx_fio_ndo_int(fio, ir->opts.QMmult, ir->opts.ngQM);
1740 gmx_fio_ndo_gmx_bool(fio, ir->opts.bSH, ir->opts.ngQM);
1741 gmx_fio_ndo_int(fio, ir->opts.CASorbitals, ir->opts.ngQM);
1742 gmx_fio_ndo_int(fio, ir->opts.CASelectrons, ir->opts.ngQM);
1743 gmx_fio_ndo_real(fio, ir->opts.SAon, ir->opts.ngQM);
1744 gmx_fio_ndo_real(fio, ir->opts.SAoff, ir->opts.ngQM);
1745 gmx_fio_ndo_int(fio, ir->opts.SAsteps, ir->opts.ngQM);
1746 gmx_fio_ndo_gmx_bool(fio, ir->opts.bOPT, ir->opts.ngQM);
1747 gmx_fio_ndo_gmx_bool(fio, ir->opts.bTS, ir->opts.ngQM);
1749 /* end of QMMM stuff */
1754 static void do_harm(t_fileio *fio, t_iparams *iparams)
1756 gmx_fio_do_real(fio, iparams->harmonic.rA);
1757 gmx_fio_do_real(fio, iparams->harmonic.krA);
1758 gmx_fio_do_real(fio, iparams->harmonic.rB);
1759 gmx_fio_do_real(fio, iparams->harmonic.krB);
1762 void do_iparams(t_fileio *fio, t_functype ftype, t_iparams *iparams,
1763 gmx_bool bRead, int file_version)
1770 gmx_fio_set_comment(fio, interaction_function[ftype].name);
1780 do_harm(fio, iparams);
1781 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && bRead)
1783 /* Correct incorrect storage of parameters */
1784 iparams->pdihs.phiB = iparams->pdihs.phiA;
1785 iparams->pdihs.cpB = iparams->pdihs.cpA;
1788 case F_LINEAR_ANGLES:
1789 gmx_fio_do_real(fio, iparams->linangle.klinA);
1790 gmx_fio_do_real(fio, iparams->linangle.aA);
1791 gmx_fio_do_real(fio, iparams->linangle.klinB);
1792 gmx_fio_do_real(fio, iparams->linangle.aB);
1795 gmx_fio_do_real(fio, iparams->fene.bm);
1796 gmx_fio_do_real(fio, iparams->fene.kb);
1799 gmx_fio_do_real(fio, iparams->restraint.lowA);
1800 gmx_fio_do_real(fio, iparams->restraint.up1A);
1801 gmx_fio_do_real(fio, iparams->restraint.up2A);
1802 gmx_fio_do_real(fio, iparams->restraint.kA);
1803 gmx_fio_do_real(fio, iparams->restraint.lowB);
1804 gmx_fio_do_real(fio, iparams->restraint.up1B);
1805 gmx_fio_do_real(fio, iparams->restraint.up2B);
1806 gmx_fio_do_real(fio, iparams->restraint.kB);
1812 gmx_fio_do_real(fio, iparams->tab.kA);
1813 gmx_fio_do_int(fio, iparams->tab.table);
1814 gmx_fio_do_real(fio, iparams->tab.kB);
1816 case F_CROSS_BOND_BONDS:
1817 gmx_fio_do_real(fio, iparams->cross_bb.r1e);
1818 gmx_fio_do_real(fio, iparams->cross_bb.r2e);
1819 gmx_fio_do_real(fio, iparams->cross_bb.krr);
1821 case F_CROSS_BOND_ANGLES:
1822 gmx_fio_do_real(fio, iparams->cross_ba.r1e);
1823 gmx_fio_do_real(fio, iparams->cross_ba.r2e);
1824 gmx_fio_do_real(fio, iparams->cross_ba.r3e);
1825 gmx_fio_do_real(fio, iparams->cross_ba.krt);
1827 case F_UREY_BRADLEY:
1828 gmx_fio_do_real(fio, iparams->u_b.thetaA);
1829 gmx_fio_do_real(fio, iparams->u_b.kthetaA);
1830 gmx_fio_do_real(fio, iparams->u_b.r13A);
1831 gmx_fio_do_real(fio, iparams->u_b.kUBA);
1832 if (file_version >= 79)
1834 gmx_fio_do_real(fio, iparams->u_b.thetaB);
1835 gmx_fio_do_real(fio, iparams->u_b.kthetaB);
1836 gmx_fio_do_real(fio, iparams->u_b.r13B);
1837 gmx_fio_do_real(fio, iparams->u_b.kUBB);
1841 iparams->u_b.thetaB = iparams->u_b.thetaA;
1842 iparams->u_b.kthetaB = iparams->u_b.kthetaA;
1843 iparams->u_b.r13B = iparams->u_b.r13A;
1844 iparams->u_b.kUBB = iparams->u_b.kUBA;
1847 case F_QUARTIC_ANGLES:
1848 gmx_fio_do_real(fio, iparams->qangle.theta);
1849 gmx_fio_ndo_real(fio, iparams->qangle.c, 5);
1852 gmx_fio_do_real(fio, iparams->bham.a);
1853 gmx_fio_do_real(fio, iparams->bham.b);
1854 gmx_fio_do_real(fio, iparams->bham.c);
1857 gmx_fio_do_real(fio, iparams->morse.b0A);
1858 gmx_fio_do_real(fio, iparams->morse.cbA);
1859 gmx_fio_do_real(fio, iparams->morse.betaA);
1860 if (file_version >= 79)
1862 gmx_fio_do_real(fio, iparams->morse.b0B);
1863 gmx_fio_do_real(fio, iparams->morse.cbB);
1864 gmx_fio_do_real(fio, iparams->morse.betaB);
1868 iparams->morse.b0B = iparams->morse.b0A;
1869 iparams->morse.cbB = iparams->morse.cbA;
1870 iparams->morse.betaB = iparams->morse.betaA;
1874 gmx_fio_do_real(fio, iparams->cubic.b0);
1875 gmx_fio_do_real(fio, iparams->cubic.kb);
1876 gmx_fio_do_real(fio, iparams->cubic.kcub);
1880 case F_POLARIZATION:
1881 gmx_fio_do_real(fio, iparams->polarize.alpha);
1884 gmx_fio_do_real(fio, iparams->anharm_polarize.alpha);
1885 gmx_fio_do_real(fio, iparams->anharm_polarize.drcut);
1886 gmx_fio_do_real(fio, iparams->anharm_polarize.khyp);
1889 if (file_version < 31)
1891 gmx_fatal(FARGS, "Old tpr files with water_polarization not supported. Make a new.");
1893 gmx_fio_do_real(fio, iparams->wpol.al_x);
1894 gmx_fio_do_real(fio, iparams->wpol.al_y);
1895 gmx_fio_do_real(fio, iparams->wpol.al_z);
1896 gmx_fio_do_real(fio, iparams->wpol.rOH);
1897 gmx_fio_do_real(fio, iparams->wpol.rHH);
1898 gmx_fio_do_real(fio, iparams->wpol.rOD);
1901 gmx_fio_do_real(fio, iparams->thole.a);
1902 gmx_fio_do_real(fio, iparams->thole.alpha1);
1903 gmx_fio_do_real(fio, iparams->thole.alpha2);
1904 gmx_fio_do_real(fio, iparams->thole.rfac);
1907 gmx_fio_do_real(fio, iparams->lj.c6);
1908 gmx_fio_do_real(fio, iparams->lj.c12);
1911 gmx_fio_do_real(fio, iparams->lj14.c6A);
1912 gmx_fio_do_real(fio, iparams->lj14.c12A);
1913 gmx_fio_do_real(fio, iparams->lj14.c6B);
1914 gmx_fio_do_real(fio, iparams->lj14.c12B);
1917 gmx_fio_do_real(fio, iparams->ljc14.fqq);
1918 gmx_fio_do_real(fio, iparams->ljc14.qi);
1919 gmx_fio_do_real(fio, iparams->ljc14.qj);
1920 gmx_fio_do_real(fio, iparams->ljc14.c6);
1921 gmx_fio_do_real(fio, iparams->ljc14.c12);
1923 case F_LJC_PAIRS_NB:
1924 gmx_fio_do_real(fio, iparams->ljcnb.qi);
1925 gmx_fio_do_real(fio, iparams->ljcnb.qj);
1926 gmx_fio_do_real(fio, iparams->ljcnb.c6);
1927 gmx_fio_do_real(fio, iparams->ljcnb.c12);
1933 gmx_fio_do_real(fio, iparams->pdihs.phiA);
1934 gmx_fio_do_real(fio, iparams->pdihs.cpA);
1935 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && file_version < 42)
1937 /* Read the incorrectly stored multiplicity */
1938 gmx_fio_do_real(fio, iparams->harmonic.rB);
1939 gmx_fio_do_real(fio, iparams->harmonic.krB);
1940 iparams->pdihs.phiB = iparams->pdihs.phiA;
1941 iparams->pdihs.cpB = iparams->pdihs.cpA;
1945 gmx_fio_do_real(fio, iparams->pdihs.phiB);
1946 gmx_fio_do_real(fio, iparams->pdihs.cpB);
1947 gmx_fio_do_int(fio, iparams->pdihs.mult);
1951 gmx_fio_do_int(fio, iparams->disres.label);
1952 gmx_fio_do_int(fio, iparams->disres.type);
1953 gmx_fio_do_real(fio, iparams->disres.low);
1954 gmx_fio_do_real(fio, iparams->disres.up1);
1955 gmx_fio_do_real(fio, iparams->disres.up2);
1956 gmx_fio_do_real(fio, iparams->disres.kfac);
1959 gmx_fio_do_int(fio, iparams->orires.ex);
1960 gmx_fio_do_int(fio, iparams->orires.label);
1961 gmx_fio_do_int(fio, iparams->orires.power);
1962 gmx_fio_do_real(fio, iparams->orires.c);
1963 gmx_fio_do_real(fio, iparams->orires.obs);
1964 gmx_fio_do_real(fio, iparams->orires.kfac);
1967 if (file_version < 82)
1969 gmx_fio_do_int(fio, idum);
1970 gmx_fio_do_int(fio, idum);
1972 gmx_fio_do_real(fio, iparams->dihres.phiA);
1973 gmx_fio_do_real(fio, iparams->dihres.dphiA);
1974 gmx_fio_do_real(fio, iparams->dihres.kfacA);
1975 if (file_version >= 82)
1977 gmx_fio_do_real(fio, iparams->dihres.phiB);
1978 gmx_fio_do_real(fio, iparams->dihres.dphiB);
1979 gmx_fio_do_real(fio, iparams->dihres.kfacB);
1983 iparams->dihres.phiB = iparams->dihres.phiA;
1984 iparams->dihres.dphiB = iparams->dihres.dphiA;
1985 iparams->dihres.kfacB = iparams->dihres.kfacA;
1989 gmx_fio_do_rvec(fio, iparams->posres.pos0A);
1990 gmx_fio_do_rvec(fio, iparams->posres.fcA);
1991 if (bRead && file_version < 27)
1993 copy_rvec(iparams->posres.pos0A, iparams->posres.pos0B);
1994 copy_rvec(iparams->posres.fcA, iparams->posres.fcB);
1998 gmx_fio_do_rvec(fio, iparams->posres.pos0B);
1999 gmx_fio_do_rvec(fio, iparams->posres.fcB);
2003 gmx_fio_do_int(fio, iparams->fbposres.geom);
2004 gmx_fio_do_rvec(fio, iparams->fbposres.pos0);
2005 gmx_fio_do_real(fio, iparams->fbposres.r);
2006 gmx_fio_do_real(fio, iparams->fbposres.k);
2009 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcA, NR_RBDIHS);
2010 if (file_version >= 25)
2012 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcB, NR_RBDIHS);
2016 /* Fourier dihedrals are internally represented
2017 * as Ryckaert-Bellemans since those are faster to compute.
2019 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcA, NR_RBDIHS);
2020 gmx_fio_ndo_real(fio, iparams->rbdihs.rbcB, NR_RBDIHS);
2024 gmx_fio_do_real(fio, iparams->constr.dA);
2025 gmx_fio_do_real(fio, iparams->constr.dB);
2028 gmx_fio_do_real(fio, iparams->settle.doh);
2029 gmx_fio_do_real(fio, iparams->settle.dhh);
2032 gmx_fio_do_real(fio, iparams->vsite.a);
2037 gmx_fio_do_real(fio, iparams->vsite.a);
2038 gmx_fio_do_real(fio, iparams->vsite.b);
2043 gmx_fio_do_real(fio, iparams->vsite.a);
2044 gmx_fio_do_real(fio, iparams->vsite.b);
2045 gmx_fio_do_real(fio, iparams->vsite.c);
2048 gmx_fio_do_int(fio, iparams->vsiten.n);
2049 gmx_fio_do_real(fio, iparams->vsiten.a);
2054 /* We got rid of some parameters in version 68 */
2055 if (bRead && file_version < 68)
2057 gmx_fio_do_real(fio, rdum);
2058 gmx_fio_do_real(fio, rdum);
2059 gmx_fio_do_real(fio, rdum);
2060 gmx_fio_do_real(fio, rdum);
2062 gmx_fio_do_real(fio, iparams->gb.sar);
2063 gmx_fio_do_real(fio, iparams->gb.st);
2064 gmx_fio_do_real(fio, iparams->gb.pi);
2065 gmx_fio_do_real(fio, iparams->gb.gbr);
2066 gmx_fio_do_real(fio, iparams->gb.bmlt);
2069 gmx_fio_do_int(fio, iparams->cmap.cmapA);
2070 gmx_fio_do_int(fio, iparams->cmap.cmapB);
2073 gmx_fatal(FARGS, "unknown function type %d (%s) in %s line %d",
2074 ftype, interaction_function[ftype].name, __FILE__, __LINE__);
2078 gmx_fio_unset_comment(fio);
2082 static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_version,
2089 gmx_fio_set_comment(fio, interaction_function[ftype].name);
2091 if (file_version < 44)
2093 for (i = 0; i < MAXNODES; i++)
2095 gmx_fio_do_int(fio, idum);
2098 gmx_fio_do_int(fio, ilist->nr);
2101 snew(ilist->iatoms, ilist->nr);
2103 gmx_fio_ndo_int(fio, ilist->iatoms, ilist->nr);
2106 gmx_fio_unset_comment(fio);
2110 static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
2111 gmx_bool bRead, int file_version)
2116 gmx_fio_do_int(fio, ffparams->atnr);
2117 if (file_version < 57)
2119 gmx_fio_do_int(fio, idum);
2121 gmx_fio_do_int(fio, ffparams->ntypes);
2124 fprintf(debug, "ffparams->atnr = %d, ntypes = %d\n",
2125 ffparams->atnr, ffparams->ntypes);
2129 snew(ffparams->functype, ffparams->ntypes);
2130 snew(ffparams->iparams, ffparams->ntypes);
2132 /* Read/write all the function types */
2133 gmx_fio_ndo_int(fio, ffparams->functype, ffparams->ntypes);
2136 pr_ivec(debug, 0, "functype", ffparams->functype, ffparams->ntypes, TRUE);
2139 if (file_version >= 66)
2141 gmx_fio_do_double(fio, ffparams->reppow);
2145 ffparams->reppow = 12.0;
2148 if (file_version >= 57)
2150 gmx_fio_do_real(fio, ffparams->fudgeQQ);
2153 /* Check whether all these function types are supported by the code.
2154 * In practice the code is backwards compatible, which means that the
2155 * numbering may have to be altered from old numbering to new numbering
2157 for (i = 0; (i < ffparams->ntypes); i++)
2161 /* Loop over file versions */
2162 for (k = 0; (k < NFTUPD); k++)
2164 /* Compare the read file_version to the update table */
2165 if ((file_version < ftupd[k].fvnr) &&
2166 (ffparams->functype[i] >= ftupd[k].ftype))
2168 ffparams->functype[i] += 1;
2171 fprintf(debug, "Incrementing function type %d to %d (due to %s)\n",
2172 i, ffparams->functype[i],
2173 interaction_function[ftupd[k].ftype].longname);
2180 do_iparams(fio, ffparams->functype[i], &ffparams->iparams[i], bRead,
2184 pr_iparams(debug, ffparams->functype[i], &ffparams->iparams[i]);
2189 static void add_settle_atoms(t_ilist *ilist)
2193 /* Settle used to only store the first atom: add the other two */
2194 srenew(ilist->iatoms, 2*ilist->nr);
2195 for (i = ilist->nr/2-1; i >= 0; i--)
2197 ilist->iatoms[4*i+0] = ilist->iatoms[2*i+0];
2198 ilist->iatoms[4*i+1] = ilist->iatoms[2*i+1];
2199 ilist->iatoms[4*i+2] = ilist->iatoms[2*i+1] + 1;
2200 ilist->iatoms[4*i+3] = ilist->iatoms[2*i+1] + 2;
2202 ilist->nr = 2*ilist->nr;
2205 static void do_ilists(t_fileio *fio, t_ilist *ilist, gmx_bool bRead,
2208 int i, j, renum[F_NRE];
2212 for (j = 0; (j < F_NRE); j++)
2217 for (k = 0; k < NFTUPD; k++)
2219 if ((file_version < ftupd[k].fvnr) && (j == ftupd[k].ftype))
2228 ilist[j].iatoms = NULL;
2232 do_ilist(fio, &ilist[j], bRead, file_version, j);
2233 if (file_version < 78 && j == F_SETTLE && ilist[j].nr > 0)
2235 add_settle_atoms(&ilist[j]);
2239 if (bRead && gmx_debug_at)
2240 pr_ilist(debug,0,interaction_function[j].longname,
2241 functype,&ilist[j],TRUE);
2246 static void do_idef(t_fileio *fio, gmx_ffparams_t *ffparams, gmx_moltype_t *molt,
2247 gmx_bool bRead, int file_version)
2249 do_ffparams(fio, ffparams, bRead, file_version);
2251 if (file_version >= 54)
2253 gmx_fio_do_real(fio, ffparams->fudgeQQ);
2256 do_ilists(fio, molt->ilist, bRead, file_version);
2259 static void do_block(t_fileio *fio, t_block *block, gmx_bool bRead, int file_version)
2261 int i, idum, dum_nra, *dum_a;
2263 if (file_version < 44)
2265 for (i = 0; i < MAXNODES; i++)
2267 gmx_fio_do_int(fio, idum);
2270 gmx_fio_do_int(fio, block->nr);
2271 if (file_version < 51)
2273 gmx_fio_do_int(fio, dum_nra);
2277 if ((block->nalloc_index > 0) && (NULL != block->index))
2279 sfree(block->index);
2281 block->nalloc_index = block->nr+1;
2282 snew(block->index, block->nalloc_index);
2284 gmx_fio_ndo_int(fio, block->index, block->nr+1);
2286 if (file_version < 51 && dum_nra > 0)
2288 snew(dum_a, dum_nra);
2289 gmx_fio_ndo_int(fio, dum_a, dum_nra);
2294 static void do_blocka(t_fileio *fio, t_blocka *block, gmx_bool bRead,
2299 if (file_version < 44)
2301 for (i = 0; i < MAXNODES; i++)
2303 gmx_fio_do_int(fio, idum);
2306 gmx_fio_do_int(fio, block->nr);
2307 gmx_fio_do_int(fio, block->nra);
2310 block->nalloc_index = block->nr+1;
2311 snew(block->index, block->nalloc_index);
2312 block->nalloc_a = block->nra;
2313 snew(block->a, block->nalloc_a);
2315 gmx_fio_ndo_int(fio, block->index, block->nr+1);
2316 gmx_fio_ndo_int(fio, block->a, block->nra);
2319 static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead,
2320 int file_version, gmx_groups_t *groups, int atnr)
2324 gmx_fio_do_real(fio, atom->m);
2325 gmx_fio_do_real(fio, atom->q);
2326 gmx_fio_do_real(fio, atom->mB);
2327 gmx_fio_do_real(fio, atom->qB);
2328 gmx_fio_do_ushort(fio, atom->type);
2329 gmx_fio_do_ushort(fio, atom->typeB);
2330 gmx_fio_do_int(fio, atom->ptype);
2331 gmx_fio_do_int(fio, atom->resind);
2332 if (file_version >= 52)
2334 gmx_fio_do_int(fio, atom->atomnumber);
2338 atom->atomnumber = NOTSET;
2340 if (file_version < 23)
2344 else if (file_version < 39)
2353 if (file_version < 57)
2355 unsigned char uchar[egcNR];
2356 gmx_fio_ndo_uchar(fio, uchar, myngrp);
2357 for (i = myngrp; (i < ngrp); i++)
2361 /* Copy the old data format to the groups struct */
2362 for (i = 0; i < ngrp; i++)
2364 groups->grpnr[i][atnr] = uchar[i];
2369 static void do_grps(t_fileio *fio, int ngrp, t_grps grps[], gmx_bool bRead,
2374 if (file_version < 23)
2378 else if (file_version < 39)
2387 for (j = 0; (j < ngrp); j++)
2391 gmx_fio_do_int(fio, grps[j].nr);
2394 snew(grps[j].nm_ind, grps[j].nr);
2396 gmx_fio_ndo_int(fio, grps[j].nm_ind, grps[j].nr);
2401 snew(grps[j].nm_ind, grps[j].nr);
2406 static void do_symstr(t_fileio *fio, char ***nm, gmx_bool bRead, t_symtab *symtab)
2412 gmx_fio_do_int(fio, ls);
2413 *nm = get_symtab_handle(symtab, ls);
2417 ls = lookup_symtab(symtab, *nm);
2418 gmx_fio_do_int(fio, ls);
2422 static void do_strstr(t_fileio *fio, int nstr, char ***nm, gmx_bool bRead,
2427 for (j = 0; (j < nstr); j++)
2429 do_symstr(fio, &(nm[j]), bRead, symtab);
2433 static void do_resinfo(t_fileio *fio, int n, t_resinfo *ri, gmx_bool bRead,
2434 t_symtab *symtab, int file_version)
2438 for (j = 0; (j < n); j++)
2440 do_symstr(fio, &(ri[j].name), bRead, symtab);
2441 if (file_version >= 63)
2443 gmx_fio_do_int(fio, ri[j].nr);
2444 gmx_fio_do_uchar(fio, ri[j].ic);
2454 static void do_atoms(t_fileio *fio, t_atoms *atoms, gmx_bool bRead, t_symtab *symtab,
2456 gmx_groups_t *groups)
2460 gmx_fio_do_int(fio, atoms->nr);
2461 gmx_fio_do_int(fio, atoms->nres);
2462 if (file_version < 57)
2464 gmx_fio_do_int(fio, groups->ngrpname);
2465 for (i = 0; i < egcNR; i++)
2467 groups->ngrpnr[i] = atoms->nr;
2468 snew(groups->grpnr[i], groups->ngrpnr[i]);
2473 snew(atoms->atom, atoms->nr);
2474 snew(atoms->atomname, atoms->nr);
2475 snew(atoms->atomtype, atoms->nr);
2476 snew(atoms->atomtypeB, atoms->nr);
2477 snew(atoms->resinfo, atoms->nres);
2478 if (file_version < 57)
2480 snew(groups->grpname, groups->ngrpname);
2482 atoms->pdbinfo = NULL;
2484 for (i = 0; (i < atoms->nr); i++)
2486 do_atom(fio, &atoms->atom[i], egcNR, bRead, file_version, groups, i);
2488 do_strstr(fio, atoms->nr, atoms->atomname, bRead, symtab);
2489 if (bRead && (file_version <= 20))
2491 for (i = 0; i < atoms->nr; i++)
2493 atoms->atomtype[i] = put_symtab(symtab, "?");
2494 atoms->atomtypeB[i] = put_symtab(symtab, "?");
2499 do_strstr(fio, atoms->nr, atoms->atomtype, bRead, symtab);
2500 do_strstr(fio, atoms->nr, atoms->atomtypeB, bRead, symtab);
2502 do_resinfo(fio, atoms->nres, atoms->resinfo, bRead, symtab, file_version);
2504 if (file_version < 57)
2506 do_strstr(fio, groups->ngrpname, groups->grpname, bRead, symtab);
2508 do_grps(fio, egcNR, groups->grps, bRead, file_version);
2512 static void do_groups(t_fileio *fio, gmx_groups_t *groups,
2513 gmx_bool bRead, t_symtab *symtab,
2518 do_grps(fio, egcNR, groups->grps, bRead, file_version);
2519 gmx_fio_do_int(fio, groups->ngrpname);
2522 snew(groups->grpname, groups->ngrpname);
2524 do_strstr(fio, groups->ngrpname, groups->grpname, bRead, symtab);
2525 for (g = 0; g < egcNR; g++)
2527 gmx_fio_do_int(fio, groups->ngrpnr[g]);
2528 if (groups->ngrpnr[g] == 0)
2532 groups->grpnr[g] = NULL;
2539 snew(groups->grpnr[g], groups->ngrpnr[g]);
2541 gmx_fio_ndo_uchar(fio, groups->grpnr[g], groups->ngrpnr[g]);
2546 static void do_atomtypes(t_fileio *fio, t_atomtypes *atomtypes, gmx_bool bRead,
2551 if (file_version > 25)
2553 gmx_fio_do_int(fio, atomtypes->nr);
2557 snew(atomtypes->radius, j);
2558 snew(atomtypes->vol, j);
2559 snew(atomtypes->surftens, j);
2560 snew(atomtypes->atomnumber, j);
2561 snew(atomtypes->gb_radius, j);
2562 snew(atomtypes->S_hct, j);
2564 gmx_fio_ndo_real(fio, atomtypes->radius, j);
2565 gmx_fio_ndo_real(fio, atomtypes->vol, j);
2566 gmx_fio_ndo_real(fio, atomtypes->surftens, j);
2567 if (file_version >= 40)
2569 gmx_fio_ndo_int(fio, atomtypes->atomnumber, j);
2571 if (file_version >= 60)
2573 gmx_fio_ndo_real(fio, atomtypes->gb_radius, j);
2574 gmx_fio_ndo_real(fio, atomtypes->S_hct, j);
2579 /* File versions prior to 26 cannot do GBSA,
2580 * so they dont use this structure
2583 atomtypes->radius = NULL;
2584 atomtypes->vol = NULL;
2585 atomtypes->surftens = NULL;
2586 atomtypes->atomnumber = NULL;
2587 atomtypes->gb_radius = NULL;
2588 atomtypes->S_hct = NULL;
2592 static void do_symtab(t_fileio *fio, t_symtab *symtab, gmx_bool bRead)
2598 gmx_fio_do_int(fio, symtab->nr);
2602 snew(symtab->symbuf, 1);
2603 symbuf = symtab->symbuf;
2604 symbuf->bufsize = nr;
2605 snew(symbuf->buf, nr);
2606 for (i = 0; (i < nr); i++)
2608 gmx_fio_do_string(fio, buf);
2609 symbuf->buf[i] = strdup(buf);
2614 symbuf = symtab->symbuf;
2615 while (symbuf != NULL)
2617 for (i = 0; (i < symbuf->bufsize) && (i < nr); i++)
2619 gmx_fio_do_string(fio, symbuf->buf[i]);
2622 symbuf = symbuf->next;
2626 gmx_fatal(FARGS, "nr of symtab strings left: %d", nr);
2631 static void do_cmap(t_fileio *fio, gmx_cmap_t *cmap_grid, gmx_bool bRead)
2633 int i, j, ngrid, gs, nelem;
2635 gmx_fio_do_int(fio, cmap_grid->ngrid);
2636 gmx_fio_do_int(fio, cmap_grid->grid_spacing);
2638 ngrid = cmap_grid->ngrid;
2639 gs = cmap_grid->grid_spacing;
2644 snew(cmap_grid->cmapdata, ngrid);
2646 for (i = 0; i < cmap_grid->ngrid; i++)
2648 snew(cmap_grid->cmapdata[i].cmap, 4*nelem);
2652 for (i = 0; i < cmap_grid->ngrid; i++)
2654 for (j = 0; j < nelem; j++)
2656 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4]);
2657 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+1]);
2658 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+2]);
2659 gmx_fio_do_real(fio, cmap_grid->cmapdata[i].cmap[j*4+3]);
2665 void tpx_make_chain_identifiers(t_atoms *atoms, t_block *mols)
2667 int m, a, a0, a1, r;
2671 /* We always assign a new chain number, but save the chain id characters
2672 * for larger molecules.
2674 #define CHAIN_MIN_ATOMS 15
2678 for (m = 0; m < mols->nr; m++)
2680 a0 = mols->index[m];
2681 a1 = mols->index[m+1];
2682 if ((a1-a0 >= CHAIN_MIN_ATOMS) && (chainid <= 'Z'))
2691 for (a = a0; a < a1; a++)
2693 atoms->resinfo[atoms->atom[a].resind].chainnum = chainnum;
2694 atoms->resinfo[atoms->atom[a].resind].chainid = c;
2699 /* Blank out the chain id if there was only one chain */
2702 for (r = 0; r < atoms->nres; r++)
2704 atoms->resinfo[r].chainid = ' ';
2709 static void do_moltype(t_fileio *fio, gmx_moltype_t *molt, gmx_bool bRead,
2710 t_symtab *symtab, int file_version,
2711 gmx_groups_t *groups)
2715 if (file_version >= 57)
2717 do_symstr(fio, &(molt->name), bRead, symtab);
2720 do_atoms(fio, &molt->atoms, bRead, symtab, file_version, groups);
2722 if (bRead && gmx_debug_at)
2724 pr_atoms(debug, 0, "atoms", &molt->atoms, TRUE);
2727 if (file_version >= 57)
2729 do_ilists(fio, molt->ilist, bRead, file_version);
2731 do_block(fio, &molt->cgs, bRead, file_version);
2732 if (bRead && gmx_debug_at)
2734 pr_block(debug, 0, "cgs", &molt->cgs, TRUE);
2738 /* This used to be in the atoms struct */
2739 do_blocka(fio, &molt->excls, bRead, file_version);
2742 static void do_molblock(t_fileio *fio, gmx_molblock_t *molb, gmx_bool bRead)
2746 gmx_fio_do_int(fio, molb->type);
2747 gmx_fio_do_int(fio, molb->nmol);
2748 gmx_fio_do_int(fio, molb->natoms_mol);
2749 /* Position restraint coordinates */
2750 gmx_fio_do_int(fio, molb->nposres_xA);
2751 if (molb->nposres_xA > 0)
2755 snew(molb->posres_xA, molb->nposres_xA);
2757 gmx_fio_ndo_rvec(fio, molb->posres_xA, molb->nposres_xA);
2759 gmx_fio_do_int(fio, molb->nposres_xB);
2760 if (molb->nposres_xB > 0)
2764 snew(molb->posres_xB, molb->nposres_xB);
2766 gmx_fio_ndo_rvec(fio, molb->posres_xB, molb->nposres_xB);
2771 static t_block mtop_mols(gmx_mtop_t *mtop)
2777 for (mb = 0; mb < mtop->nmolblock; mb++)
2779 mols.nr += mtop->molblock[mb].nmol;
2781 mols.nalloc_index = mols.nr + 1;
2782 snew(mols.index, mols.nalloc_index);
2787 for (mb = 0; mb < mtop->nmolblock; mb++)
2789 for (mol = 0; mol < mtop->molblock[mb].nmol; mol++)
2791 a += mtop->molblock[mb].natoms_mol;
2800 static void add_posres_molblock(gmx_mtop_t *mtop)
2805 gmx_molblock_t *molb;
2808 /* posres reference positions are stored in ip->posres (if present) and
2809 in ip->fbposres (if present). If normal and flat-bottomed posres are present,
2810 posres.pos0A are identical to fbposres.pos0. */
2811 il = &mtop->moltype[0].ilist[F_POSRES];
2812 ilfb = &mtop->moltype[0].ilist[F_FBPOSRES];
2813 if (il->nr == 0 && ilfb->nr == 0)
2819 for (i = 0; i < il->nr; i += 2)
2821 ip = &mtop->ffparams.iparams[il->iatoms[i]];
2822 am = max(am, il->iatoms[i+1]);
2823 if (ip->posres.pos0B[XX] != ip->posres.pos0A[XX] ||
2824 ip->posres.pos0B[YY] != ip->posres.pos0A[YY] ||
2825 ip->posres.pos0B[ZZ] != ip->posres.pos0A[ZZ])
2830 /* This loop is required if we have only flat-bottomed posres:
2832 - bFE == FALSE (no B-state for flat-bottomed posres) */
2835 for (i = 0; i < ilfb->nr; i += 2)
2837 ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
2838 am = max(am, ilfb->iatoms[i+1]);
2841 /* Make the posres coordinate block end at a molecule end */
2843 while (am >= mtop->mols.index[mol+1])
2847 molb = &mtop->molblock[0];
2848 molb->nposres_xA = mtop->mols.index[mol+1];
2849 snew(molb->posres_xA, molb->nposres_xA);
2852 molb->nposres_xB = molb->nposres_xA;
2853 snew(molb->posres_xB, molb->nposres_xB);
2857 molb->nposres_xB = 0;
2859 for (i = 0; i < il->nr; i += 2)
2861 ip = &mtop->ffparams.iparams[il->iatoms[i]];
2862 a = il->iatoms[i+1];
2863 molb->posres_xA[a][XX] = ip->posres.pos0A[XX];
2864 molb->posres_xA[a][YY] = ip->posres.pos0A[YY];
2865 molb->posres_xA[a][ZZ] = ip->posres.pos0A[ZZ];
2868 molb->posres_xB[a][XX] = ip->posres.pos0B[XX];
2869 molb->posres_xB[a][YY] = ip->posres.pos0B[YY];
2870 molb->posres_xB[a][ZZ] = ip->posres.pos0B[ZZ];
2875 /* If only flat-bottomed posres are present, take reference pos from them.
2876 Here: bFE == FALSE */
2877 for (i = 0; i < ilfb->nr; i += 2)
2879 ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
2880 a = ilfb->iatoms[i+1];
2881 molb->posres_xA[a][XX] = ip->fbposres.pos0[XX];
2882 molb->posres_xA[a][YY] = ip->fbposres.pos0[YY];
2883 molb->posres_xA[a][ZZ] = ip->fbposres.pos0[ZZ];
2888 static void set_disres_npair(gmx_mtop_t *mtop)
2895 ip = mtop->ffparams.iparams;
2897 for (mt = 0; mt < mtop->nmoltype; mt++)
2899 il = &mtop->moltype[mt].ilist[F_DISRES];
2904 for (i = 0; i < il->nr; i += 3)
2907 if (i+3 == il->nr || ip[a[i]].disres.label != ip[a[i+3]].disres.label)
2909 ip[a[i]].disres.npair = npair;
2917 static void do_mtop(t_fileio *fio, gmx_mtop_t *mtop, gmx_bool bRead,
2927 do_symtab(fio, &(mtop->symtab), bRead);
2930 pr_symtab(debug, 0, "symtab", &mtop->symtab);
2933 do_symstr(fio, &(mtop->name), bRead, &(mtop->symtab));
2935 if (file_version >= 57)
2937 do_ffparams(fio, &mtop->ffparams, bRead, file_version);
2939 gmx_fio_do_int(fio, mtop->nmoltype);
2947 snew(mtop->moltype, mtop->nmoltype);
2948 if (file_version < 57)
2950 mtop->moltype[0].name = mtop->name;
2953 for (mt = 0; mt < mtop->nmoltype; mt++)
2955 do_moltype(fio, &mtop->moltype[mt], bRead, &mtop->symtab, file_version,
2959 if (file_version >= 57)
2961 gmx_fio_do_int(fio, mtop->nmolblock);
2965 mtop->nmolblock = 1;
2969 snew(mtop->molblock, mtop->nmolblock);
2971 if (file_version >= 57)
2973 for (mb = 0; mb < mtop->nmolblock; mb++)
2975 do_molblock(fio, &mtop->molblock[mb], bRead);
2977 gmx_fio_do_int(fio, mtop->natoms);
2981 mtop->molblock[0].type = 0;
2982 mtop->molblock[0].nmol = 1;
2983 mtop->molblock[0].natoms_mol = mtop->moltype[0].atoms.nr;
2984 mtop->molblock[0].nposres_xA = 0;
2985 mtop->molblock[0].nposres_xB = 0;
2988 do_atomtypes (fio, &(mtop->atomtypes), bRead, file_version);
2991 pr_atomtypes(debug, 0, "atomtypes", &mtop->atomtypes, TRUE);
2994 if (file_version < 57)
2996 /* Debug statements are inside do_idef */
2997 do_idef (fio, &mtop->ffparams, &mtop->moltype[0], bRead, file_version);
2998 mtop->natoms = mtop->moltype[0].atoms.nr;
3001 if (file_version >= 65)
3003 do_cmap(fio, &mtop->ffparams.cmap_grid, bRead);
3007 mtop->ffparams.cmap_grid.ngrid = 0;
3008 mtop->ffparams.cmap_grid.grid_spacing = 0;
3009 mtop->ffparams.cmap_grid.cmapdata = NULL;
3012 if (file_version >= 57)
3014 do_groups(fio, &mtop->groups, bRead, &(mtop->symtab), file_version);
3017 if (file_version < 57)
3019 do_block(fio, &mtop->moltype[0].cgs, bRead, file_version);
3020 if (bRead && gmx_debug_at)
3022 pr_block(debug, 0, "cgs", &mtop->moltype[0].cgs, TRUE);
3024 do_block(fio, &mtop->mols, bRead, file_version);
3025 /* Add the posres coordinates to the molblock */
3026 add_posres_molblock(mtop);
3030 if (file_version >= 57)
3032 done_block(&mtop->mols);
3033 mtop->mols = mtop_mols(mtop);
3037 pr_block(debug, 0, "mols", &mtop->mols, TRUE);
3041 if (file_version < 51)
3043 /* Here used to be the shake blocks */
3044 do_blocka(fio, &dumb, bRead, file_version);
3057 close_symtab(&(mtop->symtab));
3061 /* If TopOnlyOK is TRUE then we can read even future versions
3062 * of tpx files, provided the file_generation hasn't changed.
3063 * If it is FALSE, we need the inputrecord too, and bail out
3064 * if the file is newer than the program.
3066 * The version and generation if the topology (see top of this file)
3067 * are returned in the two last arguments.
3069 * If possible, we will read the inputrec even when TopOnlyOK is TRUE.
3071 static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx,
3072 gmx_bool TopOnlyOK, int *file_version,
3073 int *file_generation)
3076 char file_tag[STRLEN];
3083 gmx_fio_checktype(fio);
3084 gmx_fio_setdebug(fio, bDebugMode());
3086 /* NEW! XDR tpb file */
3087 precision = sizeof(real);
3090 gmx_fio_do_string(fio, buf);
3091 if (strncmp(buf, "VERSION", 7))
3093 gmx_fatal(FARGS, "Can not read file %s,\n"
3094 " this file is from a Gromacs version which is older than 2.0\n"
3095 " Make a new one with grompp or use a gro or pdb file, if possible",
3096 gmx_fio_getname(fio));
3098 gmx_fio_do_int(fio, precision);
3099 bDouble = (precision == sizeof(double));
3100 if ((precision != sizeof(float)) && !bDouble)
3102 gmx_fatal(FARGS, "Unknown precision in file %s: real is %d bytes "
3103 "instead of %d or %d",
3104 gmx_fio_getname(fio), precision, sizeof(float), sizeof(double));
3106 gmx_fio_setprecision(fio, bDouble);
3107 fprintf(stderr, "Reading file %s, %s (%s precision)\n",
3108 gmx_fio_getname(fio), buf, bDouble ? "double" : "single");
3112 gmx_fio_write_string(fio, GromacsVersion());
3113 bDouble = (precision == sizeof(double));
3114 gmx_fio_setprecision(fio, bDouble);
3115 gmx_fio_do_int(fio, precision);
3117 sprintf(file_tag, "%s", tpx_tag);
3118 fgen = tpx_generation;
3121 /* Check versions! */
3122 gmx_fio_do_int(fio, fver);
3124 /* This is for backward compatibility with development versions 77-79
3125 * where the tag was, mistakenly, placed before the generation,
3126 * which would cause a segv instead of a proper error message
3127 * when reading the topology only from tpx with <77 code.
3129 if (fver >= 77 && fver <= 79)
3131 gmx_fio_do_string(fio, file_tag);
3136 gmx_fio_do_int(fio, fgen);
3145 gmx_fio_do_string(fio, file_tag);
3151 /* Versions before 77 don't have the tag, set it to release */
3152 sprintf(file_tag, "%s", TPX_TAG_RELEASE);
3155 if (strcmp(file_tag, tpx_tag) != 0)
3157 fprintf(stderr, "Note: file tpx tag '%s', software tpx tag '%s'\n",
3160 /* We only support reading tpx files with the same tag as the code
3161 * or tpx files with the release tag and with lower version number.
3163 if (!strcmp(file_tag, TPX_TAG_RELEASE) == 0 && fver < tpx_version)
3165 gmx_fatal(FARGS, "tpx tag/version mismatch: reading tpx file (%s) version %d, tag '%s' with program for tpx version %d, tag '%s'",
3166 gmx_fio_getname(fio), fver, file_tag,
3167 tpx_version, tpx_tag);
3172 if (file_version != NULL)
3174 *file_version = fver;
3176 if (file_generation != NULL)
3178 *file_generation = fgen;
3182 if ((fver <= tpx_incompatible_version) ||
3183 ((fver > tpx_version) && !TopOnlyOK) ||
3184 (fgen > tpx_generation) ||
3185 tpx_version == 80) /*80 was used by both 5.0-dev and 4.6-dev*/
3187 gmx_fatal(FARGS, "reading tpx file (%s) version %d with version %d program",
3188 gmx_fio_getname(fio), fver, tpx_version);
3191 do_section(fio, eitemHEADER, bRead);
3192 gmx_fio_do_int(fio, tpx->natoms);
3195 gmx_fio_do_int(fio, tpx->ngtc);
3203 gmx_fio_do_int(fio, idum);
3204 gmx_fio_do_real(fio, rdum);
3206 /*a better decision will eventually (5.0 or later) need to be made
3207 on how to treat the alchemical state of the system, which can now
3208 vary through a simulation, and cannot be completely described
3209 though a single lambda variable, or even a single state
3210 index. Eventually, should probably be a vector. MRS*/
3213 gmx_fio_do_int(fio, tpx->fep_state);
3215 gmx_fio_do_real(fio, tpx->lambda);
3216 gmx_fio_do_int(fio, tpx->bIr);
3217 gmx_fio_do_int(fio, tpx->bTop);
3218 gmx_fio_do_int(fio, tpx->bX);
3219 gmx_fio_do_int(fio, tpx->bV);
3220 gmx_fio_do_int(fio, tpx->bF);
3221 gmx_fio_do_int(fio, tpx->bBox);
3223 if ((fgen > tpx_generation))
3225 /* This can only happen if TopOnlyOK=TRUE */
3230 static int do_tpx(t_fileio *fio, gmx_bool bRead,
3231 t_inputrec *ir, t_state *state, rvec *f, gmx_mtop_t *mtop,
3232 gmx_bool bXVallocated)
3238 int file_version, file_generation;
3242 gmx_bool bPeriodicMols;
3246 tpx.natoms = state->natoms;
3247 tpx.ngtc = state->ngtc; /* need to add nnhpres here? */
3248 tpx.fep_state = state->fep_state;
3249 tpx.lambda = state->lambda[efptFEP];
3250 tpx.bIr = (ir != NULL);
3251 tpx.bTop = (mtop != NULL);
3252 tpx.bX = (state->x != NULL);
3253 tpx.bV = (state->v != NULL);
3254 tpx.bF = (f != NULL);
3258 TopOnlyOK = (ir == NULL);
3260 do_tpxheader(fio, bRead, &tpx, TopOnlyOK, &file_version, &file_generation);
3265 /* state->lambda = tpx.lambda;*/ /*remove this eventually? */
3266 /* The init_state calls initialize the Nose-Hoover xi integrals to zero */
3271 init_state(state, 0, tpx.ngtc, 0, 0, 0); /* nose-hoover chains */ /* eventually, need to add nnhpres here? */
3272 state->natoms = tpx.natoms;
3273 state->nalloc = tpx.natoms;
3279 init_state(state, tpx.natoms, tpx.ngtc, 0, 0, 0); /* nose-hoover chains */
3283 #define do_test(fio, b, p) if (bRead && (p != NULL) && !b) gmx_fatal(FARGS, "No %s in %s",#p, gmx_fio_getname(fio))
3285 do_test(fio, tpx.bBox, state->box);
3286 do_section(fio, eitemBOX, bRead);
3289 gmx_fio_ndo_rvec(fio, state->box, DIM);
3290 if (file_version >= 51)
3292 gmx_fio_ndo_rvec(fio, state->box_rel, DIM);
3296 /* We initialize box_rel after reading the inputrec */
3297 clear_mat(state->box_rel);
3299 if (file_version >= 28)
3301 gmx_fio_ndo_rvec(fio, state->boxv, DIM);
3302 if (file_version < 56)
3305 gmx_fio_ndo_rvec(fio, mdum, DIM);
3310 if (state->ngtc > 0 && file_version >= 28)
3313 /*ndo_double(state->nosehoover_xi,state->ngtc,bDum);*/
3314 /*ndo_double(state->nosehoover_vxi,state->ngtc,bDum);*/
3315 /*ndo_double(state->therm_integral,state->ngtc,bDum);*/
3316 snew(dumv, state->ngtc);
3317 if (file_version < 69)
3319 gmx_fio_ndo_real(fio, dumv, state->ngtc);
3321 /* These used to be the Berendsen tcoupl_lambda's */
3322 gmx_fio_ndo_real(fio, dumv, state->ngtc);
3326 /* Prior to tpx version 26, the inputrec was here.
3327 * I moved it to enable partial forward-compatibility
3328 * for analysis/viewer programs.
3330 if (file_version < 26)
3332 do_test(fio, tpx.bIr, ir);
3333 do_section(fio, eitemIR, bRead);
3338 do_inputrec(fio, ir, bRead, file_version,
3339 mtop ? &mtop->ffparams.fudgeQQ : NULL);
3342 pr_inputrec(debug, 0, "inputrec", ir, FALSE);
3347 do_inputrec(fio, &dum_ir, bRead, file_version,
3348 mtop ? &mtop->ffparams.fudgeQQ : NULL);
3351 pr_inputrec(debug, 0, "inputrec", &dum_ir, FALSE);
3353 done_inputrec(&dum_ir);
3359 do_test(fio, tpx.bTop, mtop);
3360 do_section(fio, eitemTOP, bRead);
3365 do_mtop(fio, mtop, bRead, file_version);
3369 do_mtop(fio, &dum_top, bRead, file_version);
3370 done_mtop(&dum_top, TRUE);
3373 do_test(fio, tpx.bX, state->x);
3374 do_section(fio, eitemX, bRead);
3379 state->flags |= (1<<estX);
3381 gmx_fio_ndo_rvec(fio, state->x, state->natoms);
3384 do_test(fio, tpx.bV, state->v);
3385 do_section(fio, eitemV, bRead);
3390 state->flags |= (1<<estV);
3392 gmx_fio_ndo_rvec(fio, state->v, state->natoms);
3395 do_test(fio, tpx.bF, f);
3396 do_section(fio, eitemF, bRead);
3399 gmx_fio_ndo_rvec(fio, f, state->natoms);
3402 /* Starting with tpx version 26, we have the inputrec
3403 * at the end of the file, so we can ignore it
3404 * if the file is never than the software (but still the
3405 * same generation - see comments at the top of this file.
3410 bPeriodicMols = FALSE;
3411 if (file_version >= 26)
3413 do_test(fio, tpx.bIr, ir);
3414 do_section(fio, eitemIR, bRead);
3417 if (file_version >= 53)
3419 /* Removed the pbc info from do_inputrec, since we always want it */
3423 bPeriodicMols = ir->bPeriodicMols;
3425 gmx_fio_do_int(fio, ePBC);
3426 gmx_fio_do_gmx_bool(fio, bPeriodicMols);
3428 if (file_generation <= tpx_generation && ir)
3430 do_inputrec(fio, ir, bRead, file_version, mtop ? &mtop->ffparams.fudgeQQ : NULL);
3433 pr_inputrec(debug, 0, "inputrec", ir, FALSE);
3435 if (file_version < 51)
3437 set_box_rel(ir, state);
3439 if (file_version < 53)
3442 bPeriodicMols = ir->bPeriodicMols;
3445 if (bRead && ir && file_version >= 53)
3447 /* We need to do this after do_inputrec, since that initializes ir */
3449 ir->bPeriodicMols = bPeriodicMols;
3458 if (state->ngtc == 0)
3460 /* Reading old version without tcoupl state data: set it */
3461 init_gtc_state(state, ir->opts.ngtc, 0, ir->opts.nhchainlength);
3463 if (tpx.bTop && mtop)
3465 if (file_version < 57)
3467 if (mtop->moltype[0].ilist[F_DISRES].nr > 0)
3469 ir->eDisre = edrSimple;
3473 ir->eDisre = edrNone;
3476 set_disres_npair(mtop);
3480 if (tpx.bTop && mtop)
3482 gmx_mtop_finalize(mtop);
3485 if (file_version >= 57)
3489 env = getenv("GMX_NOCHARGEGROUPS");
3492 sscanf(env, "%d", &ienv);
3493 fprintf(stderr, "\nFound env.var. GMX_NOCHARGEGROUPS = %d\n",
3498 "Will make single atomic charge groups in non-solvent%s\n",
3499 ienv > 1 ? " and solvent" : "");
3500 gmx_mtop_make_atomic_charge_groups(mtop, ienv == 1);
3502 fprintf(stderr, "\n");
3510 /************************************************************
3512 * The following routines are the exported ones
3514 ************************************************************/
3516 t_fileio *open_tpx(const char *fn, const char *mode)
3518 return gmx_fio_open(fn, mode);
3521 void close_tpx(t_fileio *fio)
3526 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
3527 int *file_version, int *file_generation)
3531 fio = open_tpx(fn, "r");
3532 do_tpxheader(fio, TRUE, tpx, TopOnlyOK, file_version, file_generation);
3536 void write_tpx_state(const char *fn,
3537 t_inputrec *ir, t_state *state, gmx_mtop_t *mtop)
3541 fio = open_tpx(fn, "w");
3542 do_tpx(fio, FALSE, ir, state, NULL, mtop, FALSE);
3546 void read_tpx_state(const char *fn,
3547 t_inputrec *ir, t_state *state, rvec *f, gmx_mtop_t *mtop)
3551 fio = open_tpx(fn, "r");
3552 do_tpx(fio, TRUE, ir, state, f, mtop, FALSE);
3556 int read_tpx(const char *fn,
3557 t_inputrec *ir, matrix box, int *natoms,
3558 rvec *x, rvec *v, rvec *f, gmx_mtop_t *mtop)
3566 fio = open_tpx(fn, "r");
3567 ePBC = do_tpx(fio, TRUE, ir, &state, f, mtop, TRUE);
3569 *natoms = state.natoms;
3572 copy_mat(state.box, box);
3581 int read_tpx_top(const char *fn,
3582 t_inputrec *ir, matrix box, int *natoms,
3583 rvec *x, rvec *v, rvec *f, t_topology *top)
3589 ePBC = read_tpx(fn, ir, box, natoms, x, v, f, &mtop);
3591 *top = gmx_mtop_t_to_t_topology(&mtop);
3596 gmx_bool fn2bTPX(const char *file)
3598 switch (fn2ftp(file))
3609 static void done_gmx_groups_t(gmx_groups_t *g)
3613 for (i = 0; (i < egcNR); i++)
3615 if (NULL != g->grps[i].nm_ind)
3617 sfree(g->grps[i].nm_ind);
3618 g->grps[i].nm_ind = NULL;
3620 if (NULL != g->grpnr[i])
3626 /* The contents of this array is in symtab, don't free it here */
3630 gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *ePBC,
3631 rvec **x, rvec **v, matrix box, gmx_bool bMass)
3634 int natoms, i, version, generation;
3635 gmx_bool bTop, bXNULL = FALSE;
3637 t_topology *topconv;
3640 bTop = fn2bTPX(infile);
3644 read_tpxheader(infile, &header, TRUE, &version, &generation);
3647 snew(*x, header.natoms);
3651 snew(*v, header.natoms);
3654 *ePBC = read_tpx(infile, NULL, box, &natoms,
3655 (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
3656 *top = gmx_mtop_t_to_t_topology(mtop);
3657 /* In this case we need to throw away the group data too */
3658 done_gmx_groups_t(&mtop->groups);
3660 strcpy(title, *top->name);
3661 tpx_make_chain_identifiers(&top->atoms, &top->mols);
3665 get_stx_coordnum(infile, &natoms);
3666 init_t_atoms(&top->atoms, natoms, (fn2ftp(infile) == efPDB));
3677 read_stx_conf(infile, title, &top->atoms, *x, (v == NULL) ? NULL : *v, ePBC, box);
3685 aps = gmx_atomprop_init();
3686 for (i = 0; (i < natoms); i++)
3688 if (!gmx_atomprop_query(aps, epropMass,
3689 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
3690 *top->atoms.atomname[i],
3691 &(top->atoms.atom[i].m)))
3695 fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
3696 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
3697 top->atoms.resinfo[top->atoms.atom[i].resind].nr,
3698 *top->atoms.atomname[i]);
3702 gmx_atomprop_destroy(aps);
3704 top->idef.ntypes = -1;