RE: AW: Tcl script for simulated tempering?

From: Radak, Brian K (bradak_at_anl.gov)
Date: Wed Mar 16 2016 - 10:17:07 CDT

Hi again,

So I finally figured all of this out - it was really a matter of understanding Tcl better than I did (which was not too well, apparently).

Using "source" just brings proc definitions into the current namespace, but the scope of global variables does not seem to transfer in a trivial fashion. I you use "callback" in a file and then source it, the call will fail at run time in the main script because the arrays that get populated will not exist. I was able to circumvent this by creating a package with its own namespace and then making my callback function exist in that namespace as well (so that the arrays it populates are also in that namespace). So something like this:

# create a new namespace in this file (can also add a package declaration up here)
namespace eval ::mynamespace {}

# callback function to get passed to NAMD
proc ::mynamespace::mycallback {labels values} {
  set ::mynamespace::energy_labels $labels
  set ::mynamespace::energy_values $values
}

# function that takes the callback data and populates a Tcl array in _this_ scope
proc ::mynamespace::store_energies {} {
  foreach label $::mynamespace::energy_labels values $::mynamespace::energy_values {
    set ::mynamespace::energy_array($label) $value
  }
}

proc my_special_run_function {args} {
  callback ::mynamespace::mycallback

   # do some stuff
   store_energies ;# calling this will populate ::mynamespace::energy_array with data from the last step
}

I'm sure this is not particularly brilliant programming and the paradigm (if there isn't a better one) has already been explained or explored by someone developing for NAMD, but I had not seen it before. Now that I know it is so straightforward I can develop all kinds of fun packages with custom functions! Hurray!

Brian Radak
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory

9700 South Cass Avenue, Bldg. 240
Argonne, IL 60439-4854
(630) 252-8643
brian.radak_at_anl.gov
________________________________
From: Norman Geist [norman.geist_at_uni-greifswald.de]
Sent: Wednesday, March 16, 2016 5:10 AM
To: namd-l_at_ks.uiuc.edu; Radak, Brian K
Subject: AW: AW: namd-l: Tcl script for simulated tempering?

Why don’t you just “source“ your generic set of commands to a basic namd.conf which does contain the callback routines?


Norman Geist

Von: owner-namd-l_at_ks.uiuc.edu [mailto:owner-namd-l_at_ks.uiuc.edu] Im Auftrag von Radak, Brian K
Gesendet: Dienstag, 15. März 2016 19:02
An: Norman Geist <norman.geist_at_uni-greifswald.de>; namd-l_at_ks.uiuc.edu
Betreff: RE: AW: namd-l: Tcl script for simulated tempering?

After some fooling about, I think I understand how the "callback" procedure works, although I have to say the manual is essentially useless on this area. I was able to extract the following from the replica exchange script:

#####
proc save_callback {labels values} {
  global saved_labels saved_values
  set saved_labels $labels
  set saved_values $values
}

proc save_array {} {
  global saved_labels saved_values saved_array
  puts $saved_labels
  foreach label $saved_labels value $saved_values {
    set saved_array($label) $value
  }
}

callback save_callback
#####

This is all well and good for a script that contains these commands, but I want to be able to load a generic set of commands from a different file and use them. This apparently breaks the global part of "saved_array", as that array no longer exists in the proper scope or else is not populated. I've tried mucking with Tcl namespaces and using the "variable" command instead of "global", but that does not seem to help.

Are there any solid example Tcl extensions for NAMD that actually produce a package? I'm trying to read off of ABF, but that looks like a very non-trivial example...

Brian Radak
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory

9700 South Cass Avenue, Bldg. 240
Argonne, IL 60439-4854
(630) 252-8643
brian.radak_at_anl.gov<mailto:brian.radak_at_anl.gov>
________________________________
From: Norman Geist [norman.geist_at_uni-greifswald.de]
Sent: Tuesday, March 15, 2016 10:21 AM
To: namd-l_at_ks.uiuc.edu<mailto:namd-l_at_ks.uiuc.edu>; Radak, Brian K
Subject: AW: AW: namd-l: Tcl script for simulated tempering?
Ah, sorry, misunderstood your question. I’m not actually familiar with the parallel tempering away from simple temperature replica exchange. If you can describe what you want to do exactly, we can likely give a better advice. Especially what is the difference to the conventional replica exchange method?

Norman Geist

Von: owner-namd-l_at_ks.uiuc.edu<mailto:owner-namd-l_at_ks.uiuc.edu> [mailto:owner-namd-l_at_ks.uiuc.edu] Im Auftrag von Brian Radak
Gesendet: Dienstag, 15. März 2016 14:14
An: Norman Geist <norman.geist_at_uni-greifswald.de<mailto:norman.geist_at_uni-greifswald.de>>; namd-l_at_ks.uiuc.edu<mailto:namd-l_at_ks.uiuc.edu>
Betreff: Re: AW: namd-l: Tcl script for simulated tempering?

Thanks for the reply - yes, that is definitely the main point. Unfortunately you described simulated annealing, whereas I want simulated tempering. Pointless semantics distinction? Probably.

Essentially I want to run hybrid MD/MC with the temperature changing along a fixed ladder using set statistical weights. I mostly just want to get a little bit better convergence out of some small alchemical calculations where some torsional barriers are rather important - and of course I want to avoid scaling this up to many many replicas in order to avoid a nail/sledge hammer situation.

Ultimately my main problem is that I'm not yet familiar with the specific ways that one can interact with the NAMD data (e.g. energy, volume) within Tcl. I can infer some of this from the parallel tempering (temperature replica exchange) script, but there's a lot of extra indexing, etc. in that example that I definitely do not need.

Cheers,
Brian
On 03/15/2016 02:53 AM, Norman Geist wrote:
For this purpose, you’d just need to understand that the namd inout script, is in fact a TCL script. So just leave out the numsteps parameter and do something like the following at the end of your namd conf:

[…]
set startT 10
set endT 300
set stepT 10
set perrun 1000000

set runs [expr floor(($endT-startT)/stepT)]
for {set i 0} {$i < $runs} {incr i} {
    langevintemp [expr $startT+($i*$stepT)]
    run $perrun
}

Norman Geist

Von: owner-namd-l_at_ks.uiuc.edu<mailto:owner-namd-l_at_ks.uiuc.edu> [mailto:owner-namd-l_at_ks.uiuc.edu] Im Auftrag von Radak, Brian K
Gesendet: Freitag, 11. März 2016 23:12
An: NAMD list ‎[namd-l_at_ks.uiuc.edu<mailto:namd-l_at_ks.uiuc.edu>]‎ <namd-l_at_ks.uiuc.edu><mailto:namd-l_at_ks.uiuc.edu>
Betreff: namd-l: Tcl script for simulated tempering?

Has anyone implemented a generic Tcl script for simulated tempering? I know that I could probably cannibalize the parallel tempering script for this purpose, but I'm not one to re-invent the wheel.

Thanks,
Brian

Brian Radak
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory

9700 South Cass Avenue, Bldg. 240
Argonne, IL 60439-4854
(630) 252-8643
brian.radak_at_anl.gov<mailto:brian.radak_at_anl.gov>

--
Brian Radak
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory

9700 South Cass Avenue, Bldg. 240
Argonne, IL 60439-4854
(630) 252-8643
brian.radak_at_anl.gov<mailto:brian.radak_at_anl.gov>

This archive was generated by hypermail 2.1.6 : Sun Dec 31 2017 - 23:20:14 CST