00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * RCS INFORMATION: 00011 * 00012 * $RCSfile: tcl_commands.C,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.58 $ $Date: 2022年01月20日 18:45:59 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * Fundamental VMD Tcl text commands 00019 ***************************************************************************/ 00020 00021 #include <stdlib.h> 00022 #include <string.h> 00023 #include "c_compiler.h" 00024 #include "tcl.h" 00025 #include "TclCommands.h" 00026 #include "tcl_commands.h" 00027 #include "config.h" 00028 #include "utilities.h" 00029 #include "CUDAKernels.h" 00030 #include "WKFThreads.h" 00031 #include "vmd.h" 00032 #if defined(VMDCOLVARS) 00033 #include "colvarproxy_vmd.h" 00034 #endif 00035 00036 00037 class VMDApp; 00038 00039 #define SIMPLE_TCL_OPT(string,result) \ 00040 if (!strcmp(argv[1], string)) { \ 00041 Tcl_AppendResult(interp, result, NULL); \ 00042 return TCL_OK; \ 00043 } 00044 00045 static int vmdinfo_tcl(ClientData, Tcl_Interp *interp, 00046 int argc, const char *argv[]) { 00047 VMDApp *app = (VMDApp *)Tcl_GetAssocData(interp, "VMDApp", NULL); 00048 00049 if (argc == 2) { 00050 SIMPLE_TCL_OPT("version", VMDVERSION); 00051 SIMPLE_TCL_OPT("versionmsg", VERSION_MSG); 00052 SIMPLE_TCL_OPT("authors", VMD_AUTHORS); 00053 SIMPLE_TCL_OPT("arch", VMD_ARCH); 00054 SIMPLE_TCL_OPT("options", VMD_OPTIONS); 00055 SIMPLE_TCL_OPT("www", VMD_HOMEPAGE); 00056 SIMPLE_TCL_OPT("wwwhelp", VMD_HELPPAGE); 00057 00058 // return the C++ compiler language standard/level used 00059 if (!strcmp(argv[1], "compilers")) { 00060 const char *ccversion = c_compiler_std(); 00061 00062 #if (__cplusplus >= 202002L) 00063 const char *cxxversion = "C++ 2020"; 00064 #elif (__cplusplus >= 201703L) 00065 const char *cxxversion = "C++ 2017"; 00066 #elif (__cplusplus >= 201402L) 00067 const char *cxxversion = "C++ 2014"; 00068 #elif (__cplusplus >= 201103L) 00069 const char *cxxversion = "C++ 2011"; 00070 #elif (__cplusplus >= 199711L) 00071 const char *cxxversion = "C++ 2003"; 00072 #else 00073 const char *cxxversion = "C++ 1998"; 00074 #endif 00075 00076 Tcl_Obj *tcl_result = Tcl_NewListObj(0, NULL); 00077 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewStringObj(ccversion, strlen(ccversion))); 00078 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewStringObj(cxxversion, strlen(cxxversion))); 00079 Tcl_SetObjResult(interp, tcl_result); 00080 return TCL_OK; 00081 } 00082 00083 00084 // return the estimated amount of available physical memory 00085 if (!strcmp(argv[1], "freemem")) { 00086 long vmdcorefree = vmd_get_avail_physmem_mb(); 00087 Tcl_Obj *tcl_result = Tcl_NewListObj(0, NULL); 00088 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewIntObj(vmdcorefree)); 00089 Tcl_SetObjResult(interp, tcl_result); 00090 return TCL_OK; 00091 } 00092 00093 00094 // return the number of available CPU cores 00095 if (!strcmp(argv[1], "numcpus")) { 00096 #if defined(VMDTHREADS) 00097 int numcpus = wkf_thread_numprocessors(); 00098 #else 00099 int numcpus = 1; 00100 #endif 00101 Tcl_Obj *tcl_result = Tcl_NewListObj(0, NULL); 00102 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewIntObj(numcpus)); 00103 Tcl_SetObjResult(interp, tcl_result); 00104 return TCL_OK; 00105 } 00106 00107 00108 // return the CPU affinity list for the VMD process 00109 if (!strcmp(argv[1], "cpuaffinity")) { 00110 int numcpus = -1; 00111 int *cpuaffinitylist = NULL; 00112 00113 #if defined(VMDTHREADS) 00114 cpuaffinitylist = wkf_cpu_affinitylist(&numcpus); 00115 #endif 00116 if (numcpus > 0 && cpuaffinitylist != NULL) { 00117 int i; 00118 Tcl_Obj *tcl_result = Tcl_NewListObj(0, NULL); 00119 for (i=0; i<numcpus; i++) 00120 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewIntObj(cpuaffinitylist[i])); 00121 Tcl_SetObjResult(interp, tcl_result); 00122 return TCL_OK; 00123 } 00124 00125 if (cpuaffinitylist != NULL) 00126 free(cpuaffinitylist); 00127 00128 Tcl_AppendResult(interp, "CPU affinity query unavailable on this platform", NULL); 00129 return TCL_ERROR; 00130 } 00131 00132 00133 // return the number of available CUDA devices 00134 if (!strcmp(argv[1], "numcudadevices")) { 00135 int numdevices; 00136 #if defined(VMDCUDA) 00137 vmd_cuda_num_devices(&numdevices); 00138 #else 00139 numdevices = 0; 00140 #endif 00141 Tcl_Obj *tcl_result = Tcl_NewListObj(0, NULL); 00142 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewIntObj(numdevices)); 00143 Tcl_SetObjResult(interp, tcl_result); 00144 return TCL_OK; 00145 } 00146 00147 // return the active display device (e.g. "text", "win", "cave", ...) 00148 if (!strcmp(argv[1], "dispdev")) { 00149 const char *disp = VMDgetDisplayTypeName(); 00150 Tcl_AppendResult(interp, disp, NULL); 00151 return TCL_OK; 00152 } 00153 00154 // return the MPI node name 00155 if (!strcmp(argv[1], "nodename")) { 00156 Tcl_Obj *tcl_result = Tcl_NewListObj(0, NULL); 00157 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewStringObj(app->par_name(), strlen(app->par_name()))); 00158 Tcl_SetObjResult(interp, tcl_result); 00159 return TCL_OK; 00160 } 00161 00162 // return the MPI node rank 00163 if (!strcmp(argv[1], "noderank")) { 00164 Tcl_Obj *tcl_result = Tcl_NewListObj(0, NULL); 00165 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewIntObj(app->par_rank())); 00166 Tcl_SetObjResult(interp, tcl_result); 00167 return TCL_OK; 00168 } 00169 00170 // return the MPI node count 00171 if (!strcmp(argv[1], "nodecount")) { 00172 Tcl_Obj *tcl_result = Tcl_NewListObj(0, NULL); 00173 Tcl_ListObjAppendElement(interp, tcl_result, Tcl_NewIntObj(app->par_size())); 00174 Tcl_SetObjResult(interp, tcl_result); 00175 return TCL_OK; 00176 } 00177 } 00178 00179 Tcl_AppendResult(interp, 00180 "vmdinfo: version | versionmsg | authors | arch | \n" 00181 "freemem | numcpus | cpuaffinity | numcudadevices | \n" 00182 "dispdev | nodename | noderank | nodecount | \n" 00183 "options | www | wwwhelp", NULL); 00184 return TCL_ERROR; 00185 } 00186 00187 00188 int Vmd_Init(Tcl_Interp *interp) { 00189 VMDApp *app = (VMDApp *)Tcl_GetAssocData(interp, "VMDApp", NULL); 00190 00191 // 00192 // Tcl string-based command bindings 00193 // 00194 Tcl_CreateCommand(interp, "animate", text_cmd_animate, 00195 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00196 00197 Tcl_CreateCommand(interp, "axes", text_cmd_axes, 00198 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00199 00200 Tcl_CreateCommand(interp, "color", text_cmd_color, 00201 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00202 00203 Tcl_CreateCommand(interp, "display", text_cmd_display, 00204 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00205 00206 Tcl_CreateCommand(interp, "imd", text_cmd_imd, 00207 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00208 00209 Tcl_CreateCommand(interp, "light", text_cmd_light, 00210 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00211 00212 #ifdef VMDPYTHON 00213 Tcl_CreateCommand(interp, "gopython", text_cmd_gopython, 00214 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00215 #endif 00216 00217 Tcl_CreateCommand(interp, "material", text_cmd_material, 00218 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00219 00220 Tcl_CreateCommand(interp, "mobile", text_cmd_mobile, 00221 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00222 00223 Tcl_CreateCommand(interp, "mol", text_cmd_mol, 00224 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00225 00226 Tcl_CreateCommand(interp, "molecule", text_cmd_mol, 00227 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00228 00229 Tcl_CreateCommand(interp, "mouse", text_cmd_mouse, 00230 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00231 00232 Tcl_CreateCommand(interp, "parallel", text_cmd_parallel, 00233 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00234 00235 Tcl_CreateCommand(interp, "plugin", text_cmd_plugin, 00236 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00237 00238 Tcl_CreateCommand(interp, "pointlight", text_cmd_point_light, 00239 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00240 00241 Tcl_CreateCommand(interp, "profile", text_cmd_profile, 00242 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00243 00244 Tcl_CreateCommand(interp, "render", text_cmd_render, 00245 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00246 00247 Tcl_CreateCommand(interp, "rock", text_cmd_rock, 00248 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00249 00250 Tcl_CreateCommand(interp, "rotate", text_cmd_rotate, 00251 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00252 00253 Tcl_CreateCommand(interp, "rotmat", text_cmd_rotmat, 00254 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00255 00256 Tcl_CreateCommand(interp, "sleep", text_cmd_sleep, 00257 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00258 00259 Tcl_CreateCommand(interp, "spaceball", text_cmd_spaceball, 00260 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00261 00262 Tcl_CreateCommand(interp, "stage", text_cmd_stage, 00263 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00264 00265 #if defined(VMDTK) && !defined(_MSC_VER) 00266 Tcl_CreateCommand(interp, "tkrender", text_cmd_tkrender, 00267 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00268 #endif 00269 00270 Tcl_CreateCommand(interp, "tool", text_cmd_tool, 00271 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00272 00273 Tcl_CreateCommand(interp, "translate", text_cmd_translate, 00274 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00275 00276 Tcl_CreateCommand(interp, "user", text_cmd_user, 00277 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00278 00279 Tcl_CreateCommand(interp, "vmd_label", text_cmd_label, 00280 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00281 00282 Tcl_CreateCommand(interp, "vmd_menu", text_cmd_menu, 00283 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00284 00285 Tcl_CreateCommand(interp, "vmd_scale", text_cmd_scale, 00286 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00287 00288 Tcl_CreateCommand(interp, "videostream", text_cmd_videostream, 00289 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00290 00291 Tcl_CreateCommand(interp, "vmdbench", text_cmd_vmdbench, 00292 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00293 00294 Tcl_CreateCommand(interp, "vmdcollab", text_cmd_collab, 00295 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00296 00297 Tcl_CreateCommand(interp, "vmdinfo", vmdinfo_tcl, 00298 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); 00299 00300 00301 // 00302 // Tcl object-based command bindings 00303 // 00304 #if defined(VMDCOLVARS) 00305 Tcl_CreateObjCommand(interp, "colvars", tcl_colvars, (ClientData) app, (Tcl_CmdDeleteProc*) NULL); 00306 Tcl_CreateObjCommand(interp, "cv", tcl_colvars, (ClientData) app, (Tcl_CmdDeleteProc*) NULL); 00307 Tcl_PkgProvide (interp, "colvars", COLVARS_VERSION); 00308 #endif 00309 00310 #if 0 00311 Tcl_CreateObjCommand(interp, "fastpbc", obj_fastpbc, 00312 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00313 #endif 00314 00315 Tcl_CreateObjCommand(interp, "graphlayout", obj_graphlayout, 00316 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00317 00318 Tcl_CreateObjCommand(interp, "gettimestep", cmd_gettimestep, 00319 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00320 00321 Tcl_CreateObjCommand(interp, "mdffi", obj_mdff_cc, 00322 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00323 00324 Tcl_CreateObjCommand(interp, "voltool", obj_voltool, 00325 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00326 00327 Tcl_CreateObjCommand(interp, "measure", obj_measure, 00328 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00329 00330 Tcl_CreateObjCommand(interp, "rawtimestep", cmd_rawtimestep, 00331 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00332 00333 Tcl_CreateObjCommand(interp, "segmentation", obj_segmentation, 00334 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00335 00336 #if defined(VMDTKCON) 00337 Tcl_CreateObjCommand(interp,"vmdcon", tcl_vmdcon, 00338 (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 00339 #endif 00340 00341 #if 0 00342 Tcl_CreateObjCommand(interp, "volgradient", obj_volgradient, 00343 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00344 #endif 00345 00346 Tcl_CreateObjCommand(interp, "volmap", obj_volmap, 00347 (ClientData) app, (Tcl_CmdDeleteProc *) NULL); 00348 00349 return TCL_OK; 00350 } 00351