NAMD
Public Member Functions | Static Public Member Functions | Friends | List of all members
ScriptTcl Class Reference

#include <ScriptTcl.h>

Public Member Functions

 ScriptTcl ()
 
 ~ScriptTcl ()
 
void eval (char *script)
 
void load (char *scriptFile)
 
void run ()
 
void tclmain (int, char **)
 
void measure (Vector *)
 

Static Public Member Functions

static int tclsh (int, char **)
 

Friends

class DataExchanger
 
class Controller
 
class GlobalMasterTcl
 
class colvarproxy_namd
 

Detailed Description

Definition at line 25 of file ScriptTcl.h.

Constructor & Destructor Documentation

ScriptTcl::ScriptTcl ( )

Definition at line 2104 of file ScriptTcl.C.

References DebugM, eabf_static_init(), molfile_dcdplugin_init(), molfile_dcdplugin_register(), psfgen_static_init(), register_cb(), and tcl_vector_math_init().

2104  : scriptBarrier(scriptBarrierTag) {
2105  DebugM(3,"Constructing ScriptTcl\n");
2106 #ifdef NAMD_TCL
2107  interp = 0;
2108  callbackname = 0;
2109 #endif
2110  state = new NamdState;
2111  barrierStep = 0;
2112 
2115 
2116  initWasCalled = 0;
2117  runWasCalled = 0;
2118 
2119 #ifdef NAMD_TCL
2120  config = new ConfigList;
2121 
2122  // Create interpreter
2123  interp = Tcl_CreateInterp();
2124  psfgen_static_init(interp);
2125  eabf_static_init(interp);
2126  tcl_vector_math_init(interp);
2127  Tcl_CreateCommand(interp, "python", Tcl_python,
2128  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2129  Tcl_CreateCommand(interp, "startup", Tcl_startup,
2130  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2131  Tcl_CreateCommand(interp, "exit", Tcl_exit,
2132  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2133  Tcl_CreateCommand(interp, "abort", Tcl_abort,
2134  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2135  Tcl_CreateCommand(interp, "numPes", Tcl_numPes,
2136  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2137  Tcl_CreateCommand(interp, "numNodes", Tcl_numNodes,
2138  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2139  Tcl_CreateCommand(interp, "numPhysicalNodes", Tcl_numPhysicalNodes,
2140  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2141  Tcl_CreateCommand(interp, "numReplicas", Tcl_numReplicas,
2142  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2143  Tcl_CreateCommand(interp, "myReplica", Tcl_myReplica,
2144  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2145  Tcl_CreateCommand(interp, "replicaEval", Tcl_replicaEval,
2146  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2147  Tcl_CreateCommand(interp, "replicaYield", Tcl_replicaYield,
2148  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2149  Tcl_CreateCommand(interp, "replicaSendrecv", Tcl_replicaSendrecv,
2150  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2151  Tcl_CreateCommand(interp, "replicaSend", Tcl_replicaSend,
2152  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2153  Tcl_CreateCommand(interp, "replicaRecv", Tcl_replicaRecv,
2154  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2155  Tcl_CreateCommand(interp, "replicaBarrier", Tcl_replicaBarrier,
2156  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2157  Tcl_CreateCommand(interp, "replicaAtomSendrecv", Tcl_replicaAtomSendrecv,
2158  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2159  Tcl_CreateCommand(interp, "replicaAtomSend", Tcl_replicaAtomSend,
2160  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2161  Tcl_CreateCommand(interp, "replicaAtomRecv", Tcl_replicaAtomRecv,
2162  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2163  Tcl_CreateCommand(interp, "stdout", Tcl_stdout,
2164  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2165  Tcl_CreateCommand(interp, "print", Tcl_print,
2166  (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2167  Tcl_CreateCommand(interp, "unknown", Tcl_config,
2168  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2169  Tcl_CreateCommand(interp, "param", Tcl_config,
2170  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2171  Tcl_CreateCommand(interp, "isset", Tcl_isset_config,
2172  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2173  Tcl_CreateCommand(interp, "istrue", Tcl_istrue_config,
2174  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2175  Tcl_CreateCommand(interp, "run", Tcl_run,
2176  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2177  Tcl_CreateCommand(interp, "minimize", Tcl_minimize,
2178  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2179  Tcl_CreateCommand(interp, "move", Tcl_move,
2180  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2181  Tcl_CreateCommand(interp, "moveallby", Tcl_moveallby,
2182  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2183  Tcl_CreateCommand(interp, "output", Tcl_output,
2184  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2185  Tcl_CreateCommand(interp, "measure", Tcl_measure,
2186  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2187  Tcl_CreateCommand(interp, "colvarbias", Tcl_colvarbias,
2188  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2189  Tcl_CreateCommand(interp, "colvarvalue", Tcl_colvarvalue,
2190  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2191  Tcl_CreateObjCommand(interp, "cv", Tcl_colvars,
2192  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2193  Tcl_CreateCommand(interp, "colvarfreq", Tcl_colvarfreq,
2194  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2195  Tcl_CreateCommand(interp, "checkpoint", Tcl_checkpoint,
2196  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2197  Tcl_CreateCommand(interp, "revert", Tcl_revert,
2198  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2199  Tcl_CreateCommand(interp, "checkpointStore", Tcl_checkpointReplica,
2200  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2201  Tcl_CreateCommand(interp, "checkpointLoad", Tcl_checkpointReplica,
2202  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2203  Tcl_CreateCommand(interp, "checkpointSwap", Tcl_checkpointReplica,
2204  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2205  Tcl_CreateCommand(interp, "checkpointFree", Tcl_checkpointReplica,
2206  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2207  Tcl_CreateCommand(interp, "reinitvels", Tcl_reinitvels,
2208  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2209  Tcl_CreateCommand(interp, "rescalevels", Tcl_rescalevels,
2210  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2211  Tcl_CreateCommand(interp, "reinitatoms", Tcl_reinitatoms,
2212  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2213  Tcl_CreateCommand(interp, "replicaDcdFile", Tcl_replicaDcdFile,
2214  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2215  Tcl_CreateCommand(interp, "callback", Tcl_callback,
2216  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2217  Tcl_CreateCommand(interp, "coorfile", Tcl_coorfile,
2218  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2219  Tcl_CreateCommand(interp, "dumpbench", Tcl_dumpbench,
2220  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2221  Tcl_CreateObjCommand(interp, "consForceConfig", Tcl_consForceConfig,
2222  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2223  Tcl_CreateCommand(interp, "reloadCharges", Tcl_reloadCharges,
2224  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2225  // BEGIN gf
2226  Tcl_CreateCommand(interp, "reloadGridforceGrid", Tcl_reloadGridforceGrid,
2227  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2228  Tcl_CreateCommand(interp, "updateGridScale", Tcl_updateGridScale,
2229  (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
2230  // END gf
2231 #endif
2232 
2233 }
int molfile_dcdplugin_init(void)
#define DebugM(x, y)
Definition: Debug.h:59
int psfgen_static_init(Tcl_Interp *)
int eabf_static_init(Tcl_Interp *interp)
Definition: eabfTcl.C:179
int tcl_vector_math_init(Tcl_Interp *interp)
Definition: TclCommands.C:299
int register_cb(void *v, vmdplugin_t *p)
Definition: PluginIOMgr.C:6
int molfile_dcdplugin_register(void *, vmdplugin_register_cb)
ScriptTcl::~ScriptTcl ( )

Definition at line 2345 of file ScriptTcl.C.

References DebugM, and molfile_dcdplugin_fini().

2345  {
2346  DebugM(3,"Destructing ScriptTcl\n");
2347 #ifdef NAMD_TCL
2348  if ( interp ) Tcl_DeleteInterp(interp);
2349  delete [] callbackname;
2350 #endif
2351 
2353 }
#define DebugM(x, y)
Definition: Debug.h:59
int molfile_dcdplugin_fini(void)

Member Function Documentation

void ScriptTcl::eval ( char *  script)

Definition at line 2247 of file ScriptTcl.C.

References NAMD_bug(), and NAMD_die().

Referenced by after_backend_init().

2247  {
2248 
2249 #ifdef NAMD_TCL
2250  int code = Tcl_Eval(interp,script);
2251  const char *result = Tcl_GetStringResult(interp);
2252  if (*result != 0) CkPrintf("TCL: %s\n",result);
2253  if (code != TCL_OK) {
2254  const char *errorInfo = Tcl_GetVar(interp,"errorInfo",0);
2255  NAMD_die(errorInfo ? errorInfo : "Unknown Tcl error");
2256  }
2257 #else
2258  NAMD_bug("ScriptTcl::eval called without Tcl.");
2259 #endif
2260 
2261 }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
void NAMD_die(const char *err_msg)
Definition: common.C:83
void ScriptTcl::load ( char *  scriptFile)

Definition at line 2304 of file ScriptTcl.C.

References NAMD_bug(), and NAMD_die().

Referenced by after_backend_init().

2304  {
2305 
2306 #ifdef NAMD_TCL
2307  int code = Tcl_EvalFile(interp,scriptFile);
2308  const char *result = Tcl_GetStringResult(interp);
2309  if (*result != 0) CkPrintf("TCL: %s\n",result);
2310  if (code != TCL_OK) {
2311  const char *errorInfo = Tcl_GetVar(interp,"errorInfo",0);
2312  NAMD_die(errorInfo ? errorInfo : "Unknown Tcl error");
2313  }
2314 #else
2315  NAMD_bug("ScriptTcl::load called without Tcl.");
2316 #endif
2317 
2318 }
void NAMD_bug(const char *err_msg)
Definition: common.C:123
void NAMD_die(const char *err_msg)
Definition: common.C:83
void ScriptTcl::measure ( Vector c)

Definition at line 1387 of file ScriptTcl.C.

References Node::coords, Measure::createCommands(), Measure::deleteCommands(), and Node::Object().

Referenced by Output::coordinate().

1387  {
1388  Measure::createCommands(interp);
1389  Node::Object()->coords = c;
1390  measure_result = Tcl_Eval(interp,measure_command);
1391  Node::Object()->coords = 0;
1392  Measure::deleteCommands(interp);
1393 }
static Node * Object()
Definition: Node.h:86
Vector * coords
Definition: Node.h:185
static void createCommands(Tcl_Interp *)
Definition: Measure.C:169
static void deleteCommands(Tcl_Interp *)
Definition: Measure.C:180
void ScriptTcl::run ( void  )

Definition at line 2321 of file ScriptTcl.C.

References SimParameters::minimizeCGOn, NAMD_die(), Node::Object(), replica_barrier(), SCRIPT_END, SCRIPT_MINIMIZE, and Node::simParameters.

Referenced by after_backend_init().

2321  {
2322 #else
2323 void ScriptTcl::run(char *scriptFile) {
2324 
2325  if ( NULL == scriptFile || NULL == (config = new ConfigList(scriptFile)) ) {
2326  NAMD_die("Simulation config file is empty.");
2327  }
2328 #endif
2329 
2330  if (runWasCalled == 0) {
2331  initcheck();
2333  if ( simParams->minimizeCGOn ) runController(SCRIPT_MINIMIZE);
2334  else runController(SCRIPT_RUN);
2335  runWasCalled = 1;
2336  }
2337 
2338 #if CMK_HAS_PARTITION
2339  replica_barrier();
2340 #endif
2341  runController(SCRIPT_END);
2342 
2343 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:178
void run()
Definition: ScriptTcl.C:2321
void replica_barrier()
void NAMD_die(const char *err_msg)
Definition: common.C:83
#define simParams
Definition: Output.C:127
void ScriptTcl::tclmain ( int  argc,
char **  argv 
)

Definition at line 2287 of file ScriptTcl.C.

References NAMD_die().

Referenced by after_backend_init().

2287  {
2288  Tcl_SetVar(interp, "argv0", argv[0], TCL_GLOBAL_ONLY);
2289  Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewIntObj(argc-1), TCL_GLOBAL_ONLY);
2290  Tcl_Obj *argvPtr = Tcl_NewListObj(0, NULL);
2291  for ( int i=1; i<argc; ++i ) {
2292  Tcl_ListObjAppendElement(NULL, argvPtr, Tcl_NewStringObj(argv[i],-1));
2293  }
2294  Tcl_SetVar2Ex(interp, "argv", NULL, argvPtr, TCL_GLOBAL_ONLY);
2295  int code = Tcl_EvalFile(interp,argv[0]);
2296  if (code != TCL_OK) {
2297  const char *errorInfo = Tcl_GetVar(interp,"errorInfo",0);
2298  NAMD_die(errorInfo ? errorInfo : "Unknown Tcl error");
2299  }
2300 }
void NAMD_die(const char *err_msg)
Definition: common.C:83
int ScriptTcl::tclsh ( int  argc,
char **  argv 
)
static

Definition at line 2265 of file ScriptTcl.C.

References eabf_static_init(), psfgen_static_init(), and tcl_vector_math_init().

Referenced by main().

2265  {
2266  Tcl_Interp *interp = Tcl_CreateInterp();
2267  psfgen_static_init(interp);
2268  eabf_static_init(interp);
2269  tcl_vector_math_init(interp);
2270  Tcl_SetVar(interp, "argv0", argv[0], TCL_GLOBAL_ONLY);
2271  Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewIntObj(argc-1), TCL_GLOBAL_ONLY);
2272  Tcl_Obj *argvPtr = Tcl_NewListObj(0, NULL);
2273  for ( int i=1; i<argc; ++i ) {
2274  Tcl_ListObjAppendElement(NULL, argvPtr, Tcl_NewStringObj(argv[i],-1));
2275  }
2276  Tcl_SetVar2Ex(interp, "argv", NULL, argvPtr, TCL_GLOBAL_ONLY);
2277  int code = Tcl_EvalFile(interp,argv[0]);
2278  if (code != TCL_OK) {
2279  const char *errorInfo = Tcl_GetVar(interp,"errorInfo",0);
2280  fprintf(stderr,"%s\n",(errorInfo ? errorInfo : "Unknown Tcl error"));
2281  return -1;
2282  }
2283  return 0;
2284 }
int psfgen_static_init(Tcl_Interp *)
int eabf_static_init(Tcl_Interp *interp)
Definition: eabfTcl.C:179
int tcl_vector_math_init(Tcl_Interp *interp)
Definition: TclCommands.C:299

Friends And Related Function Documentation

friend class colvarproxy_namd
friend

Definition at line 59 of file ScriptTcl.h.

friend class Controller
friend

Definition at line 57 of file ScriptTcl.h.

friend class DataExchanger
friend

Definition at line 54 of file ScriptTcl.h.

friend class GlobalMasterTcl
friend

Definition at line 58 of file ScriptTcl.h.


The documentation for this class was generated from the following files: