4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_eigio_c
= "$Id$";
37 void read_eigenvectors(char *file
,int *natoms
,bool *bFit
,
38 rvec
**xref
,bool *bDMR
,
39 rvec
**xav
,bool *bDMA
,
40 int *nvec
, int **eignr
, rvec
***eigvec
)
43 int status
,i
,snew_size
;
50 /* read (reference (t=-1) and) average (t=0) structure */
51 status
=open_trn(file
,"r");
52 fread_trnheader(status
,&head
,&bOK
);
55 fread_htrn(status
,&head
,box
,*xav
,NULL
,NULL
);
56 if ((head
.t
>=-1.1) && (head
.t
<=-0.9)) {
58 for(i
=0; i
<*natoms
; i
++)
59 copy_rvec((*xav
)[i
],(*xref
)[i
]);
60 *bDMR
= (head
.lambda
> 0.5);
61 *bFit
= (head
.lambda
> -0.5);
63 fprintf(stderr
,"Read %smass weighted reference structure with %d atoms from %s\n", *bDMR
? "" : "non ",*natoms
,file
);
65 fprintf(stderr
,"Eigenvectors in %s were determined without fitting\n",
70 fread_trnheader(status
,&head
,&bOK
);
71 fread_htrn(status
,&head
,box
,*xav
,NULL
,NULL
);
77 *bDMA
= (head
.lambda
> 0.5);
78 if ((head
.t
<=-0.01) || (head
.t
>=0.01))
79 fprintf(stderr
,"WARNING: %s does not start with t=0, which should be the "
80 "average structure. This might not be a eigenvector file. "
81 "Some things might go wrong.\n",
85 "Read %smass weighted average/minimum structure with %d atoms from %s\n",
86 *bDMA
? "" : "non ",*natoms
,file
);
91 while (fread_trnheader(status
,&head
,&bOK
)) {
92 fread_htrn(status
,&head
,box
,x
,NULL
,NULL
);
93 if (*nvec
>= snew_size
) {
95 srenew(*eignr
,snew_size
);
96 srenew(*eigvec
,snew_size
);
99 if ((head
.t
-i
<=-0.01) || (head
.t
-i
>=0.01))
100 fatal_error(0,"%s contains a frame with non-integer time (%f), this "
101 "time should be an eigenvector index. "
102 "This might not be a eigenvector file.",file
,head
.t
);
104 snew((*eigvec
)[*nvec
],*natoms
);
105 for(i
=0; i
<*natoms
; i
++)
106 copy_rvec(x
[i
],(*eigvec
)[*nvec
][i
]);
110 fprintf(stderr
,"Read %d eigenvectors (dim=%d)\n\n",*nvec
,*natoms
*DIM
);
113 void write_eigenvectors(char *trnname
,int natoms
,real mat
[],
114 bool bReverse
,int begin
,int end
,
115 int WriteXref
,rvec
*xref
,bool bDMR
,
116 rvec xav
[],bool bDMA
)
128 "\nWriting %saverage structure\nand eigenvectors 1 to %d to %s\n",
129 (WriteXref
==eWXR_YES
) ? "reference and " : "",
132 trnout
= open_tpx(trnname
,"w");
133 if (WriteXref
== eWXR_YES
)
134 /* misuse lambda: 0/1 mass weighted fit no/yes */
135 fwrite_trn(trnout
,-1,-1,bDMR
? 1.0 : 0.0,zerobox
,natoms
,xref
,NULL
,NULL
);
136 else if (WriteXref
== eWXR_NOFIT
)
137 /* misuse lambda: -1 no fit */
138 fwrite_trn(trnout
,-1,-1,-1.0,zerobox
,natoms
,x
,NULL
,NULL
);
140 /* misuse lambda: 0/1 mass weighted analysis no/yes */
141 fwrite_trn(trnout
,0,0,bDMA
? 1.0 : 0.0,zerobox
,natoms
,xav
,NULL
,NULL
);
143 for(i
=begin
; i
<=end
; i
++) {
148 for (j
=0; j
<natoms
; j
++)
150 x
[j
][d
]=mat
[vec
*ndim
+DIM
*j
+d
];
151 fwrite_trn(trnout
,i
,(real
)i
,0,zerobox
,natoms
,x
,NULL
,NULL
);