TCL Forces and Help on Script

From: Joshua D. Moore (jdmoore_at_unity.ncsu.edu)
Date: Thu Jul 06 2006 - 13:52:00 CDT

Hi,

I am getting close to getting my force output script correct. However, I
am now running into problems. I need to write the file in some sort of
binary format. It is going to be too big to write in ASCII.

In my example here, I have 192 atoms I am trying to write out fx,fy,and fz
for. I want to put them in some sort of dcd similar format, so I am
trying to do

fx(i), i = 1, numatoms
fy(i), i = 1, numatoms
fz(i), i = 1, numatoms

So the way I am currently trying to do this is with three 'for' loops.
This might be slow, but I am just trying to get it done for now.

I can write out the ASCII file fine, but when I try binary, I think I am
having trouble converting to strings. I am using 'f' which is supposed to
be single-precision floating point in the machine's native representation.

My error is

Reason: FATAL ERROR: expected floating-point number but got "$0.627131146684"
    while executing
"binary format f $fx"
    (procedure "calcforces" line 16)
    invoked from within
"calcforces"

It is putting a $ sign in front for some reason.

Thanks in advance for any help.

Here is my script.

tclforces on
tclForcesScript {

 # The IDS of the atoms

 set numatoms 192

 for {set i 1} {$i < $numatoms} {incr i 1} {
     addatom $i
     }

 proc calcforces {} {
    set filename "forces.txt"
    set fileID [open $filename "a"]

    set filename_check "forces_check.txt"
    set fileID_check [open $filename_check "a"]

    global numatoms

    loadtotalforces p

    for {set i 0} {$i < $numatoms} {incr i 1} {
    if {[array exists p]} {
    set f $p($i)
    set fx $[lindex $f 0]
    set outBinData $[binary format f $fx]
    fconfigure $fileID -translation binary
    puts -nonewline $fileID $outBinData

    puts $fileID_check $p($i)
    loadtotalforces p

    for {set i 0} {$i < $numatoms} {incr i 1} {
    if {[array exists p]} {
    set f $p($i)
    set fx $[lindex $f 0]
    set outBinData $[binary format f $fx]
    fconfigure $fileID -translation binary
    puts -nonewline $fileID $outBinData

    puts $fileID_check $p($i)
    }
    }

    for {set i 0} {$i < $numatoms} {incr i 1} {
    if {[array exists p]} {
    set f $p($i)
    set fy $[lindex $f 0]
    set outBinData $[binary format f $fy]
    fconfigure $fileID -translation binary
    puts -nonewline $fileID $outBinData
    }
    }

    for {set i 0} {$i < $numatoms} {incr i 1} {
    if {[array exists p]} {
    set f $p($i)
    set fz $[lindex $f 0]
    set outBinData $[binary format f $fz]
    fconfigure $fileID -translation binary
    puts -nonewline $fileID $outBinData
    }
    }

    close $fileID
    close $fileID_check
  }
}

--------------------------------------------------
Joshua D. Moore
Graduate Student
North Carolina State University
Department of Chemical and Biomolecular Engineering
Box 7905 Centennial Campus
Engineering Building I
911 Partners Way
Raleigh, NC 27695-7905
Phone: (919) 513-2051
Fax: (919) 513-2470
Email: jdmoore_at_unity.ncsu.edu
--------------------------------------------------

This archive was generated by hypermail 2.1.6 : Wed Feb 29 2012 - 15:42:18 CST