0

I am new in tcl programming and I need to write a script for vmd that calculates two distances between two couples of atoms and print them in an output file. I do not understand why measure can not take atom_1, etc. This is my script and thank you for your help

proc distance {distance_1 atom_1 atom_2 distance_2 atom_3 atom_4 output} {
    set outfile [open $output w]
    puts $outfile "frame, $distance_1, $distance_2"

    set nf [molinfo top get numframes]

    for {set i 0} {$i < $nf} {incr i} {
            set d1 [measure bond {$atom_1 $atom_2} frame $i]
            set d2 [measure bond {$atom_3 $atom_4} frame $i]
            puts $outfile "$i , $d1 , $d2"
    }
    close $outfile

    }
Jonny_92
  • 42
  • 9

1 Answers1

2

The problem here is:

measure bond {$atom_1 $atom_2} frame $i

The issue is that {} in Tcl actually means “quote this exactly, with no substitutions at all”. Instead of sending a list of two numbers in, it passes a list of two non-numbers (the literal strings $atom_1 and $atom_2).

The fix is to replace {$atom_1 $atom_2} with [list $atom_1 $atom_2].


Yes, proc and for and if make use of this behaviour. It's just that they pass things back to the Tcl interpreter engine as part of their execution.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215