Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / analysisdata / modules / plot.h
index 6145117e52f38a9baa83a0b5c42339709f4eba9c..9696d54e66627f73d782c2c395aa771828964563 100644 (file)
@@ -1,32 +1,36 @@
 /*
+ * 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.
  */
 /*! \file
  * \brief
  *
  * \inpublicapi
  * \ingroup module_analysisdata
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
  */
 #ifndef GMX_ANALYSISDATA_MODULES_PLOT_H
 #define GMX_ANALYSISDATA_MODULES_PLOT_H
 
 #include <string>
 
-#include "../datamodule.h"
+#include <boost/shared_ptr.hpp>
+
+#include "gromacs/analysisdata/datamodule.h"
+#include "gromacs/options/timeunitmanager.h"
+#include "gromacs/utility/common.h"
 
 namespace gmx
 {
 
+class AnalysisDataValue;
 class Options;
+class SelectionCollection;
+
+/*! \brief
+ * Common settings for data plots.
+ *
+ * \inpublicapi
+ * \ingroup module_analysisdata
+ */
+class AnalysisDataPlotSettings
+{
+    public:
+        //! Constructs default analysis plot settings.
+        AnalysisDataPlotSettings();
+
+        //! Returns the selection collection set with setSelectionCollection().
+        const SelectionCollection *selectionCollection() const
+        {
+            return selections_;
+        }
+        //! Returns the time unit set with setTimeUnit().
+        TimeUnit timeUnit() const { return timeUnit_; }
+        /*! \brief
+         * Returns the plot format.
+         *
+         * \todo Use a proper enum.
+         */
+        int plotFormat() const { return plotFormat_; }
+
+        /*! \brief
+         * Set selection collection to print as comments into the output.
+         *
+         * Formatted selection text from all selections in \p selections is
+         * printed as comments in the output file.
+         * If this method is not called, no selection information is written
+         * to the output.
+         */
+        void setSelectionCollection(const SelectionCollection *selections);
+        /*! \brief
+         * Sets the time unit for the plot.
+         *
+         * The value is used only if AbstractPlotModule::setXAxisIsTime() is
+         * called, in which case it is used to print the appropriate axis label
+         * and to scale the values.
+         * If not called, the default time unit is ps.
+         */
+        void setTimeUnit(TimeUnit timeUnit) { timeUnit_ = timeUnit; }
+
+
+        /*! \brief
+         * Adds common options for setting plot options.
+         *
+         * \param[in,out] options Options object to which options are added.
+         */
+        void addOptions(Options *options);
+
+    private:
+        const SelectionCollection *selections_;
+        TimeUnit                   timeUnit_;
+        int                        plotFormat_;
+};
 
 /*! \brief
  * Abstract data module for writing data into a file.
@@ -56,29 +125,36 @@ class Options;
  * straightforward plotting).
  *
  * By default, the data is written into an xvgr file, according to the
- * options read from the Options object given to the constructor.
+ * options read from the AnalysisDataPlotSettings object given to the
+ * constructor.
  * For non-xvgr data, it's possible to skip all headers by calling
  * setPlainOutput().
  *
- * Multipoint data is supported, in which case all the points are written to
- * the output, in the order in which they are added to the data.  A single
- * output line corresponds to a single frame.  In most cases with multipoint
- * data, setPlainOutput() should be called since the output does not make sense
- * as an xvgr file, but this is not enforced.
+ * A single output line corresponds to a single frame.  In most cases with
+ * multipoint data, setPlainOutput() should be called since the output does not
+ * make sense as an xvgr file, but this is not enforced.
+ *
+ * Multipoint data and multiple data sets are both supported, in which case all
+ * the points are written to the output, in the order in which they are added
+ * to the data.
  *
  * \ingroup module_analysisdata
  */
-class AbstractPlotModule : public AnalysisDataModuleInterface
+class AbstractPlotModule : public AnalysisDataModuleSerial
 {
     public:
         virtual ~AbstractPlotModule();
 
+        /*! \brief
+         * Set common settings for the plotting.
+         */
+        void setSettings(const AnalysisDataPlotSettings &settings);
         /*! \brief
          * Set the output file name.
          *
-         * If no file name is set (or if \p fnm is NULL), no output occurs.
+         * If no file name is set (or if \p filename is empty), no output occurs.
          */
-        void setFileName(const std::string &fnm);
+        void setFileName(const std::string &filename);
         /*! \brief
          * Set plain output.
          *
@@ -87,6 +163,10 @@ class AbstractPlotModule : public AnalysisDataModuleInterface
          * methods have any effect on the output.
          */
         void setPlainOutput(bool bPlain);
+        /*! \brief
+         * Plot errors as a separate output column after each value column.
+         */
+        void setErrorsAsSeparateColumn(bool bSeparate);
         /*! \brief
          * Omit the X coordinates from the output.
          *
@@ -106,9 +186,12 @@ class AbstractPlotModule : public AnalysisDataModuleInterface
          */
         void setXLabel(const char *label);
         /*! \brief
-         * Set X axis label for time.
+         * Treat X axis as time.
+         *
+         * Sets the label for the axis accordingly and also scales output to
+         * take into account the correct time unit.
          */
-        void setXTimeLabel();
+        void setXAxisIsTime();
         /*! \brief
          * Set Y axis label.
          */
@@ -127,41 +210,50 @@ class AbstractPlotModule : public AnalysisDataModuleInterface
          * together.
          */
         void appendLegend(const char *setname);
+        //! \copydoc appendLegend(const char *)
+        void appendLegend(const std::string &setname);
         /*! \brief
          * Set field width and precision for X value output.
          */
-        void setXFormat(int width, int prec, char fmt = 'f');
+        void setXFormat(int width, int precision, char format = 'f');
         /*! \brief
          * Set field width and precision for Y value output.
          */
-        void setYFormat(int width, int prec, char fmt = 'f');
+        void setYFormat(int width, int precision, char format = 'f');
 
         virtual int flags() const;
 
         virtual void dataStarted(AbstractAnalysisData *data);
-        virtual void frameStarted(real x, real dx);
-        virtual void pointsAdded(real x, real dx, int firstcol, int n,
-                                 const real *y, const real *dy,
-                                 const bool *present) = 0;
-        virtual void frameFinished();
+        virtual void frameStarted(const AnalysisDataFrameHeader &header);
+        virtual void pointsAdded(const AnalysisDataPointSetRef &points) = 0;
+        virtual void frameFinished(const AnalysisDataFrameHeader &header);
         virtual void dataFinished();
 
     protected:
         /*! \cond libapi */
-        explicit AbstractPlotModule(const Options &options);
+        AbstractPlotModule();
+        //! Creates AbstractPlotModule and assign common settings.
+        explicit AbstractPlotModule(const AnalysisDataPlotSettings &settings);
 
+        //! Whether an output file has been opened.
         bool isFileOpen() const;
-        void writeValue(real value) const;
+        /*! \brief
+         * Appends a single value to the current output line.
+         *
+         * \param[in] value  Value to append.
+         *
+         * Should be used from pointsAdded() implementations in derived classes
+         * to write out individual y values to the output.
+         *
+         * Must not be called if isFileOpen() returns false.
+         */
+        void writeValue(const AnalysisDataValue &value) const;
         //! \endcond
 
     private:
         class Impl;
 
-        Impl                   *_impl;
-
-        // Disallow copy and assign.
-        AbstractPlotModule(const AbstractPlotModule &);
-        void operator =(const AbstractPlotModule &);
+        PrivateImplPointer<Impl> impl_;
 };
 
 
@@ -176,11 +268,11 @@ class AbstractPlotModule : public AnalysisDataModuleInterface
 class AnalysisDataPlotModule : public AbstractPlotModule
 {
     public:
-        explicit AnalysisDataPlotModule(const Options &options);
+        AnalysisDataPlotModule();
+        //! Creates AnalysisDataPlotModule and assign common settings.
+        explicit AnalysisDataPlotModule(const AnalysisDataPlotSettings &settings);
 
-        virtual void pointsAdded(real x, real dx, int firstcol, int n,
-                                 const real *y, const real *dy,
-                                 const bool *present);
+        virtual void pointsAdded(const AnalysisDataPointSetRef &points);
 
         // Copy and assign disallowed by base.
 };
@@ -197,7 +289,9 @@ class AnalysisDataPlotModule : public AbstractPlotModule
 class AnalysisDataVectorPlotModule : public AbstractPlotModule
 {
     public:
-        explicit AnalysisDataVectorPlotModule(const Options &options);
+        AnalysisDataVectorPlotModule();
+        //! Creates AnalysisDataVectorPlotModule and assign common settings.
+        explicit AnalysisDataVectorPlotModule(const AnalysisDataPlotSettings &settings);
 
         /*! \brief
          * Set whether to write X component.
@@ -220,16 +314,21 @@ class AnalysisDataVectorPlotModule : public AbstractPlotModule
          */
         void setWriteMask(bool bWrite[4]);
 
-        virtual void pointsAdded(real x, real dx, int firstcol, int n,
-                                 const real *y, const real *dy,
-                                 const bool *present);
+        virtual void pointsAdded(const AnalysisDataPointSetRef &points);
 
     private:
-        bool                    _bWrite[4];
+        bool                    bWrite_[4];
 
         // Copy and assign disallowed by base.
 };
 
+//! Smart pointer to manage an AnalysisDataPlotModule object.
+typedef boost::shared_ptr<AnalysisDataPlotModule>
+    AnalysisDataPlotModulePointer;
+//! Smart pointer to manage an AnalysisDataVectorPlotModule object.
+typedef boost::shared_ptr<AnalysisDataVectorPlotModule>
+    AnalysisDataVectorPlotModulePointer;
+
 } // namespace gmx
 
 #endif