Linker IT Software
Google
Web www.oraxcel.com
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
Dihedral angle Excel function (Read 3531 times)
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Dihedral angle Excel function
13.11.08 at 12:58:50
 
Dihedral angle Excel function
 
A dehedral angle is the angle between 2 planes. It is a useful quantity to compute in addition to bond lengths and bond angles when studying the structure of molecules.
 
In a molecule a dihedral angle tells you something about the bond in a chain of 4 atoms:  
A1-A2-A3-A4
 
Plane one is defined by A1, A2 and A2. Plane two is defined by A2, A3 and A4. In other words it tells you something about the bond between A2 and A3.
 
To calculate the dihedral angle you can use the following formula in Excel. As parameters four ranges are expected. Just select 3 adjecent cells where the x,y,z values are for the atom.
 
Code:
Public Function DihedralAngle(Atom1XYZ As Range, Atom2XYZ As Range, Atom3XYZ As Range, Atom4XYZ As Range) As Double
    Const PI = 3.14159265358979

    Dim d12 As Double
    Dim d13 As Double
    Dim d14 As Double
    Dim d23 As Double
    Dim d24 As Double
    Dim d34 As Double
    
    Dim P As Double
    Dim Q As Double
    
    Dim cosa As Double
    Dim rada As Double
    Dim dega As Double
    
    d12 = ((Atom2XYZ.Cells(, 1).Value - Atom1XYZ.Cells(, 1).Value) ^ 2 + (Atom2XYZ.Cells(, 2).Value - Atom1XYZ.Cells(, 2).Value) ^ 2 + (Atom2XYZ.Cells(, 3).Value - Atom1XYZ.Cells(, 3).Value) ^ 2) ^ 0.5
    d13 = ((Atom3XYZ.Cells(, 1).Value - Atom1XYZ.Cells(, 1).Value) ^ 2 + (Atom3XYZ.Cells(, 2).Value - Atom1XYZ.Cells(, 2).Value) ^ 2 + (Atom3XYZ.Cells(, 3).Value - Atom1XYZ.Cells(, 3).Value) ^ 2) ^ 0.5
    d14 = ((Atom4XYZ.Cells(, 1).Value - Atom1XYZ.Cells(, 1).Value) ^ 2 + (Atom4XYZ.Cells(, 2).Value - Atom1XYZ.Cells(, 2).Value) ^ 2 + (Atom4XYZ.Cells(, 3).Value - Atom1XYZ.Cells(, 3).Value) ^ 2) ^ 0.5
    d23 = ((Atom3XYZ.Cells(, 1).Value - Atom2XYZ.Cells(, 1).Value) ^ 2 + (Atom3XYZ.Cells(, 2).Value - Atom2XYZ.Cells(, 2).Value) ^ 2 + (Atom3XYZ.Cells(, 3).Value - Atom2XYZ.Cells(, 3).Value) ^ 2) ^ 0.5
    d24 = ((Atom4XYZ.Cells(, 1).Value - Atom2XYZ.Cells(, 1).Value) ^ 2 + (Atom4XYZ.Cells(, 2).Value - Atom2XYZ.Cells(, 2).Value) ^ 2 + (Atom4XYZ.Cells(, 3).Value - Atom2XYZ.Cells(, 3).Value) ^ 2) ^ 0.5
    d34 = ((Atom4XYZ.Cells(, 1).Value - Atom3XYZ.Cells(, 1).Value) ^ 2 + (Atom4XYZ.Cells(, 2).Value - Atom3XYZ.Cells(, 2).Value) ^ 2 + (Atom4XYZ.Cells(, 3).Value - Atom3XYZ.Cells(, 3).Value) ^ 2) ^ 0.5
    
    P = d12 * d12 * ((d23 * d23) + (d34 * d34) - (d24 * d24)) + (d23 * d23) * ((-d23 * d23) + (d34 * d34) + (d24 * d24)) + (d13 * d13) * ((d23 * d23) - (d34 * d34) + (d24 * d24)) - 2 * (d23 * d23) * (d14 * d14)
    Q = ((d12 + d23 + d13) * (d12 + d23 - d13) * (d12 - d23 + d13) * (-d12 + d23 + d13) * (d23 + d34 + d24) * (d23 + d34 - d24) * (d23 - d34 + d24) * (-d23 + d34 + d24)) ^ 0.5

    cosa = P / Q
    rada = WorksheetFunction.Acos(cosa)
    dega = rada * 180 / PI
	  
    DihedralAngle = dega
End Function
 


 
Example:
=dihedralangle(B23:D23,B17:D17,B21:D21,B19:D19)
Back to top
 
« Last Edit: 13.11.08 at 12:59:36 by Gerrit-Jan Linker »  

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1