1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * GROningen Mixture of Alchemy and Childrens' Stories
40 /* This file is completely threadsafe - keep it that way! */
42 #include <thread_mpi.h>
50 #include "gmx_fatal.h"
64 #include "mtop_util.h"
66 /* This number should be increased whenever the file format changes! */
67 static const int tpx_version = 73;
69 /* This number should only be increased when you edit the TOPOLOGY section
70 * of the tpx format. This way we can maintain forward compatibility too
71 * for all analysis tools and/or external programs that only need to
72 * know the atom/residue names, charges, and bond connectivity.
74 * It first appeared in tpx version 26, when I also moved the inputrecord
75 * to the end of the tpx file, so we can just skip it if we only
78 static const int tpx_generation = 23;
80 /* This number should be the most recent backwards incompatible version
81 * I.e., if this number is 9, we cannot read tpx version 9 with this code.
83 static const int tpx_incompatible_version = 9;
87 /* Struct used to maintain tpx compatibility when function types are added */
89 int fvnr; /* file version number in which the function type first appeared */
90 int ftype; /* function type */
94 *The entries should be ordered in:
95 * 1. ascending file version number
96 * 2. ascending function type number
98 /*static const t_ftupd ftupd[] = {
103 { 22, F_DISRESVIOL },
109 { 26, F_DIHRESVIOL },
110 { 30, F_CROSS_BOND_BONDS },
111 { 30, F_CROSS_BOND_ANGLES },
112 { 30, F_UREY_BRADLEY },
113 { 30, F_POLARIZATION }
117 *The entries should be ordered in:
118 * 1. ascending function type number
119 * 2. ascending file version number
121 static const t_ftupd ftupd[] = {
122 { 20, F_CUBICBONDS },
127 { 43, F_TABBONDSNC },
128 { 70, F_RESTRBONDS },
129 { 30, F_CROSS_BOND_BONDS },
130 { 30, F_CROSS_BOND_ANGLES },
131 { 30, F_UREY_BRADLEY },
132 { 34, F_QUARTIC_ANGLES },
142 { 72, F_NPSOLVATION },
144 { 41, F_LJC_PAIRS_NB },
147 { 32, F_COUL_RECIP },
149 { 30, F_POLARIZATION },
151 { 22, F_DISRESVIOL },
155 { 26, F_DIHRESVIOL },
160 { 46, F_ECONSERVED },
165 #define NFTUPD asize(ftupd)
167 /* Needed for backward compatibility */
170 static void _do_section(t_fileio *fio,int key,gmx_bool bRead,const char *src,
176 if (gmx_fio_getftp(fio) == efTPA) {
178 gmx_fio_write_string(fio,itemstr[key]);
179 bDbg = gmx_fio_getdebug(fio);
180 gmx_fio_setdebug(fio,FALSE);
181 gmx_fio_write_string(fio,comment_str[key]);
182 gmx_fio_setdebug(fio,bDbg);
185 if (gmx_fio_getdebug(fio))
186 fprintf(stderr,"Looking for section %s (%s, %d)",
187 itemstr[key],src,line);
190 gmx_fio_do_string(fio,buf);
191 } while ((gmx_strcasecmp(buf,itemstr[key]) != 0));
193 if (gmx_strcasecmp(buf,itemstr[key]) != 0)
194 gmx_fatal(FARGS,"\nCould not find section heading %s",itemstr[key]);
195 else if (gmx_fio_getdebug(fio))
196 fprintf(stderr," and found it\n");
201 #define do_section(fio,key,bRead) _do_section(fio,key,bRead,__FILE__,__LINE__)
203 /**************************************************************
205 * Now the higer level routines that do io of the structures and arrays
207 **************************************************************/
208 static void do_pullgrp(t_fileio *fio, t_pullgrp *pgrp, gmx_bool bRead,
214 gmx_fio_do_int(fio,pgrp->nat);
216 snew(pgrp->ind,pgrp->nat);
217 bDum=gmx_fio_ndo_int(fio,pgrp->ind,pgrp->nat);
218 gmx_fio_do_int(fio,pgrp->nweight);
220 snew(pgrp->weight,pgrp->nweight);
221 bDum=gmx_fio_ndo_real(fio,pgrp->weight,pgrp->nweight);
222 gmx_fio_do_int(fio,pgrp->pbcatom);
223 gmx_fio_do_rvec(fio,pgrp->vec);
224 gmx_fio_do_rvec(fio,pgrp->init);
225 gmx_fio_do_real(fio,pgrp->rate);
226 gmx_fio_do_real(fio,pgrp->k);
227 if (file_version >= 56) {
228 gmx_fio_do_real(fio,pgrp->kB);
234 static void do_pull(t_fileio *fio, t_pull *pull,gmx_bool bRead, int file_version)
238 gmx_fio_do_int(fio,pull->ngrp);
239 gmx_fio_do_int(fio,pull->eGeom);
240 gmx_fio_do_ivec(fio,pull->dim);
241 gmx_fio_do_real(fio,pull->cyl_r1);
242 gmx_fio_do_real(fio,pull->cyl_r0);
243 gmx_fio_do_real(fio,pull->constr_tol);
244 gmx_fio_do_int(fio,pull->nstxout);
245 gmx_fio_do_int(fio,pull->nstfout);
247 snew(pull->grp,pull->ngrp+1);
248 for(g=0; g<pull->ngrp+1; g++)
249 do_pullgrp(fio,&pull->grp[g],bRead,file_version);
252 static void do_inputrec(t_fileio *fio, t_inputrec *ir,gmx_bool bRead,
253 int file_version, real *fudgeQQ)
255 int i,j,k,*tmp,idum=0;
260 real zerotemptime,finish_t,init_temp,finish_temp;
262 if (file_version != tpx_version)
264 /* Give a warning about features that are not accessible */
265 fprintf(stderr,"Note: tpx file_version %d, software version %d\n",
266 file_version,tpx_version);
274 if (file_version == 0)
279 /* Basic inputrec stuff */
280 gmx_fio_do_int(fio,ir->eI);
281 if (file_version >= 62) {
282 gmx_fio_do_gmx_large_int(fio, ir->nsteps);
284 gmx_fio_do_int(fio,idum);
287 if(file_version > 25) {
288 if (file_version >= 62) {
289 gmx_fio_do_gmx_large_int(fio, ir->init_step);
291 gmx_fio_do_int(fio,idum);
292 ir->init_step = idum;
298 if(file_version >= 58)
299 gmx_fio_do_int(fio,ir->simulation_part);
301 ir->simulation_part=1;
303 if (file_version >= 67) {
304 gmx_fio_do_int(fio,ir->nstcalcenergy);
306 ir->nstcalcenergy = 1;
308 if (file_version < 53) {
309 /* The pbc info has been moved out of do_inputrec,
310 * since we always want it, also without reading the inputrec.
312 gmx_fio_do_int(fio,ir->ePBC);
313 if ((file_version <= 15) && (ir->ePBC == 2))
315 if (file_version >= 45) {
316 gmx_fio_do_int(fio,ir->bPeriodicMols);
320 ir->bPeriodicMols = TRUE;
322 ir->bPeriodicMols = FALSE;
326 gmx_fio_do_int(fio,ir->ns_type);
327 gmx_fio_do_int(fio,ir->nstlist);
328 gmx_fio_do_int(fio,ir->ndelta);
329 if (file_version < 41) {
330 gmx_fio_do_int(fio,idum);
331 gmx_fio_do_int(fio,idum);
333 if (file_version >= 45)
334 gmx_fio_do_real(fio,ir->rtpi);
337 gmx_fio_do_int(fio,ir->nstcomm);
338 if (file_version > 34)
339 gmx_fio_do_int(fio,ir->comm_mode);
340 else if (ir->nstcomm < 0)
341 ir->comm_mode = ecmANGULAR;
343 ir->comm_mode = ecmLINEAR;
344 ir->nstcomm = abs(ir->nstcomm);
346 if(file_version > 25)
347 gmx_fio_do_int(fio,ir->nstcheckpoint);
351 gmx_fio_do_int(fio,ir->nstcgsteep);
354 gmx_fio_do_int(fio,ir->nbfgscorr);
358 gmx_fio_do_int(fio,ir->nstlog);
359 gmx_fio_do_int(fio,ir->nstxout);
360 gmx_fio_do_int(fio,ir->nstvout);
361 gmx_fio_do_int(fio,ir->nstfout);
362 gmx_fio_do_int(fio,ir->nstenergy);
363 gmx_fio_do_int(fio,ir->nstxtcout);
364 if (file_version >= 59) {
365 gmx_fio_do_double(fio,ir->init_t);
366 gmx_fio_do_double(fio,ir->delta_t);
368 gmx_fio_do_real(fio,rdum);
370 gmx_fio_do_real(fio,rdum);
373 gmx_fio_do_real(fio,ir->xtcprec);
374 if (file_version < 19) {
375 gmx_fio_do_int(fio,idum);
376 gmx_fio_do_int(fio,idum);
378 if(file_version < 18)
379 gmx_fio_do_int(fio,idum);
380 gmx_fio_do_real(fio,ir->rlist);
381 if (file_version >= 67) {
382 gmx_fio_do_real(fio,ir->rlistlong);
384 gmx_fio_do_int(fio,ir->coulombtype);
385 if (file_version < 32 && ir->coulombtype == eelRF)
386 ir->coulombtype = eelRF_NEC;
387 gmx_fio_do_real(fio,ir->rcoulomb_switch);
388 gmx_fio_do_real(fio,ir->rcoulomb);
389 gmx_fio_do_int(fio,ir->vdwtype);
390 gmx_fio_do_real(fio,ir->rvdw_switch);
391 gmx_fio_do_real(fio,ir->rvdw);
392 if (file_version < 67) {
393 ir->rlistlong = max_cutoff(ir->rlist,max_cutoff(ir->rvdw,ir->rcoulomb));
395 gmx_fio_do_int(fio,ir->eDispCorr);
396 gmx_fio_do_real(fio,ir->epsilon_r);
397 if (file_version >= 37) {
398 gmx_fio_do_real(fio,ir->epsilon_rf);
400 if (EEL_RF(ir->coulombtype)) {
401 ir->epsilon_rf = ir->epsilon_r;
404 ir->epsilon_rf = 1.0;
407 if (file_version >= 29)
408 gmx_fio_do_real(fio,ir->tabext);
412 if(file_version > 25) {
413 gmx_fio_do_int(fio,ir->gb_algorithm);
414 gmx_fio_do_int(fio,ir->nstgbradii);
415 gmx_fio_do_real(fio,ir->rgbradii);
416 gmx_fio_do_real(fio,ir->gb_saltconc);
417 gmx_fio_do_int(fio,ir->implicit_solvent);
419 ir->gb_algorithm=egbSTILL;
423 ir->implicit_solvent=eisNO;
427 gmx_fio_do_real(fio,ir->gb_epsilon_solvent);
428 gmx_fio_do_real(fio,ir->gb_obc_alpha);
429 gmx_fio_do_real(fio,ir->gb_obc_beta);
430 gmx_fio_do_real(fio,ir->gb_obc_gamma);
433 gmx_fio_do_real(fio,ir->gb_dielectric_offset);
434 gmx_fio_do_int(fio,ir->sa_algorithm);
438 ir->gb_dielectric_offset = 0.009;
439 ir->sa_algorithm = esaAPPROX;
441 gmx_fio_do_real(fio,ir->sa_surface_tension);
445 /* Better use sensible values than insane (0.0) ones... */
446 ir->gb_epsilon_solvent = 80;
447 ir->gb_obc_alpha = 1.0;
448 ir->gb_obc_beta = 0.8;
449 ir->gb_obc_gamma = 4.85;
450 ir->sa_surface_tension = 2.092;
454 gmx_fio_do_int(fio,ir->nkx);
455 gmx_fio_do_int(fio,ir->nky);
456 gmx_fio_do_int(fio,ir->nkz);
457 gmx_fio_do_int(fio,ir->pme_order);
458 gmx_fio_do_real(fio,ir->ewald_rtol);
460 if (file_version >=24)
461 gmx_fio_do_int(fio,ir->ewald_geometry);
463 ir->ewald_geometry=eewg3D;
465 if (file_version <=17) {
466 ir->epsilon_surface=0;
467 if (file_version==17)
468 gmx_fio_do_int(fio,idum);
471 gmx_fio_do_real(fio,ir->epsilon_surface);
473 gmx_fio_do_gmx_bool(fio,ir->bOptFFT);
475 gmx_fio_do_gmx_bool(fio,ir->bContinuation);
476 gmx_fio_do_int(fio,ir->etc);
477 /* before version 18, ir->etc was a gmx_bool (ir->btc),
478 * but the values 0 and 1 still mean no and
479 * berendsen temperature coupling, respectively.
481 if (file_version >= 71)
483 gmx_fio_do_int(fio,ir->nsttcouple);
487 ir->nsttcouple = ir->nstcalcenergy;
489 if (file_version <= 15)
491 gmx_fio_do_int(fio,idum);
493 if (file_version <=17)
495 gmx_fio_do_int(fio,ir->epct);
496 if (file_version <= 15)
500 ir->epct = epctSURFACETENSION;
502 gmx_fio_do_int(fio,idum);
505 /* we have removed the NO alternative at the beginning */
509 ir->epct=epctISOTROPIC;
513 ir->epc=epcBERENDSEN;
518 gmx_fio_do_int(fio,ir->epc);
519 gmx_fio_do_int(fio,ir->epct);
521 if (file_version >= 71)
523 gmx_fio_do_int(fio,ir->nstpcouple);
527 ir->nstpcouple = ir->nstcalcenergy;
529 gmx_fio_do_real(fio,ir->tau_p);
530 if (file_version <= 15) {
531 gmx_fio_do_rvec(fio,vdum);
532 clear_mat(ir->ref_p);
534 ir->ref_p[i][i] = vdum[i];
536 gmx_fio_do_rvec(fio,ir->ref_p[XX]);
537 gmx_fio_do_rvec(fio,ir->ref_p[YY]);
538 gmx_fio_do_rvec(fio,ir->ref_p[ZZ]);
540 if (file_version <= 15) {
541 gmx_fio_do_rvec(fio,vdum);
542 clear_mat(ir->compress);
544 ir->compress[i][i] = vdum[i];
547 gmx_fio_do_rvec(fio,ir->compress[XX]);
548 gmx_fio_do_rvec(fio,ir->compress[YY]);
549 gmx_fio_do_rvec(fio,ir->compress[ZZ]);
551 if (file_version >= 47) {
552 gmx_fio_do_int(fio,ir->refcoord_scaling);
553 gmx_fio_do_rvec(fio,ir->posres_com);
554 gmx_fio_do_rvec(fio,ir->posres_comB);
556 ir->refcoord_scaling = erscNO;
557 clear_rvec(ir->posres_com);
558 clear_rvec(ir->posres_comB);
560 if(file_version > 25)
561 gmx_fio_do_int(fio,ir->andersen_seed);
565 if(file_version < 26) {
566 gmx_fio_do_gmx_bool(fio,bSimAnn);
567 gmx_fio_do_real(fio,zerotemptime);
570 if (file_version < 37)
571 gmx_fio_do_real(fio,rdum);
573 gmx_fio_do_real(fio,ir->shake_tol);
574 if (file_version < 54)
575 gmx_fio_do_real(fio,*fudgeQQ);
576 gmx_fio_do_int(fio,ir->efep);
577 if (file_version <= 14 && ir->efep > efepNO)
579 if (file_version >= 59) {
580 gmx_fio_do_double(fio, ir->init_lambda);
581 gmx_fio_do_double(fio, ir->delta_lambda);
583 gmx_fio_do_real(fio,rdum);
584 ir->init_lambda = rdum;
585 gmx_fio_do_real(fio,rdum);
586 ir->delta_lambda = rdum;
588 if (file_version >= 64) {
589 gmx_fio_do_int(fio,ir->n_flambda);
591 snew(ir->flambda,ir->n_flambda);
593 bDum=gmx_fio_ndo_double(fio,ir->flambda,ir->n_flambda);
598 if (file_version >= 13)
599 gmx_fio_do_real(fio,ir->sc_alpha);
602 if (file_version >= 38)
603 gmx_fio_do_int(fio,ir->sc_power);
606 if (file_version >= 15)
607 gmx_fio_do_real(fio,ir->sc_sigma);
612 if (file_version >= 71)
614 ir->sc_sigma_min = ir->sc_sigma;
618 ir->sc_sigma_min = 0;
621 if (file_version >= 64) {
622 gmx_fio_do_int(fio,ir->nstdhdl);
627 if (file_version >= 73)
629 gmx_fio_do_int(fio, ir->separate_dhdl_file);
630 gmx_fio_do_int(fio, ir->dhdl_derivatives);
634 ir->separate_dhdl_file = sepdhdlfileYES;
635 ir->dhdl_derivatives = dhdlderivativesYES;
638 if (file_version >= 71)
640 gmx_fio_do_int(fio,ir->dh_hist_size);
641 gmx_fio_do_double(fio,ir->dh_hist_spacing);
645 ir->dh_hist_size = 0;
646 ir->dh_hist_spacing = 0.1;
648 if (file_version >= 57) {
649 gmx_fio_do_int(fio,ir->eDisre);
651 gmx_fio_do_int(fio,ir->eDisreWeighting);
652 if (file_version < 22) {
653 if (ir->eDisreWeighting == 0)
654 ir->eDisreWeighting = edrwEqual;
656 ir->eDisreWeighting = edrwConservative;
658 gmx_fio_do_gmx_bool(fio,ir->bDisreMixed);
659 gmx_fio_do_real(fio,ir->dr_fc);
660 gmx_fio_do_real(fio,ir->dr_tau);
661 gmx_fio_do_int(fio,ir->nstdisreout);
662 if (file_version >= 22) {
663 gmx_fio_do_real(fio,ir->orires_fc);
664 gmx_fio_do_real(fio,ir->orires_tau);
665 gmx_fio_do_int(fio,ir->nstorireout);
671 if(file_version >= 26) {
672 gmx_fio_do_real(fio,ir->dihre_fc);
673 if (file_version < 56) {
674 gmx_fio_do_real(fio,rdum);
675 gmx_fio_do_int(fio,idum);
681 gmx_fio_do_real(fio,ir->em_stepsize);
682 gmx_fio_do_real(fio,ir->em_tol);
683 if (file_version >= 22)
684 gmx_fio_do_gmx_bool(fio,ir->bShakeSOR);
686 ir->bShakeSOR = TRUE;
687 if (file_version >= 11)
688 gmx_fio_do_int(fio,ir->niter);
691 fprintf(stderr,"Note: niter not in run input file, setting it to %d\n",
694 if (file_version >= 21)
695 gmx_fio_do_real(fio,ir->fc_stepsize);
698 gmx_fio_do_int(fio,ir->eConstrAlg);
699 gmx_fio_do_int(fio,ir->nProjOrder);
700 gmx_fio_do_real(fio,ir->LincsWarnAngle);
701 if (file_version <= 14)
702 gmx_fio_do_int(fio,idum);
703 if (file_version >=26)
704 gmx_fio_do_int(fio,ir->nLincsIter);
707 fprintf(stderr,"Note: nLincsIter not in run input file, setting it to %d\n",
710 if (file_version < 33)
711 gmx_fio_do_real(fio,bd_temp);
712 gmx_fio_do_real(fio,ir->bd_fric);
713 gmx_fio_do_int(fio,ir->ld_seed);
714 if (file_version >= 33) {
716 gmx_fio_do_rvec(fio,ir->deform[i]);
719 clear_rvec(ir->deform[i]);
721 if (file_version >= 14)
722 gmx_fio_do_real(fio,ir->cos_accel);
725 gmx_fio_do_int(fio,ir->userint1);
726 gmx_fio_do_int(fio,ir->userint2);
727 gmx_fio_do_int(fio,ir->userint3);
728 gmx_fio_do_int(fio,ir->userint4);
729 gmx_fio_do_real(fio,ir->userreal1);
730 gmx_fio_do_real(fio,ir->userreal2);
731 gmx_fio_do_real(fio,ir->userreal3);
732 gmx_fio_do_real(fio,ir->userreal4);
735 if (file_version >= 48) {
736 gmx_fio_do_int(fio,ir->ePull);
737 if (ir->ePull != epullNO) {
740 do_pull(fio, ir->pull,bRead,file_version);
747 gmx_fio_do_int(fio,ir->opts.ngtc);
748 if (file_version >= 69) {
749 gmx_fio_do_int(fio,ir->opts.nhchainlength);
751 ir->opts.nhchainlength = 1;
753 gmx_fio_do_int(fio,ir->opts.ngacc);
754 gmx_fio_do_int(fio,ir->opts.ngfrz);
755 gmx_fio_do_int(fio,ir->opts.ngener);
758 snew(ir->opts.nrdf, ir->opts.ngtc);
759 snew(ir->opts.ref_t, ir->opts.ngtc);
760 snew(ir->opts.annealing, ir->opts.ngtc);
761 snew(ir->opts.anneal_npoints, ir->opts.ngtc);
762 snew(ir->opts.anneal_time, ir->opts.ngtc);
763 snew(ir->opts.anneal_temp, ir->opts.ngtc);
764 snew(ir->opts.tau_t, ir->opts.ngtc);
765 snew(ir->opts.nFreeze,ir->opts.ngfrz);
766 snew(ir->opts.acc, ir->opts.ngacc);
767 snew(ir->opts.egp_flags,ir->opts.ngener*ir->opts.ngener);
769 if (ir->opts.ngtc > 0) {
770 if (bRead && file_version<13) {
771 snew(tmp,ir->opts.ngtc);
772 bDum=gmx_fio_ndo_int(fio,tmp, ir->opts.ngtc);
773 for(i=0; i<ir->opts.ngtc; i++)
774 ir->opts.nrdf[i] = tmp[i];
777 bDum=gmx_fio_ndo_real(fio,ir->opts.nrdf, ir->opts.ngtc);
779 bDum=gmx_fio_ndo_real(fio,ir->opts.ref_t,ir->opts.ngtc);
780 bDum=gmx_fio_ndo_real(fio,ir->opts.tau_t,ir->opts.ngtc);
781 if (file_version<33 && ir->eI==eiBD) {
782 for(i=0; i<ir->opts.ngtc; i++)
783 ir->opts.tau_t[i] = bd_temp;
786 if (ir->opts.ngfrz > 0)
787 bDum=gmx_fio_ndo_ivec(fio,ir->opts.nFreeze,ir->opts.ngfrz);
788 if (ir->opts.ngacc > 0)
789 gmx_fio_ndo_rvec(fio,ir->opts.acc,ir->opts.ngacc);
790 if (file_version >= 12)
791 bDum=gmx_fio_ndo_int(fio,ir->opts.egp_flags,
792 ir->opts.ngener*ir->opts.ngener);
794 if(bRead && file_version < 26) {
795 for(i=0;i<ir->opts.ngtc;i++) {
797 ir->opts.annealing[i] = eannSINGLE;
798 ir->opts.anneal_npoints[i] = 2;
799 snew(ir->opts.anneal_time[i],2);
800 snew(ir->opts.anneal_temp[i],2);
801 /* calculate the starting/ending temperatures from reft, zerotemptime, and nsteps */
802 finish_t = ir->init_t + ir->nsteps * ir->delta_t;
803 init_temp = ir->opts.ref_t[i]*(1-ir->init_t/zerotemptime);
804 finish_temp = ir->opts.ref_t[i]*(1-finish_t/zerotemptime);
805 ir->opts.anneal_time[i][0] = ir->init_t;
806 ir->opts.anneal_time[i][1] = finish_t;
807 ir->opts.anneal_temp[i][0] = init_temp;
808 ir->opts.anneal_temp[i][1] = finish_temp;
810 ir->opts.annealing[i] = eannNO;
811 ir->opts.anneal_npoints[i] = 0;
815 /* file version 26 or later */
816 /* First read the lists with annealing and npoints for each group */
817 bDum=gmx_fio_ndo_int(fio,ir->opts.annealing,ir->opts.ngtc);
818 bDum=gmx_fio_ndo_int(fio,ir->opts.anneal_npoints,ir->opts.ngtc);
819 for(j=0;j<(ir->opts.ngtc);j++) {
820 k=ir->opts.anneal_npoints[j];
822 snew(ir->opts.anneal_time[j],k);
823 snew(ir->opts.anneal_temp[j],k);
825 bDum=gmx_fio_ndo_real(fio,ir->opts.anneal_time[j],k);
826 bDum=gmx_fio_ndo_real(fio,ir->opts.anneal_temp[j],k);
830 if (file_version >= 45) {
831 gmx_fio_do_int(fio,ir->nwall);
832 gmx_fio_do_int(fio,ir->wall_type);
833 if (file_version >= 50)
834 gmx_fio_do_real(fio,ir->wall_r_linpot);
836 ir->wall_r_linpot = -1;
837 gmx_fio_do_int(fio,ir->wall_atomtype[0]);
838 gmx_fio_do_int(fio,ir->wall_atomtype[1]);
839 gmx_fio_do_real(fio,ir->wall_density[0]);
840 gmx_fio_do_real(fio,ir->wall_density[1]);
841 gmx_fio_do_real(fio,ir->wall_ewald_zfac);
845 ir->wall_atomtype[0] = -1;
846 ir->wall_atomtype[1] = -1;
847 ir->wall_density[0] = 0;
848 ir->wall_density[1] = 0;
849 ir->wall_ewald_zfac = 3;
851 /* Cosine stuff for electric fields */
852 for(j=0; (j<DIM); j++) {
853 gmx_fio_do_int(fio,ir->ex[j].n);
854 gmx_fio_do_int(fio,ir->et[j].n);
856 snew(ir->ex[j].a, ir->ex[j].n);
857 snew(ir->ex[j].phi,ir->ex[j].n);
858 snew(ir->et[j].a, ir->et[j].n);
859 snew(ir->et[j].phi,ir->et[j].n);
861 bDum=gmx_fio_ndo_real(fio,ir->ex[j].a, ir->ex[j].n);
862 bDum=gmx_fio_ndo_real(fio,ir->ex[j].phi,ir->ex[j].n);
863 bDum=gmx_fio_ndo_real(fio,ir->et[j].a, ir->et[j].n);
864 bDum=gmx_fio_ndo_real(fio,ir->et[j].phi,ir->et[j].n);
868 if(file_version>=39){
869 gmx_fio_do_gmx_bool(fio,ir->bQMMM);
870 gmx_fio_do_int(fio,ir->QMMMscheme);
871 gmx_fio_do_real(fio,ir->scalefactor);
872 gmx_fio_do_int(fio,ir->opts.ngQM);
874 snew(ir->opts.QMmethod, ir->opts.ngQM);
875 snew(ir->opts.QMbasis, ir->opts.ngQM);
876 snew(ir->opts.QMcharge, ir->opts.ngQM);
877 snew(ir->opts.QMmult, ir->opts.ngQM);
878 snew(ir->opts.bSH, ir->opts.ngQM);
879 snew(ir->opts.CASorbitals, ir->opts.ngQM);
880 snew(ir->opts.CASelectrons,ir->opts.ngQM);
881 snew(ir->opts.SAon, ir->opts.ngQM);
882 snew(ir->opts.SAoff, ir->opts.ngQM);
883 snew(ir->opts.SAsteps, ir->opts.ngQM);
884 snew(ir->opts.bOPT, ir->opts.ngQM);
885 snew(ir->opts.bTS, ir->opts.ngQM);
887 if (ir->opts.ngQM > 0) {
888 bDum=gmx_fio_ndo_int(fio,ir->opts.QMmethod,ir->opts.ngQM);
889 bDum=gmx_fio_ndo_int(fio,ir->opts.QMbasis,ir->opts.ngQM);
890 bDum=gmx_fio_ndo_int(fio,ir->opts.QMcharge,ir->opts.ngQM);
891 bDum=gmx_fio_ndo_int(fio,ir->opts.QMmult,ir->opts.ngQM);
892 bDum=gmx_fio_ndo_gmx_bool(fio,ir->opts.bSH,ir->opts.ngQM);
893 bDum=gmx_fio_ndo_int(fio,ir->opts.CASorbitals,ir->opts.ngQM);
894 bDum=gmx_fio_ndo_int(fio,ir->opts.CASelectrons,ir->opts.ngQM);
895 bDum=gmx_fio_ndo_real(fio,ir->opts.SAon,ir->opts.ngQM);
896 bDum=gmx_fio_ndo_real(fio,ir->opts.SAoff,ir->opts.ngQM);
897 bDum=gmx_fio_ndo_int(fio,ir->opts.SAsteps,ir->opts.ngQM);
898 bDum=gmx_fio_ndo_gmx_bool(fio,ir->opts.bOPT,ir->opts.ngQM);
899 bDum=gmx_fio_ndo_gmx_bool(fio,ir->opts.bTS,ir->opts.ngQM);
901 /* end of QMMM stuff */
906 static void do_harm(t_fileio *fio, t_iparams *iparams,gmx_bool bRead)
908 gmx_fio_do_real(fio,iparams->harmonic.rA);
909 gmx_fio_do_real(fio,iparams->harmonic.krA);
910 gmx_fio_do_real(fio,iparams->harmonic.rB);
911 gmx_fio_do_real(fio,iparams->harmonic.krB);
914 void do_iparams(t_fileio *fio, t_functype ftype,t_iparams *iparams,
915 gmx_bool bRead, int file_version)
922 gmx_fio_set_comment(fio, interaction_function[ftype].name);
930 do_harm(fio, iparams,bRead);
931 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && bRead) {
932 /* Correct incorrect storage of parameters */
933 iparams->pdihs.phiB = iparams->pdihs.phiA;
934 iparams->pdihs.cpB = iparams->pdihs.cpA;
938 gmx_fio_do_real(fio,iparams->fene.bm);
939 gmx_fio_do_real(fio,iparams->fene.kb);
942 gmx_fio_do_real(fio,iparams->restraint.lowA);
943 gmx_fio_do_real(fio,iparams->restraint.up1A);
944 gmx_fio_do_real(fio,iparams->restraint.up2A);
945 gmx_fio_do_real(fio,iparams->restraint.kA);
946 gmx_fio_do_real(fio,iparams->restraint.lowB);
947 gmx_fio_do_real(fio,iparams->restraint.up1B);
948 gmx_fio_do_real(fio,iparams->restraint.up2B);
949 gmx_fio_do_real(fio,iparams->restraint.kB);
955 gmx_fio_do_real(fio,iparams->tab.kA);
956 gmx_fio_do_int(fio,iparams->tab.table);
957 gmx_fio_do_real(fio,iparams->tab.kB);
959 case F_CROSS_BOND_BONDS:
960 gmx_fio_do_real(fio,iparams->cross_bb.r1e);
961 gmx_fio_do_real(fio,iparams->cross_bb.r2e);
962 gmx_fio_do_real(fio,iparams->cross_bb.krr);
964 case F_CROSS_BOND_ANGLES:
965 gmx_fio_do_real(fio,iparams->cross_ba.r1e);
966 gmx_fio_do_real(fio,iparams->cross_ba.r2e);
967 gmx_fio_do_real(fio,iparams->cross_ba.r3e);
968 gmx_fio_do_real(fio,iparams->cross_ba.krt);
971 gmx_fio_do_real(fio,iparams->u_b.theta);
972 gmx_fio_do_real(fio,iparams->u_b.ktheta);
973 gmx_fio_do_real(fio,iparams->u_b.r13);
974 gmx_fio_do_real(fio,iparams->u_b.kUB);
976 case F_QUARTIC_ANGLES:
977 gmx_fio_do_real(fio,iparams->qangle.theta);
978 bDum=gmx_fio_ndo_real(fio,iparams->qangle.c,5);
981 gmx_fio_do_real(fio,iparams->bham.a);
982 gmx_fio_do_real(fio,iparams->bham.b);
983 gmx_fio_do_real(fio,iparams->bham.c);
986 gmx_fio_do_real(fio,iparams->morse.b0);
987 gmx_fio_do_real(fio,iparams->morse.cb);
988 gmx_fio_do_real(fio,iparams->morse.beta);
991 gmx_fio_do_real(fio,iparams->cubic.b0);
992 gmx_fio_do_real(fio,iparams->cubic.kb);
993 gmx_fio_do_real(fio,iparams->cubic.kcub);
998 gmx_fio_do_real(fio,iparams->polarize.alpha);
1001 if (file_version < 31)
1002 gmx_fatal(FARGS,"Old tpr files with water_polarization not supported. Make a new.");
1003 gmx_fio_do_real(fio,iparams->wpol.al_x);
1004 gmx_fio_do_real(fio,iparams->wpol.al_y);
1005 gmx_fio_do_real(fio,iparams->wpol.al_z);
1006 gmx_fio_do_real(fio,iparams->wpol.rOH);
1007 gmx_fio_do_real(fio,iparams->wpol.rHH);
1008 gmx_fio_do_real(fio,iparams->wpol.rOD);
1011 gmx_fio_do_real(fio,iparams->thole.a);
1012 gmx_fio_do_real(fio,iparams->thole.alpha1);
1013 gmx_fio_do_real(fio,iparams->thole.alpha2);
1014 gmx_fio_do_real(fio,iparams->thole.rfac);
1017 gmx_fio_do_real(fio,iparams->lj.c6);
1018 gmx_fio_do_real(fio,iparams->lj.c12);
1021 gmx_fio_do_real(fio,iparams->lj14.c6A);
1022 gmx_fio_do_real(fio,iparams->lj14.c12A);
1023 gmx_fio_do_real(fio,iparams->lj14.c6B);
1024 gmx_fio_do_real(fio,iparams->lj14.c12B);
1027 gmx_fio_do_real(fio,iparams->ljc14.fqq);
1028 gmx_fio_do_real(fio,iparams->ljc14.qi);
1029 gmx_fio_do_real(fio,iparams->ljc14.qj);
1030 gmx_fio_do_real(fio,iparams->ljc14.c6);
1031 gmx_fio_do_real(fio,iparams->ljc14.c12);
1033 case F_LJC_PAIRS_NB:
1034 gmx_fio_do_real(fio,iparams->ljcnb.qi);
1035 gmx_fio_do_real(fio,iparams->ljcnb.qj);
1036 gmx_fio_do_real(fio,iparams->ljcnb.c6);
1037 gmx_fio_do_real(fio,iparams->ljcnb.c12);
1043 gmx_fio_do_real(fio,iparams->pdihs.phiA);
1044 gmx_fio_do_real(fio,iparams->pdihs.cpA);
1045 if ((ftype == F_ANGRES || ftype == F_ANGRESZ) && file_version < 42) {
1046 /* Read the incorrectly stored multiplicity */
1047 gmx_fio_do_real(fio,iparams->harmonic.rB);
1048 gmx_fio_do_real(fio,iparams->harmonic.krB);
1049 iparams->pdihs.phiB = iparams->pdihs.phiA;
1050 iparams->pdihs.cpB = iparams->pdihs.cpA;
1052 gmx_fio_do_real(fio,iparams->pdihs.phiB);
1053 gmx_fio_do_real(fio,iparams->pdihs.cpB);
1054 gmx_fio_do_int(fio,iparams->pdihs.mult);
1058 gmx_fio_do_int(fio,iparams->disres.label);
1059 gmx_fio_do_int(fio,iparams->disres.type);
1060 gmx_fio_do_real(fio,iparams->disres.low);
1061 gmx_fio_do_real(fio,iparams->disres.up1);
1062 gmx_fio_do_real(fio,iparams->disres.up2);
1063 gmx_fio_do_real(fio,iparams->disres.kfac);
1066 gmx_fio_do_int(fio,iparams->orires.ex);
1067 gmx_fio_do_int(fio,iparams->orires.label);
1068 gmx_fio_do_int(fio,iparams->orires.power);
1069 gmx_fio_do_real(fio,iparams->orires.c);
1070 gmx_fio_do_real(fio,iparams->orires.obs);
1071 gmx_fio_do_real(fio,iparams->orires.kfac);
1074 gmx_fio_do_int(fio,iparams->dihres.power);
1075 gmx_fio_do_int(fio,iparams->dihres.label);
1076 gmx_fio_do_real(fio,iparams->dihres.phi);
1077 gmx_fio_do_real(fio,iparams->dihres.dphi);
1078 gmx_fio_do_real(fio,iparams->dihres.kfac);
1081 gmx_fio_do_rvec(fio,iparams->posres.pos0A);
1082 gmx_fio_do_rvec(fio,iparams->posres.fcA);
1083 if (bRead && file_version < 27) {
1084 copy_rvec(iparams->posres.pos0A,iparams->posres.pos0B);
1085 copy_rvec(iparams->posres.fcA,iparams->posres.fcB);
1087 gmx_fio_do_rvec(fio,iparams->posres.pos0B);
1088 gmx_fio_do_rvec(fio,iparams->posres.fcB);
1092 bDum=gmx_fio_ndo_real(fio,iparams->rbdihs.rbcA,NR_RBDIHS);
1093 if(file_version>=25)
1094 bDum=gmx_fio_ndo_real(fio,iparams->rbdihs.rbcB,NR_RBDIHS);
1097 /* Fourier dihedrals are internally represented
1098 * as Ryckaert-Bellemans since those are faster to compute.
1100 bDum=gmx_fio_ndo_real(fio,iparams->rbdihs.rbcA, NR_RBDIHS);
1101 bDum=gmx_fio_ndo_real(fio,iparams->rbdihs.rbcB, NR_RBDIHS);
1105 gmx_fio_do_real(fio,iparams->constr.dA);
1106 gmx_fio_do_real(fio,iparams->constr.dB);
1109 gmx_fio_do_real(fio,iparams->settle.doh);
1110 gmx_fio_do_real(fio,iparams->settle.dhh);
1113 gmx_fio_do_real(fio,iparams->vsite.a);
1118 gmx_fio_do_real(fio,iparams->vsite.a);
1119 gmx_fio_do_real(fio,iparams->vsite.b);
1124 gmx_fio_do_real(fio,iparams->vsite.a);
1125 gmx_fio_do_real(fio,iparams->vsite.b);
1126 gmx_fio_do_real(fio,iparams->vsite.c);
1129 gmx_fio_do_int(fio,iparams->vsiten.n);
1130 gmx_fio_do_real(fio,iparams->vsiten.a);
1135 /* We got rid of some parameters in version 68 */
1136 if(bRead && file_version<68)
1138 gmx_fio_do_real(fio,rdum);
1139 gmx_fio_do_real(fio,rdum);
1140 gmx_fio_do_real(fio,rdum);
1141 gmx_fio_do_real(fio,rdum);
1143 gmx_fio_do_real(fio,iparams->gb.sar);
1144 gmx_fio_do_real(fio,iparams->gb.st);
1145 gmx_fio_do_real(fio,iparams->gb.pi);
1146 gmx_fio_do_real(fio,iparams->gb.gbr);
1147 gmx_fio_do_real(fio,iparams->gb.bmlt);
1150 gmx_fio_do_int(fio,iparams->cmap.cmapA);
1151 gmx_fio_do_int(fio,iparams->cmap.cmapB);
1154 gmx_fatal(FARGS,"unknown function type %d (%s) in %s line %d",
1156 ftype,interaction_function[ftype].name,__FILE__,__LINE__);
1159 gmx_fio_unset_comment(fio);
1162 static void do_ilist(t_fileio *fio, t_ilist *ilist,gmx_bool bRead,int file_version,
1169 gmx_fio_set_comment(fio, interaction_function[ftype].name);
1171 if (file_version < 44) {
1172 for(i=0; i<MAXNODES; i++)
1173 gmx_fio_do_int(fio,idum);
1175 gmx_fio_do_int(fio,ilist->nr);
1177 snew(ilist->iatoms,ilist->nr);
1178 bDum=gmx_fio_ndo_int(fio,ilist->iatoms,ilist->nr);
1180 gmx_fio_unset_comment(fio);
1183 static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
1184 gmx_bool bRead, int file_version)
1190 gmx_fio_do_int(fio,ffparams->atnr);
1191 if (file_version < 57) {
1192 gmx_fio_do_int(fio,idum);
1194 gmx_fio_do_int(fio,ffparams->ntypes);
1196 fprintf(debug,"ffparams->atnr = %d, ntypes = %d\n",
1197 ffparams->atnr,ffparams->ntypes);
1199 snew(ffparams->functype,ffparams->ntypes);
1200 snew(ffparams->iparams,ffparams->ntypes);
1202 /* Read/write all the function types */
1203 bDum=gmx_fio_ndo_int(fio,ffparams->functype,ffparams->ntypes);
1205 pr_ivec(debug,0,"functype",ffparams->functype,ffparams->ntypes,TRUE);
1207 if (file_version >= 66) {
1208 gmx_fio_do_double(fio,ffparams->reppow);
1210 ffparams->reppow = 12.0;
1213 if (file_version >= 57) {
1214 gmx_fio_do_real(fio,ffparams->fudgeQQ);
1217 /* Check whether all these function types are supported by the code.
1218 * In practice the code is backwards compatible, which means that the
1219 * numbering may have to be altered from old numbering to new numbering
1221 for (i=0; (i<ffparams->ntypes); i++) {
1223 /* Loop over file versions */
1224 for (k=0; (k<NFTUPD); k++)
1225 /* Compare the read file_version to the update table */
1226 if ((file_version < ftupd[k].fvnr) &&
1227 (ffparams->functype[i] >= ftupd[k].ftype)) {
1228 ffparams->functype[i] += 1;
1230 fprintf(debug,"Incrementing function type %d to %d (due to %s)\n",
1231 i,ffparams->functype[i],
1232 interaction_function[ftupd[k].ftype].longname);
1237 do_iparams(fio, ffparams->functype[i],&ffparams->iparams[i],bRead,
1240 pr_iparams(debug,ffparams->functype[i],&ffparams->iparams[i]);
1244 static void do_ilists(t_fileio *fio, t_ilist *ilist,gmx_bool bRead,
1247 int i,j,renum[F_NRE];
1248 gmx_bool bDum=TRUE,bClear;
1251 for(j=0; (j<F_NRE); j++) {
1254 for (k=0; k<NFTUPD; k++)
1255 if ((file_version < ftupd[k].fvnr) && (j == ftupd[k].ftype))
1259 ilist[j].iatoms = NULL;
1261 do_ilist(fio, &ilist[j],bRead,file_version,j);
1264 if (bRead && gmx_debug_at)
1265 pr_ilist(debug,0,interaction_function[j].longname,
1266 functype,&ilist[j],TRUE);
1271 static void do_idef(t_fileio *fio, gmx_ffparams_t *ffparams,gmx_moltype_t *molt,
1272 gmx_bool bRead, int file_version)
1274 do_ffparams(fio, ffparams,bRead,file_version);
1276 if (file_version >= 54) {
1277 gmx_fio_do_real(fio,ffparams->fudgeQQ);
1280 do_ilists(fio, molt->ilist,bRead,file_version);
1283 static void do_block(t_fileio *fio, t_block *block,gmx_bool bRead,int file_version)
1285 int i,idum,dum_nra,*dum_a;
1288 if (file_version < 44)
1289 for(i=0; i<MAXNODES; i++)
1290 gmx_fio_do_int(fio,idum);
1291 gmx_fio_do_int(fio,block->nr);
1292 if (file_version < 51)
1293 gmx_fio_do_int(fio,dum_nra);
1295 block->nalloc_index = block->nr+1;
1296 snew(block->index,block->nalloc_index);
1298 bDum=gmx_fio_ndo_int(fio,block->index,block->nr+1);
1300 if (file_version < 51 && dum_nra > 0) {
1301 snew(dum_a,dum_nra);
1302 bDum=gmx_fio_ndo_int(fio,dum_a,dum_nra);
1307 static void do_blocka(t_fileio *fio, t_blocka *block,gmx_bool bRead,
1313 if (file_version < 44)
1314 for(i=0; i<MAXNODES; i++)
1315 gmx_fio_do_int(fio,idum);
1316 gmx_fio_do_int(fio,block->nr);
1317 gmx_fio_do_int(fio,block->nra);
1319 block->nalloc_index = block->nr+1;
1320 snew(block->index,block->nalloc_index);
1321 block->nalloc_a = block->nra;
1322 snew(block->a,block->nalloc_a);
1324 bDum=gmx_fio_ndo_int(fio,block->index,block->nr+1);
1325 bDum=gmx_fio_ndo_int(fio,block->a,block->nra);
1328 static void do_atom(t_fileio *fio, t_atom *atom,int ngrp,gmx_bool bRead,
1329 int file_version, gmx_groups_t *groups,int atnr)
1333 gmx_fio_do_real(fio,atom->m);
1334 gmx_fio_do_real(fio,atom->q);
1335 gmx_fio_do_real(fio,atom->mB);
1336 gmx_fio_do_real(fio,atom->qB);
1337 gmx_fio_do_ushort(fio, atom->type);
1338 gmx_fio_do_ushort(fio, atom->typeB);
1339 gmx_fio_do_int(fio,atom->ptype);
1340 gmx_fio_do_int(fio,atom->resind);
1341 if (file_version >= 52)
1342 gmx_fio_do_int(fio,atom->atomnumber);
1344 atom->atomnumber = NOTSET;
1345 if (file_version < 23)
1347 else if (file_version < 39)
1352 if (file_version < 57) {
1353 unsigned char uchar[egcNR];
1354 gmx_fio_ndo_uchar(fio,uchar,myngrp);
1355 for(i=myngrp; (i<ngrp); i++) {
1358 /* Copy the old data format to the groups struct */
1359 for(i=0; i<ngrp; i++) {
1360 groups->grpnr[i][atnr] = uchar[i];
1365 static void do_grps(t_fileio *fio, int ngrp,t_grps grps[],gmx_bool bRead,
1371 if (file_version < 23)
1373 else if (file_version < 39)
1378 for(j=0; (j<ngrp); j++) {
1380 gmx_fio_do_int(fio,grps[j].nr);
1382 snew(grps[j].nm_ind,grps[j].nr);
1383 bDum=gmx_fio_ndo_int(fio,grps[j].nm_ind,grps[j].nr);
1387 snew(grps[j].nm_ind,grps[j].nr);
1392 static void do_symstr(t_fileio *fio, char ***nm,gmx_bool bRead,t_symtab *symtab)
1397 gmx_fio_do_int(fio,ls);
1398 *nm = get_symtab_handle(symtab,ls);
1401 ls = lookup_symtab(symtab,*nm);
1402 gmx_fio_do_int(fio,ls);
1406 static void do_strstr(t_fileio *fio, int nstr,char ***nm,gmx_bool bRead,
1411 for (j=0; (j<nstr); j++)
1412 do_symstr(fio, &(nm[j]),bRead,symtab);
1415 static void do_resinfo(t_fileio *fio, int n,t_resinfo *ri,gmx_bool bRead,
1416 t_symtab *symtab, int file_version)
1420 for (j=0; (j<n); j++) {
1421 do_symstr(fio, &(ri[j].name),bRead,symtab);
1422 if (file_version >= 63) {
1423 gmx_fio_do_int(fio,ri[j].nr);
1424 gmx_fio_do_uchar(fio, ri[j].ic);
1432 static void do_atoms(t_fileio *fio, t_atoms *atoms,gmx_bool bRead,t_symtab *symtab,
1434 gmx_groups_t *groups)
1438 gmx_fio_do_int(fio,atoms->nr);
1439 gmx_fio_do_int(fio,atoms->nres);
1440 if (file_version < 57) {
1441 gmx_fio_do_int(fio,groups->ngrpname);
1442 for(i=0; i<egcNR; i++) {
1443 groups->ngrpnr[i] = atoms->nr;
1444 snew(groups->grpnr[i],groups->ngrpnr[i]);
1448 snew(atoms->atom,atoms->nr);
1449 snew(atoms->atomname,atoms->nr);
1450 snew(atoms->atomtype,atoms->nr);
1451 snew(atoms->atomtypeB,atoms->nr);
1452 snew(atoms->resinfo,atoms->nres);
1453 if (file_version < 57) {
1454 snew(groups->grpname,groups->ngrpname);
1456 atoms->pdbinfo = NULL;
1458 for(i=0; (i<atoms->nr); i++) {
1459 do_atom(fio, &atoms->atom[i],egcNR,bRead, file_version,groups,i);
1461 do_strstr(fio, atoms->nr,atoms->atomname,bRead,symtab);
1462 if (bRead && (file_version <= 20)) {
1463 for(i=0; i<atoms->nr; i++) {
1464 atoms->atomtype[i] = put_symtab(symtab,"?");
1465 atoms->atomtypeB[i] = put_symtab(symtab,"?");
1468 do_strstr(fio, atoms->nr,atoms->atomtype,bRead,symtab);
1469 do_strstr(fio, atoms->nr,atoms->atomtypeB,bRead,symtab);
1471 do_resinfo(fio, atoms->nres,atoms->resinfo,bRead,symtab,file_version);
1473 if (file_version < 57) {
1474 do_strstr(fio, groups->ngrpname,groups->grpname,bRead,symtab);
1476 do_grps(fio, egcNR,groups->grps,bRead,file_version);
1480 static void do_groups(t_fileio *fio, gmx_groups_t *groups,
1481 gmx_bool bRead,t_symtab *symtab,
1487 do_grps(fio, egcNR,groups->grps,bRead,file_version);
1488 gmx_fio_do_int(fio,groups->ngrpname);
1490 snew(groups->grpname,groups->ngrpname);
1492 do_strstr(fio, groups->ngrpname,groups->grpname,bRead,symtab);
1493 for(g=0; g<egcNR; g++) {
1494 gmx_fio_do_int(fio,groups->ngrpnr[g]);
1495 if (groups->ngrpnr[g] == 0) {
1497 groups->grpnr[g] = NULL;
1501 snew(groups->grpnr[g],groups->ngrpnr[g]);
1503 bDum=gmx_fio_ndo_uchar(fio, groups->grpnr[g],groups->ngrpnr[g]);
1508 static void do_atomtypes(t_fileio *fio, t_atomtypes *atomtypes,gmx_bool bRead,
1509 t_symtab *symtab,int file_version)
1512 gmx_bool bDum = TRUE;
1514 if (file_version > 25) {
1515 gmx_fio_do_int(fio,atomtypes->nr);
1518 snew(atomtypes->radius,j);
1519 snew(atomtypes->vol,j);
1520 snew(atomtypes->surftens,j);
1521 snew(atomtypes->atomnumber,j);
1522 snew(atomtypes->gb_radius,j);
1523 snew(atomtypes->S_hct,j);
1525 bDum=gmx_fio_ndo_real(fio,atomtypes->radius,j);
1526 bDum=gmx_fio_ndo_real(fio,atomtypes->vol,j);
1527 bDum=gmx_fio_ndo_real(fio,atomtypes->surftens,j);
1528 if(file_version >= 40)
1530 bDum=gmx_fio_ndo_int(fio,atomtypes->atomnumber,j);
1532 if(file_version >= 60)
1534 bDum=gmx_fio_ndo_real(fio,atomtypes->gb_radius,j);
1535 bDum=gmx_fio_ndo_real(fio,atomtypes->S_hct,j);
1538 /* File versions prior to 26 cannot do GBSA,
1539 * so they dont use this structure
1542 atomtypes->radius = NULL;
1543 atomtypes->vol = NULL;
1544 atomtypes->surftens = NULL;
1545 atomtypes->atomnumber = NULL;
1546 atomtypes->gb_radius = NULL;
1547 atomtypes->S_hct = NULL;
1551 static void do_symtab(t_fileio *fio, t_symtab *symtab,gmx_bool bRead)
1557 gmx_fio_do_int(fio,symtab->nr);
1560 snew(symtab->symbuf,1);
1561 symbuf = symtab->symbuf;
1562 symbuf->bufsize = nr;
1563 snew(symbuf->buf,nr);
1564 for (i=0; (i<nr); i++) {
1565 gmx_fio_do_string(fio,buf);
1566 symbuf->buf[i]=strdup(buf);
1570 symbuf = symtab->symbuf;
1571 while (symbuf!=NULL) {
1572 for (i=0; (i<symbuf->bufsize) && (i<nr); i++)
1573 gmx_fio_do_string(fio,symbuf->buf[i]);
1575 symbuf=symbuf->next;
1578 gmx_fatal(FARGS,"nr of symtab strings left: %d",nr);
1582 static void do_cmap(t_fileio *fio, gmx_cmap_t *cmap_grid, gmx_bool bRead)
1584 int i,j,ngrid,gs,nelem;
1586 gmx_fio_do_int(fio,cmap_grid->ngrid);
1587 gmx_fio_do_int(fio,cmap_grid->grid_spacing);
1589 ngrid = cmap_grid->ngrid;
1590 gs = cmap_grid->grid_spacing;
1595 snew(cmap_grid->cmapdata,ngrid);
1597 for(i=0;i<cmap_grid->ngrid;i++)
1599 snew(cmap_grid->cmapdata[i].cmap,4*nelem);
1603 for(i=0;i<cmap_grid->ngrid;i++)
1605 for(j=0;j<nelem;j++)
1607 gmx_fio_do_real(fio,cmap_grid->cmapdata[i].cmap[j*4]);
1608 gmx_fio_do_real(fio,cmap_grid->cmapdata[i].cmap[j*4+1]);
1609 gmx_fio_do_real(fio,cmap_grid->cmapdata[i].cmap[j*4+2]);
1610 gmx_fio_do_real(fio,cmap_grid->cmapdata[i].cmap[j*4+3]);
1616 void tpx_make_chain_identifiers(t_atoms *atoms,t_block *mols)
1622 /* We always assign a new chain number, but save the chain id characters
1623 * for larger molecules.
1625 #define CHAIN_MIN_ATOMS 15
1629 for(m=0; m<mols->nr; m++)
1632 a1=mols->index[m+1];
1633 if ((a1-a0 >= CHAIN_MIN_ATOMS) && (chainid <= 'Z'))
1642 for(a=a0; a<a1; a++)
1644 atoms->resinfo[atoms->atom[a].resind].chainnum = chainnum;
1645 atoms->resinfo[atoms->atom[a].resind].chainid = c;
1650 /* Blank out the chain id if there was only one chain */
1653 for(r=0; r<atoms->nres; r++)
1655 atoms->resinfo[r].chainid = ' ';
1660 static void do_moltype(t_fileio *fio, gmx_moltype_t *molt,gmx_bool bRead,
1661 t_symtab *symtab, int file_version,
1662 gmx_groups_t *groups)
1666 if (file_version >= 57) {
1667 do_symstr(fio, &(molt->name),bRead,symtab);
1670 do_atoms(fio, &molt->atoms, bRead, symtab, file_version, groups);
1672 if (bRead && gmx_debug_at) {
1673 pr_atoms(debug,0,"atoms",&molt->atoms,TRUE);
1676 if (file_version >= 57) {
1677 do_ilists(fio, molt->ilist,bRead,file_version);
1679 do_block(fio, &molt->cgs,bRead,file_version);
1680 if (bRead && gmx_debug_at) {
1681 pr_block(debug,0,"cgs",&molt->cgs,TRUE);
1685 /* This used to be in the atoms struct */
1686 do_blocka(fio, &molt->excls, bRead, file_version);
1689 static void do_molblock(t_fileio *fio, gmx_molblock_t *molb,gmx_bool bRead,
1694 gmx_fio_do_int(fio,molb->type);
1695 gmx_fio_do_int(fio,molb->nmol);
1696 gmx_fio_do_int(fio,molb->natoms_mol);
1697 /* Position restraint coordinates */
1698 gmx_fio_do_int(fio,molb->nposres_xA);
1699 if (molb->nposres_xA > 0) {
1701 snew(molb->posres_xA,molb->nposres_xA);
1703 gmx_fio_ndo_rvec(fio,molb->posres_xA,molb->nposres_xA);
1705 gmx_fio_do_int(fio,molb->nposres_xB);
1706 if (molb->nposres_xB > 0) {
1708 snew(molb->posres_xB,molb->nposres_xB);
1710 gmx_fio_ndo_rvec(fio,molb->posres_xB,molb->nposres_xB);
1715 static t_block mtop_mols(gmx_mtop_t *mtop)
1721 for(mb=0; mb<mtop->nmolblock; mb++) {
1722 mols.nr += mtop->molblock[mb].nmol;
1724 mols.nalloc_index = mols.nr + 1;
1725 snew(mols.index,mols.nalloc_index);
1730 for(mb=0; mb<mtop->nmolblock; mb++) {
1731 for(mol=0; mol<mtop->molblock[mb].nmol; mol++) {
1732 a += mtop->molblock[mb].natoms_mol;
1741 static void add_posres_molblock(gmx_mtop_t *mtop)
1746 gmx_molblock_t *molb;
1749 il = &mtop->moltype[0].ilist[F_POSRES];
1755 for(i=0; i<il->nr; i+=2) {
1756 ip = &mtop->ffparams.iparams[il->iatoms[i]];
1757 am = max(am,il->iatoms[i+1]);
1758 if (ip->posres.pos0B[XX] != ip->posres.pos0A[XX] ||
1759 ip->posres.pos0B[YY] != ip->posres.pos0A[YY] ||
1760 ip->posres.pos0B[ZZ] != ip->posres.pos0A[ZZ]) {
1764 /* Make the posres coordinate block end at a molecule end */
1766 while(am >= mtop->mols.index[mol+1]) {
1769 molb = &mtop->molblock[0];
1770 molb->nposres_xA = mtop->mols.index[mol+1];
1771 snew(molb->posres_xA,molb->nposres_xA);
1773 molb->nposres_xB = molb->nposres_xA;
1774 snew(molb->posres_xB,molb->nposres_xB);
1776 molb->nposres_xB = 0;
1778 for(i=0; i<il->nr; i+=2) {
1779 ip = &mtop->ffparams.iparams[il->iatoms[i]];
1780 a = il->iatoms[i+1];
1781 molb->posres_xA[a][XX] = ip->posres.pos0A[XX];
1782 molb->posres_xA[a][YY] = ip->posres.pos0A[YY];
1783 molb->posres_xA[a][ZZ] = ip->posres.pos0A[ZZ];
1785 molb->posres_xB[a][XX] = ip->posres.pos0B[XX];
1786 molb->posres_xB[a][YY] = ip->posres.pos0B[YY];
1787 molb->posres_xB[a][ZZ] = ip->posres.pos0B[ZZ];
1792 static void set_disres_npair(gmx_mtop_t *mtop)
1799 ip = mtop->ffparams.iparams;
1801 for(mt=0; mt<mtop->nmoltype; mt++) {
1802 il = &mtop->moltype[mt].ilist[F_DISRES];
1806 for(i=0; i<il->nr; i+=3) {
1808 if (i+3 == il->nr || ip[a[i]].disres.label != ip[a[i+3]].disres.label) {
1809 ip[a[i]].disres.npair = npair;
1817 static void do_mtop(t_fileio *fio, gmx_mtop_t *mtop,gmx_bool bRead,
1825 do_symtab(fio, &(mtop->symtab),bRead);
1827 pr_symtab(debug,0,"symtab",&mtop->symtab);
1829 do_symstr(fio, &(mtop->name),bRead,&(mtop->symtab));
1831 if (file_version >= 57) {
1832 do_ffparams(fio, &mtop->ffparams,bRead,file_version);
1834 gmx_fio_do_int(fio,mtop->nmoltype);
1839 snew(mtop->moltype,mtop->nmoltype);
1840 if (file_version < 57) {
1841 mtop->moltype[0].name = mtop->name;
1844 for(mt=0; mt<mtop->nmoltype; mt++) {
1845 do_moltype(fio, &mtop->moltype[mt],bRead,&mtop->symtab,file_version,
1849 if (file_version >= 57) {
1850 gmx_fio_do_int(fio,mtop->nmolblock);
1852 mtop->nmolblock = 1;
1855 snew(mtop->molblock,mtop->nmolblock);
1857 if (file_version >= 57) {
1858 for(mb=0; mb<mtop->nmolblock; mb++) {
1859 do_molblock(fio, &mtop->molblock[mb],bRead,file_version);
1861 gmx_fio_do_int(fio,mtop->natoms);
1863 mtop->molblock[0].type = 0;
1864 mtop->molblock[0].nmol = 1;
1865 mtop->molblock[0].natoms_mol = mtop->moltype[0].atoms.nr;
1866 mtop->molblock[0].nposres_xA = 0;
1867 mtop->molblock[0].nposres_xB = 0;
1870 do_atomtypes (fio, &(mtop->atomtypes),bRead,&(mtop->symtab), file_version);
1872 pr_atomtypes(debug,0,"atomtypes",&mtop->atomtypes,TRUE);
1874 if (file_version < 57) {
1875 /* Debug statements are inside do_idef */
1876 do_idef (fio, &mtop->ffparams,&mtop->moltype[0],bRead,file_version);
1877 mtop->natoms = mtop->moltype[0].atoms.nr;
1880 if(file_version >= 65)
1882 do_cmap(fio, &mtop->ffparams.cmap_grid,bRead);
1886 mtop->ffparams.cmap_grid.ngrid = 0;
1887 mtop->ffparams.cmap_grid.grid_spacing = 0.1;
1888 mtop->ffparams.cmap_grid.cmapdata = NULL;
1891 if (file_version >= 57) {
1892 do_groups(fio, &mtop->groups,bRead,&(mtop->symtab),file_version);
1895 if (file_version < 57) {
1896 do_block(fio, &mtop->moltype[0].cgs,bRead,file_version);
1897 if (bRead && gmx_debug_at) {
1898 pr_block(debug,0,"cgs",&mtop->moltype[0].cgs,TRUE);
1900 do_block(fio, &mtop->mols,bRead,file_version);
1901 /* Add the posres coordinates to the molblock */
1902 add_posres_molblock(mtop);
1905 if (file_version >= 57) {
1906 mtop->mols = mtop_mols(mtop);
1909 pr_block(debug,0,"mols",&mtop->mols,TRUE);
1913 if (file_version < 51) {
1914 /* Here used to be the shake blocks */
1915 do_blocka(fio, &dumb,bRead,file_version);
1923 close_symtab(&(mtop->symtab));
1927 /* If TopOnlyOK is TRUE then we can read even future versions
1928 * of tpx files, provided the file_generation hasn't changed.
1929 * If it is FALSE, we need the inputrecord too, and bail out
1930 * if the file is newer than the program.
1932 * The version and generation if the topology (see top of this file)
1933 * are returned in the two last arguments.
1935 * If possible, we will read the inputrec even when TopOnlyOK is TRUE.
1937 static void do_tpxheader(t_fileio *fio,gmx_bool bRead,t_tpxheader *tpx,
1938 gmx_bool TopOnlyOK, int *file_version,
1939 int *file_generation)
1948 gmx_fio_checktype(fio);
1949 gmx_fio_setdebug(fio,bDebugMode());
1951 /* NEW! XDR tpb file */
1952 precision = sizeof(real);
1954 gmx_fio_do_string(fio,buf);
1955 if (strncmp(buf,"VERSION",7))
1956 gmx_fatal(FARGS,"Can not read file %s,\n"
1957 " this file is from a Gromacs version which is older than 2.0\n"
1958 " Make a new one with grompp or use a gro or pdb file, if possible",
1959 gmx_fio_getname(fio));
1960 gmx_fio_do_int(fio,precision);
1961 bDouble = (precision == sizeof(double));
1962 if ((precision != sizeof(float)) && !bDouble)
1963 gmx_fatal(FARGS,"Unknown precision in file %s: real is %d bytes "
1964 "instead of %d or %d",
1965 gmx_fio_getname(fio),precision,sizeof(float),sizeof(double));
1966 gmx_fio_setprecision(fio,bDouble);
1967 fprintf(stderr,"Reading file %s, %s (%s precision)\n",
1968 gmx_fio_getname(fio),buf,bDouble ? "double" : "single");
1971 gmx_fio_write_string(fio,GromacsVersion());
1972 bDouble = (precision == sizeof(double));
1973 gmx_fio_setprecision(fio,bDouble);
1974 gmx_fio_do_int(fio,precision);
1976 fgen = tpx_generation;
1979 /* Check versions! */
1980 gmx_fio_do_int(fio,fver);
1983 gmx_fio_do_int(fio,fgen);
1987 if(file_version!=NULL)
1988 *file_version = fver;
1989 if(file_generation!=NULL)
1990 *file_generation = fgen;
1993 if ((fver <= tpx_incompatible_version) ||
1994 ((fver > tpx_version) && !TopOnlyOK) ||
1995 (fgen > tpx_generation))
1996 gmx_fatal(FARGS,"reading tpx file (%s) version %d with version %d program",
1997 gmx_fio_getname(fio),fver,tpx_version);
1999 do_section(fio,eitemHEADER,bRead);
2000 gmx_fio_do_int(fio,tpx->natoms);
2002 gmx_fio_do_int(fio,tpx->ngtc);
2006 gmx_fio_do_int(fio,idum);
2007 gmx_fio_do_real(fio,rdum);
2009 gmx_fio_do_real(fio,tpx->lambda);
2010 gmx_fio_do_int(fio,tpx->bIr);
2011 gmx_fio_do_int(fio,tpx->bTop);
2012 gmx_fio_do_int(fio,tpx->bX);
2013 gmx_fio_do_int(fio,tpx->bV);
2014 gmx_fio_do_int(fio,tpx->bF);
2015 gmx_fio_do_int(fio,tpx->bBox);
2017 if((fgen > tpx_generation)) {
2018 /* This can only happen if TopOnlyOK=TRUE */
2023 static int do_tpx(t_fileio *fio, gmx_bool bRead,
2024 t_inputrec *ir,t_state *state,rvec *f,gmx_mtop_t *mtop,
2025 gmx_bool bXVallocated)
2030 gmx_bool TopOnlyOK,bDum=TRUE;
2031 int file_version,file_generation;
2035 gmx_bool bPeriodicMols;
2038 tpx.natoms = state->natoms;
2039 tpx.ngtc = state->ngtc;
2040 tpx.lambda = state->lambda;
2041 tpx.bIr = (ir != NULL);
2042 tpx.bTop = (mtop != NULL);
2043 tpx.bX = (state->x != NULL);
2044 tpx.bV = (state->v != NULL);
2045 tpx.bF = (f != NULL);
2049 TopOnlyOK = (ir==NULL);
2051 do_tpxheader(fio,bRead,&tpx,TopOnlyOK,&file_version,&file_generation);
2055 state->lambda = tpx.lambda;
2056 /* The init_state calls initialize the Nose-Hoover xi integrals to zero */
2060 init_state(state,0,tpx.ngtc,0,0); /* nose-hoover chains */ /* eventually, need to add nnhpres here? */
2061 state->natoms = tpx.natoms;
2062 state->nalloc = tpx.natoms;
2066 init_state(state,tpx.natoms,tpx.ngtc,0,0); /* nose-hoover chains */
2070 #define do_test(fio,b,p) if (bRead && (p!=NULL) && !b) gmx_fatal(FARGS,"No %s in %s",#p,gmx_fio_getname(fio))
2072 do_test(fio,tpx.bBox,state->box);
2073 do_section(fio,eitemBOX,bRead);
2075 gmx_fio_ndo_rvec(fio,state->box,DIM);
2076 if (file_version >= 51) {
2077 gmx_fio_ndo_rvec(fio,state->box_rel,DIM);
2079 /* We initialize box_rel after reading the inputrec */
2080 clear_mat(state->box_rel);
2082 if (file_version >= 28) {
2083 gmx_fio_ndo_rvec(fio,state->boxv,DIM);
2084 if (file_version < 56) {
2086 gmx_fio_ndo_rvec(fio,mdum,DIM);
2091 if (state->ngtc > 0 && file_version >= 28) {
2093 /*ndo_double(state->nosehoover_xi,state->ngtc,bDum);*/
2094 /*ndo_double(state->nosehoover_vxi,state->ngtc,bDum);*/
2095 /*ndo_double(state->therm_integral,state->ngtc,bDum);*/
2096 snew(dumv,state->ngtc);
2097 if (file_version < 69) {
2098 bDum=gmx_fio_ndo_real(fio,dumv,state->ngtc);
2100 /* These used to be the Berendsen tcoupl_lambda's */
2101 bDum=gmx_fio_ndo_real(fio,dumv,state->ngtc);
2105 /* Prior to tpx version 26, the inputrec was here.
2106 * I moved it to enable partial forward-compatibility
2107 * for analysis/viewer programs.
2109 if(file_version<26) {
2110 do_test(fio,tpx.bIr,ir);
2111 do_section(fio,eitemIR,bRead);
2114 do_inputrec(fio, ir,bRead,file_version,
2115 mtop ? &mtop->ffparams.fudgeQQ : NULL);
2117 pr_inputrec(debug,0,"inputrec",ir,FALSE);
2120 do_inputrec(fio, &dum_ir,bRead,file_version,
2121 mtop ? &mtop->ffparams.fudgeQQ :NULL);
2123 pr_inputrec(debug,0,"inputrec",&dum_ir,FALSE);
2124 done_inputrec(&dum_ir);
2130 do_test(fio,tpx.bTop,mtop);
2131 do_section(fio,eitemTOP,bRead);
2134 do_mtop(fio,mtop,bRead, file_version);
2136 do_mtop(fio,&dum_top,bRead,file_version);
2137 done_mtop(&dum_top,TRUE);
2140 do_test(fio,tpx.bX,state->x);
2141 do_section(fio,eitemX,bRead);
2144 state->flags |= (1<<estX);
2146 gmx_fio_ndo_rvec(fio,state->x,state->natoms);
2149 do_test(fio,tpx.bV,state->v);
2150 do_section(fio,eitemV,bRead);
2153 state->flags |= (1<<estV);
2155 gmx_fio_ndo_rvec(fio,state->v,state->natoms);
2158 do_test(fio,tpx.bF,f);
2159 do_section(fio,eitemF,bRead);
2160 if (tpx.bF) gmx_fio_ndo_rvec(fio,f,state->natoms);
2162 /* Starting with tpx version 26, we have the inputrec
2163 * at the end of the file, so we can ignore it
2164 * if the file is never than the software (but still the
2165 * same generation - see comments at the top of this file.
2170 bPeriodicMols = FALSE;
2171 if (file_version >= 26) {
2172 do_test(fio,tpx.bIr,ir);
2173 do_section(fio,eitemIR,bRead);
2175 if (file_version >= 53) {
2176 /* Removed the pbc info from do_inputrec, since we always want it */
2179 bPeriodicMols = ir->bPeriodicMols;
2181 gmx_fio_do_int(fio,ePBC);
2182 gmx_fio_do_gmx_bool(fio,bPeriodicMols);
2184 if (file_generation <= tpx_generation && ir) {
2185 do_inputrec(fio, ir,bRead,file_version,mtop ? &mtop->ffparams.fudgeQQ : NULL);
2187 pr_inputrec(debug,0,"inputrec",ir,FALSE);
2188 if (file_version < 51)
2189 set_box_rel(ir,state);
2190 if (file_version < 53) {
2192 bPeriodicMols = ir->bPeriodicMols;
2195 if (bRead && ir && file_version >= 53) {
2196 /* We need to do this after do_inputrec, since that initializes ir */
2198 ir->bPeriodicMols = bPeriodicMols;
2207 if (state->ngtc == 0)
2209 /* Reading old version without tcoupl state data: set it */
2210 init_gtc_state(state,ir->opts.ngtc,0,ir->opts.nhchainlength);
2212 if (tpx.bTop && mtop)
2214 if (file_version < 57)
2216 if (mtop->moltype[0].ilist[F_DISRES].nr > 0)
2218 ir->eDisre = edrSimple;
2222 ir->eDisre = edrNone;
2225 set_disres_npair(mtop);
2229 if (tpx.bTop && mtop)
2231 gmx_mtop_finalize(mtop);
2234 if (file_version >= 57)
2238 env = getenv("GMX_NOCHARGEGROUPS");
2241 sscanf(env,"%d",&ienv);
2242 fprintf(stderr,"\nFound env.var. GMX_NOCHARGEGROUPS = %d\n",
2247 "Will make single atomic charge groups in non-solvent%s\n",
2248 ienv > 1 ? " and solvent" : "");
2249 gmx_mtop_make_atomic_charge_groups(mtop,ienv==1);
2251 fprintf(stderr,"\n");
2259 /************************************************************
2261 * The following routines are the exported ones
2263 ************************************************************/
2265 t_fileio *open_tpx(const char *fn,const char *mode)
2267 return gmx_fio_open(fn,mode);
2270 void close_tpx(t_fileio *fio)
2275 void read_tpxheader(const char *fn, t_tpxheader *tpx, gmx_bool TopOnlyOK,
2276 int *file_version, int *file_generation)
2280 fio = open_tpx(fn,"r");
2281 do_tpxheader(fio,TRUE,tpx,TopOnlyOK,file_version,file_generation);
2285 void write_tpx_state(const char *fn,
2286 t_inputrec *ir,t_state *state,gmx_mtop_t *mtop)
2290 fio = open_tpx(fn,"w");
2291 do_tpx(fio,FALSE,ir,state,NULL,mtop,FALSE);
2295 void read_tpx_state(const char *fn,
2296 t_inputrec *ir,t_state *state,rvec *f,gmx_mtop_t *mtop)
2300 fio = open_tpx(fn,"r");
2301 do_tpx(fio,TRUE,ir,state,f,mtop,FALSE);
2305 int read_tpx(const char *fn,
2306 t_inputrec *ir, matrix box,int *natoms,
2307 rvec *x,rvec *v,rvec *f,gmx_mtop_t *mtop)
2315 fio = open_tpx(fn,"r");
2316 ePBC = do_tpx(fio,TRUE,ir,&state,f,mtop,TRUE);
2318 *natoms = state.natoms;
2320 copy_mat(state.box,box);
2328 int read_tpx_top(const char *fn,
2329 t_inputrec *ir, matrix box,int *natoms,
2330 rvec *x,rvec *v,rvec *f,t_topology *top)
2336 ePBC = read_tpx(fn,ir,box,natoms,x,v,f,&mtop);
2338 *top = gmx_mtop_t_to_t_topology(&mtop);
2343 gmx_bool fn2bTPX(const char *file)
2345 switch (fn2ftp(file)) {
2355 gmx_bool read_tps_conf(const char *infile,char *title,t_topology *top,int *ePBC,
2356 rvec **x,rvec **v,matrix box,gmx_bool bMass)
2359 int natoms,i,version,generation;
2360 gmx_bool bTop,bXNULL;
2362 t_topology *topconv;
2365 bTop = fn2bTPX(infile);
2368 read_tpxheader(infile,&header,TRUE,&version,&generation);
2370 snew(*x,header.natoms);
2372 snew(*v,header.natoms);
2374 *ePBC = read_tpx(infile,NULL,box,&natoms,
2375 (x==NULL) ? NULL : *x,(v==NULL) ? NULL : *v,NULL,mtop);
2376 *top = gmx_mtop_t_to_t_topology(mtop);
2378 strcpy(title,*top->name);
2379 tpx_make_chain_identifiers(&top->atoms,&top->mols);
2382 get_stx_coordnum(infile,&natoms);
2383 init_t_atoms(&top->atoms,natoms,FALSE);
2384 bXNULL = (x == NULL);
2388 read_stx_conf(infile,title,&top->atoms,*x,(v==NULL) ? NULL : *v,ePBC,box);
2394 aps = gmx_atomprop_init();
2395 for(i=0; (i<natoms); i++)
2396 if (!gmx_atomprop_query(aps,epropMass,
2397 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
2398 *top->atoms.atomname[i],
2399 &(top->atoms.atom[i].m))) {
2401 fprintf(debug,"Can not find mass for atom %s %d %s, setting to 1\n",
2402 *top->atoms.resinfo[top->atoms.atom[i].resind].name,
2403 top->atoms.resinfo[top->atoms.atom[i].resind].nr,
2404 *top->atoms.atomname[i]);
2406 gmx_atomprop_destroy(aps);
2408 top->idef.ntypes=-1;