Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

GlobalMasterTcl.C

Go to the documentation of this file.
00001 
00007 #include "InfoStream.h"
00008 #include "Node.h"
00009 #include "Molecule.h"
00010 #include "ReductionMgr.h"
00011 #include "ScriptTcl.h"
00012 #include <stdio.h>
00013 
00014 #include "GlobalMaster.h"
00015 #include "GlobalMasterTcl.h"
00016 
00017 #ifdef NAMD_TCL
00018 #define USE_COMPAT_CONST
00019 #include <tcl.h>
00020 #endif
00021 #include "TclCommands.h"
00022 
00023 //#define DEBUGM
00024 #define MIN_DEBUG_LEVEL 3
00025 #include "Debug.h"
00026 
00027 
00028 #ifdef NAMD_TCL
00029 int GlobalMasterTcl::Tcl_print(ClientData,
00030         Tcl_Interp *, int argc, char *argv[]) {
00031   int arglen = 1;  int ai;
00032   for (ai=1; ai<argc; ++ai) { arglen += strlen(argv[ai]) + 1; }
00033   char *buf = new char[arglen];  *buf = 0;
00034   for (ai=1; ai<argc; ++ai) { strcat(buf,argv[ai]); strcat(buf," "); }
00035   ai = strlen(buf);  if ( ai ) buf[ai-1] = 0;
00036   CkPrintf("TCL: %s\n",buf);
00037   delete [] buf;
00038   return TCL_OK;
00039 }
00040 
00041 
00042 int GlobalMasterTcl::Tcl_atomid(ClientData clientData,
00043         Tcl_Interp *interp, int argc, char *argv[]) {
00044   if (argc != 4) {
00045     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00046     return TCL_ERROR;
00047   }
00048   char *segid = argv[1];
00049   int resid;
00050   if (Tcl_GetInt(interp,argv[2],&resid) != TCL_OK) {
00051     return TCL_ERROR;
00052   }
00053   char *aname = argv[3];
00054 
00055   Molecule *mol = (Molecule *)clientData;
00056   int atomid = mol->get_atom_from_name(segid,resid,aname);
00057 
00058   if (atomid < 0) {
00059     Tcl_SetResult(interp,"atom not found",TCL_VOLATILE);
00060     return TCL_ERROR;
00061   }
00062   atomid += 1;
00063 
00064   char s[10];  sprintf(s,"%d",atomid);
00065   Tcl_SetResult(interp,s,TCL_VOLATILE);
00066   DebugM(4,"Atom ID " << atomid << " identified by name\n");
00067   return TCL_OK;
00068 }
00069 
00070 
00071 int GlobalMasterTcl::Tcl_addatom(ClientData clientData,
00072         Tcl_Interp *interp, int argc, char *argv[]) {
00073   DebugM(2,"Tcl_addatom called\n");
00074   if (argc != 2) {
00075     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00076     return TCL_ERROR;
00077   }
00078   int atomid;
00079   if (Tcl_GetInt(interp,argv[1],&atomid) != TCL_OK) {
00080     return TCL_ERROR;
00081   }
00082   Molecule *mol = Node::Object()->molecule;
00083   int numAtoms = mol->numAtoms;
00084   if ( (atomid-1) < 0 || (atomid-1) >= numAtoms ) {
00085     char errmsg[128];
00086     sprintf(errmsg,"illegal atomid %d",atomid);
00087     Tcl_SetResult(interp,errmsg,TCL_VOLATILE);
00088     return TCL_ERROR;
00089   }
00090   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00091   self->modifyRequestedAtoms().add(atomid-1);
00092   DebugM(4,"Atom ID " << atomid << " added to config list\n");
00093   return TCL_OK;
00094 }
00095 
00096 
00097 int GlobalMasterTcl::Tcl_addgroup(ClientData clientData,
00098         Tcl_Interp *interp, int argc, char *argv[]) {
00099   DebugM(2,"Tcl_addgroup called\n");
00100   if (argc != 2) {
00101     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00102     return TCL_ERROR;
00103   }
00104 
00105   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00106   ResizeArray<AtomIDList> &group_list = self->modifyRequestedGroups();
00107   ForceList &force_list = self->modifyGroupForces();
00108 
00109   /* set gcount to the number of groups after we add one, and add it! */
00110   int gcount = 1 + group_list.size();
00111   group_list.resize(gcount);
00112   force_list.add(Vector(0,0,0)); // make sure the force is zero
00113 
00114   /* get the list of atoms that go in the group */
00115   int listc, i;  char **listv;
00116   if (Tcl_SplitList(interp,argv[1],&listc,&listv) != TCL_OK) {
00117     return TCL_ERROR;
00118   }
00119 
00120   Molecule *mol = Node::Object()->molecule;
00121   int numAtoms = mol->numAtoms;
00122   /* add each atom to the new group */
00123   for ( i = 0; i < listc; ++i ) {
00124     int atomid;
00125     if (Tcl_GetInt(interp,listv[i],&atomid) != TCL_OK) { // error getting int
00126       group_list.resize(gcount-1); // remove the group we made
00127       Tcl_Free((char*) listv);
00128       return TCL_ERROR;
00129     }
00130     if ( (atomid-1) < 0 || (atomid-1) >= numAtoms ) {
00131       char errmsg[128];
00132       sprintf(errmsg,"illegal atomid %d",atomid);
00133       Tcl_SetResult(interp,errmsg,TCL_VOLATILE);
00134       return TCL_ERROR;
00135     }
00136     group_list[gcount-1].add(atomid-1); // add the atom to the group
00137   }
00138   Tcl_Free((char*) listv);
00139 
00140   /* return the group number to TCL */
00141   char s[10];  sprintf(s,"g%d",gcount);
00142   Tcl_SetResult(interp,s,TCL_VOLATILE);
00143 
00144   DebugM(4,"Group " << s << " added to config list\n");
00145   return TCL_OK;
00146 }
00147 
00148 /* this function is useless - it reconfigures whenever you add atoms! */
00149 int GlobalMasterTcl::Tcl_reconfig(ClientData clientData,
00150         Tcl_Interp *interp, int argc, char **) {
00151   DebugM(2,"Tcl_reconfig called\n");
00152   if (argc != 1) {
00153     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00154     return TCL_ERROR;
00155   }
00156   iout << iWARN << "'reconfig' is obsolete - reconfiguration is now automatic." << endi;
00157   iout << iWARN << "Use 'clearconfig' to clear the list of atoms and groups." << endi;
00158   DebugM(4,"Reconfiguration turned on\n");
00159   return TCL_OK;
00160 }
00161 
00162 int GlobalMasterTcl::Tcl_clearconfig(ClientData clientData,
00163         Tcl_Interp *interp, int argc, char **) {
00164   DebugM(2,"Tcl_reconfig called\n");
00165   if (argc != 1) {
00166     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00167     return TCL_ERROR;
00168   }
00169   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00170   self->modifyRequestedGroups().resize(0);
00171   self->modifyGroupForces().resize(0);
00172   self->modifyRequestedAtoms().resize(0);
00173   self->modifyForcedAtoms().resize(0);
00174   self->modifyAppliedForces().resize(0);
00175   return TCL_OK;
00176 }
00177 
00178 int GlobalMasterTcl::Tcl_getstep(ClientData clientData,
00179         Tcl_Interp *interp, int argc, char **) {
00180   DebugM(2,"Tcl_reconfig called\n");
00181   if (argc != 1) {
00182     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00183     return TCL_ERROR;
00184   }
00185   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00186   
00187   char s[16];  sprintf(s,"%d",self->step);
00188   Tcl_SetResult(interp,s,TCL_VOLATILE);
00189   return TCL_OK;
00190 }
00191 
00192 int GlobalMasterTcl::Tcl_loadforces(ClientData clientData,
00193         Tcl_Interp *interp, int objc, Tcl_Obj * const objv[]) {
00194   DebugM(1,"Making tcl force array\n");
00195   if(objc != 2) {
00196     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00197     return TCL_ERROR;
00198   }
00199   Tcl_Obj * const force_array_name = objv[1];
00200   
00201   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00202   AtomIDList::const_iterator forced_ids_i = self->getLastAtomsForcedBegin();
00203   AtomIDList::const_iterator forced_ids_e = self->getLastAtomsForcedEnd();
00204   ForceList::const_iterator forces_i = self->getLastForcesBegin();
00205 
00206   // plf -- changed 06/12/2008 to check for more than one force on each atom
00207 
00208   // now make a Tcl array containing all of the requested atoms and
00209   // their forces
00210   DebugM(1,"Making Tcl array\n");
00211   while(forced_ids_i != forced_ids_e) {
00212     Tcl_Obj *array_key = Tcl_NewIntObj((int)((*forced_ids_i)+1)); // the id
00213 
00214     // Check if the element is already defined, and if so, add to it
00215     Tcl_Obj *oldlist = Tcl_ObjGetVar2(interp, force_array_name, array_key, 0);
00216     Tcl_Obj *newlist = Tcl_NewListObj(0,NULL); // the list <fx,fy,fz>
00217     if (oldlist == NULL) {
00218       Tcl_ListObjAppendElement(interp, newlist,
00219         Tcl_NewDoubleObj((double)((*forces_i).x)));
00220       Tcl_ListObjAppendElement(interp, newlist, 
00221         Tcl_NewDoubleObj((double)((*forces_i).y)));
00222       Tcl_ListObjAppendElement(interp, newlist, 
00223         Tcl_NewDoubleObj((double)((*forces_i).z)));
00224     } else {
00225       Tcl_Obj** old_elems;
00226       int num_old_elems;
00227       double currval = 0.0;
00228       Tcl_ListObjGetElements(interp, oldlist, &num_old_elems, &old_elems);
00229       if (num_old_elems != 3) {
00230         NAMD_die("TCL error in loadforces! Force list doesn't have 3 elements!");
00231       }
00232       Tcl_GetDoubleFromObj(interp, old_elems[0], &currval);
00233       Tcl_ListObjAppendElement(interp, newlist,
00234         Tcl_NewDoubleObj((double)((*forces_i).x) + currval));
00235       Tcl_GetDoubleFromObj(interp, old_elems[1], &currval);
00236       Tcl_ListObjAppendElement(interp, newlist, 
00237         Tcl_NewDoubleObj((double)((*forces_i).y + currval)));
00238       Tcl_GetDoubleFromObj(interp, old_elems[2], &currval);
00239       Tcl_ListObjAppendElement(interp, newlist, 
00240         Tcl_NewDoubleObj((double)((*forces_i).z + currval)));
00241     }
00242 
00243     // add the pair (id,F) to the array
00244     if (!Tcl_ObjSetVar2(interp, force_array_name, array_key, newlist, 0)) {
00245       NAMD_die("TCL error in loadforces!");
00246       return TCL_ERROR;
00247     }
00248 
00249     // what is this for?
00250     Tcl_DecrRefCount(array_key);
00251 
00252     // go to the next atom
00253     forced_ids_i++;
00254     forces_i++;
00255   }
00256 
00257   DebugM(1,"Done making tcl force array\n");
00258   return TCL_OK;
00259 }
00260 
00261 
00262 // Here I simply copied the code from "Tcl_loadforces" above. The
00263 // only difference is the source data.
00264 int GlobalMasterTcl::Tcl_loadtotalforces(ClientData clientData,
00265         Tcl_Interp *interp, int objc, Tcl_Obj * const objv[])
00266 {
00267   if(objc != 2)
00268   { Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00269     return TCL_ERROR;
00270   }
00271   Tcl_Obj * const force_array_name = objv[1];
00272   
00273   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00274   AtomIDList::const_iterator forced_ids_i = self->getForceIdBegin();
00275   AtomIDList::const_iterator forced_ids_e = self->getForceIdEnd();
00276   ForceList::const_iterator forces_i = self->getTotalForce();
00277   
00278   // now make a Tcl array containing all of the requested atoms and
00279   // their forces
00280   while(forced_ids_i != forced_ids_e) {
00281     Tcl_Obj *array_key = Tcl_NewIntObj((int)((*forced_ids_i)+1)); // the id
00282     Tcl_Obj *newlist = Tcl_NewListObj(0,NULL); // the list <fx,fy,fz>
00283     Tcl_ListObjAppendElement(interp, newlist,
00284       Tcl_NewDoubleObj((double)((*forces_i).x)));
00285     Tcl_ListObjAppendElement(interp, newlist, 
00286       Tcl_NewDoubleObj((double)((*forces_i).y)));
00287     Tcl_ListObjAppendElement(interp, newlist, 
00288       Tcl_NewDoubleObj((double)((*forces_i).z)));
00289 
00290     // add the pair (id,F) to the array
00291     if (!Tcl_ObjSetVar2(interp, force_array_name, array_key, newlist, 0)) {
00292       NAMD_die("TCL error in loadtotalforces!");
00293       return TCL_ERROR;
00294     }
00295 
00296     // what is this for?
00297     Tcl_DecrRefCount(array_key);
00298 
00299     // go to the next atom
00300     forced_ids_i++;
00301     forces_i++;
00302   }
00303   return TCL_OK;
00304 }
00305 
00306   
00307 int GlobalMasterTcl::Tcl_loadcoords(ClientData clientData,
00308         Tcl_Interp *interp, int objc, Tcl_Obj * const objv[]) {
00309   if (objc != 2) {
00310     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00311     return TCL_ERROR;
00312   }
00313   Tcl_Obj * const vname = objv[1];
00314   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00315   AtomIDList::const_iterator a_i = self->getAtomIdBegin();
00316   AtomIDList::const_iterator a_e = self->getAtomIdEnd();
00317   PositionList::const_iterator p_i = self->getAtomPositionBegin();
00318   for ( ; a_i != a_e; ++a_i, ++p_i ) {
00319     Tcl_Obj *newlist = Tcl_NewListObj(0, NULL);
00320     Tcl_Obj *arrkey = Tcl_NewIntObj((int)((*a_i)+1));
00321     
00322     Tcl_ListObjAppendElement(interp, newlist, 
00323       Tcl_NewDoubleObj((double)((*p_i).x)));
00324     Tcl_ListObjAppendElement(interp, newlist, 
00325       Tcl_NewDoubleObj((double)((*p_i).y)));
00326     Tcl_ListObjAppendElement(interp, newlist, 
00327       Tcl_NewDoubleObj((double)((*p_i).z)));
00328    
00329     if (!Tcl_ObjSetVar2(interp, vname, arrkey, newlist, 0)) {
00330       NAMD_die("TCL error in global force calculation!");
00331       return TCL_ERROR;
00332     }
00333     Tcl_DecrRefCount(arrkey);
00334   }
00335 
00336   /* do the group stuff */
00337   PositionList::const_iterator c_i = self->getGroupPositionBegin();
00338   PositionList::const_iterator c_e = self->getGroupPositionEnd();
00339   int gcount = 1;
00340   for ( ; c_i != c_e; ++c_i, ++gcount ) {
00341     Tcl_Obj *newlist = Tcl_NewListObj(0, NULL);
00342     char buf[10];
00343     sprintf(buf, "g%d", gcount);
00344     Tcl_Obj *arrkey = Tcl_NewStringObj(buf, -1);
00345  
00346     Tcl_ListObjAppendElement(interp, newlist,
00347       Tcl_NewDoubleObj((double)((*c_i).x)));
00348     Tcl_ListObjAppendElement(interp, newlist,
00349       Tcl_NewDoubleObj((double)((*c_i).y)));
00350     Tcl_ListObjAppendElement(interp, newlist,
00351       Tcl_NewDoubleObj((double)((*c_i).z)));
00352    
00353     if (!Tcl_ObjSetVar2(interp, vname, arrkey, newlist, 0)) {
00354       NAMD_die("TCL error in global force calculation!");
00355       return TCL_ERROR;
00356     }
00357     Tcl_DecrRefCount(arrkey);
00358   }
00359   return TCL_OK;
00360 }
00361 
00362 
00363 int GlobalMasterTcl::Tcl_loadmasses(ClientData clientData,
00364         Tcl_Interp *interp, int objc, Tcl_Obj * const objv[]) {
00365   if (objc != 2) {
00366     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00367     return TCL_ERROR;
00368   }
00369   Tcl_Obj * const vname = objv[1];
00370   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00371   Molecule *mol = Node::Object()->molecule;
00372   AtomIDList::const_iterator a_i = self->getAtomIdBegin();
00373   AtomIDList::const_iterator a_e = self->getAtomIdEnd();
00374   for ( ; a_i != a_e; ++a_i) {
00375     Tcl_Obj *arrkey = Tcl_NewIntObj((int)((*a_i)+1));
00376     if (!Tcl_ObjSetVar2(interp, vname, arrkey,
00377                         Tcl_NewDoubleObj((double)(mol->atommass(*a_i))),
00378                         0)) {
00379       NAMD_die("TCL error in global force calculation!");
00380       return TCL_ERROR;
00381     }
00382     Tcl_DecrRefCount(arrkey);
00383   }
00384 
00385   const BigReal *g_i, *g_e;
00386   g_i = self->getGroupMassBegin();
00387   g_e = self->getGroupMassEnd();
00388   int gcount = 1;
00389   for ( ; g_i != g_e; ++g_i, ++gcount) {
00390     char buf[10];
00391     sprintf(buf, "g%d", gcount);
00392     Tcl_Obj *arrkey = Tcl_NewStringObj(buf, -1);
00393     if (!Tcl_ObjSetVar2(interp, vname, arrkey,
00394                         Tcl_NewDoubleObj((double)(*g_i)),
00395                         0)) {
00396       NAMD_die("TCL error in global force calculation!");
00397       return TCL_ERROR;
00398     }
00399     Tcl_DecrRefCount(arrkey);
00400   }
00401   return TCL_OK;
00402 }
00403 
00404 
00405 int GlobalMasterTcl::Tcl_addforce(ClientData clientData,
00406         Tcl_Interp *interp, int objc, Tcl_Obj * const objv[]) {
00407   DebugM(2,"Tcl_addforce called\n");
00408   if (objc != 3) {
00409     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
00410     return TCL_ERROR;
00411   }
00412   Tcl_Obj **force;  int fnum;  int atomid;  double x, y, z;
00413   int isgroup = 0;
00414   char *id = Tcl_GetStringFromObj(objv[1], NULL); 
00415   if ( id[0] == 'g' ) {
00416     isgroup = 1;
00417     if ( Tcl_GetInt(interp,id+1,&atomid) != TCL_OK ) return TCL_ERROR;
00418   } else {
00419     if ( Tcl_GetInt(interp,id,&atomid) != TCL_OK ) return TCL_ERROR;
00420   }
00421   if (Tcl_ListObjGetElements(interp, objv[2], &fnum, &force) != TCL_OK) {
00422     return TCL_ERROR;
00423   }
00424   if ( (fnum != 3) ||
00425        (Tcl_GetDoubleFromObj(interp, force[0],&x) != TCL_OK) ||
00426        (Tcl_GetDoubleFromObj(interp, force[1],&y) != TCL_OK) ||
00427        (Tcl_GetDoubleFromObj(interp, force[2],&z) != TCL_OK) ) {
00428     Tcl_SetResult(interp,"force not a vector",TCL_VOLATILE);
00429     return TCL_ERROR;
00430   }
00431 
00432   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00433   if ( isgroup ) {
00434     self->modifyGroupForces().item(atomid-1) += Vector(x,y,z);
00435   } else {
00436     self->modifyForcedAtoms().add(atomid-1);
00437     self->modifyAppliedForces().add(Vector(x,y,z));
00438   }
00439   DebugM(4,"Atom ID " << atomid << " added to force list\n");
00440   return TCL_OK;
00441 }
00442 
00443 
00444 int GlobalMasterTcl::Tcl_addenergy(ClientData clientData,
00445         Tcl_Interp *interp, int argc, char *argv[])
00446 {
00447   double energy;
00448   
00449   if (argc != 2)
00450     return TCL_ERROR;
00451   if (Tcl_GetDouble(interp,argv[1],&energy) != TCL_OK)
00452     return TCL_ERROR;
00453   
00454   GlobalMasterTcl *self = (GlobalMasterTcl *)clientData;
00455   self->reduction->item(REDUCTION_MISC_ENERGY) += energy;
00456   
00457   return TCL_OK;
00458 }
00459 #endif
00460 
00461 
00462 GlobalMasterTcl::GlobalMasterTcl() {
00463   DebugM(3,"Constructing GlobalMasterTcl\n");
00464 #ifdef NAMD_TCL
00465   interp = 0;
00466 #endif
00467   reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00468   initialize();
00469   DebugM(2,"Done constructing ("<<requestedGroups().size()<<" initial groups)\n");
00470 }
00471 
00472 GlobalMasterTcl::~GlobalMasterTcl() {
00473   DebugM(3,"Destructing GlobalMasterTcl\n");
00474 #ifdef NAMD_TCL
00475 /*
00476   if ( interp ) Tcl_DeleteInterp(interp);
00477 */
00478 #endif
00479   delete reduction;
00480 }
00481 
00482 
00483 void GlobalMasterTcl::initialize() {
00484   DebugM(4,"Initializing master\n");
00485 #ifdef NAMD_TCL
00486   DebugM(1,"here\n");
00487   if(Node::Object() == NULL) NAMD_die("Node::Object() == NULL");
00488   if(Node::Object()->getScript() == NULL)
00489     NAMD_die("Node::Object()->getScript() == NULL");
00490 
00491   interp = Node::Object()->getScript()->interp;
00492   DebugM(1,"here\n");
00493   Tcl_CreateCommand(interp, "atomid", Tcl_atomid,
00494     (ClientData) (Node::Object()->molecule), (Tcl_CmdDeleteProc *) NULL);
00495   Tcl_CreateCommand(interp, "vecadd", proc_vecadd,
00496     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
00497   Tcl_CreateCommand(interp, "vecsub", proc_vecsub,
00498     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
00499   Tcl_CreateCommand(interp, "vecscale", proc_vecscale,
00500     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
00501   Tcl_CreateCommand(interp, "getbond", proc_getbond,
00502     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
00503   Tcl_CreateCommand(interp, "getangle", proc_getangle,
00504     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
00505   Tcl_CreateCommand(interp, "getdihedral", proc_getdihedral,
00506     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
00507   Tcl_CreateCommand(interp, "anglegrad", proc_anglegrad,
00508     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
00509   Tcl_CreateCommand(interp, "dihedralgrad", proc_dihedralgrad,
00510     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
00511 
00512   DebugM(1,"here\n");
00513   // Call interpreter to determine requested atoms
00514   Tcl_CreateCommand(interp, "addatom", Tcl_addatom,
00515     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00516   Tcl_CreateCommand(interp, "addgroup", Tcl_addgroup,
00517       (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00518 
00519   DebugM(1,"here\n");
00520   // Get the script
00521   StringList *script = Node::Object()->configList->find("tclForcesScript");
00522 
00523   DebugM(1,"here\n");
00524   for ( ; script; script = script->next ) {
00525     int code;
00526     DebugM(1,"here "<<script->data<<"\n");
00527     if ( strstr(script->data,"\n") ) {
00528        code = Tcl_Eval(interp,script->data);
00529     }
00530     else code = Tcl_EvalFile(interp,script->data);
00531     DebugM(1,"here\n");
00532     const char *result = Tcl_GetStringResult(interp);
00533     DebugM(1,"here\n");
00534     if (*result != 0) CkPrintf("TCL: %s\n",result);
00535     DebugM(1,"here\n");
00536     if (code != TCL_OK) {
00537       const char *errorInfo = Tcl_GetVar(interp,"errorInfo",0);
00538       NAMD_die(errorInfo);
00539     }
00540   }
00541 
00542   DebugM(1,"here\n");
00543   Tcl_DeleteCommand(interp, "addatom");
00544   Tcl_DeleteCommand(interp, "addgroup");
00545 
00546   Tcl_CreateObjCommand(interp, (char *)"loadforces", Tcl_loadforces,
00547     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00548   Tcl_CreateObjCommand(interp, (char *)"loadtotalforces", Tcl_loadtotalforces,
00549     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00550   Tcl_CreateObjCommand(interp, (char *)"loadcoords", Tcl_loadcoords,
00551     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00552   Tcl_CreateObjCommand(interp, (char *)"loadmasses", Tcl_loadmasses,
00553     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00554   Tcl_CreateObjCommand(interp, (char *)"addforce", Tcl_addforce,
00555     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00556   Tcl_CreateCommand(interp, (char *)"addenergy", Tcl_addenergy,
00557     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00558   Tcl_CreateCommand(interp, (char *)"reconfig", Tcl_reconfig,
00559       (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00560   Tcl_CreateCommand(interp, (char *)"clearconfig", Tcl_clearconfig,
00561       (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00562   Tcl_CreateCommand(interp, (char *)"addatom", Tcl_addatom,
00563     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00564   Tcl_CreateCommand(interp, (char *)"addgroup", Tcl_addgroup,
00565     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00566   Tcl_CreateCommand(interp, (char *)"getstep", Tcl_getstep,
00567     (ClientData) this, (Tcl_CmdDeleteProc *) NULL);
00568 #else
00569 
00570   NAMD_die("Sorry, tclForces is not available; built without TCL.");
00571 
00572 #endif
00573   DebugM(2,"done initializing master\n");
00574 }
00575 
00576 
00577 void GlobalMasterTcl::calculate() {
00578   DebugM(4,"Calculating forces on master\n");
00579 
00580   /* clear out the requested forces first! */
00581   modifyAppliedForces().resize(0);
00582   modifyForcedAtoms().resize(0);
00583   modifyGroupForces().setall(Vector(0,0,0));
00584 
00585 #ifdef NAMD_TCL
00586   // Call interpreter to calculate forces
00587 
00588   char cmd[129];  int code;
00589   strcpy(cmd,"calcforces");  code = Tcl_Eval(interp,cmd);
00590   const char *result = Tcl_GetStringResult(interp);
00591   if (*result != 0) CkPrintf("TCL: %s\n",result);
00592   if (code != TCL_OK) {
00593     const char *errorInfo = Tcl_GetVar(interp,"errorInfo",0);
00594     NAMD_die(errorInfo);
00595   }
00596 #endif
00597 
00598   reduction->submit();
00599 
00600 }

Generated on Fri Aug 29 04:07:40 2008 for NAMD by  doxygen 1.3.9.1