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 void _do_section(int fp
,int key
,bool bRead
,const char *src
,int line
)
173 if (gmx_fio_getftp(fp
) == efTPA
) {
175 do_string(itemstr
[key
]);
176 bDbg
= gmx_fio_getdebug(fp
);
177 gmx_fio_setdebug(fp
,FALSE
);
178 do_string(comment_str
[key
]);
179 gmx_fio_setdebug(fp
,bDbg
);
182 if (gmx_fio_getdebug(fp
))
183 fprintf(stderr
,"Looking for section %s (%s, %d)",
184 itemstr
[key
],src
,line
);
188 } while ((strcasecmp(buf
,itemstr
[key
]) != 0));
190 if (strcasecmp(buf
,itemstr
[key
]) != 0)
191 gmx_fatal(FARGS
,"\nCould not find section heading %s",itemstr
[key
]);
192 else if (gmx_fio_getdebug(fp
))
193 fprintf(stderr
," and found it\n");
198 #define do_section(key,bRead) _do_section(fp,key,bRead,__FILE__,__LINE__)
200 /**************************************************************
202 * Now the higer level routines that do io of the structures and arrays
204 **************************************************************/
205 static void do_pullgrp(t_pullgrp
*pgrp
,bool bRead
, int file_version
)
212 snew(pgrp
->ind
,pgrp
->nat
);
213 ndo_int(pgrp
->ind
,pgrp
->nat
,bDum
);
214 do_int(pgrp
->nweight
);
216 snew(pgrp
->weight
,pgrp
->nweight
);
217 ndo_real(pgrp
->weight
,pgrp
->nweight
,bDum
);
218 do_int(pgrp
->pbcatom
);
223 if (file_version
>= 56) {
230 static void do_pull(t_pull
*pull
,bool bRead
, int file_version
)
237 do_real(pull
->cyl_r1
);
238 do_real(pull
->cyl_r0
);
239 do_real(pull
->constr_tol
);
240 do_int(pull
->nstxout
);
241 do_int(pull
->nstfout
);
243 snew(pull
->grp
,pull
->ngrp
+1);
244 for(g
=0; g
<pull
->ngrp
+1; g
++)
245 do_pullgrp(&pull
->grp
[g
],bRead
,file_version
);
248 static void do_rotgrp(t_rotgrp
*rotg
,bool bRead
, int file_version
)
254 do_int(rotg
->bMassW
);
257 snew(rotg
->ind
,rotg
->nat
);
258 ndo_int(rotg
->ind
,rotg
->nat
,bDum
);
260 snew(rotg
->x_ref
,rotg
->nat
);
261 ndo_rvec(rotg
->x_ref
,rotg
->nat
);
263 do_rvec(rotg
->pivot
);
266 do_real(rotg
->slab_dist
);
267 do_real(rotg
->min_gaussian
);
269 do_int(rotg
->eFittype
);
272 static void do_rot(t_rot
*rot
,bool bRead
, int file_version
)
277 do_int(rot
->nstrout
);
278 do_int(rot
->nsttout
);
280 snew(rot
->grp
,rot
->ngrp
);
281 for(g
=0; g
<rot
->ngrp
; g
++)
282 do_rotgrp(&rot
->grp
[g
],bRead
,file_version
);
285 static void do_inputrec(t_inputrec
*ir
,bool bRead
, int file_version
,
288 int i
,j
,k
,*tmp
,idum
=0;
293 real zerotemptime
,finish_t
,init_temp
,finish_temp
;
295 if (file_version
!= tpx_version
) {
296 /* Give a warning about features that are not accessible */
297 fprintf(stderr
,"Note: tpx file_version %d, software version %d\n",
298 file_version
,tpx_version
);
304 if (file_version
>= 1) {
305 /* Basic inputrec stuff */
307 if (file_version
>= 62) {
308 do_gmx_large_int(ir
->nsteps
);
313 if(file_version
> 25) {
314 if (file_version
>= 62) {
315 do_gmx_large_int(ir
->init_step
);
318 ir
->init_step
= idum
;
324 if(file_version
>= 58)
325 do_int(ir
->simulation_part
);
327 ir
->simulation_part
=1;
329 if (file_version
>= 67) {
330 do_int(ir
->nstcalcenergy
);
332 ir
->nstcalcenergy
= 1;
334 if (file_version
< 53) {
335 /* The pbc info has been moved out of do_inputrec,
336 * since we always want it, also without reading the inputrec.
339 if ((file_version
<= 15) && (ir
->ePBC
== 2))
341 if (file_version
>= 45) {
342 do_int(ir
->bPeriodicMols
);
346 ir
->bPeriodicMols
= TRUE
;
348 ir
->bPeriodicMols
= FALSE
;
355 if (file_version
< 41) {
359 if (file_version
>= 45)
364 if (file_version
> 34)
365 do_int(ir
->comm_mode
);
366 else if (ir
->nstcomm
< 0)
367 ir
->comm_mode
= ecmANGULAR
;
369 ir
->comm_mode
= ecmLINEAR
;
370 ir
->nstcomm
= abs(ir
->nstcomm
);
372 if(file_version
> 25)
373 do_int(ir
->nstcheckpoint
);
377 do_int(ir
->nstcgsteep
);
380 do_int(ir
->nbfgscorr
);
388 do_int(ir
->nstenergy
);
389 do_int(ir
->nstxtcout
);
390 if (file_version
>= 59) {
391 do_double(ir
->init_t
);
392 do_double(ir
->delta_t
);
399 do_real(ir
->xtcprec
);
400 if (file_version
< 19) {
404 if(file_version
< 18)
407 if (file_version
>= 67) {
408 do_real(ir
->rlistlong
);
410 do_int(ir
->coulombtype
);
411 if (file_version
< 32 && ir
->coulombtype
== eelRF
)
412 ir
->coulombtype
= eelRF_NEC
;
413 do_real(ir
->rcoulomb_switch
);
414 do_real(ir
->rcoulomb
);
416 do_real(ir
->rvdw_switch
);
418 if (file_version
< 67) {
419 ir
->rlistlong
= max_cutoff(ir
->rlist
,max_cutoff(ir
->rvdw
,ir
->rcoulomb
));
421 do_int(ir
->eDispCorr
);
422 do_real(ir
->epsilon_r
);
423 if (file_version
>= 37) {
424 do_real(ir
->epsilon_rf
);
426 if (EEL_RF(ir
->coulombtype
)) {
427 ir
->epsilon_rf
= ir
->epsilon_r
;
430 ir
->epsilon_rf
= 1.0;
433 if (file_version
>= 29)
438 if(file_version
> 25) {
439 do_int(ir
->gb_algorithm
);
440 do_int(ir
->nstgbradii
);
441 do_real(ir
->rgbradii
);
442 do_real(ir
->gb_saltconc
);
443 do_int(ir
->implicit_solvent
);
445 ir
->gb_algorithm
=egbSTILL
;
449 ir
->implicit_solvent
=eisNO
;
453 do_real(ir
->gb_epsilon_solvent
);
454 do_real(ir
->gb_obc_alpha
);
455 do_real(ir
->gb_obc_beta
);
456 do_real(ir
->gb_obc_gamma
);
459 do_real(ir
->gb_dielectric_offset
);
460 do_int(ir
->sa_algorithm
);
464 ir
->gb_dielectric_offset
= 0.09;
465 ir
->sa_algorithm
= esaAPPROX
;
467 do_real(ir
->sa_surface_tension
);
471 /* Better use sensible values than insane (0.0) ones... */
472 ir
->gb_epsilon_solvent
= 80;
473 ir
->gb_obc_alpha
= 1.0;
474 ir
->gb_obc_beta
= 0.8;
475 ir
->gb_obc_gamma
= 4.85;
476 ir
->sa_surface_tension
= 2.092;
483 do_int(ir
->pme_order
);
484 do_real(ir
->ewald_rtol
);
486 if (file_version
>=24)
487 do_int(ir
->ewald_geometry
);
489 ir
->ewald_geometry
=eewg3D
;
491 if (file_version
<=17) {
492 ir
->epsilon_surface
=0;
493 if (file_version
==17)
497 do_real(ir
->epsilon_surface
);
501 do_int(ir
->bContinuation
);
503 /* before version 18, ir->etc was a bool (ir->btc),
504 * but the values 0 and 1 still mean no and
505 * berendsen temperature coupling, respectively.
507 if (file_version
<= 15)
509 if (file_version
<=17) {
511 if (file_version
<= 15) {
513 ir
->epct
= epctSURFACETENSION
;
517 /* we have removed the NO alternative at the beginning */
520 ir
->epct
=epctISOTROPIC
;
523 ir
->epc
=epcBERENDSEN
;
530 if (file_version
<= 15) {
532 clear_mat(ir
->ref_p
);
534 ir
->ref_p
[i
][i
] = vdum
[i
];
536 do_rvec(ir
->ref_p
[XX
]);
537 do_rvec(ir
->ref_p
[YY
]);
538 do_rvec(ir
->ref_p
[ZZ
]);
540 if (file_version
<= 15) {
542 clear_mat(ir
->compress
);
544 ir
->compress
[i
][i
] = vdum
[i
];
547 do_rvec(ir
->compress
[XX
]);
548 do_rvec(ir
->compress
[YY
]);
549 do_rvec(ir
->compress
[ZZ
]);
551 if (file_version
>= 47) {
552 do_int(ir
->refcoord_scaling
);
553 do_rvec(ir
->posres_com
);
554 do_rvec(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 do_int(ir
->andersen_seed
);
565 if(file_version
< 26) {
567 do_real(zerotemptime
);
570 if (file_version
< 37)
573 do_real(ir
->shake_tol
);
574 if (file_version
< 54)
577 if (file_version
<= 14 && ir
->efep
> efepNO
)
579 if (file_version
>= 59) {
580 do_double(ir
->init_lambda
);
581 do_double(ir
->delta_lambda
);
584 ir
->init_lambda
= rdum
;
586 ir
->delta_lambda
= rdum
;
588 if (file_version
>= 64) {
589 do_int(ir
->n_flambda
);
591 snew(ir
->flambda
,ir
->n_flambda
);
593 ndo_double(ir
->flambda
,ir
->n_flambda
,bDum
);
598 if (file_version
>= 13)
599 do_real(ir
->sc_alpha
);
602 if (file_version
>= 38)
603 do_int(ir
->sc_power
);
606 if (file_version
>= 15)
607 do_real(ir
->sc_sigma
);
610 if (file_version
>= 64) {
615 if (file_version
>= 57) {
618 do_int(ir
->eDisreWeighting
);
619 if (file_version
< 22) {
620 if (ir
->eDisreWeighting
== 0)
621 ir
->eDisreWeighting
= edrwEqual
;
623 ir
->eDisreWeighting
= edrwConservative
;
625 do_int(ir
->bDisreMixed
);
628 do_int(ir
->nstdisreout
);
629 if (file_version
>= 22) {
630 do_real(ir
->orires_fc
);
631 do_real(ir
->orires_tau
);
632 do_int(ir
->nstorireout
);
638 if(file_version
>= 26) {
639 do_real(ir
->dihre_fc
);
640 if (file_version
< 56) {
648 do_real(ir
->em_stepsize
);
650 if (file_version
>= 22)
651 do_int(ir
->bShakeSOR
);
653 ir
->bShakeSOR
= TRUE
;
654 if (file_version
>= 11)
658 fprintf(stderr
,"Note: niter not in run input file, setting it to %d\n",
661 if (file_version
>= 21)
662 do_real(ir
->fc_stepsize
);
665 do_int(ir
->eConstrAlg
);
666 do_int(ir
->nProjOrder
);
667 do_real(ir
->LincsWarnAngle
);
668 if (file_version
<= 14)
670 if (file_version
>=26)
671 do_int(ir
->nLincsIter
);
674 fprintf(stderr
,"Note: nLincsIter not in run input file, setting it to %d\n",
677 if (file_version
< 33)
679 do_real(ir
->bd_fric
);
681 if (file_version
>= 33) {
683 do_rvec(ir
->deform
[i
]);
686 clear_rvec(ir
->deform
[i
]);
688 if (file_version
>= 14)
689 do_real(ir
->cos_accel
);
692 do_int(ir
->userint1
);
693 do_int(ir
->userint2
);
694 do_int(ir
->userint3
);
695 do_int(ir
->userint4
);
696 do_real(ir
->userreal1
);
697 do_real(ir
->userreal2
);
698 do_real(ir
->userreal3
);
699 do_real(ir
->userreal4
);
702 if (file_version
>= 48) {
704 if (ir
->ePull
!= epullNO
) {
707 do_pull(ir
->pull
,bRead
,file_version
);
713 /* Enforced rotation */
714 if (file_version
>= 71) {
716 if (ir
->bRot
== TRUE
) {
719 do_rot(ir
->rot
,bRead
,file_version
);
726 do_int(ir
->opts
.ngtc
);
727 if (file_version
>= 69) {
728 do_int(ir
->opts
.nhchainlength
);
730 ir
->opts
.nhchainlength
= 1;
732 do_int(ir
->opts
.ngacc
);
733 do_int(ir
->opts
.ngfrz
);
734 do_int(ir
->opts
.ngener
);
737 snew(ir
->opts
.nrdf
, ir
->opts
.ngtc
);
738 snew(ir
->opts
.ref_t
, ir
->opts
.ngtc
);
739 snew(ir
->opts
.annealing
, ir
->opts
.ngtc
);
740 snew(ir
->opts
.anneal_npoints
, ir
->opts
.ngtc
);
741 snew(ir
->opts
.anneal_time
, ir
->opts
.ngtc
);
742 snew(ir
->opts
.anneal_temp
, ir
->opts
.ngtc
);
743 snew(ir
->opts
.tau_t
, ir
->opts
.ngtc
);
744 snew(ir
->opts
.nFreeze
,ir
->opts
.ngfrz
);
745 snew(ir
->opts
.acc
, ir
->opts
.ngacc
);
746 snew(ir
->opts
.egp_flags
,ir
->opts
.ngener
*ir
->opts
.ngener
);
748 if (ir
->opts
.ngtc
> 0) {
749 if (bRead
&& file_version
<13) {
750 snew(tmp
,ir
->opts
.ngtc
);
751 ndo_int (tmp
, ir
->opts
.ngtc
,bDum
);
752 for(i
=0; i
<ir
->opts
.ngtc
; i
++)
753 ir
->opts
.nrdf
[i
] = tmp
[i
];
756 ndo_real(ir
->opts
.nrdf
, ir
->opts
.ngtc
,bDum
);
758 ndo_real(ir
->opts
.ref_t
,ir
->opts
.ngtc
,bDum
);
759 ndo_real(ir
->opts
.tau_t
,ir
->opts
.ngtc
,bDum
);
760 if (file_version
<33 && ir
->eI
==eiBD
) {
761 for(i
=0; i
<ir
->opts
.ngtc
; i
++)
762 ir
->opts
.tau_t
[i
] = bd_temp
;
765 if (ir
->opts
.ngfrz
> 0)
766 ndo_ivec(ir
->opts
.nFreeze
,ir
->opts
.ngfrz
,bDum
);
767 if (ir
->opts
.ngacc
> 0)
768 ndo_rvec(ir
->opts
.acc
,ir
->opts
.ngacc
);
769 if (file_version
>= 12)
770 ndo_int(ir
->opts
.egp_flags
,ir
->opts
.ngener
*ir
->opts
.ngener
,bDum
);
772 if(bRead
&& file_version
< 26) {
773 for(i
=0;i
<ir
->opts
.ngtc
;i
++) {
775 ir
->opts
.annealing
[i
] = eannSINGLE
;
776 ir
->opts
.anneal_npoints
[i
] = 2;
777 snew(ir
->opts
.anneal_time
[i
],2);
778 snew(ir
->opts
.anneal_temp
[i
],2);
779 /* calculate the starting/ending temperatures from reft, zerotemptime, and nsteps */
780 finish_t
= ir
->init_t
+ ir
->nsteps
* ir
->delta_t
;
781 init_temp
= ir
->opts
.ref_t
[i
]*(1-ir
->init_t
/zerotemptime
);
782 finish_temp
= ir
->opts
.ref_t
[i
]*(1-finish_t
/zerotemptime
);
783 ir
->opts
.anneal_time
[i
][0] = ir
->init_t
;
784 ir
->opts
.anneal_time
[i
][1] = finish_t
;
785 ir
->opts
.anneal_temp
[i
][0] = init_temp
;
786 ir
->opts
.anneal_temp
[i
][1] = finish_temp
;
788 ir
->opts
.annealing
[i
] = eannNO
;
789 ir
->opts
.anneal_npoints
[i
] = 0;
793 /* file version 26 or later */
794 /* First read the lists with annealing and npoints for each group */
795 ndo_int(ir
->opts
.annealing
,ir
->opts
.ngtc
,bDum
);
796 ndo_int(ir
->opts
.anneal_npoints
,ir
->opts
.ngtc
,bDum
);
797 for(j
=0;j
<(ir
->opts
.ngtc
);j
++) {
798 k
=ir
->opts
.anneal_npoints
[j
];
800 snew(ir
->opts
.anneal_time
[j
],k
);
801 snew(ir
->opts
.anneal_temp
[j
],k
);
803 ndo_real(ir
->opts
.anneal_time
[j
],k
,bDum
);
804 ndo_real(ir
->opts
.anneal_temp
[j
],k
,bDum
);
808 if (file_version
>= 45) {
810 do_int(ir
->wall_type
);
811 if (file_version
>= 50)
812 do_real(ir
->wall_r_linpot
);
814 ir
->wall_r_linpot
= -1;
815 do_int(ir
->wall_atomtype
[0]);
816 do_int(ir
->wall_atomtype
[1]);
817 do_real(ir
->wall_density
[0]);
818 do_real(ir
->wall_density
[1]);
819 do_real(ir
->wall_ewald_zfac
);
823 ir
->wall_atomtype
[0] = -1;
824 ir
->wall_atomtype
[1] = -1;
825 ir
->wall_density
[0] = 0;
826 ir
->wall_density
[1] = 0;
827 ir
->wall_ewald_zfac
= 3;
829 /* Cosine stuff for electric fields */
830 for(j
=0; (j
<DIM
); j
++) {
831 do_int (ir
->ex
[j
].n
);
832 do_int (ir
->et
[j
].n
);
834 snew(ir
->ex
[j
].a
, ir
->ex
[j
].n
);
835 snew(ir
->ex
[j
].phi
,ir
->ex
[j
].n
);
836 snew(ir
->et
[j
].a
, ir
->et
[j
].n
);
837 snew(ir
->et
[j
].phi
,ir
->et
[j
].n
);
839 ndo_real(ir
->ex
[j
].a
, ir
->ex
[j
].n
,bDum
);
840 ndo_real(ir
->ex
[j
].phi
,ir
->ex
[j
].n
,bDum
);
841 ndo_real(ir
->et
[j
].a
, ir
->et
[j
].n
,bDum
);
842 ndo_real(ir
->et
[j
].phi
,ir
->et
[j
].n
,bDum
);
846 if(file_version
>=39){
848 do_int(ir
->QMMMscheme
);
849 do_real(ir
->scalefactor
);
850 do_int(ir
->opts
.ngQM
);
852 snew(ir
->opts
.QMmethod
, ir
->opts
.ngQM
);
853 snew(ir
->opts
.QMbasis
, ir
->opts
.ngQM
);
854 snew(ir
->opts
.QMcharge
, ir
->opts
.ngQM
);
855 snew(ir
->opts
.QMmult
, ir
->opts
.ngQM
);
856 snew(ir
->opts
.bSH
, ir
->opts
.ngQM
);
857 snew(ir
->opts
.CASorbitals
, ir
->opts
.ngQM
);
858 snew(ir
->opts
.CASelectrons
,ir
->opts
.ngQM
);
859 snew(ir
->opts
.SAon
, ir
->opts
.ngQM
);
860 snew(ir
->opts
.SAoff
, ir
->opts
.ngQM
);
861 snew(ir
->opts
.SAsteps
, ir
->opts
.ngQM
);
862 snew(ir
->opts
.bOPT
, ir
->opts
.ngQM
);
863 snew(ir
->opts
.bTS
, ir
->opts
.ngQM
);
865 if (ir
->opts
.ngQM
> 0) {
866 ndo_int(ir
->opts
.QMmethod
,ir
->opts
.ngQM
,bDum
);
867 ndo_int(ir
->opts
.QMbasis
,ir
->opts
.ngQM
,bDum
);
868 ndo_int(ir
->opts
.QMcharge
,ir
->opts
.ngQM
,bDum
);
869 ndo_int(ir
->opts
.QMmult
,ir
->opts
.ngQM
,bDum
);
870 ndo_int(ir
->opts
.bSH
,ir
->opts
.ngQM
,bDum
);
871 ndo_int(ir
->opts
.CASorbitals
,ir
->opts
.ngQM
,bDum
);
872 ndo_int(ir
->opts
.CASelectrons
,ir
->opts
.ngQM
,bDum
);
873 ndo_real(ir
->opts
.SAon
,ir
->opts
.ngQM
,bDum
);
874 ndo_real(ir
->opts
.SAoff
,ir
->opts
.ngQM
,bDum
);
875 ndo_int(ir
->opts
.SAsteps
,ir
->opts
.ngQM
,bDum
);
876 ndo_int(ir
->opts
.bOPT
,ir
->opts
.ngQM
,bDum
);
877 ndo_int(ir
->opts
.bTS
,ir
->opts
.ngQM
,bDum
);
879 /* end of QMMM stuff */
885 static void do_harm(t_iparams
*iparams
,bool bRead
)
887 do_real(iparams
->harmonic
.rA
);
888 do_real(iparams
->harmonic
.krA
);
889 do_real(iparams
->harmonic
.rB
);
890 do_real(iparams
->harmonic
.krB
);
893 void do_iparams(t_functype ftype
,t_iparams
*iparams
,bool bRead
, int file_version
)
900 set_comment(interaction_function
[ftype
].name
);
908 do_harm(iparams
,bRead
);
909 if ((ftype
== F_ANGRES
|| ftype
== F_ANGRESZ
) && bRead
) {
910 /* Correct incorrect storage of parameters */
911 iparams
->pdihs
.phiB
= iparams
->pdihs
.phiA
;
912 iparams
->pdihs
.cpB
= iparams
->pdihs
.cpA
;
916 do_real(iparams
->fene
.bm
);
917 do_real(iparams
->fene
.kb
);
920 do_real(iparams
->restraint
.lowA
);
921 do_real(iparams
->restraint
.up1A
);
922 do_real(iparams
->restraint
.up2A
);
923 do_real(iparams
->restraint
.kA
);
924 do_real(iparams
->restraint
.lowB
);
925 do_real(iparams
->restraint
.up1B
);
926 do_real(iparams
->restraint
.up2B
);
927 do_real(iparams
->restraint
.kB
);
933 do_real(iparams
->tab
.kA
);
934 do_int (iparams
->tab
.table
);
935 do_real(iparams
->tab
.kB
);
937 case F_CROSS_BOND_BONDS
:
938 do_real(iparams
->cross_bb
.r1e
);
939 do_real(iparams
->cross_bb
.r2e
);
940 do_real(iparams
->cross_bb
.krr
);
942 case F_CROSS_BOND_ANGLES
:
943 do_real(iparams
->cross_ba
.r1e
);
944 do_real(iparams
->cross_ba
.r2e
);
945 do_real(iparams
->cross_ba
.r3e
);
946 do_real(iparams
->cross_ba
.krt
);
949 do_real(iparams
->u_b
.theta
);
950 do_real(iparams
->u_b
.ktheta
);
951 do_real(iparams
->u_b
.r13
);
952 do_real(iparams
->u_b
.kUB
);
954 case F_QUARTIC_ANGLES
:
955 do_real(iparams
->qangle
.theta
);
956 ndo_real(iparams
->qangle
.c
,5,bDum
);
959 do_real(iparams
->bham
.a
);
960 do_real(iparams
->bham
.b
);
961 do_real(iparams
->bham
.c
);
964 do_real(iparams
->morse
.b0
);
965 do_real(iparams
->morse
.cb
);
966 do_real(iparams
->morse
.beta
);
969 do_real(iparams
->cubic
.b0
);
970 do_real(iparams
->cubic
.kb
);
971 do_real(iparams
->cubic
.kcub
);
976 do_real(iparams
->polarize
.alpha
);
979 if (file_version
< 31)
980 gmx_fatal(FARGS
,"Old tpr files with water_polarization not supported. Make a new.");
981 do_real(iparams
->wpol
.al_x
);
982 do_real(iparams
->wpol
.al_y
);
983 do_real(iparams
->wpol
.al_z
);
984 do_real(iparams
->wpol
.rOH
);
985 do_real(iparams
->wpol
.rHH
);
986 do_real(iparams
->wpol
.rOD
);
989 do_real(iparams
->thole
.a
);
990 do_real(iparams
->thole
.alpha1
);
991 do_real(iparams
->thole
.alpha2
);
992 do_real(iparams
->thole
.rfac
);
995 do_real(iparams
->lj
.c6
);
996 do_real(iparams
->lj
.c12
);
999 do_real(iparams
->lj14
.c6A
);
1000 do_real(iparams
->lj14
.c12A
);
1001 do_real(iparams
->lj14
.c6B
);
1002 do_real(iparams
->lj14
.c12B
);
1005 do_real(iparams
->ljc14
.fqq
);
1006 do_real(iparams
->ljc14
.qi
);
1007 do_real(iparams
->ljc14
.qj
);
1008 do_real(iparams
->ljc14
.c6
);
1009 do_real(iparams
->ljc14
.c12
);
1011 case F_LJC_PAIRS_NB
:
1012 do_real(iparams
->ljcnb
.qi
);
1013 do_real(iparams
->ljcnb
.qj
);
1014 do_real(iparams
->ljcnb
.c6
);
1015 do_real(iparams
->ljcnb
.c12
);
1021 do_real(iparams
->pdihs
.phiA
);
1022 do_real(iparams
->pdihs
.cpA
);
1023 if ((ftype
== F_ANGRES
|| ftype
== F_ANGRESZ
) && file_version
< 42) {
1024 /* Read the incorrectly stored multiplicity */
1025 do_real(iparams
->harmonic
.rB
);
1026 do_real(iparams
->harmonic
.krB
);
1027 iparams
->pdihs
.phiB
= iparams
->pdihs
.phiA
;
1028 iparams
->pdihs
.cpB
= iparams
->pdihs
.cpA
;
1030 do_real(iparams
->pdihs
.phiB
);
1031 do_real(iparams
->pdihs
.cpB
);
1032 do_int (iparams
->pdihs
.mult
);
1036 do_int (iparams
->disres
.label
);
1037 do_int (iparams
->disres
.type
);
1038 do_real(iparams
->disres
.low
);
1039 do_real(iparams
->disres
.up1
);
1040 do_real(iparams
->disres
.up2
);
1041 do_real(iparams
->disres
.kfac
);
1044 do_int (iparams
->orires
.ex
);
1045 do_int (iparams
->orires
.label
);
1046 do_int (iparams
->orires
.power
);
1047 do_real(iparams
->orires
.c
);
1048 do_real(iparams
->orires
.obs
);
1049 do_real(iparams
->orires
.kfac
);
1052 do_int (iparams
->dihres
.power
);
1053 do_int (iparams
->dihres
.label
);
1054 do_real(iparams
->dihres
.phi
);
1055 do_real(iparams
->dihres
.dphi
);
1056 do_real(iparams
->dihres
.kfac
);
1059 do_rvec(iparams
->posres
.pos0A
);
1060 do_rvec(iparams
->posres
.fcA
);
1061 if (bRead
&& file_version
< 27) {
1062 copy_rvec(iparams
->posres
.pos0A
,iparams
->posres
.pos0B
);
1063 copy_rvec(iparams
->posres
.fcA
,iparams
->posres
.fcB
);
1065 do_rvec(iparams
->posres
.pos0B
);
1066 do_rvec(iparams
->posres
.fcB
);
1070 ndo_real(iparams
->rbdihs
.rbcA
,NR_RBDIHS
,bDum
);
1071 if(file_version
>=25)
1072 ndo_real(iparams
->rbdihs
.rbcB
,NR_RBDIHS
,bDum
);
1075 /* Fourier dihedrals are internally represented
1076 * as Ryckaert-Bellemans since those are faster to compute.
1078 ndo_real(iparams
->rbdihs
.rbcA
, NR_RBDIHS
, bDum
);
1079 ndo_real(iparams
->rbdihs
.rbcB
, NR_RBDIHS
, bDum
);
1083 do_real(iparams
->constr
.dA
);
1084 do_real(iparams
->constr
.dB
);
1087 do_real(iparams
->settle
.doh
);
1088 do_real(iparams
->settle
.dhh
);
1091 do_real(iparams
->vsite
.a
);
1096 do_real(iparams
->vsite
.a
);
1097 do_real(iparams
->vsite
.b
);
1102 do_real(iparams
->vsite
.a
);
1103 do_real(iparams
->vsite
.b
);
1104 do_real(iparams
->vsite
.c
);
1107 do_int (iparams
->vsiten
.n
);
1108 do_real(iparams
->vsiten
.a
);
1113 /* We got rid of some parameters in version 68 */
1114 if(bRead
&& file_version
<68)
1121 do_real(iparams
->gb
.sar
);
1122 do_real(iparams
->gb
.st
);
1123 do_real(iparams
->gb
.pi
);
1124 do_real(iparams
->gb
.gbr
);
1125 do_real(iparams
->gb
.bmlt
);
1128 do_int(iparams
->cmap
.cmapA
);
1129 do_int(iparams
->cmap
.cmapB
);
1132 gmx_fatal(FARGS
,"unknown function type %d (%s) in %s line %d",
1134 ftype
,interaction_function
[ftype
].name
,__FILE__
,__LINE__
);
1140 static void do_ilist(t_ilist
*ilist
,bool bRead
,int file_version
,
1147 set_comment(interaction_function
[ftype
].name
);
1149 if (file_version
< 44) {
1150 for(i
=0; i
<MAXNODES
; i
++)
1155 snew(ilist
->iatoms
,ilist
->nr
);
1156 ndo_int(ilist
->iatoms
,ilist
->nr
,bDum
);
1161 static void do_ffparams(gmx_ffparams_t
*ffparams
,
1162 bool bRead
, int file_version
)
1167 do_int(ffparams
->atnr
);
1168 if (file_version
< 57) {
1171 do_int(ffparams
->ntypes
);
1173 fprintf(debug
,"ffparams->atnr = %d, ntypes = %d\n",
1174 ffparams
->atnr
,ffparams
->ntypes
);
1176 snew(ffparams
->functype
,ffparams
->ntypes
);
1177 snew(ffparams
->iparams
,ffparams
->ntypes
);
1179 /* Read/write all the function types */
1180 ndo_int(ffparams
->functype
,ffparams
->ntypes
,bDum
);
1182 pr_ivec(debug
,0,"functype",ffparams
->functype
,ffparams
->ntypes
,TRUE
);
1184 if (file_version
>= 66) {
1185 do_double(ffparams
->reppow
);
1187 ffparams
->reppow
= 12.0;
1190 if (file_version
>= 57) {
1191 do_real(ffparams
->fudgeQQ
);
1194 /* Check whether all these function types are supported by the code.
1195 * In practice the code is backwards compatible, which means that the
1196 * numbering may have to be altered from old numbering to new numbering
1198 for (i
=0; (i
<ffparams
->ntypes
); i
++) {
1200 /* Loop over file versions */
1201 for (k
=0; (k
<NFTUPD
); k
++)
1202 /* Compare the read file_version to the update table */
1203 if ((file_version
< ftupd
[k
].fvnr
) &&
1204 (ffparams
->functype
[i
] >= ftupd
[k
].ftype
)) {
1205 ffparams
->functype
[i
] += 1;
1207 fprintf(debug
,"Incrementing function type %d to %d (due to %s)\n",
1208 i
,ffparams
->functype
[i
],
1209 interaction_function
[ftupd
[k
].ftype
].longname
);
1214 do_iparams(ffparams
->functype
[i
],&ffparams
->iparams
[i
],bRead
,file_version
);
1216 pr_iparams(debug
,ffparams
->functype
[i
],&ffparams
->iparams
[i
]);
1220 static void do_ilists(t_ilist
*ilist
,bool bRead
, int file_version
)
1222 int i
,j
,k
,renum
[F_NRE
];
1223 bool bDum
=TRUE
,bClear
;
1225 for(j
=0; (j
<F_NRE
); j
++) {
1228 for (k
=0; k
<NFTUPD
; k
++)
1229 if ((file_version
< ftupd
[k
].fvnr
) && (j
== ftupd
[k
].ftype
))
1233 ilist
[j
].iatoms
= NULL
;
1235 do_ilist(&ilist
[j
],bRead
,file_version
,j
);
1238 if (bRead && gmx_debug_at)
1239 pr_ilist(debug,0,interaction_function[j].longname,
1240 functype,&ilist[j],TRUE);
1245 static void do_idef(gmx_ffparams_t
*ffparams
,gmx_moltype_t
*molt
,
1246 bool bRead
, int file_version
)
1248 do_ffparams(ffparams
,bRead
,file_version
);
1250 if (file_version
>= 54) {
1251 do_real(ffparams
->fudgeQQ
);
1254 do_ilists(molt
->ilist
,bRead
,file_version
);
1257 static void do_block(t_block
*block
,bool bRead
,int file_version
)
1259 int i
,idum
,dum_nra
,*dum_a
;
1262 if (file_version
< 44)
1263 for(i
=0; i
<MAXNODES
; i
++)
1266 if (file_version
< 51)
1269 block
->nalloc_index
= block
->nr
+1;
1270 snew(block
->index
,block
->nalloc_index
);
1272 ndo_int(block
->index
,block
->nr
+1,bDum
);
1274 if (file_version
< 51 && dum_nra
> 0) {
1275 snew(dum_a
,dum_nra
);
1276 ndo_int(dum_a
,dum_nra
,bDum
);
1281 static void do_blocka(t_blocka
*block
,bool bRead
,int file_version
)
1286 if (file_version
< 44)
1287 for(i
=0; i
<MAXNODES
; i
++)
1290 do_int (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 ndo_int(block
->index
,block
->nr
+1,bDum
);
1298 ndo_int(block
->a
,block
->nra
,bDum
);
1301 static void do_atom(t_atom
*atom
,int ngrp
,bool bRead
, int file_version
,
1302 gmx_groups_t
*groups
,int atnr
)
1310 do_ushort(atom
->type
);
1311 do_ushort(atom
->typeB
);
1312 do_int (atom
->ptype
);
1313 do_int (atom
->resind
);
1314 if (file_version
>= 52)
1315 do_int(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 do_nuchar(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(int ngrp
,t_grps grps
[],bool bRead
, int file_version
)
1343 if (file_version
< 23)
1345 else if (file_version
< 39)
1350 for(j
=0; (j
<ngrp
); j
++) {
1352 do_int (grps
[j
].nr
);
1354 snew(grps
[j
].nm_ind
,grps
[j
].nr
);
1355 ndo_int(grps
[j
].nm_ind
,grps
[j
].nr
,bDum
);
1359 snew(grps
[j
].nm_ind
,grps
[j
].nr
);
1364 static void do_symstr(char ***nm
,bool bRead
,t_symtab
*symtab
)
1370 *nm
= get_symtab_handle(symtab
,ls
);
1373 ls
= lookup_symtab(symtab
,*nm
);
1378 static void do_strstr(int nstr
,char ***nm
,bool bRead
,t_symtab
*symtab
)
1382 for (j
=0; (j
<nstr
); j
++)
1383 do_symstr(&(nm
[j
]),bRead
,symtab
);
1386 static void do_resinfo(int n
,t_resinfo
*ri
,bool bRead
,t_symtab
*symtab
,
1391 for (j
=0; (j
<n
); j
++) {
1392 do_symstr(&(ri
[j
].name
),bRead
,symtab
);
1393 if (file_version
>= 63) {
1403 static void do_atoms(t_atoms
*atoms
,bool bRead
,t_symtab
*symtab
,
1405 gmx_groups_t
*groups
)
1410 do_int(atoms
->nres
);
1411 if (file_version
< 57) {
1412 do_int(groups
->ngrpname
);
1413 for(i
=0; i
<egcNR
; i
++) {
1414 groups
->ngrpnr
[i
] = atoms
->nr
;
1415 snew(groups
->grpnr
[i
],groups
->ngrpnr
[i
]);
1419 snew(atoms
->atom
,atoms
->nr
);
1420 snew(atoms
->atomname
,atoms
->nr
);
1421 snew(atoms
->atomtype
,atoms
->nr
);
1422 snew(atoms
->atomtypeB
,atoms
->nr
);
1423 snew(atoms
->resinfo
,atoms
->nres
);
1424 if (file_version
< 57) {
1425 snew(groups
->grpname
,groups
->ngrpname
);
1427 atoms
->pdbinfo
= NULL
;
1429 for(i
=0; (i
<atoms
->nr
); i
++) {
1430 do_atom(&atoms
->atom
[i
],egcNR
,bRead
, file_version
,groups
,i
);
1432 do_strstr(atoms
->nr
,atoms
->atomname
,bRead
,symtab
);
1433 if (bRead
&& (file_version
<= 20)) {
1434 for(i
=0; i
<atoms
->nr
; i
++) {
1435 atoms
->atomtype
[i
] = put_symtab(symtab
,"?");
1436 atoms
->atomtypeB
[i
] = put_symtab(symtab
,"?");
1439 do_strstr(atoms
->nr
,atoms
->atomtype
,bRead
,symtab
);
1440 do_strstr(atoms
->nr
,atoms
->atomtypeB
,bRead
,symtab
);
1442 do_resinfo(atoms
->nres
,atoms
->resinfo
,bRead
,symtab
,file_version
);
1444 if (file_version
< 57) {
1445 do_strstr(groups
->ngrpname
,groups
->grpname
,bRead
,symtab
);
1447 do_grps(egcNR
,groups
->grps
,bRead
,file_version
);
1451 static void do_groups(gmx_groups_t
*groups
,
1452 bool bRead
,t_symtab
*symtab
,
1458 do_grps(egcNR
,groups
->grps
,bRead
,file_version
);
1459 do_int(groups
->ngrpname
);
1461 snew(groups
->grpname
,groups
->ngrpname
);
1463 do_strstr(groups
->ngrpname
,groups
->grpname
,bRead
,symtab
);
1464 for(g
=0; g
<egcNR
; g
++) {
1465 do_int(groups
->ngrpnr
[g
]);
1466 if (groups
->ngrpnr
[g
] == 0) {
1468 groups
->grpnr
[g
] = NULL
;
1472 snew(groups
->grpnr
[g
],groups
->ngrpnr
[g
]);
1474 ndo_nuchar(groups
->grpnr
[g
],groups
->ngrpnr
[g
],bDum
);
1479 static void do_atomtypes(t_atomtypes
*atomtypes
,bool bRead
,
1480 t_symtab
*symtab
,int file_version
)
1485 if (file_version
> 25) {
1486 do_int(atomtypes
->nr
);
1489 snew(atomtypes
->radius
,j
);
1490 snew(atomtypes
->vol
,j
);
1491 snew(atomtypes
->surftens
,j
);
1492 snew(atomtypes
->atomnumber
,j
);
1493 snew(atomtypes
->gb_radius
,j
);
1494 snew(atomtypes
->S_hct
,j
);
1496 ndo_real(atomtypes
->radius
,j
,bDum
);
1497 ndo_real(atomtypes
->vol
,j
,bDum
);
1498 ndo_real(atomtypes
->surftens
,j
,bDum
);
1499 if(file_version
>= 40)
1501 ndo_int(atomtypes
->atomnumber
,j
,bDum
);
1503 if(file_version
>= 60)
1505 ndo_real(atomtypes
->gb_radius
,j
,bDum
);
1506 ndo_real(atomtypes
->S_hct
,j
,bDum
);
1509 /* File versions prior to 26 cannot do GBSA,
1510 * so they dont use this structure
1513 atomtypes
->radius
= NULL
;
1514 atomtypes
->vol
= NULL
;
1515 atomtypes
->surftens
= NULL
;
1516 atomtypes
->atomnumber
= NULL
;
1517 atomtypes
->gb_radius
= NULL
;
1518 atomtypes
->S_hct
= NULL
;
1522 static void do_symtab(t_symtab
*symtab
,bool bRead
)
1531 snew(symtab
->symbuf
,1);
1532 symbuf
= symtab
->symbuf
;
1533 symbuf
->bufsize
= nr
;
1534 snew(symbuf
->buf
,nr
);
1535 for (i
=0; (i
<nr
); i
++) {
1537 symbuf
->buf
[i
]=strdup(buf
);
1541 symbuf
= symtab
->symbuf
;
1542 while (symbuf
!=NULL
) {
1543 for (i
=0; (i
<symbuf
->bufsize
) && (i
<nr
); i
++)
1544 do_string(symbuf
->buf
[i
]);
1546 symbuf
=symbuf
->next
;
1549 gmx_fatal(FARGS
,"nr of symtab strings left: %d",nr
);
1554 do_cmap(gmx_cmap_t
*cmap_grid
, bool bRead
)
1556 int i
,j
,ngrid
,gs
,nelem
;
1558 do_int(cmap_grid
->ngrid
);
1559 do_int(cmap_grid
->grid_spacing
);
1561 ngrid
= cmap_grid
->ngrid
;
1562 gs
= cmap_grid
->grid_spacing
;
1567 snew(cmap_grid
->cmapdata
,ngrid
);
1569 for(i
=0;i
<cmap_grid
->ngrid
;i
++)
1571 snew(cmap_grid
->cmapdata
[i
].cmap
,4*nelem
);
1575 for(i
=0;i
<cmap_grid
->ngrid
;i
++)
1577 for(j
=0;j
<nelem
;j
++)
1579 do_real(cmap_grid
->cmapdata
[i
].cmap
[j
*4]);
1580 do_real(cmap_grid
->cmapdata
[i
].cmap
[j
*4+1]);
1581 do_real(cmap_grid
->cmapdata
[i
].cmap
[j
*4+2]);
1582 do_real(cmap_grid
->cmapdata
[i
].cmap
[j
*4+3]);
1589 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(gmx_moltype_t
*molt
,bool bRead
,t_symtab
*symtab
,
1617 gmx_groups_t
*groups
)
1621 if (file_version
>= 57) {
1622 do_symstr(&(molt
->name
),bRead
,symtab
);
1625 do_atoms(&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(molt
->ilist
,bRead
,file_version
);
1634 do_block(&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(&molt
->excls
, bRead
, file_version
);
1644 static void do_molblock(gmx_molblock_t
*molb
,bool bRead
,int file_version
)
1650 do_int(molb
->natoms_mol
);
1651 /* Position restraint coordinates */
1652 do_int(molb
->nposres_xA
);
1653 if (molb
->nposres_xA
> 0) {
1655 snew(molb
->posres_xA
,molb
->nposres_xA
);
1657 ndo_rvec(molb
->posres_xA
,molb
->nposres_xA
);
1659 do_int(molb
->nposres_xB
);
1660 if (molb
->nposres_xB
> 0) {
1662 snew(molb
->posres_xB
,molb
->nposres_xB
);
1664 ndo_rvec(molb
->posres_xB
,molb
->nposres_xB
);
1669 static t_block
mtop_mols(gmx_mtop_t
*mtop
)
1675 for(mb
=0; mb
<mtop
->nmolblock
; mb
++) {
1676 mols
.nr
+= mtop
->molblock
[mb
].nmol
;
1678 mols
.nalloc_index
= mols
.nr
+ 1;
1679 snew(mols
.index
,mols
.nalloc_index
);
1684 for(mb
=0; mb
<mtop
->nmolblock
; mb
++) {
1685 for(mol
=0; mol
<mtop
->molblock
[mb
].nmol
; mol
++) {
1686 a
+= mtop
->molblock
[mb
].natoms_mol
;
1695 static void add_posres_molblock(gmx_mtop_t
*mtop
)
1700 gmx_molblock_t
*molb
;
1703 il
= &mtop
->moltype
[0].ilist
[F_POSRES
];
1709 for(i
=0; i
<il
->nr
; i
+=2) {
1710 ip
= &mtop
->ffparams
.iparams
[il
->iatoms
[i
]];
1711 am
= max(am
,il
->iatoms
[i
+1]);
1712 if (ip
->posres
.pos0B
[XX
] != ip
->posres
.pos0A
[XX
] ||
1713 ip
->posres
.pos0B
[YY
] != ip
->posres
.pos0A
[YY
] ||
1714 ip
->posres
.pos0B
[ZZ
] != ip
->posres
.pos0A
[ZZ
]) {
1718 /* Make the posres coordinate block end at a molecule end */
1720 while(am
>= mtop
->mols
.index
[mol
+1]) {
1723 molb
= &mtop
->molblock
[0];
1724 molb
->nposres_xA
= mtop
->mols
.index
[mol
+1];
1725 snew(molb
->posres_xA
,molb
->nposres_xA
);
1727 molb
->nposres_xB
= molb
->nposres_xA
;
1728 snew(molb
->posres_xB
,molb
->nposres_xB
);
1730 molb
->nposres_xB
= 0;
1732 for(i
=0; i
<il
->nr
; i
+=2) {
1733 ip
= &mtop
->ffparams
.iparams
[il
->iatoms
[i
]];
1734 a
= il
->iatoms
[i
+1];
1735 molb
->posres_xA
[a
][XX
] = ip
->posres
.pos0A
[XX
];
1736 molb
->posres_xA
[a
][YY
] = ip
->posres
.pos0A
[YY
];
1737 molb
->posres_xA
[a
][ZZ
] = ip
->posres
.pos0A
[ZZ
];
1739 molb
->posres_xB
[a
][XX
] = ip
->posres
.pos0B
[XX
];
1740 molb
->posres_xB
[a
][YY
] = ip
->posres
.pos0B
[YY
];
1741 molb
->posres_xB
[a
][ZZ
] = ip
->posres
.pos0B
[ZZ
];
1746 static void set_disres_npair(gmx_mtop_t
*mtop
)
1753 ip
= mtop
->ffparams
.iparams
;
1755 for(mt
=0; mt
<mtop
->nmoltype
; mt
++) {
1756 il
= &mtop
->moltype
[mt
].ilist
[F_DISRES
];
1760 for(i
=0; i
<il
->nr
; i
+=3) {
1762 if (i
+3 == il
->nr
|| ip
[a
[i
]].disres
.label
!= ip
[a
[i
+3]].disres
.label
) {
1763 ip
[a
[i
]].disres
.npair
= npair
;
1771 static void do_mtop(gmx_mtop_t
*mtop
,bool bRead
, int file_version
)
1778 do_symtab(&(mtop
->symtab
),bRead
);
1780 pr_symtab(debug
,0,"symtab",&mtop
->symtab
);
1782 do_symstr(&(mtop
->name
),bRead
,&(mtop
->symtab
));
1784 if (file_version
>= 57) {
1785 do_ffparams(&mtop
->ffparams
,bRead
,file_version
);
1787 do_int(mtop
->nmoltype
);
1792 snew(mtop
->moltype
,mtop
->nmoltype
);
1793 if (file_version
< 57) {
1794 mtop
->moltype
[0].name
= mtop
->name
;
1797 for(mt
=0; mt
<mtop
->nmoltype
; mt
++) {
1798 do_moltype(&mtop
->moltype
[mt
],bRead
,&mtop
->symtab
,file_version
,
1802 if (file_version
>= 57) {
1803 do_int(mtop
->nmolblock
);
1805 mtop
->nmolblock
= 1;
1808 snew(mtop
->molblock
,mtop
->nmolblock
);
1810 if (file_version
>= 57) {
1811 for(mb
=0; mb
<mtop
->nmolblock
; mb
++) {
1812 do_molblock(&mtop
->molblock
[mb
],bRead
,file_version
);
1814 do_int(mtop
->natoms
);
1816 mtop
->molblock
[0].type
= 0;
1817 mtop
->molblock
[0].nmol
= 1;
1818 mtop
->molblock
[0].natoms_mol
= mtop
->moltype
[0].atoms
.nr
;
1819 mtop
->molblock
[0].nposres_xA
= 0;
1820 mtop
->molblock
[0].nposres_xB
= 0;
1823 do_atomtypes (&(mtop
->atomtypes
),bRead
,&(mtop
->symtab
), file_version
);
1825 pr_atomtypes(debug
,0,"atomtypes",&mtop
->atomtypes
,TRUE
);
1827 if (file_version
< 57) {
1828 /* Debug statements are inside do_idef */
1829 do_idef (&mtop
->ffparams
,&mtop
->moltype
[0],bRead
,file_version
);
1830 mtop
->natoms
= mtop
->moltype
[0].atoms
.nr
;
1833 if(file_version
>= 65)
1835 do_cmap(&mtop
->ffparams
.cmap_grid
,bRead
);
1839 mtop
->ffparams
.cmap_grid
.ngrid
= 0;
1840 mtop
->ffparams
.cmap_grid
.grid_spacing
= 0.1;
1841 mtop
->ffparams
.cmap_grid
.cmapdata
= NULL
;
1844 if (file_version
>= 57) {
1845 do_groups(&mtop
->groups
,bRead
,&(mtop
->symtab
),file_version
);
1848 if (file_version
< 57) {
1849 do_block(&mtop
->moltype
[0].cgs
,bRead
,file_version
);
1850 if (bRead
&& gmx_debug_at
) {
1851 pr_block(debug
,0,"cgs",&mtop
->moltype
[0].cgs
,TRUE
);
1853 do_block(&mtop
->mols
,bRead
,file_version
);
1854 /* Add the posres coordinates to the molblock */
1855 add_posres_molblock(mtop
);
1858 if (file_version
>= 57) {
1859 mtop
->mols
= mtop_mols(mtop
);
1862 pr_block(debug
,0,"mols",&mtop
->mols
,TRUE
);
1866 if (file_version
< 51) {
1867 /* Here used to be the shake blocks */
1868 do_blocka(&dumb
,bRead
,file_version
);
1876 close_symtab(&(mtop
->symtab
));
1880 /* If TopOnlyOK is TRUE then we can read even future versions
1881 * of tpx files, provided the file_generation hasn't changed.
1882 * If it is FALSE, we need the inputrecord too, and bail out
1883 * if the file is newer than the program.
1885 * The version and generation if the topology (see top of this file)
1886 * are returned in the two last arguments.
1888 * If possible, we will read the inputrec even when TopOnlyOK is TRUE.
1890 static void do_tpxheader(int fp
,bool bRead
,t_tpxheader
*tpx
, bool TopOnlyOK
,
1891 int *file_version
, int *file_generation
)
1900 gmx_fio_setdebug(fp
,bDebugMode());
1902 /* NEW! XDR tpb file */
1903 precision
= sizeof(real
);
1906 if (strncmp(buf
,"VERSION",7))
1907 gmx_fatal(FARGS
,"Can not read file %s,\n"
1908 " this file is from a Gromacs version which is older than 2.0\n"
1909 " Make a new one with grompp or use a gro or pdb file, if possible",
1910 gmx_fio_getname(fp
));
1912 bDouble
= (precision
== sizeof(double));
1913 if ((precision
!= sizeof(float)) && !bDouble
)
1914 gmx_fatal(FARGS
,"Unknown precision in file %s: real is %d bytes "
1915 "instead of %d or %d",
1916 gmx_fio_getname(fp
),precision
,sizeof(float),sizeof(double));
1917 gmx_fio_setprecision(fp
,bDouble
);
1918 fprintf(stderr
,"Reading file %s, %s (%s precision)\n",
1919 gmx_fio_getname(fp
),buf
,bDouble
? "double" : "single");
1922 do_string(GromacsVersion());
1923 bDouble
= (precision
== sizeof(double));
1924 gmx_fio_setprecision(fp
,bDouble
);
1927 fgen
= tpx_generation
;
1930 /* Check versions! */
1938 if(file_version
!=NULL
)
1939 *file_version
= fver
;
1940 if(file_generation
!=NULL
)
1941 *file_generation
= fgen
;
1944 if ((fver
<= tpx_incompatible_version
) ||
1945 ((fver
> tpx_version
) && !TopOnlyOK
) ||
1946 (fgen
> tpx_generation
))
1947 gmx_fatal(FARGS
,"reading tpx file (%s) version %d with version %d program",
1948 gmx_fio_getname(fp
),fver
,tpx_version
);
1950 do_section(eitemHEADER
,bRead
);
1951 do_int (tpx
->natoms
);
1960 do_real(tpx
->lambda
);
1968 if((fgen
> tpx_generation
)) {
1969 /* This can only happen if TopOnlyOK=TRUE */
1974 static int do_tpx(int fp
,bool bRead
,
1975 t_inputrec
*ir
,t_state
*state
,rvec
*f
,gmx_mtop_t
*mtop
,
1981 bool TopOnlyOK
,bDum
=TRUE
;
1982 int file_version
,file_generation
;
1989 tpx
.natoms
= state
->natoms
;
1990 tpx
.ngtc
= state
->ngtc
;
1991 tpx
.lambda
= state
->lambda
;
1992 tpx
.bIr
= (ir
!= NULL
);
1993 tpx
.bTop
= (mtop
!= NULL
);
1994 tpx
.bX
= (state
->x
!= NULL
);
1995 tpx
.bV
= (state
->v
!= NULL
);
1996 tpx
.bF
= (f
!= NULL
);
2000 TopOnlyOK
= (ir
==NULL
);
2002 do_tpxheader(fp
,bRead
,&tpx
,TopOnlyOK
,&file_version
,&file_generation
);
2006 state
->lambda
= tpx
.lambda
;
2007 /* The init_state calls initialize the Nose-Hoover xi integrals to zero */
2011 init_state(state
,0,tpx
.ngtc
,0,0); /* nose-hoover chains */ /* eventually, need to add nnhpres here? */
2012 state
->natoms
= tpx
.natoms
;
2013 state
->nalloc
= tpx
.natoms
;
2017 init_state(state
,tpx
.natoms
,tpx
.ngtc
,0,0); /* nose-hoover chains */
2021 #define do_test(b,p) if (bRead && (p!=NULL) && !b) gmx_fatal(FARGS,"No %s in %s",#p,gmx_fio_getname(fp))
2023 do_test(tpx
.bBox
,state
->box
);
2024 do_section(eitemBOX
,bRead
);
2026 ndo_rvec(state
->box
,DIM
);
2027 if (file_version
>= 51) {
2028 ndo_rvec(state
->box_rel
,DIM
);
2030 /* We initialize box_rel after reading the inputrec */
2031 clear_mat(state
->box_rel
);
2033 if (file_version
>= 28) {
2034 ndo_rvec(state
->boxv
,DIM
);
2035 if (file_version
< 56) {
2042 if (state
->ngtc
> 0 && file_version
>= 28) {
2044 /*ndo_double(state->nosehoover_xi,state->ngtc,bDum);*/
2045 /*ndo_double(state->nosehoover_vxi,state->ngtc,bDum);*/
2046 /*ndo_double(state->therm_integral,state->ngtc,bDum);*/
2047 snew(dumv
,state
->ngtc
);
2048 if (file_version
< 69) {
2049 ndo_real(dumv
,state
->ngtc
,bDum
);
2051 /* These used to be the Berendsen tcoupl_lambda's */
2052 ndo_real(dumv
,state
->ngtc
,bDum
);
2056 /* Prior to tpx version 26, the inputrec was here.
2057 * I moved it to enable partial forward-compatibility
2058 * for analysis/viewer programs.
2060 if(file_version
<26) {
2061 do_test(tpx
.bIr
,ir
);
2062 do_section(eitemIR
,bRead
);
2065 do_inputrec(ir
,bRead
,file_version
,mtop
? &mtop
->ffparams
.fudgeQQ
: NULL
);
2067 pr_inputrec(debug
,0,"inputrec",ir
,FALSE
);
2070 do_inputrec(&dum_ir
,bRead
,file_version
,mtop
? &mtop
->ffparams
.fudgeQQ
:NULL
);
2072 pr_inputrec(debug
,0,"inputrec",&dum_ir
,FALSE
);
2073 done_inputrec(&dum_ir
);
2079 do_test(tpx
.bTop
,mtop
);
2080 do_section(eitemTOP
,bRead
);
2083 do_mtop(mtop
,bRead
, file_version
);
2085 do_mtop(&dum_top
,bRead
,file_version
);
2086 done_mtop(&dum_top
,TRUE
);
2089 do_test(tpx
.bX
,state
->x
);
2090 do_section(eitemX
,bRead
);
2093 state
->flags
|= (1<<estX
);
2095 ndo_rvec(state
->x
,state
->natoms
);
2098 do_test(tpx
.bV
,state
->v
);
2099 do_section(eitemV
,bRead
);
2102 state
->flags
|= (1<<estV
);
2104 ndo_rvec(state
->v
,state
->natoms
);
2108 do_section(eitemF
,bRead
);
2109 if (tpx
.bF
) ndo_rvec(f
,state
->natoms
);
2111 /* Starting with tpx version 26, we have the inputrec
2112 * at the end of the file, so we can ignore it
2113 * if the file is never than the software (but still the
2114 * same generation - see comments at the top of this file.
2119 bPeriodicMols
= FALSE
;
2120 if (file_version
>= 26) {
2121 do_test(tpx
.bIr
,ir
);
2122 do_section(eitemIR
,bRead
);
2124 if (file_version
>= 53) {
2125 /* Removed the pbc info from do_inputrec, since we always want it */
2128 bPeriodicMols
= ir
->bPeriodicMols
;
2131 do_int(bPeriodicMols
);
2133 if (file_generation
<= tpx_generation
&& ir
) {
2134 do_inputrec(ir
,bRead
,file_version
,mtop
? &mtop
->ffparams
.fudgeQQ
: NULL
);
2136 pr_inputrec(debug
,0,"inputrec",ir
,FALSE
);
2137 if (file_version
< 51)
2138 set_box_rel(ir
,state
);
2139 if (file_version
< 53) {
2141 bPeriodicMols
= ir
->bPeriodicMols
;
2144 if (bRead
&& ir
&& file_version
>= 53) {
2145 /* We need to do this after do_inputrec, since that initializes ir */
2147 ir
->bPeriodicMols
= bPeriodicMols
;
2156 if (state
->ngtc
== 0)
2158 /* Reading old version without tcoupl state data: set it */
2159 init_gtc_state(state
,ir
->opts
.ngtc
,0,ir
->opts
.nhchainlength
);
2161 if (tpx
.bTop
&& mtop
)
2163 if (file_version
< 57)
2165 if (mtop
->moltype
[0].ilist
[F_DISRES
].nr
> 0)
2167 ir
->eDisre
= edrSimple
;
2171 ir
->eDisre
= edrNone
;
2174 set_disres_npair(mtop
);
2178 if (tpx
.bTop
&& mtop
)
2180 gmx_mtop_finalize(mtop
);
2183 if (file_version
>= 57)
2187 env
= getenv("GMX_NOCHARGEGROUPS");
2190 sscanf(env
,"%d",&ienv
);
2191 fprintf(stderr
,"\nFound env.var. GMX_NOCHARGEGROUPS = %d\n",
2196 "Will make single atomic charge groups in non-solvent%s\n",
2197 ienv
> 1 ? " and solvent" : "");
2198 gmx_mtop_make_atomic_charge_groups(mtop
,ienv
==1);
2200 fprintf(stderr
,"\n");
2208 /************************************************************
2210 * The following routines are the exported ones
2212 ************************************************************/
2214 int open_tpx(const char *fn
,const char *mode
)
2216 return gmx_fio_open(fn
,mode
);
2219 void close_tpx(int fp
)
2224 void read_tpxheader(const char *fn
, t_tpxheader
*tpx
, bool TopOnlyOK
,
2225 int *file_version
, int *file_generation
)
2229 fp
= open_tpx(fn
,"r");
2230 do_tpxheader(fp
,TRUE
,tpx
,TopOnlyOK
,file_version
,file_generation
);
2234 void write_tpx_state(const char *fn
,
2235 t_inputrec
*ir
,t_state
*state
,gmx_mtop_t
*mtop
)
2239 fp
= open_tpx(fn
,"w");
2240 do_tpx(fp
,FALSE
,ir
,state
,NULL
,mtop
,FALSE
);
2244 void read_tpx_state(const char *fn
,
2245 t_inputrec
*ir
,t_state
*state
,rvec
*f
,gmx_mtop_t
*mtop
)
2249 fp
= open_tpx(fn
,"r");
2250 do_tpx(fp
,TRUE
,ir
,state
,f
,mtop
,FALSE
);
2254 int read_tpx(const char *fn
,
2255 t_inputrec
*ir
, matrix box
,int *natoms
,
2256 rvec
*x
,rvec
*v
,rvec
*f
,gmx_mtop_t
*mtop
)
2264 fp
= open_tpx(fn
,"r");
2265 ePBC
= do_tpx(fp
,TRUE
,ir
,&state
,f
,mtop
,TRUE
);
2267 *natoms
= state
.natoms
;
2269 copy_mat(state
.box
,box
);
2277 int read_tpx_top(const char *fn
,
2278 t_inputrec
*ir
, matrix box
,int *natoms
,
2279 rvec
*x
,rvec
*v
,rvec
*f
,t_topology
*top
)
2285 ePBC
= read_tpx(fn
,ir
,box
,natoms
,x
,v
,f
,&mtop
);
2287 *top
= gmx_mtop_t_to_t_topology(&mtop
);
2292 bool fn2bTPX(const char *file
)
2294 switch (fn2ftp(file
)) {
2304 bool read_tps_conf(const char *infile
,char *title
,t_topology
*top
,int *ePBC
,
2305 rvec
**x
,rvec
**v
,matrix box
,bool bMass
)
2308 int natoms
,i
,version
,generation
;
2311 t_topology
*topconv
;
2314 bTop
= fn2bTPX(infile
);
2317 read_tpxheader(infile
,&header
,TRUE
,&version
,&generation
);
2319 snew(*x
,header
.natoms
);
2321 snew(*v
,header
.natoms
);
2323 *ePBC
= read_tpx(infile
,NULL
,box
,&natoms
,
2324 (x
==NULL
) ? NULL
: *x
,(v
==NULL
) ? NULL
: *v
,NULL
,mtop
);
2325 *top
= gmx_mtop_t_to_t_topology(mtop
);
2327 strcpy(title
,*top
->name
);
2328 tpx_make_chain_identifiers(&top
->atoms
,&top
->mols
);
2331 get_stx_coordnum(infile
,&natoms
);
2332 init_t_atoms(&top
->atoms
,natoms
,FALSE
);
2333 bXNULL
= (x
== NULL
);
2337 read_stx_conf(infile
,title
,&top
->atoms
,*x
,(v
==NULL
) ? NULL
: *v
,ePBC
,box
);
2343 aps
= gmx_atomprop_init();
2344 for(i
=0; (i
<natoms
); i
++)
2345 if (!gmx_atomprop_query(aps
,epropMass
,
2346 *top
->atoms
.resinfo
[top
->atoms
.atom
[i
].resind
].name
,
2347 *top
->atoms
.atomname
[i
],
2348 &(top
->atoms
.atom
[i
].m
))) {
2350 fprintf(debug
,"Can not find mass for atom %s %d %s, setting to 1\n",
2351 *top
->atoms
.resinfo
[top
->atoms
.atom
[i
].resind
].name
,
2352 top
->atoms
.resinfo
[top
->atoms
.atom
[i
].resind
].nr
,
2353 *top
->atoms
.atomname
[i
]);
2355 gmx_atomprop_destroy(aps
);
2357 top
->idef
.ntypes
=-1;