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
= 71;
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
= 22;
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 { 41, F_LJC_PAIRS_NB
},
145 { 32, F_COUL_RECIP
},
147 { 30, F_POLARIZATION
},
149 { 22, F_DISRESVIOL
},
153 { 26, F_DIHRESVIOL
},
158 { 46, F_ECONSERVED
},
163 #define NFTUPD asize(ftupd)
165 /* Needed for backward compatibility */
168 static void _do_section(t_fileio
*fio
,int key
,bool bRead
,const char *src
,
174 if (gmx_fio_getftp(fio
) == efTPA
) {
176 gmx_fio_write_string(fio
,itemstr
[key
]);
177 bDbg
= gmx_fio_getdebug(fio
);
178 gmx_fio_setdebug(fio
,FALSE
);
179 gmx_fio_write_string(fio
,comment_str
[key
]);
180 gmx_fio_setdebug(fio
,bDbg
);
183 if (gmx_fio_getdebug(fio
))
184 fprintf(stderr
,"Looking for section %s (%s, %d)",
185 itemstr
[key
],src
,line
);
188 gmx_fio_do_string(fio
,buf
);
189 } while ((strcasecmp(buf
,itemstr
[key
]) != 0));
191 if (strcasecmp(buf
,itemstr
[key
]) != 0)
192 gmx_fatal(FARGS
,"\nCould not find section heading %s",itemstr
[key
]);
193 else if (gmx_fio_getdebug(fio
))
194 fprintf(stderr
," and found it\n");
199 #define do_section(fio,key,bRead) _do_section(fio,key,bRead,__FILE__,__LINE__)
201 /**************************************************************
203 * Now the higer level routines that do io of the structures and arrays
205 **************************************************************/
206 static void do_pullgrp(t_fileio
*fio
, t_pullgrp
*pgrp
, bool bRead
,
212 gmx_fio_do_int(fio
,pgrp
->nat
);
214 snew(pgrp
->ind
,pgrp
->nat
);
215 bDum
=gmx_fio_ndo_int(fio
,pgrp
->ind
,pgrp
->nat
);
216 gmx_fio_do_int(fio
,pgrp
->nweight
);
218 snew(pgrp
->weight
,pgrp
->nweight
);
219 bDum
=gmx_fio_ndo_real(fio
,pgrp
->weight
,pgrp
->nweight
);
220 gmx_fio_do_int(fio
,pgrp
->pbcatom
);
221 gmx_fio_do_rvec(fio
,pgrp
->vec
);
222 gmx_fio_do_rvec(fio
,pgrp
->init
);
223 gmx_fio_do_real(fio
,pgrp
->rate
);
224 gmx_fio_do_real(fio
,pgrp
->k
);
225 if (file_version
>= 56) {
226 gmx_fio_do_real(fio
,pgrp
->kB
);
232 static void do_pull(t_fileio
*fio
, t_pull
*pull
,bool bRead
, int file_version
)
236 gmx_fio_do_int(fio
,pull
->ngrp
);
237 gmx_fio_do_int(fio
,pull
->eGeom
);
238 gmx_fio_do_ivec(fio
,pull
->dim
);
239 gmx_fio_do_real(fio
,pull
->cyl_r1
);
240 gmx_fio_do_real(fio
,pull
->cyl_r0
);
241 gmx_fio_do_real(fio
,pull
->constr_tol
);
242 gmx_fio_do_int(fio
,pull
->nstxout
);
243 gmx_fio_do_int(fio
,pull
->nstfout
);
245 snew(pull
->grp
,pull
->ngrp
+1);
246 for(g
=0; g
<pull
->ngrp
+1; g
++)
247 do_pullgrp(fio
,&pull
->grp
[g
],bRead
,file_version
);
250 static void do_inputrec(t_fileio
*fio
, t_inputrec
*ir
,bool bRead
,
251 int file_version
, real
*fudgeQQ
)
253 int i
,j
,k
,*tmp
,idum
=0;
258 real zerotemptime
,finish_t
,init_temp
,finish_temp
;
260 if (file_version
!= tpx_version
)
262 /* Give a warning about features that are not accessible */
263 fprintf(stderr
,"Note: tpx file_version %d, software version %d\n",
264 file_version
,tpx_version
);
272 if (file_version
== 0)
277 /* Basic inputrec stuff */
278 gmx_fio_do_int(fio
,ir
->eI
);
279 if (file_version
>= 62) {
280 gmx_fio_do_gmx_large_int(fio
, ir
->nsteps
);
282 gmx_fio_do_int(fio
,idum
);
285 if(file_version
> 25) {
286 if (file_version
>= 62) {
287 gmx_fio_do_gmx_large_int(fio
, ir
->init_step
);
289 gmx_fio_do_int(fio
,idum
);
290 ir
->init_step
= idum
;
296 if(file_version
>= 58)
297 gmx_fio_do_int(fio
,ir
->simulation_part
);
299 ir
->simulation_part
=1;
301 if (file_version
>= 67) {
302 gmx_fio_do_int(fio
,ir
->nstcalcenergy
);
304 ir
->nstcalcenergy
= 1;
306 if (file_version
< 53) {
307 /* The pbc info has been moved out of do_inputrec,
308 * since we always want it, also without reading the inputrec.
310 gmx_fio_do_int(fio
,ir
->ePBC
);
311 if ((file_version
<= 15) && (ir
->ePBC
== 2))
313 if (file_version
>= 45) {
314 gmx_fio_do_int(fio
,ir
->bPeriodicMols
);
318 ir
->bPeriodicMols
= TRUE
;
320 ir
->bPeriodicMols
= FALSE
;
324 gmx_fio_do_int(fio
,ir
->ns_type
);
325 gmx_fio_do_int(fio
,ir
->nstlist
);
326 gmx_fio_do_int(fio
,ir
->ndelta
);
327 if (file_version
< 41) {
328 gmx_fio_do_int(fio
,idum
);
329 gmx_fio_do_int(fio
,idum
);
331 if (file_version
>= 45)
332 gmx_fio_do_real(fio
,ir
->rtpi
);
335 gmx_fio_do_int(fio
,ir
->nstcomm
);
336 if (file_version
> 34)
337 gmx_fio_do_int(fio
,ir
->comm_mode
);
338 else if (ir
->nstcomm
< 0)
339 ir
->comm_mode
= ecmANGULAR
;
341 ir
->comm_mode
= ecmLINEAR
;
342 ir
->nstcomm
= abs(ir
->nstcomm
);
344 if(file_version
> 25)
345 gmx_fio_do_int(fio
,ir
->nstcheckpoint
);
349 gmx_fio_do_int(fio
,ir
->nstcgsteep
);
352 gmx_fio_do_int(fio
,ir
->nbfgscorr
);
356 gmx_fio_do_int(fio
,ir
->nstlog
);
357 gmx_fio_do_int(fio
,ir
->nstxout
);
358 gmx_fio_do_int(fio
,ir
->nstvout
);
359 gmx_fio_do_int(fio
,ir
->nstfout
);
360 gmx_fio_do_int(fio
,ir
->nstenergy
);
361 gmx_fio_do_int(fio
,ir
->nstxtcout
);
362 if (file_version
>= 59) {
363 gmx_fio_do_double(fio
,ir
->init_t
);
364 gmx_fio_do_double(fio
,ir
->delta_t
);
366 gmx_fio_do_real(fio
,rdum
);
368 gmx_fio_do_real(fio
,rdum
);
371 gmx_fio_do_real(fio
,ir
->xtcprec
);
372 if (file_version
< 19) {
373 gmx_fio_do_int(fio
,idum
);
374 gmx_fio_do_int(fio
,idum
);
376 if(file_version
< 18)
377 gmx_fio_do_int(fio
,idum
);
378 gmx_fio_do_real(fio
,ir
->rlist
);
379 if (file_version
>= 67) {
380 gmx_fio_do_real(fio
,ir
->rlistlong
);
382 gmx_fio_do_int(fio
,ir
->coulombtype
);
383 if (file_version
< 32 && ir
->coulombtype
== eelRF
)
384 ir
->coulombtype
= eelRF_NEC
;
385 gmx_fio_do_real(fio
,ir
->rcoulomb_switch
);
386 gmx_fio_do_real(fio
,ir
->rcoulomb
);
387 gmx_fio_do_int(fio
,ir
->vdwtype
);
388 gmx_fio_do_real(fio
,ir
->rvdw_switch
);
389 gmx_fio_do_real(fio
,ir
->rvdw
);
390 if (file_version
< 67) {
391 ir
->rlistlong
= max_cutoff(ir
->rlist
,max_cutoff(ir
->rvdw
,ir
->rcoulomb
));
393 gmx_fio_do_int(fio
,ir
->eDispCorr
);
394 gmx_fio_do_real(fio
,ir
->epsilon_r
);
395 if (file_version
>= 37) {
396 gmx_fio_do_real(fio
,ir
->epsilon_rf
);
398 if (EEL_RF(ir
->coulombtype
)) {
399 ir
->epsilon_rf
= ir
->epsilon_r
;
402 ir
->epsilon_rf
= 1.0;
405 if (file_version
>= 29)
406 gmx_fio_do_real(fio
,ir
->tabext
);
410 if(file_version
> 25) {
411 gmx_fio_do_int(fio
,ir
->gb_algorithm
);
412 gmx_fio_do_int(fio
,ir
->nstgbradii
);
413 gmx_fio_do_real(fio
,ir
->rgbradii
);
414 gmx_fio_do_real(fio
,ir
->gb_saltconc
);
415 gmx_fio_do_int(fio
,ir
->implicit_solvent
);
417 ir
->gb_algorithm
=egbSTILL
;
421 ir
->implicit_solvent
=eisNO
;
425 gmx_fio_do_real(fio
,ir
->gb_epsilon_solvent
);
426 gmx_fio_do_real(fio
,ir
->gb_obc_alpha
);
427 gmx_fio_do_real(fio
,ir
->gb_obc_beta
);
428 gmx_fio_do_real(fio
,ir
->gb_obc_gamma
);
431 gmx_fio_do_real(fio
,ir
->gb_dielectric_offset
);
432 gmx_fio_do_int(fio
,ir
->sa_algorithm
);
436 ir
->gb_dielectric_offset
= 0.09;
437 ir
->sa_algorithm
= esaAPPROX
;
439 gmx_fio_do_real(fio
,ir
->sa_surface_tension
);
443 /* Better use sensible values than insane (0.0) ones... */
444 ir
->gb_epsilon_solvent
= 80;
445 ir
->gb_obc_alpha
= 1.0;
446 ir
->gb_obc_beta
= 0.8;
447 ir
->gb_obc_gamma
= 4.85;
448 ir
->sa_surface_tension
= 2.092;
452 gmx_fio_do_int(fio
,ir
->nkx
);
453 gmx_fio_do_int(fio
,ir
->nky
);
454 gmx_fio_do_int(fio
,ir
->nkz
);
455 gmx_fio_do_int(fio
,ir
->pme_order
);
456 gmx_fio_do_real(fio
,ir
->ewald_rtol
);
458 if (file_version
>=24)
459 gmx_fio_do_int(fio
,ir
->ewald_geometry
);
461 ir
->ewald_geometry
=eewg3D
;
463 if (file_version
<=17) {
464 ir
->epsilon_surface
=0;
465 if (file_version
==17)
466 gmx_fio_do_int(fio
,idum
);
469 gmx_fio_do_real(fio
,ir
->epsilon_surface
);
471 gmx_fio_do_bool(fio
,ir
->bOptFFT
);
473 gmx_fio_do_bool(fio
,ir
->bContinuation
);
474 gmx_fio_do_int(fio
,ir
->etc
);
475 /* before version 18, ir->etc was a bool (ir->btc),
476 * but the values 0 and 1 still mean no and
477 * berendsen temperature coupling, respectively.
479 if (file_version
>= 71)
481 gmx_fio_do_int(fio
,ir
->nsttcouple
);
485 ir
->nsttcouple
= ir
->nstcalcenergy
;
487 if (file_version
<= 15)
489 gmx_fio_do_int(fio
,idum
);
491 if (file_version
<=17)
493 gmx_fio_do_int(fio
,ir
->epct
);
494 if (file_version
<= 15)
498 ir
->epct
= epctSURFACETENSION
;
500 gmx_fio_do_int(fio
,idum
);
503 /* we have removed the NO alternative at the beginning */
507 ir
->epct
=epctISOTROPIC
;
511 ir
->epc
=epcBERENDSEN
;
516 gmx_fio_do_int(fio
,ir
->epc
);
517 gmx_fio_do_int(fio
,ir
->epct
);
519 if (file_version
>= 71)
521 gmx_fio_do_int(fio
,ir
->nstpcouple
);
525 ir
->nstpcouple
= ir
->nstcalcenergy
;
527 gmx_fio_do_real(fio
,ir
->tau_p
);
528 if (file_version
<= 15) {
529 gmx_fio_do_rvec(fio
,vdum
);
530 clear_mat(ir
->ref_p
);
532 ir
->ref_p
[i
][i
] = vdum
[i
];
534 gmx_fio_do_rvec(fio
,ir
->ref_p
[XX
]);
535 gmx_fio_do_rvec(fio
,ir
->ref_p
[YY
]);
536 gmx_fio_do_rvec(fio
,ir
->ref_p
[ZZ
]);
538 if (file_version
<= 15) {
539 gmx_fio_do_rvec(fio
,vdum
);
540 clear_mat(ir
->compress
);
542 ir
->compress
[i
][i
] = vdum
[i
];
545 gmx_fio_do_rvec(fio
,ir
->compress
[XX
]);
546 gmx_fio_do_rvec(fio
,ir
->compress
[YY
]);
547 gmx_fio_do_rvec(fio
,ir
->compress
[ZZ
]);
549 if (file_version
>= 47) {
550 gmx_fio_do_int(fio
,ir
->refcoord_scaling
);
551 gmx_fio_do_rvec(fio
,ir
->posres_com
);
552 gmx_fio_do_rvec(fio
,ir
->posres_comB
);
554 ir
->refcoord_scaling
= erscNO
;
555 clear_rvec(ir
->posres_com
);
556 clear_rvec(ir
->posres_comB
);
558 if(file_version
> 25)
559 gmx_fio_do_int(fio
,ir
->andersen_seed
);
563 if(file_version
< 26) {
564 gmx_fio_do_bool(fio
,bSimAnn
);
565 gmx_fio_do_real(fio
,zerotemptime
);
568 if (file_version
< 37)
569 gmx_fio_do_real(fio
,rdum
);
571 gmx_fio_do_real(fio
,ir
->shake_tol
);
572 if (file_version
< 54)
573 gmx_fio_do_real(fio
,*fudgeQQ
);
574 gmx_fio_do_int(fio
,ir
->efep
);
575 if (file_version
<= 14 && ir
->efep
> efepNO
)
577 if (file_version
>= 59) {
578 gmx_fio_do_double(fio
, ir
->init_lambda
);
579 gmx_fio_do_double(fio
, ir
->delta_lambda
);
581 gmx_fio_do_real(fio
,rdum
);
582 ir
->init_lambda
= rdum
;
583 gmx_fio_do_real(fio
,rdum
);
584 ir
->delta_lambda
= rdum
;
586 if (file_version
>= 64) {
587 gmx_fio_do_int(fio
,ir
->n_flambda
);
589 snew(ir
->flambda
,ir
->n_flambda
);
591 bDum
=gmx_fio_ndo_double(fio
,ir
->flambda
,ir
->n_flambda
);
596 if (file_version
>= 13)
597 gmx_fio_do_real(fio
,ir
->sc_alpha
);
600 if (file_version
>= 38)
601 gmx_fio_do_int(fio
,ir
->sc_power
);
604 if (file_version
>= 15)
605 gmx_fio_do_real(fio
,ir
->sc_sigma
);
608 if (file_version
>= 64) {
609 gmx_fio_do_int(fio
,ir
->nstdhdl
);
613 if (file_version
>= 71)
615 gmx_fio_do_int(fio
,ir
->dh_table_size
);
616 gmx_fio_do_double(fio
,ir
->dh_table_spacing
);
620 ir
->dh_table_size
= 0;
621 ir
->dh_table_spacing
= 0.1;
623 if (file_version
>= 57) {
624 gmx_fio_do_int(fio
,ir
->eDisre
);
626 gmx_fio_do_int(fio
,ir
->eDisreWeighting
);
627 if (file_version
< 22) {
628 if (ir
->eDisreWeighting
== 0)
629 ir
->eDisreWeighting
= edrwEqual
;
631 ir
->eDisreWeighting
= edrwConservative
;
633 gmx_fio_do_bool(fio
,ir
->bDisreMixed
);
634 gmx_fio_do_real(fio
,ir
->dr_fc
);
635 gmx_fio_do_real(fio
,ir
->dr_tau
);
636 gmx_fio_do_int(fio
,ir
->nstdisreout
);
637 if (file_version
>= 22) {
638 gmx_fio_do_real(fio
,ir
->orires_fc
);
639 gmx_fio_do_real(fio
,ir
->orires_tau
);
640 gmx_fio_do_int(fio
,ir
->nstorireout
);
646 if(file_version
>= 26) {
647 gmx_fio_do_real(fio
,ir
->dihre_fc
);
648 if (file_version
< 56) {
649 gmx_fio_do_real(fio
,rdum
);
650 gmx_fio_do_int(fio
,idum
);
656 gmx_fio_do_real(fio
,ir
->em_stepsize
);
657 gmx_fio_do_real(fio
,ir
->em_tol
);
658 if (file_version
>= 22)
659 gmx_fio_do_bool(fio
,ir
->bShakeSOR
);
661 ir
->bShakeSOR
= TRUE
;
662 if (file_version
>= 11)
663 gmx_fio_do_int(fio
,ir
->niter
);
666 fprintf(stderr
,"Note: niter not in run input file, setting it to %d\n",
669 if (file_version
>= 21)
670 gmx_fio_do_real(fio
,ir
->fc_stepsize
);
673 gmx_fio_do_int(fio
,ir
->eConstrAlg
);
674 gmx_fio_do_int(fio
,ir
->nProjOrder
);
675 gmx_fio_do_real(fio
,ir
->LincsWarnAngle
);
676 if (file_version
<= 14)
677 gmx_fio_do_int(fio
,idum
);
678 if (file_version
>=26)
679 gmx_fio_do_int(fio
,ir
->nLincsIter
);
682 fprintf(stderr
,"Note: nLincsIter not in run input file, setting it to %d\n",
685 if (file_version
< 33)
686 gmx_fio_do_real(fio
,bd_temp
);
687 gmx_fio_do_real(fio
,ir
->bd_fric
);
688 gmx_fio_do_int(fio
,ir
->ld_seed
);
689 if (file_version
>= 33) {
691 gmx_fio_do_rvec(fio
,ir
->deform
[i
]);
694 clear_rvec(ir
->deform
[i
]);
696 if (file_version
>= 14)
697 gmx_fio_do_real(fio
,ir
->cos_accel
);
700 gmx_fio_do_int(fio
,ir
->userint1
);
701 gmx_fio_do_int(fio
,ir
->userint2
);
702 gmx_fio_do_int(fio
,ir
->userint3
);
703 gmx_fio_do_int(fio
,ir
->userint4
);
704 gmx_fio_do_real(fio
,ir
->userreal1
);
705 gmx_fio_do_real(fio
,ir
->userreal2
);
706 gmx_fio_do_real(fio
,ir
->userreal3
);
707 gmx_fio_do_real(fio
,ir
->userreal4
);
710 if (file_version
>= 48) {
711 gmx_fio_do_int(fio
,ir
->ePull
);
712 if (ir
->ePull
!= epullNO
) {
715 do_pull(fio
, ir
->pull
,bRead
,file_version
);
722 gmx_fio_do_int(fio
,ir
->opts
.ngtc
);
723 if (file_version
>= 69) {
724 gmx_fio_do_int(fio
,ir
->opts
.nhchainlength
);
726 ir
->opts
.nhchainlength
= 1;
728 gmx_fio_do_int(fio
,ir
->opts
.ngacc
);
729 gmx_fio_do_int(fio
,ir
->opts
.ngfrz
);
730 gmx_fio_do_int(fio
,ir
->opts
.ngener
);
733 snew(ir
->opts
.nrdf
, ir
->opts
.ngtc
);
734 snew(ir
->opts
.ref_t
, ir
->opts
.ngtc
);
735 snew(ir
->opts
.annealing
, ir
->opts
.ngtc
);
736 snew(ir
->opts
.anneal_npoints
, ir
->opts
.ngtc
);
737 snew(ir
->opts
.anneal_time
, ir
->opts
.ngtc
);
738 snew(ir
->opts
.anneal_temp
, ir
->opts
.ngtc
);
739 snew(ir
->opts
.tau_t
, ir
->opts
.ngtc
);
740 snew(ir
->opts
.nFreeze
,ir
->opts
.ngfrz
);
741 snew(ir
->opts
.acc
, ir
->opts
.ngacc
);
742 snew(ir
->opts
.egp_flags
,ir
->opts
.ngener
*ir
->opts
.ngener
);
744 if (ir
->opts
.ngtc
> 0) {
745 if (bRead
&& file_version
<13) {
746 snew(tmp
,ir
->opts
.ngtc
);
747 bDum
=gmx_fio_ndo_int(fio
,tmp
, ir
->opts
.ngtc
);
748 for(i
=0; i
<ir
->opts
.ngtc
; i
++)
749 ir
->opts
.nrdf
[i
] = tmp
[i
];
752 bDum
=gmx_fio_ndo_real(fio
,ir
->opts
.nrdf
, ir
->opts
.ngtc
);
754 bDum
=gmx_fio_ndo_real(fio
,ir
->opts
.ref_t
,ir
->opts
.ngtc
);
755 bDum
=gmx_fio_ndo_real(fio
,ir
->opts
.tau_t
,ir
->opts
.ngtc
);
756 if (file_version
<33 && ir
->eI
==eiBD
) {
757 for(i
=0; i
<ir
->opts
.ngtc
; i
++)
758 ir
->opts
.tau_t
[i
] = bd_temp
;
761 if (ir
->opts
.ngfrz
> 0)
762 bDum
=gmx_fio_ndo_ivec(fio
,ir
->opts
.nFreeze
,ir
->opts
.ngfrz
);
763 if (ir
->opts
.ngacc
> 0)
764 gmx_fio_ndo_rvec(fio
,ir
->opts
.acc
,ir
->opts
.ngacc
);
765 if (file_version
>= 12)
766 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.egp_flags
,
767 ir
->opts
.ngener
*ir
->opts
.ngener
);
769 if(bRead
&& file_version
< 26) {
770 for(i
=0;i
<ir
->opts
.ngtc
;i
++) {
772 ir
->opts
.annealing
[i
] = eannSINGLE
;
773 ir
->opts
.anneal_npoints
[i
] = 2;
774 snew(ir
->opts
.anneal_time
[i
],2);
775 snew(ir
->opts
.anneal_temp
[i
],2);
776 /* calculate the starting/ending temperatures from reft, zerotemptime, and nsteps */
777 finish_t
= ir
->init_t
+ ir
->nsteps
* ir
->delta_t
;
778 init_temp
= ir
->opts
.ref_t
[i
]*(1-ir
->init_t
/zerotemptime
);
779 finish_temp
= ir
->opts
.ref_t
[i
]*(1-finish_t
/zerotemptime
);
780 ir
->opts
.anneal_time
[i
][0] = ir
->init_t
;
781 ir
->opts
.anneal_time
[i
][1] = finish_t
;
782 ir
->opts
.anneal_temp
[i
][0] = init_temp
;
783 ir
->opts
.anneal_temp
[i
][1] = finish_temp
;
785 ir
->opts
.annealing
[i
] = eannNO
;
786 ir
->opts
.anneal_npoints
[i
] = 0;
790 /* file version 26 or later */
791 /* First read the lists with annealing and npoints for each group */
792 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.annealing
,ir
->opts
.ngtc
);
793 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.anneal_npoints
,ir
->opts
.ngtc
);
794 for(j
=0;j
<(ir
->opts
.ngtc
);j
++) {
795 k
=ir
->opts
.anneal_npoints
[j
];
797 snew(ir
->opts
.anneal_time
[j
],k
);
798 snew(ir
->opts
.anneal_temp
[j
],k
);
800 bDum
=gmx_fio_ndo_real(fio
,ir
->opts
.anneal_time
[j
],k
);
801 bDum
=gmx_fio_ndo_real(fio
,ir
->opts
.anneal_temp
[j
],k
);
805 if (file_version
>= 45) {
806 gmx_fio_do_int(fio
,ir
->nwall
);
807 gmx_fio_do_int(fio
,ir
->wall_type
);
808 if (file_version
>= 50)
809 gmx_fio_do_real(fio
,ir
->wall_r_linpot
);
811 ir
->wall_r_linpot
= -1;
812 gmx_fio_do_int(fio
,ir
->wall_atomtype
[0]);
813 gmx_fio_do_int(fio
,ir
->wall_atomtype
[1]);
814 gmx_fio_do_real(fio
,ir
->wall_density
[0]);
815 gmx_fio_do_real(fio
,ir
->wall_density
[1]);
816 gmx_fio_do_real(fio
,ir
->wall_ewald_zfac
);
820 ir
->wall_atomtype
[0] = -1;
821 ir
->wall_atomtype
[1] = -1;
822 ir
->wall_density
[0] = 0;
823 ir
->wall_density
[1] = 0;
824 ir
->wall_ewald_zfac
= 3;
826 /* Cosine stuff for electric fields */
827 for(j
=0; (j
<DIM
); j
++) {
828 gmx_fio_do_int(fio
,ir
->ex
[j
].n
);
829 gmx_fio_do_int(fio
,ir
->et
[j
].n
);
831 snew(ir
->ex
[j
].a
, ir
->ex
[j
].n
);
832 snew(ir
->ex
[j
].phi
,ir
->ex
[j
].n
);
833 snew(ir
->et
[j
].a
, ir
->et
[j
].n
);
834 snew(ir
->et
[j
].phi
,ir
->et
[j
].n
);
836 bDum
=gmx_fio_ndo_real(fio
,ir
->ex
[j
].a
, ir
->ex
[j
].n
);
837 bDum
=gmx_fio_ndo_real(fio
,ir
->ex
[j
].phi
,ir
->ex
[j
].n
);
838 bDum
=gmx_fio_ndo_real(fio
,ir
->et
[j
].a
, ir
->et
[j
].n
);
839 bDum
=gmx_fio_ndo_real(fio
,ir
->et
[j
].phi
,ir
->et
[j
].n
);
843 if(file_version
>=39){
844 gmx_fio_do_bool(fio
,ir
->bQMMM
);
845 gmx_fio_do_int(fio
,ir
->QMMMscheme
);
846 gmx_fio_do_real(fio
,ir
->scalefactor
);
847 gmx_fio_do_int(fio
,ir
->opts
.ngQM
);
849 snew(ir
->opts
.QMmethod
, ir
->opts
.ngQM
);
850 snew(ir
->opts
.QMbasis
, ir
->opts
.ngQM
);
851 snew(ir
->opts
.QMcharge
, ir
->opts
.ngQM
);
852 snew(ir
->opts
.QMmult
, ir
->opts
.ngQM
);
853 snew(ir
->opts
.bSH
, ir
->opts
.ngQM
);
854 snew(ir
->opts
.CASorbitals
, ir
->opts
.ngQM
);
855 snew(ir
->opts
.CASelectrons
,ir
->opts
.ngQM
);
856 snew(ir
->opts
.SAon
, ir
->opts
.ngQM
);
857 snew(ir
->opts
.SAoff
, ir
->opts
.ngQM
);
858 snew(ir
->opts
.SAsteps
, ir
->opts
.ngQM
);
859 snew(ir
->opts
.bOPT
, ir
->opts
.ngQM
);
860 snew(ir
->opts
.bTS
, ir
->opts
.ngQM
);
862 if (ir
->opts
.ngQM
> 0) {
863 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.QMmethod
,ir
->opts
.ngQM
);
864 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.QMbasis
,ir
->opts
.ngQM
);
865 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.QMcharge
,ir
->opts
.ngQM
);
866 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.QMmult
,ir
->opts
.ngQM
);
867 bDum
=gmx_fio_ndo_bool(fio
,ir
->opts
.bSH
,ir
->opts
.ngQM
);
868 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.CASorbitals
,ir
->opts
.ngQM
);
869 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.CASelectrons
,ir
->opts
.ngQM
);
870 bDum
=gmx_fio_ndo_real(fio
,ir
->opts
.SAon
,ir
->opts
.ngQM
);
871 bDum
=gmx_fio_ndo_real(fio
,ir
->opts
.SAoff
,ir
->opts
.ngQM
);
872 bDum
=gmx_fio_ndo_int(fio
,ir
->opts
.SAsteps
,ir
->opts
.ngQM
);
873 bDum
=gmx_fio_ndo_bool(fio
,ir
->opts
.bOPT
,ir
->opts
.ngQM
);
874 bDum
=gmx_fio_ndo_bool(fio
,ir
->opts
.bTS
,ir
->opts
.ngQM
);
876 /* end of QMMM stuff */
881 static void do_harm(t_fileio
*fio
, t_iparams
*iparams
,bool bRead
)
883 gmx_fio_do_real(fio
,iparams
->harmonic
.rA
);
884 gmx_fio_do_real(fio
,iparams
->harmonic
.krA
);
885 gmx_fio_do_real(fio
,iparams
->harmonic
.rB
);
886 gmx_fio_do_real(fio
,iparams
->harmonic
.krB
);
889 void do_iparams(t_fileio
*fio
, t_functype ftype
,t_iparams
*iparams
,
890 bool bRead
, int file_version
)
897 gmx_fio_set_comment(fio
, interaction_function
[ftype
].name
);
905 do_harm(fio
, iparams
,bRead
);
906 if ((ftype
== F_ANGRES
|| ftype
== F_ANGRESZ
) && bRead
) {
907 /* Correct incorrect storage of parameters */
908 iparams
->pdihs
.phiB
= iparams
->pdihs
.phiA
;
909 iparams
->pdihs
.cpB
= iparams
->pdihs
.cpA
;
913 gmx_fio_do_real(fio
,iparams
->fene
.bm
);
914 gmx_fio_do_real(fio
,iparams
->fene
.kb
);
917 gmx_fio_do_real(fio
,iparams
->restraint
.lowA
);
918 gmx_fio_do_real(fio
,iparams
->restraint
.up1A
);
919 gmx_fio_do_real(fio
,iparams
->restraint
.up2A
);
920 gmx_fio_do_real(fio
,iparams
->restraint
.kA
);
921 gmx_fio_do_real(fio
,iparams
->restraint
.lowB
);
922 gmx_fio_do_real(fio
,iparams
->restraint
.up1B
);
923 gmx_fio_do_real(fio
,iparams
->restraint
.up2B
);
924 gmx_fio_do_real(fio
,iparams
->restraint
.kB
);
930 gmx_fio_do_real(fio
,iparams
->tab
.kA
);
931 gmx_fio_do_int(fio
,iparams
->tab
.table
);
932 gmx_fio_do_real(fio
,iparams
->tab
.kB
);
934 case F_CROSS_BOND_BONDS
:
935 gmx_fio_do_real(fio
,iparams
->cross_bb
.r1e
);
936 gmx_fio_do_real(fio
,iparams
->cross_bb
.r2e
);
937 gmx_fio_do_real(fio
,iparams
->cross_bb
.krr
);
939 case F_CROSS_BOND_ANGLES
:
940 gmx_fio_do_real(fio
,iparams
->cross_ba
.r1e
);
941 gmx_fio_do_real(fio
,iparams
->cross_ba
.r2e
);
942 gmx_fio_do_real(fio
,iparams
->cross_ba
.r3e
);
943 gmx_fio_do_real(fio
,iparams
->cross_ba
.krt
);
946 gmx_fio_do_real(fio
,iparams
->u_b
.theta
);
947 gmx_fio_do_real(fio
,iparams
->u_b
.ktheta
);
948 gmx_fio_do_real(fio
,iparams
->u_b
.r13
);
949 gmx_fio_do_real(fio
,iparams
->u_b
.kUB
);
951 case F_QUARTIC_ANGLES
:
952 gmx_fio_do_real(fio
,iparams
->qangle
.theta
);
953 bDum
=gmx_fio_ndo_real(fio
,iparams
->qangle
.c
,5);
956 gmx_fio_do_real(fio
,iparams
->bham
.a
);
957 gmx_fio_do_real(fio
,iparams
->bham
.b
);
958 gmx_fio_do_real(fio
,iparams
->bham
.c
);
961 gmx_fio_do_real(fio
,iparams
->morse
.b0
);
962 gmx_fio_do_real(fio
,iparams
->morse
.cb
);
963 gmx_fio_do_real(fio
,iparams
->morse
.beta
);
966 gmx_fio_do_real(fio
,iparams
->cubic
.b0
);
967 gmx_fio_do_real(fio
,iparams
->cubic
.kb
);
968 gmx_fio_do_real(fio
,iparams
->cubic
.kcub
);
973 gmx_fio_do_real(fio
,iparams
->polarize
.alpha
);
976 if (file_version
< 31)
977 gmx_fatal(FARGS
,"Old tpr files with water_polarization not supported. Make a new.");
978 gmx_fio_do_real(fio
,iparams
->wpol
.al_x
);
979 gmx_fio_do_real(fio
,iparams
->wpol
.al_y
);
980 gmx_fio_do_real(fio
,iparams
->wpol
.al_z
);
981 gmx_fio_do_real(fio
,iparams
->wpol
.rOH
);
982 gmx_fio_do_real(fio
,iparams
->wpol
.rHH
);
983 gmx_fio_do_real(fio
,iparams
->wpol
.rOD
);
986 gmx_fio_do_real(fio
,iparams
->thole
.a
);
987 gmx_fio_do_real(fio
,iparams
->thole
.alpha1
);
988 gmx_fio_do_real(fio
,iparams
->thole
.alpha2
);
989 gmx_fio_do_real(fio
,iparams
->thole
.rfac
);
992 gmx_fio_do_real(fio
,iparams
->lj
.c6
);
993 gmx_fio_do_real(fio
,iparams
->lj
.c12
);
996 gmx_fio_do_real(fio
,iparams
->lj14
.c6A
);
997 gmx_fio_do_real(fio
,iparams
->lj14
.c12A
);
998 gmx_fio_do_real(fio
,iparams
->lj14
.c6B
);
999 gmx_fio_do_real(fio
,iparams
->lj14
.c12B
);
1002 gmx_fio_do_real(fio
,iparams
->ljc14
.fqq
);
1003 gmx_fio_do_real(fio
,iparams
->ljc14
.qi
);
1004 gmx_fio_do_real(fio
,iparams
->ljc14
.qj
);
1005 gmx_fio_do_real(fio
,iparams
->ljc14
.c6
);
1006 gmx_fio_do_real(fio
,iparams
->ljc14
.c12
);
1008 case F_LJC_PAIRS_NB
:
1009 gmx_fio_do_real(fio
,iparams
->ljcnb
.qi
);
1010 gmx_fio_do_real(fio
,iparams
->ljcnb
.qj
);
1011 gmx_fio_do_real(fio
,iparams
->ljcnb
.c6
);
1012 gmx_fio_do_real(fio
,iparams
->ljcnb
.c12
);
1018 gmx_fio_do_real(fio
,iparams
->pdihs
.phiA
);
1019 gmx_fio_do_real(fio
,iparams
->pdihs
.cpA
);
1020 if ((ftype
== F_ANGRES
|| ftype
== F_ANGRESZ
) && file_version
< 42) {
1021 /* Read the incorrectly stored multiplicity */
1022 gmx_fio_do_real(fio
,iparams
->harmonic
.rB
);
1023 gmx_fio_do_real(fio
,iparams
->harmonic
.krB
);
1024 iparams
->pdihs
.phiB
= iparams
->pdihs
.phiA
;
1025 iparams
->pdihs
.cpB
= iparams
->pdihs
.cpA
;
1027 gmx_fio_do_real(fio
,iparams
->pdihs
.phiB
);
1028 gmx_fio_do_real(fio
,iparams
->pdihs
.cpB
);
1029 gmx_fio_do_int(fio
,iparams
->pdihs
.mult
);
1033 gmx_fio_do_int(fio
,iparams
->disres
.label
);
1034 gmx_fio_do_int(fio
,iparams
->disres
.type
);
1035 gmx_fio_do_real(fio
,iparams
->disres
.low
);
1036 gmx_fio_do_real(fio
,iparams
->disres
.up1
);
1037 gmx_fio_do_real(fio
,iparams
->disres
.up2
);
1038 gmx_fio_do_real(fio
,iparams
->disres
.kfac
);
1041 gmx_fio_do_int(fio
,iparams
->orires
.ex
);
1042 gmx_fio_do_int(fio
,iparams
->orires
.label
);
1043 gmx_fio_do_int(fio
,iparams
->orires
.power
);
1044 gmx_fio_do_real(fio
,iparams
->orires
.c
);
1045 gmx_fio_do_real(fio
,iparams
->orires
.obs
);
1046 gmx_fio_do_real(fio
,iparams
->orires
.kfac
);
1049 gmx_fio_do_int(fio
,iparams
->dihres
.power
);
1050 gmx_fio_do_int(fio
,iparams
->dihres
.label
);
1051 gmx_fio_do_real(fio
,iparams
->dihres
.phi
);
1052 gmx_fio_do_real(fio
,iparams
->dihres
.dphi
);
1053 gmx_fio_do_real(fio
,iparams
->dihres
.kfac
);
1056 gmx_fio_do_rvec(fio
,iparams
->posres
.pos0A
);
1057 gmx_fio_do_rvec(fio
,iparams
->posres
.fcA
);
1058 if (bRead
&& file_version
< 27) {
1059 copy_rvec(iparams
->posres
.pos0A
,iparams
->posres
.pos0B
);
1060 copy_rvec(iparams
->posres
.fcA
,iparams
->posres
.fcB
);
1062 gmx_fio_do_rvec(fio
,iparams
->posres
.pos0B
);
1063 gmx_fio_do_rvec(fio
,iparams
->posres
.fcB
);
1067 bDum
=gmx_fio_ndo_real(fio
,iparams
->rbdihs
.rbcA
,NR_RBDIHS
);
1068 if(file_version
>=25)
1069 bDum
=gmx_fio_ndo_real(fio
,iparams
->rbdihs
.rbcB
,NR_RBDIHS
);
1072 /* Fourier dihedrals are internally represented
1073 * as Ryckaert-Bellemans since those are faster to compute.
1075 bDum
=gmx_fio_ndo_real(fio
,iparams
->rbdihs
.rbcA
, NR_RBDIHS
);
1076 bDum
=gmx_fio_ndo_real(fio
,iparams
->rbdihs
.rbcB
, NR_RBDIHS
);
1080 gmx_fio_do_real(fio
,iparams
->constr
.dA
);
1081 gmx_fio_do_real(fio
,iparams
->constr
.dB
);
1084 gmx_fio_do_real(fio
,iparams
->settle
.doh
);
1085 gmx_fio_do_real(fio
,iparams
->settle
.dhh
);
1088 gmx_fio_do_real(fio
,iparams
->vsite
.a
);
1093 gmx_fio_do_real(fio
,iparams
->vsite
.a
);
1094 gmx_fio_do_real(fio
,iparams
->vsite
.b
);
1099 gmx_fio_do_real(fio
,iparams
->vsite
.a
);
1100 gmx_fio_do_real(fio
,iparams
->vsite
.b
);
1101 gmx_fio_do_real(fio
,iparams
->vsite
.c
);
1104 gmx_fio_do_int(fio
,iparams
->vsiten
.n
);
1105 gmx_fio_do_real(fio
,iparams
->vsiten
.a
);
1110 /* We got rid of some parameters in version 68 */
1111 if(bRead
&& file_version
<68)
1113 gmx_fio_do_real(fio
,rdum
);
1114 gmx_fio_do_real(fio
,rdum
);
1115 gmx_fio_do_real(fio
,rdum
);
1116 gmx_fio_do_real(fio
,rdum
);
1118 gmx_fio_do_real(fio
,iparams
->gb
.sar
);
1119 gmx_fio_do_real(fio
,iparams
->gb
.st
);
1120 gmx_fio_do_real(fio
,iparams
->gb
.pi
);
1121 gmx_fio_do_real(fio
,iparams
->gb
.gbr
);
1122 gmx_fio_do_real(fio
,iparams
->gb
.bmlt
);
1125 gmx_fio_do_int(fio
,iparams
->cmap
.cmapA
);
1126 gmx_fio_do_int(fio
,iparams
->cmap
.cmapB
);
1129 gmx_fatal(FARGS
,"unknown function type %d (%s) in %s line %d",
1131 ftype
,interaction_function
[ftype
].name
,__FILE__
,__LINE__
);
1134 gmx_fio_unset_comment(fio
);
1137 static void do_ilist(t_fileio
*fio
, t_ilist
*ilist
,bool bRead
,int file_version
,
1144 gmx_fio_set_comment(fio
, interaction_function
[ftype
].name
);
1146 if (file_version
< 44) {
1147 for(i
=0; i
<MAXNODES
; i
++)
1148 gmx_fio_do_int(fio
,idum
);
1150 gmx_fio_do_int(fio
,ilist
->nr
);
1152 snew(ilist
->iatoms
,ilist
->nr
);
1153 bDum
=gmx_fio_ndo_int(fio
,ilist
->iatoms
,ilist
->nr
);
1155 gmx_fio_unset_comment(fio
);
1158 static void do_ffparams(t_fileio
*fio
, gmx_ffparams_t
*ffparams
,
1159 bool bRead
, int file_version
)
1164 gmx_fio_do_int(fio
,ffparams
->atnr
);
1165 if (file_version
< 57) {
1166 gmx_fio_do_int(fio
,idum
);
1168 gmx_fio_do_int(fio
,ffparams
->ntypes
);
1170 fprintf(debug
,"ffparams->atnr = %d, ntypes = %d\n",
1171 ffparams
->atnr
,ffparams
->ntypes
);
1173 snew(ffparams
->functype
,ffparams
->ntypes
);
1174 snew(ffparams
->iparams
,ffparams
->ntypes
);
1176 /* Read/write all the function types */
1177 bDum
=gmx_fio_ndo_int(fio
,ffparams
->functype
,ffparams
->ntypes
);
1179 pr_ivec(debug
,0,"functype",ffparams
->functype
,ffparams
->ntypes
,TRUE
);
1181 if (file_version
>= 66) {
1182 gmx_fio_do_double(fio
,ffparams
->reppow
);
1184 ffparams
->reppow
= 12.0;
1187 if (file_version
>= 57) {
1188 gmx_fio_do_real(fio
,ffparams
->fudgeQQ
);
1191 /* Check whether all these function types are supported by the code.
1192 * In practice the code is backwards compatible, which means that the
1193 * numbering may have to be altered from old numbering to new numbering
1195 for (i
=0; (i
<ffparams
->ntypes
); i
++) {
1197 /* Loop over file versions */
1198 for (k
=0; (k
<NFTUPD
); k
++)
1199 /* Compare the read file_version to the update table */
1200 if ((file_version
< ftupd
[k
].fvnr
) &&
1201 (ffparams
->functype
[i
] >= ftupd
[k
].ftype
)) {
1202 ffparams
->functype
[i
] += 1;
1204 fprintf(debug
,"Incrementing function type %d to %d (due to %s)\n",
1205 i
,ffparams
->functype
[i
],
1206 interaction_function
[ftupd
[k
].ftype
].longname
);
1211 do_iparams(fio
, ffparams
->functype
[i
],&ffparams
->iparams
[i
],bRead
,
1214 pr_iparams(debug
,ffparams
->functype
[i
],&ffparams
->iparams
[i
]);
1218 static void do_ilists(t_fileio
*fio
, t_ilist
*ilist
,bool bRead
,
1221 int i
,j
,k
,renum
[F_NRE
];
1222 bool bDum
=TRUE
,bClear
;
1224 for(j
=0; (j
<F_NRE
); j
++) {
1227 for (k
=0; k
<NFTUPD
; k
++)
1228 if ((file_version
< ftupd
[k
].fvnr
) && (j
== ftupd
[k
].ftype
))
1232 ilist
[j
].iatoms
= NULL
;
1234 do_ilist(fio
, &ilist
[j
],bRead
,file_version
,j
);
1237 if (bRead && gmx_debug_at)
1238 pr_ilist(debug,0,interaction_function[j].longname,
1239 functype,&ilist[j],TRUE);
1244 static void do_idef(t_fileio
*fio
, gmx_ffparams_t
*ffparams
,gmx_moltype_t
*molt
,
1245 bool bRead
, int file_version
)
1247 do_ffparams(fio
, ffparams
,bRead
,file_version
);
1249 if (file_version
>= 54) {
1250 gmx_fio_do_real(fio
,ffparams
->fudgeQQ
);
1253 do_ilists(fio
, molt
->ilist
,bRead
,file_version
);
1256 static void do_block(t_fileio
*fio
, t_block
*block
,bool bRead
,int file_version
)
1258 int i
,idum
,dum_nra
,*dum_a
;
1261 if (file_version
< 44)
1262 for(i
=0; i
<MAXNODES
; i
++)
1263 gmx_fio_do_int(fio
,idum
);
1264 gmx_fio_do_int(fio
,block
->nr
);
1265 if (file_version
< 51)
1266 gmx_fio_do_int(fio
,dum_nra
);
1268 block
->nalloc_index
= block
->nr
+1;
1269 snew(block
->index
,block
->nalloc_index
);
1271 bDum
=gmx_fio_ndo_int(fio
,block
->index
,block
->nr
+1);
1273 if (file_version
< 51 && dum_nra
> 0) {
1274 snew(dum_a
,dum_nra
);
1275 bDum
=gmx_fio_ndo_int(fio
,dum_a
,dum_nra
);
1280 static void do_blocka(t_fileio
*fio
, t_blocka
*block
,bool bRead
,
1286 if (file_version
< 44)
1287 for(i
=0; i
<MAXNODES
; i
++)
1288 gmx_fio_do_int(fio
,idum
);
1289 gmx_fio_do_int(fio
,block
->nr
);
1290 gmx_fio_do_int(fio
,block
->nra
);
1292 block
->nalloc_index
= block
->nr
+1;
1293 snew(block
->index
,block
->nalloc_index
);
1294 block
->nalloc_a
= block
->nra
;
1295 snew(block
->a
,block
->nalloc_a
);
1297 bDum
=gmx_fio_ndo_int(fio
,block
->index
,block
->nr
+1);
1298 bDum
=gmx_fio_ndo_int(fio
,block
->a
,block
->nra
);
1301 static void do_atom(t_fileio
*fio
, t_atom
*atom
,int ngrp
,bool bRead
,
1302 int file_version
, gmx_groups_t
*groups
,int atnr
)
1306 gmx_fio_do_real(fio
,atom
->m
);
1307 gmx_fio_do_real(fio
,atom
->q
);
1308 gmx_fio_do_real(fio
,atom
->mB
);
1309 gmx_fio_do_real(fio
,atom
->qB
);
1310 gmx_fio_do_ushort(fio
, atom
->type
);
1311 gmx_fio_do_ushort(fio
, atom
->typeB
);
1312 gmx_fio_do_int(fio
,atom
->ptype
);
1313 gmx_fio_do_int(fio
,atom
->resind
);
1314 if (file_version
>= 52)
1315 gmx_fio_do_int(fio
,atom
->atomnumber
);
1317 atom
->atomnumber
= NOTSET
;
1318 if (file_version
< 23)
1320 else if (file_version
< 39)
1325 if (file_version
< 57) {
1326 unsigned char uchar
[egcNR
];
1327 gmx_fio_ndo_uchar(fio
,uchar
,myngrp
);
1328 for(i
=myngrp
; (i
<ngrp
); i
++) {
1331 /* Copy the old data format to the groups struct */
1332 for(i
=0; i
<ngrp
; i
++) {
1333 groups
->grpnr
[i
][atnr
] = uchar
[i
];
1338 static void do_grps(t_fileio
*fio
, int ngrp
,t_grps grps
[],bool bRead
,
1344 if (file_version
< 23)
1346 else if (file_version
< 39)
1351 for(j
=0; (j
<ngrp
); j
++) {
1353 gmx_fio_do_int(fio
,grps
[j
].nr
);
1355 snew(grps
[j
].nm_ind
,grps
[j
].nr
);
1356 bDum
=gmx_fio_ndo_int(fio
,grps
[j
].nm_ind
,grps
[j
].nr
);
1360 snew(grps
[j
].nm_ind
,grps
[j
].nr
);
1365 static void do_symstr(t_fileio
*fio
, char ***nm
,bool bRead
,t_symtab
*symtab
)
1370 gmx_fio_do_int(fio
,ls
);
1371 *nm
= get_symtab_handle(symtab
,ls
);
1374 ls
= lookup_symtab(symtab
,*nm
);
1375 gmx_fio_do_int(fio
,ls
);
1379 static void do_strstr(t_fileio
*fio
, int nstr
,char ***nm
,bool bRead
,
1384 for (j
=0; (j
<nstr
); j
++)
1385 do_symstr(fio
, &(nm
[j
]),bRead
,symtab
);
1388 static void do_resinfo(t_fileio
*fio
, int n
,t_resinfo
*ri
,bool bRead
,
1389 t_symtab
*symtab
, int file_version
)
1393 for (j
=0; (j
<n
); j
++) {
1394 do_symstr(fio
, &(ri
[j
].name
),bRead
,symtab
);
1395 if (file_version
>= 63) {
1396 gmx_fio_do_int(fio
,ri
[j
].nr
);
1397 gmx_fio_do_uchar(fio
, ri
[j
].ic
);
1405 static void do_atoms(t_fileio
*fio
, t_atoms
*atoms
,bool bRead
,t_symtab
*symtab
,
1407 gmx_groups_t
*groups
)
1411 gmx_fio_do_int(fio
,atoms
->nr
);
1412 gmx_fio_do_int(fio
,atoms
->nres
);
1413 if (file_version
< 57) {
1414 gmx_fio_do_int(fio
,groups
->ngrpname
);
1415 for(i
=0; i
<egcNR
; i
++) {
1416 groups
->ngrpnr
[i
] = atoms
->nr
;
1417 snew(groups
->grpnr
[i
],groups
->ngrpnr
[i
]);
1421 snew(atoms
->atom
,atoms
->nr
);
1422 snew(atoms
->atomname
,atoms
->nr
);
1423 snew(atoms
->atomtype
,atoms
->nr
);
1424 snew(atoms
->atomtypeB
,atoms
->nr
);
1425 snew(atoms
->resinfo
,atoms
->nres
);
1426 if (file_version
< 57) {
1427 snew(groups
->grpname
,groups
->ngrpname
);
1429 atoms
->pdbinfo
= NULL
;
1431 for(i
=0; (i
<atoms
->nr
); i
++) {
1432 do_atom(fio
, &atoms
->atom
[i
],egcNR
,bRead
, file_version
,groups
,i
);
1434 do_strstr(fio
, atoms
->nr
,atoms
->atomname
,bRead
,symtab
);
1435 if (bRead
&& (file_version
<= 20)) {
1436 for(i
=0; i
<atoms
->nr
; i
++) {
1437 atoms
->atomtype
[i
] = put_symtab(symtab
,"?");
1438 atoms
->atomtypeB
[i
] = put_symtab(symtab
,"?");
1441 do_strstr(fio
, atoms
->nr
,atoms
->atomtype
,bRead
,symtab
);
1442 do_strstr(fio
, atoms
->nr
,atoms
->atomtypeB
,bRead
,symtab
);
1444 do_resinfo(fio
, atoms
->nres
,atoms
->resinfo
,bRead
,symtab
,file_version
);
1446 if (file_version
< 57) {
1447 do_strstr(fio
, groups
->ngrpname
,groups
->grpname
,bRead
,symtab
);
1449 do_grps(fio
, egcNR
,groups
->grps
,bRead
,file_version
);
1453 static void do_groups(t_fileio
*fio
, gmx_groups_t
*groups
,
1454 bool bRead
,t_symtab
*symtab
,
1460 do_grps(fio
, egcNR
,groups
->grps
,bRead
,file_version
);
1461 gmx_fio_do_int(fio
,groups
->ngrpname
);
1463 snew(groups
->grpname
,groups
->ngrpname
);
1465 do_strstr(fio
, groups
->ngrpname
,groups
->grpname
,bRead
,symtab
);
1466 for(g
=0; g
<egcNR
; g
++) {
1467 gmx_fio_do_int(fio
,groups
->ngrpnr
[g
]);
1468 if (groups
->ngrpnr
[g
] == 0) {
1470 groups
->grpnr
[g
] = NULL
;
1474 snew(groups
->grpnr
[g
],groups
->ngrpnr
[g
]);
1476 bDum
=gmx_fio_ndo_uchar(fio
, groups
->grpnr
[g
],groups
->ngrpnr
[g
]);
1481 static void do_atomtypes(t_fileio
*fio
, t_atomtypes
*atomtypes
,bool bRead
,
1482 t_symtab
*symtab
,int file_version
)
1487 if (file_version
> 25) {
1488 gmx_fio_do_int(fio
,atomtypes
->nr
);
1491 snew(atomtypes
->radius
,j
);
1492 snew(atomtypes
->vol
,j
);
1493 snew(atomtypes
->surftens
,j
);
1494 snew(atomtypes
->atomnumber
,j
);
1495 snew(atomtypes
->gb_radius
,j
);
1496 snew(atomtypes
->S_hct
,j
);
1498 bDum
=gmx_fio_ndo_real(fio
,atomtypes
->radius
,j
);
1499 bDum
=gmx_fio_ndo_real(fio
,atomtypes
->vol
,j
);
1500 bDum
=gmx_fio_ndo_real(fio
,atomtypes
->surftens
,j
);
1501 if(file_version
>= 40)
1503 bDum
=gmx_fio_ndo_int(fio
,atomtypes
->atomnumber
,j
);
1505 if(file_version
>= 60)
1507 bDum
=gmx_fio_ndo_real(fio
,atomtypes
->gb_radius
,j
);
1508 bDum
=gmx_fio_ndo_real(fio
,atomtypes
->S_hct
,j
);
1511 /* File versions prior to 26 cannot do GBSA,
1512 * so they dont use this structure
1515 atomtypes
->radius
= NULL
;
1516 atomtypes
->vol
= NULL
;
1517 atomtypes
->surftens
= NULL
;
1518 atomtypes
->atomnumber
= NULL
;
1519 atomtypes
->gb_radius
= NULL
;
1520 atomtypes
->S_hct
= NULL
;
1524 static void do_symtab(t_fileio
*fio
, t_symtab
*symtab
,bool bRead
)
1530 gmx_fio_do_int(fio
,symtab
->nr
);
1533 snew(symtab
->symbuf
,1);
1534 symbuf
= symtab
->symbuf
;
1535 symbuf
->bufsize
= nr
;
1536 snew(symbuf
->buf
,nr
);
1537 for (i
=0; (i
<nr
); i
++) {
1538 gmx_fio_do_string(fio
,buf
);
1539 symbuf
->buf
[i
]=strdup(buf
);
1543 symbuf
= symtab
->symbuf
;
1544 while (symbuf
!=NULL
) {
1545 for (i
=0; (i
<symbuf
->bufsize
) && (i
<nr
); i
++)
1546 gmx_fio_do_string(fio
,symbuf
->buf
[i
]);
1548 symbuf
=symbuf
->next
;
1551 gmx_fatal(FARGS
,"nr of symtab strings left: %d",nr
);
1555 static void do_cmap(t_fileio
*fio
, gmx_cmap_t
*cmap_grid
, bool bRead
)
1557 int i
,j
,ngrid
,gs
,nelem
;
1559 gmx_fio_do_int(fio
,cmap_grid
->ngrid
);
1560 gmx_fio_do_int(fio
,cmap_grid
->grid_spacing
);
1562 ngrid
= cmap_grid
->ngrid
;
1563 gs
= cmap_grid
->grid_spacing
;
1568 snew(cmap_grid
->cmapdata
,ngrid
);
1570 for(i
=0;i
<cmap_grid
->ngrid
;i
++)
1572 snew(cmap_grid
->cmapdata
[i
].cmap
,4*nelem
);
1576 for(i
=0;i
<cmap_grid
->ngrid
;i
++)
1578 for(j
=0;j
<nelem
;j
++)
1580 gmx_fio_do_real(fio
,cmap_grid
->cmapdata
[i
].cmap
[j
*4]);
1581 gmx_fio_do_real(fio
,cmap_grid
->cmapdata
[i
].cmap
[j
*4+1]);
1582 gmx_fio_do_real(fio
,cmap_grid
->cmapdata
[i
].cmap
[j
*4+2]);
1583 gmx_fio_do_real(fio
,cmap_grid
->cmapdata
[i
].cmap
[j
*4+3]);
1589 void tpx_make_chain_identifiers(t_atoms
*atoms
,t_block
*mols
)
1592 unsigned char c
,chain
;
1593 #define CHAIN_MIN_ATOMS 15
1596 for(m
=0; m
<mols
->nr
; m
++) {
1598 a1
=mols
->index
[m
+1];
1599 if ((a1
-a0
>= CHAIN_MIN_ATOMS
) && (chain
<= 'Z')) {
1604 for(a
=a0
; a
<a1
; a
++) {
1605 atoms
->resinfo
[atoms
->atom
[a
].resind
].chain
= c
;
1609 for(r
=0; r
<atoms
->nres
; r
++) {
1610 atoms
->resinfo
[r
].chain
= ' ';
1615 static void do_moltype(t_fileio
*fio
, gmx_moltype_t
*molt
,bool bRead
,
1616 t_symtab
*symtab
, int file_version
,
1617 gmx_groups_t
*groups
)
1621 if (file_version
>= 57) {
1622 do_symstr(fio
, &(molt
->name
),bRead
,symtab
);
1625 do_atoms(fio
, &molt
->atoms
, bRead
, symtab
, file_version
, groups
);
1627 if (bRead
&& gmx_debug_at
) {
1628 pr_atoms(debug
,0,"atoms",&molt
->atoms
,TRUE
);
1631 if (file_version
>= 57) {
1632 do_ilists(fio
, molt
->ilist
,bRead
,file_version
);
1634 do_block(fio
, &molt
->cgs
,bRead
,file_version
);
1635 if (bRead
&& gmx_debug_at
) {
1636 pr_block(debug
,0,"cgs",&molt
->cgs
,TRUE
);
1640 /* This used to be in the atoms struct */
1641 do_blocka(fio
, &molt
->excls
, bRead
, file_version
);
1644 static void do_molblock(t_fileio
*fio
, gmx_molblock_t
*molb
,bool bRead
,
1649 gmx_fio_do_int(fio
,molb
->type
);
1650 gmx_fio_do_int(fio
,molb
->nmol
);
1651 gmx_fio_do_int(fio
,molb
->natoms_mol
);
1652 /* Position restraint coordinates */
1653 gmx_fio_do_int(fio
,molb
->nposres_xA
);
1654 if (molb
->nposres_xA
> 0) {
1656 snew(molb
->posres_xA
,molb
->nposres_xA
);
1658 gmx_fio_ndo_rvec(fio
,molb
->posres_xA
,molb
->nposres_xA
);
1660 gmx_fio_do_int(fio
,molb
->nposres_xB
);
1661 if (molb
->nposres_xB
> 0) {
1663 snew(molb
->posres_xB
,molb
->nposres_xB
);
1665 gmx_fio_ndo_rvec(fio
,molb
->posres_xB
,molb
->nposres_xB
);
1670 static t_block
mtop_mols(gmx_mtop_t
*mtop
)
1676 for(mb
=0; mb
<mtop
->nmolblock
; mb
++) {
1677 mols
.nr
+= mtop
->molblock
[mb
].nmol
;
1679 mols
.nalloc_index
= mols
.nr
+ 1;
1680 snew(mols
.index
,mols
.nalloc_index
);
1685 for(mb
=0; mb
<mtop
->nmolblock
; mb
++) {
1686 for(mol
=0; mol
<mtop
->molblock
[mb
].nmol
; mol
++) {
1687 a
+= mtop
->molblock
[mb
].natoms_mol
;
1696 static void add_posres_molblock(gmx_mtop_t
*mtop
)
1701 gmx_molblock_t
*molb
;
1704 il
= &mtop
->moltype
[0].ilist
[F_POSRES
];
1710 for(i
=0; i
<il
->nr
; i
+=2) {
1711 ip
= &mtop
->ffparams
.iparams
[il
->iatoms
[i
]];
1712 am
= max(am
,il
->iatoms
[i
+1]);
1713 if (ip
->posres
.pos0B
[XX
] != ip
->posres
.pos0A
[XX
] ||
1714 ip
->posres
.pos0B
[YY
] != ip
->posres
.pos0A
[YY
] ||
1715 ip
->posres
.pos0B
[ZZ
] != ip
->posres
.pos0A
[ZZ
]) {
1719 /* Make the posres coordinate block end at a molecule end */
1721 while(am
>= mtop
->mols
.index
[mol
+1]) {
1724 molb
= &mtop
->molblock
[0];
1725 molb
->nposres_xA
= mtop
->mols
.index
[mol
+1];
1726 snew(molb
->posres_xA
,molb
->nposres_xA
);
1728 molb
->nposres_xB
= molb
->nposres_xA
;
1729 snew(molb
->posres_xB
,molb
->nposres_xB
);
1731 molb
->nposres_xB
= 0;
1733 for(i
=0; i
<il
->nr
; i
+=2) {
1734 ip
= &mtop
->ffparams
.iparams
[il
->iatoms
[i
]];
1735 a
= il
->iatoms
[i
+1];
1736 molb
->posres_xA
[a
][XX
] = ip
->posres
.pos0A
[XX
];
1737 molb
->posres_xA
[a
][YY
] = ip
->posres
.pos0A
[YY
];
1738 molb
->posres_xA
[a
][ZZ
] = ip
->posres
.pos0A
[ZZ
];
1740 molb
->posres_xB
[a
][XX
] = ip
->posres
.pos0B
[XX
];
1741 molb
->posres_xB
[a
][YY
] = ip
->posres
.pos0B
[YY
];
1742 molb
->posres_xB
[a
][ZZ
] = ip
->posres
.pos0B
[ZZ
];
1747 static void set_disres_npair(gmx_mtop_t
*mtop
)
1754 ip
= mtop
->ffparams
.iparams
;
1756 for(mt
=0; mt
<mtop
->nmoltype
; mt
++) {
1757 il
= &mtop
->moltype
[mt
].ilist
[F_DISRES
];
1761 for(i
=0; i
<il
->nr
; i
+=3) {
1763 if (i
+3 == il
->nr
|| ip
[a
[i
]].disres
.label
!= ip
[a
[i
+3]].disres
.label
) {
1764 ip
[a
[i
]].disres
.npair
= npair
;
1772 static void do_mtop(t_fileio
*fio
, gmx_mtop_t
*mtop
,bool bRead
,
1780 do_symtab(fio
, &(mtop
->symtab
),bRead
);
1782 pr_symtab(debug
,0,"symtab",&mtop
->symtab
);
1784 do_symstr(fio
, &(mtop
->name
),bRead
,&(mtop
->symtab
));
1786 if (file_version
>= 57) {
1787 do_ffparams(fio
, &mtop
->ffparams
,bRead
,file_version
);
1789 gmx_fio_do_int(fio
,mtop
->nmoltype
);
1794 snew(mtop
->moltype
,mtop
->nmoltype
);
1795 if (file_version
< 57) {
1796 mtop
->moltype
[0].name
= mtop
->name
;
1799 for(mt
=0; mt
<mtop
->nmoltype
; mt
++) {
1800 do_moltype(fio
, &mtop
->moltype
[mt
],bRead
,&mtop
->symtab
,file_version
,
1804 if (file_version
>= 57) {
1805 gmx_fio_do_int(fio
,mtop
->nmolblock
);
1807 mtop
->nmolblock
= 1;
1810 snew(mtop
->molblock
,mtop
->nmolblock
);
1812 if (file_version
>= 57) {
1813 for(mb
=0; mb
<mtop
->nmolblock
; mb
++) {
1814 do_molblock(fio
, &mtop
->molblock
[mb
],bRead
,file_version
);
1816 gmx_fio_do_int(fio
,mtop
->natoms
);
1818 mtop
->molblock
[0].type
= 0;
1819 mtop
->molblock
[0].nmol
= 1;
1820 mtop
->molblock
[0].natoms_mol
= mtop
->moltype
[0].atoms
.nr
;
1821 mtop
->molblock
[0].nposres_xA
= 0;
1822 mtop
->molblock
[0].nposres_xB
= 0;
1825 do_atomtypes (fio
, &(mtop
->atomtypes
),bRead
,&(mtop
->symtab
), file_version
);
1827 pr_atomtypes(debug
,0,"atomtypes",&mtop
->atomtypes
,TRUE
);
1829 if (file_version
< 57) {
1830 /* Debug statements are inside do_idef */
1831 do_idef (fio
, &mtop
->ffparams
,&mtop
->moltype
[0],bRead
,file_version
);
1832 mtop
->natoms
= mtop
->moltype
[0].atoms
.nr
;
1835 if(file_version
>= 65)
1837 do_cmap(fio
, &mtop
->ffparams
.cmap_grid
,bRead
);
1841 mtop
->ffparams
.cmap_grid
.ngrid
= 0;
1842 mtop
->ffparams
.cmap_grid
.grid_spacing
= 0.1;
1843 mtop
->ffparams
.cmap_grid
.cmapdata
= NULL
;
1846 if (file_version
>= 57) {
1847 do_groups(fio
, &mtop
->groups
,bRead
,&(mtop
->symtab
),file_version
);
1850 if (file_version
< 57) {
1851 do_block(fio
, &mtop
->moltype
[0].cgs
,bRead
,file_version
);
1852 if (bRead
&& gmx_debug_at
) {
1853 pr_block(debug
,0,"cgs",&mtop
->moltype
[0].cgs
,TRUE
);
1855 do_block(fio
, &mtop
->mols
,bRead
,file_version
);
1856 /* Add the posres coordinates to the molblock */
1857 add_posres_molblock(mtop
);
1860 if (file_version
>= 57) {
1861 mtop
->mols
= mtop_mols(mtop
);
1864 pr_block(debug
,0,"mols",&mtop
->mols
,TRUE
);
1868 if (file_version
< 51) {
1869 /* Here used to be the shake blocks */
1870 do_blocka(fio
, &dumb
,bRead
,file_version
);
1878 close_symtab(&(mtop
->symtab
));
1882 /* If TopOnlyOK is TRUE then we can read even future versions
1883 * of tpx files, provided the file_generation hasn't changed.
1884 * If it is FALSE, we need the inputrecord too, and bail out
1885 * if the file is newer than the program.
1887 * The version and generation if the topology (see top of this file)
1888 * are returned in the two last arguments.
1890 * If possible, we will read the inputrec even when TopOnlyOK is TRUE.
1892 static void do_tpxheader(t_fileio
*fio
,bool bRead
,t_tpxheader
*tpx
,
1893 bool TopOnlyOK
, int *file_version
,
1894 int *file_generation
)
1903 gmx_fio_checktype(fio
);
1904 gmx_fio_setdebug(fio
,bDebugMode());
1906 /* NEW! XDR tpb file */
1907 precision
= sizeof(real
);
1909 gmx_fio_do_string(fio
,buf
);
1910 if (strncmp(buf
,"VERSION",7))
1911 gmx_fatal(FARGS
,"Can not read file %s,\n"
1912 " this file is from a Gromacs version which is older than 2.0\n"
1913 " Make a new one with grompp or use a gro or pdb file, if possible",
1914 gmx_fio_getname(fio
));
1915 gmx_fio_do_int(fio
,precision
);
1916 bDouble
= (precision
== sizeof(double));
1917 if ((precision
!= sizeof(float)) && !bDouble
)
1918 gmx_fatal(FARGS
,"Unknown precision in file %s: real is %d bytes "
1919 "instead of %d or %d",
1920 gmx_fio_getname(fio
),precision
,sizeof(float),sizeof(double));
1921 gmx_fio_setprecision(fio
,bDouble
);
1922 fprintf(stderr
,"Reading file %s, %s (%s precision)\n",
1923 gmx_fio_getname(fio
),buf
,bDouble
? "double" : "single");
1926 gmx_fio_write_string(fio
,GromacsVersion());
1927 bDouble
= (precision
== sizeof(double));
1928 gmx_fio_setprecision(fio
,bDouble
);
1929 gmx_fio_do_int(fio
,precision
);
1931 fgen
= tpx_generation
;
1934 /* Check versions! */
1935 gmx_fio_do_int(fio
,fver
);
1938 gmx_fio_do_int(fio
,fgen
);
1942 if(file_version
!=NULL
)
1943 *file_version
= fver
;
1944 if(file_generation
!=NULL
)
1945 *file_generation
= fgen
;
1948 if ((fver
<= tpx_incompatible_version
) ||
1949 ((fver
> tpx_version
) && !TopOnlyOK
) ||
1950 (fgen
> tpx_generation
))
1951 gmx_fatal(FARGS
,"reading tpx file (%s) version %d with version %d program",
1952 gmx_fio_getname(fio
),fver
,tpx_version
);
1954 do_section(fio
,eitemHEADER
,bRead
);
1955 gmx_fio_do_int(fio
,tpx
->natoms
);
1957 gmx_fio_do_int(fio
,tpx
->ngtc
);
1961 gmx_fio_do_int(fio
,idum
);
1962 gmx_fio_do_real(fio
,rdum
);
1964 gmx_fio_do_real(fio
,tpx
->lambda
);
1965 gmx_fio_do_int(fio
,tpx
->bIr
);
1966 gmx_fio_do_int(fio
,tpx
->bTop
);
1967 gmx_fio_do_int(fio
,tpx
->bX
);
1968 gmx_fio_do_int(fio
,tpx
->bV
);
1969 gmx_fio_do_int(fio
,tpx
->bF
);
1970 gmx_fio_do_int(fio
,tpx
->bBox
);
1972 if((fgen
> tpx_generation
)) {
1973 /* This can only happen if TopOnlyOK=TRUE */
1978 static int do_tpx(t_fileio
*fio
, bool bRead
,
1979 t_inputrec
*ir
,t_state
*state
,rvec
*f
,gmx_mtop_t
*mtop
,
1985 bool TopOnlyOK
,bDum
=TRUE
;
1986 int file_version
,file_generation
;
1993 tpx
.natoms
= state
->natoms
;
1994 tpx
.ngtc
= state
->ngtc
;
1995 tpx
.lambda
= state
->lambda
;
1996 tpx
.bIr
= (ir
!= NULL
);
1997 tpx
.bTop
= (mtop
!= NULL
);
1998 tpx
.bX
= (state
->x
!= NULL
);
1999 tpx
.bV
= (state
->v
!= NULL
);
2000 tpx
.bF
= (f
!= NULL
);
2004 TopOnlyOK
= (ir
==NULL
);
2006 do_tpxheader(fio
,bRead
,&tpx
,TopOnlyOK
,&file_version
,&file_generation
);
2010 state
->lambda
= tpx
.lambda
;
2011 /* The init_state calls initialize the Nose-Hoover xi integrals to zero */
2015 init_state(state
,0,tpx
.ngtc
,0,0); /* nose-hoover chains */ /* eventually, need to add nnhpres here? */
2016 state
->natoms
= tpx
.natoms
;
2017 state
->nalloc
= tpx
.natoms
;
2021 init_state(state
,tpx
.natoms
,tpx
.ngtc
,0,0); /* nose-hoover chains */
2025 #define do_test(fio,b,p) if (bRead && (p!=NULL) && !b) gmx_fatal(FARGS,"No %s in %s",#p,gmx_fio_getname(fio))
2027 do_test(fio
,tpx
.bBox
,state
->box
);
2028 do_section(fio
,eitemBOX
,bRead
);
2030 gmx_fio_ndo_rvec(fio
,state
->box
,DIM
);
2031 if (file_version
>= 51) {
2032 gmx_fio_ndo_rvec(fio
,state
->box_rel
,DIM
);
2034 /* We initialize box_rel after reading the inputrec */
2035 clear_mat(state
->box_rel
);
2037 if (file_version
>= 28) {
2038 gmx_fio_ndo_rvec(fio
,state
->boxv
,DIM
);
2039 if (file_version
< 56) {
2041 gmx_fio_ndo_rvec(fio
,mdum
,DIM
);
2046 if (state
->ngtc
> 0 && file_version
>= 28) {
2048 /*ndo_double(state->nosehoover_xi,state->ngtc,bDum);*/
2049 /*ndo_double(state->nosehoover_vxi,state->ngtc,bDum);*/
2050 /*ndo_double(state->therm_integral,state->ngtc,bDum);*/
2051 snew(dumv
,state
->ngtc
);
2052 if (file_version
< 69) {
2053 bDum
=gmx_fio_ndo_real(fio
,dumv
,state
->ngtc
);
2055 /* These used to be the Berendsen tcoupl_lambda's */
2056 bDum
=gmx_fio_ndo_real(fio
,dumv
,state
->ngtc
);
2060 /* Prior to tpx version 26, the inputrec was here.
2061 * I moved it to enable partial forward-compatibility
2062 * for analysis/viewer programs.
2064 if(file_version
<26) {
2065 do_test(fio
,tpx
.bIr
,ir
);
2066 do_section(fio
,eitemIR
,bRead
);
2069 do_inputrec(fio
, ir
,bRead
,file_version
,
2070 mtop
? &mtop
->ffparams
.fudgeQQ
: NULL
);
2072 pr_inputrec(debug
,0,"inputrec",ir
,FALSE
);
2075 do_inputrec(fio
, &dum_ir
,bRead
,file_version
,
2076 mtop
? &mtop
->ffparams
.fudgeQQ
:NULL
);
2078 pr_inputrec(debug
,0,"inputrec",&dum_ir
,FALSE
);
2079 done_inputrec(&dum_ir
);
2085 do_test(fio
,tpx
.bTop
,mtop
);
2086 do_section(fio
,eitemTOP
,bRead
);
2089 do_mtop(fio
,mtop
,bRead
, file_version
);
2091 do_mtop(fio
,&dum_top
,bRead
,file_version
);
2092 done_mtop(&dum_top
,TRUE
);
2095 do_test(fio
,tpx
.bX
,state
->x
);
2096 do_section(fio
,eitemX
,bRead
);
2099 state
->flags
|= (1<<estX
);
2101 gmx_fio_ndo_rvec(fio
,state
->x
,state
->natoms
);
2104 do_test(fio
,tpx
.bV
,state
->v
);
2105 do_section(fio
,eitemV
,bRead
);
2108 state
->flags
|= (1<<estV
);
2110 gmx_fio_ndo_rvec(fio
,state
->v
,state
->natoms
);
2113 do_test(fio
,tpx
.bF
,f
);
2114 do_section(fio
,eitemF
,bRead
);
2115 if (tpx
.bF
) gmx_fio_ndo_rvec(fio
,f
,state
->natoms
);
2117 /* Starting with tpx version 26, we have the inputrec
2118 * at the end of the file, so we can ignore it
2119 * if the file is never than the software (but still the
2120 * same generation - see comments at the top of this file.
2125 bPeriodicMols
= FALSE
;
2126 if (file_version
>= 26) {
2127 do_test(fio
,tpx
.bIr
,ir
);
2128 do_section(fio
,eitemIR
,bRead
);
2130 if (file_version
>= 53) {
2131 /* Removed the pbc info from do_inputrec, since we always want it */
2134 bPeriodicMols
= ir
->bPeriodicMols
;
2136 gmx_fio_do_int(fio
,ePBC
);
2137 gmx_fio_do_bool(fio
,bPeriodicMols
);
2139 if (file_generation
<= tpx_generation
&& ir
) {
2140 do_inputrec(fio
, ir
,bRead
,file_version
,mtop
? &mtop
->ffparams
.fudgeQQ
: NULL
);
2142 pr_inputrec(debug
,0,"inputrec",ir
,FALSE
);
2143 if (file_version
< 51)
2144 set_box_rel(ir
,state
);
2145 if (file_version
< 53) {
2147 bPeriodicMols
= ir
->bPeriodicMols
;
2150 if (bRead
&& ir
&& file_version
>= 53) {
2151 /* We need to do this after do_inputrec, since that initializes ir */
2153 ir
->bPeriodicMols
= bPeriodicMols
;
2162 if (state
->ngtc
== 0)
2164 /* Reading old version without tcoupl state data: set it */
2165 init_gtc_state(state
,ir
->opts
.ngtc
,0,ir
->opts
.nhchainlength
);
2167 if (tpx
.bTop
&& mtop
)
2169 if (file_version
< 57)
2171 if (mtop
->moltype
[0].ilist
[F_DISRES
].nr
> 0)
2173 ir
->eDisre
= edrSimple
;
2177 ir
->eDisre
= edrNone
;
2180 set_disres_npair(mtop
);
2184 if (tpx
.bTop
&& mtop
)
2186 gmx_mtop_finalize(mtop
);
2189 if (file_version
>= 57)
2193 env
= getenv("GMX_NOCHARGEGROUPS");
2196 sscanf(env
,"%d",&ienv
);
2197 fprintf(stderr
,"\nFound env.var. GMX_NOCHARGEGROUPS = %d\n",
2202 "Will make single atomic charge groups in non-solvent%s\n",
2203 ienv
> 1 ? " and solvent" : "");
2204 gmx_mtop_make_atomic_charge_groups(mtop
,ienv
==1);
2206 fprintf(stderr
,"\n");
2214 /************************************************************
2216 * The following routines are the exported ones
2218 ************************************************************/
2220 t_fileio
*open_tpx(const char *fn
,const char *mode
)
2222 return gmx_fio_open(fn
,mode
);
2225 void close_tpx(t_fileio
*fio
)
2230 void read_tpxheader(const char *fn
, t_tpxheader
*tpx
, bool TopOnlyOK
,
2231 int *file_version
, int *file_generation
)
2235 fio
= open_tpx(fn
,"r");
2236 do_tpxheader(fio
,TRUE
,tpx
,TopOnlyOK
,file_version
,file_generation
);
2240 void write_tpx_state(const char *fn
,
2241 t_inputrec
*ir
,t_state
*state
,gmx_mtop_t
*mtop
)
2245 fio
= open_tpx(fn
,"w");
2246 do_tpx(fio
,FALSE
,ir
,state
,NULL
,mtop
,FALSE
);
2250 void read_tpx_state(const char *fn
,
2251 t_inputrec
*ir
,t_state
*state
,rvec
*f
,gmx_mtop_t
*mtop
)
2255 fio
= open_tpx(fn
,"r");
2256 do_tpx(fio
,TRUE
,ir
,state
,f
,mtop
,FALSE
);
2260 int read_tpx(const char *fn
,
2261 t_inputrec
*ir
, matrix box
,int *natoms
,
2262 rvec
*x
,rvec
*v
,rvec
*f
,gmx_mtop_t
*mtop
)
2270 fio
= open_tpx(fn
,"r");
2271 ePBC
= do_tpx(fio
,TRUE
,ir
,&state
,f
,mtop
,TRUE
);
2273 *natoms
= state
.natoms
;
2275 copy_mat(state
.box
,box
);
2283 int read_tpx_top(const char *fn
,
2284 t_inputrec
*ir
, matrix box
,int *natoms
,
2285 rvec
*x
,rvec
*v
,rvec
*f
,t_topology
*top
)
2291 ePBC
= read_tpx(fn
,ir
,box
,natoms
,x
,v
,f
,&mtop
);
2293 *top
= gmx_mtop_t_to_t_topology(&mtop
);
2298 bool fn2bTPX(const char *file
)
2300 switch (fn2ftp(file
)) {
2310 bool read_tps_conf(const char *infile
,char *title
,t_topology
*top
,int *ePBC
,
2311 rvec
**x
,rvec
**v
,matrix box
,bool bMass
)
2314 int natoms
,i
,version
,generation
;
2317 t_topology
*topconv
;
2320 bTop
= fn2bTPX(infile
);
2323 read_tpxheader(infile
,&header
,TRUE
,&version
,&generation
);
2325 snew(*x
,header
.natoms
);
2327 snew(*v
,header
.natoms
);
2329 *ePBC
= read_tpx(infile
,NULL
,box
,&natoms
,
2330 (x
==NULL
) ? NULL
: *x
,(v
==NULL
) ? NULL
: *v
,NULL
,mtop
);
2331 *top
= gmx_mtop_t_to_t_topology(mtop
);
2333 strcpy(title
,*top
->name
);
2334 tpx_make_chain_identifiers(&top
->atoms
,&top
->mols
);
2337 get_stx_coordnum(infile
,&natoms
);
2338 init_t_atoms(&top
->atoms
,natoms
,FALSE
);
2339 bXNULL
= (x
== NULL
);
2343 read_stx_conf(infile
,title
,&top
->atoms
,*x
,(v
==NULL
) ? NULL
: *v
,ePBC
,box
);
2349 aps
= gmx_atomprop_init();
2350 for(i
=0; (i
<natoms
); i
++)
2351 if (!gmx_atomprop_query(aps
,epropMass
,
2352 *top
->atoms
.resinfo
[top
->atoms
.atom
[i
].resind
].name
,
2353 *top
->atoms
.atomname
[i
],
2354 &(top
->atoms
.atom
[i
].m
))) {
2356 fprintf(debug
,"Can not find mass for atom %s %d %s, setting to 1\n",
2357 *top
->atoms
.resinfo
[top
->atoms
.atom
[i
].resind
].name
,
2358 top
->atoms
.resinfo
[top
->atoms
.atom
[i
].resind
].nr
,
2359 *top
->atoms
.atomname
[i
]);
2361 gmx_atomprop_destroy(aps
);
2363 top
->idef
.ntypes
=-1;