Exemplo n.º 1
0
    def setUp(self):

        # optimal parameters
        self.opt_r = 0.69  # the two h are at +0.69 and -0.69
        self.opt_sigma = 1.24

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

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

        # sampler
        self.sampler = Metropolis(nwalkers=1000,
                                  nstep=2000,
                                  step_size=0.5,
                                  ndim=self.wf.ndim,
                                  nelec=self.wf.nelec,
                                  init=self.mol.domain('normal'),
                                  move={
                                      'type': 'all-elec',
                                      'proba': 'normal'
                                  })

        self.hmc_sampler = Hamiltonian(nwalkers=100,
                                       nstep=200,
                                       step_size=0.1,
                                       ndim=self.wf.ndim,
                                       nelec=self.wf.nelec,
                                       init=self.mol.domain('normal'))

        # optimizer
        self.opt = optim.Adam(self.wf.parameters(), lr=0.01)

        # solver
        self.solver = SolverOrbital(wf=self.wf,
                                    sampler=self.sampler,
                                    optimizer=self.opt)

        # ground state energy
        self.ground_state_energy = -1.16

        # ground state pos
        self.ground_state_pos = 0.69
Exemplo n.º 2
0
    def setUp(self):

        atom_str = 'C 0 0 -0.69; O 0 0 0.69'
        self.m = gto.M(atom=atom_str, basis='sto-3g', unit='bohr')
        self.mol = Molecule(atom=atom_str,
                            calculator='pyscf',
                            basis='sto-3g',
                            unit='bohr')

        # define the wave function
        self.wf = OrbitalTest(self.mol)
        self.x = 2 * torch.rand(5, 3 * self.mol.nelec) - 1.
        self.x.requires_grad = True
Exemplo n.º 3
0
    def setUp(self):

        # define the molecule
        at = 'H 0 0 0; H 0 0 1'
        self.mol = Molecule(atom=at,
                            calculator='pyscf',
                            basis='sto-3g',
                            unit='bohr')

        self.m = gto.M(atom=at, basis='sto-3g', unit='bohr')

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

        self.pos = torch.zeros(100, self.mol.nelec * 3)
        self.pos[:, 2] = torch.linspace(-5, 5, 100)

        self.pos = Variable(self.pos)
        self.pos.requires_grad = True
        self.iorb = 0
        self.x = self.pos[:, 2].detach().numpy()
Exemplo n.º 4
0
            ao {torch.tensor} -- input ao matrix
            pos {torch.tensor} -- position of the electron that has moved
            idelec {int} -- index of the electron that has moved

        Returns:
            torch.tensor -- new ao matrix
        """
        ao_new = ao.clone()
        ids, ide = (idelec) * 3, (idelec + 1) * 3
        ao_new[:, idelec, :] = self.forward(pos[:, ids:ide],
                                            one_elec=True).squeeze(1)
        return ao_new


if __name__ == "__main__":

    from deepqmc.wavefunction.molecule import Molecule
    from time import time
    m = Molecule(atom='H 0 0 0; H 0 0 3.015', basis='dz')

    ao = AtomicOrbitals(m, cuda=False)
    pos = torch.rand(10, ao.nelec * 3)

    t0 = time()
    aoval = ao(pos)
    print('Total calculation : ', time() - t0)

    t0 = time()
    aoval = ao(pos[:, :3], one_elec=True)
    print('1elec, calculation : ', time() - t0)
Exemplo n.º 5
0
class TestH2(unittest.TestCase):
    def setUp(self):

        # optimal parameters
        self.opt_r = 0.69  # the two h are at +0.69 and -0.69
        self.opt_sigma = 1.24

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

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

        # sampler
        self.sampler = Metropolis(nwalkers=1000,
                                  nstep=2000,
                                  step_size=0.5,
                                  ndim=self.wf.ndim,
                                  nelec=self.wf.nelec,
                                  init=self.mol.domain('normal'),
                                  move={
                                      'type': 'all-elec',
                                      'proba': 'normal'
                                  })

        self.hmc_sampler = Hamiltonian(nwalkers=100,
                                       nstep=200,
                                       step_size=0.1,
                                       ndim=self.wf.ndim,
                                       nelec=self.wf.nelec,
                                       init=self.mol.domain('normal'))

        # optimizer
        self.opt = optim.Adam(self.wf.parameters(), lr=0.01)

        # solver
        self.solver = SolverOrbital(wf=self.wf,
                                    sampler=self.sampler,
                                    optimizer=self.opt)

        # ground state energy
        self.ground_state_energy = -1.16

        # ground state pos
        self.ground_state_pos = 0.69

    def test_single_point(self):

        self.solver.wf.ao.atom_coords[0, 2] = -self.ground_state_pos
        self.solver.wf.ao.atom_coords[1, 2] = self.ground_state_pos
        self.solver.sampler = self.sampler

        # sample and compute observables
        _, e, v = self.solver.single_point()

        print('Energy   :', e)
        print('Variance :', v)

        # assert(e>self.ground_state_energy and e<-1.)
        assert (e > 2 * self.ground_state_energy and e < 0.)
        assert (v > 0 and v < 5.)

    def test_single_point_hmc(self):

        self.solver.wf.ao.atom_coords[0, 2] = -self.ground_state_pos
        self.solver.wf.ao.atom_coords[1, 2] = self.ground_state_pos
        self.solver.sampler = self.hmc_sampler

        # sample and compute observables
        _, e, v = self.solver.single_point()

        print('Energy   :', e)
        print('Variance :', v)

        # assert(e>self.ground_state_energy and e<-1.)
        assert (e > 2 * self.ground_state_energy and e < 0.)
        assert (v > 0 and v < 5.)

    def test_geo_opt(self):

        self.solver.wf.ao.atom_coords[0, 2].data = torch.tensor(-0.37)
        self.solver.wf.ao.atom_coords[1, 2].data = torch.tensor(0.37)

        self.solver.configure(task='geo_opt')
        self.solver.observable(['local_energy', 'atomic_distances'])
        self.solver.run(50, loss='energy')

        # load the best model
        best_model = torch.load('model.pth')
        self.solver.wf.load_state_dict(best_model['model_state_dict'])
        self.solver.wf.eval()

        # sample and compute variables
        _, e, v = self.solver.single_point()
        e = e.data.numpy()
        v = v.data.numpy()

        # it might be too much to assert with the ground state energy
        assert (e > 2 * self.ground_state_energy and e < 0.)
        assert (v > 0 and v < 2.)
Exemplo n.º 6
0
from deepqmc.wavefunction.wf_orbital import Orbital
from deepqmc.solver.solver_orbital import SolverOrbital
from deepqmc.utils.torch_utils import set_torch_double_precision

from deepqmc.sampler.metropolis import Metropolis
from deepqmc.sampler.hamiltonian import Hamiltonian
from deepqmc.wavefunction.molecule import Molecule

from deepqmc.utils.plot_data import (load_observable, save_observalbe,
                                     plot_block, plot_walkers_traj,
                                     plot_energy, plot_data)

set_torch_double_precision()

# define the molecule
mol = Molecule(atom='He 0 0 0', basis_type='sto', basis='dzp', unit='bohr')

# define the wave function
wf = Orbital(mol, kinetic='jacobi', configs='cas(2,2)', use_jastrow=True)
wf.jastrow.weight.data[0] = 1.

# sampler
sampler = Metropolis(nwalkers=500,
                     nstep=2000,
                     step_size=0.05,
                     nelec=wf.nelec,
                     ndim=wf.ndim,
                     init=mol.domain('normal'),
                     move={
                         'type': 'all-elec',
                         'proba': 'normal'
Exemplo n.º 7
0
from torch.autograd import Variable
from torch.optim import Adam

from deepqmc.wavefunction.wf_orbital import Orbital
from deepqmc.solver.solver_orbital import SolverOrbital
#from deepqmc.solver.solver_orbital_distributed import DistSolverOrbital  as SolverOrbital

from deepqmc.sampler.metropolis import Metropolis
from deepqmc.wavefunction.molecule import Molecule

from deepqmc.solver.plot_orbital import plot_molecule
from deepqmc.solver.plot_orbital import plot_molecule_mayavi as plot_molecule
from deepqmc.solver.plot_data import plot_observable

# define the molecule
mol = Molecule(atom='water.xyz', basis_type='sto', basis='sz')

# define the wave function
wf = Orbital(mol)

#sampler
sampler = Metropolis(nwalkers=100,
                     nstep=1000,
                     step_size=0.5,
                     ndim=wf.ndim,
                     nelec=wf.nelec,
                     move='one')

# optimizer
opt = Adam(wf.parameters(), lr=0.01)
Exemplo n.º 8
0
        Returns:
            list -- atomic types and positions
        """
        d = []
        for iat in range(self.natom):
            at = self.atoms[iat]
            xyz = self.ao.atom_coords[iat, :].detach().numpy().tolist()
            d.append((at, xyz))
        return d


if __name__ == "__main__":

    from deepqmc.wavefunction.molecule import Molecule

    mol = Molecule(atom='Li 0 0 0; H 0 0 3.015', basis='sz')

    # define the wave function
    wf_jacobi = Orbital(mol,
                        kinetic='jacobi',
                        configs='cas(2,2)',
                        use_jastrow=True,
                        cuda=False)

    wf_auto = Orbital(mol,
                      kinetic='auto',
                      configs='cas(2,2)',
                      use_jastrow=True,
                      cuda=False)

    pos = torch.rand(20, wf_auto.ao.nelec * 3)
Exemplo n.º 9
0
def rot_mat(angles):
    dA = (angles[1] - angles[0]) * np.pi / 180
    c, s = np.cos(dA), np.sin(dA)
    return np.array([[c, s, 0], [-s, c, 0], [0, 0, 1]])


def bend_molecule(mol, r, index=1):
    mol.atom_coords[index] = (
        r @ np.array(mol.atom_coords[index])).astype('float32')

    return mol


# define the molecule
mol = Molecule(atom='water_line.xyz',
               unit='angs',
               basis_type='gto',
               basis='sto-3g')

# define the wave function
wf = Orbital(mol, kinetic_jacobi=True)

# sampler
sampler = Metropolis(nwalkers=1000,
                     nstep=5000,
                     step_size=0.5,
                     ndim=wf.ndim,
                     nelec=wf.nelec,
                     move='one')

# solver
solver = SolverOrbital(wf=wf, sampler=sampler)
Exemplo n.º 10
0
# bond distance : 0.74 A -> 1.38 a
# optimal H positions +0.69 and -0.69
# ground state energy : -31.688 eV -> -1.16 hartree
# bond dissociation energy 4.478 eV -> 0.16 hartree


class OrbitalH2(Orbital):
    def __init__(self, mol):
        super(OrbitalH2, self).__init__(mol)

    def pool(self, x):
        return (x[:, 0, 0] * x[:, 1, 0]).view(-1, 1)


# define the molecule
mol = Molecule(atom='H 0 0 -0.37; H 0 0 0.37', basis_type='sto', basis='sz')
#mol = Molecule(atom='H 0 0 -0.37; H 0 0 0.37', basis_type='gto', basis='sto-3g')

# define the wave function
wf = OrbitalH2(mol)

#sampler
sampler = Metropolis(nwalkers=1000,
                     nstep=1000,
                     step_size=0.5,
                     ndim=wf.ndim,
                     nelec=wf.nelec,
                     move='one')

# optimizer
opt = Adam(wf.parameters(), lr=0.01)
Exemplo n.º 11
0
from torch.optim import Adam

from deepqmc.wavefunction.wf_orbital import Orbital
from deepqmc.solver.solver_orbital import SolverOrbital
from deepqmc.solver.torch_utils import set_torch_double_precision

from deepqmc.sampler.metropolis import Metropolis
from deepqmc.wavefunction.molecule import Molecule

from deepqmc.solver.plot_data import plot_energy

set_torch_double_precision()

# define the molecule
mol = Molecule(atom='C 0 0 0; O 0 0 2.173',
               calculator='pyscf',
               basis='sto-3g',
               unit='bohr')

# define the wave function
wf = Orbital(mol, kinetic='jacobi', configs='cas(4,4)', use_jastrow=True)

# sampler
sampler = Metropolis(nwalkers=1000,
                     nstep=1000,
                     step_size=0.1,
                     nelec=wf.nelec,
                     ndim=wf.ndim,
                     init=mol.domain('normal'),
                     move={
                         'type': 'one-elec',
                         'proba': 'normal'
Exemplo n.º 12
0
#from deepqmc.sampler.generalized_metropolis import GeneralizedMetropolis
from deepqmc.sampler.hamiltonian import Hamiltonian

from deepqmc.wavefunction.molecule import Molecule
from deepqmc.solver.plot_data import plot_energy

# bond distance : 0.74 A -> 1.38 a
# optimal H positions +0.69 and -0.69
# ground state energy : -31.688 eV -> -1.16 hartree
# bond dissociation energy 4.478 eV -> 0.16 hartree

# set_torch_double_precision()

# define the molecule
mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69',
               basis_type='gto',
               basis='sto-6g',
               unit='bohr')

# define the wave function
wf = Orbital(mol,
             kinetic='jacobi',
             configs='singlet(1,1)',
             use_jastrow=True,
             cuda=True)

# sampler
sampler = Metropolis(nwalkers=100,
                     nstep=200,
                     step_size=0.5,
                     ndim=wf.ndim,
                     nelec=wf.nelec,
Exemplo n.º 13
0
from deepqmc.solver.plot_data import plot_energy

# bond distance : 0.74 A -> 1.38 a
# optimal H positions +0.69 and -0.69
# ground state energy : -31.688 eV -> -1.16 hartree
# bond dissociation energy 4.478 eV -> 0.16 hartree

hvd.init()
if torch.cuda.is_available():
    torch.cuda.set_device(hvd.local_rank())

set_torch_double_precision()

# define the molecule
mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69',
               calculator='pyscf',
               basis='sto-6g',
               unit='bohr')

# define the wave function
wf = Orbital(mol,
             kinetic='jacobi',
             configs='singlet(1,1)',
             use_jastrow=True,
             cuda=False)

# sampler
sampler = Metropolis(nwalkers=1000,
                     nstep=1000,
                     step_size=0.5,
                     ndim=wf.ndim,
                     nelec=wf.nelec,
Exemplo n.º 14
0
Arquivo: h2.py Projeto: NLESC-JCER/QMC
from deepqmc.wavefunction.molecule import Molecule
from deepqmc.utils.plot_data import (load_observable, save_observalbe,
                                     plot_block, plot_walkers_traj,
                                     plot_energy, plot_data)

# bond distance : 0.74 A -> 1.38 a
# optimal H positions +0.69 and -0.69
# ground state energy : -31.688 eV -> -1.16 hartree
# bond dissociation energy 4.478 eV -> 0.16 hartree

set_torch_double_precision()

# define the molecule
mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69',
               calculator='adf',
               basis='dzp',
               unit='bohr')

# define the wave function
wf = Orbital(mol, kinetic='jacobi', configs='cas(2,2)', use_jastrow=True)

wf.jastrow.weight.data[0] = 1.

# sampler
sampler = Metropolis(nwalkers=500,
                     nstep=2000,
                     step_size=0.2,
                     ndim=wf.ndim,
                     nelec=wf.nelec,
                     init=mol.domain('atomic'),
                     move={
Exemplo n.º 15
0
from deepqmc.solver.solver_orbital import SolverOrbital
from deepqmc.utils.torch_utils import set_torch_double_precision

from deepqmc.sampler.metropolis import Metropolis
from deepqmc.sampler.hamiltonian import Hamiltonian
from deepqmc.wavefunction.molecule import Molecule

from deepqmc.utils.plot_data import (load_observable, save_observalbe,
                                     plot_block, plot_walkers_traj,
                                     plot_energy, plot_data)

set_torch_double_precision()

# define the molecule
mol = Molecule(atom='Li 0 0 0; H 0 0 3.015',
               calculator='pyscf',
               basis='dzp',
               unit='bohr')

# define the wave function
wf = Orbital(mol, kinetic='jacobi', configs='ground_state', use_jastrow=True)

wf.jastrow.weight.data[0] = 1.

# sampler
sampler = Metropolis(nwalkers=500,
                     nstep=2000,
                     step_size=0.05,
                     nelec=wf.nelec,
                     ndim=wf.ndim,
                     init=mol.domain('atomic'),
                     move={