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) 2012,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.
37 /* This file is completely threadsafe - keep it that way! */
38 #include "conformation-utilities.h"
49 static real dist2(t_pbc *pbc, rvec x, rvec y)
53 pbc_dx(pbc, x, y, dx);
58 static real distance_to_z(rvec x)
60 return (sqr(x[XX])+sqr(x[YY]));
63 static void low_rotate_conf(int natom, rvec *x, real alfa, real beta, real gamma)
68 for (i = 0; i < natom; i++)
70 copy_rvec(x[i], x_old);
71 /*calculate new x[i] by rotation alfa around the x-axis*/
73 x[i][YY] = cos(alfa)*x_old[YY] - sin(alfa)*x_old[ZZ];
74 x[i][ZZ] = sin(alfa)*x_old[YY] + cos(alfa)*x_old[ZZ];
75 copy_rvec(x[i], x_old);
76 /*calculate new x[i] by rotation beta around the y-axis*/
77 x[i][XX] = cos(beta)*x_old[XX] + sin(beta)*x_old[ZZ];
79 x[i][ZZ] = -sin(beta)*x_old[XX] + cos(beta)*x_old[ZZ];
80 copy_rvec(x[i], x_old);
81 /*calculate new x[i] by rotation gamma around the z-axis*/
82 x[i][XX] = x_old[XX]*cos(gamma) - x_old[YY]*sin(gamma);
83 x[i][YY] = x_old[XX]*sin(gamma) + x_old[YY]*cos(gamma);
88 static void low_rotate_conf_indexed(int nindex, atom_id *index, rvec *x, real alfa, real beta, real gamma)
93 for (i = 0; i < nindex; i++)
95 copy_rvec(x[index[i]], x_old);
96 /*calculate new x[index[i]] by rotation alfa around the x-axis*/
97 x[index[i]][XX] = x_old[XX];
98 x[index[i]][YY] = cos(alfa)*x_old[YY] - sin(alfa)*x_old[ZZ];
99 x[index[i]][ZZ] = sin(alfa)*x_old[YY] + cos(alfa)*x_old[ZZ];
100 copy_rvec(x[index[i]], x_old);
101 /*calculate new x[index[i]] by rotation beta around the y-axis*/
102 x[index[i]][XX] = cos(beta)*x_old[XX] + sin(beta)*x_old[ZZ];
103 x[index[i]][YY] = x_old[YY];
104 x[index[i]][ZZ] = -sin(beta)*x_old[XX] + cos(beta)*x_old[ZZ];
105 copy_rvec(x[index[i]], x_old);
106 /*calculate new x[index[i]] by rotation gamma around the z-axis*/
107 x[index[i]][XX] = x_old[XX]*cos(gamma) - x_old[YY]*sin(gamma);
108 x[index[i]][YY] = x_old[XX]*sin(gamma) + x_old[YY]*cos(gamma);
109 x[index[i]][ZZ] = x_old[ZZ];
113 void rotate_conf(int natom, rvec *x, rvec *v, real alfa, real beta, real gamma)
117 low_rotate_conf(natom, x, alfa, beta, gamma);
121 low_rotate_conf(natom, v, alfa, beta, gamma);
125 /* Make a new box around a configuration*/
126 void make_new_box(int natoms, rvec *x, matrix box, rvec box_space,
133 /*calculate minimum and maximum x[0..DIM-1]*/
134 for (m = 0; (m < DIM); m++)
136 xmin[m] = xmax[m] = x[0][m];
138 for (i = 1; (i < natoms); i++)
140 for (m = 0; m < DIM; m++)
142 xmin[m] = min(xmin[m], x[i][m]);
143 xmax[m] = max(xmax[m], x[i][m]);
147 /*calculate the new box sizes for cubic and octahedral ...*/
148 for (m = 0; (m < DIM); m++)
150 box[m][m] = xmax[m]-xmin[m]+2*box_space[m];
153 /*move the molecule to the center of the box*/
156 for (i = 0; (i < natoms); i++)
158 for (m = 0; (m < DIM); m++)
160 x[i][m] += 0.5*(box[m][m]-xmin[m]-xmax[m]);