proc phi {i1 i2 i3 i4 fi} { set PI 3.14159265358979323846 set atoms [atomselect top "index $i1 $i2 $i3 $i4" frame $fi] set positions [$atoms get {x y z}] set rA [lindex $positions 0] set rB [lindex $positions 1] set rC [lindex $positions 2] set rD [lindex $positions 3] set one [expr -[vecdot [veccross [vecsub $rA $rB] [vecsub $rB $rC]] [veccross [vecsub $rB $rC] [vecsub $rC $rD]]] / ([veclength [veccross [vecsub $rA $rB] [vecsub $rB $rC]]] * [veclength [veccross [vecsub $rB $rC] [vecsub $rC $rD]]])] if {$one > 1.0 || $one < -1.0} { set one [expr $one / $one] } set phi [expr acos($one) * 180 / $PI - 180] return [list $phi] } proc allphi {i1 i2 i3 i4 i5} { set nf [molinfo top get numframes] set outfile [open angles.txt w] puts $outfile "ith phi psi" for {set i 0} {$i < $nf} {incr i} { set A1 [phi $i1 $i2 $i3 $i4 $i] set A2 [phi $i2 $i3 $i4 $i5 $i] puts $outfile "$i $A1 $A2" } close $outfile }