00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifdef VMDIMD
00019 #include "CmdIMD.h"
00020 #endif
00021
00022 #include "IMDMgr.h"
00023 #include "CommandQueue.h"
00024 #include "VMDApp.h"
00025 #include "MoleculeList.h"
00026 #include "utilities.h"
00027 #include "config.h"
00028 #include <stdlib.h>
00029 #include <tcl.h>
00030
00031 int text_cmd_imd(ClientData cd, Tcl_Interp *interp, int argc,
00032 const char *argv[]) {
00033
00034 #ifdef VMDIMD
00035 VMDApp *app = (VMDApp *)cd;
00036 CommandQueue *cmdQueue = app->commandQueue;
00037
00038 if (argc == 1) {
00039 Tcl_AppendResult(interp,
00040 "Need parameters for 'imd' command. Possibilities include: \n",
00041 "pause [on|off|toggle]\n",
00042 "detach\n" ,
00043 "kill\n" ,
00044 "connect <hostname> <port>\n" ,
00045 "transfer <rate>\n" ,
00046 "keep <rate>\n" ,
00047 NULL);
00048 return TCL_ERROR;
00049 }
00050
00051 else if (!strupncmp(argv[1], "pause", CMDLEN)) {
00052 if ((argc == 3) && (!strupncmp(argv[2], "toggle", CMDLEN))) {
00053 app->imdMgr->togglepause();
00054 cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::PAUSE_TOGGLE));
00055 }
00056 else if ((argc == 3) && (!strupncmp(argv[2], "on", CMDLEN))) {
00057 app->imdMgr->pause();
00058 cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::PAUSE_ON));
00059 }
00060 else if ((argc == 3) && (!strupncmp(argv[2], "off", CMDLEN))) {
00061 app->imdMgr->unpause();
00062 cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::PAUSE_OFF));
00063 }
00064 else {
00065 Tcl_AppendResult(interp, "Wrong arguments: imd pause <on|off|toggle>", NULL);
00066 return TCL_ERROR;
00067 }
00068
00069 if (!app->imdMgr->connected()) {
00070 Tcl_AppendResult(interp, "No IMD connection available.", NULL);
00071 return TCL_ERROR;
00072 }
00073 }
00074 else if ((argc == 4) && (!strupncmp(argv[1], "connect", CMDLEN)) ) {
00075 int port = atoi(argv[3]);
00076 Molecule *mol = app->moleculeList->top();
00077 if (!mol) {
00078 Tcl_AppendResult(interp,
00079 "Can't connect, no molecule loaded", NULL);
00080 return TCL_ERROR;
00081 }
00082 if (app->imdMgr->connected()) {
00083 char buf[500];
00084 sprintf(buf, "Can't connect; already connected to simulation running on"
00085 "host %s over port %d", app->imdMgr->gethost(),
00086 app->imdMgr->getport());
00087 Tcl_SetResult(interp, buf, TCL_VOLATILE);
00088 return TCL_ERROR;
00089 }
00090 if (!app->imd_connect(mol->id(), argv[2], port)) {
00091 Tcl_AppendResult(interp, "Unable to connect to host ", argv[2],
00092 " on port ", argv[3], NULL);
00093 return TCL_ERROR;
00094 }
00095 }
00096 else if (argc == 2) {
00097 if (!app->imdMgr->connected()) {
00098 Tcl_AppendResult(interp, "No IMD connection available.", NULL);
00099 return TCL_ERROR;
00100 }
00101 else if (!strupncmp(argv[1], "detach", CMDLEN)) {
00102 app->imdMgr->detach();
00103 cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::DETACH));
00104 } else if (!strupncmp(argv[1], "kill", CMDLEN)) {
00105 app->imdMgr->kill();
00106 cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::KILL));
00107 } else {
00108 Tcl_AppendResult(interp,
00109 "Usage: imd [pause | detach | kill]", NULL);
00110 return TCL_ERROR;
00111 }
00112 }
00113 else if ((argc == 3) && (!strupncmp(argv[1], "transfer", CMDLEN)) ) {
00114 int rate = atoi(argv[2]);
00115 app->imdMgr->set_trans_rate(rate);
00116 cmdQueue->runcommand(new CmdIMDRate(CmdIMDRate::TRANSFER, rate));
00117 }
00118 else if ((argc == 3) && (!strupncmp(argv[1], "keep", CMDLEN)) ) {
00119 int rate = atoi(argv[2]);
00120 app->imdMgr->set_keep_rate(rate);
00121 cmdQueue->runcommand(new CmdIMDRate(CmdIMDRate::KEEP, rate));
00122 }
00123 else
00124 return TCL_ERROR;
00125
00126 return TCL_OK;
00127
00128 #else
00129 Tcl_AppendResult(interp,
00130 "IMD functionality not present. Recompile with IMD enabled.", NULL);
00131 return TCL_ERROR;
00132 #endif
00133 }
00134
00135
00136
00137