From: John Stone (johns_at_ks.uiuc.edu)
Date: Wed Apr 11 2012 - 14:06:52 CDT

Hi,
  The source of your problem is that you are calling "return" in your loop,
therefor the loop terminates after it runs for the first time. The second
"return" call will never be reached since the first one will end the proc.
Both versions of the script you sent have that same problem. If you
want to return results for each lipid, you need to create a list of
results adding to the end with "lappend" each time through.

Cheers,
  John Stone
  vmd_at_ks.uiuc.edu

On Mon, Apr 09, 2012 at 12:45:44PM -0500, Andrés Morales wrote:
> 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

-- 
NIH Resource for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
http://www.ks.uiuc.edu/~johns/           Phone: 217-244-3349
http://www.ks.uiuc.edu/Research/vmd/       Fax: 217-244-6078