def test_make_grid_integral(self): """Test molecular make_grid works as designed.""" pts = HortonLinear(70) tf = ExpRTransform(1e-5, 2e1) rgrid = tf.transform_1d_grid(pts) numbers = np.array([1, 1]) coordinates = np.array([[0.0, 0.0, -0.5], [0.0, 0.0, 0.5]], float) becke = BeckeWeights(order=3) # construct molgrid for grid_type, deci in ( ("coarse", 3), ("medium", 4), ("fine", 5), ("veryfine", 6), ("ultrafine", 6), ("insane", 6), ): mg = MolGrid.make_grid(numbers, coordinates, rgrid, grid_type, becke) dist0 = np.sqrt(((coordinates[0] - mg.points)**2).sum(axis=1)) dist1 = np.sqrt(((coordinates[1] - mg.points)**2).sum(axis=1)) fn = np.exp(-2 * dist0) / np.pi + np.exp(-2 * dist1) / np.pi occupation = mg.integrate(fn) assert_almost_equal(occupation, 2.0, decimal=deci)
def test_make_grid_different_grid_type(self): """Test different kind molgrid initizalize setting.""" # three different radial grid rad2 = GaussLaguerre(50) rad3 = GaussLaguerre(70) # construct grid numbers = np.array([1, 8, 1]) coordinates = np.array( [[0.0, 0.0, -0.5], [0.0, 0.0, 0.5], [0.0, 0.5, 0.0]], float) becke = BeckeWeights(order=3) # grid_type test with list mg = MolGrid.make_grid( numbers, coordinates, rad2, ["fine", "veryfine", "medium"], becke, store=True, ) dist0 = np.sqrt(((coordinates[0] - mg.points)**2).sum(axis=1)) dist1 = np.sqrt(((coordinates[1] - mg.points)**2).sum(axis=1)) dist2 = np.sqrt(((coordinates[2] - mg.points)**2).sum(axis=1)) fn = (np.exp(-2 * dist0) + np.exp(-2 * dist1) + np.exp(-2 * dist2)) / np.pi occupation = mg.integrate(fn) assert_almost_equal(occupation, 3, decimal=3) atgrid1 = AtomGrid.from_predefined(numbers[0], rad2, "fine", center=coordinates[0]) atgrid2 = AtomGrid.from_predefined(numbers[1], rad2, "veryfine", center=coordinates[1]) atgrid3 = AtomGrid.from_predefined(numbers[2], rad2, "medium", center=coordinates[2]) assert_allclose(mg._atomic_grids[0].points, atgrid1.points) assert_allclose(mg._atomic_grids[1].points, atgrid2.points) assert_allclose(mg._atomic_grids[2].points, atgrid3.points) # grid type test with dict mg = MolGrid.make_grid(numbers, coordinates, rad3, { 1: "fine", 8: "veryfine" }, becke, store=True) dist0 = np.sqrt(((coordinates[0] - mg.points)**2).sum(axis=1)) dist1 = np.sqrt(((coordinates[1] - mg.points)**2).sum(axis=1)) dist2 = np.sqrt(((coordinates[2] - mg.points)**2).sum(axis=1)) fn = (np.exp(-2 * dist0) + np.exp(-2 * dist1) + np.exp(-2 * dist2)) / np.pi occupation = mg.integrate(fn) assert_almost_equal(occupation, 3, decimal=3) atgrid1 = AtomGrid.from_predefined(numbers[0], rad3, "fine", center=coordinates[0]) atgrid2 = AtomGrid.from_predefined(numbers[1], rad3, "veryfine", center=coordinates[1]) atgrid3 = AtomGrid.from_predefined(numbers[2], rad3, "fine", center=coordinates[2]) assert_allclose(mg._atomic_grids[0].points, atgrid1.points) assert_allclose(mg._atomic_grids[1].points, atgrid2.points) assert_allclose(mg._atomic_grids[2].points, atgrid3.points)
def test_raise_errors(self): """Test molgrid errors raise.""" atg = AtomGrid.from_pruned( self.rgrid, 0.5, r_sectors=np.array([]), degs=np.array([17]), center=np.array([0.0, 0.0, 0.0]), ) # errors of aim_weight with self.assertRaises(TypeError): MolGrid([atg], aim_weights="test", atom_nums=np.array([1])) with self.assertRaises(ValueError): MolGrid([atg], aim_weights=np.array(3), atom_nums=np.array([1])) with self.assertRaises(TypeError): MolGrid([atg], aim_weights=[3, 5], atom_nums=np.array([1])) # integrate errors becke = BeckeWeights({1: 0.472_431_53}, order=3) molg = MolGrid([atg], becke, np.array([1])) with self.assertRaises(ValueError): molg.integrate() with self.assertRaises(TypeError): molg.integrate(1) with self.assertRaises(ValueError): molg.integrate(np.array([3, 5])) with self.assertRaises(ValueError): molg.get_atomic_grid(-3) molg = MolGrid([atg], becke, np.array([1]), store=True) with self.assertRaises(ValueError): molg.get_atomic_grid(-5) # test make_grid error pts = HortonLinear(70) tf = ExpRTransform(1e-5, 2e1) rgrid = tf.transform_1d_grid(pts) numbers = np.array([1, 1]) becke = BeckeWeights(order=3) # construct molgrid with self.assertRaises(ValueError): MolGrid.make_grid(numbers, np.array([0.0, 0.0, 0.0]), rgrid, "fine", becke) with self.assertRaises(ValueError): MolGrid.make_grid(np.array([1, 1]), np.array([[0.0, 0.0, 0.0]]), rgrid, "fine", becke) with self.assertRaises(ValueError): MolGrid.make_grid(np.array([1, 1]), np.array([[0.0, 0.0, 0.0]]), rgrid, "fine", becke) with self.assertRaises(TypeError): MolGrid.make_grid( np.array([1, 1]), np.array([[0.0, 0.0, -0.5], [0.0, 0.0, 0.5]]), {3, 5}, "fine", becke, ) with self.assertRaises(TypeError): MolGrid.make_grid( np.array([1, 1]), np.array([[0.0, 0.0, -0.5], [0.0, 0.0, 0.5]]), rgrid, np.array([3, 5]), becke, )