def test_mol_grid(moldesc): # default: level 4 m = Mol(moldesc, basis="6-311++G**", dtype=dtype) m.setup_grid() rgrid = m.get_grid().get_rgrid() # only check the dimension and the type because the number of grid points # can be changed assert rgrid.shape[1] == 3 assert m.get_grid().coord_type == "cart"
def system1(request): poss = torch.tensor([[0.0, 0.0, 0.8], [0.0, 0.0, -0.8]], dtype=dtype) moldesc = ([1, 1], poss) # untruncated grid is required to pass the hamiltonian tests m = Mol(moldesc, basis="3-21G", dtype=dtype, grid=3, orthogonalize_basis=request.param["basis_ortho"]) m.setup_grid() hamilton = m.get_hamiltonian() hamilton.build() hamilton.setup_grid(m.get_grid()) return m
def test_rks_grad_vext(xc, atomzs, dist, vext_p): # check if the gradient w.r.t. vext is obtained correctly (only check 1st # grad because we don't need 2nd grad at the moment) poss = torch.tensor([[-0.5, 0.0, 0.0], [0.5, 0.0, 0.0]], dtype=dtype) * dist mol = Mol((atomzs, poss), basis="3-21G", dtype=dtype, grid=3) mol.setup_grid() rgrid = mol.get_grid().get_rgrid() # (ngrid, ndim) rgrid_norm = torch.norm(rgrid, dim=-1) # (ngrid,) def get_energy(vext_params): vext = rgrid_norm * rgrid_norm * vext_params # (ngrid,) qc = KS(mol, xc=xc, vext=vext, restricted=True).run() ene = qc.energy() return ene vext_params = torch.tensor(vext_p, dtype=dtype).requires_grad_() torch.autograd.gradcheck(get_energy, (vext_params, ))