3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Green Red Orange Magenta Azure Cyan Skyblue
46 void read_eigenvectors(const char *file
,int *natoms
,bool *bFit
,
47 rvec
**xref
,bool *bDMR
,
48 rvec
**xav
,bool *bDMA
,
49 int *nvec
, int **eignr
,
50 rvec
***eigvec
,real
**eigval
)
53 int status
,i
,snew_size
;
60 /* read (reference (t=-1) and) average (t=0) structure */
61 status
=open_trn(file
,"r");
62 fread_trnheader(status
,&head
,&bOK
);
65 fread_htrn(status
,&head
,box
,*xav
,NULL
,NULL
);
67 if ((head
.t
>=-1.1) && (head
.t
<=-0.9))
70 for(i
=0; i
<*natoms
; i
++)
71 copy_rvec((*xav
)[i
],(*xref
)[i
]);
72 *bDMR
= (head
.lambda
> 0.5);
73 *bFit
= (head
.lambda
> -0.5);
76 fprintf(stderr
,"Read %smass weighted reference structure with %d atoms from %s\n", *bDMR
? "" : "non ",*natoms
,file
);
80 fprintf(stderr
,"Eigenvectors in %s were determined without fitting\n",file
);
84 fread_trnheader(status
,&head
,&bOK
);
85 fread_htrn(status
,&head
,box
,*xav
,NULL
,NULL
);
92 *bDMA
= (head
.lambda
> 0.5);
93 if ((head
.t
<=-0.01) || (head
.t
>=0.01))
95 fprintf(stderr
,"WARNING: %s does not start with t=0, which should be the "
96 "average structure. This might not be a eigenvector file. "
97 "Some things might go wrong.\n",
103 "Read %smass weighted average/minimum structure with %d atoms from %s\n",
104 *bDMA
? "" : "non ",*natoms
,file
);
109 snew(*eignr
,snew_size
);
110 snew(*eigval
,snew_size
);
111 snew(*eigvec
,snew_size
);
114 while (fread_trnheader(status
,&head
,&bOK
))
116 fread_htrn(status
,&head
,box
,x
,NULL
,NULL
);
117 if (*nvec
>= snew_size
)
120 srenew(*eignr
,snew_size
);
121 srenew(*eigval
,snew_size
);
122 srenew(*eigvec
,snew_size
);
125 (*eigval
)[*nvec
]=head
.t
;
127 snew((*eigvec
)[*nvec
],*natoms
);
128 for(i
=0; i
<*natoms
; i
++)
130 copy_rvec(x
[i
],(*eigvec
)[*nvec
][i
]);
135 fprintf(stderr
,"Read %d eigenvectors (for %d atoms)\n\n",*nvec
,*natoms
);
139 void write_eigenvectors(const char *trnname
,int natoms
,real mat
[],
140 bool bReverse
,int begin
,int end
,
141 int WriteXref
,rvec
*xref
,bool bDMR
,
142 rvec xav
[], bool bDMA
,real eigval
[])
154 "\nWriting %saverage structure & eigenvectors %d--%d to %s\n",
155 (WriteXref
==eWXR_YES
) ? "reference, " : "",
158 trnout
= open_tpx(trnname
,"w");
159 if (WriteXref
== eWXR_YES
)
161 /* misuse lambda: 0/1 mass weighted fit no/yes */
162 fwrite_trn(trnout
,-1,-1,bDMR
? 1.0 : 0.0,zerobox
,natoms
,xref
,NULL
,NULL
);
164 else if (WriteXref
== eWXR_NOFIT
)
166 /* misuse lambda: -1 no fit */
167 fwrite_trn(trnout
,-1,-1,-1.0,zerobox
,natoms
,x
,NULL
,NULL
);
170 /* misuse lambda: 0/1 mass weighted analysis no/yes */
171 fwrite_trn(trnout
,0,0,bDMA
? 1.0 : 0.0,zerobox
,natoms
,xav
,NULL
,NULL
);
173 for(i
=0; i
<=(end
-begin
); i
++)
181 for (j
=0; j
<natoms
; j
++)
183 x
[j
][d
]=mat
[vec
*ndim
+DIM
*j
+d
];
185 /* Store the eigenvalue in the time field */
186 fwrite_trn(trnout
,begin
+i
,eigval
[vec
],0,zerobox
,natoms
,x
,NULL
,NULL
);