/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
+ * 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.
*
- * G R O M A C S
+ * 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.
*
- * GROningen MAchine for Chemical Simulations
+ * 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.
*
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * 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, 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 www.gromacs.org.
+ * 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 papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
*/
/*! \internal \file
* \brief
* Implements classes in analysismodule.h.
*
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_trajectoryanalysis
*/
-#include "gromacs/trajectoryanalysis/analysismodule.h"
+#include "gmxpre.h"
+
+#include "analysismodule.h"
#include <utility>
public:
//! Container that associates a data handle to its AnalysisData object.
typedef std::map<const AnalysisData *, AnalysisDataHandle>
- HandleContainer;
+ HandleContainer;
//! \copydoc TrajectoryAnalysisModuleData::TrajectoryAnalysisModuleData()
- Impl(TrajectoryAnalysisModule *module,
+ Impl(TrajectoryAnalysisModule *module,
const AnalysisDataParallelOptions &opt,
- const SelectionCollection &selections);
+ const SelectionCollection &selections);
+
+ //! Checks whether the given AnalysisData has been initialized.
+ bool isInitialized(const AnalysisData &data) const;
//! Keeps a data handle for each AnalysisData object.
- HandleContainer handles_;
+ HandleContainer handles_;
//! Stores thread-local selections.
const SelectionCollection &selections_;
};
TrajectoryAnalysisModuleData::Impl::Impl(
- TrajectoryAnalysisModule *module,
+ TrajectoryAnalysisModule *module,
const AnalysisDataParallelOptions &opt,
- const SelectionCollection &selections)
+ const SelectionCollection &selections)
: selections_(selections)
{
TrajectoryAnalysisModule::Impl::AnalysisDatasetContainer::const_iterator i;
for (i = module->impl_->analysisDatasets_.begin();
i != module->impl_->analysisDatasets_.end(); ++i)
{
- handles_.insert(std::make_pair(i->second, i->second->startData(opt)));
+ AnalysisDataHandle handle;
+ if (isInitialized(*i->second))
+ {
+ handle = i->second->startData(opt);
+ }
+ handles_.insert(std::make_pair(i->second, handle));
}
}
+bool TrajectoryAnalysisModuleData::Impl::isInitialized(
+ const AnalysisData &data) const
+{
+ for (int i = 0; i < data.dataSetCount(); ++i)
+ {
+ if (data.columnCount(i) > 0)
+ {
+ // If not all of the column counts are set, startData() in the
+ // constructor asserts, so that does not need to be checked here.
+ return true;
+ }
+ }
+ return false;
+}
+
/********************************************************************
* TrajectoryAnalysisModuleData
*/
TrajectoryAnalysisModuleData::TrajectoryAnalysisModuleData(
- TrajectoryAnalysisModule *module,
+ TrajectoryAnalysisModule *module,
const AnalysisDataParallelOptions &opt,
- const SelectionCollection &selections)
+ const SelectionCollection &selections)
: impl_(new Impl(module, opt, selections))
{
}
Impl::HandleContainer::iterator i;
for (i = impl_->handles_.begin(); i != impl_->handles_.end(); ++i)
{
- i->second.finishData();
+ if (i->second.isValid())
+ {
+ i->second.finishData();
+ }
}
impl_->handles_.clear();
}
TrajectoryAnalysisModuleData::parallelSelections(const SelectionList &selections)
{
// TODO: Consider an implementation that does not allocate memory every time.
- SelectionList newSelections;
+ SelectionList newSelections;
newSelections.reserve(selections.size());
SelectionList::const_iterator i = selections.begin();
- for ( ; i != selections.end(); ++i)
+ for (; i != selections.end(); ++i)
{
newSelections.push_back(parallelSelection(*i));
}
namespace
{
-/*! \internal \brief
+/*! \brief
* Basic thread-local trajectory analysis data storage class.
*
* Most simple tools should only require data handles and selections to be
* \param[in] opt Data parallelization options.
* \param[in] selections Thread-local selection collection.
*/
- TrajectoryAnalysisModuleDataBasic(TrajectoryAnalysisModule *module,
+ TrajectoryAnalysisModuleDataBasic(TrajectoryAnalysisModule *module,
const AnalysisDataParallelOptions &opt,
- const SelectionCollection &selections);
+ const SelectionCollection &selections);
virtual void finish();
};
TrajectoryAnalysisModuleDataBasic::TrajectoryAnalysisModuleDataBasic(
- TrajectoryAnalysisModule *module,
+ TrajectoryAnalysisModule *module,
const AnalysisDataParallelOptions &opt,
- const SelectionCollection &selections)
+ const SelectionCollection &selections)
: TrajectoryAnalysisModuleData(module, opt, selections)
{
}
finishDataHandles();
}
-} // namespace
+} // namespace
/********************************************************************
void TrajectoryAnalysisModule::optionsFinished(
- Options * /*options*/,
+ Options * /*options*/,
TrajectoryAnalysisSettings * /*settings*/)
{
}
-void TrajectoryAnalysisModule::initAfterFirstFrame(const t_trxframe &/*fr*/)
+void TrajectoryAnalysisModule::initAfterFirstFrame(
+ const TrajectoryAnalysisSettings & /*settings*/,
+ const t_trxframe & /*fr*/)
{
}
TrajectoryAnalysisModuleDataPointer
TrajectoryAnalysisModule::startFrames(const AnalysisDataParallelOptions &opt,
- const SelectionCollection &selections)
+ const SelectionCollection &selections)
{
return TrajectoryAnalysisModuleDataPointer(
new TrajectoryAnalysisModuleDataBasic(this, opt, selections));
void TrajectoryAnalysisModule::registerBasicDataset(AbstractAnalysisData *data,
- const char *name)
+ const char *name)
{
+ GMX_RELEASE_ASSERT(data != NULL, "Attempting to register NULL data");
// TODO: Strong exception safety should be possible to implement.
GMX_RELEASE_ASSERT(impl_->datasets_.find(name) == impl_->datasets_.end(),
"Duplicate data set name registered");
void TrajectoryAnalysisModule::registerAnalysisDataset(AnalysisData *data,
- const char *name)
+ const char *name)
{
// TODO: Strong exception safety should be possible to implement.
registerBasicDataset(data, name);