Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / selection / selelem.h
index 8c562294d58777792e0f1da26b17da29013a4830..ddc429850f7f3e8d7d2a89a33a72afad46d54e37 100644 (file)
@@ -1,32 +1,36 @@
 /*
+ * 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
@@ -39,7 +43,7 @@
  * This is an implementation header: there should be no need to use it outside
  * this directory.
  *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_selection
  */
 #ifndef GMX_SELECTION_SELELEM_H
 
 #include <boost/shared_ptr.hpp>
 
-#include "gromacs/legacyheaders/types/simple.h"
+#include "gromacs/selection/indexutil.h"
 #include "gromacs/utility/common.h"
+#include "gromacs/utility/real.h"
 
-#include "indexutil.h"
 #include "selvalue.h"
 
 struct gmx_ana_poscalc_t;
@@ -112,12 +116,12 @@ typedef enum
 /** Defines the arithmetic operation of gmx::SelectionTreeElement objects with type \ref SEL_ARITHMETIC. */
 typedef enum
 {
-    ARITH_PLUS,         /**< + */
-    ARITH_MINUS,        /**< - */
-    ARITH_NEG,          /**< Unary - */
-    ARITH_MULT,         /**< * */
-    ARITH_DIV,          /**< / */
-    ARITH_EXP           /**< ^ (to power) */
+    ARITH_PLUS,         /**< Addition (`+`) */
+    ARITH_MINUS,        /**< Subtraction (`-`) */
+    ARITH_NEG,          /**< Unary `-` */
+    ARITH_MULT,         /**< Multiplication (`*`) */
+    ARITH_DIV,          /**< Division (`/`) */
+    ARITH_EXP           /**< Power (`^`) */
 } e_arithmetic_t;
 
 /** Returns a string representation of the type of a gmx::SelectionTreeElement. */
@@ -163,6 +167,10 @@ _gmx_sel_value_type_str(const gmx_ana_selvalue_t *val);
  * The element (or one of its children) is dynamic.
  */
 #define SEL_DYNAMIC     16
+/*! \brief
+ * The element may contain atom indices in an unsorted order.
+ */
+#define SEL_UNSORTED    32
 /*! \brief
  * Mask that covers the flags that describe the number of values.
  */
@@ -229,12 +237,14 @@ _gmx_sel_value_type_str(const gmx_ana_selvalue_t *val);
 namespace gmx
 {
 
+class ExceptionInitializer;
+
 /*! \brief
  * Function pointer for evaluating a gmx::SelectionTreeElement.
  */
-typedef void (*sel_evalfunc)(struct gmx_sel_evaluate_t *data,
+typedef void (*sel_evalfunc)(struct gmx_sel_evaluate_t         *data,
                              const SelectionTreeElementPointer &sel,
-                             gmx_ana_index_t *g);
+                             gmx_ana_index_t                   *g);
 
 /*! \internal \brief
  * Represents an element of a selection expression.
@@ -302,6 +312,51 @@ class SelectionTreeElement
         void setName(const char *name) { name_ = (name != NULL ? name : ""); }
         //! \copydoc setName(const char *)
         void setName(const std::string &name) { name_ = name; }
+        /*! \brief
+         * Sets the name of a root element if it is missing.
+         *
+         * \param[in] selectionText  Full selection text to use as a fallback.
+         * \throws    std::bad_alloc if out of memory.
+         *
+         * If index groups have not yet been set and the selection is a result
+         * of a group reference, the name may still be empty after this call.
+         *
+         * Strong exception safety guarantee.
+         */
+        void fillNameIfMissing(const char *selectionText);
+
+        /*! \brief
+         * Checks that this element and its children do not contain unsupported
+         * elements with unsorted atoms.
+         *
+         * \param[in] bUnsortedAllowed Whether this element's parents allow it
+         *     to have unsorted atoms.
+         * \param     errors           Object for reporting any error messages.
+         * \throws    std::bad_alloc if out of memory.
+         *
+         * Errors are reported as nested exceptions in \p errors.
+         */
+        void checkUnsortedAtoms(bool                  bUnsortedAllowed,
+                                ExceptionInitializer *errors) const;
+        /*! \brief
+         * Resolves an unresolved reference to an index group.
+         *
+         * \param[in] grps   Index groups to use to resolve the reference.
+         * \param[in] natoms Maximum number of atoms the selections can evaluate to
+         *     (zero if the topology/atom count is not set yet).
+         * \throws    std::bad_alloc if out of memory.
+         * \throws    InconsistentInputError if the reference cannot be
+         *     resolved.
+         */
+        void resolveIndexGroupReference(gmx_ana_indexgrps_t *grps, int natoms);
+        /*! \brief
+         * Checks that an index group has valid atom indices.
+         *
+         * \param[in] natoms Maximum number of atoms the selections can evaluate to.
+         * \throws    std::bad_alloc if out of memory.
+         * \throws    InconsistentInputError if there are invalid atom indices.
+         */
+        void checkIndexGroup(int natoms);
 
         //! Type of the element.
         e_selelem_t                         type;
@@ -408,7 +463,7 @@ _gmx_sel_print_evalfunc_name(FILE *fp, gmx::sel_evalfunc evalfunc);
 /** Sets the value type of a gmx::SelectionTreeElement. */
 void
 _gmx_selelem_set_vtype(const gmx::SelectionTreeElementPointer &sel,
-                       e_selvalue_t vtype);
+                       e_selvalue_t                            vtype);
 
 /** Frees the memory allocated for a selection method. */
 void