From: Andrés Morales (h.andres.m1986_at_gmail.com)
Date: Mon Apr 09 2012 - 12:45:44 CDT

Dear VMD Users:

I want to calculate the average angle between the lipid dipole vector (P-N
dipole vectors in DPPC headgroups ) and the bilayer normal. So I use
the following script:

proc angle_ave {sel1 sel2} {

global M_PI
set conv [expr 180.0/$M_PI]
set num1 [$sel1 num]
set sum 0
foreach atom1 [$sel1 get {x y z}] atom2 [$sel2 get {x y z}] {
set v [vecsub $atom2 $atom1]
set z1 [lindex $v 2]
                set theta [expr $conv * asin($z1 / [veclength $v] )]
set tilt [expr 90 - $theta ]
  set sum [expr $sum + $tilt]
return $tilt
}
set prom [expr $sum / $num1]
return $prom
}

set sel1 [atomselect top "lipids and resid 1 to 36 and name P "]
set sel2 [atomselect top "lipids and resid 1 to 36 and name N "]
set average [angle_ave $sel1 $sel2]

But it only returns the tilt angle value for the first lipid (resid 1).

Any suggestions?

Thanks a lot

Andres