Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / selection / centerofmass.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2009,2010,2011,2013, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \file
36  * \brief API for calculation of centers of mass/geometry.
37  *
38  * This header defines a few functions that can be used to calculate
39  * centers of mass/geometry for a group of atoms.
40  * These routines can be used independently of the other parts of the
41  * library, but they are also used internally by the selection engine.
42  * In most cases, it should not be necessary to call these functions
43  * directly.
44  * Instead, one should write an analysis tool such that it gets all
45  * positions through selections.
46  *
47  * The functions in the header can be divided into a few groups based on the
48  * parameters they take. The simplest group of functions calculates the center
49  * of a single group of atoms:
50  *  - gmx_calc_cog(): Calculates the center of geometry (COG) of a given
51  *    group of atoms.
52  *  - gmx_calc_com(): Calculates the center of mass (COM) of a given group
53  *    of atoms.
54  *  - gmx_calc_comg(): Calculates either the COM or COG, based on a
55  *    boolean flag.
56  *
57  * A second set of routines is provided for calculating the centers for groups
58  * that wrap over periodic boundaries (gmx_calc_cog_pbc(), gmx_calc_com_pbc(),
59  * gmx_calc_comg_pbc()). These functions are slower, because they need to
60  * adjust the center iteratively.
61  *
62  * It is also possible to calculate centers for several groups of atoms in
63  * one call. The functions gmx_calc_cog_block(), gmx_calc_com_block() and
64  * gmx_calc_comg_block() take an index group and a partitioning of that index
65  * group (as a \c t_block structure), and calculate the centers for
66  * each group defined by the \c t_block structure separately.
67  *
68  * Finally, there is a function gmx_calc_comg_blocka() that takes both the
69  * index group and the partitioning as a single \c t_blocka structure.
70  *
71  * \author Teemu Murtola <teemu.murtola@gmail.com>
72  * \ingroup module_selection
73  */
74 #ifndef GMX_SELECTION_CENTEROFMASS_H
75 #define GMX_SELECTION_CENTEROFMASS_H
76
77 #include "../legacyheaders/typedefs.h"
78
79 /*! \brief
80  * Calculate a single center of geometry.
81  *
82  * \param[in]  top    Topology structure (unused, can be NULL).
83  * \param[in]  x      Position vectors of all atoms.
84  * \param[in]  nrefat Number of atoms in the index.
85  * \param[in]  index  Indices of atoms.
86  * \param[out] xout   COG position for the indexed atoms.
87  * \returns    0 on success.
88  */
89 int
90 gmx_calc_cog(t_topology *top, rvec x[], int nrefat, atom_id index[], rvec xout);
91 /** Calculate a single center of mass. */
92 int
93 gmx_calc_com(t_topology *top, rvec x[], int nrefat, atom_id index[], rvec xout);
94 /** Calculate force on a single center of geometry. */
95 int
96 gmx_calc_cog_f(t_topology *top, rvec f[], int nrefat, atom_id index[], rvec fout);
97 /*! \brief
98  * Calculate force on a single center of mass.
99  *
100  * \param[in]  top    Topology structure (unused, can be NULL).
101  * \param[in]  f      Forces on all atoms.
102  * \param[in]  nrefat Number of atoms in the index.
103  * \param[in]  index  Indices of atoms.
104  * \param[out] fout   Force on the COM position for the indexed atoms.
105  * \returns    0 on success.
106  */
107 int
108 gmx_calc_com_f(t_topology *top, rvec f[], int nrefat, atom_id index[], rvec fout);
109 /** Calculate a single center of mass/geometry. */
110 int
111 gmx_calc_comg(t_topology *top, rvec x[], int nrefat, atom_id index[],
112               bool bMass, rvec xout);
113 /** Calculate force on a single center of mass/geometry. */
114 int
115 gmx_calc_comg_f(t_topology *top, rvec f[], int nrefat, atom_id index[],
116                 bool bMass, rvec fout);
117
118 /** Calculate a single center of geometry iteratively, taking PBC into account. */
119 int
120 gmx_calc_cog_pbc(t_topology *top, rvec x[], t_pbc *pbc,
121                  int nrefat, atom_id index[], rvec xout);
122 /** Calculate a single center of mass iteratively, taking PBC into account. */
123 int
124 gmx_calc_com_pbc(t_topology *top, rvec x[], t_pbc *pbc,
125                  int nrefat, atom_id index[], rvec xout);
126 /** Calculate a single center of mass/geometry iteratively with PBC. */
127 int
128 gmx_calc_comg_pbc(t_topology *top, rvec x[], t_pbc *pbc,
129                   int nrefat, atom_id index[], bool bMass, rvec xout);
130
131 /*! \brief
132  * Calculate centers of geometry for a blocked index.
133  *
134  * \param[in]  top   Topology structure (unused, can be NULL).
135  * \param[in]  x     Position vectors of all atoms.
136  * \param[in]  block t_block structure that divides \p index into blocks.
137  * \param[in]  index Indices of atoms.
138  * \param[out] xout  \p block->nr COG positions.
139  * \returns    0 on success.
140  */
141 int
142 gmx_calc_cog_block(t_topology *top, rvec x[], t_block *block,
143                    atom_id index[], rvec xout[]);
144 /** Calculate centers of mass for a blocked index. */
145 int
146 gmx_calc_com_block(t_topology *top, rvec x[], t_block *block,
147                    atom_id index[], rvec xout[]);
148 /** Calculate forces on centers of geometry for a blocked index. */
149 int
150 gmx_calc_cog_f_block(t_topology *top, rvec f[], t_block *block,
151                      atom_id index[], rvec fout[]);
152 /*! \brief
153  * Calculate forces on centers of mass for a blocked index.
154  *
155  * \param[in]  top   Topology structure (unused, can be NULL).
156  * \param[in]  f     Forces on all atoms.
157  * \param[in]  block t_block structure that divides \p index into blocks.
158  * \param[in]  index Indices of atoms.
159  * \param[out] fout  \p block->nr Forces on COM positions.
160  * \returns    0 on success.
161  */
162 int
163 gmx_calc_com_f_block(t_topology *top, rvec f[], t_block *block,
164                      atom_id index[], rvec fout[]);
165 /** Calculate centers of mass/geometry for a blocked index. */
166 int
167 gmx_calc_comg_block(t_topology *top, rvec x[], t_block *block,
168                     atom_id index[], bool bMass, rvec xout[]);
169 /** Calculate forces on centers of mass/geometry for a blocked index. */
170 int
171 gmx_calc_comg_f_block(t_topology *top, rvec f[], t_block *block,
172                       atom_id index[], bool bMass, rvec fout[]);
173 /** Calculate centers of mass/geometry for a set of blocks; */
174 int
175 gmx_calc_comg_blocka(t_topology *top, rvec x[], t_blocka *block,
176                      bool bMass, rvec xout[]);
177 /** Calculate forces on centers of mass/geometry for a set of blocks; */
178 int
179 gmx_calc_comg_f_blocka(t_topology *top, rvec x[], t_blocka *block,
180                        bool bMass, rvec xout[]);
181
182 #endif