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.
40 #include "gromacs/utility/smalloc.h"
41 #include "gromacs/legacyheaders/macros.h"
42 #include "gromacs/math/vec.h"
43 #include "gromacs/fileio/xvgr.h"
44 #include "gromacs/fileio/matio.h"
45 #include "gromacs/utility/futil.h"
47 t_mat *init_mat(int n1, gmx_bool b1D)
58 m->mat = mk_matrix(n1, n1, b1D);
67 void copy_t_mat(t_mat *dst, t_mat *src)
71 if (dst->nn != src->nn)
73 fprintf(stderr, "t_mat structures not identical in size dst %d src %d\n", dst->nn, src->nn);
76 dst->maxrms = src->maxrms;
77 dst->minrms = src->minrms;
78 dst->sumrms = src->sumrms;
79 for (i = 0; (i < src->nn); i++)
81 for (j = 0; (j < src->nn); j++)
83 dst->mat[i][j] = src->mat[i][j];
85 dst->erow[i] = src->erow[i];
86 dst->m_ind[i] = src->m_ind[i];
90 void enlarge_mat(t_mat *m, int deltan)
94 srenew(m->erow, m->nn+deltan);
95 srenew(m->m_ind, m->nn+deltan);
96 srenew(m->mat, m->nn+deltan);
98 /* Reallocate existing rows in the matrix, and set them to zero */
99 for (i = 0; (i < m->nn); i++)
101 srenew(m->mat[i], m->nn+deltan);
102 for (j = m->nn; (j < m->nn+deltan); j++)
107 /* Allocate new rows of the matrix, set energies to zero */
108 for (i = m->nn; (i < m->nn+deltan); i++)
111 snew(m->mat[i], m->nn+deltan);
116 void reset_index(t_mat *m)
120 for (i = 0; (i < m->n1); i++)
126 void set_mat_entry(t_mat *m, int i, int j, real val)
128 m->mat[i][j] = m->mat[j][i] = val;
129 m->maxrms = max(m->maxrms, val);
132 m->minrms = min(m->minrms, val);
135 m->nn = max(m->nn, max(j+1, i+1));
138 void done_mat(t_mat **m)
140 done_matrix((*m)->n1, &((*m)->mat));
147 real mat_energy(t_mat *m)
152 for (j = 0; (j < m->nn-1); j++)
154 emat += sqr(m->mat[j][j+1]);
159 void swap_rows(t_mat *m, int iswap, int jswap)
165 itmp = m->m_ind[iswap];
166 m->m_ind[iswap] = m->m_ind[jswap];
167 m->m_ind[jswap] = itmp;
169 /* Swap rows (since the matrix is an array of pointers) */
171 m->mat[iswap] = m->mat[jswap];
175 for (i = 0; (i < m->nn); i++)
177 ttt = m->mat[i][iswap];
178 m->mat[i][iswap] = m->mat[i][jswap];
179 m->mat[i][jswap] = ttt;
183 void swap_mat(t_mat *m)
188 tmp = init_mat(m->nn, FALSE);
189 for (i = 0; (i < m->nn); i++)
191 for (j = 0; (j < m->nn); j++)
193 tmp->mat[m->m_ind[i]][m->m_ind[j]] = m->mat[i][j];
196 /*tmp->mat[i][j] = m->mat[m->m_ind[i]][m->m_ind[j]]; */
197 for (i = 0; (i < m->nn); i++)
199 for (j = 0; (j < m->nn); j++)
201 m->mat[i][j] = tmp->mat[i][j];
207 void low_rmsd_dist(const char *fn, real maxrms, int nn, real **mat,
208 const output_env_t oenv)
216 for (i = 0; i < nn; i++)
218 for (j = i+1; j < nn; j++)
220 x = (int)(fac*mat[i][j]+0.5);
228 fp = xvgropen(fn, "RMS Distribution", "RMS (nm)", "a.u.", oenv);
229 for (i = 0; (i < 101); i++)
231 fprintf(fp, "%10g %10d\n", i/fac, histo[i]);
237 void rmsd_distribution(const char *fn, t_mat *rms, const output_env_t oenv)
239 low_rmsd_dist(fn, rms->maxrms, rms->nn, rms->mat, oenv);
242 t_clustid *new_clustid(int n1)
248 for (i = 0; (i < n1); i++)