NAMD
eabfTcl.C
Go to the documentation of this file.
1 //
2 // The extended adaptive biasing force method has been contributed to NAMD by the following authors:
3 //
4 // Haohao Fu and Christophe Chipot
5 // Laboratoire International Associ\'e
6 // Centre National de la Recherche Scientifique et University of Illinois at Urbana--Champaign
7 // Unit\'e Mixte de Recherche No. 7565, Universit\'e de Lorraine
8 // B.P. 70239, 54506 Vand\oe uvre-lès-Nancy cedex, France
9 //
10 // Copyright 2016, Centre National de la Recherche Scientifique
11 //
12 
13 #ifndef LINK_CPP
14 #define LINK_CPP
15 
16 #include "eabf.h"
17 #include "eabf1D.h"
18 #include "eabf2D.h"
19 #include "eabffunc.h"
20 
21 #ifdef NAMD_TCL
22 #include <tcl.h>
23 
29 
30 // the point to the runtime parseABF object
31 static eABF* parse = 0;
32 
33 // the interface to Tcl, startrun
34 static int Tcl_startrun(ClientData useless, Tcl_Interp* stupidTcl, int argc, Tcl_Obj *CONST objv[])
35 {
36  std::string* argv = new std::string[argc];
37  // the last objv is the dimension of free-energy surface
38  for(int i=0; i<argc; i++)
39  {
40  argv[i] = Tcl_GetString(objv[i]);
41  }
42 
43  // 1D eABF
44  if (eabffunc::chartoint(argv[argc - 1]) == 1)
45  {
46  parse = new eABF1D(eabffunc::chartodouble(argv[1]), // lowerboundary
47  eabffunc::chartodouble(argv[2]), // upperboundary
48  eabffunc::chartodouble(argv[3]), // width
49  eabffunc::chartodouble(argv[4]), //krestr
50  std::string(argv[5]), // outputfile
51  eabffunc::chartoint(argv[6]), // outputfreq
52  bool(eabffunc::chartoint(argv[7])), // restart
53  std::string(argv[8]), // inputfile
54  bool(eabffunc::chartoint(argv[9])), // outputgrad
55  eabffunc::chartoint(argv[10]), // gradfreq
56  eabffunc::chartodouble(argv[11])); // temperature
57  }
58 
59  // 2D eABF
60  if (eabffunc::chartoint(argv[argc - 1]) == 2)
61  {
62  parse = new eABF2D(eabffunc::chartodouble(argv[1]), // lowerboundary
63  eabffunc::chartodouble(argv[2]), // upperboundary
64  eabffunc::chartodouble(argv[3]), // width
65  eabffunc::chartodouble(argv[4]), // krestr
66  eabffunc::chartodouble(argv[5]), // lowerboundary2
67  eabffunc::chartodouble(argv[6]), // upperboundary2
68  eabffunc::chartodouble(argv[7]), // width2
69  eabffunc::chartodouble(argv[8]), // krestr2
70  std::string(argv[9]), // outputfile
71  eabffunc::chartoint(argv[10]), // outputfreq
72  bool(eabffunc::chartoint(argv[11])), // restart
73  std::string(argv[12]), // inputfile
74  bool(eabffunc::chartoint(argv[13])), // outputgrad
75  eabffunc::chartoint(argv[14]), // gradfreq
76  eabffunc::chartodouble(argv[15])); // temperature
77  }
78 
79  delete[] argv;
80  return TCL_OK;
81 }
82 
83 // the interface to tcl, updaterun
84 static int Tcl_updaterun(ClientData useless, Tcl_Interp* stupidTcl, int argc, Tcl_Obj *CONST argv[])
85 {
86  std::string colvar = Tcl_GetString(argv[1]);
87  parse->update(colvar);
88  return TCL_OK;
89 }
90 
91 // set col
92 static int Tcl_setcol(ClientData useless, Tcl_Interp* stupidTcl, int argc, Tcl_Obj *CONST argv[])
93 {
94  std::vector<int> cols;
95  for (int i = 1; i<argc; i++)
96  {
97  cols.push_back(eabffunc::chartoint(Tcl_GetString(argv[i])));
98  }
99  parse->setcolumn(cols);
100  return TCL_OK;
101 }
102 
103 // input: dimension lowerboundary upperboundary width outputfile file1 file2 ...
104 // or: dimension lowerboundary upperboundary width lowerboundary2 upperboundary2 width2 outputfile file1 file2...
105 static int Tcl_mergefile(ClientData useless, Tcl_Interp* stupidTcl, int argc, Tcl_Obj *CONST objv[])
106 {
107  std::string* argv = new std::string[argc];
108  // the last objv is the dimension of free-energy surface
109  for (int i = 0; i < argc; i++)
110  {
111  argv[i] = Tcl_GetString(objv[i]);
112  }
113 
114  // 1D eABF
115  if (eabffunc::chartoint(argv[1]) == 1)
116  {
117  parse = new eABF1D(eabffunc::chartodouble(argv[2]), // lowerboundary
118  eabffunc::chartodouble(argv[3]), // upperboundary
119  eabffunc::chartodouble(argv[4]), // width
120  0, //krestr
121  std::string(argv[5]), // outputfile
122  0, // outputfreq
123  0, // restart
124  "", // inputfile
125  0, // outputgrad
126  0, // gradfreq
127  0); // temperature
128 
129  // merge file
130  for (int i = 6; i < argc; i++)
131  {
132  parse->mergefile(argv[i], std::string(argv[5]));
133  }
134  }
135 
136  if (eabffunc::chartoint(argv[1]) == 2)
137  {
138  parse = new eABF2D(eabffunc::chartodouble(argv[2]), // lowerboundary
139  eabffunc::chartodouble(argv[3]), // upperboundary
140  eabffunc::chartodouble(argv[4]), // width
141  0, //krestr
142  eabffunc::chartodouble(argv[5]), // lowerboundary2
143  eabffunc::chartodouble(argv[6]), // upperboundary2
144  eabffunc::chartodouble(argv[7]), // width2
145  0, //krestr2
146  std::string(argv[8]), // outputfile
147  0, // outputfreq
148  0, // restart
149  "", // inputfile
150  0, // outputgrad
151  0, // gradfreq
152  0); //temperature
153 
154  // merge file
155  for (int i = 9; i < argc; i++)
156  {
157  parse->mergefile(argv[i], std::string(argv[8]));
158  }
159  }
160 
161  delete[] argv;
162  return TCL_OK;
163 }
164 
165 extern "C" int Eabf_Init(Tcl_Interp* stupidTcl)
166 {
167  // create Tcl process "startrun" and "updaterun"
168  Tcl_CreateObjCommand(stupidTcl, "startrun", Tcl_startrun, (ClientData)0, (Tcl_CmdDeleteProc*)0);
169  Tcl_CreateObjCommand(stupidTcl, "updaterun", Tcl_updaterun, (ClientData)0, (Tcl_CmdDeleteProc*)0);
170  Tcl_CreateObjCommand(stupidTcl, "mergefile", Tcl_mergefile, (ClientData)0, (Tcl_CmdDeleteProc*)0);
171  Tcl_CreateObjCommand(stupidTcl, "setcol", Tcl_setcol, (ClientData)0, (Tcl_CmdDeleteProc*)0);
172  Tcl_PkgProvide(stupidTcl, "Eabf", "1.0.0");
173 
174  Tcl_Eval(stupidTcl, "puts \"eABF [package require Eabf]\"");
175 
176  return TCL_OK;
177 }
178 
179 int eabf_static_init(Tcl_Interp *interp) {
180  Tcl_StaticPackage(0,"Eabf",Eabf_Init,0);
181  return Tcl_Eval(interp,"package ifneeded Eabf 1.0.0 {load {} Eabf}");
182 }
183 
184 #endif // NAMD_TCL
185 #endif // LINK_CPP
Definition: eabf.h:22
static int Tcl_startrun(ClientData useless, Tcl_Interp *stupidTcl, int argc, Tcl_Obj *CONST objv[])
Definition: eabfTcl.C:34
Definition: eabf2D.h:23
int Eabf_Init(Tcl_Interp *stupidTcl)
Definition: eabfTcl.C:165
static int Tcl_updaterun(ClientData useless, Tcl_Interp *stupidTcl, int argc, Tcl_Obj *CONST argv[])
Definition: eabfTcl.C:84
bool mergefile(const std::string &inputname, const std::string &outputname)
Definition: eabf.h:39
int chartoint(const std::string &c)
Definition: eabffunc.C:48
bool setcolumn(std::vector< int > col)
Definition: eabf.h:52
int eabf_static_init(Tcl_Interp *interp)
Definition: eabfTcl.C:179
static int Tcl_mergefile(ClientData useless, Tcl_Interp *stupidTcl, int argc, Tcl_Obj *CONST objv[])
Definition: eabfTcl.C:105
double chartodouble(const std::string &c)
Definition: eabffunc.C:57
static int Tcl_setcol(ClientData useless, Tcl_Interp *stupidTcl, int argc, Tcl_Obj *CONST argv[])
Definition: eabfTcl.C:92
virtual bool update(const std::string &)=0
Definition: eabf1D.h:23
static eABF * parse
Definition: eabfTcl.C:31