Updated selection documentation.
[gromacs/qmmm-gamess-us.git] / src / gmxlib / trajana / position.c
blob60763dd8c829f48ecae6b18e5f9a9d04950da08e
1 /*
3 * This source code is part of
5 * G R O M A C S
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
31 /*! \internal \file
32 * \brief Implementation of functions in position.h.
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
38 #include <string.h>
40 #include <smalloc.h>
41 #include <typedefs.h>
42 #include <vec.h>
44 #include <indexutil.h>
45 #include <position.h>
47 /*!
48 * \param[out] pos Output structure.
50 * Any contents of \p pos are discarded without freeing.
52 void
53 gmx_ana_pos_clear(gmx_ana_pos_t *pos)
55 pos->nr = 0;
56 pos->x = NULL;
57 gmx_ana_indexmap_clear(&pos->m);
58 pos->g = NULL;
61 /*!
62 * \param[in,out] pos Position data structure.
63 * \param[in] n Maximum number of positions.
64 * \param[in] isize Maximum number of atoms.
66 * Ensures that enough memory is allocated in \p pos to calculate \p n
67 * positions from \p isize atoms.
69 void
70 gmx_ana_pos_reserve(gmx_ana_pos_t *pos, int n, int isize)
72 if (pos->nr < n)
74 pos->nr = n;
75 srenew(pos->x, n);
77 if (isize > 0)
79 gmx_ana_indexmap_reserve(&pos->m, n, isize);
83 /*!
84 * \param[out] pos Position data structure to initialize.
85 * \param[in] x Position vector to use.
87 void
88 gmx_ana_pos_init_const(gmx_ana_pos_t *pos, rvec x)
90 gmx_ana_pos_clear(pos);
91 pos->nr = 1;
92 snew(pos->x, 1);
93 copy_rvec(x, pos->x[0]);
94 gmx_ana_indexmap_init(&pos->m, NULL, NULL, INDEX_UNKNOWN);
95 pos->g = NULL;
98 /*!
99 * \param[in,out] pos Position data structure.
101 * Frees any memory allocated within \p pos.
102 * The pointer \p pos itself is not freed.
104 * \see gmx_ana_pos_free()
106 void
107 gmx_ana_pos_deinit(gmx_ana_pos_t *pos)
109 pos->nr = 0;
110 sfree(pos->x); pos->x = NULL;
111 gmx_ana_indexmap_deinit(&pos->m);
115 * \param[in,out] pos Position data structure.
117 * Frees any memory allocated for \p pos.
118 * The pointer \p pos is also freed, and is invalid after the call.
120 * \see gmx_ana_pos_deinit()
122 void
123 gmx_ana_pos_free(gmx_ana_pos_t *pos)
125 gmx_ana_pos_deinit(pos);
126 sfree(pos);
130 * \param[in,out] dest Destination positions.
131 * \param[in] src Source positions.
132 * \param[in] bFirst If TRUE, memory is allocated for \p dest and a full
133 * copy is made; otherwise, only variable parts are copied, and no memory
134 * is allocated.
136 * \p dest should have been initialized somehow (calloc() is enough).
138 void
139 gmx_ana_pos_copy(gmx_ana_pos_t *dest, gmx_ana_pos_t *src, bool bFirst)
141 if (bFirst)
143 gmx_ana_pos_reserve(dest, src->nr, 0);
145 dest->nr = src->nr;
146 memcpy(dest->x, src->x, dest->nr*sizeof(*dest->x));
147 gmx_ana_indexmap_copy(&dest->m, &src->m, bFirst);
148 dest->g = src->g;