Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / topology / mtop_util.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2012,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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37 #ifndef GMX_TOPOLOGY_MTOP_UTIL_H
38 #define GMX_TOPOLOGY_MTOP_UTIL_H
39
40 #include "gromacs/legacyheaders/types/inputrec.h"
41 #include "gromacs/utility/basedefinitions.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 struct gmx_localtop_t;
48 struct gmx_moltype_t;
49 struct gmx_mtop_t;
50 struct t_atom;
51 struct t_atoms;
52 struct t_block;
53 struct t_ilist;
54 struct t_topology;
55
56 /* Should be called after generating or reading mtop,
57  * to set some compute intesive variables to avoid
58  * N^2 operations later on.
59  */
60 void
61 gmx_mtop_finalize(struct gmx_mtop_t *mtop);
62
63 /* Counts the number of atoms of each type. State should be 0 for
64  * state A and 1 for state B types.  typecount should have at
65  * least mtop->ffparams.atnr elements.
66  */
67 void
68 gmx_mtop_count_atomtypes(const struct gmx_mtop_t *mtop, int state, int typecount[]);
69
70 /* Returns the total number of charge groups in mtop */
71 int
72 ncg_mtop(const struct gmx_mtop_t *mtop);
73
74 /* Removes the charge groups, i.e. makes single atom charge groups, in mtop */
75 void gmx_mtop_remove_chargegroups(struct gmx_mtop_t *mtop);
76
77
78 /* Abstract data type for looking up atoms by global atom number */
79 typedef struct gmx_mtop_atomlookup *gmx_mtop_atomlookup_t;
80
81 /* Initialize atom lookup by global atom number */
82 gmx_mtop_atomlookup_t
83 gmx_mtop_atomlookup_init(const struct gmx_mtop_t *mtop);
84
85 /* As gmx_mtop_atomlookup_init, but optimized for atoms involved in settle */
86 gmx_mtop_atomlookup_t
87 gmx_mtop_atomlookup_settle_init(const struct gmx_mtop_t *mtop);
88
89 /* Destroy a gmx_mtop_atomlookup_t data structure */
90 void
91 gmx_mtop_atomlookup_destroy(gmx_mtop_atomlookup_t alook);
92
93
94 /* Returns a pointer to the t_atom struct belonging to atnr_global.
95  * This can be an expensive operation, so if possible use
96  * one of the atom loop constructs below.
97  */
98 void
99 gmx_mtop_atomnr_to_atom(const gmx_mtop_atomlookup_t alook,
100                         int                         atnr_global,
101                         struct t_atom             **atom);
102
103
104 /* Returns a pointer to the molecule interaction array ilist_mol[F_NRE]
105  * and the local atom number in the molecule belonging to atnr_global.
106  */
107 void
108 gmx_mtop_atomnr_to_ilist(const gmx_mtop_atomlookup_t alook,
109                          int atnr_global,
110                          struct t_ilist **ilist_mol, int *atnr_offset);
111
112
113 /* Returns the molecule block index
114  * and the molecule number in the block
115  * and the atom number offset for the atom indices in moltype
116  * belonging to atnr_global.
117  */
118 void
119 gmx_mtop_atomnr_to_molblock_ind(const gmx_mtop_atomlookup_t alook,
120                                 int atnr_global,
121                                 int *molb, int *molnr, int *atnr_mol);
122
123
124 /* Returns atom name, global resnr and residue name  of atom atnr_global */
125 void
126 gmx_mtop_atominfo_global(const struct gmx_mtop_t *mtop, int atnr_global,
127                          char **atomname, int *resnr, char **resname);
128
129
130 /* Abstract type for atom loop over all atoms */
131 typedef struct gmx_mtop_atomloop_all *gmx_mtop_atomloop_all_t;
132
133 /* Initialize an atom loop over all atoms in the system.
134  * The order of the atoms will be as in the state struct.
135  * Only use this when you really need to loop over all atoms,
136  * i.e. when you use groups which might differ per molecule,
137  * otherwise use gmx_mtop_atomloop_block.
138  */
139 gmx_mtop_atomloop_all_t
140 gmx_mtop_atomloop_all_init(const struct gmx_mtop_t *mtop);
141
142 /* Loop to the next atom.
143  * When not at the end:
144  *   returns TRUE and at_global,
145  *   writes the global atom number in *at_global
146  *   and sets the pointer atom to the t_atom struct of that atom.
147  * When at the end, destroys aloop and returns FALSE.
148  * Use as:
149  * gmx_mtop_atomloop_all_t aloop;
150  * aloop = gmx_mtop_atomloop_all_init(mtop)
151  * while (gmx_mtop_atomloop_all_next(aloop,&at_global,&atom)) {
152  *     ...
153  * }
154  */
155 gmx_bool
156 gmx_mtop_atomloop_all_next(gmx_mtop_atomloop_all_t aloop,
157                            int *at_global, struct t_atom **atom);
158
159 /* Return the atomname, the residue number and residue name
160  * of the current atom in the loop.
161  */
162 void
163 gmx_mtop_atomloop_all_names(gmx_mtop_atomloop_all_t aloop,
164                             char **atomname, int *resnr, char **resname);
165
166 /* Return the a pointer to the moltype struct of the current atom
167  * in the loop and the atom number in the molecule.
168  */
169 void
170 gmx_mtop_atomloop_all_moltype(gmx_mtop_atomloop_all_t aloop,
171                               struct gmx_moltype_t **moltype, int *at_mol);
172
173
174 /* Abstract type for atom loop over atoms in all molecule blocks */
175 typedef struct gmx_mtop_atomloop_block *gmx_mtop_atomloop_block_t;
176
177 /* Initialize an atom loop over atoms in all molecule blocks the system.
178  */
179 gmx_mtop_atomloop_block_t
180 gmx_mtop_atomloop_block_init(const struct gmx_mtop_t *mtop);
181
182 /* Loop to the next atom.
183  * When not at the end:
184  *   returns TRUE
185  *   sets the pointer atom to the t_atom struct of that atom
186  *   and return the number of molecules corresponding to this atom.
187  * When at the end, destroys aloop and returns FALSE.
188  * Use as:
189  * gmx_mtop_atomloop_block_t aloop;
190  * aloop = gmx_mtop_atomloop_block_init(mtop)
191  * while (gmx_mtop_atomloop_block_next(aloop,&atom,&nmol)) {
192  *     ...
193  * }
194  */
195 gmx_bool
196 gmx_mtop_atomloop_block_next(gmx_mtop_atomloop_block_t aloop,
197                              struct t_atom **atom, int *nmol);
198
199
200 /* Abstract type for ilist loop over all ilists */
201 typedef struct gmx_mtop_ilistloop *gmx_mtop_ilistloop_t;
202
203 /* Initialize an ilist loop over all molecule types in the system. */
204 gmx_mtop_ilistloop_t
205 gmx_mtop_ilistloop_init(const struct gmx_mtop_t *mtop);
206
207
208 /* Loop to the next molecule,
209  * When not at the end:
210  *   returns TRUE and a pointer to the next array ilist_mol[F_NRE],
211  *   writes the number of molecules for this ilist in *nmol.
212  * When at the end, destroys iloop and returns FALSE.
213  */
214 gmx_bool
215 gmx_mtop_ilistloop_next(gmx_mtop_ilistloop_t iloop,
216                         struct t_ilist **ilist_mol, int *nmol);
217
218
219 /* Abstract type for ilist loop over all ilists of all molecules */
220 typedef struct gmx_mtop_ilistloop_all *gmx_mtop_ilistloop_all_t;
221
222 /* Initialize an ilist loop over all molecule types in the system.
223  * Only use this when you really need to loop over all molecules,
224  * i.e. when you use groups which might differ per molecule,
225  * otherwise use gmx_mtop_ilistloop.
226  */
227 gmx_mtop_ilistloop_all_t
228 gmx_mtop_ilistloop_all_init(const struct gmx_mtop_t *mtop);
229
230 /* Loop to the next molecule,
231  * When not at the end:
232  *   returns TRUE and a pointer to the next array ilist_mol[F_NRE],
233  *   writes the atom offset which should be added to iatoms in atnr_offset.
234  * When at the end, destroys iloop and returns FALSE.
235  */
236 gmx_bool
237 gmx_mtop_ilistloop_all_next(gmx_mtop_ilistloop_all_t iloop,
238                             struct t_ilist **ilist_mol, int *atnr_offset);
239
240
241 /* Returns the total number of interactions in the system of type ftype */
242 int
243 gmx_mtop_ftype_count(const struct gmx_mtop_t *mtop, int ftype);
244
245
246 /* Returns a charge group index for the whole system */
247 struct t_block
248 gmx_mtop_global_cgs(const struct gmx_mtop_t *mtop);
249
250
251 /* Returns a single t_atoms struct for the whole system */
252 struct t_atoms
253 gmx_mtop_global_atoms(const struct gmx_mtop_t *mtop);
254
255
256 /* Make all charge groups the size of one atom.
257  * When bKeepSingleMolCG==TRUE keep charge groups for molecules
258  * that consist of a single charge group.
259  */
260 void
261 gmx_mtop_make_atomic_charge_groups(struct gmx_mtop_t *mtop, gmx_bool bKeepSingleMolCG);
262
263
264 /* Generate a 'local' topology for the whole system.
265  * When ir!=NULL the free energy interactions will be sorted to the end.
266  */
267 struct gmx_localtop_t *
268 gmx_mtop_generate_local_top(const struct gmx_mtop_t *mtop, const t_inputrec *ir);
269
270
271 /* Converts a gmx_mtop_t struct to t_topology.
272  * All memory relating only to mtop will be freed.
273  */
274 struct t_topology
275 gmx_mtop_t_to_t_topology(struct gmx_mtop_t *mtop);
276
277 #ifdef __cplusplus
278 }
279 #endif
280
281 #endif