示例#1
0
 def test_normalisation(self):
     r = np.random.rand(100,3)
     
     n = norm_vect(r)
     d = dot_product(n,n)
     
     ones = np.ones((100))
     
     assert_almost_equal(d, ones, 8, err_msg="Your vectors don't normalise too well")
示例#2
0
def dihedral_calc(r1, r2, r3, r4):
    """
    This function calculates the  angle made by the vectors normal
    to the planes made by r1, r2, r3 and r2, r3, r4. 

    Each of the positions is assumed to be a 3 by n array for 
    n lists of dihedral sets

    r1
     \ 
      \
       r2---r3
              \
               \
               r4

    The angle for dihedral will go between +180 and -180 degrees
    """
    r12 = vect_calc(r1, r2)
    r23 = vect_calc(r2, r3)
    r34 = vect_calc(r3, r4)

    r123 = np.cross(r12[:], r23[:])
    r234 = np.cross(r23[:], r34[:])

    n123 = norm_vect(r123)
    n234 = norm_vect(r234)

    axis_2 = np.cross(n123[:], r23[:])
    axis_2_norm = norm_vect(axis_2)

    x = dot_product(n123[:], n234[:])
    y = dot_product(axis_2_norm[:], n234[:])

    dih_angle = np.arctan2(y, x)

    return dih_angle