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.
39 #include "gromacs/utility/smalloc.h"
40 #include "gromacs/math/vec.h"
42 #include "gromacs/fileio/trnio.h"
43 #include "gromacs/fileio/tpxio.h"
44 #include "gromacs/utility/futil.h"
46 void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit,
47 rvec **xref, gmx_bool *bDMR,
48 rvec **xav, gmx_bool *bDMA,
49 int *nvec, int **eignr,
50 rvec ***eigvec, real **eigval)
61 /* read (reference (t=-1) and) average (t=0) structure */
62 status = open_trn(file, "r");
63 fread_trnheader(status, &head, &bOK);
64 *natoms = head.natoms;
66 fread_htrn(status, &head, box, *xav, NULL, NULL);
68 if ((head.t >= -1.1) && (head.t <= -0.9))
71 for (i = 0; i < *natoms; i++)
73 copy_rvec((*xav)[i], (*xref)[i]);
75 *bDMR = (head.lambda > 0.5);
76 *bFit = (head.lambda > -0.5);
79 fprintf(stderr, "Read %smass weighted reference structure with %d atoms from %s\n", *bDMR ? "" : "non ", *natoms, file);
83 fprintf(stderr, "Eigenvectors in %s were determined without fitting\n", file);
87 fread_trnheader(status, &head, &bOK);
88 fread_htrn(status, &head, box, *xav, NULL, NULL);
95 *bDMA = (head.lambda > 0.5);
96 if ((head.t <= -0.01) || (head.t >= 0.01))
98 fprintf(stderr, "WARNING: %s does not start with t=0, which should be the "
99 "average structure. This might not be a eigenvector file. "
100 "Some things might go wrong.\n",
106 "Read %smass weighted average/minimum structure with %d atoms from %s\n",
107 *bDMA ? "" : "non ", *natoms, file);
112 snew(*eignr, snew_size);
113 snew(*eigval, snew_size);
114 snew(*eigvec, snew_size);
117 while (fread_trnheader(status, &head, &bOK))
119 fread_htrn(status, &head, box, x, NULL, NULL);
120 if (*nvec >= snew_size)
123 srenew(*eignr, snew_size);
124 srenew(*eigval, snew_size);
125 srenew(*eigvec, snew_size);
128 (*eigval)[*nvec] = head.t;
129 (*eignr)[*nvec] = i-1;
130 snew((*eigvec)[*nvec], *natoms);
131 for (i = 0; i < *natoms; i++)
133 copy_rvec(x[i], (*eigvec)[*nvec][i]);
138 fprintf(stderr, "Read %d eigenvectors (for %d atoms)\n\n", *nvec, *natoms);
142 void write_eigenvectors(const char *trnname, int natoms, real mat[],
143 gmx_bool bReverse, int begin, int end,
144 int WriteXref, rvec *xref, gmx_bool bDMR,
145 rvec xav[], gmx_bool bDMA, real eigval[])
148 int ndim, i, j, d, vec;
157 "\nWriting %saverage structure & eigenvectors %d--%d to %s\n",
158 (WriteXref == eWXR_YES) ? "reference, " : "",
159 begin, end, trnname);
161 trnout = open_tpx(trnname, "w");
162 if (WriteXref == eWXR_YES)
164 /* misuse lambda: 0/1 mass weighted fit no/yes */
165 fwrite_trn(trnout, -1, -1, bDMR ? 1.0 : 0.0, zerobox, natoms, xref, NULL, NULL);
167 else if (WriteXref == eWXR_NOFIT)
169 /* misuse lambda: -1 no fit */
170 fwrite_trn(trnout, -1, -1, -1.0, zerobox, natoms, x, NULL, NULL);
173 /* misuse lambda: 0/1 mass weighted analysis no/yes */
174 fwrite_trn(trnout, 0, 0, bDMA ? 1.0 : 0.0, zerobox, natoms, xav, NULL, NULL);
176 for (i = 0; i <= (end-begin); i++)
188 for (j = 0; j < natoms; j++)
190 for (d = 0; d < DIM; d++)
192 x[j][d] = mat[vec*ndim+DIM*j+d];
196 /* Store the eigenvalue in the time field */
197 fwrite_trn(trnout, begin+i, eigval[vec], 0, zerobox, natoms, x, NULL, NULL);