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 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
44 #include "gmx_fatal.h"
51 /* The source code in this file should be thread-safe.
52 Please keep it that way. */
54 /* This number should be increased whenever the file format changes! */
55 static const int enx_version = 5;
57 const char *enx_block_id_name[] = {
58 "Averaged orientation restraints",
59 "Instantaneous orientation restraints",
60 "Orientation restraint order tensor(s)",
61 "Distance restraints",
68 /* Stuff for reading pre 4.1 energy files */
70 gmx_bool bOldFileOpen; /* Is this an open old file? */
71 gmx_bool bReadFirstStep; /* Did we read the first step? */
72 int first_step; /* First step in the energy file */
73 int step_prev; /* Previous step */
74 int nsum_prev; /* Previous step sum length */
75 t_energy *ener_prev; /* Previous energy sums */
86 static void enxsubblock_init(t_enxsubblock *sb)
90 sb->type=xdr_datatype_double;
92 sb->type=xdr_datatype_float;
108 static void enxsubblock_free(t_enxsubblock *sb)
144 for(i=0;i<sb->sval_alloc;i++)
157 /* allocate the appropriate amount of memory for the given type and nr */
158 static void enxsubblock_alloc(t_enxsubblock *sb)
160 /* allocate the appropriate amount of memory */
163 case xdr_datatype_float:
164 if (sb->nr > sb->fval_alloc)
166 srenew(sb->fval, sb->nr);
167 sb->fval_alloc=sb->nr;
170 case xdr_datatype_double:
171 if (sb->nr > sb->dval_alloc)
173 srenew(sb->dval, sb->nr);
174 sb->dval_alloc=sb->nr;
177 case xdr_datatype_int:
178 if (sb->nr > sb->ival_alloc)
180 srenew(sb->ival, sb->nr);
181 sb->ival_alloc=sb->nr;
184 case xdr_datatype_large_int:
185 if (sb->nr > sb->lval_alloc)
187 srenew(sb->lval, sb->nr);
188 sb->lval_alloc=sb->nr;
191 case xdr_datatype_char:
192 if (sb->nr > sb->cval_alloc)
194 srenew(sb->cval, sb->nr);
195 sb->cval_alloc=sb->nr;
198 case xdr_datatype_string:
199 if (sb->nr > sb->sval_alloc)
203 srenew(sb->sval, sb->nr);
204 for(i=sb->sval_alloc;i<sb->nr;i++)
208 sb->sval_alloc=sb->nr;
212 gmx_incons("Unknown block type: this file is corrupted or from the future");
216 static void enxblock_init(t_enxblock *eb)
224 static void enxblock_free(t_enxblock *eb)
226 if (eb->nsub_alloc>0)
229 for(i=0;i<eb->nsub_alloc;i++)
231 enxsubblock_free(&(eb->sub[i]));
239 void init_enxframe(t_enxframe *fr)
255 void free_enxframe(t_enxframe *fr)
263 for(b=0; b<fr->nblock_alloc; b++)
265 enxblock_free(&(fr->block[b]));
270 void add_blocks_enxframe(t_enxframe *fr, int n)
273 if (n > fr->nblock_alloc)
277 srenew(fr->block, n);
278 for(b=fr->nblock_alloc;b<fr->nblock;b++)
280 enxblock_init(&(fr->block[b]));
286 t_enxblock *find_block_id_enxframe(t_enxframe *ef, int id, t_enxblock *prev)
293 starti=(prev - ef->block) + 1;
295 for(i=starti; i<ef->nblock; i++)
297 if (ef->block[i].id == id)
298 return &(ef->block[i]);
303 void add_subblocks_enxblock(t_enxblock *eb, int n)
306 if (eb->nsub > eb->nsub_alloc)
311 for(b=eb->nsub_alloc; b<n; b++)
313 enxsubblock_init(&(eb->sub[b]));
319 static void enx_warning(const char *msg)
321 if (getenv("GMX_ENX_NO_FATAL") != NULL)
327 gmx_fatal(FARGS,"%s\n%s",
329 "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");
333 static void edr_strings(XDR *xdr,gmx_bool bRead,int file_version,
334 int n,gmx_enxnm_t **nms)
359 if(!xdr_string(xdr,&(nm->name),STRLEN))
361 gmx_file("Cannot write energy names to file; maybe you are out of disk space?");
363 if (file_version >= 2)
365 if(!xdr_string(xdr,&(nm->unit),STRLEN))
367 gmx_file("Cannot write energy names to file; maybe you are out of disk space?");
372 nm->unit = strdup("kJ/mol");
377 void do_enxnms(ener_file_t ef,int *nre,gmx_enxnm_t **nms)
381 gmx_bool bRead = gmx_fio_getread(ef->fio);
385 gmx_fio_checktype(ef->fio);
387 xdr = gmx_fio_getxdr(ef->fio);
389 if (!xdr_int(xdr,&magic))
393 gmx_file("Cannot write energy names to file; maybe you are out of disk space?");
400 /* Assume this is an old edr format */
403 ef->eo.bOldFileOpen = TRUE;
404 ef->eo.bReadFirstStep = FALSE;
405 srenew(ef->eo.ener_prev,*nre);
409 ef->eo.bOldFileOpen=FALSE;
413 gmx_fatal(FARGS,"Energy names magic number mismatch, this is not a GROMACS edr file");
415 file_version = enx_version;
416 xdr_int(xdr,&file_version);
417 if (file_version > enx_version)
419 gmx_fatal(FARGS,"reading tpx file (%s) version %d with version %d program",gmx_fio_getname(ef->fio),file_version,enx_version);
423 if (file_version != enx_version)
425 fprintf(stderr,"Note: enx file_version %d, software version %d\n",
426 file_version,enx_version);
429 edr_strings(xdr,bRead,file_version,*nre,nms);
432 static gmx_bool do_eheader(ener_file_t ef,int *file_version,t_enxframe *fr,
433 int nre_test,gmx_bool *bWrongPrecision,gmx_bool *bOK)
436 real first_real_to_check;
437 int b,i,zero=0,dum=0;
438 gmx_bool bRead = gmx_fio_getread(ef->fio);
443 xdr_datatype dtreal=xdr_datatype_float;
445 xdr_datatype dtreal=xdr_datatype_double;
450 *bWrongPrecision = FALSE;
454 /* The original energy frame started with a real,
455 * so we have to use a real for compatibility.
456 * This is VERY DIRTY code, since do_eheader can be called
457 * with the wrong precision set and then we could read r > -1e10,
458 * while actually the intention was r < -1e10.
459 * When nre_test >= 0, do_eheader should therefore terminate
460 * before the number of i/o calls starts depending on what has been read
461 * (which is the case for for instance the block sizes for variable
462 * number of blocks, where this number is read before).
464 first_real_to_check = -2e10;
465 if (!gmx_fio_do_real(ef->fio, first_real_to_check))
469 if (first_real_to_check > -1e10)
471 /* Assume we are reading an old format */
473 fr->t = first_real_to_check;
474 if (!gmx_fio_do_int(ef->fio, dum)) *bOK = FALSE;
479 if (!gmx_fio_do_int(ef->fio, magic)) *bOK = FALSE;
480 if (magic != -7777777)
482 enx_warning("Energy header magic number mismatch, this is not a GROMACS edr file");
486 *file_version = enx_version;
487 if (!gmx_fio_do_int(ef->fio, *file_version)) *bOK = FALSE;
488 if (*bOK && *file_version > enx_version)
490 gmx_fatal(FARGS,"reading tpx file (%s) version %d with version %d program",gmx_fio_getname(ef->fio),file_version,enx_version);
492 if (!gmx_fio_do_double(ef->fio, fr->t)) *bOK = FALSE;
493 if (!gmx_fio_do_gmx_large_int(ef->fio, fr->step)) *bOK = FALSE;
494 if (!bRead && fr->nsum == 1) {
495 /* Do not store sums of length 1,
496 * since this does not add information.
498 if (!gmx_fio_do_int(ef->fio, zero)) *bOK = FALSE;
500 if (!gmx_fio_do_int(ef->fio, fr->nsum)) *bOK = FALSE;
502 if (*file_version >= 3)
504 if (!gmx_fio_do_gmx_large_int(ef->fio, fr->nsteps)) *bOK = FALSE;
508 fr->nsteps = max(1,fr->nsum);
510 if (*file_version >= 5)
512 if (!gmx_fio_do_double(ef->fio, fr->dt)) *bOK = FALSE;
519 if (!gmx_fio_do_int(ef->fio, fr->nre)) *bOK = FALSE;
520 if (*file_version < 4)
522 if (!gmx_fio_do_int(ef->fio, ndisre)) *bOK = FALSE;
526 /* now reserved for possible future use */
527 if (!gmx_fio_do_int(ef->fio, dum)) *bOK = FALSE;
530 if (!gmx_fio_do_int(ef->fio, fr->nblock)) *bOK = FALSE;
531 if (fr->nblock < 0) *bOK=FALSE;
535 if (*file_version >= 4)
537 enx_warning("Distance restraint blocks in old style in new style file");
545 /* Frames could have nre=0, so we can not rely only on the fr->nre check */
546 if (bRead && nre_test >= 0 &&
547 ((fr->nre > 0 && fr->nre != nre_test) ||
548 fr->nre < 0 || ndisre < 0 || fr->nblock < 0))
550 *bWrongPrecision = TRUE;
554 /* we now know what these should be, or we've already bailed out because
555 of wrong precision */
556 if ( *file_version==1 && (fr->t < 0 || fr->t > 1e20 || fr->step < 0 ) )
558 enx_warning("edr file with negative step number or unreasonable time (and without version number).");
566 add_blocks_enxframe(fr, fr->nblock);
572 /* sub[0] is the instantaneous data, sub[1] is time averaged */
573 add_subblocks_enxblock(&(fr->block[0]), 2);
574 fr->block[0].id=enxDISRE;
575 fr->block[0].sub[0].nr=ndisre;
576 fr->block[0].sub[1].nr=ndisre;
577 fr->block[0].sub[0].type=dtreal;
578 fr->block[0].sub[1].type=dtreal;
582 /* read block header info */
583 for(b=startb; b<fr->nblock; b++)
587 /* blocks in old version files always have 1 subblock that
588 consists of reals. */
593 add_subblocks_enxblock(&(fr->block[b]), 1);
597 if (fr->block[b].nsub != 1)
599 gmx_incons("Writing an old version .edr file with too many subblocks");
601 if (fr->block[b].sub[0].type != dtreal)
603 gmx_incons("Writing an old version .edr file the wrong subblock type");
606 nrint = fr->block[b].sub[0].nr;
608 if (!gmx_fio_do_int(ef->fio, nrint))
612 fr->block[b].id = b - startb;
613 fr->block[b].sub[0].nr = nrint;
614 fr->block[b].sub[0].type = dtreal;
619 /* in the new version files, the block header only contains
620 the ID and the number of subblocks */
621 int nsub=fr->block[b].nsub;
622 *bOK = *bOK && gmx_fio_do_int(ef->fio, fr->block[b].id);
623 *bOK = *bOK && gmx_fio_do_int(ef->fio, nsub);
625 fr->block[b].nsub=nsub;
627 add_subblocks_enxblock(&(fr->block[b]), nsub);
629 /* read/write type & size for each subblock */
632 t_enxsubblock *sub=&(fr->block[b].sub[i]); /* shortcut */
633 int typenr=sub->type;
635 *bOK=*bOK && gmx_fio_do_int(ef->fio, typenr);
636 *bOK=*bOK && gmx_fio_do_int(ef->fio, sub->nr);
638 sub->type = (xdr_datatype)typenr;
642 if (!gmx_fio_do_int(ef->fio, fr->e_size)) *bOK = FALSE;
644 /* now reserved for possible future use */
645 if (!gmx_fio_do_int(ef->fio, dum)) *bOK = FALSE;
647 /* Do a dummy int to keep the format compatible with the old code */
648 if (!gmx_fio_do_int(ef->fio, dum)) *bOK = FALSE;
650 if (*bOK && *file_version == 1 && nre_test < 0)
653 if (fp >= ener_old_nalloc)
655 gmx_incons("Problem with reading old format energy files");
659 if (!ef->eo.bReadFirstStep)
661 ef->eo.bReadFirstStep = TRUE;
662 ef->eo.first_step = fr->step;
663 ef->eo.step_prev = fr->step;
664 ef->eo.nsum_prev = 0;
667 fr->nsum = fr->step - ef->eo.first_step + 1;
668 fr->nsteps = fr->step - ef->eo.step_prev;
675 void free_enxnms(int n,gmx_enxnm_t *nms)
688 void close_enx(ener_file_t ef)
690 if(gmx_fio_close(ef->fio) != 0)
692 gmx_file("Cannot close energy file; it might be corrupt, or maybe you are out of disk space?");
696 static gmx_bool empty_file(const char *fn)
703 fp = gmx_fio_fopen(fn,"r");
704 ret = fread(&dum,sizeof(dum),1,fp);
712 ener_file_t open_enx(const char *fn,const char *mode)
715 gmx_enxnm_t *nms=NULL;
718 gmx_bool bWrongPrecision,bOK=TRUE;
719 struct ener_file *ef;
724 ef->fio=gmx_fio_open(fn,mode);
725 gmx_fio_checktype(ef->fio);
726 gmx_fio_setprecision(ef->fio,FALSE);
727 do_enxnms(ef,&nre,&nms);
729 do_eheader(ef,&file_version,fr,nre,&bWrongPrecision,&bOK);
732 gmx_file("Cannot read energy file header. Corrupt file?");
735 /* Now check whether this file is in single precision */
736 if (!bWrongPrecision &&
737 ((fr->e_size && (fr->nre == nre) &&
738 (nre*4*(long int)sizeof(float) == fr->e_size)) ) )
740 fprintf(stderr,"Opened %s as single precision energy file\n",fn);
741 free_enxnms(nre,nms);
745 gmx_fio_rewind(ef->fio);
746 gmx_fio_checktype(ef->fio);
747 gmx_fio_setprecision(ef->fio,TRUE);
748 do_enxnms(ef,&nre,&nms);
749 do_eheader(ef,&file_version,fr,nre,&bWrongPrecision,&bOK);
752 gmx_file("Cannot write energy file header; maybe you are out of disk space?");
755 if (((fr->e_size && (fr->nre == nre) &&
756 (nre*4*(long int)sizeof(double) == fr->e_size)) ))
757 fprintf(stderr,"Opened %s as double precision energy file\n",
761 gmx_fatal(FARGS,"File %s is empty",fn);
763 gmx_fatal(FARGS,"Energy file %s not recognized, maybe different CPU?",
766 free_enxnms(nre,nms);
770 gmx_fio_rewind(ef->fio);
773 ef->fio = gmx_fio_open(fn,mode);
780 t_fileio *enx_file_pointer(const ener_file_t ef)
785 static void convert_full_sums(ener_old_t *ener_old,t_enxframe *fr)
789 double esum_all,eav_all;
795 for(i=0; i<fr->nre; i++)
797 if (fr->ener[i].e != 0) ne++;
798 if (fr->ener[i].esum != 0) ns++;
800 if (ne > 0 && ns == 0)
802 /* We do not have all energy sums */
807 /* Convert old full simulation sums to sums between energy frames */
808 nstep_all = fr->step - ener_old->first_step + 1;
809 if (fr->nsum > 1 && fr->nsum == nstep_all && ener_old->nsum_prev > 0)
811 /* Set the new sum length: the frame step difference */
812 fr->nsum = fr->step - ener_old->step_prev;
813 for(i=0; i<fr->nre; i++)
815 esum_all = fr->ener[i].esum;
816 eav_all = fr->ener[i].eav;
817 fr->ener[i].esum = esum_all - ener_old->ener_prev[i].esum;
818 fr->ener[i].eav = eav_all - ener_old->ener_prev[i].eav
819 - dsqr(ener_old->ener_prev[i].esum/(nstep_all - fr->nsum)
820 - esum_all/nstep_all)*
821 (nstep_all - fr->nsum)*nstep_all/(double)fr->nsum;
822 ener_old->ener_prev[i].esum = esum_all;
823 ener_old->ener_prev[i].eav = eav_all;
825 ener_old->nsum_prev = nstep_all;
827 else if (fr->nsum > 0)
829 if (fr->nsum != nstep_all)
831 fprintf(stderr,"\nWARNING: something is wrong with the energy sums, will not use exact averages\n");
832 ener_old->nsum_prev = 0;
836 ener_old->nsum_prev = nstep_all;
838 /* Copy all sums to ener_prev */
839 for(i=0; i<fr->nre; i++)
841 ener_old->ener_prev[i].esum = fr->ener[i].esum;
842 ener_old->ener_prev[i].eav = fr->ener[i].eav;
846 ener_old->step_prev = fr->step;
849 gmx_bool do_enx(ener_file_t ef,t_enxframe *fr)
853 gmx_bool bRead,bOK,bOK1,bSane;
859 bRead = gmx_fio_getread(ef->fio);
862 fr->e_size = fr->nre*sizeof(fr->ener[0].e)*4;
863 /*d_size = fr->ndisre*(sizeof(real)*2);*/
865 gmx_fio_checktype(ef->fio);
867 if (!do_eheader(ef,&file_version,fr,-1,NULL,&bOK))
871 fprintf(stderr,"\rLast energy frame read %d time %8.3f ",
872 ef->framenr-1,ef->frametime);
876 "\nWARNING: Incomplete energy frame: nr %d time %8.3f\n",
882 gmx_file("Cannot write energy file header; maybe you are out of disk space?");
888 if ((ef->framenr < 20 || ef->framenr % 10 == 0) &&
889 (ef->framenr < 200 || ef->framenr % 100 == 0) &&
890 (ef->framenr < 2000 || ef->framenr % 1000 == 0))
892 fprintf(stderr,"\rReading energy frame %6d time %8.3f ",
896 ef->frametime = fr->t;
898 /* Check sanity of this header */
899 bSane = fr->nre > 0 ;
900 for(b=0; b<fr->nblock; b++)
902 bSane = bSane || (fr->block[b].nsub > 0);
904 if (!((fr->step >= 0) && bSane))
906 fprintf(stderr,"\nWARNING: there may be something wrong with energy file %s\n",
907 gmx_fio_getname(ef->fio));
908 fprintf(stderr,"Found: step=%s, nre=%d, nblock=%d, time=%g.\n"
909 "Trying to skip frame expect a crash though\n",
910 gmx_step_str(fr->step,buf),fr->nre,fr->nblock,fr->t);
912 if (bRead && fr->nre > fr->e_alloc)
914 srenew(fr->ener,fr->nre);
915 for(i=fr->e_alloc; (i<fr->nre); i++)
919 fr->ener[i].esum = 0;
921 fr->e_alloc = fr->nre;
924 for(i=0; i<fr->nre; i++)
926 bOK = bOK && gmx_fio_do_real(ef->fio, fr->ener[i].e);
928 /* Do not store sums of length 1,
929 * since this does not add information.
931 if (file_version == 1 ||
932 (bRead && fr->nsum > 0) || fr->nsum > 1)
934 tmp1 = fr->ener[i].eav;
935 bOK = bOK && gmx_fio_do_real(ef->fio, tmp1);
937 fr->ener[i].eav = tmp1;
939 /* This is to save only in single precision (unless compiled in DP) */
940 tmp2 = fr->ener[i].esum;
941 bOK = bOK && gmx_fio_do_real(ef->fio, tmp2);
943 fr->ener[i].esum = tmp2;
945 if (file_version == 1)
947 /* Old, unused real */
949 bOK = bOK && gmx_fio_do_real(ef->fio, rdum);
954 /* Here we can not check for file_version==1, since one could have
955 * continued an old format simulation with a new one with mdrun -append.
957 if (bRead && ef->eo.bOldFileOpen)
959 /* Convert old full simulation sums to sums between energy frames */
960 convert_full_sums(&(ef->eo),fr);
962 /* read the blocks */
963 for(b=0; b<fr->nblock; b++)
965 /* now read the subblocks. */
966 int nsub=fr->block[b].nsub; /* shortcut */
971 t_enxsubblock *sub=&(fr->block[b].sub[i]); /* shortcut */
975 enxsubblock_alloc(sub);
978 /* read/write data */
982 case xdr_datatype_float:
983 bOK1=gmx_fio_ndo_float(ef->fio, sub->fval, sub->nr);
985 case xdr_datatype_double:
986 bOK1=gmx_fio_ndo_double(ef->fio, sub->dval, sub->nr);
988 case xdr_datatype_int:
989 bOK1=gmx_fio_ndo_int(ef->fio, sub->ival, sub->nr);
991 case xdr_datatype_large_int:
992 bOK1=gmx_fio_ndo_gmx_large_int(ef->fio, sub->lval, sub->nr);
994 case xdr_datatype_char:
995 bOK1=gmx_fio_ndo_uchar(ef->fio, sub->cval, sub->nr);
997 case xdr_datatype_string:
998 bOK1=gmx_fio_ndo_string(ef->fio, sub->sval, sub->nr);
1001 gmx_incons("Reading unknown block data type: this file is corrupted or from the future");
1009 if( gmx_fio_flush(ef->fio) != 0)
1011 gmx_file("Cannot write energy file; maybe you are out of disk space?");
1019 fprintf(stderr,"\nLast energy frame read %d",
1021 fprintf(stderr,"\nWARNING: Incomplete energy frame: nr %d time %8.3f\n",
1026 gmx_fatal(FARGS,"could not write energies");
1034 static real find_energy(const char *name, int nre, gmx_enxnm_t *enm,
1039 for(i=0; i<nre; i++)
1041 if (strcmp(enm[i].name,name) == 0)
1043 return fr->ener[i].e;
1047 gmx_fatal(FARGS,"Could not find energy term named '%s'",name);
1053 void get_enx_state(const char *fn, real t, gmx_groups_t *groups, t_inputrec *ir,
1056 /* Should match the names in mdebin.c */
1057 static const char *boxvel_nm[] = {
1058 "Box-Vel-XX", "Box-Vel-YY", "Box-Vel-ZZ",
1059 "Box-Vel-YX", "Box-Vel-ZX", "Box-Vel-ZY"
1062 static const char *pcouplmu_nm[] = {
1063 "Pcoupl-Mu-XX", "Pcoupl-Mu-YY", "Pcoupl-Mu-ZZ",
1064 "Pcoupl-Mu-YX", "Pcoupl-Mu-ZX", "Pcoupl-Mu-ZY"
1066 static const char *baro_nm[] = {
1071 int ind0[] = { XX,YY,ZZ,YY,ZZ,ZZ };
1072 int ind1[] = { XX,YY,ZZ,XX,XX,YY };
1073 int nre,nfr,i,j,ni,npcoupl;
1076 gmx_enxnm_t *enm=NULL;
1080 in = open_enx(fn,"r");
1081 do_enxnms(in,&nre,&enm);
1084 while ((nfr==0 || fr->t != t) && do_enx(in,fr)) {
1088 fprintf(stderr,"\n");
1090 if (nfr == 0 || fr->t != t)
1091 gmx_fatal(FARGS,"Could not find frame with time %f in '%s'",t,fn);
1093 npcoupl = TRICLINIC(ir->compress) ? 6 : 3;
1094 if (ir->epc == epcPARRINELLORAHMAN) {
1095 clear_mat(state->boxv);
1096 for(i=0; i<npcoupl; i++) {
1097 state->boxv[ind0[i]][ind1[i]] =
1098 find_energy(boxvel_nm[i],nre,enm,fr);
1100 fprintf(stderr,"\nREAD %d BOX VELOCITIES FROM %s\n\n",npcoupl,fn);
1103 if (ir->etc == etcNOSEHOOVER)
1109 for(i=0; i<state->ngtc; i++) {
1110 ni = groups->grps[egcTC].nm_ind[i];
1111 bufi = *(groups->grpname[ni]);
1112 for(j=0; (j<state->nhchainlength); j++)
1114 if (IR_NVT_TROTTER(ir))
1116 sprintf(cns,"-%d",j);
1118 sprintf(buf,"Xi%s-%s",cns,bufi);
1119 state->nosehoover_xi[i] = find_energy(buf,nre,enm,fr);
1120 sprintf(buf,"vXi%s-%s",cns,bufi);
1121 state->nosehoover_vxi[i] = find_energy(buf,nre,enm,fr);
1125 fprintf(stderr,"\nREAD %d NOSE-HOOVER Xi chains FROM %s\n\n",state->ngtc,fn);
1127 if (IR_NPT_TROTTER(ir) || IR_NPH_TROTTER(ir))
1129 for(i=0; i<state->nnhpres; i++) {
1130 bufi = baro_nm[0]; /* All barostat DOF's together for now */
1131 for(j=0; (j<state->nhchainlength); j++)
1133 sprintf(buf,"Xi-%d-%s",j,bufi);
1134 state->nhpres_xi[i] = find_energy(buf,nre,enm,fr);
1135 sprintf(buf,"vXi-%d-%s",j,bufi);
1136 state->nhpres_vxi[i] = find_energy(buf,nre,enm,fr);
1139 fprintf(stderr,"\nREAD %d NOSE-HOOVER BAROSTAT Xi chains FROM %s\n\n",state->nnhpres,fn);
1143 free_enxnms(nre,enm);