2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
44 #include "gmx_fatal.h"
45 #include "gromacs/utility/smalloc.h"
52 /* The source code in this file should be thread-safe.
53 Please keep it that way. */
55 /* This number should be increased whenever the file format changes! */
56 static const int enx_version = 5;
58 const char *enx_block_id_name[] = {
59 "Averaged orientation restraints",
60 "Instantaneous orientation restraints",
61 "Orientation restraint order tensor(s)",
62 "Distance restraints",
69 /* Stuff for reading pre 4.1 energy files */
71 gmx_bool bOldFileOpen; /* Is this an open old file? */
72 gmx_bool bReadFirstStep; /* Did we read the first step? */
73 int first_step; /* First step in the energy file */
74 int step_prev; /* Previous step */
75 int nsum_prev; /* Previous step sum length */
76 t_energy *ener_prev; /* Previous energy sums */
87 static void enxsubblock_init(t_enxsubblock *sb)
91 sb->type = xdr_datatype_double;
93 sb->type = xdr_datatype_float;
109 static void enxsubblock_free(t_enxsubblock *sb)
145 for (i = 0; i < sb->sval_alloc; i++)
158 /* allocate the appropriate amount of memory for the given type and nr */
159 static void enxsubblock_alloc(t_enxsubblock *sb)
161 /* allocate the appropriate amount of memory */
164 case xdr_datatype_float:
165 if (sb->nr > sb->fval_alloc)
167 srenew(sb->fval, sb->nr);
168 sb->fval_alloc = sb->nr;
171 case xdr_datatype_double:
172 if (sb->nr > sb->dval_alloc)
174 srenew(sb->dval, sb->nr);
175 sb->dval_alloc = sb->nr;
178 case xdr_datatype_int:
179 if (sb->nr > sb->ival_alloc)
181 srenew(sb->ival, sb->nr);
182 sb->ival_alloc = sb->nr;
185 case xdr_datatype_int64:
186 if (sb->nr > sb->lval_alloc)
188 srenew(sb->lval, sb->nr);
189 sb->lval_alloc = sb->nr;
192 case xdr_datatype_char:
193 if (sb->nr > sb->cval_alloc)
195 srenew(sb->cval, sb->nr);
196 sb->cval_alloc = sb->nr;
199 case xdr_datatype_string:
200 if (sb->nr > sb->sval_alloc)
204 srenew(sb->sval, sb->nr);
205 for (i = sb->sval_alloc; i < sb->nr; i++)
209 sb->sval_alloc = sb->nr;
213 gmx_incons("Unknown block type: this file is corrupted or from the future");
217 static void enxblock_init(t_enxblock *eb)
225 static void enxblock_free(t_enxblock *eb)
227 if (eb->nsub_alloc > 0)
230 for (i = 0; i < eb->nsub_alloc; i++)
232 enxsubblock_free(&(eb->sub[i]));
240 void init_enxframe(t_enxframe *fr)
251 fr->nblock_alloc = 0;
256 void free_enxframe(t_enxframe *fr)
264 for (b = 0; b < fr->nblock_alloc; b++)
266 enxblock_free(&(fr->block[b]));
271 void add_blocks_enxframe(t_enxframe *fr, int n)
274 if (n > fr->nblock_alloc)
278 srenew(fr->block, n);
279 for (b = fr->nblock_alloc; b < fr->nblock; b++)
281 enxblock_init(&(fr->block[b]));
283 fr->nblock_alloc = n;
287 t_enxblock *find_block_id_enxframe(t_enxframe *ef, int id, t_enxblock *prev)
289 gmx_off_t starti = 0;
294 starti = (prev - ef->block) + 1;
296 for (i = starti; i < ef->nblock; i++)
298 if (ef->block[i].id == id)
300 return &(ef->block[i]);
306 void add_subblocks_enxblock(t_enxblock *eb, int n)
309 if (eb->nsub > eb->nsub_alloc)
314 for (b = eb->nsub_alloc; b < n; b++)
316 enxsubblock_init(&(eb->sub[b]));
322 static void enx_warning(const char *msg)
324 if (getenv("GMX_ENX_NO_FATAL") != NULL)
330 gmx_fatal(FARGS, "%s\n%s",
332 "If you want to use the correct frames before the corrupted frame and avoid this fatal error set the env.var. GMX_ENX_NO_FATAL");
336 static void edr_strings(XDR *xdr, gmx_bool bRead, int file_version,
337 int n, gmx_enxnm_t **nms)
346 for (i = 0; i < n; i++)
362 if (!xdr_string(xdr, &(nm->name), STRLEN))
364 gmx_file("Cannot write energy names to file; maybe you are out of disk space?");
366 if (file_version >= 2)
368 if (!xdr_string(xdr, &(nm->unit), STRLEN))
370 gmx_file("Cannot write energy names to file; maybe you are out of disk space?");
375 nm->unit = strdup("kJ/mol");
380 void do_enxnms(ener_file_t ef, int *nre, gmx_enxnm_t **nms)
384 gmx_bool bRead = gmx_fio_getread(ef->fio);
388 gmx_fio_checktype(ef->fio);
390 xdr = gmx_fio_getxdr(ef->fio);
392 if (!xdr_int(xdr, &magic))
396 gmx_file("Cannot write energy names to file; maybe you are out of disk space?");
403 /* Assume this is an old edr format */
406 ef->eo.bOldFileOpen = TRUE;
407 ef->eo.bReadFirstStep = FALSE;
408 srenew(ef->eo.ener_prev, *nre);
412 ef->eo.bOldFileOpen = FALSE;
416 gmx_fatal(FARGS, "Energy names magic number mismatch, this is not a GROMACS edr file");
418 file_version = enx_version;
419 xdr_int(xdr, &file_version);
420 if (file_version > enx_version)
422 gmx_fatal(FARGS, "reading tpx file (%s) version %d with version %d program", gmx_fio_getname(ef->fio), file_version, enx_version);
426 if (file_version != enx_version)
428 fprintf(stderr, "Note: enx file_version %d, software version %d\n",
429 file_version, enx_version);
432 edr_strings(xdr, bRead, file_version, *nre, nms);
435 static gmx_bool do_eheader(ener_file_t ef, int *file_version, t_enxframe *fr,
436 int nre_test, gmx_bool *bWrongPrecision, gmx_bool *bOK)
438 int magic = -7777777;
439 real first_real_to_check;
440 int b, i, zero = 0, dum = 0;
441 gmx_bool bRead = gmx_fio_getread(ef->fio);
446 xdr_datatype dtreal = xdr_datatype_float;
448 xdr_datatype dtreal = xdr_datatype_double;
453 *bWrongPrecision = FALSE;
457 /* The original energy frame started with a real,
458 * so we have to use a real for compatibility.
459 * This is VERY DIRTY code, since do_eheader can be called
460 * with the wrong precision set and then we could read r > -1e10,
461 * while actually the intention was r < -1e10.
462 * When nre_test >= 0, do_eheader should therefore terminate
463 * before the number of i/o calls starts depending on what has been read
464 * (which is the case for for instance the block sizes for variable
465 * number of blocks, where this number is read before).
467 first_real_to_check = -2e10;
468 if (!gmx_fio_do_real(ef->fio, first_real_to_check))
472 if (first_real_to_check > -1e10)
474 /* Assume we are reading an old format */
476 fr->t = first_real_to_check;
477 if (!gmx_fio_do_int(ef->fio, dum))
485 if (!gmx_fio_do_int(ef->fio, magic))
489 if (magic != -7777777)
491 enx_warning("Energy header magic number mismatch, this is not a GROMACS edr file");
495 *file_version = enx_version;
496 if (!gmx_fio_do_int(ef->fio, *file_version))
500 if (*bOK && *file_version > enx_version)
502 gmx_fatal(FARGS, "reading tpx file (%s) version %d with version %d program", gmx_fio_getname(ef->fio), file_version, enx_version);
504 if (!gmx_fio_do_double(ef->fio, fr->t))
508 if (!gmx_fio_do_int64(ef->fio, fr->step))
512 if (!bRead && fr->nsum == 1)
514 /* Do not store sums of length 1,
515 * since this does not add information.
517 if (!gmx_fio_do_int(ef->fio, zero))
524 if (!gmx_fio_do_int(ef->fio, fr->nsum))
529 if (*file_version >= 3)
531 if (!gmx_fio_do_int64(ef->fio, fr->nsteps))
538 fr->nsteps = max(1, fr->nsum);
540 if (*file_version >= 5)
542 if (!gmx_fio_do_double(ef->fio, fr->dt))
552 if (!gmx_fio_do_int(ef->fio, fr->nre))
556 if (*file_version < 4)
558 if (!gmx_fio_do_int(ef->fio, ndisre))
565 /* now reserved for possible future use */
566 if (!gmx_fio_do_int(ef->fio, dum))
572 if (!gmx_fio_do_int(ef->fio, fr->nblock))
583 if (*file_version >= 4)
585 enx_warning("Distance restraint blocks in old style in new style file");
593 /* Frames could have nre=0, so we can not rely only on the fr->nre check */
594 if (bRead && nre_test >= 0 &&
595 ((fr->nre > 0 && fr->nre != nre_test) ||
596 fr->nre < 0 || ndisre < 0 || fr->nblock < 0))
598 *bWrongPrecision = TRUE;
602 /* we now know what these should be, or we've already bailed out because
603 of wrong precision */
604 if (*file_version == 1 && (fr->t < 0 || fr->t > 1e20 || fr->step < 0 ) )
606 enx_warning("edr file with negative step number or unreasonable time (and without version number).");
614 add_blocks_enxframe(fr, fr->nblock);
620 /* sub[0] is the instantaneous data, sub[1] is time averaged */
621 add_subblocks_enxblock(&(fr->block[0]), 2);
622 fr->block[0].id = enxDISRE;
623 fr->block[0].sub[0].nr = ndisre;
624 fr->block[0].sub[1].nr = ndisre;
625 fr->block[0].sub[0].type = dtreal;
626 fr->block[0].sub[1].type = dtreal;
630 /* read block header info */
631 for (b = startb; b < fr->nblock; b++)
633 if (*file_version < 4)
635 /* blocks in old version files always have 1 subblock that
636 consists of reals. */
641 add_subblocks_enxblock(&(fr->block[b]), 1);
645 if (fr->block[b].nsub != 1)
647 gmx_incons("Writing an old version .edr file with too many subblocks");
649 if (fr->block[b].sub[0].type != dtreal)
651 gmx_incons("Writing an old version .edr file the wrong subblock type");
654 nrint = fr->block[b].sub[0].nr;
656 if (!gmx_fio_do_int(ef->fio, nrint))
660 fr->block[b].id = b - startb;
661 fr->block[b].sub[0].nr = nrint;
662 fr->block[b].sub[0].type = dtreal;
667 /* in the new version files, the block header only contains
668 the ID and the number of subblocks */
669 int nsub = fr->block[b].nsub;
670 *bOK = *bOK && gmx_fio_do_int(ef->fio, fr->block[b].id);
671 *bOK = *bOK && gmx_fio_do_int(ef->fio, nsub);
673 fr->block[b].nsub = nsub;
676 add_subblocks_enxblock(&(fr->block[b]), nsub);
679 /* read/write type & size for each subblock */
680 for (i = 0; i < nsub; i++)
682 t_enxsubblock *sub = &(fr->block[b].sub[i]); /* shortcut */
683 int typenr = sub->type;
685 *bOK = *bOK && gmx_fio_do_int(ef->fio, typenr);
686 *bOK = *bOK && gmx_fio_do_int(ef->fio, sub->nr);
688 sub->type = (xdr_datatype)typenr;
692 if (!gmx_fio_do_int(ef->fio, fr->e_size))
697 /* now reserved for possible future use */
698 if (!gmx_fio_do_int(ef->fio, dum))
703 /* Do a dummy int to keep the format compatible with the old code */
704 if (!gmx_fio_do_int(ef->fio, dum))
709 if (*bOK && *file_version == 1 && nre_test < 0)
711 if (!ef->eo.bReadFirstStep)
713 ef->eo.bReadFirstStep = TRUE;
714 ef->eo.first_step = fr->step;
715 ef->eo.step_prev = fr->step;
716 ef->eo.nsum_prev = 0;
719 fr->nsum = fr->step - ef->eo.first_step + 1;
720 fr->nsteps = fr->step - ef->eo.step_prev;
727 void free_enxnms(int n, gmx_enxnm_t *nms)
731 for (i = 0; i < n; i++)
740 void close_enx(ener_file_t ef)
742 if (gmx_fio_close(ef->fio) != 0)
744 gmx_file("Cannot close energy file; it might be corrupt, or maybe you are out of disk space?");
748 static gmx_bool empty_file(const char *fn)
755 fp = gmx_fio_fopen(fn, "r");
756 ret = fread(&dum, sizeof(dum), 1, fp);
764 ener_file_t open_enx(const char *fn, const char *mode)
767 gmx_enxnm_t *nms = NULL;
768 int file_version = -1;
770 gmx_bool bWrongPrecision, bOK = TRUE;
771 struct ener_file *ef;
777 ef->fio = gmx_fio_open(fn, mode);
778 gmx_fio_checktype(ef->fio);
779 gmx_fio_setprecision(ef->fio, FALSE);
780 do_enxnms(ef, &nre, &nms);
782 do_eheader(ef, &file_version, fr, nre, &bWrongPrecision, &bOK);
785 gmx_file("Cannot read energy file header. Corrupt file?");
788 /* Now check whether this file is in single precision */
789 if (!bWrongPrecision &&
790 ((fr->e_size && (fr->nre == nre) &&
791 (nre*4*(long int)sizeof(float) == fr->e_size)) ) )
793 fprintf(stderr, "Opened %s as single precision energy file\n", fn);
794 free_enxnms(nre, nms);
798 gmx_fio_rewind(ef->fio);
799 gmx_fio_checktype(ef->fio);
800 gmx_fio_setprecision(ef->fio, TRUE);
801 do_enxnms(ef, &nre, &nms);
802 do_eheader(ef, &file_version, fr, nre, &bWrongPrecision, &bOK);
805 gmx_file("Cannot write energy file header; maybe you are out of disk space?");
808 if (((fr->e_size && (fr->nre == nre) &&
809 (nre*4*(long int)sizeof(double) == fr->e_size)) ))
811 fprintf(stderr, "Opened %s as double precision energy file\n",
818 gmx_fatal(FARGS, "File %s is empty", fn);
822 gmx_fatal(FARGS, "Energy file %s not recognized, maybe different CPU?",
826 free_enxnms(nre, nms);
830 gmx_fio_rewind(ef->fio);
834 ef->fio = gmx_fio_open(fn, mode);
842 t_fileio *enx_file_pointer(const ener_file_t ef)
847 static void convert_full_sums(ener_old_t *ener_old, t_enxframe *fr)
851 double esum_all, eav_all;
857 for (i = 0; i < fr->nre; i++)
859 if (fr->ener[i].e != 0)
863 if (fr->ener[i].esum != 0)
868 if (ne > 0 && ns == 0)
870 /* We do not have all energy sums */
875 /* Convert old full simulation sums to sums between energy frames */
876 nstep_all = fr->step - ener_old->first_step + 1;
877 if (fr->nsum > 1 && fr->nsum == nstep_all && ener_old->nsum_prev > 0)
879 /* Set the new sum length: the frame step difference */
880 fr->nsum = fr->step - ener_old->step_prev;
881 for (i = 0; i < fr->nre; i++)
883 esum_all = fr->ener[i].esum;
884 eav_all = fr->ener[i].eav;
885 fr->ener[i].esum = esum_all - ener_old->ener_prev[i].esum;
886 fr->ener[i].eav = eav_all - ener_old->ener_prev[i].eav
887 - dsqr(ener_old->ener_prev[i].esum/(nstep_all - fr->nsum)
888 - esum_all/nstep_all)*
889 (nstep_all - fr->nsum)*nstep_all/(double)fr->nsum;
890 ener_old->ener_prev[i].esum = esum_all;
891 ener_old->ener_prev[i].eav = eav_all;
893 ener_old->nsum_prev = nstep_all;
895 else if (fr->nsum > 0)
897 if (fr->nsum != nstep_all)
899 fprintf(stderr, "\nWARNING: something is wrong with the energy sums, will not use exact averages\n");
900 ener_old->nsum_prev = 0;
904 ener_old->nsum_prev = nstep_all;
906 /* Copy all sums to ener_prev */
907 for (i = 0; i < fr->nre; i++)
909 ener_old->ener_prev[i].esum = fr->ener[i].esum;
910 ener_old->ener_prev[i].eav = fr->ener[i].eav;
914 ener_old->step_prev = fr->step;
917 gmx_bool do_enx(ener_file_t ef, t_enxframe *fr)
919 int file_version = -1;
921 gmx_bool bRead, bOK, bOK1, bSane;
922 real tmp1, tmp2, rdum;
927 bRead = gmx_fio_getread(ef->fio);
930 fr->e_size = fr->nre*sizeof(fr->ener[0].e)*4;
931 /*d_size = fr->ndisre*(sizeof(real)*2);*/
933 gmx_fio_checktype(ef->fio);
935 if (!do_eheader(ef, &file_version, fr, -1, NULL, &bOK))
939 fprintf(stderr, "\rLast energy frame read %d time %8.3f ",
940 ef->framenr-1, ef->frametime);
944 "\nWARNING: Incomplete energy frame: nr %d time %8.3f\n",
950 gmx_file("Cannot write energy file header; maybe you are out of disk space?");
956 if ((ef->framenr < 20 || ef->framenr % 10 == 0) &&
957 (ef->framenr < 200 || ef->framenr % 100 == 0) &&
958 (ef->framenr < 2000 || ef->framenr % 1000 == 0))
960 fprintf(stderr, "\rReading energy frame %6d time %8.3f ",
964 ef->frametime = fr->t;
966 /* Check sanity of this header */
968 for (b = 0; b < fr->nblock; b++)
970 bSane = bSane || (fr->block[b].nsub > 0);
972 if (!((fr->step >= 0) && bSane))
974 fprintf(stderr, "\nWARNING: there may be something wrong with energy file %s\n",
975 gmx_fio_getname(ef->fio));
976 fprintf(stderr, "Found: step=%s, nre=%d, nblock=%d, time=%g.\n"
977 "Trying to skip frame expect a crash though\n",
978 gmx_step_str(fr->step, buf), fr->nre, fr->nblock, fr->t);
980 if (bRead && fr->nre > fr->e_alloc)
982 srenew(fr->ener, fr->nre);
983 for (i = fr->e_alloc; (i < fr->nre); i++)
987 fr->ener[i].esum = 0;
989 fr->e_alloc = fr->nre;
992 for (i = 0; i < fr->nre; i++)
994 bOK = bOK && gmx_fio_do_real(ef->fio, fr->ener[i].e);
996 /* Do not store sums of length 1,
997 * since this does not add information.
999 if (file_version == 1 ||
1000 (bRead && fr->nsum > 0) || fr->nsum > 1)
1002 tmp1 = fr->ener[i].eav;
1003 bOK = bOK && gmx_fio_do_real(ef->fio, tmp1);
1006 fr->ener[i].eav = tmp1;
1009 /* This is to save only in single precision (unless compiled in DP) */
1010 tmp2 = fr->ener[i].esum;
1011 bOK = bOK && gmx_fio_do_real(ef->fio, tmp2);
1014 fr->ener[i].esum = tmp2;
1017 if (file_version == 1)
1019 /* Old, unused real */
1021 bOK = bOK && gmx_fio_do_real(ef->fio, rdum);
1026 /* Here we can not check for file_version==1, since one could have
1027 * continued an old format simulation with a new one with mdrun -append.
1029 if (bRead && ef->eo.bOldFileOpen)
1031 /* Convert old full simulation sums to sums between energy frames */
1032 convert_full_sums(&(ef->eo), fr);
1034 /* read the blocks */
1035 for (b = 0; b < fr->nblock; b++)
1037 /* now read the subblocks. */
1038 int nsub = fr->block[b].nsub; /* shortcut */
1041 for (i = 0; i < nsub; i++)
1043 t_enxsubblock *sub = &(fr->block[b].sub[i]); /* shortcut */
1047 enxsubblock_alloc(sub);
1050 /* read/write data */
1054 case xdr_datatype_float:
1055 bOK1 = gmx_fio_ndo_float(ef->fio, sub->fval, sub->nr);
1057 case xdr_datatype_double:
1058 bOK1 = gmx_fio_ndo_double(ef->fio, sub->dval, sub->nr);
1060 case xdr_datatype_int:
1061 bOK1 = gmx_fio_ndo_int(ef->fio, sub->ival, sub->nr);
1063 case xdr_datatype_int64:
1064 bOK1 = gmx_fio_ndo_int64(ef->fio, sub->lval, sub->nr);
1066 case xdr_datatype_char:
1067 bOK1 = gmx_fio_ndo_uchar(ef->fio, sub->cval, sub->nr);
1069 case xdr_datatype_string:
1070 bOK1 = gmx_fio_ndo_string(ef->fio, sub->sval, sub->nr);
1073 gmx_incons("Reading unknown block data type: this file is corrupted or from the future");
1081 if (gmx_fio_flush(ef->fio) != 0)
1083 gmx_file("Cannot write energy file; maybe you are out of disk space?");
1091 fprintf(stderr, "\nLast energy frame read %d",
1093 fprintf(stderr, "\nWARNING: Incomplete energy frame: nr %d time %8.3f\n",
1094 ef->framenr, fr->t);
1098 gmx_fatal(FARGS, "could not write energies");
1106 static real find_energy(const char *name, int nre, gmx_enxnm_t *enm,
1111 for (i = 0; i < nre; i++)
1113 if (strcmp(enm[i].name, name) == 0)
1115 return fr->ener[i].e;
1119 gmx_fatal(FARGS, "Could not find energy term named '%s'", name);
1125 void get_enx_state(const char *fn, real t, gmx_groups_t *groups, t_inputrec *ir,
1128 /* Should match the names in mdebin.c */
1129 static const char *boxvel_nm[] = {
1130 "Box-Vel-XX", "Box-Vel-YY", "Box-Vel-ZZ",
1131 "Box-Vel-YX", "Box-Vel-ZX", "Box-Vel-ZY"
1134 static const char *pcouplmu_nm[] = {
1135 "Pcoupl-Mu-XX", "Pcoupl-Mu-YY", "Pcoupl-Mu-ZZ",
1136 "Pcoupl-Mu-YX", "Pcoupl-Mu-ZX", "Pcoupl-Mu-ZY"
1138 static const char *baro_nm[] = {
1143 int ind0[] = { XX, YY, ZZ, YY, ZZ, ZZ };
1144 int ind1[] = { XX, YY, ZZ, XX, XX, YY };
1145 int nre, nfr, i, j, ni, npcoupl;
1148 gmx_enxnm_t *enm = NULL;
1152 in = open_enx(fn, "r");
1153 do_enxnms(in, &nre, &enm);
1156 while ((nfr == 0 || fr->t != t) && do_enx(in, fr))
1161 fprintf(stderr, "\n");
1163 if (nfr == 0 || fr->t != t)
1165 gmx_fatal(FARGS, "Could not find frame with time %f in '%s'", t, fn);
1168 npcoupl = TRICLINIC(ir->compress) ? 6 : 3;
1169 if (ir->epc == epcPARRINELLORAHMAN)
1171 clear_mat(state->boxv);
1172 for (i = 0; i < npcoupl; i++)
1174 state->boxv[ind0[i]][ind1[i]] =
1175 find_energy(boxvel_nm[i], nre, enm, fr);
1177 fprintf(stderr, "\nREAD %d BOX VELOCITIES FROM %s\n\n", npcoupl, fn);
1180 if (ir->etc == etcNOSEHOOVER)
1186 for (i = 0; i < state->ngtc; i++)
1188 ni = groups->grps[egcTC].nm_ind[i];
1189 bufi = *(groups->grpname[ni]);
1190 for (j = 0; (j < state->nhchainlength); j++)
1192 if (IR_NVT_TROTTER(ir))
1194 sprintf(cns, "-%d", j);
1196 sprintf(buf, "Xi%s-%s", cns, bufi);
1197 state->nosehoover_xi[i] = find_energy(buf, nre, enm, fr);
1198 sprintf(buf, "vXi%s-%s", cns, bufi);
1199 state->nosehoover_vxi[i] = find_energy(buf, nre, enm, fr);
1203 fprintf(stderr, "\nREAD %d NOSE-HOOVER Xi chains FROM %s\n\n", state->ngtc, fn);
1205 if (IR_NPT_TROTTER(ir) || IR_NPH_TROTTER(ir))
1207 for (i = 0; i < state->nnhpres; i++)
1209 bufi = baro_nm[0]; /* All barostat DOF's together for now */
1210 for (j = 0; (j < state->nhchainlength); j++)
1212 sprintf(buf, "Xi-%d-%s", j, bufi);
1213 state->nhpres_xi[i] = find_energy(buf, nre, enm, fr);
1214 sprintf(buf, "vXi-%d-%s", j, bufi);
1215 state->nhpres_vxi[i] = find_energy(buf, nre, enm, fr);
1218 fprintf(stderr, "\nREAD %d NOSE-HOOVER BAROSTAT Xi chains FROM %s\n\n", state->nnhpres, fn);
1222 free_enxnms(nre, enm);