Add initial support for python bindings
[alexxy/gromacs.git] / src / pygromacs / sip / trajectoryanalysis / analysismodule.sip
1
2 struct t_trxframe {
3
4 %TypeHeaderCode
5 #include <gromacs/fileio/trx.h>
6 #include "vec.h"
7 %End
8
9     int flags;
10     int not_ok;
11     bool bDouble;
12     int natoms;
13     double t0;
14     double tf;
15     double tpf;
16     double tppf;
17     bool bTitle;
18     const char *title;
19     bool bStep;
20     int step;
21     bool bTime;
22     double time;
23     bool bLambda;
24     bool bFepState;
25     double lambda;
26     int fep_state;
27     bool bAtoms;
28     // TODO
29     /*void *atoms;*/
30     bool bPrec;
31     double prec;
32     bool bX;
33     rvec *x {
34     %GetCode
35         rvecs *arr = new rvecs(sipCpp->x, sipCpp->natoms);
36         sipPy = sipConvertFromNewType(arr, sipType_rvecs, NULL);
37     %End
38     %SetCode
39
40     %End
41     };
42     bool bV;
43     rvec *v {
44     %GetCode
45         rvecs *arr = new rvecs(sipCpp->v, sipCpp->natoms);
46         sipPy = sipConvertFromNewType(arr, sipType_rvecs, NULL);
47     %End
48     %SetCode
49
50     %End
51     };
52     bool bF;
53     rvec *f {
54     %GetCode
55         rvecs *arr = new rvecs(sipCpp->f, sipCpp->natoms);
56         sipPy = sipConvertFromNewType(arr, sipType_rvecs, NULL);
57     %End
58     %SetCode
59
60     %End
61     };
62     bool bBox;
63     matrix box {
64     %GetCode
65         Matrix *mat = new Matrix(sipCpp->box);
66         sipPy = sipConvertFromNewType(mat, sipType_Matrix, NULL);
67     %End
68     %SetCode
69
70     %End
71     };
72     bool bPBC;
73     int ePBC;
74     // TODO
75     /*t_gmxvmdplugin* *vmdplugin; */
76 };
77
78 struct t_pbc {
79
80 %TypeHeaderCode
81 #include <gromacs/pbcutil/pbc.h>
82 #include "vec.h"
83 %End
84     int ePBC;
85     int ndim_ePBC;
86     int ePBCDX;
87     int dim;
88     matrix box {
89     %GetCode
90         Matrix *mat = new Matrix(sipCpp->box);
91         sipPy = sipConvertFromNewType(mat, sipType_Matrix, NULL);
92     %End
93     %SetCode
94
95     %End
96     };
97     rvec fbox_diag {
98     %GetCode
99         py_rvec *vec = new py_rvec(sipCpp->fbox_diag);
100         sipPy = sipConvertFromNewType(vec, sipType_py_rvec, NULL);
101     %End
102     %SetCode
103
104     %End
105     };
106     rvec hbox_diag {
107     %GetCode
108         py_rvec *vec = new py_rvec(sipCpp->fbox_diag);
109         sipPy = sipConvertFromNewType(vec, sipType_py_rvec, NULL);
110     %End
111     %SetCode
112
113     %End
114     };
115     rvec mhbox_diag {
116     %GetCode
117         py_rvec *vec = new py_rvec(sipCpp->mhbox_diag);
118         sipPy = sipConvertFromNewType(vec, sipType_py_rvec, NULL);
119     %End
120     %SetCode
121
122     %End
123     };
124     double max_cutoff2;
125     bool bLimitDistance;
126     double limit_distance2;
127     int  ntric_vec;
128     /*ivec tric_shift[MAX_NTRICVEC];*/
129     /*rvec tric_vec[MAX_NTRICVEC];*/
130 };
131
132 class TrajectoryAnalysisModuleData /NoDefaultCtors/ {
133
134 %TypeHeaderCode
135 #include <gromacs/trajectoryanalysis/analysismodule.h>
136 using namespace gmx;
137 %End
138
139 public:
140     virtual void finish() = 0;
141 };
142
143 class TrajectoryAnalysisModule {
144
145 %TypeHeaderCode
146 #include <gromacs/trajectoryanalysis/analysismodule.h>
147 using namespace gmx;
148 %End
149 public:
150     virtual void initOptions(Options *options, TrajectoryAnalysisSettings *settings) = 0;
151     virtual void optionsFinished(Options *options, TrajectoryAnalysisSettings *settings);
152     virtual void initAnalysis(const TrajectoryAnalysisSettings &settings, const TopologyInformation &top) = 0;
153     virtual void initAfterFirstFrame(const TrajectoryAnalysisSettings &settings, const t_trxframe &fr);
154 //    virtual TrajectoryAnalysisModuleDataPointer       startFrames (const AnalysisDataParallelOptions &opt, const SelectionCollection &selections);
155     virtual void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc, TrajectoryAnalysisModuleData *pdata ) = 0;
156     virtual void finishFrames(TrajectoryAnalysisModuleData *pdata);
157     virtual void finishAnalysis(int nframes) = 0;
158     virtual void writeOutput() = 0;
159     const char* name() const;
160     const char* description() const;
161     int datasetCount() const;
162 protected:
163     TrajectoryAnalysisModule(const char *name, const char *description);
164 private:
165     TrajectoryAnalysisModule(const TrajectoryAnalysisModule &other);
166 };
167
168 %Exception gmx::InconsistentInputError(SIP_Exception) {
169
170 %TypeHeaderCode
171 #include <gromacs/utility/exceptions.h>
172 using namespace std;
173 %End
174
175 %RaiseCode
176     printf("lALLA\n");
177     const char *detail = sipExceptionRef.what();
178
179     SIP_BLOCK_THREADS
180     PyErr_SetString(sipException_gmx_InconsistentInputError, detail);
181     SIP_UNBLOCK_THREADS
182 %End
183 };
184
185 class TrajectoryAnalysisCommandLineRunner {
186 %TypeHeaderCode
187 #include <gromacs/trajectoryanalysis/cmdlinerunner.h>
188 %End
189
190 public:
191     TrajectoryAnalysisCommandLineRunner(TrajectoryAnalysisModule *module);
192     int run(SIP_PYLIST) throw (gmx::InconsistentInputError);
193     %MethodCode
194     int argc = PyList_GET_SIZE(a0);
195
196     char **argv = new char *[argc + 1];
197
198     // Convert the list.
199     for (int a = 0; a < argc; ++a)
200     {
201         PyObject *arg_obj = PyList_GET_ITEM(a0, a);
202         const char *arg = sipString_AsLatin1String(&arg_obj);
203
204         if (arg)
205         {
206             arg = strdup(arg);
207             Py_DECREF(arg_obj);
208         }
209         else
210         {
211             arg = "unknown";
212         }
213
214         argv[a] = const_cast<char *>(arg);
215     }
216
217     argv[argc] = NULL;
218
219     try {
220         sipCpp->run(argc, argv);
221     } catch (gmx::InconsistentInputError &e) {
222         sipIsErr = 1;
223         PyErr_SetString(sipException_gmx_InconsistentInputError, e.what());
224     }
225     %End
226 private:
227     TrajectoryAnalysisCommandLineRunner(const TrajectoryAnalysisCommandLineRunner &other);
228 };
229