Update headers, fix style for some py files
[alexxy/gromacs.git] / src / python / sip / trajectoryanalysis / analysismodule.sip
index c482ba316676c8bc8645b0ca5b4a893d8b7fe454..cd5c65628d586318e104bfd68010ba3c260ad501 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, 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.
  * the research papers on the package. Check out http://www.gromacs.org.
  */
 
+%PostInitialisationCode
+    import_array();
+%End
+
 struct t_trxframe {
 
 %TypeHeaderCode
 #include <gromacs/fileio/trx.h>
-#include "vec.h"
+#include "numpy_conv.h"
 %End
 
     int flags;
@@ -59,48 +63,31 @@ struct t_trxframe {
     double lambda;
     int fep_state;
     bool bAtoms;
-    // TODO
-    /*void *atoms;*/
+    t_atoms *atoms;
     bool bPrec;
     double prec;
     bool bX;
-    rvec *x {
+    SIP_PYOBJECT x /NoSetter/ {
     %GetCode
-        rvecs *arr = new rvecs(sipCpp->x, sipCpp->natoms);
-        sipPy = sipConvertFromNewType(arr, sipType_rvecs, NULL);
-    %End
-    %SetCode
-
+        sipPy = array2dToNumpy(sipCpp->natoms, 3, sipCpp->x);
     %End
     };
     bool bV;
-    rvec *v {
+    SIP_PYOBJECT v /NoSetter/ {
     %GetCode
-        rvecs *arr = new rvecs(sipCpp->v, sipCpp->natoms);
-        sipPy = sipConvertFromNewType(arr, sipType_rvecs, NULL);
-    %End
-    %SetCode
-
+        sipPy = array2dToNumpy(sipCpp->natoms, 3, sipCpp->v);
     %End
     };
     bool bF;
-    rvec *f {
+    SIP_PYOBJECT f /NoSetter/ {
     %GetCode
-        rvecs *arr = new rvecs(sipCpp->f, sipCpp->natoms);
-        sipPy = sipConvertFromNewType(arr, sipType_rvecs, NULL);
-    %End
-    %SetCode
-
+        sipPy = array2dToNumpy(sipCpp->natoms, 3, sipCpp->f);
     %End
     };
     bool bBox;
-    matrix box {
+    SIP_PYOBJECT box /NoSetter/ {
     %GetCode
-        Matrix *mat = new Matrix(sipCpp->box);
-        sipPy = sipConvertFromNewType(mat, sipType_Matrix, NULL);
-    %End
-    %SetCode
-
+        sipPy = array2dToNumpy(3, 3, sipCpp->box);
     %End
     };
     bool bPBC;
@@ -113,46 +100,30 @@ struct t_pbc {
 
 %TypeHeaderCode
 #include <gromacs/pbcutil/pbc.h>
-#include "vec.h"
+#include "numpy_conv.h"
 %End
     int ePBC;
     int ndim_ePBC;
     int ePBCDX;
     int dim;
-    matrix box {
+    SIP_PYOBJECT box /NoSetter/ {
     %GetCode
-        Matrix *mat = new Matrix(sipCpp->box);
-        sipPy = sipConvertFromNewType(mat, sipType_Matrix, NULL);
-    %End
-    %SetCode
-
+        sipPy = array2dToNumpy(3, 3, sipCpp->box);
     %End
     };
-    rvec fbox_diag {
+    SIP_PYOBJECT fbox_diag /NoSetter/ {
     %GetCode
-        py_rvec *vec = new py_rvec(sipCpp->fbox_diag);
-        sipPy = sipConvertFromNewType(vec, sipType_py_rvec, NULL);
-    %End
-    %SetCode
-
+        sipPy = array1dToNumpy(3, sipCpp->fbox_diag);
     %End
     };
-    rvec hbox_diag {
+    SIP_PYOBJECT hbox_diag /NoSetter/ {
     %GetCode
-        py_rvec *vec = new py_rvec(sipCpp->fbox_diag);
-        sipPy = sipConvertFromNewType(vec, sipType_py_rvec, NULL);
-    %End
-    %SetCode
-
+        sipPy = array1dToNumpy(3, sipCpp->hbox_diag);
     %End
     };
-    rvec mhbox_diag {
+    SIP_PYOBJECT mhbox_diag /NoSetter/ {
     %GetCode
-        py_rvec *vec = new py_rvec(sipCpp->mhbox_diag);
-        sipPy = sipConvertFromNewType(vec, sipType_py_rvec, NULL);
-    %End
-    %SetCode
-
+        sipPy = array1dToNumpy(3, sipCpp->mhbox_diag);
     %End
     };
     double max_cutoff2;
@@ -174,25 +145,42 @@ public:
     virtual void finish() = 0;
 };
 
-class TrajectoryAnalysisModule {
+%ModuleHeaderCode
+#include "gromacs/utility/exceptions.h"
+%End
+
+%VirtualErrorHandler vehandler
+    SIP_RELEASE_GIL(sipGILState);
+
+    GMX_THROW(gmx::InternalError("Python virtual overload raised an exception, see traceback"));
+%End
+
+%Include vector.sip
+
+class TrajectoryAnalysisModule /VirtualErrorHandler=vehandler/ {
 
 %TypeHeaderCode
 #include <gromacs/trajectoryanalysis/analysismodule.h>
 using namespace gmx;
 %End
 public:
-    virtual void initOptions(Options *options, TrajectoryAnalysisSettings *settings) = 0;
-    virtual void optionsFinished(Options *options, TrajectoryAnalysisSettings *settings);
+    virtual void initOptions(IOptionsContainer *options, TrajectoryAnalysisSettings *settings) = 0;
+    virtual void optionsFinished(TrajectoryAnalysisSettings *settings);
     virtual void initAnalysis(const TrajectoryAnalysisSettings &settings, const TopologyInformation &top) = 0;
     virtual void initAfterFirstFrame(const TrajectoryAnalysisSettings &settings, const t_trxframe &fr);
 //    virtual TrajectoryAnalysisModuleDataPointer      startFrames (const AnalysisDataParallelOptions &opt, const SelectionCollection &selections);
-    virtual void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc, TrajectoryAnalysisModuleData *pdata ) = 0;
+    virtual void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc, TrajectoryAnalysisModuleData *pdata) = 0;
     virtual void finishFrames(TrajectoryAnalysisModuleData *pdata);
     virtual void finishAnalysis(int nframes) = 0;
     virtual void writeOutput() = 0;
+    virtual const std::vector<TrajectoryAnalysisModule*> getBatch();
+    virtual const std::vector<char*> getArgv(int);
     const char* name() const;
     const char* description() const;
     int datasetCount() const;
+//    const std::vector<std::string> datasetNames() const;
+    AbstractAnalysisData& datasetFromIndex(int index) const;
+    AbstractAnalysisData& datasetFromName(const char *name) const;
 protected:
     TrajectoryAnalysisModule(const char *name, const char *description);
 private:
@@ -207,7 +195,6 @@ using namespace std;
 %End
 
 %RaiseCode
-    printf("lALLA\n");
     const char *detail = sipExceptionRef.what();
 
     SIP_BLOCK_THREADS
@@ -215,49 +202,3 @@ using namespace std;
     SIP_UNBLOCK_THREADS
 %End
 };
-
-class TrajectoryAnalysisCommandLineRunner {
-%TypeHeaderCode
-#include <gromacs/trajectoryanalysis/cmdlinerunner.h>
-%End
-
-public:
-    TrajectoryAnalysisCommandLineRunner(TrajectoryAnalysisModule *module);
-    int run(SIP_PYLIST) throw (gmx::InconsistentInputError);
-    %MethodCode
-    int argc = PyList_GET_SIZE(a0);
-
-    char **argv = new char *[argc + 1];
-
-    // Convert the list.
-    for (int a = 0; a < argc; ++a)
-    {
-        PyObject *arg_obj = PyList_GET_ITEM(a0, a);
-        const char *arg = sipString_AsLatin1String(&arg_obj);
-
-        if (arg)
-        {
-            arg = strdup(arg);
-            Py_DECREF(arg_obj);
-        }
-        else
-        {
-            arg = "unknown";
-        }
-
-        argv[a] = const_cast<char *>(arg);
-    }
-
-    argv[argc] = NULL;
-
-    try {
-        sipCpp->run(argc, argv);
-    } catch (gmx::InconsistentInputError &e) {
-        sipIsErr = 1;
-        PyErr_SetString(sipException_gmx_InconsistentInputError, e.what());
-    }
-    %End
-private:
-    TrajectoryAnalysisCommandLineRunner(const TrajectoryAnalysisCommandLineRunner &other);
-};
-