/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
+ * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
*
- * G R O M A C S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
*
- * GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
*
* To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
*/
/*! \internal \file
* \brief
* Implements functions in centerofmass.h.
*
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
-#include <typedefs.h>
-#include <pbc.h>
-#include <vec.h>
+#include "centerofmass.h"
-#include "gromacs/selection/centerofmass.h"
+#include <errno.h>
+
+#include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/topology/block.h"
+#include "gromacs/topology/topology.h"
-/*!
- * \param[in] top Topology structure (unused, can be NULL).
- * \param[in] x Position vectors of all atoms.
- * \param[in] nrefat Number of atoms in the index.
- * \param[in] index Indices of atoms.
- * \param[out] xout COG position for the indexed atoms.
- * \returns 0 on success.
- */
int
-gmx_calc_cog(t_topology *top, rvec x[], int nrefat, atom_id index[], rvec xout)
+gmx_calc_cog(t_topology * /* top */, rvec x[], int nrefat, atom_id index[], rvec xout)
{
int m, ai;
mtot = 0;
for (m = 0; m < nrefat; ++m)
{
- ai = index[m];
+ ai = index[m];
mass = top->atoms.atom[ai].m;
for (j = 0; j < DIM; ++j)
{
* \param[in] index Indices of atoms.
* \param[out] fout Force on the COG position for the indexed atoms.
* \returns 0 on success, EINVAL if \p top is NULL.
- *
- * No special function is provided for calculating the force on the center of
- * mass, because this can be achieved with gmx_calc_cog().
*/
int
gmx_calc_cog_f(t_topology *top, rvec f[], int nrefat, atom_id index[], rvec fout)
mtot = 0;
for (m = 0; m < nrefat; ++m)
{
- ai = index[m];
+ ai = index[m];
mass = top->atoms.atom[ai].m;
for (j = 0; j < DIM; ++j)
{
}
mtot += mass;
}
- svmul(mtot, fout, fout);
+ svmul(mtot / nrefat, fout, fout);
+ return 0;
+}
+
+int
+gmx_calc_com_f(t_topology * /* top */, rvec f[], int nrefat, atom_id index[], rvec fout)
+{
+ clear_rvec(fout);
+ for (int m = 0; m < nrefat; ++m)
+ {
+ const int ai = index[m];
+ rvec_inc(fout, f[ai]);
+ }
return 0;
}
* \param[out] fout Force on the COM/COG position for the indexed atoms.
* \returns 0 on success, EINVAL if \p top is NULL and \p bMass is false.
*
- * Calls either gmx_calc_cog() or gmx_calc_cog_f() depending on the value of
+ * Calls either gmx_calc_cog_f() or gmx_calc_com_f() depending on the value of
* \p bMass.
* Other parameters are passed unmodified to these functions.
*/
{
if (bMass)
{
- return gmx_calc_cog(top, f, nrefat, index, fout);
+ return gmx_calc_com_f(top, f, nrefat, index, fout);
}
else
{
mtot = 0;
for (m = 0; m < nrefat; ++m)
{
- ai = index[m];
+ ai = index[m];
mass = top->atoms.atom[ai].m;
for (j = 0; j < DIM; ++j)
{
bChanged = false;
for (m = 0; m < nrefat; ++m)
{
- ai = index[m];
+ ai = index[m];
mass = top->atoms.atom[ai].m / mtot;
pbc_dx(pbc, x[ai], xout, dx);
rvec_add(xout, dx, xtest);
}
-/*!
- * \param[in] top Topology structure (unused, can be NULL).
- * \param[in] x Position vectors of all atoms.
- * \param[in] block t_block structure that divides \p index into blocks.
- * \param[in] index Indices of atoms.
- * \param[out] xout \p block->nr COG positions.
- * \returns 0 on success.
- */
int
-gmx_calc_cog_block(t_topology *top, rvec x[], t_block *block, atom_id index[],
+gmx_calc_cog_block(t_topology * /* top */, rvec x[], t_block *block, atom_id index[],
rvec xout[])
{
int b, i, ai;
mtot = 0;
for (i = block->index[b]; i < block->index[b+1]; ++i)
{
- ai = index[i];
+ ai = index[i];
mass = top->atoms.atom[ai].m;
for (d = 0; d < DIM; ++d)
{
mtot = 0;
for (i = block->index[b]; i < block->index[b+1]; ++i)
{
- ai = index[i];
+ ai = index[i];
mass = top->atoms.atom[ai].m;
for (d = 0; d < DIM; ++d)
{
}
mtot += mass;
}
- svmul(mtot, fb, fout[b]);
+ svmul(mtot / (block->index[b+1] - block->index[b]), fb, fout[b]);
+ }
+ return 0;
+}
+
+int
+gmx_calc_com_f_block(t_topology * /* top */, rvec f[], t_block *block, atom_id index[],
+ rvec fout[])
+{
+ for (int b = 0; b < block->nr; ++b)
+ {
+ rvec fb;
+ clear_rvec(fb);
+ for (int i = block->index[b]; i < block->index[b+1]; ++i)
+ {
+ const int ai = index[i];
+ rvec_inc(fb, f[ai]);
+ }
+ copy_rvec(fb, fout[b]);
}
return 0;
}
* \param[out] fout \p block->nr forces on the COM/COG positions.
* \returns 0 on success, EINVAL if \p top is NULL and \p bMass is true.
*
- * Calls either gmx_calc_com_block() or gmx_calc_cog_block() depending on the
- * value of \p bMass.
+ * Calls either gmx_calc_com_f_block() or gmx_calc_cog_f_block() depending on
+ * the value of \p bMass.
* Other parameters are passed unmodified to these functions.
*/
int
{
if (bMass)
{
- return gmx_calc_cog_block(top, f, block, index, fout);
+ return gmx_calc_com_f_block(top, f, block, index, fout);
}
else
{