def GetGdirAngle(coords1, coords2, coords3, r_21=None, r_23=None):
    """Calculate direction of energy gradients between bond angle atoms.
  
  Args:
    coords1 (float*): 3 cartesian coordinates [Angstrom] of atom1.
    coords2 (float*): 3 cartesian coordinates [Angstrom] of atom2.
    coords3 (float*): 3 cartesian coordinates [Angstrom] of atom3.
    r_21 (float): Distance between atom2 and atom1 (default None).
    r_23 (float): Distance between atom2 and atom3 (default None).

  Returns:
    gdir1 (float*), gdir2 (float*), gdir3 (float*): vectors in the direction of
        max increasing bond angle.
  """
    if r_21 is not None:
        r_21 = geomcalc.GetRij(coords2, coords1)
    if r_23 is not None:
        r_23 = geomcalc.GetRij(coords2, coords3)
    u_21 = geomcalc.GetUij(coords2, coords1, r_21)
    u_23 = geomcalc.GetUij(coords2, coords3, r_23)
    cp = geomcalc.GetUcp(u_21, u_23)
    gdir1 = geomcalc.GetUcp(u_21, cp) / r_21
    gdir3 = geomcalc.GetUcp(cp, u_23) / r_23
    gdir2 = -1.0 * (gdir1 + gdir3)
    return gdir1, gdir2, gdir3
def GetGDirTorsion(coords1, coords2, coords3, coords4, r_12=None, r_23=None,
                   r_34=None):
  """Calculate direction of energy gradients between torsion atoms.
  
  Args:
    coords1 (float*): 3 cartesian coordinates [Angstrom] of atom1.
    coords2 (float*): 3 cartesian coordinates [Angstrom] of atom2.
    coords3 (float*): 3 cartesian coordinates [Angstrom] of atom3.
    coords4 (float*): 3 cartesian coordinates [Angstrom] of atom4.
    r_12 (float): Distance between atom1 and atom2 (default None).
    r_23 (float): Distance between atom2 and atom3 (default None).
    r_34 (float): Distance between atom3 and atom4 (default None).
  
  Returns:
    gdir1 (float*), gdir2 (float*), gdir3 (float*), gdir4 (float*): Vectors in
        the direction of max increasing torsion angle.
  """
  u_21 = geomcalc.GetUij(coords2, coords1, r_12)
  u_34 = geomcalc.GetUij(coords3, coords4, r_34)
  u_23 = geomcalc.GetUij(coords2, coords3, r_23)
  u_32 = -1.0 * u_23
  a_123 = geomcalc.GetAijk(coords1, coords2, coords3, r_12, r_23)
  a_432 = geomcalc.GetAijk(coords4, coords3, coords2, r_34, r_23)
  s_123 = math.sin(const.DEG2RAD * a_123)
  s_432 = math.sin(const.DEG2RAD * a_432)
  c_123 = math.cos(const.DEG2RAD * a_123)
  c_432 = math.cos(const.DEG2RAD * a_432)
  gdir1 = geomcalc.GetUcp(u_21, u_23) / (r_12*s_123)
  gdir4 = geomcalc.GetUcp(u_34, u_32) / (r_34*s_432)
  gdir2 = (r_12/r_23*c_123 - 1.0)*gdir1 - (r_34/r_23*c_432)*gdir4
  gdir3 = (r_34/r_23*c_432 - 1.0)*gdir4 - (r_12/r_23*c_123)*gdir1
  return gdir1, gdir2, gdir3, gdir4
 def testAntiReflexive(self):
     """Asserts opposite value with inverted input order."""
     params = ARBITRARY_UNIT_XYZ2, ARBITRARY_UNIT_XYZ1
     self.assertListAlmostEqual(geomcalc.GetUcp(*params),
                                CROSS_UNIT_VECTOR_21)
 def testArbitrary(self):
     """Asserts correct value with two arbitrary unit vectors."""
     params = ARBITRARY_UNIT_XYZ1, ARBITRARY_UNIT_XYZ2
     self.assertListAlmostEqual(geomcalc.GetUcp(*params),
                                CROSS_UNIT_VECTOR_12)
 def testInPlaneYZ(self):
     """Asserts x-axis as result of two xz-plane vectors."""
     params = ARBITRARY_UNIT_YZ3, ARBITRARY_UNIT_YZ4
     self.assertListAlmostEqual(geomcalc.GetUcp(*params), POSITIVE_UNIT_X)
 def testInPlaneXY(self):
     """Asserts z-axis as result of two xy-plane vectors."""
     params = ARBITRARY_UNIT_XY1, ARBITRARY_UNIT_XY2
     self.assertListAlmostEqual(geomcalc.GetUcp(*params), NEGATIVE_UNIT_Z)
 def testUnitZX(self):
     """Asserts positive y-axis as result of z-axis and x-axis cross."""
     params = POSITIVE_UNIT_Z, POSITIVE_UNIT_X
     self.assertListAlmostEqual(geomcalc.GetUcp(*params), POSITIVE_UNIT_Y)
 def testUnitYX(self):
     """Asserts negative z-axis as result of y-axis and x-axis cross."""
     params = POSITIVE_UNIT_Y, POSITIVE_UNIT_X
     self.assertListAlmostEqual(geomcalc.GetUcp(*params), NEGATIVE_UNIT_Z)
 def testZeroVector(self):
     """Asserts zero vector result for zero vector input."""
     params = ORIGIN, ARBITRARY_UNIT_XYZ1
     self.assertListAlmostEqual(geomcalc.GetUcp(*params), ORIGIN)