Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / analysismodule.cpp
index 5fe6f45234b7611a82458bb06e4b02de637338da..a64a95fec7ec0f53d213d9beefd50f054e69c060 100644 (file)
@@ -1,41 +1,47 @@
 /*
+ * 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>
 
@@ -107,6 +113,9 @@ class TrajectoryAnalysisModuleData::Impl
              const AnalysisDataParallelOptions &opt,
              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_;
         //! Stores thread-local selections.
@@ -123,10 +132,30 @@ TrajectoryAnalysisModuleData::Impl::Impl(
     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
@@ -152,7 +181,10 @@ void TrajectoryAnalysisModuleData::finishDataHandles()
     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();
 }
@@ -197,7 +229,7 @@ TrajectoryAnalysisModuleData::parallelSelections(const SelectionList &selections
 namespace
 {
 
-/*! \internal \brief
+/*! \brief
  * Basic thread-local trajectory analysis data storage class.
  *
  * Most simple tools should only require data handles and selections to be
@@ -263,7 +295,9 @@ void TrajectoryAnalysisModule::optionsFinished(
 }
 
 
-void TrajectoryAnalysisModule::initAfterFirstFrame(const t_trxframe & /*fr*/)
+void TrajectoryAnalysisModule::initAfterFirstFrame(
+        const TrajectoryAnalysisSettings & /*settings*/,
+        const t_trxframe                 & /*fr*/)
 {
 }
 
@@ -334,6 +368,7 @@ AbstractAnalysisData &TrajectoryAnalysisModule::datasetFromName(const char *name
 void TrajectoryAnalysisModule::registerBasicDataset(AbstractAnalysisData *data,
                                                     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");