/*
* 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.
%Module gromacs.TrajectoryAnalysis
+%DefaultEncoding "UTF-8"
+
%Import options/Options.sip
%Import topology/Topology.sip
%Include definitions.sip
%Include analysissettings.sip
+%Include analysisdata.sip
%Include analysismodule.sip
+
+%Include modules.sip
+
+%ModuleCode
+#include "gromacs/trajectoryanalysis/analysismodule.h"
+#include "gromacs/trajectoryanalysis/cmdlinerunner.h"
+#include "gromacs/utility/exceptions.h"
+
+class PyFactory : public gmx::TrajectoryAnalysisCommandLineRunner::ModuleFactoryFunctor {
+public:
+ PyFactory(PyObject *mod) : mod(mod) {} ;
+ gmx::TrajectoryAnalysisModulePointer operator () () {
+ int iserr = 0;
+ int can = sipCanConvertToType(mod, sipType_TrajectoryAnalysisModule, 0);
+ // TODO: throw if can't
+ gmx::TrajectoryAnalysisModule *module = (gmx::TrajectoryAnalysisModule*) sipConvertToType(
+ mod, sipType_TrajectoryAnalysisModule, NULL, 0, NULL, &iserr);
+ return TrajectoryAnalysisModulePointer(module);
+ }
+private:
+ PyObject *mod;
+};
+
+void runAsMain(PyObject *mod, PyObject *py_argv) {
+ int argc = PyList_GET_SIZE(py_argv);
+
+ char **argv = new char *[argc + 1];
+ bool to_free[argc];
+ std::fill(to_free, to_free+argc, false);
+
+ // Convert the list.
+ // TODO: Use something better than AsLatin1String to avoid unicode errors
+ for (int a = 0; a < argc; ++a)
+ {
+ PyObject *arg_obj = PyList_GET_ITEM(py_argv, a);
+ const char *arg = sipString_AsLatin1String(&arg_obj);
+
+ if (arg)
+ {
+ arg = strdup(arg);
+ Py_DECREF(arg_obj);
+ to_free[a] = true;
+ }
+ else
+ {
+ arg = "unknown";
+ }
+
+ argv[a] = const_cast<char *>(arg);
+ }
+
+ argv[argc] = NULL;
+
+ PyFactory factory(mod);
+ TrajectoryAnalysisCommandLineRunner::runAsMain(argc, argv, &factory);
+
+ for (int i = 0; i < argc; i++)
+ if (to_free[i])
+ free(argv[i]);
+ delete[] argv;
+}
+
+%End
+
+void runAsMain(SIP_PYOBJECT mod, SIP_PYLIST argv);