Esempio n. 1
0
 def test_becke_parameter_calc(self):
     """Test parameter function."""
     R = BeckeRTransform.find_parameter(self.array, 0.1, 1.2)
     # R = 1.1
     assert np.isclose(R, 1.1)
     btf = BeckeRTransform(0.1, R)
     tf_array = btf.transform(self.array)
     assert tf_array[9] == 1.2
     # for even number of grid
     R = BeckeRTransform.find_parameter(self.array_2, 0.2, 1.3)
     btf_2 = BeckeRTransform(0.2, R)
     tf_elemt = btf_2.transform(
         np.array([(self.array_2[4] + self.array_2[5]) / 2]))
     assert_allclose(tf_elemt, 1.3)
Esempio n. 2
0
 def test_errors_assert(self):
     """Test errors raise."""
     # parameter error
     with self.assertRaises(ValueError):
         BeckeRTransform.find_parameter(np.arange(5), 0.5, 0.1)
     # transform non array type
     with self.assertRaises(TypeError):
         btf = BeckeRTransform(0.1, 1.1)
         btf.transform("dafasdf")
     # inverse init error
     with self.assertRaises(TypeError):
         InverseRTransform(0.5)
     # type error for transform_1d_grid
     with self.assertRaises(TypeError):
         btf = BeckeRTransform(0.1, 1.1)
         btf.transform_1d_grid(np.arange(3))
     with self.assertRaises(ZeroDivisionError):
         btf = BeckeRTransform(0.1, 0)
         itf = InverseRTransform(btf)
         itf._d1(0.5)
     with self.assertRaises(ZeroDivisionError):
         btf = BeckeRTransform(0.1, 0)
         itf = InverseRTransform(btf)
         itf._d1(np.array([0.1, 0.2, 0.3]))
Esempio n. 3
0
 def test_becke_infinite(self):
     """Test becke transformation when inf generated."""
     inf_array = np.linspace(-1, 1, 21)
     R = BeckeRTransform.find_parameter(inf_array, 0.1, 1.2)
     btf = BeckeRTransform(0.1, R, trim_inf=True)
     tf_array = btf.transform(inf_array)
     inv_array = btf.inverse(tf_array)
     assert_allclose(inv_array, inf_array)
     # extra test for neg inf
     # test for number
     result = btf._convert_inf(-np.inf)
     assert_almost_equal(result, -1e16)
     result = btf._convert_inf(np.inf)
     assert_almost_equal(result, 1e16)
     # test for array
     test_array = np.random.rand(5)
     test_array[3] = -np.inf
     result = btf._convert_inf(test_array)
     assert_almost_equal(result[3], -1e16)
     test_array[3] = np.inf
     result = btf._convert_inf(test_array)
     assert_almost_equal(result[3], 1e16)