eabfTcl.C

Go to the documentation of this file.
00001 //
00002 // The extended adaptive biasing force method has been contributed to NAMD by the following authors:
00003 //
00004 //    Haohao Fu and Christophe Chipot
00005 //    Laboratoire International Associ\'e
00006 //    Centre National de la Recherche Scientifique et University of Illinois at Urbana--Champaign
00007 //    Unit\'e Mixte de Recherche No. 7565, Universit\'e de Lorraine
00008 //    B.P. 70239, 54506 Vand\oe uvre-lès-Nancy cedex, France
00009 //
00010 // Copyright 2016, Centre National de la Recherche Scientifique
00011 //
00012 
00013 #ifndef LINK_CPP
00014 #define LINK_CPP
00015 
00016 #include "eabf.h"
00017 #include "eabf1D.h"
00018 #include "eabf2D.h"
00019 #include "eabffunc.h"
00020 
00021 #ifdef NAMD_TCL
00022 #include <tcl.h>
00023 
00029 
00030 // the point to the runtime parseABF object
00031 static eABF* parse = 0;
00032 
00033 // the interface to Tcl, startrun
00034 static int Tcl_startrun(ClientData useless, Tcl_Interp* stupidTcl, int argc, Tcl_Obj *CONST objv[])
00035 {
00036     std::string* argv = new std::string[argc];
00037     // the last objv is the dimension of free-energy surface
00038     for(int i=0; i<argc; i++)
00039     {
00040         argv[i] = Tcl_GetString(objv[i]);
00041     }
00042 
00043         // 1D eABF
00044         if (eabffunc::chartoint(argv[argc - 1]) == 1)
00045     {
00046                 parse = new eABF1D(eabffunc::chartodouble(argv[1]),      // lowerboundary
00047                         eabffunc::chartodouble(argv[2]),      // upperboundary
00048                         eabffunc::chartodouble(argv[3]),      // width
00049                         eabffunc::chartodouble(argv[4]),    //krestr
00050                         std::string(argv[5]),             // outputfile
00051                         eabffunc::chartoint(argv[6]),         // outputfreq
00052                         bool(eabffunc::chartoint(argv[7])),   // restart
00053                         std::string(argv[8]),             // inputfile
00054                         bool(eabffunc::chartoint(argv[9])),  // outputgrad
00055                         eabffunc::chartoint(argv[10]),        // gradfreq
00056                         eabffunc::chartodouble(argv[11]));     // temperature
00057     }
00058 
00059         // 2D eABF
00060         if (eabffunc::chartoint(argv[argc - 1]) == 2)
00061     {
00062                 parse = new eABF2D(eabffunc::chartodouble(argv[1]),      // lowerboundary
00063                         eabffunc::chartodouble(argv[2]),      // upperboundary
00064                         eabffunc::chartodouble(argv[3]),      // width
00065                         eabffunc::chartodouble(argv[4]),      // krestr
00066                         eabffunc::chartodouble(argv[5]),      // lowerboundary2
00067                         eabffunc::chartodouble(argv[6]),      // upperboundary2
00068                         eabffunc::chartodouble(argv[7]),      // width2
00069                         eabffunc::chartodouble(argv[8]),       // krestr2
00070                         std::string(argv[9]),             // outputfile
00071                         eabffunc::chartoint(argv[10]),         // outputfreq
00072                         bool(eabffunc::chartoint(argv[11])),   // restart
00073                         std::string(argv[12]),             // inputfile
00074                         bool(eabffunc::chartoint(argv[13])),  // outputgrad
00075                         eabffunc::chartoint(argv[14]),        // gradfreq
00076                         eabffunc::chartodouble(argv[15]));     // temperature
00077     }
00078 
00079         delete[] argv;
00080     return TCL_OK;
00081 }
00082 
00083 // the interface to tcl, updaterun
00084 static int Tcl_updaterun(ClientData useless, Tcl_Interp* stupidTcl, int argc, Tcl_Obj *CONST argv[])
00085 {
00086         std::string colvar = Tcl_GetString(argv[1]);
00087         parse->update(colvar);
00088     return TCL_OK;
00089 }
00090 
00091 // set col
00092 static int Tcl_setcol(ClientData useless, Tcl_Interp* stupidTcl, int argc, Tcl_Obj *CONST argv[])
00093 {
00094         std::vector<int> cols;
00095         for (int i = 1; i<argc; i++)
00096         {
00097                 cols.push_back(eabffunc::chartoint(Tcl_GetString(argv[i])));
00098         }
00099         parse->setcolumn(cols);
00100         return TCL_OK;
00101 }
00102 
00103 // input: dimension lowerboundary upperboundary width outputfile file1 file2 ...
00104 // or: dimension lowerboundary upperboundary width lowerboundary2 upperboundary2 width2 outputfile file1 file2...
00105 static int Tcl_mergefile(ClientData useless, Tcl_Interp* stupidTcl, int argc, Tcl_Obj *CONST objv[])
00106 {
00107         std::string* argv = new std::string[argc];
00108         // the last objv is the dimension of free-energy surface
00109         for (int i = 0; i < argc; i++)
00110         {
00111                 argv[i] = Tcl_GetString(objv[i]);
00112         }
00113 
00114         // 1D eABF
00115         if (eabffunc::chartoint(argv[1]) == 1)
00116         {
00117                 parse = new eABF1D(eabffunc::chartodouble(argv[2]),      // lowerboundary
00118                         eabffunc::chartodouble(argv[3]),      // upperboundary
00119                         eabffunc::chartodouble(argv[4]),      // width
00120                         0,                                 //krestr
00121                         std::string(argv[5]),             // outputfile
00122                         0,         // outputfreq
00123                         0,   // restart
00124                         "",             // inputfile
00125                         0,  // outputgrad
00126                         0,        // gradfreq
00127                         0);    // temperature
00128 
00129                 // merge file
00130                 for (int i = 6; i < argc; i++)
00131                 {
00132                         parse->mergefile(argv[i], std::string(argv[5]));
00133                 }
00134         }
00135 
00136         if (eabffunc::chartoint(argv[1]) == 2)
00137         {
00138                 parse = new eABF2D(eabffunc::chartodouble(argv[2]),      // lowerboundary
00139                         eabffunc::chartodouble(argv[3]),      // upperboundary
00140                         eabffunc::chartodouble(argv[4]),      // width
00141                         0,                                  //krestr
00142                         eabffunc::chartodouble(argv[5]),      // lowerboundary2
00143                         eabffunc::chartodouble(argv[6]),      // upperboundary2
00144                         eabffunc::chartodouble(argv[7]),      // width2
00145                         0,                                 //krestr2
00146                         std::string(argv[8]),             // outputfile
00147                         0,         // outputfreq
00148                         0,   // restart
00149                         "",             // inputfile
00150                         0,  // outputgrad
00151                         0,   // gradfreq
00152                         0);        //temperature
00153 
00154                         // merge file 
00155                 for (int i = 9; i < argc; i++)
00156                 {
00157                         parse->mergefile(argv[i], std::string(argv[8]));
00158                 }
00159         }
00160 
00161         delete[] argv;
00162         return TCL_OK;
00163 }
00164 
00165 extern "C" int Eabf_Init(Tcl_Interp* stupidTcl)
00166 {
00167         // create Tcl process "startrun" and "updaterun"
00168         Tcl_CreateObjCommand(stupidTcl, "startrun", Tcl_startrun, (ClientData)0, (Tcl_CmdDeleteProc*)0);
00169         Tcl_CreateObjCommand(stupidTcl, "updaterun", Tcl_updaterun, (ClientData)0, (Tcl_CmdDeleteProc*)0);
00170         Tcl_CreateObjCommand(stupidTcl, "mergefile", Tcl_mergefile, (ClientData)0, (Tcl_CmdDeleteProc*)0);
00171         Tcl_CreateObjCommand(stupidTcl, "setcol", Tcl_setcol, (ClientData)0, (Tcl_CmdDeleteProc*)0);
00172         Tcl_PkgProvide(stupidTcl, "Eabf", "1.0.0");
00173 
00174         Tcl_Eval(stupidTcl, "puts \"eABF [package require Eabf]\"");
00175 
00176         return TCL_OK;
00177 }
00178 
00179 int eabf_static_init(Tcl_Interp *interp) {
00180   Tcl_StaticPackage(0,"Eabf",Eabf_Init,0);
00181   return Tcl_Eval(interp,"package ifneeded Eabf 1.0.0 {load {} Eabf}");
00182 }
00183 
00184 #endif // NAMD_TCL
00185 #endif // LINK_CPP

Generated on Sat Sep 23 01:17:13 2017 for NAMD by  doxygen 1.4.7