예제 #1
0
class TestAOderivativesADF(unittest.TestCase):

    def setUp(self):

        # define the molecule
        path_hdf5 = PATH_TEST / 'hdf5/C_adf_dzp.hdf5'
        self.mol = Molecule(load=path_hdf5)

        # define the wave function
        self.wf = Orbital(self.mol, include_all_mo=True)

        # define the grid points
        npts = 11
        self.pos = torch.rand(npts, self.mol.nelec * 3)
        self.pos = Variable(self.pos)
        self.pos.requires_grad = True

    def test_ao_deriv(self):

        ao = self.wf.ao(self.pos)
        dao = self.wf.ao(self.pos, derivative=1)

        dao_grad = grad(
            ao, self.pos, grad_outputs=torch.ones_like(ao))[0]

        gradcheck(self.wf.ao, self.pos)
        assert(torch.allclose(dao.sum(), dao_grad.sum()))

    def test_ao_hess(self):

        ao = self.wf.ao(self.pos)
        d2ao = self.wf.ao(self.pos, derivative=2)
        d2ao_grad = hess(ao, self.pos)
        assert(torch.allclose(d2ao.sum(), d2ao_grad.sum()))
예제 #2
0
class TestInterpolate(unittest.TestCase):

    def setUp(self):

        # molecule
        self.mol = Molecule(
            atom='H 0 0 -0.69; H 0 0 0.69',
            unit='bohr',
            calculator='pyscf',
            basis='dzp')

        # wave function
        self.wf = Orbital(self.mol, kinetic='jacobi',
                          configs='single(2,2)',
                          use_jastrow=True)

        npts = 51
        self.pos = torch.zeros(npts, 6)
        self.pos[:, 2] = torch.linspace(-2, 2, npts)

    def test_ao(self):

        interp_ao = InterpolateAtomicOrbitals(self.wf)
        inter = interp_ao(self.pos)
        ref = self.wf.ao(self.pos)
        delta = (inter - ref).abs().mean()
        assert(delta < 0.1)

    def test_mo_reg(self):

        interp_mo = InterpolateMolecularOrbitals(self.wf)
        inter = interp_mo(self.pos, method='reg')
        ref = self.wf.mo(self.wf.mo_scf(self.wf.ao(self.pos)))
        delta = (inter - ref).abs().mean()
        assert(delta < 0.1)

    def test_mo_irreg(self):

        interp_mo = InterpolateMolecularOrbitals(self.wf)
        inter = interp_mo(self.pos, method='irreg')
        ref = self.wf.mo(self.wf.mo_scf(self.wf.ao(self.pos)))
        delta = (inter - ref).abs().mean()
        assert(delta < 0.1)
예제 #3
0
class TestAOderivativesPyscf(unittest.TestCase):

    def setUp(self):

        # define the molecule
        at = 'C 0 0 0'
        basis = 'dzp'
        self.mol = Molecule(atom=at,
                            calculator='pyscf',
                            basis=basis,
                            unit='bohr')

        self.m = gto.M(atom=at, basis=basis, unit='bohr')

        # define the wave function
        self.wf = Orbital(self.mol, include_all_mo=True)

        # define the grid points
        npts = 11
        self.pos = torch.rand(npts, self.mol.nelec * 3)
        self.pos = Variable(self.pos)
        self.pos.requires_grad = True

    def test_ao_deriv(self):

        ao = self.wf.ao(self.pos)
        dao = self.wf.ao(self.pos, derivative=1)

        dao_grad = grad(
            ao, self.pos, grad_outputs=torch.ones_like(ao))[0]

        gradcheck(self.wf.ao, self.pos)
        assert(torch.allclose(dao.sum(), dao_grad.sum()))

    def test_ao_hess(self):

        ao = self.wf.ao(self.pos)
        d2ao = self.wf.ao(self.pos, derivative=2)
        d2ao_grad = hess(ao, self.pos)
        assert(torch.allclose(d2ao.sum(), d2ao_grad.sum()))
예제 #4
0
class TestMOvaluesADF(unittest.TestCase):
    def setUp(self):

        # define the molecule
        path_hdf5 = (PATH_TEST / 'hdf5/C_adf_dzp.hdf5').absolute().as_posix()
        self.mol = Molecule(load=path_hdf5)

        # define the wave function
        self.wf = Orbital(self.mol, include_all_mo=True)

        # define the grid points
        self.npts = 21
        pts = get_pts(self.npts)

        self.pos = 10 * torch.ones(self.npts**2, self.mol.nelec * 3)
        self.pos[:, :3] = pts
        self.pos = Variable(self.pos)
        self.pos.requires_grad = True

    def test_mo(self):

        movals = self.wf.mo_scf(self.wf.ao(self.pos)).detach().numpy()

        for iorb in range(self.mol.basis.nmo):
            path_cube = PATH_TEST / f'cube/C_MO_%SCF_A%{iorb + 1}.cub'
            fname = path_cube.absolute().as_posix()
            adf_ref_data = np.array(read_cubefile(fname)).reshape(
                self.npts, self.npts)**2
            qmctorch_data = (movals[:, 0, iorb]).reshape(self.npts,
                                                         self.npts)**2

            delta = np.abs(adf_ref_data - qmctorch_data)

            if __PLOT__:
                plt.subplot(1, 3, 1)
                plt.imshow(adf_ref_data)

                plt.subplot(1, 3, 2)
                plt.imshow(qmctorch_data)

                plt.subplot(1, 3, 3)
                plt.imshow(delta)
                plt.show()

            # the 0,0 point is much larger due to num instabilities
            delta = np.sort(delta.flatten())
            delta = delta[:-1]
            assert (delta.mean() < 1E-3)
예제 #5
0
class TestAOvaluesADF(unittest.TestCase):
    def setUp(self):

        # define the molecule
        path_hdf5 = (PATH_TEST / 'hdf5/C_adf_dzp.hdf5').absolute().as_posix()
        self.mol = Molecule(load=path_hdf5)

        # define the wave function
        self.wf = Orbital(self.mol, include_all_mo=True)

        # define the grid points
        self.npts = 21
        pts = get_pts(self.npts)

        self.pos = torch.zeros(self.npts**2, self.mol.nelec * 3)
        self.pos[:, :3] = pts
        self.pos = Variable(self.pos)
        self.pos.requires_grad = True

    def test_ao(self):

        aovals = self.wf.ao(self.pos).detach().numpy()

        for iorb in range(self.mol.basis.nao):

            path_cube = PATH_TEST / f'cube/C_AO_%Basis%AO{iorb}.cub'
            fname = path_cube.absolute().as_posix()
            adf_ref_data = np.array(read_cubefile(fname)).reshape(
                self.npts, self.npts)
            qmctorch_data = (aovals[:, 0, iorb]).reshape(self.npts, self.npts)

            delta = np.abs(adf_ref_data - qmctorch_data)

            if __PLOT__:
                plt.subplot(1, 3, 1)
                plt.imshow(adf_ref_data)

                plt.subplot(1, 3, 2)
                plt.imshow(qmctorch_data)

                plt.subplot(1, 3, 3)
                plt.imshow(delta)
                plt.show()

            assert (delta.mean() < 1E-3)
예제 #6
0
class TestAOvaluesPyscf(unittest.TestCase):
    def setUp(self):

        # define the molecule
        at = 'C 0 0 0'
        basis = 'dzp'
        self.mol = Molecule(atom=at,
                            calculator='pyscf',
                            basis=basis,
                            unit='bohr')

        self.m = gto.M(atom=at, basis=basis, unit='bohr')

        # define the wave function
        self.wf = Orbital(self.mol)

        self.pos = torch.zeros(100, self.mol.nelec * 3)

        self.pos[:, 0] = torch.linspace(-5, 5, 100)
        self.pos[:, 1] = torch.linspace(-5, 5, 100)
        self.pos[:, 2] = torch.linspace(-5, 5, 100)

        self.pos = Variable(self.pos)
        self.pos.requires_grad = True

        self.x = self.pos[:, 0].detach().numpy()

    def test_ao(self):

        nzlm = np.linalg.norm(self.m.cart2sph_coeff(), axis=1)

        aovals = self.wf.ao(self.pos).detach().numpy() / nzlm
        aovals_ref = self.m.eval_ao('GTOval_cart',
                                    self.pos.detach().numpy()[:, :3])

        for iorb in range(self.mol.basis.nao):

            if __PLOT__:

                plt.plot(self.x, aovals[:, 0, iorb])
                plt.plot(self.x, aovals_ref[:, iorb])
                plt.show()

            assert np.allclose(aovals[:, 0, iorb], aovals_ref[:, iorb])

    def test_ao_deriv(self):

        nzlm = np.linalg.norm(self.m.cart2sph_coeff(), axis=1)

        daovals = self.wf.ao(self.pos, derivative=1).detach().numpy() / nzlm

        daovals_ref = self.m.eval_gto('GTOval_ip_cart',
                                      self.pos.detach().numpy()[:, :3])
        daovals_ref = daovals_ref.sum(0)

        for iorb in range(self.mol.basis.nao):

            if __PLOT__:
                plt.plot(self.x, daovals[:, 0, iorb])
                plt.plot(self.x, daovals_ref[:, iorb])
                plt.show()

            assert np.allclose(daovals[:, 0, iorb], daovals_ref[:, iorb])