Пример #1
0
void initvmd() {
  // Assume that VMD should not initialize or use MPI
  // It is conceivable we would want to be able to load the VMD
  // Python module into a MPI-based Python run, and enable the 
  // MPI features of VMD, but we'll have to determine the best way
  // to detect this and it will need to be tested since we may have
  // to handle this case differently than the normal MPI case where
  // VMD explicitly does MPI initialization and shutdown itself. 
  int mpienabled = 0;

  // If there's already a VMDapp in get_vmdapp, then we must be running
  // inside a standalone VMD instead of being loaded as a python extension.
  // Don't throw an error - just load the methods for interoperability
  // in case vmd.so is in the PYTHONPATH of the standalone application.
  if (get_vmdapp() != NULL) {
    (void)Py_InitModule((char *)"vmd", VMDAppMethods);
    return;
  }

  int argc=1;
  char *argv[1];
  argv[0] = Py_GetProgramFullPath();
  if (!VMDinitialize(&argc, (char ***) &argv, mpienabled)) {
    return;
  }

  // XXX this is a hack, and it would be better to tie this into 
  //     VMDApp more directly at some later point, but the regular
  //     VMD startup code is similarly lame, so we'll use it for now.
  const char *disp = getenv("VMDDISPLAYDEVICE");
  if (!disp) disp="text";

  int loc[2] = { 50, 50 };
  int size[2] = { 400, 400 };
  VMDgetDisplayFrame(loc, size);

  VMDApp *app = new VMDApp(1, argv, mpienabled);
  app->VMDinit(1, argv, disp, loc, size);

  // read application defaults
  VMDreadInit(app);

  // read user-defined startup files
  VMDreadStartup(app);

  set_vmdapp(app);

  // set my local static
  the_app = app;

  PyObject *vmdmodule = Py_InitModule((char *)"vmd", VMDAppMethods);

  initanimate();
  initatomsel();
  initaxes();
  initcolor();
  initdisplay();
  initgraphics();
  initimd();
  initlabel();
  initmaterial();
  initmolecule();
  initmolrep();
  initmouse();
  initrender();
  inittrans();
  initvmdmenu();

#ifdef VMDNUMPY
  initvmdnumpy();
#endif

  if (PyErr_Occurred()) return;

  static const char *modules[] = {
    "animate", "atomsel", "axes", "color", "display", "graphics",
    "imd", "label", "material", "molecule", "molrep", "mouse", 
    "render", "trans", "vmdmenu", "vmdnumpy"
  };
  for (unsigned i=0; i<sizeof(modules)/sizeof(const char *); i++) {
    const char *m = modules[i];
#if (PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION < 5)
#define CAST_HACK (char *)
#else 
#define CAST_HACK
#endif
    PyModule_AddObject(vmdmodule, CAST_HACK m, PyImport_ImportModule( CAST_HACK m));
  }
  event_tstate = PyThreadState_Get();
#if defined(VMD_SHARED)
  PyOS_InputHook = vmd_input_hook;
#endif
}
Пример #2
0
int VMDmain(int argc, char **argv) {
#else
int main(int argc, char **argv) {
#endif
  int mpienabled = 0;

  PROFILE_MAIN_THREAD(); // mark main VMD thread within profiler timelines

  PROFILE_PUSH_RANGE("VMD main() initialization", 4);

#if defined(VMDMPI)
  // so long as the caller has not disabled MPI, we initialize MPI when VMD
  // has been compiled to support it.
  if (getenv("VMDNOMPI") == NULL) {
    mpienabled = 1;
  }
#endif

  if (!VMDinitialize(&argc, &argv, mpienabled)) {
    return 0;
  }

  const char *displayTypeName = VMDgetDisplayTypeName();
  int displayLoc[2], displaySize[2];
  VMDgetDisplayFrame(displayLoc, displaySize);

  VMDApp *app = new VMDApp(argc, argv, mpienabled);

  if (!app->VMDinit(argc, argv, displayTypeName, displayLoc, displaySize)) {
    delete app;
    return 1;
  }

  PROFILE_POP_RANGE();
  PROFILE_PUSH_RANGE("VMD startup scripts", 1);

  // read various application defaults
  VMDreadInit(app);

  PROFILE_POP_RANGE();
  PROFILE_PUSH_RANGE("VMD process user script(s)", 1);

  // read user-defined startup files
  VMDreadStartup(app);

  PROFILE_POP_RANGE();
  PROFILE_PUSH_RANGE("VMD interactive event loop", 1);

  // main event loop
  do {
    // If we knew that there were no embedded python interpreter, we could
    // process Tcl events here, rather than within the VMD instance. 
#ifdef VMDTCL
    // Loop on the Tcl event notifier
    // while (Tcl_DoOneEvent(TCL_DONT_WAIT));
#endif

    // handle Fltk events
    VMDupdateFltk();

#if 0
    // take over the console
    if (vmd_check_stdin()) {
      app->process_console();
    }
#endif

  } while(app->VMDupdate(VMD_CHECK_EVENTS));

  PROFILE_POP_RANGE();

  // end of program
  delete app;
  VMDshutdown(mpienabled);

  return 0;
}