def test_VectorParser_explicit(): vp = displace.VectorParser() assert np.allclose(vp('[1., 2., 3.]'), [1, 2, 3])
def test_VectorParser_xyz_mixed(): xyz = eg.c2h4[1] vp = displace.VectorParser(xyz) soln = [1.2, xyz[3, 0]**2, np.dot(xyz[3], xyz[2] - xyz[1])] assert np.allclose(vp('[1.2, 3[0]^2., 3 o (2 - 1)]'), soln)
def test_VectorParser_unrec_axis(): vp = displace.VectorParser() with pytest.raises(ValueError, match=r'Axis specification not recognized'): rot = vp([1, 1, 1, 1])
def test_VectorParser_xyz_cross(): xyz = eg.c2h4[1] vp = displace.VectorParser(xyz) soln = np.cross(xyz[3] - xyz[1], xyz[4] - xyz[1]) assert np.allclose(vp('(3 - 1) x (4 - 1)'), soln)
def test_VectorParser_xyz_proj(): xyz = eg.c2h4[1] vp = displace.VectorParser(xyz) soln = np.dot(xyz[3], xyz[1]) / np.dot(xyz[1], xyz[1]) * xyz[1] assert np.allclose(vp('(3 o 1) / (1 o 1) * 1'), soln)
def test_VectorParser_xyz_subtract(): xyz = eg.c2h4[1] vp = displace.VectorParser(xyz) assert np.allclose(vp('3 - 1'), xyz[3] - xyz[1])
def test_VectorParser_xyz_unary(): xyz = eg.c2h4[1] vp = displace.VectorParser(xyz) assert np.allclose(vp('-1'), -xyz[1])
def test_VectorParser_xyz_getter(): xyz = eg.c2h4[1] vp = displace.VectorParser(xyz) assert np.allclose(vp.xyz, xyz)
def test_VectorParser_cross_unit(): vp = displace.VectorParser() ax = np.array([[6, -3, 2], [1, 1, 1], [2, 2, 0]]) ax2 = np.array([1, 2, 3]) assert np.allclose(vp(ax, unit=True), ax2 / np.linalg.norm(ax2))
def test_VectorParser_vector(): vp = displace.VectorParser() assert np.allclose(vp([1, 2, 3]), [1, 2, 3])