def test_evaluate_deriv_basis_lincomb(): """Test gbasis.evals.eval.evaluate_deriv_basis_lincomb.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]])) evaluate_obj = EvalDeriv(basis) cart_transform = np.random.rand(14, 19) sph_transform = np.random.rand(14, 18) assert np.allclose( evaluate_obj.construct_array_lincomb( cart_transform, "cartesian", points=np.array([[1, 1, 1]]), orders=np.array([0, 0, 0]) ), evaluate_deriv_basis( basis, np.array([[1, 1, 1]]), np.array([0, 0, 0]), cart_transform, coord_type="cartesian", ), ) assert np.allclose( evaluate_obj.construct_array_lincomb( sph_transform, "spherical", points=np.array([[1, 1, 1]]), orders=np.array([2, 1, 0]) ), evaluate_deriv_basis( basis, np.array([[1, 1, 1]]), np.array([2, 1, 0]), sph_transform, coord_type="spherical" ), )
def test_evaluate_deriv_basis_mix(): """Test gbasis.evals.eval.evaluate_deriv_basis_mix.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]])) evaluate_obj = EvalDeriv(basis) assert np.allclose( evaluate_obj.construct_array_mix( ["cartesian"] * 8, points=np.array([[1, 1, 1]]), orders=np.array([0, 0, 0]) ), evaluate_deriv_basis( basis, np.array([[1, 1, 1]]), np.array([0, 0, 0]), coord_type=["cartesian"] * 8 ), ) assert np.allclose( evaluate_obj.construct_array_mix( ["spherical"] * 8, points=np.array([[1, 1, 1]]), orders=np.array([2, 1, 0]) ), evaluate_deriv_basis( basis, np.array([[1, 1, 1]]), np.array([2, 1, 0]), coord_type=["spherical"] * 8 ), )
def test_evaluate_density_gradient(): """Test gbasis.evals.density.evaluate_density_gradient.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]])) transform = np.random.rand(14, 18) density = np.random.rand(14, 14) density += density.T points = np.random.rand(10, 3) np.allclose( evaluate_density_gradient(density, basis, points, transform).T, np.array([ np.einsum( "ij,ik,jk->k", density, evaluate_deriv_basis(basis, points, np.array([1, 0, 0]), transform), evaluate_basis(basis, points, transform), ) + np.einsum( "ij,ik,jk->k", density, evaluate_basis(basis, points, transform), evaluate_deriv_basis(basis, points, np.array([1, 0, 0]), transform), ), np.einsum( "ij,ik,jk->k", density, evaluate_deriv_basis(basis, points, np.array([0, 1, 0]), transform), evaluate_basis(basis, points, transform), ) + np.einsum( "ij,ik,jk->k", density, evaluate_basis(basis, points, transform), evaluate_deriv_basis(basis, points, np.array([0, 1, 0]), transform), ), np.einsum( "ij,ik,jk->k", density, evaluate_deriv_basis(basis, points, np.array([0, 0, 1]), transform), evaluate_basis(basis, points, transform), ) + np.einsum( "ij,ik,jk->k", density, evaluate_basis(basis, points, transform), evaluate_deriv_basis(basis, points, np.array([0, 0, 1]), transform), ), ]), )
def evaluate_deriv_reduced_density_matrix( orders_one, orders_two, one_density_matrix, basis, points, transform=None, coord_type="spherical", ): r"""Return the derivative of the first-order reduced density matrix at the given points. ..math:: \left. \frac{\partial^{p_x + p_y + p_z}}{\partial x_1^{p_x} \partial y_1^{p_y} \partial z_1^{p_z}} \frac{\partial^{q_x + q_y + q_z}}{\partial x_2^{q_x} \partial y_2^{q_y} \partial z_2^{q_z}} \gamma(\mathbf{r}_1, \mathbf{r}_2) \right|_{\mathbf{r}_1 = \mathbf{r}_2 = \mathbf{r}_n} = \sum_{ij} \gamma_{ij} \left. \frac{\partial^{p_x + p_y + p_z}}{\partial x_1^{p_x} \partial y_1^{p_y} \partial z_1^{p_z}} \phi_i(\mathbf{r}_1) \right|_{\mathbf{r}_1 = \mathbf{r}_n} \left. \frac{\partial^{q_x + q_y + q_z}}{\partial x_2^{q_x} \partial y_2^{q_y} \partial z_2^{q_z}} \phi_j(\mathbf{r}_2) \right|_{\mathbf{r}_2 = \mathbf{r}_n} where :math:`\mathbf{r}_1` is the first point, :math:`\mathbf{r}_2` is the second point, and :math:`\mathbf{r}_n` is the point at which the derivative is evaluated. Parameters ---------- orders_one : np.ndarray(3,) Orders of the derivative for the first point, :math:`mathbf{r}_1`. orders_two : np.ndarray(3,) Orders of the derivative for the second point, :math:`mathbf{r}_1`. one_density_matrix : np.ndarray(K_orbs, K_orbs) One-electron density matrix in terms of the given basis set. If the basis is transformed using `transform` keyword, then the density matrix is assumed to be expressed with respect to the transformed basis set. basis : list/tuple of GeneralizedContractionShell Shells of generalized contractions. points : np.ndarray(N, 3) Cartesian coordinates of the points in space (in atomic units) where the basis functions are evaluated. Rows correspond to the points and columns correspond to the :math:`x, y, \text{and} z` components. transform : np.ndarray(K_orbs, K_cont) Transformation matrix from the basis set in the given coordinate system (e.g. AO) to linear combinations of contractions (e.g. MO). Transformation is applied to the left, i.e. the sum is over the index 1 of `transform` and index 0 of the array for contractions. Default is no transformation. coord_type : {"cartesian", list/tuple of "cartesian" or "spherical", "spherical"} Types of the coordinate system for the contractions. If "cartesian", then all of the contractions are treated as Cartesian contractions. If "spherical", then all of the contractions are treated as spherical contractions. If list/tuple, then each entry must be a "cartesian" or "spherical" to specify the coordinate type of each `GeneralizedContractionShell` instance. Default value is "spherical". Returns ------- deriv_reduced_density_matrix : np.ndarray(N,) Derivative of the first-order reduced density matrix evaluated at `N` grid points. """ deriv_orb_eval_one = evaluate_deriv_basis(basis, points, orders_one, transform=transform, coord_type=coord_type) if np.array_equal(orders_one, orders_two): deriv_orb_eval_two = deriv_orb_eval_one else: deriv_orb_eval_two = evaluate_deriv_basis(basis, points, orders_two, transform=transform, coord_type=coord_type) density = one_density_matrix.dot(deriv_orb_eval_two) density *= deriv_orb_eval_one density = np.sum(density, axis=0) return density