00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * RCS INFORMATION: 00011 * 00012 * $RCSfile: py_molrep.C,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.32 $ $Date: 2019年05月31日 03:29:51 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * Python interface for managing graphical representations 00019 ***************************************************************************/ 00020 00021 #include "py_commands.h" 00022 #include "VMDApp.h" 00023 00024 // Helper function to check if a representation is valid 00025 static int valid_rep(int rep, int molid, VMDApp *app) { 00026 if (rep < 0 || rep >= app->num_molreps(molid)) { 00027 PyErr_Format(PyExc_ValueError, "Invalid rep number '%d", rep); 00028 return 0; 00029 } 00030 return 1; 00031 } 00032 00033 00034 static const char num_doc[] = 00035 "Get number of representations present for molecule\n\n" 00036 "Args:\n" 00037 " molid (int): Molecule ID to query\n" 00038 "Returns:\n" 00039 " (int): Number of representation"; 00040 static PyObject* py_molrep_num(PyObject *self, PyObject *args, PyObject *kwargs) { 00041 const char *kwlist[] = {"molid", NULL}; 00042 int molid; 00043 00044 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:molrep.num", 00045 (char**) kwlist, &molid)) 00046 return NULL; 00047 00048 VMDApp *app; 00049 if (!(app = get_vmdapp())) 00050 return NULL; 00051 00052 if (!valid_molid(molid, app)) 00053 return NULL; 00054 00055 return as_pyint(app->num_molreps(molid)); 00056 } 00057 00058 00059 static const char addrep_doc[] = 00060 "Add a representation to the molecule. If optional arguments are not\n" 00061 "specified, they default to whatever the previously added representation has.\n" 00062 "Args:\n" 00063 " molid (int): Molecule ID to add represenation to\n" 00064 " style (str): Representation style (like 'NewCartoon'), optional\n" 00065 " color (str): Coloring method (like 'ColorID 1' or 'Type'), optional\n" 00066 " selection (str): Atoms to apply representation to, optional\n" 00067 " material (str): Material for represenation (like 'Opaque')\n" 00068 "Returns:\n" 00069 " (int): Index of added representation"; 00070 static PyObject *py_addrep(PyObject *self, PyObject *args, PyObject *kwargs) { 00071 const char *kwlist[] = {"molid", "style", "color", "selection", "material", 00072 NULL}; 00073 char *style = NULL, *color = NULL, *selection = NULL, *material = NULL; 00074 int molid; 00075 00076 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|zzzz:molrep.addrep", 00077 (char**) kwlist, &molid, &style, &color, 00078 &selection, &material)) 00079 return NULL; 00080 00081 VMDApp *app; 00082 if (!(app = get_vmdapp())) 00083 return NULL; 00084 00085 if (!valid_molid(molid, app)) 00086 return NULL; 00087 00088 if (style && !app->molecule_set_style(style)) { 00089 PyErr_Format(PyExc_ValueError, "Invalid style '%s'", style); 00090 return NULL; 00091 } 00092 00093 if (color && !app->molecule_set_color(color)) { 00094 PyErr_Format(PyExc_ValueError, "Invalid color '%s'", color); 00095 return NULL; 00096 } 00097 00098 if (selection && !app->molecule_set_selection(selection)) { 00099 PyErr_Format(PyExc_ValueError, "Invalid selection '%s'", selection); 00100 return NULL; 00101 } 00102 00103 if (material && !app->molecule_set_material(material)) { 00104 PyErr_Format(PyExc_ValueError, "Invalid material '%s'", material); 00105 return NULL; 00106 } 00107 00108 if (!(app->molecule_addrep(molid))) { 00109 PyErr_SetString(PyExc_RuntimeError, "Could not add representation"); 00110 return NULL; 00111 } 00112 00113 return as_pyint(app->num_molreps(molid) - 1); 00114 } 00115 00116 00117 static const char delrep_doc[] = 00118 "Delete a representation\n\n" 00119 "Args:\n" 00120 " molid (int): Molecule ID to delete representation from\n" 00121 " rep (int): Representation index to delete\n"; 00122 static PyObject *py_delrep(PyObject *self, PyObject *args, PyObject *kwargs) { 00123 const char *kwlist[] = {"molid", "rep", NULL}; 00124 int molid, rep; 00125 00126 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.delrep", 00127 (char**) kwlist, &molid, &rep)) 00128 return NULL; 00129 00130 VMDApp *app; 00131 if (!(app = get_vmdapp())) 00132 return NULL; 00133 00134 if (!valid_molid(molid, app)) 00135 return NULL; 00136 00137 if (!valid_rep(rep, molid, app)) 00138 return NULL; 00139 00140 app->molrep_delete(molid, rep); 00141 00142 Py_INCREF(Py_None); 00143 return Py_None; 00144 } 00145 00146 00147 static const char style_doc[] = 00148 "Get the style associated with a representation\n\n" 00149 "Args:\n" 00150 " molid (int): Molecule ID with representation\n" 00151 " rep (int): Representation index to query\n" 00152 "Returns:\n" 00153 " (str): Representation style, like 'NewCartoon'"; 00154 static PyObject *py_get_style(PyObject *self, PyObject *args, PyObject *kwargs) { 00155 const char *kwlist[] = {"molid", "rep", NULL}; 00156 int molid, rep; 00157 00158 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_style", 00159 (char**) kwlist, &molid, &rep)) 00160 return NULL; 00161 00162 VMDApp *app; 00163 if (!(app = get_vmdapp())) 00164 return NULL; 00165 00166 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00167 return NULL; 00168 00169 return as_pystring(app->molrep_get_style(molid, rep)); 00170 } 00171 00172 00173 static const char select_doc[] = 00174 "Get the atom selection associated with a representation\n\n" 00175 "Args:\n" 00176 " molid (int): Molecule ID with representation\n" 00177 " rep (int): Representation index to query\n" 00178 "Returns:\n" 00179 " (str): Atom selection"; 00180 static PyObject *py_get_selection(PyObject *self, PyObject *args, 00181 PyObject *kwargs) { 00182 const char *kwlist[] = {"molid", "rep", NULL}; 00183 int molid, rep; 00184 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_selection", 00185 (char**) kwlist, &molid, &rep)) 00186 return NULL; 00187 00188 VMDApp *app; 00189 if (!(app = get_vmdapp())) 00190 return NULL; 00191 00192 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00193 return NULL; 00194 00195 return as_pystring(app->molrep_get_selection(molid, rep)); 00196 } 00197 00198 00199 static const char color_doc[] = 00200 "Get the coloring scheme associated with a representation\n\n" 00201 "Args:\n" 00202 " molid (int): Molecule ID with representation\n" 00203 " rep (int): Representation index to query\n" 00204 "Returns:\n" 00205 " (str): Coloring scheme, like 'Type' or 'ColorID 5'"; 00206 static PyObject *py_get_color(PyObject *self, PyObject *args, PyObject *kwargs) { 00207 const char *kwlist[] = {"molid", "rep", NULL}; 00208 int molid, rep; 00209 00210 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_color", 00211 (char**) kwlist, &molid, &rep)) 00212 return NULL; 00213 00214 VMDApp *app; 00215 if (!(app = get_vmdapp())) 00216 return NULL; 00217 00218 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00219 return NULL; 00220 00221 return as_pystring(app->molrep_get_color(molid, rep)); 00222 } 00223 00224 00225 static const char material_doc[] = 00226 "Get the material associated with a representation\n\n" 00227 "Args:\n" 00228 " molid (int): Molecule ID with representation\n" 00229 " rep (int): Representation index to query\n" 00230 "Returns:\n" 00231 " (str): Material used, like 'Opaque'"; 00232 static PyObject *py_get_material(PyObject *self, PyObject *args, 00233 PyObject *kwargs) { 00234 const char *kwlist[] = {"molid", "rep", NULL}; 00235 int molid, rep; 00236 00237 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_material", 00238 (char**) kwlist, &molid, &rep)) 00239 return NULL; 00240 00241 VMDApp *app; 00242 if (!(app = get_vmdapp())) 00243 return NULL; 00244 00245 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00246 return NULL; 00247 00248 return as_pystring(app->molrep_get_material(molid, rep)); 00249 } 00250 00251 00252 static const char get_scale_doc[] = 00253 "Get the minimum and maximum color scale values for a representation\n\n" 00254 "Args:\n" 00255 " molid (int): Molecule ID with representation\n" 00256 " rep (int): Representation index to query\n" 00257 "Returns:\n" 00258 " (2-tuple of float): (min, max) color scale values"; 00259 static PyObject *py_get_scaleminmax(PyObject *self, PyObject *args, 00260 PyObject *kwargs) { 00261 const char *kwlist[] = {"molid", "rep", NULL}; 00262 int molid, rep; 00263 float min, max; 00264 00265 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_scaleminmax", 00266 (char**) kwlist, &molid, &rep)) 00267 return NULL; 00268 00269 VMDApp *app; 00270 if (!(app = get_vmdapp())) 00271 return NULL; 00272 00273 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00274 return NULL; 00275 00276 if (!app->molrep_get_scaleminmax(molid, rep, &min, &max)) { 00277 PyErr_Format(PyExc_ValueError, "Unable to get color scale range for " 00278 "molid '%d' representation '%d'", molid, rep); 00279 return NULL; 00280 } 00281 return Py_BuildValue("(f,f)", min, max); 00282 } 00283 00284 00285 static const char set_scale_doc[] = 00286 "Set the minimum and maximum color scale values for a representation\n\n" 00287 "Args:\n" 00288 " molid (int): Molecule ID with representation\n" 00289 " rep (int): Representation index to modify\n" 00290 " scale_min (float): Minimum scale value\n" 00291 " scale_max (float): Maximum scale value"; 00292 static PyObject *py_set_scaleminmax(PyObject *self, PyObject *args, 00293 PyObject *kwargs) { 00294 const char *kwlist[] = {"molid", "rep", "scale_min", "scale_max", NULL}; 00295 int molid, rep; 00296 float min, max; 00297 00298 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iiff:molrep.set_scaleminmax", 00299 (char**) kwlist, &molid, &rep, &min, &max)) 00300 return NULL; 00301 00302 VMDApp *app; 00303 if (!(app = get_vmdapp())) 00304 return NULL; 00305 00306 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00307 return NULL; 00308 00309 if (!app->molrep_set_scaleminmax(molid, rep, min, max)) { 00310 PyErr_Format(PyExc_RuntimeError, "Unable to set color scale range for " 00311 "molid '%d' representation '%d'", molid, rep); 00312 return NULL; 00313 } 00314 00315 Py_INCREF(Py_None); 00316 return Py_None; 00317 } 00318 00319 00320 static const char reset_doc[] = 00321 "Automatically set the color scale minimum and maximum values to span the\n" 00322 "input data\n\n" 00323 "Args:\n" 00324 " molid (int): Molecule ID with representation\n" 00325 " rep (int): Representation index to modify"; 00326 static PyObject *py_reset_scaleminmax(PyObject *self, PyObject *args, 00327 PyObject *kwargs) { 00328 const char *kwlist[] = {"molid", "rep", NULL}; 00329 int molid, rep; 00330 00331 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.reset_scaleminmax", 00332 (char**) kwlist, &molid, &rep)) 00333 return NULL; 00334 00335 VMDApp *app; 00336 if (!(app = get_vmdapp())) 00337 return NULL; 00338 00339 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00340 return NULL; 00341 00342 if (!app->molrep_reset_scaleminmax(molid, rep)) { 00343 PyErr_Format(PyExc_ValueError, "Unable to reset color scale range for " 00344 "molid '%d' representation '%d'", molid, rep); 00345 return NULL; 00346 } 00347 00348 Py_INCREF(Py_None); 00349 return Py_None; 00350 } 00351 00352 00353 static const char modrep_doc[] = 00354 "Modify properties of a representation. Any number of optional arguments may\n" 00355 "be specified.\n\n" 00356 "Args:\n" 00357 " molid (int): Molecule ID with representation\n" 00358 " rep (int): Representation index to modify\n" 00359 " style (str): Representation style (like 'NewCartoon'), optional\n" 00360 " color (str): Coloring method (like 'ColorID 1' or 'Type'), optional\n" 00361 " selection (str): Atoms to apply representation to, optional\n" 00362 " material (str): Material for represenation (like 'Opaque')\n" 00363 " scaleminmax (2-tuple or list of float): (min, max) values for color scale\n" 00364 "Returns:\n" 00365 " (bool): If modification(s) were successful"; 00366 static PyObject *py_modrep(PyObject *self, PyObject *args, PyObject *kwargs) { 00367 const char *kwlist[] = {"molid", "rep", "style", "selection", "color", 00368 "material", "scaleminmax", NULL}; 00369 char *style = NULL, *sel = NULL, *color = NULL, *material = NULL; 00370 float min = -1.f, max = -1.f; 00371 PyObject *ret; 00372 int molid, rep; 00373 00374 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|zzzz(ff):molrep.modrep", 00375 (char**) kwlist, &molid, &rep, &style, &sel, 00376 &color, &material, &min, &max)) 00377 return NULL; 00378 00379 VMDApp *app; 00380 if (!(app = get_vmdapp())) 00381 return NULL; 00382 00383 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00384 return NULL; 00385 00386 int rc = 1; 00387 if (style) 00388 rc &= app->molrep_set_style(molid, rep, style); 00389 00390 if (sel) 00391 rc &= app->molrep_set_selection(molid, rep, sel); 00392 00393 if (color) 00394 rc &= app->molrep_set_color(molid, rep, color); 00395 00396 if (material) 00397 rc &= app->molrep_set_material(molid, rep, material); 00398 00399 if (min != -1 && max != -1) { 00400 rc &= app->molrep_set_scaleminmax(molid, rep, min, max); 00401 } 00402 00403 ret = rc ? Py_True : Py_False; 00404 Py_INCREF(ret); 00405 return ret; 00406 } 00407 00408 static const char repname_doc[] = 00409 "Get the name of a representation\n\n" 00410 "Args:\n" 00411 " molid (int): Molecule ID with representation\n" 00412 " rep (int): Representation index to query\n" 00413 "Returns:\n" 00414 " (str): Representation name"; 00415 static PyObject *py_get_repname(PyObject *self, PyObject *args, 00416 PyObject *kwargs) { 00417 const char *kwlist[] = {"molid", "rep", NULL}; 00418 int molid, rep; 00419 const char *name; 00420 00421 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_repname", 00422 (char**) kwlist, &molid, &rep)) 00423 return NULL; 00424 00425 VMDApp *app; 00426 if (!(app = get_vmdapp())) 00427 return NULL; 00428 00429 if (!valid_molid(molid, app) || !valid_rep(rep, molid, app)) 00430 return NULL; 00431 00432 name = app->molrep_get_name(molid, rep); 00433 if (!name) { 00434 PyErr_Format(PyExc_ValueError, "Could not get name for molid '%d' rep '%d'", 00435 molid, rep); 00436 return NULL; 00437 } 00438 00439 return as_pystring(name); 00440 } 00441 00442 00443 static const char repindex_doc[] = 00444 "Get the index of a representation from its name\n\n" 00445 "Args:\n" 00446 " molid (int): Molecule ID with representation\n" 00447 " name (str): Representation name\n" 00448 "Returns:\n" 00449 " (int): Representation index, or None if no such representation"; 00450 static PyObject* py_repindex(PyObject *self, PyObject *args, PyObject *kwargs) { 00451 const char *kwlist[] = {"molid", "name", NULL}; 00452 int molid, repid; 00453 char *name; 00454 00455 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is:molrep.repindex", 00456 (char**) kwlist, &molid, &name)) 00457 return NULL; 00458 00459 VMDApp *app; 00460 if (!(app = get_vmdapp())) 00461 return NULL; 00462 00463 if (!valid_molid(molid, app)) 00464 return NULL; 00465 00466 repid = app->molrep_get_by_name(molid, name); 00467 00468 // Return None if representation doesn't exist 00469 if (repid == -1) { 00470 Py_INCREF(Py_None); 00471 return Py_None; 00472 } 00473 00474 return as_pyint(repid); 00475 } 00476 00477 00478 static const char autoupdate_doc[] = 00479 "Get if representation automatically updates its atom selection\n\n" 00480 "Args:\n" 00481 " molid (int): Molecule ID with representation\n" 00482 " rep (int): Representation index to query\n" 00483 "Returns:\n" 00484 " (bool): Status of autoupdate"; 00485 static PyObject* py_get_autoupdate(PyObject *self, PyObject *args, 00486 PyObject *kwargs) { 00487 const char *kwlist[] = {"molid", "rep", NULL}; 00488 int molid, repid; 00489 PyObject *result; 00490 00491 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_autoupdate", 00492 (char**) kwlist, &molid, &repid)) 00493 return NULL; 00494 00495 VMDApp *app; 00496 if (!(app = get_vmdapp())) 00497 return NULL; 00498 00499 if (!valid_molid(molid, app) || !valid_rep(repid, molid, app)) 00500 return NULL; 00501 00502 result = app->molrep_get_selupdate(molid, repid) ? Py_True : Py_False; 00503 00504 Py_INCREF(result); 00505 return result; 00506 } 00507 00508 00509 static const char set_autoupdate_doc[] = 00510 "Set if the representation should automatically update its atom selection\n" 00511 "when the frame is changed. Useful for selections like 'within'\n\n" 00512 "Args:\n" 00513 " molid (int): Molecule ID with representation\n" 00514 " rep (int): Representation index to query\n" 00515 " autoupdate (bool): Whether or not autoupdate is on"; 00516 static PyObject *py_set_autoupdate(PyObject *self, PyObject *args, 00517 PyObject *kwargs) { 00518 const char *kwlist[] = {"molid", "rep", "autoupdate", NULL}; 00519 int molid, repid, onoff; 00520 00521 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iiO&:molrep.set_autoupdate", 00522 (char**) kwlist, &molid, &repid, 00523 convert_bool, &onoff)) 00524 return NULL; 00525 00526 VMDApp *app; 00527 if (!(app = get_vmdapp())) 00528 return NULL; 00529 00530 if (!valid_molid(molid, app) || !valid_rep(repid, molid, app)) 00531 return NULL; 00532 00533 if (!app->molrep_set_selupdate(molid, repid, onoff)) { 00534 PyErr_Format(PyExc_ValueError, "Cannot set selection update molid '%d'" 00535 " rep '%d'", molid, repid); 00536 return NULL; 00537 } 00538 00539 Py_INCREF(Py_None); 00540 return Py_None; 00541 } 00542 00543 00544 static const char cupdate_doc[] = 00545 "Query if the representations color automatically updates\n\n" 00546 "Args:\n" 00547 " molid (int): Molecule ID with representation\n" 00548 " rep (int): Representation index to query\n" 00549 "Returns:\n" 00550 " (bool): If colorupdate is set"; 00551 static PyObject* py_get_colorupdate(PyObject *self, PyObject *args, 00552 PyObject *kwargs) { 00553 const char *kwlist[] = {"molid", "rep", NULL}; 00554 int molid, repid; 00555 PyObject *retval; 00556 00557 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_colorupdate", 00558 (char**) kwlist, &molid, &repid)) 00559 return NULL; 00560 00561 VMDApp *app; 00562 if (!(app = get_vmdapp())) 00563 return NULL; 00564 00565 if (!valid_molid(molid, app) || !valid_rep(repid, molid, app)) 00566 return NULL; 00567 00568 retval = app->molrep_get_colorupdate(molid, repid) ? Py_True : Py_False; 00569 Py_INCREF(retval); 00570 00571 return retval; 00572 } 00573 00574 00575 static const char set_cupdate_doc[] = 00576 "Sets if the representation's color should automatically update when the\n" 00577 "frame is changed. Useful for distance based coloring, etc.\n\n" 00578 "Args:\n" 00579 " molid (int): Molecule ID with representation\n" 00580 " rep (int): Representation index to query\n" 00581 " autoupdate (bool): If color should automatically update"; 00582 static PyObject* py_set_colorupdate(PyObject *self, PyObject *args, 00583 PyObject *kwargs) { 00584 const char *kwlist[] = {"molid", "rep", "autoupdate", NULL}; 00585 int molid, repid, onoff; 00586 00587 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iiO&:molrep.set_colorupdate", 00588 (char**) kwlist, &molid, &repid, 00589 convert_bool, &onoff)) 00590 return NULL; 00591 00592 VMDApp *app; 00593 if (!(app = get_vmdapp())) 00594 return NULL; 00595 00596 if (!valid_molid(molid, app) || !valid_rep(repid, molid, app)) 00597 return NULL; 00598 00599 if (!app->molrep_set_colorupdate(molid, repid, onoff)) { 00600 PyErr_Format(PyExc_ValueError, "Cannot set color update molid '%d' rep '%d'", 00601 molid, repid); 00602 return NULL; 00603 } 00604 00605 Py_INCREF(Py_None); 00606 return Py_None; 00607 } 00608 00609 00610 static const char get_smooth_doc[] = 00611 "Get the number of frames over which a representation is smoothed\n\n" 00612 "Args:\n" 00613 " molid (int): Molecule ID with representation\n" 00614 " rep (int): Representation index to query\n" 00615 "Returns:\n" 00616 " (int): Number of frames representation is smoothed over"; 00617 static PyObject* py_get_smoothing(PyObject *self, PyObject *args, 00618 PyObject *kwargs) { 00619 const char *kwlist[] = {"molid", "rep", NULL}; 00620 int molid, repid; 00621 00622 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_smoothing", 00623 (char**) kwlist, &molid, &repid)) 00624 return NULL; 00625 00626 VMDApp *app; 00627 if (!(app = get_vmdapp())) 00628 return NULL; 00629 00630 if (!valid_molid(molid, app) || !valid_rep(repid, molid, app)) 00631 return NULL; 00632 00633 return as_pyint(app->molrep_get_smoothing(molid, repid)); 00634 } 00635 00636 00637 static const char set_smooth_doc[] = 00638 "Sets the number of frames over which a representation is smoothed\n\n" 00639 "Args:\n" 00640 " molid (int): Molecule ID with representation\n" 00641 " rep (int): Representation index to query\n" 00642 " smoothing (int): Smoothing window"; 00643 static PyObject* py_set_smoothing(PyObject *self, PyObject *args, 00644 PyObject *kwargs) { 00645 const char *kwlist[] = {"molid", "rep", "smoothing", NULL}; 00646 int molid, repid, n; 00647 00648 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii:molrep.set_smoothing", 00649 (char**) kwlist, &molid, &repid, &n)) 00650 return NULL; 00651 00652 if (n < 0) { 00653 PyErr_Format(PyExc_ValueError, "Smoothing window must be 0 or higher." 00654 " Got %d", n); 00655 return NULL; 00656 } 00657 00658 VMDApp *app; 00659 if (!(app = get_vmdapp())) 00660 return NULL; 00661 00662 if (!valid_molid(molid, app) || !valid_rep(repid, molid, app)) 00663 return NULL; 00664 00665 app->molrep_set_smoothing(molid, repid, n); 00666 Py_INCREF(Py_None); 00667 return Py_None; 00668 } 00669 00670 00671 static const char visible_doc[] = 00672 "Query if a representation is visible\n\n" 00673 "Args:\n" 00674 " molid (int): Molecule ID with representation\n" 00675 " rep (int): Representation index to query\n" 00676 "Returns:\n" 00677 " (bool): If representation is visible"; 00678 static PyObject* py_get_visible(PyObject *self, PyObject *args, 00679 PyObject *kwargs) { 00680 const char *kwlist[] = {"molid", "rep", NULL}; 00681 int molid, repid; 00682 PyObject *retval; 00683 00684 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:molrep.get_visible", 00685 (char**) kwlist, &molid, &repid)) 00686 return NULL; 00687 00688 VMDApp *app; 00689 if (!(app = get_vmdapp())) 00690 return NULL; 00691 00692 if (!valid_molid(molid, app) || !valid_rep(repid, molid, app)) 00693 return NULL; 00694 00695 retval = app->molrep_is_shown(molid, repid) ? Py_True : Py_False; 00696 Py_INCREF(retval); 00697 return retval; 00698 } 00699 00700 00701 static const char set_visible_doc[] = 00702 "Set if a representation is visible\n\n" 00703 "Args:\n" 00704 " molid (int): Molecule ID with representation\n" 00705 " rep (int): Representation index to query\n" 00706 " visible (bool): If representation should be displayed"; 00707 static PyObject* py_set_visible(PyObject *self, PyObject *args, 00708 PyObject *kwargs) { 00709 const char *kwlist[] = {"molid", "rep", "visible", NULL}; 00710 int molid, repid, n; 00711 00712 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iiO&:molrep.set_visible", 00713 (char**) kwlist, &molid, &repid, 00714 convert_bool, &n)) 00715 return NULL; 00716 00717 VMDApp *app; 00718 if (!(app = get_vmdapp())) 00719 return NULL; 00720 00721 if (!valid_molid(molid, app) || !valid_rep(repid, molid, app)) 00722 return NULL; 00723 00724 app->molrep_show(molid, repid, n); 00725 Py_INCREF(Py_None); 00726 return Py_None; 00727 } 00728 00729 00730 static PyMethodDef methods[] = { 00731 {"num", (PyCFunction)py_molrep_num, METH_VARARGS | METH_KEYWORDS, num_doc}, 00732 {"addrep", (PyCFunction)py_addrep, METH_VARARGS | METH_KEYWORDS, addrep_doc}, 00733 {"delrep", (PyCFunction)py_delrep, METH_VARARGS | METH_KEYWORDS, delrep_doc}, 00734 {"get_style", (PyCFunction)py_get_style, METH_VARARGS | METH_KEYWORDS, style_doc}, 00735 {"get_color", (PyCFunction)py_get_color, METH_VARARGS | METH_KEYWORDS, color_doc}, 00736 {"get_selection", (PyCFunction)py_get_selection, METH_VARARGS | METH_KEYWORDS, select_doc}, 00737 {"get_material", (PyCFunction)py_get_material, METH_VARARGS | METH_KEYWORDS, material_doc}, 00738 {"modrep", (PyCFunction)py_modrep, METH_VARARGS | METH_KEYWORDS, modrep_doc}, 00739 {"get_repname", (PyCFunction)py_get_repname, METH_VARARGS | METH_KEYWORDS, repname_doc}, 00740 {"repindex", (PyCFunction)py_repindex, METH_VARARGS | METH_KEYWORDS, repindex_doc}, 00741 {"get_autoupdate", (PyCFunction)py_get_autoupdate, METH_VARARGS | METH_KEYWORDS, autoupdate_doc}, 00742 {"set_autoupdate", (PyCFunction)py_set_autoupdate, METH_VARARGS | METH_KEYWORDS, set_autoupdate_doc}, 00743 {"get_scaleminmax", (PyCFunction)py_get_scaleminmax, METH_VARARGS | METH_KEYWORDS, get_scale_doc}, 00744 {"set_scaleminmax", (PyCFunction)py_set_scaleminmax, METH_VARARGS | METH_KEYWORDS, set_scale_doc}, 00745 {"reset_scaleminmax", (PyCFunction)py_reset_scaleminmax, METH_VARARGS | METH_KEYWORDS, reset_doc}, 00746 {"get_colorupdate", (PyCFunction)py_get_colorupdate, METH_VARARGS | METH_KEYWORDS, cupdate_doc}, 00747 {"set_colorupdate", (PyCFunction)py_set_colorupdate, METH_VARARGS | METH_KEYWORDS, set_cupdate_doc}, 00748 {"get_smoothing", (PyCFunction)py_get_smoothing, METH_VARARGS | METH_KEYWORDS, get_smooth_doc}, 00749 {"set_smoothing", (PyCFunction)py_set_smoothing, METH_VARARGS | METH_KEYWORDS, set_smooth_doc}, 00750 {"get_visible", (PyCFunction)py_get_visible, METH_VARARGS | METH_KEYWORDS, visible_doc}, 00751 {"set_visible", (PyCFunction)py_set_visible, METH_VARARGS | METH_KEYWORDS, set_visible_doc}, 00752 {NULL, NULL} 00753 }; 00754 00755 00756 static const char rep_moddoc[] = 00757 "Methods for controlling graphical representations associated with a molecule"; 00758 00759 00760 #if PY_MAJOR_VERSION >= 3 00761 static struct PyModuleDef molrepdef = { 00762 PyModuleDef_HEAD_INIT, 00763 "molrep", 00764 rep_moddoc, 00765 -1, 00766 methods, 00767 }; 00768 #endif 00769 00770 00771 PyObject* initmolrep(void) { 00772 #if PY_MAJOR_VERSION >= 3 00773 PyObject *m = PyModule_Create(&molrepdef); 00774 #else 00775 PyObject *m= Py_InitModule3("molrep", methods, rep_moddoc); 00776 #endif 00777 00778 return m; 00779 } 00780