-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractTorsion.java
36 lines (32 loc) · 1.39 KB
/
AbstractTorsion.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.io.*;
import org.apache.commons.math3.geometry.euclidean.threed.*;
/** This class represents a torsion angle. */
public abstract class AbstractTorsion implements Immutable, Serializable
{
/** for serialization */
public static final long serialVersionUID = 1L;
/**
* Returns the corresponding vector2-vector3 dihedral angle in degrees.
* @param vector1 position of atom1
* @param vector2 position of atom2
* @param vector3 position of atom3
* @param vector4 position of atom4
* @return the dihedral angle in degrees
*/
public static double getDihedralAngle(Vector3D vector1, Vector3D vector2, Vector3D vector3, Vector3D vector4)
{
Vector3D b1 = vector2.add(-1.0, vector1);
Vector3D b2 = vector3.add(-1.0, vector2);
Vector3D b3 = vector4.add(-1.0, vector3);
// make sure the vectors are not collinear
if (Vector3D.angle(b1,b2) == 0 || Vector3D.angle(b2,b3) == 0)
{
System.out.println("Warning! Collinear dihedral angle!");
return 0.0;
}
// compute dihedral angle
double term1 = Vector3D.dotProduct(b1.scalarMultiply( b2.getNorm() ), Vector3D.crossProduct(b2, b3) );
double term2 = Vector3D.dotProduct(Vector3D.crossProduct(b1, b2), Vector3D.crossProduct(b2, b3) );
return Math.toDegrees( Math.atan2(term1, term2) );
}
}