Exemplo n.º 1
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)
Exemplo n.º 2
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)