code: def dihedral(array_of_xyzs):
      
      p1 = array_of_xyzs[0]
      p2 = array_of_xyzs[1]
      p3 = array_of_xyzs[2]
      p4 = array_of_xyzs[3]
  
      vector1 = -1.0 * (p2 - p1)
      vector2 = p3 - p2
      vector3 = p4 - p3
  
      # Normalize vector so as not to influence magnitude of vector
      # rejections
      vector2 /= np.linalg.norm(vector2)
  
      # Vector rejections:
      # v = projection of vector1 onto plane perpendicular to vector2
      #   = vector1 - component that aligns with vector2
      # w = projection of vector3 onto plane perpendicular to vector2
      #   = vector3 = component that aligns with vector2
      v = vector1 - np.dot(vector1, vector2) * vector2
      w = vector3 - np.dot(vector3, vector2) * vector2
  
      # Angle between v and w in a plane that is the torsion angle
      # v and w not normalized explicitly, but we use tan so that doesn't
      # matter
      x = np.dot(v, w)
      y = np.dot(np.cross(vector2, v), w)
      principle_dihedral = np.arctan2(y,x)
      # I'm leaving this variable explicit because it should be clear that
      # we need to make sure there are no non-principle angles that better
      # satisfy the constraint for some reason, but that needs to be done
      # outside this function. 
      return principle_dihedral
docs: Calculates dihedral angle between four coordinate points. Used for
      dihedral constraints.