00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "py_commands.h"
00022 #include "CommandQueue.h"
00023 #include "VMDApp.h"
00024 #include "Molecule.h"
00025 #include "MoleculeList.h"
00026 #include "Animation.h"
00027
00028
00029 static char once_doc[] = "once() -> None\nAnimate once through all frames.";
00030 static PyObject *once(PyObject *self, PyObject *args) {
00031 if (!PyArg_ParseTuple(args, (char *)""))
00032 return NULL;
00033
00034 VMDApp *app = get_vmdapp();
00035 app->animation_set_style(Animation::ANIM_ONCE);
00036
00037 Py_INCREF(Py_None);
00038 return Py_None;
00039 }
00040
00041
00042 static char rock_doc[] = "rock() -> None\nAnimate back and forth between first and last frames.";
00043 static PyObject *rock(PyObject *self, PyObject *args) {
00044 if (!PyArg_ParseTuple(args, (char *)""))
00045 return NULL;
00046
00047 VMDApp *app = get_vmdapp();
00048 app->animation_set_style(Animation::ANIM_ROCK);
00049
00050 Py_INCREF(Py_None);
00051 return Py_None;
00052 }
00053
00054
00055 static char loop_doc[] = "loop() -> None\nAnimate in a continuous loop.";
00056 static PyObject *loop(PyObject *self, PyObject *args) {
00057 if (!PyArg_ParseTuple(args, (char *)""))
00058 return NULL;
00059
00060 VMDApp *app = get_vmdapp();
00061 app->animation_set_style(Animation::ANIM_LOOP);
00062
00063 Py_INCREF(Py_None);
00064 return Py_None;
00065 }
00066
00067
00068 static char style_doc[] = "style() -> string\nReturns current animation style ('rock', 'once', or 'loop').";
00069 static PyObject *style(PyObject *self, PyObject *args) {
00070 if (!PyArg_ParseTuple(args, (char *)""))
00071 return NULL;
00072
00073 int stylenum = get_vmdapp()->anim->anim_style();
00074 return PyString_FromString(animationStyleName[stylenum]);
00075 }
00076
00077
00078 static char goto_doc[] = "goto(frame) -> None\nGo to frame on the next display update.";
00079 static PyObject *anim_goto(PyObject *self, PyObject *args) {
00080 int frame;
00081 if (!PyArg_ParseTuple(args, (char *)"i", &frame))
00082 return NULL;
00083
00084 VMDApp *app = get_vmdapp();
00085 app->animation_set_frame(frame);
00086
00087 Py_INCREF(Py_None);
00088 return Py_None;
00089 }
00090
00091
00092 static char reverse_doc[] = "reverse() -> None\nStart animating in reverse.";
00093 static PyObject *reverse(PyObject *self, PyObject *args) {
00094 if (!PyArg_ParseTuple(args, (char *)""))
00095 return NULL;
00096
00097 VMDApp *app = get_vmdapp();
00098 app->animation_set_dir(Animation::ANIM_REVERSE);
00099
00100 Py_INCREF(Py_None);
00101 return Py_None;
00102 }
00103
00104
00105 static char forward_doc[] = "forward() -> None\nStart animating forward.";
00106 static PyObject *forward(PyObject *self, PyObject *args) {
00107 if (!PyArg_ParseTuple(args, (char *)""))
00108 return NULL;
00109
00110 VMDApp *app = get_vmdapp();
00111 app->animation_set_dir(Animation::ANIM_FORWARD);
00112
00113 Py_INCREF(Py_None);
00114 return Py_None;
00115 }
00116
00117
00118 static char prev_doc[] = "prev() -> None\nAnimate to the previous frame and stop.";
00119 static PyObject *prev(PyObject *self, PyObject *args) {
00120 if (!PyArg_ParseTuple(args, (char *)""))
00121 return NULL;
00122
00123 VMDApp *app = get_vmdapp();
00124 app->animation_set_dir(Animation::ANIM_REVERSE1);
00125
00126 Py_INCREF(Py_None);
00127 return Py_None;
00128 }
00129
00130
00131 static char next_doc[] = "next() -> None\nAnimate to the next frame and stop.";
00132 static PyObject *next(PyObject *self, PyObject *args) {
00133 if (!PyArg_ParseTuple(args, (char *)""))
00134 return NULL;
00135
00136 VMDApp *app = get_vmdapp();
00137 app->animation_set_dir(Animation::ANIM_FORWARD1);
00138
00139 Py_INCREF(Py_None);
00140 return Py_None;
00141 }
00142
00143
00144 static char pause_doc[] = "pause() -> None\nPause the animation.";
00145 static PyObject *pause(PyObject *self, PyObject *args) {
00146 if (!PyArg_ParseTuple(args, (char *)""))
00147 return NULL;
00148
00149 VMDApp *app = get_vmdapp();
00150 app->animation_set_dir(Animation::ANIM_PAUSE);
00151
00152 Py_INCREF(Py_None);
00153 return Py_None;
00154 }
00155
00156
00157 static char speed_doc[] = "speed(value) -> current value\nSet animation speed; pass -1 to get current speed; returns new speed.";
00158 static PyObject *speed(PyObject *self, PyObject *args) {
00159 float value = -1.0f;
00160 if (!PyArg_ParseTuple(args, (char *)"|f",&value))
00161 return NULL;
00162
00163 VMDApp *app = get_vmdapp();
00164 if (value > 0) {
00165 app->animation_set_speed(value);
00166 }
00167
00168
00169 return PyFloat_FromDouble(app->anim->speed());
00170 }
00171
00172
00173 static char skip_doc[] = "skip(value) -> new value\nSet stride for animation frames; pass -1 to get current value only;\nreturns new value.";
00174 static PyObject *skip(PyObject *self, PyObject *args) {
00175 int value = 0;
00176 if (!PyArg_ParseTuple(args, (char *)"|i",&value))
00177 return NULL;
00178
00179 VMDApp *app = get_vmdapp();
00180 if (value > 0) {
00181 app->animation_set_stride(value);
00182 }
00183 return PyInt_FromLong(app->anim->skip());
00184 }
00185
00186
00187 static char is_active_doc[] = "is_active(molid) -> boolean\nIs given molecule active (animateable)?";
00188 static PyObject *is_active(PyObject *self, PyObject *args) {
00189 int molid;
00190 if (!PyArg_ParseTuple(args, (char *)"i", &molid))
00191 return NULL;
00192
00193 VMDApp *app = get_vmdapp();
00194 Molecule *mol = app->moleculeList->mol_from_id(molid);
00195 if (!mol) {
00196 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00197 return NULL;
00198 }
00199 return PyInt_FromLong(mol->active);
00200 }
00201
00202
00203 static char activate_doc[] = "activate(molid, bool) -> None\nActivate/inactivate the given molecule.";
00204 static PyObject *activate(PyObject *self, PyObject *args) {
00205 int molid;
00206 PyObject *boolobj;
00207 if (!PyArg_ParseTuple(args, (char *)"iO", &molid, &boolobj))
00208 return NULL;
00209
00210 VMDApp *app = get_vmdapp();
00211 Molecule *mol = app->moleculeList->mol_from_id(molid);
00212 if (!mol) {
00213 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00214 return NULL;
00215 }
00216 app->molecule_activate(molid, PyObject_IsTrue(boolobj));
00217
00218 Py_INCREF(Py_None);
00219 return Py_None;
00220 }
00221
00222 static PyMethodDef methods[] = {
00223 {(char *)"once", (vmdPyMethod)once, METH_VARARGS, once_doc},
00224 {(char *)"rock", (vmdPyMethod)rock, METH_VARARGS, rock_doc },
00225 {(char *)"loop", (vmdPyMethod)loop, METH_VARARGS, loop_doc },
00226 {(char *)"style", (vmdPyMethod)style, METH_VARARGS, style_doc },
00227 {(char *)"goto", (vmdPyMethod)anim_goto, METH_VARARGS, goto_doc },
00228 {(char *)"reverse", (vmdPyMethod)reverse, METH_VARARGS, reverse_doc },
00229 {(char *)"forward", (vmdPyMethod)forward, METH_VARARGS, forward_doc },
00230 {(char *)"prev", (vmdPyMethod)prev, METH_VARARGS, prev_doc },
00231 {(char *)"next", (vmdPyMethod)next, METH_VARARGS, next_doc },
00232 {(char *)"pause", (vmdPyMethod)pause, METH_VARARGS, pause_doc },
00233 {(char *)"speed", (vmdPyMethod)speed, METH_VARARGS, speed_doc },
00234 {(char *)"skip", (vmdPyMethod)skip, METH_VARARGS, skip_doc },
00235 {(char *)"is_active", (vmdPyMethod)is_active, METH_VARARGS, is_active_doc },
00236 {(char *)"activate", (vmdPyMethod)activate, METH_VARARGS, activate_doc },
00237 {NULL, NULL}
00238 };
00239
00240 void initanimate() {
00241 (void) Py_InitModule((char *)"animate", methods);
00242 }
00243
00244
00245
00246