#
# 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.
analysismodule.h
analysissettings.h
cmdlinerunner.h
+ topologyinformation.h
)
if (BUILD_TESTING)
#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"
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<rvec *>(boxtop_), box);
- }
- if (x)
- {
- if (!xtop_)
- {
- *x = nullptr;
- GMX_THROW(APIError("Topology coordinates requested without setting efUseTopX"));
- }
- *x = xtop_;
- }
-}
-
} // namespace gmx
*/
/*! \file
* \brief
- * Declares gmx::TrajectoryAnalysisSettings and gmx::TopologyInformation.
+ * Declares gmx::TrajectoryAnalysisSettings.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \inpublicapi
#include <string>
-#include "gromacs/math/vectypes.h"
#include "gromacs/options/timeunitmanager.h"
#include "gromacs/utility/classhelpers.h"
-struct gmx_mtop_t;
-struct t_topology;
-
namespace gmx
{
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<gmx_mtop_t> 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
#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"
/*
* 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.
#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"
/*
* 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.
#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"
*
* 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.
#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"
#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"
#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"
#include <algorithm>
#include <string>
-#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"
#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"
// Load the topology if requested.
if (!topfile_.empty())
{
- topInfo_.mtop_ = gmx::compat::make_unique<gmx_mtop_t>();
- 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))
{
/*
* 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.
#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"
--- /dev/null
+/*
+ * 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.
+ */
+/*! \internal \file
+ * \brief
+ * Implements classes in topologyinformation.h.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_trajectoryanalysis
+ */
+#include "gmxpre.h"
+
+#include "topologyinformation.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"
+#include "gromacs/utility/arrayref.h"
+#include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/smalloc.h"
+
+namespace gmx
+{
+
+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::fillFromInputFile(const std::string &filename)
+{
+ mtop_ = gmx::compat::make_unique<gmx_mtop_t>();
+ 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
+{
+ if (box)
+ {
+ copy_mat(const_cast<rvec *>(boxtop_), box);
+ }
+ if (x)
+ {
+ if (!xtop_)
+ {
+ *x = nullptr;
+ GMX_THROW(APIError("Topology coordinates requested without setting efUseTopX"));
+ }
+ *x = xtop_;
+ }
+}
+
+} // namespace gmx
--- /dev/null
+/*
+ * 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 <teemu.murtola@gmail.com>
+ * \author Mark Abraham <mark.j.abraham@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_trajectoryanalysis
+ */
+#ifndef GMX_TRAJECTORYANALYSIS_TOPOLOGYINFORMATION_H
+#define GMX_TRAJECTORYANALYSIS_TOPOLOGYINFORMATION_H
+
+#include <string>
+
+#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<gmx_mtop_t> 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