def test_raise_errors(self): """Test molgrid errors raise.""" atg = AtomicGrid.special_init( self.rgrid, 0.5, scales=np.array([]), degs=np.array([17]), center=np.array([0.0, 0.0, 0.0]), ) # initilize errors with self.assertRaises(NotImplementedError): MolGrid([atg], np.array([1]), aim_weights="test") with self.assertRaises(ValueError): MolGrid([atg], np.array([1]), aim_weights=np.array(3)) with self.assertRaises(TypeError): MolGrid([atg], np.array([1]), aim_weights=[3, 5]) # integrate errors molg = MolGrid([atg], 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(NotImplementedError): molg.get_atomic_grid(0) with self.assertRaises(ValueError): molg.get_aim_weights(-3) molg = MolGrid([atg], np.array([1]), store=True) with self.assertRaises(ValueError): molg.get_atomic_grid(-5)
def test_molgrid_attrs(self): """Test MolGrid attributes.""" # numbers = np.array([6, 8], int) coordinates = np.array([[0.0, 0.2, -0.5], [0.1, 0.0, 0.5]], float) atg1 = AtomGrid.from_pruned( self.rgrid, 1.228, r_sectors=np.array([]), degs=np.array([17]), center=coordinates[0], ) atg2 = AtomGrid.from_pruned( self.rgrid, 0.945, r_sectors=np.array([]), degs=np.array([17]), center=coordinates[1], ) becke = BeckeWeights(order=3) mg = MolGrid([atg1, atg2], becke, np.array([6, 8]), store=True) assert mg.size == 2 * 110 * 100 assert mg.points.shape == (mg.size, 3) assert mg.weights.shape == (mg.size, ) assert mg.aim_weights.shape == (mg.size, ) assert mg.get_atomic_grid(0) is atg1 assert mg.get_atomic_grid(1) is atg2 simple_ag1 = mg.get_atomic_grid(0) simple_ag2 = mg.get_atomic_grid(1) assert_allclose(simple_ag1.points, atg1.points) assert_allclose(simple_ag1.weights, atg1.weights) assert_allclose(simple_ag2.weights, atg2.weights) # test molgrid is not stored mg2 = MolGrid([atg1, atg2], becke, np.array([6, 8]), store=False) assert mg2._atomic_grids is None simple2_ag1 = mg2.get_atomic_grid(0) simple2_ag2 = mg2.get_atomic_grid(1) assert isinstance(simple2_ag1, LocalGrid) assert isinstance(simple2_ag2, LocalGrid) assert_allclose(simple2_ag1.points, atg1.points) assert_allclose(simple2_ag1.weights, atg1.weights) assert_allclose(simple2_ag2.weights, atg2.weights)
def test_molgrid_attrs(self): """Test MolGrid attributes.""" # numbers = np.array([6, 8], int) coordinates = np.array([[0.0, 0.2, -0.5], [0.1, 0.0, 0.5]], float) atg1 = AtomicGrid.special_init( self.rgrid, 1.228, scales=np.array([]), degs=np.array([17]), center=coordinates[0], ) atg2 = AtomicGrid.special_init( self.rgrid, 0.945, scales=np.array([]), degs=np.array([17]), center=coordinates[1], ) mg = MolGrid([atg1, atg2], np.array([6, 8]), store=True) assert mg.size == 2 * 110 * 100 assert mg.points.shape == (mg.size, 3) assert mg.weights.shape == (mg.size,) assert mg.aim_weights.shape == (mg.size,) assert mg.get_atomic_grid(0) is atg1 assert mg.get_atomic_grid(1) is atg2 simple_ag1 = mg.get_simple_atomic_grid(0) simple_ag2 = mg.get_simple_atomic_grid(1) assert_allclose(simple_ag1.points, atg1.points) assert_allclose(simple_ag2.points, atg2.points) aim_at1 = mg.get_aim_weights(0) aim_at2 = mg.get_aim_weights(1) assert_allclose(simple_ag1.weights, atg1.weights * aim_at1) assert_allclose(simple_ag2.weights, atg2.weights * aim_at2)
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, )