From: Tristan Croll (tristan.croll_at_qut.edu.au)
Date: Sun Nov 15 2015 - 20:22:38 CST

I see the file attachment is still stripped out. Well, if anyone wants to play with it feel free to email me for a copy.

-----Original Message-----
From: owner-vmd-l_at_ks.uiuc.edu [mailto:owner-vmd-l_at_ks.uiuc.edu] On Behalf Of Tristan Croll
Sent: Monday, 16 November 2015 10:46 AM
To: John Stone
Cc: vmd-l_at_ks.uiuc.edu
Subject: Re: vmd-l: Re: namd-l: On-the-fly modification of tclforces script?

OK, pretty much as expected that one was riddled with errors, but this version (attached as .txt since the server seems to have stripped out the .C attachment from my previous email) compiles and works as expected after making the following changes to other files:

tcl_commands.h, line 29:
extern int text_cmd_imd(ClientData, Tcl_Interp *, int, const char *[]);

becomes

extern int text_cmd_imd(ClientData, Tcl_Interp *, int, Tcl_Obj *const[]);

tcl_commands.C, line 182:

Tcl_CreateCommand(interp, "imd", text_cmd_imd,

becomes

Tcl_CreateObjCommand(interp, "imd", text_cmd_imd,

When a simulation is running, the command

imd impulse 10 {0 100 0}

will give an instantaneous force on atom 10 along the y axis. Rather fun to watch, actually...

Cheers,

Tristan

________________________________________
From: Tristan Croll
Sent: Sunday, 15 November 2015 8:32 PM
To: John Stone
Cc: vmd-l_at_ks.uiuc.edu
Subject: Re: vmd-l: Re: namd-l: On-the-fly modification of tclforces script?

Hi John,

I think this will do what I'm after, but I'd appreciate it if you (or anyone else who might be interested) could give it a once-over. My main change is the addition of the "impulse" case (lines 149-175) - but in order to add that I had to re-cast argv from char to Tcl_Obj (to correctly handle the force vector) and change all the other cases accordingly. Considering that I'm learning the fundamentals of C++ syntax as I go, it's entirely possible I did something (or multiple somethings) wrong. If I've done it correctly, then the command

imd impulse <index> <force vector>

should append the atom index and force to the list to be applied at the next timestep. It would also be trivial to add an equivalent command, say

imd tug ...

to instead add them to the persistent force list.

Thanks,

Tristan

________________________________________
From: John Stone <johns_at_ks.uiuc.edu>
Sent: Sunday, 15 November 2015 1:51 AM
To: Tristan Croll
Cc: vmd-l_at_ks.uiuc.edu
Subject: Re: vmd-l: Re: namd-l: On-the-fly modification of tclforces script?

Tristan,
  Hmm, I had thought we also had an existing scheme to set them, but I may be remembering something that had been a hack/prototype and not in the production versions of VMD. I'm out of town at the annual Supercomputing conference until next Friday, but when I get back to the lab I would be happy to look into this more closely. In the mean time, I'd suggest you keep playing around with the code.

Cheers,
  John

On Sat, Nov 14, 2015 at 04:55:11AM +0000, Tristan Croll wrote:
> OK, if I understand correctly (which is entirely possible - my knowledge of C++ remains quite fuzzy), the uf[xyz] variables are effectively just read-outs of the forces being applied in IMD. In GeometryMol.C we have:
>
> 00148 if (ts != NULL) {
> 00149 if (ts->force != NULL) {
> 00150 float ufx = ts->force[ind*3 ];
> 00151 float ufy = ts->force[ind*3 + 1];
> 00152 float ufz = ts->force[ind*3 + 2];
> 00153 totalforce = sqrtf(ufx*ufx + ufy*ufy + ufz*ufz);
> 00154 }
>
> which is what sets them, but they don't go back in the other
> direction. Meanwhile, in Molecule.C we have
>
> 00132 // If an IMD simulation is in progress, store the forces in the current
> 00133 // timestep and send them to the simulation. Otherwise, just toss them.
> 00134 if (app->imd_connected(id())) {
> 00135 // Add persistent forces to regular forces
> 00136 force_indices.appendlist(&persistent_force_indices[0], persistent_force_indices.num());
> 00137 force_vectors.appendlist(&persistent_force_vectors[0], persistent_force_vectors.num());
> 00138
> 00139 // Clear old forces out of the timestep
> 00140 Timestep *ts = current();
> 00141 if (ts && ts->force) {
> 00142 memset(ts->force, 0, 3*nAtoms*sizeof(float));
> 00143 }
>
> The forces that actually get applied to the simulation are wiped and re-calculated each timestep, re-setting uf[xyz] in the process. So at present it doesn't seem possible to apply forces to a simulation from TCL.
>
> Cheers,
>
> Tristan
>
> ________________________________________
> From: Tristan Croll
> Sent: Saturday, 14 November 2015 2:20 PM
> To: John Stone
> Cc: vmd-l_at_ks.uiuc.edu
> Subject: Re: vmd-l: Re: namd-l: On-the-fly modification of tclforces script?
>
> Hi John,
>
> Looks like I should clarify that. $sel set ufx works exactly as expected in a static molecule, or in an IMD simulation that has been prepped but is not yet connected to NAMD. The moment I connect to NAMD the command stops doing anything, even if the simulation is paused.
>
> Thanks,
>
> Tristan
>
> ________________________________________
> From: Tristan Croll
> Sent: Saturday, 14 November 2015 1:24 PM
> To: John Stone
> Cc: vmd-l_at_ks.uiuc.edu
> Subject: Re: vmd-l: Re: namd-l: On-the-fly modification of tclforces script?
>
> Hi John,
>
> Essentially, I'm just looking for a neat way to force specific configurations within the context of a running IMD simulation. For example, to force a section of backbone into a helix, or to induce a specific rotamer. I want to be able to do this on-the-fly, without stopping and generating a new simulation configuration, hence the need for a scripted approach.
>
> The uf[xyz] keywords seem ideal in principle, but I can't seem to set them through the TCL interface. The following commands:
>
> set sel [atomselect top "residue 1"]
> $sel set ufx 1
> $sel get ufx
>
> don't throw any errors, but the last command returns an array of zeros. The get command works correctly when I manually apply forces with the mouse, but as far as I can see set currently does nothing for these keywords.
>
> Thanks,
>
> Tristan
>
> ________________________________________
> From: John Stone <johns_at_ks.uiuc.edu>
> Sent: Saturday, 14 November 2015 12:17 PM
> To: Tristan Croll
> Cc: Jim Phillips; namd-l_at_ks.uiuc.edu; vmd-l_at_ks.uiuc.edu
> Subject: Re: vmd-l: Re: namd-l: On-the-fly modification of tclforces script?
>
> Okay. Try uf[xyz] and let me know if you need something different to
> achieve whatever it is you're after.
>
> Cheers,
> John
>
> On Sat, Nov 14, 2015 at 01:28:39AM +0000, Tristan Croll wrote:
> > Only in the fact that I was ignorant of their existence, by the looks of things. Well, that makes life easier...
> >
> >
> >
> > Tristan Croll
> > Lecturer
> > Faculty of Health
> > School of Biomedical Sciences
> > Institute of Health and Biomedical Engineering Queensland University
> > of Technology
> > 60 Musk Ave
> > Kelvin Grove QLD 4059 Australia
> > +61 7 3138 6443
> >
> > This email and its attachments (if any) contain confidential information intended for use by the addressee and may be privileged. We do not waive any confidentiality, privilege or copyright associated with the email or the attachments. If you are not the intended addressee, you must not use, transmit, disclose or copy the email or any attachments. If you receive this email by mistake, please notify the sender immediately and delete the original email.
> >
> >
> >
> > > On 14 Nov 2015, at 11:05 am, John Stone <johns_at_ks.uiuc.edu> wrote:
> > >
> > > Tristan,
> > > Since I don't have much context from the prior discussion, how
> > > does this differ from setting ufx/ufy/ufz in VMD?
> > >
> > > Cheers,
> > > John
> > >
> > >> On Sat, Nov 14, 2015 at 12:14:28AM +0000, Tristan Croll wrote:
> > >> Something like:
> > >>
> > >> imd impulse <mol> <index> <force vector>
> > >>
> > >> as a simple wrapper for addForce would add a lot of flexibility.
> > >>
> > >> Cheers,
> > >>
> > >> Tristan
> > >>
> > >>
> > >> ________________________________________
> > >> From: Tristan Croll
> > >> Sent: Saturday, 14 November 2015 8:48 AM
> > >> To: Jim Phillips; namd-l_at_ks.uiuc.edu; Tristan Croll
> > >> Cc: vmd-l_at_ks.uiuc.edu
> > >> Subject: Re: namd-l: On-the-fly modification of tclforces script?
> > >>
> > >> Hi again,
> > >>
> > >> Before seriously getting into this, I'm thinking it would be more elegant (and long-term useful) to make Molecule::addforce (from Molecule.C) available as a TCL command in VMD. On the downside, the added forces would have to be calculated (or at least re-applied) at each step in VMD, but on the plus side there's no file i/o involved. What do you think?
> > >>
> > >> Thanks,
> > >>
> > >> Tristan
> > >>
> > >> ________________________________________
> > >> From: owner-namd-l_at_ks.uiuc.edu <owner-namd-l_at_ks.uiuc.edu> on
> > >> behalf of Tristan Croll <tristan.croll_at_qut.edu.au>
> > >> Sent: Wednesday, 11 November 2015 8:03 AM
> > >> To: Jim Phillips; namd-l_at_ks.uiuc.edu
> > >> Subject: Re: namd-l: On-the-fly modification of tclforces script?
> > >>
> > >> Thanks Jim. I'll start tinkering with that.
> > >>
> > >> ________________________________________
> > >> From: Jim Phillips <jim_at_ks.uiuc.edu>
> > >> Sent: Wednesday, 11 November 2015 1:53 AM
> > >> To: namd-l_at_ks.uiuc.edu; Tristan Croll
> > >> Subject: Re: namd-l: On-the-fly modification of tclforces script?
> > >>
> > >> Hi Tristan,
> > >>
> > >> In NAMD 2.11b1 you can do the following:
> > >>
> > >> tclForces on
> > >> tclForcesScript {
> > >> }
> > >> startup
> > >> while ( 1 ) {
> > >> clearconfig ; # drop previously requested atoms
> > >> source forcescript.tcl
> > >> run 200
> > >> }
> > >>
> > >> The main function of the tclForcesScript is to delay tclForces
> > >> setup until after startup has progressed far enough to process atom lookup commands.
> > >> You can give it /dev/null or an inline script with at least one
> > >> newline as above. I could make tclForcesScript optional, but I
> > >> think keeping it mandatory results in clearer error messages for new users.
> > >>
> > >> The "startup" command is like "run 0" without the force
> > >> calculation, so it won't notice that you haven't defined a
> > >> calcforces proc. Without the "startup" command you would need to do this:
> > >>
> > >> tclForces on
> > >> tclForcesScript {
> > >> proc calcforces {} { }
> > >> }
> > >> run 0
> > >> .
> > >>
> > >> Note that in 2.11b1 if you want total forces on atoms/groups you
> > >> need to explicitly request them. For backwards compatibility use "catch":
> > >>
> > >> tclForces on
> > >> tclForcesScript {
> > >> catch { enabletotalforces }
> > >> proc calcforces {} { }
> > >> }
> > >>
> > >> Also, since you're hoping to push updates from VMD, you at least
> > >> need to use an atomic filesystem operation like rename to update
> > >> forcescript.tcl so NAMD doesn't see an incomplete file, or you
> > >> could use sockets. For an example see the file lib/replica/namd_replica_server.tcl in NAMD 2.8