Use gmx_mtop_t in selections, part 3
authorTeemu Murtola <teemu.murtola@gmail.com>
Thu, 29 Sep 2016 18:44:49 +0000 (21:44 +0300)
committerDavid van der Spoel <davidvanderspoel@gmail.com>
Fri, 14 Oct 2016 13:38:34 +0000 (15:38 +0200)
Convert remainder of the selection code to use gmx_mtop_t.

Part of #1862.

Change-Id: Icb1c4a30cc5456e64ed2d73f93ca4a7d6dbfbfbd

19 files changed:
src/gromacs/selection/compiler.cpp
src/gromacs/selection/evaluate.cpp
src/gromacs/selection/evaluate.h
src/gromacs/selection/selection.cpp
src/gromacs/selection/selection.h
src/gromacs/selection/selectioncollection-impl.h
src/gromacs/selection/selectioncollection.cpp
src/gromacs/selection/selmethod.h
src/gromacs/selection/sm_compare.cpp
src/gromacs/selection/sm_distance.cpp
src/gromacs/selection/sm_insolidangle.cpp
src/gromacs/selection/sm_keywords.cpp
src/gromacs/selection/sm_merge.cpp
src/gromacs/selection/sm_permute.cpp
src/gromacs/selection/sm_position.cpp
src/gromacs/selection/sm_same.cpp
src/gromacs/selection/sm_simple.cpp
src/gromacs/topology/topology.cpp
src/gromacs/topology/topology.h

index 2027a495fd7906884c0c1e85494716d591299bec..217a4b71b52fbc566dbdc091adc0eb80839eaa74 100644 (file)
@@ -1829,7 +1829,7 @@ store_param_val(const SelectionTreeElementPointer &sel)
  * is prevented by using \ref SEL_METHODINIT and \ref SEL_OUTINIT flags.
  */
 static void
-init_method(const SelectionTreeElementPointer &sel, t_topology *top, int isize)
+init_method(const SelectionTreeElementPointer &sel, const gmx_mtop_t *top, int isize)
 {
     /* Find out whether there are any atom-valued parameters */
     bool bAtomVal                     = false;
index 6804c41de9380b44b4b7e70ea36e6439bf3e38c7..70e5fd1ddd7cc3d9b1b89ee09f34fe6f7d499b3c 100644 (file)
@@ -369,7 +369,7 @@ _gmx_sel_print_evalfunc_name(FILE *fp, gmx::sel_evalfunc evalfunc)
 void
 _gmx_sel_evaluate_init(gmx_sel_evaluate_t *data,
                        gmx_sel_mempool_t *mp, gmx_ana_index_t *gall,
-                       t_topology *top, t_trxframe *fr, t_pbc *pbc)
+                       const gmx_mtop_t *top, t_trxframe *fr, t_pbc *pbc)
 {
     data->mp   = mp;
     data->gall = gall;
index 337e9be336f59b3cbcfdff32d8319d34a29376d0..e2135e2ca2715c038bfc07422da145dadf9ec573 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2016, 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.
@@ -52,9 +52,9 @@
 #include "selelem.h"
 
 struct gmx_ana_index_t;
+struct gmx_mtop_t;
 struct gmx_sel_mempool_t;
 struct t_pbc;
-struct t_topology;
 struct t_trxframe;
 
 /*! \internal \brief
@@ -67,7 +67,7 @@ struct gmx_sel_evaluate_t
     /** Index group that contains all the atoms. */
     gmx_ana_index_t          *gall;
     /** Topology information. */
-    t_topology               *top;
+    const gmx_mtop_t         *top;
     /** Current frame. */
     t_trxframe               *fr;
     /** PBC data. */
@@ -81,7 +81,7 @@ struct gmx_sel_evaluate_t
 void
 _gmx_sel_evaluate_init(gmx_sel_evaluate_t *data,
                        gmx_sel_mempool_t *mp, gmx_ana_index_t *gall,
-                       t_topology *top, t_trxframe *fr, t_pbc *pbc);
+                       const gmx_mtop_t *top, t_trxframe *fr, t_pbc *pbc);
 /** Evaluates the children of a general selection element. */
 void
 _gmx_sel_evaluate_children(gmx_sel_evaluate_t                     *data,
index 0b2f337be4dfb4b94c0b7b452c7b8212e2685193..d1ec9e623c3059ad19ff8c885768acf611d43f0e 100644 (file)
@@ -47,6 +47,7 @@
 
 #include "gromacs/selection/nbsearch.h"
 #include "gromacs/selection/position.h"
+#include "gromacs/topology/mtop_lookup.h"
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
@@ -160,22 +161,24 @@ namespace
  *
  * Does not throw if enough space has been reserved for the output vectors.
  */
-void computeMassesAndCharges(const t_topology *top, const gmx_ana_pos_t &pos,
+void computeMassesAndCharges(const gmx_mtop_t *top, const gmx_ana_pos_t &pos,
                              std::vector<real> *masses,
                              std::vector<real> *charges)
 {
     GMX_ASSERT(top != NULL, "Should not have been called with NULL topology");
     masses->clear();
     charges->clear();
+    int molb = 0;
     for (int b = 0; b < pos.count(); ++b)
     {
         real mass   = 0.0;
         real charge = 0.0;
         for (int i = pos.m.mapb.index[b]; i < pos.m.mapb.index[b+1]; ++i)
         {
-            const int index = pos.m.mapb.a[i];
-            mass   += top->atoms.atom[index].m;
-            charge += top->atoms.atom[index].q;
+            const int     index  = pos.m.mapb.a[i];
+            const t_atom &atom   = mtopGetAtomParameters(top, index, &molb);
+            mass                += atom.m;
+            charge              += atom.q;
         }
         masses->push_back(mass);
         charges->push_back(charge);
@@ -200,7 +203,7 @@ SelectionData::refreshName()
 }
 
 void
-SelectionData::initializeMassesAndCharges(const t_topology *top)
+SelectionData::initializeMassesAndCharges(const gmx_mtop_t *top)
 {
     GMX_ASSERT(posMass_.empty() && posCharge_.empty(),
                "Should not be called more than once");
@@ -219,7 +222,7 @@ SelectionData::initializeMassesAndCharges(const t_topology *top)
 
 
 void
-SelectionData::refreshMassesAndCharges(const t_topology *top)
+SelectionData::refreshMassesAndCharges(const gmx_mtop_t *top)
 {
     if (top != NULL && isDynamic() && !hasFlag(efSelection_DynamicMask))
     {
@@ -251,7 +254,7 @@ SelectionData::computeAverageCoveredFraction(int nframes)
 
 
 void
-SelectionData::restoreOriginalPositions(const t_topology *top)
+SelectionData::restoreOriginalPositions(const gmx_mtop_t *top)
 {
     if (isDynamic())
     {
index c9f619ee3b9a0d9202989f0abfb4e1d56c0a93ad..1b9df4157d7181f2b581dccd17a5b9972d6a7e1e 100644 (file)
@@ -53,7 +53,6 @@
 #include "gromacs/utility/gmxassert.h"
 
 struct gmx_mtop_t;
-struct t_topology;
 
 namespace gmx
 {
@@ -151,7 +150,7 @@ class SelectionData
          *
          * Strong exception safety guarantee.
          */
-        void initializeMassesAndCharges(const t_topology *top);
+        void initializeMassesAndCharges(const gmx_mtop_t *top);
         /*! \brief
          * Updates masses and charges after dynamic selection has been
          * evaluated.
@@ -160,7 +159,7 @@ class SelectionData
          *
          * Called by SelectionEvaluator.
          */
-        void refreshMassesAndCharges(const t_topology *top);
+        void refreshMassesAndCharges(const gmx_mtop_t *top);
         /*! \brief
          * Updates the covered fraction after a selection has been evaluated.
          *
@@ -186,7 +185,7 @@ class SelectionData
          * \a rootElement_ object.
          * Called by SelectionEvaluator::evaluateFinal().
          */
-        void restoreOriginalPositions(const t_topology *top);
+        void restoreOriginalPositions(const gmx_mtop_t *top);
 
     private:
         //! Name of the selection.
index d59bf9ac0b817127d5ebd4fc08258e3b0492b96b..56d62fc327ca7e8be7112e6b14194bac8582df9a 100644 (file)
@@ -57,9 +57,9 @@
 #include "poscalc.h"
 #include "selelem.h"
 
+struct gmx_mtop_t;
 struct gmx_sel_mempool_t;
 struct t_pbc;
-struct t_topology;
 struct t_trxframe;
 
 namespace gmx
@@ -100,7 +100,7 @@ struct gmx_ana_selcollection_t
     char                         **varstrs;
 
     /** Topology for the collection. */
-    t_topology                                        *top;
+    const gmx_mtop_t                                  *top;
     /** Index group that contains all the atoms. */
     gmx_ana_index_t                                    gall;
     /** Memory pool used for selection evaluation. */
index 5ae0f85ca1aa4871c4edd323222543d685f466f1..ccb1e98dd3962445decc4480ca7c8fd6870b35e4 100644 (file)
@@ -451,7 +451,7 @@ void checkExternalGroups(const SelectionTreeElementPointer &root,
 }
 
 //! Checks whether the given topology properties are available.
-void checkTopologyProperties(const t_topology                  *top,
+void checkTopologyProperties(const gmx_mtop_t                  *top,
                              const SelectionTopologyProperties &props)
 {
     if (top == NULL)
@@ -462,7 +462,7 @@ void checkTopologyProperties(const t_topology                  *top,
         }
         return;
     }
-    if (props.needsMasses && !top->atoms.haveMass)
+    if (props.needsMasses && !gmx_mtop_has_masses(top))
     {
         GMX_THROW(InconsistentInputError("Selection requires mass information, but it is not available in the topology"));
     }
@@ -616,6 +616,7 @@ SelectionCollection::setTopology(gmx_mtop_t *top, int natoms)
 {
     GMX_RELEASE_ASSERT(natoms > 0 || top != NULL,
                        "The number of atoms must be given if there is no topology");
+    checkTopologyProperties(top, requiredTopologyProperties());
     // Get the number of atoms from the topology if it is not given.
     if (natoms <= 0)
     {
@@ -638,17 +639,7 @@ SelectionCollection::setTopology(gmx_mtop_t *top, int natoms)
     gmx_ana_selcollection_t *sc = &impl_->sc_;
     // Do this first, as it allocates memory, while the others don't throw.
     gmx_ana_index_init_simple(&sc->gall, natoms);
-    // TODO: Adapt to use mtop throughout.
-    if (top != nullptr)
-    {
-        snew(sc->top, 1);
-        *sc->top = gmx_mtop_t_to_t_topology(top, false);
-        checkTopologyProperties(sc->top, requiredTopologyProperties());
-    }
-    else
-    {
-        checkTopologyProperties(nullptr, requiredTopologyProperties());
-    }
+    sc->top = top;
     sc->pcc.setTopology(top);
 }
 
index 31eae94fbe2b8d46c2ddc00fd6b0f65a1f66c6d6..4b5515308980e53a24565e8bce4014b363f8594f 100644 (file)
 struct gmx_ana_index_t;
 struct gmx_ana_pos_t;
 struct gmx_ana_selcollection_t;
+struct gmx_mtop_t;
 struct t_pbc;
-struct t_topology;
 struct t_trxframe;
 
 namespace gmx
@@ -328,7 +328,7 @@ class SelectionParserSymbolTable;
 struct SelMethodEvalContext
 {
     //! Initializes the context with given values.
-    SelMethodEvalContext(const t_topology *top, t_trxframe *fr, const t_pbc *pbc)
+    SelMethodEvalContext(const gmx_mtop_t *top, t_trxframe *fr, const t_pbc *pbc)
         : top(top), fr(fr), pbc(pbc)
     {
     }
@@ -339,7 +339,7 @@ struct SelMethodEvalContext
      * Can be NULL if \ref SMETH_REQTOP or \ref SMETH_REQMASS is not set for
      * the method.
      */
-    const t_topology *top;
+    const gmx_mtop_t *top;
     /*! \brief
      * Trajectory frame.
      *
@@ -501,7 +501,7 @@ typedef void  (*sel_posfunc)(gmx::PositionCalculationCollection *pcc, void *data
  * This function may be called multiple times for the same method if the
  * method takes parameters with \ref SPAR_ATOMVAL set.
  */
-typedef void  (*sel_initfunc)(t_topology *top, int npar,
+typedef void  (*sel_initfunc)(const gmx_mtop_t *top, int npar,
                               gmx_ana_selparam_t *param, void *data);
 /*! \brief
  * Initializes output data structure.
@@ -530,7 +530,7 @@ typedef void  (*sel_initfunc)(t_topology *top, int npar,
  * This function may be called multiple times for the same method if the
  * method takes parameters with \ref SPAR_ATOMVAL set.
  */
-typedef void  (*sel_outinitfunc)(t_topology *top, gmx_ana_selvalue_t *out,
+typedef void  (*sel_outinitfunc)(const gmx_mtop_t *top, gmx_ana_selvalue_t *out,
                                  void *data);
 /*! \brief
  * Frees the internal data.
index 1ad37e51b3f6bbddc5864eeeb161980edb684dc7..c92a940e02864adbbee4f656764a041271c5cd05 100644 (file)
@@ -124,7 +124,7 @@ init_data_compare(int npar, gmx_ana_selparam_t *param);
  * \returns   0 if the input data is valid, -1 on error.
  */
 static void
-init_compare(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_compare(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Frees the memory allocated for comparison expression evaluation. */
 static void
 free_data_compare(void *data);
@@ -416,7 +416,7 @@ convert_real_int(int n, t_compare_value *val, e_comparison_t cmpt, bool bRight)
 }
 
 static void
-init_compare(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_compare(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_compare *d = (t_methoddata_compare *)data;
     int                   n1, n2;
index 04c86245c98dcc8dbeb9f486da1b9e6939654838..738657c92f051fd9cf11fa8da9407d0d0bae0c12 100644 (file)
@@ -108,7 +108,7 @@ init_data_common(int npar, gmx_ana_selparam_t *param);
  * Also checks that the cutoff is valid.
  */
 static void
-init_common(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_common(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Frees the data allocated for a distance-based selection method. */
 static void
 free_data_common(void *data);
@@ -232,7 +232,7 @@ init_data_common(int /* npar */, gmx_ana_selparam_t *param)
 }
 
 static void
-init_common(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_common(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_distance *d = static_cast<t_methoddata_distance *>(data);
 
index 9c172a613e3d331edcfa2f1e1a4afd3621240eaa..3bb50305f3a62af73f19a26e016e86966a50e9cc 100644 (file)
@@ -257,7 +257,7 @@ init_data_insolidangle(int npar, gmx_ana_selparam_t *param);
  * and allocates memory for the bins used during the evaluation.
  */
 static void
-init_insolidangle(t_topology * top, int npar, gmx_ana_selparam_t * param, void *data);
+init_insolidangle(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t * param, void *data);
 /** Frees the data allocated for the \p insolidangle selection method. */
 static void
 free_data_insolidangle(void *data);
@@ -402,7 +402,7 @@ init_data_insolidangle(int /* npar */, gmx_ana_selparam_t *param)
 }
 
 static void
-init_insolidangle(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
+init_insolidangle(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
 {
     t_methoddata_insolidangle *surf = (t_methoddata_insolidangle *)data;
     int                        i, c;
index 8f2dfe29f3b05449c6762f235ead806a43e68b2d..e675249a4c1dc5cd4415a0f5f51049a85df72a69 100644 (file)
@@ -104,7 +104,7 @@ init_data_kwstr(int npar, gmx_ana_selparam_t * param);
  * \param[in] data  Should point to \ref t_methoddata_kwint.
  */
 static void
-init_kwint(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_kwint(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /*! \brief
  * Initializes data for real keyword evaluation.
  *
@@ -115,7 +115,7 @@ init_kwint(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
  * \returns   0 (the initialization always succeeds).
  */
 static void
-init_kwreal(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_kwreal(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /*! \brief
  * Initializes data for string keyword evaluation.
  *
@@ -125,7 +125,7 @@ init_kwreal(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
  * \param[in] data  Should point to t_methoddata_kwstr.
  */
 static void
-init_kwstr(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_kwstr(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Frees the memory allocated for string keyword evaluation. */
 static void
 free_data_kwstr(void *data);
@@ -347,7 +347,7 @@ gmx_ana_selmethod_t sm_keyword_str = {
  * Calls the initialization method of the wrapped keyword.
  */
 static void
-init_kweval(t_topology *top, int npar, gmx_ana_selparam_t * param, void *data);
+init_kweval(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t * param, void *data);
 /*! \brief
  * Initializes output for keyword evaluation in an arbitrary group.
  *
@@ -357,7 +357,7 @@ init_kweval(t_topology *top, int npar, gmx_ana_selparam_t * param, void *data);
  * \returns       0 for success.
  */
 static void
-init_output_kweval(t_topology *top, gmx_ana_selvalue_t *out, void *data);
+init_output_kweval(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data);
 /** Frees the data allocated for keyword evaluation in an arbitrary group. */
 static void
 free_data_kweval(void *data);
@@ -441,7 +441,7 @@ init_data_kwint(int  /* npar */, gmx_ana_selparam_t * /* param */)
 }
 
 static void
-init_kwint(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_kwint(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_kwint *d = (t_methoddata_kwint *)data;
 
@@ -516,7 +516,7 @@ init_data_kwreal(int /* npar */, gmx_ana_selparam_t * /* param */)
 }
 
 static void
-init_kwreal(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_kwreal(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_kwreal *d = (t_methoddata_kwreal *)data;
 
@@ -610,7 +610,7 @@ _gmx_selelem_set_kwstr_match_type(const gmx::SelectionTreeElementPointer &sel,
 }
 
 static void
-init_kwstr(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_kwstr(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_kwstr *d = static_cast<t_methoddata_kwstr *>(data);
 
@@ -674,7 +674,7 @@ evaluate_keyword_str(const gmx::SelMethodEvalContext & /*context*/,
  ********************************************************************/
 
 static void
-init_kweval(t_topology *top, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
+init_kweval(const gmx_mtop_t *top, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
 {
     t_methoddata_kweval *d = static_cast<t_methoddata_kweval *>(data);
 
@@ -682,7 +682,7 @@ init_kweval(t_topology *top, int /* npar */, gmx_ana_selparam_t * /* param */, v
 }
 
 static void
-init_output_kweval(t_topology * /* top */, gmx_ana_selvalue_t *out, void *data)
+init_output_kweval(const gmx_mtop_t * /* top */, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_kweval *d = static_cast<t_methoddata_kweval *>(data);
 
index bb1bb435d5f2e719b1e8b2c591cd42a1f68d36da..309de2f09ffcf280818b0a2c7897a4f300005ddd 100644 (file)
@@ -76,13 +76,13 @@ init_data_merge(int npar, gmx_ana_selparam_t *param);
  * \returns   0 if everything is successful, -1 on error.
  */
 static void
-init_merge(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_merge(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Initializes output for the \p merge selection modifier. */
 static void
-init_output_merge(t_topology *top, gmx_ana_selvalue_t *out, void *data);
+init_output_merge(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data);
 /** Initializes output for the \p plus selection modifier. */
 static void
-init_output_plus(t_topology *top, gmx_ana_selvalue_t *out, void *data);
+init_output_plus(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data);
 /** Frees the memory allocated for the merging selection modifiers. */
 static void
 free_data_merge(void *data);
@@ -197,7 +197,7 @@ init_data_merge(int npar, gmx_ana_selparam_t *param)
 }
 
 static void
-init_merge(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
+init_merge(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
 
@@ -224,7 +224,7 @@ init_merge(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t * /* param
  * \param[in,out] data  Should point to \c t_methoddata_merge.
  */
 static void
-init_output_common(t_topology *top, gmx_ana_selvalue_t *out, void *data)
+init_output_common(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
 
@@ -250,7 +250,7 @@ init_output_common(t_topology *top, gmx_ana_selvalue_t *out, void *data)
  * \param[in,out] data  Should point to \c t_methoddata_merge.
  */
 static void
-init_output_merge(t_topology *top, gmx_ana_selvalue_t *out, void *data)
+init_output_merge(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
     int                 i, j;
@@ -272,7 +272,7 @@ init_output_merge(t_topology *top, gmx_ana_selvalue_t *out, void *data)
  * \param[in,out] data  Should point to \c t_methoddata_merge.
  */
 static void
-init_output_plus(t_topology *top, gmx_ana_selvalue_t *out, void *data)
+init_output_plus(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
     int                 i;
index 789e3d9fa33980e6675f723dcd136c77115837d8..b55c4048bafaa1189cc0cc13fdc6f748d58ef5da 100644 (file)
@@ -87,7 +87,7 @@ init_data_permute(int npar, gmx_ana_selparam_t *param);
  * \returns   0 if the input permutation is valid, -1 on error.
  */
 static void
-init_permute(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_permute(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /*! \brief
  * Initializes output for the \p permute selection modifier.
  *
@@ -96,7 +96,7 @@ init_permute(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
  * \param[in,out] data  Should point to \c t_methoddata_permute.
  */
 static void
-init_output_permute(t_topology *top, gmx_ana_selvalue_t *out, void *data);
+init_output_permute(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data);
 /** Frees the memory allocated for the \p permute selection modifier. */
 static void
 free_data_permute(void *data);
@@ -168,7 +168,7 @@ init_data_permute(int /* npar */, gmx_ana_selparam_t *param)
 }
 
 static void
-init_permute(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_permute(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_permute *d = (t_methoddata_permute *)data;
     int                   i;
@@ -201,7 +201,7 @@ init_permute(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param,
 }
 
 static void
-init_output_permute(t_topology * /* top */, gmx_ana_selvalue_t *out, void *data)
+init_output_permute(const gmx_mtop_t * /* top */, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_permute *d = (t_methoddata_permute *)data;
     int                   i, j, b;
index a2122006e03d065e8c3b52d3cc252be1386fa06c..1b22204c83d95118042b7ee54a36271a94818bd1 100644 (file)
@@ -90,7 +90,7 @@ set_poscoll_pos(gmx::PositionCalculationCollection *pcc, void *data);
  * externally using _gmx_selelem_set_kwpos_type().
  */
 static void
-init_kwpos(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_kwpos(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /*! \brief
  * Initializes the \p cog selection method.
  *
@@ -101,7 +101,7 @@ init_kwpos(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
  * \returns       0 on success, a non-zero error code on error.
  */
 static void
-init_cog(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_cog(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /*! \brief
  * Initializes the \p cog selection method.
  *
@@ -112,7 +112,7 @@ init_cog(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
  * \returns       0 on success, a non-zero error code on error.
  */
 static void
-init_com(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_com(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /*! \brief
  * Initializes output for position evaluation selection methods.
  *
@@ -122,7 +122,7 @@ init_com(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
  * \returns       0 for success.
  */
 static void
-init_output_pos(t_topology *top, gmx_ana_selvalue_t *out, void *data);
+init_output_pos(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data);
 /** Frees the data allocated for position evaluation selection methods. */
 static void
 free_data_pos(void *data);
@@ -317,7 +317,7 @@ _gmx_selelem_set_kwpos_flags(gmx::SelectionTreeElement *sel, int flags)
 }
 
 static void
-init_kwpos(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_kwpos(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_pos *d = (t_methoddata_pos *)data;
 
@@ -334,7 +334,7 @@ init_kwpos(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, vo
 }
 
 static void
-init_cog(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_cog(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_pos *d = (t_methoddata_pos *)data;
 
@@ -344,7 +344,7 @@ init_cog(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void
 }
 
 static void
-init_com(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_com(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_pos *d = (t_methoddata_pos *)data;
 
@@ -355,7 +355,7 @@ init_com(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void
 }
 
 static void
-init_output_pos(t_topology * /* top */, gmx_ana_selvalue_t *out, void *data)
+init_output_pos(const gmx_mtop_t * /* top */, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_pos *d = (t_methoddata_pos *)data;
 
index cc543499b1283edfffe5438afe2d831a27da5eb2..f475efd72d09eaed9626e4c4f840808d8d6e73c3 100644 (file)
@@ -119,7 +119,7 @@ init_data_same(int npar, gmx_ana_selparam_t *param);
  * \returns 0 on success, -1 on failure.
  */
 static void
-init_same(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+init_same(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Frees the data allocated for the \p same selection method. */
 static void
 free_data_same(void *data);
@@ -281,7 +281,7 @@ _gmx_selelem_custom_init_same(gmx_ana_selmethod_t                           **me
 }
 
 static void
-init_same(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
+init_same(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
 {
     t_methoddata_same *d = (t_methoddata_same *)data;
 
index c8cb777231307f3b66bc3ba59b3bf7eb27e218f8..4af50ee16347c9c3f1f3bde89f02d89b9c784ac7 100644 (file)
 #include <cctype>
 
 #include "gromacs/selection/position.h"
+#include "gromacs/topology/mtop_lookup.h"
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/gmxassert.h"
 
 #include "selmethod.h"
 
@@ -82,7 +84,7 @@ evaluate_resindex(const gmx::SelMethodEvalContext &context,
  * If molecule information is not found, also prints an error message.
  */
 static void
-check_molecules(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+check_molecules(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Evaluates the \p molindex selection keyword. */
 static void
 evaluate_molindex(const gmx::SelMethodEvalContext &context,
@@ -104,7 +106,7 @@ evaluate_pdbatomname(const gmx::SelMethodEvalContext &context,
  * \param     data Not used.
  */
 static void
-check_atomtype(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+check_atomtype(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Evaluates the \p atomtype selection keyword. */
 static void
 evaluate_atomtype(const gmx::SelMethodEvalContext &context,
@@ -130,7 +132,7 @@ evaluate_mass(const gmx::SelMethodEvalContext &context,
  * \param     data Not used.
  */
 static void
-check_charge(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+check_charge(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Evaluates the \p charge selection keyword. */
 static void
 evaluate_charge(const gmx::SelMethodEvalContext &context,
@@ -147,7 +149,7 @@ evaluate_charge(const gmx::SelMethodEvalContext &context,
  * If PDB info is not found, also prints an error message.
  */
 static void
-check_pdbinfo(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
+check_pdbinfo(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Evaluates the \p altloc selection keyword. */
 static void
 evaluate_altloc(const gmx::SelMethodEvalContext &context,
@@ -540,14 +542,12 @@ static void
 evaluate_resnr(const gmx::SelMethodEvalContext &context,
                gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-    int  resind;
-
-    out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    out->nr  = g->isize;
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        resind      = context.top->atoms.atom[g->index[i]].resind;
-        out->u.i[i] = context.top->atoms.resinfo[resind].nr;
+        mtopGetAtomAndResidueName(context.top, g->index[i], &molb,
+                                  nullptr, &out->u.i[i], nullptr, nullptr);
     }
 }
 
@@ -561,17 +561,19 @@ static void
 evaluate_resindex(const gmx::SelMethodEvalContext &context,
                   gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-
-    out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    out->nr  = g->isize;
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        out->u.i[i] = context.top->atoms.atom[g->index[i]].resind + 1;
+        int resind;
+        mtopGetAtomAndResidueName(context.top, g->index[i], &molb,
+                                  nullptr, nullptr, nullptr, &resind);
+        out->u.i[i] = resind + 1;
     }
 }
 
 static void
-check_molecules(t_topology *top, int /* npar */, gmx_ana_selparam_t * /* param */, void * /* data */)
+check_molecules(const gmx_mtop_t *top, int /* npar */, gmx_ana_selparam_t * /* param */, void * /* data */)
 {
     bool bOk;
 
@@ -615,12 +617,14 @@ static void
 evaluate_atomname(const gmx::SelMethodEvalContext &context,
                   gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        out->u.s[i] = *context.top->atoms.atomname[g->index[i]];
+        const char *atom_name;
+        mtopGetAtomAndResidueName(context.top, g->index[i], &molb,
+                                  &atom_name, nullptr, nullptr, nullptr);
+        out->u.s[i] = const_cast<char *>(atom_name);
     }
 }
 
@@ -634,27 +638,23 @@ static void
 evaluate_pdbatomname(const gmx::SelMethodEvalContext &context,
                      gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        char *s = context.top->atoms.pdbinfo[g->index[i]].atomnm;
+        const char *s = mtopGetAtomPdbInfo(context.top, g->index[i], &molb).atomnm;
         while (std::isspace(*s))
         {
             ++s;
         }
-        out->u.s[i] = s;
+        out->u.s[i] = const_cast<char *>(s);
     }
 }
 
 static void
-check_atomtype(t_topology *top, int /* npar */, gmx_ana_selparam_t * /* param */, void * /* data */)
+check_atomtype(const gmx_mtop_t *top, int /* npar */, gmx_ana_selparam_t * /* param */, void * /* data */)
 {
-    bool bOk;
-
-    bOk = (top != NULL && (top->atoms.haveType));
-    if (!bOk)
+    if (!gmx_mtop_has_atomtypes(top))
     {
         GMX_THROW(gmx::InconsistentInputError("Atom types not available in topology"));
     }
@@ -671,12 +671,15 @@ static void
 evaluate_atomtype(const gmx::SelMethodEvalContext &context,
                   gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        out->u.s[i] = *context.top->atoms.atomtype[g->index[i]];
+        int atomIndexInMolecule;
+        mtopGetMolblockIndex(context.top, g->index[i], &molb,
+                             nullptr, &atomIndexInMolecule);
+        const gmx_moltype_t &moltype = context.top->moltype[context.top->molblock[molb].type];
+        out->u.s[i] = *moltype.atoms.atomtype[atomIndexInMolecule];
     }
 }
 
@@ -690,14 +693,11 @@ static void
 evaluate_resname(const gmx::SelMethodEvalContext &context,
                  gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-    int  resind;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        resind      = context.top->atoms.atom[g->index[i]].resind;
-        out->u.s[i] = *context.top->atoms.resinfo[resind].name;
+        out->u.s[i] = *mtopGetResidueInfo(context.top, g->index[i], &molb).name;
     }
 }
 
@@ -711,14 +711,11 @@ static void
 evaluate_insertcode(const gmx::SelMethodEvalContext &context,
                     gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-    int  resind;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        resind         = context.top->atoms.atom[g->index[i]].resind;
-        out->u.s[i][0] = context.top->atoms.resinfo[resind].ic;
+        out->u.s[i][0] = mtopGetResidueInfo(context.top, g->index[i], &molb).ic;
     }
 }
 
@@ -732,14 +729,11 @@ static void
 evaluate_chain(const gmx::SelMethodEvalContext &context,
                gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-    int  resind;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        resind         = context.top->atoms.atom[g->index[i]].resind;
-        out->u.s[i][0] = context.top->atoms.resinfo[resind].chainid;
+        out->u.s[i][0] = mtopGetResidueInfo(context.top, g->index[i], &molb).chainid;
     }
 }
 
@@ -753,23 +747,21 @@ static void
 evaluate_mass(const gmx::SelMethodEvalContext &context,
               gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    GMX_RELEASE_ASSERT(context.top != nullptr && context.top->atoms.haveMass,
+    GMX_RELEASE_ASSERT(gmx_mtop_has_masses(context.top),
                        "Masses not available for evaluation");
     out->nr = g->isize;
+    int molb = 0;
     for (int i = 0; i < g->isize; ++i)
     {
-        out->u.r[i] = context.top->atoms.atom[g->index[i]].m;
+        out->u.r[i] = mtopGetAtomMass(context.top, g->index[i], &molb);
     }
 }
 
 
 static void
-check_charge(t_topology *top, int /* npar */, gmx_ana_selparam_t * /* param */, void * /* data */)
+check_charge(const gmx_mtop_t *top, int /* npar */, gmx_ana_selparam_t * /* param */, void * /* data */)
 {
-    bool bOk;
-
-    bOk = (top != NULL && top->atoms.haveCharge);
-    if (!bOk)
+    if (!gmx_mtop_has_charges(top))
     {
         GMX_THROW(gmx::InconsistentInputError("Charges not available in topology"));
     }
@@ -785,22 +777,18 @@ static void
 evaluate_charge(const gmx::SelMethodEvalContext &context,
                 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        out->u.r[i] = context.top->atoms.atom[g->index[i]].q;
+        out->u.r[i] = mtopGetAtomParameters(context.top, g->index[i], &molb).q;
     }
 }
 
 static void
-check_pdbinfo(t_topology *top, int /* npar */, gmx_ana_selparam_t * /* param */, void * /* data */)
+check_pdbinfo(const gmx_mtop_t *top, int /* npar */, gmx_ana_selparam_t * /* param */, void * /* data */)
 {
-    bool bOk;
-
-    bOk = (top != NULL && top->atoms.havePdbInfo);
-    if (!bOk)
+    if (!gmx_mtop_has_pdbinfo(top))
     {
         GMX_THROW(gmx::InconsistentInputError("PDB info not available in topology"));
     }
@@ -816,12 +804,11 @@ static void
 evaluate_altloc(const gmx::SelMethodEvalContext &context,
                 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        out->u.s[i][0] = context.top->atoms.pdbinfo[g->index[i]].altloc;
+        out->u.s[i][0] = mtopGetAtomPdbInfo(context.top, g->index[i], &molb).altloc;
     }
 }
 
@@ -836,12 +823,11 @@ static void
 evaluate_occupancy(const gmx::SelMethodEvalContext &context,
                    gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        out->u.r[i] = context.top->atoms.pdbinfo[g->index[i]].occup;
+        out->u.r[i] = mtopGetAtomPdbInfo(context.top, g->index[i], &molb).occup;
     }
 }
 
@@ -856,12 +842,11 @@ static void
 evaluate_betafactor(const gmx::SelMethodEvalContext &context,
                     gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void * /* data */)
 {
-    int  i;
-
     out->nr = g->isize;
-    for (i = 0; i < g->isize; ++i)
+    int molb = 0;
+    for (int i = 0; i < g->isize; ++i)
     {
-        out->u.r[i] = context.top->atoms.pdbinfo[g->index[i]].bfac;
+        out->u.r[i] = mtopGetAtomPdbInfo(context.top, g->index[i], &molb).bfac;
     }
 }
 
index bc9dd15c0bacef2dfe26f5e7d8fe037d72d2efce..f84f1062dd3bc182cf90fd5812bc8f344f9f04d8 100644 (file)
@@ -186,6 +186,24 @@ bool gmx_mtop_has_charges(const gmx_mtop_t *mtop)
     return mtop->nmoltype == 0 || mtop->moltype[0].atoms.haveCharge;
 }
 
+bool gmx_mtop_has_atomtypes(const gmx_mtop_t *mtop)
+{
+    if (mtop == nullptr)
+    {
+        return false;
+    }
+    return mtop->nmoltype == 0 || mtop->moltype[0].atoms.haveType;
+}
+
+bool gmx_mtop_has_pdbinfo(const gmx_mtop_t *mtop)
+{
+    if (mtop == nullptr)
+    {
+        return false;
+    }
+    return mtop->nmoltype == 0 || mtop->moltype[0].atoms.havePdbInfo;
+}
+
 static void pr_grps(FILE *fp, const char *title, const t_grps grps[], char **grpname[])
 {
     int i, j;
index 15e380d6e022c90ba717e53a4375454cb6c0e48e..c9daf7e7f999d36d102b080d746771ca29903e8d 100644 (file)
@@ -152,6 +152,8 @@ void done_top(t_topology *top);
 
 bool gmx_mtop_has_masses(const gmx_mtop_t *mtop);
 bool gmx_mtop_has_charges(const gmx_mtop_t *mtop);
+bool gmx_mtop_has_atomtypes(const gmx_mtop_t *mtop);
+bool gmx_mtop_has_pdbinfo(const gmx_mtop_t *mtop);
 
 void pr_mtop(FILE *fp, int indent, const char *title, const gmx_mtop_t *mtop,
              gmx_bool bShowNumbers);