proc frame_rmsd {selection frame1 frame2} { set mol [$selection molindex] # check the range set num [molinfo $mol get numframes] if {$frame1 < 0 || $frame1 >= $num || $frame2 < 0 || $frame2 >= $num} { error "frame_rmsd: frame number out of range" } # get the first coordinate set set sel1 [atomselect $mol [$selection text] frame $frame1] set coords1 [$sel1 get {x y z}] # get the second coordinate set set sel2 [atomselect $mol [$selection text] frame $frame2] set coords2 [$sel2 get {x y z}] # and compute the rmsd values set rmsd 0 foreach coord1 $coords1 coord2 $coords2 { set rmsd [expr $rmsd + [veclength2 [vecsub $coord2 $coord1]]] } # divide by the number of atoms and return the result return [expr $rmsd / ([$selection num] + 0.0)] }