# Re: C codes for dihedral angle

• From: Renxiao Wang <renxiao()at()chem.ucla.edu>
• Subject: Re: C codes for dihedral angle
• Date: Thu, 27 Jan 2000 11:53:43 -0800 (PST)

``` Dear rajarshi,
I think you have already been overwhelmed by unrelevent answers. Here is
exactly what you want:
----------------------------------------------------------------------------
float Torsion_Angle(float p1[3], float p2[3], float p3[3], float p4[3])  {
int i;
float angle;
float v12[3],v23[3],v34[3],v1[3],v2[3],v3[3];
for(i=0;i<=2;i++)
{
v12[i]=p2[i]-p1[i];
v23[i]=p3[i]-p2[i];
v34[i]=p4[i]-p3[i];
}
Cross_Multiply(v12,v23,v1);
Cross_Multiply(v23,v34,v2);
angle=Angle_Of_Two_Vectors(v1,v2);
Cross_Multiply(v1,v2,v3);
if((v23[0]/v3[0]>0)||(v23[1]/v3[1]>0)||(v23[2]/v3[2])>0) return
angle;
else return -angle;  }
void Cross_Multiply(float v1[3], float v2[3], float result[3])  {
result[0]=v1[1]*v2[2]-v2[1]*v1[2];
result[1]=v1[2]*v2[0]-v2[2]*v1[0];
result[2]=v1[0]*v2[1]-v2[0]*v1[1];
return;  }
----------------------------------------------------------------------------
This is cut from my program LigBuilder. Hope it helps.
Best wishes,
Arthur
------------------------------------------------------------------------
| Dr. Renxiao Wang                                                     |
------------------------------------------------------------------------
| Department of Chemistry and Biochemistry | 3281 Sawtelle Blvd. #104  |
| University of California Los Angeles     | Los Angeles, CA90066      |
| Los Angeles, CA 90024                    | U.S.A                     |
| Phone: 310-8250269 (Lab)                 | Phone: 310-3904638 (Home) |
------------------------------------------------------------------------
| E-mail: renxiao()at()chem.ucla.edu                                        |
| WWW: http://zimbu.chem.ucla.edu/~arthur/
|
------------------------------------------------------------------------
```