Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

py_vmd.C

Go to the documentation of this file.
00001 
00002 #include "py_commands.h"
00003 #include "vmd.h"
00004 #include "DisplayDevice.h"
00005 
00006 extern "C" {
00007   void initvmd();
00008 }
00009 
00010 static PyObject *py_vmdupdate(PyObject *self, PyObject *args) {
00011   VMDApp *app = get_vmdapp();
00012   if (!app) {
00013     fprintf(stderr, "no app!!\n");
00014     Py_INCREF(Py_None);
00015     return Py_None; 
00016   }
00017   return Py_BuildValue("i", app->VMDupdate(1));
00018 }
00019 
00020 static PyObject *py_vmdexit(PyObject *self, PyObject *args) {
00021   char *msg;
00022   int code = 0;
00023   int pauseseconds = 0;
00024   if (!PyArg_ParseTuple(args, "s|ii", &msg, &code, &pauseseconds))
00025     return NULL;
00026   VMDApp *app = get_vmdapp();
00027   app->VMDexit(msg, code, pauseseconds);
00028   // don't call VMDshutdown, because calling Tcl_Finalize() crashes Tkinter
00029   // Maybe add a callback to the Python atexit module?
00030   Py_INCREF(Py_None);
00031   return Py_None; 
00032 }
00033 
00034 static PyMethodDef VMDAppMethods [] = {
00035     { (char *)"VMDupdate", py_vmdupdate, METH_VARARGS },
00036     { (char *)"VMDexit", py_vmdexit, METH_VARARGS },
00037     { NULL, NULL }
00038 };
00039 
00040 void initvmd() {
00041   // If there's already a VMDapp in get_vmdapp, then we must be running
00042   // inside a standalone VMD instead of being loaded as a python extension.
00043   // Don't throw an error - just treat it as a no-op for interoperability
00044   // in case vmd.so is in the PYTHONPATH of the standalone application.
00045   if (get_vmdapp() != NULL) {
00046     static PyMethodDef NullMethods[] = {
00047       { NULL, NULL }
00048     };
00049     (void)Py_InitModule((char *)"vmd", NullMethods);
00050     return;
00051   }
00052 
00053   int argc=1;
00054   char *argv[1];
00055   argv[0] = Py_GetProgramFullPath();
00056   if (!VMDinitialize(&argc, argv)) {
00057     return;
00058   }
00059 
00060   const char *disp = "text";
00061 
00062   int loc[2] = { 50, 50 };
00063   int size[2] = { 400, 400 };
00064   VMDgetDisplayFrame(loc, size);
00065 
00066   VMDApp *app = new VMDApp(1, argv);
00067   app->VMDinit(1, argv, disp, loc, size);
00068 
00069   // read application defaults
00070   VMDreadInit(app);
00071 
00072   // read user-defined startup files
00073   VMDreadStartup(app);
00074 
00075   set_vmdapp(app);
00076 
00077   PyObject *vmdmodule = Py_InitModule((char *)"vmd", VMDAppMethods);
00078 
00079   initanimate();
00080   initatomsel();
00081   initaxes();
00082   initcolor();
00083   initdisplay();
00084   initgraphics();
00085   initimd();
00086   initlabel();
00087   initmaterial();
00088   initmolecule();
00089   initmolrep();
00090   initmouse();
00091   initrender();
00092   inittrans();
00093   initvmdmenu();
00094 
00095 #ifdef VMDNUMPY
00096   initvmdnumpy();
00097 #endif
00098 
00099   if (PyErr_Occurred()) return;
00100 
00101   static const char *modules[] = {
00102     "animate", "atomsel", "axes", "color", "display", "graphics",
00103     "imd", "label", "material", "molecule", "molrep", "mouse", 
00104     "render", "trans", "vmdmenu", "vmdnumpy"
00105   };
00106   for (unsigned i=0; i<sizeof(modules)/sizeof(const char *); i++) {
00107     const char *m = modules[i];
00108 #if (PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION < 5)
00109 #define CAST_HACK (char *)
00110 #else 
00111 #define CAST_HACK
00112 #endif
00113     PyModule_AddObject(vmdmodule, CAST_HACK m, PyImport_ImportModule( CAST_HACK m));
00114   }
00115 }
00116 

Generated on Mon Oct 6 01:26:31 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002