def test_becke_parameter_calc(self): """Test parameter function.""" R = BeckeTF.find_parameter(self.array, 0.1, 1.2) # R = 1.1 assert np.isclose(R, 1.1) btf = BeckeTF(0.1, R) tf_array = btf.transform(self.array) assert tf_array[9] == 1.2 # for even number of grid R = BeckeTF.find_parameter(self.array_2, 0.2, 1.3) btf_2 = BeckeTF(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)
def test_errors_assert(self): """Test errors raise.""" # parameter error with self.assertRaises(ValueError): BeckeTF.find_parameter(np.arange(5), 0.5, 0.1) # transform non array type with self.assertRaises(TypeError): btf = BeckeTF(0.1, 1.1) btf.transform(0.5) # inverse init error with self.assertRaises(TypeError): InverseTF(0.5) # type error for transform_grid with self.assertRaises(TypeError): btf = BeckeTF(0.1, 1.1) btf.transform_grid(np.arange(3))
def test_becke_infinite(self): """Test becke transformation when inf generated.""" inf_array = np.linspace(-1, 1, 21) R = BeckeTF.find_parameter(inf_array, 0.1, 1.2) btf = BeckeTF(0.1, R) tf_array = btf.transform(inf_array, trim_inf=True) inv_array = btf.inverse(tf_array) assert_allclose(inv_array, inf_array)
def test_errors_assert(self): """Test errors raise.""" # parameter error with self.assertRaises(ValueError): BeckeTF.find_parameter(np.arange(5), 0.5, 0.1) # transform non array type with self.assertRaises(TypeError): btf = BeckeTF(0.1, 1.1) btf.transform("dafasdf") # inverse init error with self.assertRaises(TypeError): InverseTF(0.5) # type error for transform_1d_grid with self.assertRaises(TypeError): btf = BeckeTF(0.1, 1.1) btf.transform_1d_grid(np.arange(3)) with self.assertRaises(ZeroDivisionError): btf = BeckeTF(0.1, 0) itf = InverseTF(btf) itf._d1(0.5) with self.assertRaises(ZeroDivisionError): btf = BeckeTF(0.1, 0) itf = InverseTF(btf) itf._d1(np.array([0.1, 0.2, 0.3]))
def test_becke_infinite(self): """Test becke transformation when inf generated.""" inf_array = np.linspace(-1, 1, 21) R = BeckeTF.find_parameter(inf_array, 0.1, 1.2) btf = BeckeTF(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)
alc_hf = Alchemical_tools( basis, molecule, point_charge_positions=R, point_charges_values=q, coord_type="cartesian", k="HF", ) r0 = 1e-10 radii = get_cov_radii(molecule.atnums) n_rad_points = 100 deg = 5 onedgrid = GaussChebyshev(n_rad_points) molecule_at_grid = [] for i in range(len(molecule.atnums)): Rad = BeckeTF.find_parameter(onedgrid.points, r0, radii[i]) rad_grid = BeckeTF(r0, Rad).transform_grid(onedgrid) molecule_at_grid = molecule_at_grid + [ AtomicGrid.special_init(rad_grid, radii[i], degs=[deg], scales=[]) ] molgrid = MolGrid(molecule_at_grid, molecule.atnums) alc_lda = Alchemical_tools( basis, molecule, point_charge_positions=R, point_charges_values=q, coord_type="cartesian", k="lda_x", molgrid=molgrid, ) two_electron_int = electron_repulsion_integral(basis,