494d39b26e0e703aeaed81156f5b5b72ebf03108
[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,2014, 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 /*! \internal \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/types/simple.h"
78 #include "../math/vectypes.h"
79
80 struct t_block;
81 struct t_blocka;
82 struct t_pbc;
83 struct t_topology;
84
85 /*! \brief
86  * Calculate a single center of geometry.
87  *
88  * \param[in]  top    Topology structure (unused, can be NULL).
89  * \param[in]  x      Position vectors of all atoms.
90  * \param[in]  nrefat Number of atoms in the index.
91  * \param[in]  index  Indices of atoms.
92  * \param[out] xout   COG position for the indexed atoms.
93  * \returns    0 on success.
94  */
95 int
96 gmx_calc_cog(t_topology *top, rvec x[], int nrefat, atom_id index[], rvec xout);
97 /** Calculate a single center of mass. */
98 int
99 gmx_calc_com(t_topology *top, rvec x[], int nrefat, atom_id index[], rvec xout);
100 /** Calculate force on a single center of geometry. */
101 int
102 gmx_calc_cog_f(t_topology *top, rvec f[], int nrefat, atom_id index[], rvec fout);
103 /*! \brief
104  * Calculate force on a single center of mass.
105  *
106  * \param[in]  top    Topology structure (unused, can be NULL).
107  * \param[in]  f      Forces on all atoms.
108  * \param[in]  nrefat Number of atoms in the index.
109  * \param[in]  index  Indices of atoms.
110  * \param[out] fout   Force on the COM position for the indexed atoms.
111  * \returns    0 on success.
112  */
113 int
114 gmx_calc_com_f(t_topology *top, rvec f[], int nrefat, atom_id index[], rvec fout);
115 /** Calculate a single center of mass/geometry. */
116 int
117 gmx_calc_comg(t_topology *top, rvec x[], int nrefat, atom_id index[],
118               bool bMass, rvec xout);
119 /** Calculate force on a single center of mass/geometry. */
120 int
121 gmx_calc_comg_f(t_topology *top, rvec f[], int nrefat, atom_id index[],
122                 bool bMass, rvec fout);
123
124 /** Calculate a single center of geometry iteratively, taking PBC into account. */
125 int
126 gmx_calc_cog_pbc(t_topology *top, rvec x[], t_pbc *pbc,
127                  int nrefat, atom_id index[], rvec xout);
128 /** Calculate a single center of mass iteratively, taking PBC into account. */
129 int
130 gmx_calc_com_pbc(t_topology *top, rvec x[], t_pbc *pbc,
131                  int nrefat, atom_id index[], rvec xout);
132 /** Calculate a single center of mass/geometry iteratively with PBC. */
133 int
134 gmx_calc_comg_pbc(t_topology *top, rvec x[], t_pbc *pbc,
135                   int nrefat, atom_id index[], bool bMass, rvec xout);
136
137 /*! \brief
138  * Calculate centers of geometry for a blocked index.
139  *
140  * \param[in]  top   Topology structure (unused, can be NULL).
141  * \param[in]  x     Position vectors of all atoms.
142  * \param[in]  block t_block structure that divides \p index into blocks.
143  * \param[in]  index Indices of atoms.
144  * \param[out] xout  \p block->nr COG positions.
145  * \returns    0 on success.
146  */
147 int
148 gmx_calc_cog_block(t_topology *top, rvec x[], t_block *block,
149                    atom_id index[], rvec xout[]);
150 /** Calculate centers of mass for a blocked index. */
151 int
152 gmx_calc_com_block(t_topology *top, rvec x[], t_block *block,
153                    atom_id index[], rvec xout[]);
154 /** Calculate forces on centers of geometry for a blocked index. */
155 int
156 gmx_calc_cog_f_block(t_topology *top, rvec f[], t_block *block,
157                      atom_id index[], rvec fout[]);
158 /*! \brief
159  * Calculate forces on centers of mass for a blocked index.
160  *
161  * \param[in]  top   Topology structure (unused, can be NULL).
162  * \param[in]  f     Forces on all atoms.
163  * \param[in]  block t_block structure that divides \p index into blocks.
164  * \param[in]  index Indices of atoms.
165  * \param[out] fout  \p block->nr Forces on COM positions.
166  * \returns    0 on success.
167  */
168 int
169 gmx_calc_com_f_block(t_topology *top, rvec f[], t_block *block,
170                      atom_id index[], rvec fout[]);
171 /** Calculate centers of mass/geometry for a blocked index. */
172 int
173 gmx_calc_comg_block(t_topology *top, rvec x[], t_block *block,
174                     atom_id index[], bool bMass, rvec xout[]);
175 /** Calculate forces on centers of mass/geometry for a blocked index. */
176 int
177 gmx_calc_comg_f_block(t_topology *top, rvec f[], t_block *block,
178                       atom_id index[], bool bMass, rvec fout[]);
179 /** Calculate centers of mass/geometry for a set of blocks; */
180 int
181 gmx_calc_comg_blocka(t_topology *top, rvec x[], t_blocka *block,
182                      bool bMass, rvec xout[]);
183 /** Calculate forces on centers of mass/geometry for a set of blocks; */
184 int
185 gmx_calc_comg_f_blocka(t_topology *top, rvec x[], t_blocka *block,
186                        bool bMass, rvec xout[]);
187
188 #endif