/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_trajectoryanalysis
*/
-#include "runnercommon.h"
+#include "gmxpre.h"
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include "runnercommon.h"
#include <string.h>
#include "gromacs/legacyheaders/oenv.h"
-#include "gromacs/legacyheaders/rmpbc.h"
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/statutil.h"
-#include "gromacs/legacyheaders/tpxio.h"
-#include "gromacs/legacyheaders/vec.h"
+#include "gromacs/fileio/timecontrol.h"
+#include "gromacs/fileio/tpxio.h"
+#include "gromacs/fileio/trx.h"
+#include "gromacs/fileio/trxio.h"
+#include "gromacs/math/vec.h"
#include "gromacs/options/basicoptions.h"
#include "gromacs/options/filenameoption.h"
#include "gromacs/options/options.h"
+#include "gromacs/pbcutil/rmpbc.h"
#include "gromacs/selection/indexutil.h"
#include "gromacs/selection/selectioncollection.h"
#include "gromacs/selection/selectionfileoption.h"
+#include "gromacs/topology/topology.h"
#include "gromacs/trajectoryanalysis/analysissettings.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/programcontext.h"
+#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
#include "analysissettings-impl.h"
TrajectoryAnalysisSettings &settings_;
TopologyInformation topInfo_;
- bool bHelp_;
- bool bShowHidden_;
- bool bQuiet_;
//! Name of the trajectory file (empty if not provided).
std::string trjfile_;
//! Name of the topology file (empty if no topology provided).
TrajectoryAnalysisRunnerCommon::Impl::Impl(TrajectoryAnalysisSettings *settings)
: settings_(*settings),
- bHelp_(false), bShowHidden_(false), bQuiet_(false),
startTime_(0.0), endTime_(0.0), deltaTime_(0.0),
grps_(NULL),
bTrajOpen_(false), fr(NULL), gpbc_(NULL), status_(NULL), oenv_(NULL)
{
TrajectoryAnalysisSettings &settings = impl_->settings_;
- // Add options for help.
- options->addOption(BooleanOption("h").store(&impl_->bHelp_)
- .description("Print help and quit"));
- options->addOption(BooleanOption("hidden").store(&impl_->bShowHidden_)
- .hidden()
- .description("Show hidden options"));
- options->addOption(BooleanOption("quiet").store(&impl_->bQuiet_)
- .hidden()
- .description("Hide options in normal run"));
-
// Add common file name arguments.
options->addOption(FileNameOption("f")
.filetype(eftTrajectory).inputFile()
.store(&impl_->ndxfile_)
.defaultBasename("index")
.description("Extra index groups"));
- options->addOption(SelectionFileOption("sf"));
// Add options for trajectory time control.
options->addOption(DoubleOption("b").store(&impl_->startTime_).timeValue()
options->addOption(BooleanOption("pbc").store(&settings.impl_->bPBC)
.description("Use periodic boundary conditions for distance calculation"));
}
+
+ options->addOption(SelectionFileOption("sf"));
}
}
-bool
+void
TrajectoryAnalysisRunnerCommon::optionsFinished(Options *options)
{
- if (impl_->bHelp_)
- {
- return false;
- }
-
impl_->settings_.impl_->plotSettings.setTimeUnit(
impl_->settings_.impl_->timeUnitManager.timeUnit());
{
setTimeValue(TDELTA, impl_->deltaTime_);
}
-
- return true;
}
void
-TrajectoryAnalysisRunnerCommon::initIndexGroups(SelectionCollection *selections)
+TrajectoryAnalysisRunnerCommon::initIndexGroups(SelectionCollection *selections,
+ bool bUseDefaults)
{
if (impl_->ndxfile_.empty())
{
- // TODO: Initialize default selections
- selections->setIndexGroups(NULL);
- }
- else
- {
- gmx_ana_indexgrps_init(&impl_->grps_, NULL, impl_->ndxfile_.c_str());
- selections->setIndexGroups(impl_->grps_);
+ if (!bUseDefaults)
+ {
+ selections->setIndexGroups(NULL);
+ return;
+ }
+ initTopology(selections);
}
+ const char *const ndxfile
+ = (!impl_->ndxfile_.empty() ? impl_->ndxfile_.c_str() : NULL);
+ gmx_ana_indexgrps_init(&impl_->grps_, impl_->topInfo_.topology(), ndxfile);
+ selections->setIndexGroups(impl_->grps_);
}
void
TrajectoryAnalysisRunnerCommon::initTopology(SelectionCollection *selections)
{
+ // Return immediately if the topology has already been loaded.
+ if (impl_->topInfo_.hasTopology())
+ {
+ return;
+ }
+
const TrajectoryAnalysisSettings &settings = impl_->settings_;
- bool bRequireTop
+ const bool bRequireTop
= settings.hasFlag(TrajectoryAnalysisSettings::efRequireTop)
|| selections->requiresTopology();
if (bRequireTop && impl_->topfile_.empty())
}
time_unit_t time_unit
= static_cast<time_unit_t>(impl_->settings_.timeUnit() + 1);
- output_env_init(&impl_->oenv_, 0, NULL, time_unit, FALSE, exvgNONE, 0, 0);
+ output_env_init(&impl_->oenv_, getProgramContext(), time_unit, FALSE, exvgNONE, 0);
int frflags = impl_->settings_.frflags();
frflags |= TRX_NEED_X;
"Trajectory (%d atoms) does not match topology (%d atoms)",
impl_->fr->natoms, top.topology()->atoms.nr)));
}
- // TODO: Check index groups if they have been initialized based on the topology.
- /*
- if (top)
- {
- for (int i = 0; i < impl_->sel->nr(); ++i)
- {
- gmx_ana_index_check(impl_->sel->sel(i)->indexGroup(),
- impl_->fr->natoms);
- }
- }
- */
}
else
{
if (top.hasTopology() && impl_->settings_.hasRmPBC())
{
impl_->gpbc_ = gmx_rmpbc_init(&top.topology()->idef, top.ePBC(),
- impl_->fr->natoms, impl_->fr->box);
+ impl_->fr->natoms);
}
}
}
-TrajectoryAnalysisRunnerCommon::HelpFlags
-TrajectoryAnalysisRunnerCommon::helpFlags() const
-{
- HelpFlags flags = 0;
-
- if (!impl_->bQuiet_)
- {
- flags |= efHelpShowOptions;
- if (impl_->bHelp_)
- {
- flags |= efHelpShowDescriptions;
- }
- if (impl_->bShowHidden_)
- {
- flags |= efHelpShowHidden;
- }
- }
- return flags;
-}
-
bool
TrajectoryAnalysisRunnerCommon::hasTrajectory() const
{