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.
37 #include "gromacs/pbcutil/rmpbc.h"
44 #include "gromacs/pbcutil/mshift.h"
45 #include "gromacs/pbcutil/pbc.h"
47 #include "gromacs/math/vec.h"
48 #include "gromacs/utility/futil.h"
49 #include "gromacs/utility/fatalerror.h"
50 #include "gromacs/utility/smalloc.h"
65 static t_graph *gmx_rmpbc_get_graph(gmx_rmpbc_t gpbc, int ePBC, int natoms)
73 || gpbc->idef->ntypes <= 0)
79 for (i = 0; i < gpbc->ngraph; i++)
81 if (natoms == gpbc->graph[i].natoms)
88 /* We'd like to check with the number of atoms in the topology,
89 * but we don't have that available.
90 * So we check against the number of atoms that gmx_rmpbc_init
93 if (natoms > gpbc->natoms_init)
95 gmx_fatal(FARGS, "Structure or trajectory file has more atoms (%d) than the topology (%d)", natoms, gpbc->natoms_init);
98 srenew(gpbc->graph, gpbc->ngraph);
99 gr = &gpbc->graph[gpbc->ngraph-1];
101 gr->gr = mk_graph(NULL, gpbc->idef, 0, natoms, FALSE, FALSE);
107 gmx_rmpbc_t gmx_rmpbc_init(t_idef *idef, int ePBC, int natoms)
113 gpbc->natoms_init = natoms;
115 /* This sets pbc when we now it,
116 * otherwise we guess it from the instantaneous box in the trajectory.
121 if (gpbc->idef->ntypes <= 0)
125 "WARNING: If there are molecules in the input trajectory file\n"
126 " that are broken across periodic boundaries, they\n"
127 " cannot be made whole (or treated as whole) without\n"
128 " you providing a run input file.\n\n");
134 void gmx_rmpbc_done(gmx_rmpbc_t gpbc)
140 for (i = 0; i < gpbc->ngraph; i++)
142 done_graph(gpbc->graph[i].gr);
143 sfree(gpbc->graph[i].gr);
145 if (gpbc->graph != NULL)
153 static int gmx_rmpbc_ePBC(gmx_rmpbc_t gpbc, matrix box)
155 if (NULL != gpbc && gpbc->ePBC >= 0)
161 return guess_ePBC(box);
165 void gmx_rmpbc(gmx_rmpbc_t gpbc, int natoms, matrix box, rvec x[])
170 ePBC = gmx_rmpbc_ePBC(gpbc, box);
171 gr = gmx_rmpbc_get_graph(gpbc, ePBC, natoms);
174 mk_mshift(stdout, gr, ePBC, box, x);
175 shift_self(gr, box, x);
179 void gmx_rmpbc_copy(gmx_rmpbc_t gpbc, int natoms, matrix box, rvec x[], rvec x_s[])
185 ePBC = gmx_rmpbc_ePBC(gpbc, box);
186 gr = gmx_rmpbc_get_graph(gpbc, ePBC, natoms);
189 mk_mshift(stdout, gr, ePBC, box, x);
190 shift_x(gr, box, x, x_s);
194 for (i = 0; i < natoms; i++)
196 copy_rvec(x[i], x_s[i]);
201 void gmx_rmpbc_trxfr(gmx_rmpbc_t gpbc, t_trxframe *fr)
206 if (fr->bX && fr->bBox)
208 ePBC = gmx_rmpbc_ePBC(gpbc, fr->box);
209 gr = gmx_rmpbc_get_graph(gpbc, ePBC, fr->natoms);
212 mk_mshift(stdout, gr, ePBC, fr->box, fr->x);
213 shift_self(gr, fr->box, fr->x);
218 void rm_gropbc(t_atoms *atoms, rvec x[], matrix box)
223 /* check periodic boundary */
224 for (n = 1; (n < atoms->nr); n++)
226 for (m = DIM-1; m >= 0; m--)
228 dist = x[n][m]-x[n-1][m];
229 if (fabs(dist) > 0.9*box[m][m])
233 for (d = 0; d <= m; d++)
235 x[n][d] -= box[m][d];
240 for (d = 0; d <= m; d++)
242 x[n][d] += box[m][d];