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 "VMDApp.h"
00023
00024
00025 static PyObject *molrep_num(PyObject *self, PyObject *args) {
00026 int molid;
00027 if (!PyArg_ParseTuple(args, (char *)"i:molrep.num", &molid))
00028 return NULL;
00029
00030 VMDApp *app = get_vmdapp();
00031 if (!app->molecule_valid_id(molid)) {
00032 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00033 return NULL;
00034 }
00035 return PyInt_FromLong(app->num_molreps(molid));
00036 }
00037
00038
00039 static PyObject *addrep(PyObject *self, PyObject *args, PyObject *keywds) {
00040 int molid;
00041 char *style=NULL, *color=NULL, *selection=NULL, *material=NULL;
00042 static char *kwlist[] = {
00043 (char *)"molid", (char *)"style", (char *)"color", (char *)"selection",
00044 (char *)"material", NULL
00045 };
00046 if (!PyArg_ParseTupleAndKeywords(args, keywds,
00047 (char *)"i|ssss:molrep.addrep", kwlist,
00048 &molid, &style, &color, &selection, &material))
00049 return NULL;
00050
00051 VMDApp *app = get_vmdapp();
00052 if (!app->molecule_valid_id(molid)) {
00053 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00054 return NULL;
00055 }
00056 if (style && !app->molecule_set_style(style)) {
00057 PyErr_SetString(PyExc_ValueError, (char *)"Invalid style");
00058 return NULL;
00059 }
00060 if (color && !app->molecule_set_color(color)) {
00061 PyErr_SetString(PyExc_ValueError, (char *)"Invalid color");
00062 return NULL;
00063 }
00064 if (selection && !app->molecule_set_selection(selection)) {
00065 PyErr_SetString(PyExc_ValueError, (char *)"Invalid selection");
00066 return NULL;
00067 }
00068 if (material && !app->molecule_set_material(material)) {
00069 PyErr_SetString(PyExc_ValueError, (char *)"Invalid material");
00070 return NULL;
00071 }
00072 app->molecule_addrep(molid);
00073
00074 Py_INCREF(Py_None);
00075 return Py_None;
00076 }
00077
00078
00079 static PyObject *delrep(PyObject *self, PyObject *args) {
00080 int molid, rep;
00081 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.delrep", &molid, &rep))
00082 return NULL;
00083
00084 VMDApp *app = get_vmdapp();
00085 if (!app->molecule_valid_id(molid)) {
00086 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00087 return NULL;
00088 }
00089 if (rep < 0 || rep >= app->num_molreps(molid)) {
00090 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00091 return NULL;
00092 }
00093 app->molrep_delete(molid, rep);
00094
00095 Py_INCREF(Py_None);
00096 return Py_None;
00097 }
00098
00099
00100 static PyObject *get_style(PyObject *self, PyObject *args) {
00101 int molid, rep;
00102 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_style", &molid, &rep))
00103 return NULL;
00104
00105 VMDApp *app = get_vmdapp();
00106 if (!app->molecule_valid_id(molid)) {
00107 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00108 return NULL;
00109 }
00110 if (rep < 0 || rep >= app->num_molreps(molid)) {
00111 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00112 return NULL;
00113 }
00114 return PyString_FromString((char *)app->molrep_get_style(molid, rep));
00115 }
00116
00117
00118 static PyObject *get_selection(PyObject *self, PyObject *args) {
00119 int molid, rep;
00120 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_selection", &molid, &rep))
00121 return NULL;
00122
00123 VMDApp *app = get_vmdapp();
00124 if (!app->molecule_valid_id(molid)) {
00125 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00126 return NULL;
00127 }
00128 if (rep < 0 || rep >= app->num_molreps(molid)) {
00129 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00130 return NULL;
00131 }
00132 return PyString_FromString((char *)app->molrep_get_selection(molid, rep));
00133 }
00134
00135
00136 static PyObject *get_color(PyObject *self, PyObject *args) {
00137 int molid, rep;
00138 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_color", &molid, &rep))
00139 return NULL;
00140
00141 VMDApp *app = get_vmdapp();
00142 if (!app->molecule_valid_id(molid)) {
00143 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00144 return NULL;
00145 }
00146 if (rep < 0 || rep >= app->num_molreps(molid)) {
00147 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00148 return NULL;
00149 }
00150 return PyString_FromString((char *)app->molrep_get_color(molid, rep));
00151 }
00152
00153
00154 static PyObject *get_material(PyObject *self, PyObject *args) {
00155 int molid, rep;
00156 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_material", &molid, &rep))
00157 return NULL;
00158
00159 VMDApp *app = get_vmdapp();
00160 if (!app->molecule_valid_id(molid)) {
00161 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00162 return NULL;
00163 }
00164 if (rep < 0 || rep >= app->num_molreps(molid)) {
00165 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00166 return NULL;
00167 }
00168 return PyString_FromString((char *)app->molrep_get_material(molid, rep));
00169 }
00170
00171
00172 static PyObject *get_scaleminmax(PyObject *self, PyObject *args) {
00173 int molid, rep;
00174 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_scaleminmax", &molid, &rep))
00175 return NULL;
00176
00177 VMDApp *app = get_vmdapp();
00178 if (!app->molecule_valid_id(molid)) {
00179 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00180 return NULL;
00181 }
00182 if (rep < 0 || rep >= app->num_molreps(molid)) {
00183 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00184 return NULL;
00185 }
00186 float min, max;
00187 if (!app->molrep_get_scaleminmax(molid, rep, &min, &max)) {
00188 PyErr_SetString(PyExc_ValueError, (char *)"Unable to get color scale range for this rep");
00189 return NULL;
00190 }
00191 return Py_BuildValue((char *)"[f,f]", min, max);
00192 }
00193
00194
00195 static PyObject *set_scaleminmax(PyObject *self, PyObject *args) {
00196 int molid, rep;
00197 float min, max;
00198 if (!PyArg_ParseTuple(args, (char *)"iiff:molrep.set_scaleminmax", &molid,
00199 &rep, &min, &max))
00200 return NULL;
00201
00202 VMDApp *app = get_vmdapp();
00203 if (!app->molecule_valid_id(molid)) {
00204 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00205 return NULL;
00206 }
00207 if (rep < 0 || rep >= app->num_molreps(molid)) {
00208 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00209 return NULL;
00210 }
00211 if (!app->molrep_set_scaleminmax(molid, rep, min, max)) {
00212 PyErr_SetString(PyExc_ValueError, (char *)"Unable to get color scale range for this rep");
00213 return NULL;
00214 }
00215 Py_INCREF(Py_None);
00216 return Py_None;
00217 }
00218
00219
00220 static PyObject *reset_scaleminmax(PyObject *self, PyObject *args) {
00221 int molid, rep;
00222 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.auto_scaleminmax", &molid, &rep))
00223 return NULL;
00224
00225 VMDApp *app = get_vmdapp();
00226 if (!app->molecule_valid_id(molid)) {
00227 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00228 return NULL;
00229 }
00230 if (rep < 0 || rep >= app->num_molreps(molid)) {
00231 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00232 return NULL;
00233 }
00234 if (!app->molrep_reset_scaleminmax(molid, rep)) {
00235 PyErr_SetString(PyExc_ValueError, (char *)"Unable to reset color scale range for this rep");
00236 return NULL;
00237 }
00238 Py_INCREF(Py_None);
00239 return Py_None;
00240 }
00241
00242
00243
00244 static PyObject *modrep(PyObject *self, PyObject *args, PyObject *keywds) {
00245
00246 char *style=NULL, *sel=NULL, *color=NULL, *material=NULL;
00247 PyObject *scaleminmax = NULL;
00248 int molid, rep;
00249
00250 static char *kwlist[] = {
00251 (char *)"molid", (char *)"rep", (char *)"style", (char *)"sel",
00252 (char *)"color", (char *)"material", (char *)"scaleminmax", NULL
00253 };
00254
00255 if (!PyArg_ParseTupleAndKeywords(args, keywds, (char *)"ii|ssssO!:molrep.modrep", kwlist,
00256 &molid, &rep, &style, &sel, &color, &material, &PyList_Type, &scaleminmax))
00257 return NULL;
00258
00259 VMDApp *app = get_vmdapp();
00260 if (!app->molecule_valid_id(molid)) {
00261 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molecule id");
00262 return NULL;
00263 }
00264 if (rep < 0 || rep >= app->num_molreps(molid)) {
00265 PyErr_SetString(PyExc_ValueError, (char *)"Invalid rep number");
00266 return NULL;
00267 }
00268
00269 int rc = 1;
00270 if (style)
00271 rc &= app->molrep_set_style(molid, rep, style);
00272 if (sel)
00273 rc &= app->molrep_set_selection(molid, rep, sel);
00274 if (color)
00275 rc &= app->molrep_set_color(molid, rep, color);
00276 if (material)
00277 rc &= app->molrep_set_material(molid, rep, material);
00278 if (scaleminmax) {
00279 if (PyList_Size(scaleminmax) == 2) {
00280 float min = (float)PyFloat_AsDouble(PyList_GET_ITEM(scaleminmax, 0));
00281 float max = (float)PyFloat_AsDouble(PyList_GET_ITEM(scaleminmax, 1));
00282 if (PyErr_Occurred()) return NULL;
00283 rc &= app->molrep_set_scaleminmax(molid, rep, min, max);
00284 } else {
00285 PyErr_SetString(PyExc_ValueError, (char *)"scaleminmax must have two items");
00286 return NULL;
00287 }
00288 }
00289 return PyInt_FromLong(rc);
00290 }
00291
00292
00293 static PyObject *get_repname(PyObject *self, PyObject *args) {
00294 int molid, repid;
00295 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_repname", &molid, &repid))
00296 return NULL;
00297 VMDApp *app = get_vmdapp();
00298 const char *name = app->molrep_get_name(molid, repid);
00299 if (!name) {
00300 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00301 return NULL;
00302 }
00303 return PyString_FromString((char *)name);
00304 }
00305
00306
00307 static PyObject *repindex(PyObject *self, PyObject *args) {
00308 int molid;
00309 char *name;
00310 if (!PyArg_ParseTuple(args, (char *)"is:molrep.repindex", &molid, &name))
00311 return NULL;
00312 VMDApp *app = get_vmdapp();
00313 int repid = app->molrep_get_by_name(molid, name);
00314 return PyInt_FromLong(repid);
00315 }
00316
00317
00318 static PyObject *get_autoupdate(PyObject *self, PyObject *args) {
00319 int molid, repid;
00320 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_autoupdate", &molid, &repid))
00321 return NULL;
00322 VMDApp *app = get_vmdapp();
00323 const char *name = app->molrep_get_name(molid, repid);
00324 if (!name) {
00325 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00326 return NULL;
00327 }
00328 return PyInt_FromLong(app->molrep_get_selupdate(molid, repid));
00329 }
00330
00331
00332 static PyObject *set_autoupdate(PyObject *self, PyObject *args) {
00333 int molid, repid, onoff;
00334 if (!PyArg_ParseTuple(args, (char *)"iii:molrep.set_autoupdate", &molid, &repid, &onoff))
00335 return NULL;
00336 VMDApp *app = get_vmdapp();
00337 if (!app->molrep_set_selupdate(molid, repid, onoff)) {
00338 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00339 return NULL;
00340 }
00341 Py_INCREF(Py_None);
00342 return Py_None;
00343 }
00344
00345
00346 static PyObject *get_colorupdate(PyObject *self, PyObject *args) {
00347 int molid, repid;
00348 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_colorupdate", &molid, &repid))
00349 return NULL;
00350 VMDApp *app = get_vmdapp();
00351 const char *name = app->molrep_get_name(molid, repid);
00352 if (!name) {
00353 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00354 return NULL;
00355 }
00356 return PyInt_FromLong(app->molrep_get_colorupdate(molid, repid));
00357 }
00358
00359
00360 static PyObject *set_colorupdate(PyObject *self, PyObject *args) {
00361 int molid, repid, onoff;
00362 if (!PyArg_ParseTuple(args, (char *)"iii:molrep.set_colorupdate", &molid, &repid, &onoff))
00363 return NULL;
00364 VMDApp *app = get_vmdapp();
00365 if (!app->molrep_set_colorupdate(molid, repid, onoff)) {
00366 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00367 return NULL;
00368 }
00369 Py_INCREF(Py_None);
00370 return Py_None;
00371 }
00372
00373
00374 static PyObject *get_smoothing(PyObject *self, PyObject *args) {
00375 int molid, repid;
00376 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_smoothing", &molid, &repid))
00377 return NULL;
00378 VMDApp *app = get_vmdapp();
00379 const char *name = app->molrep_get_name(molid, repid);
00380 if (!name) {
00381 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00382 return NULL;
00383 }
00384 return PyInt_FromLong(app->molrep_get_smoothing(molid, repid));
00385 }
00386
00387
00388 static PyObject *set_smoothing(PyObject *self, PyObject *args) {
00389 int molid, repid, n;
00390 if (!PyArg_ParseTuple(args, (char *)"iii:molrep.set_smoothing", &molid, &repid, &n))
00391 return NULL;
00392 if (n < 0) {
00393 PyErr_SetString(PyExc_ValueError, (char *)"Smoothing window must be 0 or higher");
00394 return NULL;
00395 }
00396 VMDApp *app = get_vmdapp();
00397 if (!app->molrep_set_smoothing(molid, repid, n)) {
00398 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00399 return NULL;
00400 }
00401 Py_INCREF(Py_None);
00402 return Py_None;
00403 }
00404
00405
00406 static PyObject *get_visible(PyObject *self, PyObject *args) {
00407 int molid, repid;
00408 if (!PyArg_ParseTuple(args, (char *)"ii:molrep.get_visible", &molid, &repid))
00409 return NULL;
00410 VMDApp *app = get_vmdapp();
00411 const char *name = app->molrep_get_name(molid, repid);
00412 if (!name) {
00413 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00414 return NULL;
00415 }
00416 return PyInt_FromLong(app->molrep_is_shown(molid, repid));
00417 }
00418
00419
00420 static PyObject *set_visible(PyObject *self, PyObject *args) {
00421 int molid, repid, n;
00422 if (!PyArg_ParseTuple(args, (char *)"iii:molrep.set_visible", &molid, &repid, &n))
00423 return NULL;
00424 if (n < 0) {
00425 PyErr_SetString(PyExc_ValueError, (char *)"Smoothing window must be 0 or higher");
00426 return NULL;
00427 }
00428 VMDApp *app = get_vmdapp();
00429 if (!app->molrep_show(molid, repid, n)) {
00430 PyErr_SetString(PyExc_ValueError, (char *)"Invalid molid or repid");
00431 return NULL;
00432 }
00433 Py_INCREF(Py_None);
00434 return Py_None;
00435 }
00436
00437 static PyMethodDef methods[] = {
00438 {(char *)"num", (vmdPyMethod)molrep_num, METH_VARARGS},
00439 {(char *)"addrep", (PyCFunction)addrep, METH_VARARGS | METH_KEYWORDS},
00440 {(char *)"delrep", (vmdPyMethod)delrep, METH_VARARGS},
00441 {(char *)"get_style", (vmdPyMethod)get_style, METH_VARARGS},
00442 {(char *)"get_color", (vmdPyMethod)get_color, METH_VARARGS},
00443 {(char *)"get_selection", (vmdPyMethod)get_selection, METH_VARARGS},
00444 {(char *)"get_material", (vmdPyMethod)get_material, METH_VARARGS},
00445 {(char *)"modrep", (PyCFunction)modrep, METH_VARARGS | METH_KEYWORDS},
00446 {(char *)"get_repname", (vmdPyMethod)get_repname, METH_VARARGS},
00447 {(char *)"repindex", (vmdPyMethod)repindex, METH_VARARGS},
00448 {(char *)"get_autoupdate", (vmdPyMethod)get_autoupdate, METH_VARARGS},
00449 {(char *)"set_autoupdate", (vmdPyMethod)set_autoupdate, METH_VARARGS},
00450 {(char *)"get_scaleminmax", (vmdPyMethod)get_scaleminmax, METH_VARARGS},
00451 {(char *)"set_scaleminmax", (vmdPyMethod)set_scaleminmax, METH_VARARGS},
00452 {(char *)"reset_scaleminmax", (vmdPyMethod)reset_scaleminmax, METH_VARARGS},
00453 {(char *)"get_colorupdate", (vmdPyMethod)get_colorupdate, METH_VARARGS},
00454 {(char *)"set_colorupdate", (vmdPyMethod)set_colorupdate, METH_VARARGS},
00455 {(char *)"get_smoothing", (vmdPyMethod)get_smoothing, METH_VARARGS},
00456 {(char *)"set_smoothing", (vmdPyMethod)set_smoothing, METH_VARARGS},
00457 {(char *)"get_visible", (vmdPyMethod)get_visible, METH_VARARGS},
00458 {(char *)"set_visible", (vmdPyMethod)set_visible, METH_VARARGS},
00459 {NULL, NULL}
00460 };
00461
00462 void initmolrep() {
00463 (void) Py_InitModule((char *)"molrep", methods);
00464 }
00465