Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / selection / evaluate.cpp
index 7d23aef17a46d6829850cf21279c59c031c53ad3..dd3d3d1de59bccd2c6708afc0276ef6337408312 100644 (file)
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_selection
  */
-#include <string.h>
+#include "gmxpre.h"
+
+#include "evaluate.h"
 
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/vec.h"
+#include <string.h>
 
 #include "gromacs/math/utilities.h"
+#include "gromacs/math/vec.h"
 #include "gromacs/selection/indexutil.h"
-#include "gromacs/selection/poscalc.h"
 #include "gromacs/selection/selection.h"
-#include "gromacs/selection/selmethod.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/smalloc.h"
 
-#include "evaluate.h"
 #include "mempool.h"
+#include "poscalc.h"
 #include "selectioncollection-impl.h"
 #include "selelem.h"
+#include "selmethod.h"
 
 using gmx::SelectionTreeElement;
 using gmx::SelectionTreeElementPointer;
@@ -465,9 +467,9 @@ SelectionEvaluator::evaluateFinal(SelectionCollection *coll, int nframes)
  * Evaluates each child of \p sel in \p g.
  */
 void
-_gmx_sel_evaluate_children(gmx_sel_evaluate_t                *data,
-                           const SelectionTreeElementPointer &sel,
-                           gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_children(gmx_sel_evaluate_t                     *data,
+                           const gmx::SelectionTreeElementPointer &sel,
+                           gmx_ana_index_t                        *g)
 {
     SelectionTreeElementPointer child = sel->child;
     while (child)
@@ -499,7 +501,16 @@ _gmx_sel_evaluate_static(gmx_sel_evaluate_t                      * /* data */,
                          const gmx::SelectionTreeElementPointer &sel,
                          gmx_ana_index_t                        *g)
 {
-    gmx_ana_index_intersection(sel->v.u.g, &sel->u.cgrp, g);
+    if (sel->flags & SEL_UNSORTED)
+    {
+        // This only works if g contains all the atoms, but that is currently
+        // the only supported case.
+        gmx_ana_index_copy(sel->v.u.g, &sel->u.cgrp, false);
+    }
+    else
+    {
+        gmx_ana_index_intersection(sel->v.u.g, &sel->u.cgrp, g);
+    }
 }
 
 
@@ -522,9 +533,9 @@ _gmx_sel_evaluate_static(gmx_sel_evaluate_t                      * /* data */,
  * full subexpression handling.
  */
 void
-_gmx_sel_evaluate_subexpr_simple(gmx_sel_evaluate_t                *data,
-                                 const SelectionTreeElementPointer &sel,
-                                 gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_subexpr_simple(gmx_sel_evaluate_t                     *data,
+                                 const gmx::SelectionTreeElementPointer &sel,
+                                 gmx_ana_index_t                        *g)
 {
     if (sel->child->evaluate)
     {
@@ -550,9 +561,9 @@ _gmx_sel_evaluate_subexpr_simple(gmx_sel_evaluate_t                *data,
  * not need full subexpression handling.
  */
 void
-_gmx_sel_evaluate_subexpr_staticeval(gmx_sel_evaluate_t                *data,
-                                     const SelectionTreeElementPointer &sel,
-                                     gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_subexpr_staticeval(gmx_sel_evaluate_t                     *data,
+                                     const gmx::SelectionTreeElementPointer &sel,
+                                     gmx_ana_index_t                        *g)
 {
     if (sel->u.cgrp.isize == 0)
     {
@@ -590,9 +601,9 @@ _gmx_sel_evaluate_subexpr_staticeval(gmx_sel_evaluate_t                *data,
  * major problem.
  */
 void
-_gmx_sel_evaluate_subexpr(gmx_sel_evaluate_t                *data,
-                          const SelectionTreeElementPointer &sel,
-                          gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_subexpr(gmx_sel_evaluate_t                     *data,
+                          const gmx::SelectionTreeElementPointer &sel,
+                          gmx_ana_index_t                        *g)
 {
     gmx_ana_index_t      gmiss;
 
@@ -703,9 +714,9 @@ _gmx_sel_evaluate_subexpr(gmx_sel_evaluate_t                *data,
  * other references.
  */
 void
-_gmx_sel_evaluate_subexprref_simple(gmx_sel_evaluate_t                *data,
-                                    const SelectionTreeElementPointer &sel,
-                                    gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_subexprref_simple(gmx_sel_evaluate_t                     *data,
+                                    const gmx::SelectionTreeElementPointer &sel,
+                                    gmx_ana_index_t                        *g)
 {
     if (g)
     {
@@ -742,9 +753,9 @@ _gmx_sel_evaluate_subexprref_simple(gmx_sel_evaluate_t                *data,
  * \ref SEL_SUBEXPRREF elements.
  */
 void
-_gmx_sel_evaluate_subexprref(gmx_sel_evaluate_t                *data,
-                             const SelectionTreeElementPointer &sel,
-                             gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_subexprref(gmx_sel_evaluate_t                     *data,
+                             const gmx::SelectionTreeElementPointer &sel,
+                             gmx_ana_index_t                        *g)
 {
     int        i, j;
 
@@ -867,9 +878,9 @@ _gmx_sel_evaluate_subexprref(gmx_sel_evaluate_t                *data,
  * but is used internally.
  */
 void
-_gmx_sel_evaluate_method_params(gmx_sel_evaluate_t                *data,
-                                const SelectionTreeElementPointer &sel,
-                                gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_method_params(gmx_sel_evaluate_t                     *data,
+                                const gmx::SelectionTreeElementPointer &sel,
+                                gmx_ana_index_t                        *g)
 {
     SelectionTreeElementPointer child = sel->child;
     while (child)
@@ -908,9 +919,9 @@ _gmx_sel_evaluate_method_params(gmx_sel_evaluate_t                *data,
  * \ref SEL_EXPRESSION elements.
  */
 void
-_gmx_sel_evaluate_method(gmx_sel_evaluate_t                *data,
-                         const SelectionTreeElementPointer &sel,
-                         gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_method(gmx_sel_evaluate_t                     *data,
+                         const gmx::SelectionTreeElementPointer &sel,
+                         gmx_ana_index_t                        *g)
 {
     _gmx_sel_evaluate_method_params(data, sel, g);
     if (sel->flags & SEL_INITFRAME)
@@ -950,9 +961,9 @@ _gmx_sel_evaluate_method(gmx_sel_evaluate_t                *data,
  * \ref SEL_MODIFIER elements.
  */
 void
-_gmx_sel_evaluate_modifier(gmx_sel_evaluate_t                *data,
-                           const SelectionTreeElementPointer &sel,
-                           gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_modifier(gmx_sel_evaluate_t                     *data,
+                           const gmx::SelectionTreeElementPointer &sel,
+                           gmx_ana_index_t                        *g)
 {
     _gmx_sel_evaluate_method_params(data, sel, g);
     if (sel->flags & SEL_INITFRAME)
@@ -991,9 +1002,9 @@ _gmx_sel_evaluate_modifier(gmx_sel_evaluate_t                *data,
  * \ref SEL_BOOLEAN elements with \ref BOOL_NOT.
  */
 void
-_gmx_sel_evaluate_not(gmx_sel_evaluate_t                *data,
-                      const SelectionTreeElementPointer &sel,
-                      gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_not(gmx_sel_evaluate_t                     *data,
+                      const gmx::SelectionTreeElementPointer &sel,
+                      gmx_ana_index_t                        *g)
 {
     MempoolSelelemReserver reserver(sel->child, g->isize);
     sel->child->evaluate(data, sel->child, g);
@@ -1026,9 +1037,9 @@ _gmx_sel_evaluate_not(gmx_sel_evaluate_t                *data,
  * \ref SEL_BOOLEAN elements with \ref BOOL_AND.
  */
 void
-_gmx_sel_evaluate_and(gmx_sel_evaluate_t                *data,
-                      const SelectionTreeElementPointer &sel,
-                      gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_and(gmx_sel_evaluate_t                     *data,
+                      const gmx::SelectionTreeElementPointer &sel,
+                      gmx_ana_index_t                        *g)
 {
     SelectionTreeElementPointer child = sel->child;
     /* Skip the first child if it does not have an evaluation function. */
@@ -1079,9 +1090,9 @@ _gmx_sel_evaluate_and(gmx_sel_evaluate_t                *data,
  * \ref SEL_BOOLEAN elements with \ref BOOL_OR.
  */
 void
-_gmx_sel_evaluate_or(gmx_sel_evaluate_t                *data,
-                     const SelectionTreeElementPointer &sel,
-                     gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_or(gmx_sel_evaluate_t                     *data,
+                     const gmx::SelectionTreeElementPointer &sel,
+                     gmx_ana_index_t                        *g)
 {
     gmx_ana_index_t             tmp, tmp2;
 
@@ -1124,9 +1135,9 @@ _gmx_sel_evaluate_or(gmx_sel_evaluate_t                *data,
  * \returns   0 on success, a non-zero error code on error.
  */
 void
-_gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t                *data,
-                             const SelectionTreeElementPointer &sel,
-                             gmx_ana_index_t                   *g)
+_gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t                     *data,
+                             const gmx::SelectionTreeElementPointer &sel,
+                             gmx_ana_index_t                        *g)
 {
     int         n, i, i1, i2;
     real        lval, rval = 0., val = 0.;