Re: selection error in forces script

From: Olya Kravchenko (ovkrav_at_gmail.com)
Date: Tue Mar 08 2016 - 00:08:00 CST

To answer my own question: it seems that VMD expressions are not
applicable in this case. Here is a working script, in case someone
finds it useful:

set numatoms 200

set atoms {}
for { set i 1 } { $i <= $numatoms } { incr i } {
    lappend atoms $i
}
foreach atom $atoms {
    addatom $atom
}

set linaccel_namd [vecscale [expr 1.0/418.68] $linaccel]
print "linear acceleration imparted: ($linaccel) Ang*ps^-2"

proc calcforces { } {
    global atoms numatoms linaccel_namd
    loadcoords coords
    loadmasses masses

    foreach i $atoms {
        foreach {x y z} $coords($i) { ; }
        if { $z > 27.5 && $z < 37.5 } {
            set force [vecscale $masses($i) $linaccel_namd]
            addforce $atoms $force
        }
    }
}

On Tue, Mar 8, 2016 at 12:02 AM, Olya Kravchenko <ovkrav_at_gmail.com> wrote:
> Hi all,
>
> I have another question about applying constant forces. My system is a
> box of argon atoms, I would like to apply constant force in Z
> direction to atoms that pass through XY slab of certain thickness
> located at the center. Here is my script (this is to be called in
> .conf file):
>
> set sel [atomselect top all]
> set ailist [$sel get index]
> foreach i $ailist { addatom $i }
>
> set linaccel_namd [vecscale [expr 1.0/418.68] $linaccel]
> print "linear acceleration imparted: ($linaccel) Ang*ps^-2"
>
> proc calcforces { } {
> global ailist linaccel_namd
> loadcoords coords
> loadmasses masses
> foreach i $ailist {
> foreach {x y z} $coords($i) {;}
> if { $z > 27.5 and $z < 37.5} {
> set force [vecscale $masses($i) $linaccel_namd]
> addforce $atom $force
> }
> }
> }
>
> When I submit the job I am getting the following error:
>
> Reason: FATAL ERROR: wrong # args
> while executing "atomselect top all"
> invoked from within "set sel [atomselect top all]"
> (file "my_force1.tcl" line 1)
>
> Charm++ fatal error:
> FATAL ERROR: wrong # args
> while executing "atomselect top all" invoked from within
> "set sel [atomselect top all]"
> (file "my_force1.tcl" line 1)
>
> Why is it complaining about [atomselect top all]? I tried various ways
> to set this selection and when I make it an array (which I know makes
> no sense but I just wanted to proceed further and see if it complains
> about the next line) I see the same error message about second line
> (set ailist [$sel get index]). Can't figure out what is wrong with the
> syntax here. Help, please?
>

This archive was generated by hypermail 2.1.6 : Tue Dec 27 2016 - 23:21:50 CST