From 34be89f1264fd0b19c27b72160371d944257a2c7 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Wed, 20 Jun 2018 09:38:40 +0200 Subject: [PATCH] Split TopologyInformation into its own header This will help provide a useful upgrade path for tools to get away from t_topology, and eventually into the new framework. Introduced a builder function to fill TopologyInformation from a tpr file, which will be needed shortly for porting old tools. Refs #1862 Change-Id: If2594cdcd3f9817ff83e7fb73208cdb5c497bb1a --- src/gromacs/trajectoryanalysis/CMakeLists.txt | 3 +- .../trajectoryanalysis/analysissettings.cpp | 54 ------- src/gromacs/trajectoryanalysis/analysissettings.h | 75 +--------- src/gromacs/trajectoryanalysis/cmdlinerunner.cpp | 1 + .../trajectoryanalysis/modules/freevolume.cpp | 3 +- .../trajectoryanalysis/modules/pairdist.cpp | 3 +- src/gromacs/trajectoryanalysis/modules/rdf.cpp | 3 +- src/gromacs/trajectoryanalysis/modules/sasa.cpp | 1 + src/gromacs/trajectoryanalysis/modules/select.cpp | 1 + src/gromacs/trajectoryanalysis/runnercommon.cpp | 18 +-- .../trajectoryanalysis/tests/cmdlinerunner.cpp | 3 +- ...nalysissettings.cpp => topologyinformation.cpp} | 156 +++------------------ .../trajectoryanalysis/topologyinformation.h | 145 +++++++++++++++++++ 13 files changed, 183 insertions(+), 283 deletions(-) copy src/gromacs/trajectoryanalysis/{analysissettings.cpp => topologyinformation.cpp} (56%) create mode 100644 src/gromacs/trajectoryanalysis/topologyinformation.h diff --git a/src/gromacs/trajectoryanalysis/CMakeLists.txt b/src/gromacs/trajectoryanalysis/CMakeLists.txt index 037a964838..86e61baab2 100644 --- a/src/gromacs/trajectoryanalysis/CMakeLists.txt +++ b/src/gromacs/trajectoryanalysis/CMakeLists.txt @@ -1,7 +1,7 @@ # # This file is part of the GROMACS molecular simulation package. # -# Copyright (c) 2010,2013,2014,2015, by the GROMACS development team, led by +# Copyright (c) 2010,2013,2014,2015,2018, 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. @@ -39,6 +39,7 @@ gmx_install_headers( analysismodule.h analysissettings.h cmdlinerunner.h + topologyinformation.h ) if (BUILD_TESTING) diff --git a/src/gromacs/trajectoryanalysis/analysissettings.cpp b/src/gromacs/trajectoryanalysis/analysissettings.cpp index b6bb0d64db..3f6b2f8f7e 100644 --- a/src/gromacs/trajectoryanalysis/analysissettings.cpp +++ b/src/gromacs/trajectoryanalysis/analysissettings.cpp @@ -45,13 +45,8 @@ #include "gromacs/commandline/cmdlineoptionsmodule.h" #include "gromacs/fileio/trxio.h" -#include "gromacs/math/vec.h" -#include "gromacs/topology/mtop_util.h" -#include "gromacs/topology/topology.h" #include "gromacs/utility/arrayref.h" -#include "gromacs/utility/exceptions.h" #include "gromacs/utility/gmxassert.h" -#include "gromacs/utility/smalloc.h" #include "analysissettings-impl.h" @@ -180,53 +175,4 @@ TrajectoryAnalysisSettings::setHelpText(const ArrayRef &help) impl_->optionsModuleSettings_->setHelpText(help); } - -/******************************************************************** - * TopologyInformation - */ - -TopologyInformation::TopologyInformation() - : mtop_(nullptr), top_(nullptr), bTop_(false), xtop_(nullptr), ePBC_(-1) -{ - clear_mat(boxtop_); -} - - -TopologyInformation::~TopologyInformation() -{ - done_top_mtop(top_, mtop_.get()); - sfree(top_); - sfree(xtop_); -} - - -t_topology *TopologyInformation::topology() const -{ - if (top_ == nullptr && mtop_ != nullptr) - { - snew(top_, 1); - *top_ = gmx_mtop_t_to_t_topology(mtop_.get(), false); - } - return top_; -} - - -void -TopologyInformation::getTopologyConf(rvec **x, matrix box) const -{ - if (box) - { - copy_mat(const_cast(boxtop_), box); - } - if (x) - { - if (!xtop_) - { - *x = nullptr; - GMX_THROW(APIError("Topology coordinates requested without setting efUseTopX")); - } - *x = xtop_; - } -} - } // namespace gmx diff --git a/src/gromacs/trajectoryanalysis/analysissettings.h b/src/gromacs/trajectoryanalysis/analysissettings.h index cc7033c7c3..9d40901fb6 100644 --- a/src/gromacs/trajectoryanalysis/analysissettings.h +++ b/src/gromacs/trajectoryanalysis/analysissettings.h @@ -34,7 +34,7 @@ */ /*! \file * \brief - * Declares gmx::TrajectoryAnalysisSettings and gmx::TopologyInformation. + * Declares gmx::TrajectoryAnalysisSettings. * * \author Teemu Murtola * \inpublicapi @@ -45,13 +45,9 @@ #include -#include "gromacs/math/vectypes.h" #include "gromacs/options/timeunitmanager.h" #include "gromacs/utility/classhelpers.h" -struct gmx_mtop_t; -struct t_topology; - namespace gmx { @@ -236,75 +232,6 @@ class TrajectoryAnalysisSettings friend class TrajectoryAnalysisRunnerCommon; }; -/*! \brief - * Topology information passed to a trajectory analysis module. - * - * This class is used to pass topology information to trajectory analysis - * modules and to manage memory for them. Having a single wrapper object - * instead of passing each item separately makes TrajectoryAnalysisModule - * interface simpler, and also reduces the need to change existing code if - * additional information is added. - * - * Methods in this class do not throw if not explicitly stated. - * - * \inpublicapi - * \ingroup module_trajectoryanalysis - */ -class TopologyInformation -{ - public: - //! Returns true if a topology file was loaded. - bool hasTopology() const { return mtop_ != nullptr; } - //! Returns true if a full topology file was loaded. - bool hasFullTopology() const { return bTop_; } - //! Returns the loaded topology, or NULL if not loaded. - const gmx_mtop_t *mtop() const { return mtop_.get(); } - //! Returns the loaded topology, or NULL if not loaded. - t_topology *topology() const; - //! Returns the ePBC field from the topology. - int ePBC() const { return ePBC_; } - /*! \brief - * Gets the configuration from the topology. - * - * \param[out] x Topology coordinate pointer to initialize. - * (can be NULL, in which case it is not used). - * \param[out] box Box size from the topology file - * (can be NULL, in which case it is not used). - * \throws APIError if topology coordinates are not available and - * \p x is not NULL. - * - * If TrajectoryAnalysisSettings::efUseTopX has not been specified, - * \p x should be NULL. - * - * The pointer returned in \p *x should not be freed. - */ - void getTopologyConf(rvec **x, matrix box) const; - - private: - TopologyInformation(); - ~TopologyInformation(); - - std::unique_ptr mtop_; - //! The topology structure, or NULL if no topology loaded. - // TODO: Replace fully with mtop. - mutable t_topology *top_; - //! true if full tpx file was loaded, false otherwise. - bool bTop_; - //! Coordinates from the topology (can be NULL). - rvec *xtop_; - //! The box loaded from the topology file. - matrix boxtop_; - //! The ePBC field loaded from the topology file. - int ePBC_; - - GMX_DISALLOW_COPY_AND_ASSIGN(TopologyInformation); - - /*! \brief - * Needed to initialize the data. - */ - friend class TrajectoryAnalysisRunnerCommon; -}; - } // namespace gmx #endif diff --git a/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp b/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp index 239bffc799..4b93e7c42f 100644 --- a/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp +++ b/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp @@ -54,6 +54,7 @@ #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/trajectoryanalysis/analysismodule.h" #include "gromacs/trajectoryanalysis/analysissettings.h" +#include "gromacs/trajectoryanalysis/topologyinformation.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/filestream.h" #include "gromacs/utility/gmxassert.h" diff --git a/src/gromacs/trajectoryanalysis/modules/freevolume.cpp b/src/gromacs/trajectoryanalysis/modules/freevolume.cpp index 04561e89e2..ed54bd60ec 100644 --- a/src/gromacs/trajectoryanalysis/modules/freevolume.cpp +++ b/src/gromacs/trajectoryanalysis/modules/freevolume.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018, 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. @@ -64,6 +64,7 @@ #include "gromacs/topology/topology.h" #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/trajectoryanalysis/analysissettings.h" +#include "gromacs/trajectoryanalysis/topologyinformation.h" #include "gromacs/utility/arrayref.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/pleasecite.h" diff --git a/src/gromacs/trajectoryanalysis/modules/pairdist.cpp b/src/gromacs/trajectoryanalysis/modules/pairdist.cpp index 72f7417944..843e36655b 100644 --- a/src/gromacs/trajectoryanalysis/modules/pairdist.cpp +++ b/src/gromacs/trajectoryanalysis/modules/pairdist.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2016, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2016,2018, 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. @@ -60,6 +60,7 @@ #include "gromacs/selection/selectionoption.h" #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/trajectoryanalysis/analysissettings.h" +#include "gromacs/trajectoryanalysis/topologyinformation.h" #include "gromacs/utility/arrayref.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/stringutil.h" diff --git a/src/gromacs/trajectoryanalysis/modules/rdf.cpp b/src/gromacs/trajectoryanalysis/modules/rdf.cpp index 664682e0ab..45079fc98f 100644 --- a/src/gromacs/trajectoryanalysis/modules/rdf.cpp +++ b/src/gromacs/trajectoryanalysis/modules/rdf.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2016, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2018, 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. @@ -70,6 +70,7 @@ #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/trajectoryanalysis/analysismodule.h" #include "gromacs/trajectoryanalysis/analysissettings.h" +#include "gromacs/trajectoryanalysis/topologyinformation.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/stringutil.h" diff --git a/src/gromacs/trajectoryanalysis/modules/sasa.cpp b/src/gromacs/trajectoryanalysis/modules/sasa.cpp index cad893791f..4e16edf928 100644 --- a/src/gromacs/trajectoryanalysis/modules/sasa.cpp +++ b/src/gromacs/trajectoryanalysis/modules/sasa.cpp @@ -68,6 +68,7 @@ #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/trajectoryanalysis/analysismodule.h" #include "gromacs/trajectoryanalysis/analysissettings.h" +#include "gromacs/trajectoryanalysis/topologyinformation.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/futil.h" #include "gromacs/utility/pleasecite.h" diff --git a/src/gromacs/trajectoryanalysis/modules/select.cpp b/src/gromacs/trajectoryanalysis/modules/select.cpp index 3063708ca7..15810ffa18 100644 --- a/src/gromacs/trajectoryanalysis/modules/select.cpp +++ b/src/gromacs/trajectoryanalysis/modules/select.cpp @@ -67,6 +67,7 @@ #include "gromacs/topology/topology.h" #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/trajectoryanalysis/analysissettings.h" +#include "gromacs/trajectoryanalysis/topologyinformation.h" #include "gromacs/utility/arrayref.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/gmxassert.h" diff --git a/src/gromacs/trajectoryanalysis/runnercommon.cpp b/src/gromacs/trajectoryanalysis/runnercommon.cpp index 59ca34b855..4ba187e4ad 100644 --- a/src/gromacs/trajectoryanalysis/runnercommon.cpp +++ b/src/gromacs/trajectoryanalysis/runnercommon.cpp @@ -48,8 +48,6 @@ #include #include -#include "gromacs/compat/make_unique.h" -#include "gromacs/fileio/confio.h" #include "gromacs/fileio/oenv.h" #include "gromacs/fileio/timecontrol.h" #include "gromacs/fileio/trxio.h" @@ -65,6 +63,7 @@ #include "gromacs/topology/topology.h" #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/trajectoryanalysis/analysissettings.h" +#include "gromacs/trajectoryanalysis/topologyinformation.h" #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/gmxassert.h" @@ -181,20 +180,7 @@ TrajectoryAnalysisRunnerCommon::Impl::initTopology(bool required) // Load the topology if requested. if (!topfile_.empty()) { - topInfo_.mtop_ = gmx::compat::make_unique(); - readConfAndTopology(topfile_.c_str(), &topInfo_.bTop_, topInfo_.mtop_.get(), - &topInfo_.ePBC_, &topInfo_.xtop_, nullptr, - topInfo_.boxtop_); - // TODO: Only load this here if the tool actually needs it; selections - // take care of themselves. - for (gmx_moltype_t &moltype : topInfo_.mtop_->moltype) - { - if (!moltype.atoms.haveMass) - { - // Try to read masses from database, be silent about missing masses - atomsSetMassesBasedOnNames(&moltype.atoms, FALSE); - } - } + topInfo_.fillFromInputFile(topfile_); if (hasTrajectory() && !settings_.hasFlag(TrajectoryAnalysisSettings::efUseTopX)) { diff --git a/src/gromacs/trajectoryanalysis/tests/cmdlinerunner.cpp b/src/gromacs/trajectoryanalysis/tests/cmdlinerunner.cpp index 221651b7f4..6dfefd8c2c 100644 --- a/src/gromacs/trajectoryanalysis/tests/cmdlinerunner.cpp +++ b/src/gromacs/trajectoryanalysis/tests/cmdlinerunner.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2018, 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. @@ -53,6 +53,7 @@ #include "gromacs/trajectory/trajectoryframe.h" #include "gromacs/trajectoryanalysis/analysismodule.h" #include "gromacs/trajectoryanalysis/analysissettings.h" +#include "gromacs/trajectoryanalysis/topologyinformation.h" #include "gromacs/utility/exceptions.h" #include "testutils/cmdlinetest.h" diff --git a/src/gromacs/trajectoryanalysis/analysissettings.cpp b/src/gromacs/trajectoryanalysis/topologyinformation.cpp similarity index 56% copy from src/gromacs/trajectoryanalysis/analysissettings.cpp copy to src/gromacs/trajectoryanalysis/topologyinformation.cpp index b6bb0d64db..482cda74ca 100644 --- a/src/gromacs/trajectoryanalysis/analysissettings.cpp +++ b/src/gromacs/trajectoryanalysis/topologyinformation.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2018, 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. @@ -34,17 +34,17 @@ */ /*! \internal \file * \brief - * Implements classes in analysissettings.h. + * Implements classes in topologyinformation.h. * * \author Teemu Murtola * \ingroup module_trajectoryanalysis */ #include "gmxpre.h" -#include "analysissettings.h" +#include "topologyinformation.h" -#include "gromacs/commandline/cmdlineoptionsmodule.h" -#include "gromacs/fileio/trxio.h" +#include "gromacs/compat/make_unique.h" +#include "gromacs/fileio/confio.h" #include "gromacs/math/vec.h" #include "gromacs/topology/mtop_util.h" #include "gromacs/topology/topology.h" @@ -53,138 +53,9 @@ #include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" -#include "analysissettings-impl.h" - namespace gmx { - -/******************************************************************** - * TrajectoryAnalysisSettings - */ - -TrajectoryAnalysisSettings::TrajectoryAnalysisSettings() - : impl_(new Impl) -{ - impl_->frflags |= TRX_NEED_X; -} - - -TrajectoryAnalysisSettings::~TrajectoryAnalysisSettings() -{ -} - - -void TrajectoryAnalysisSettings::setOptionsModuleSettings( - ICommandLineOptionsModuleSettings *settings) -{ - impl_->optionsModuleSettings_ = settings; -} - - -TimeUnit -TrajectoryAnalysisSettings::timeUnit() const -{ - return impl_->timeUnit; -} - - -const AnalysisDataPlotSettings & -TrajectoryAnalysisSettings::plotSettings() const -{ - return impl_->plotSettings; -} - - -unsigned long -TrajectoryAnalysisSettings::flags() const -{ - return impl_->flags; -} - - -bool -TrajectoryAnalysisSettings::hasFlag(unsigned long flag) const -{ - return impl_->flags & flag; -} - - -bool -TrajectoryAnalysisSettings::hasPBC() const -{ - return impl_->bPBC; -} - - -bool -TrajectoryAnalysisSettings::hasRmPBC() const -{ - return impl_->bRmPBC; -} - - -int -TrajectoryAnalysisSettings::frflags() const -{ - return impl_->frflags; -} - - -void -TrajectoryAnalysisSettings::setFlags(unsigned long flags) -{ - impl_->flags = flags; -} - - -void -TrajectoryAnalysisSettings::setFlag(unsigned long flag, bool bSet) -{ - if (bSet) - { - impl_->flags |= flag; - } - else - { - impl_->flags &= ~flag; - } -} - - -void -TrajectoryAnalysisSettings::setPBC(bool bPBC) -{ - impl_->bPBC = bPBC; -} - - -void -TrajectoryAnalysisSettings::setRmPBC(bool bRmPBC) -{ - impl_->bRmPBC = bRmPBC; -} - - -void -TrajectoryAnalysisSettings::setFrameFlags(int frflags) -{ - impl_->frflags = frflags; -} - -void -TrajectoryAnalysisSettings::setHelpText(const ArrayRef &help) -{ - GMX_RELEASE_ASSERT(impl_->optionsModuleSettings_ != nullptr, - "setHelpText() called in invalid context"); - impl_->optionsModuleSettings_->setHelpText(help); -} - - -/******************************************************************** - * TopologyInformation - */ - TopologyInformation::TopologyInformation() : mtop_(nullptr), top_(nullptr), bTop_(false), xtop_(nullptr), ePBC_(-1) { @@ -210,6 +81,23 @@ t_topology *TopologyInformation::topology() const return top_; } +void TopologyInformation::fillFromInputFile(const std::string &filename) +{ + mtop_ = gmx::compat::make_unique(); + readConfAndTopology(filename.c_str(), &bTop_, mtop_.get(), + &ePBC_, &xtop_, nullptr, + boxtop_); + // TODO: Only load this here if the tool actually needs it; selections + // take care of themselves. + for (gmx_moltype_t &moltype : mtop_->moltype) + { + if (!moltype.atoms.haveMass) + { + // Try to read masses from database, be silent about missing masses + atomsSetMassesBasedOnNames(&moltype.atoms, FALSE); + } + } +} void TopologyInformation::getTopologyConf(rvec **x, matrix box) const diff --git a/src/gromacs/trajectoryanalysis/topologyinformation.h b/src/gromacs/trajectoryanalysis/topologyinformation.h new file mode 100644 index 0000000000..30510afeb0 --- /dev/null +++ b/src/gromacs/trajectoryanalysis/topologyinformation.h @@ -0,0 +1,145 @@ +/* + * This file is part of the GROMACS molecular simulation package. + * + * Copyright (c) 2018, 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. + * + * 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. + * + * 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. + * + * 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 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 research papers on the package. Check out http://www.gromacs.org. + */ +/*! \file + * \brief + * Declares gmx::TopologyInformation. + * + * \author Teemu Murtola + * \author Mark Abraham + * \inlibraryapi + * \ingroup module_trajectoryanalysis + */ +#ifndef GMX_TRAJECTORYANALYSIS_TOPOLOGYINFORMATION_H +#define GMX_TRAJECTORYANALYSIS_TOPOLOGYINFORMATION_H + +#include + +#include "gromacs/math/vectypes.h" +#include "gromacs/utility/classhelpers.h" + +struct gmx_mtop_t; +struct t_topology; + +namespace gmx +{ + +class TopologyInformation; +class TrajectoryAnalysisRunnerCommon; + +/*! \libinternal + * \brief Topology information passed to a trajectory analysis module. + * + * This class is used to pass topology information to trajectory analysis + * modules and to manage memory for them. Having a single wrapper object + * instead of passing each item separately makes TrajectoryAnalysisModule + * interface simpler, and also reduces the need to change existing code if + * additional information is added. + * + * It is intended that eventually most clients of this class will be + * analysis tools ported to the new analysis framework, but we will + * use this infrastructure also from the legacy analysis tools during + * the transition period. That will make it easier to put those tools + * under tests, and eventually port them. + * + * Methods in this class do not throw if not explicitly stated. + * + * \ingroup module_trajectoryanalysis + */ +class TopologyInformation +{ + public: + //! Returns true if a topology file was loaded. + bool hasTopology() const { return mtop_ != nullptr; } + //! Returns true if a full topology file was loaded. + bool hasFullTopology() const { return bTop_; } + /*! \brief Builder function to fill the contents of + * TopologyInformation in \c topInfo from \c filename. + * + * Different tools require, might need, would benefit from, or + * do not need topology information. This functions implements + * the two-phase construction that is currently needed to + * support that. */ + void fillFromInputFile(const std::string &filename); + //! Returns the loaded topology, or NULL if not loaded. + const gmx_mtop_t *mtop() const { return mtop_.get(); } + //! Returns the loaded topology, or NULL if not loaded. + t_topology *topology() const; + //! Returns the ePBC field from the topology. + int ePBC() const { return ePBC_; } + /*! \brief + * Gets the configuration from the topology. + * + * \param[out] x Topology coordinate pointer to initialize. + * (can be NULL, in which case it is not used). + * \param[out] box Box size from the topology file + * (can be NULL, in which case it is not used). + * \throws APIError if topology coordinates are not available and + * \p x is not NULL. + * + * If TrajectoryAnalysisSettings::efUseTopX has not been specified, + * \p x should be NULL. + * + * The pointer returned in \p *x should not be freed. + */ + void getTopologyConf(rvec **x, matrix box) const; + + private: + TopologyInformation(); + ~TopologyInformation(); + + std::unique_ptr mtop_; + //! The topology structure, or NULL if no topology loaded. + // TODO: Replace fully with mtop. + mutable t_topology *top_; + //! true if full tpx file was loaded, false otherwise. + bool bTop_; + //! Coordinates from the topology (can be NULL). + rvec *xtop_; + //! The box loaded from the topology file. + matrix boxtop_; + //! The ePBC field loaded from the topology file. + int ePBC_; + + GMX_DISALLOW_COPY_AND_ASSIGN(TopologyInformation); + + /*! \brief + * Needed to initialize the data. + */ + friend class TrajectoryAnalysisRunnerCommon; +}; + +} // namespace gmx + +#endif -- 2.11.4.GIT