예제 #1
0
def OPTIMIZE(
    dft_checkfile,
    output,
    anchors=None,
    nconfig=1000,
    ci_checkfile=None,
    start_from=None,
    S=None,
    client=None,
    npartitions=None,
    jastrow_kws=None,
    slater_kws=None,
    linemin_kws=None,
):
    if linemin_kws is None:
        linemin_kws = {}

    target_root = 0
    if ci_checkfile is None:
        mol, mf = pyqmc.recover_pyscf(dft_checkfile)
        mc = None
    else:
        mol, mf, mc = pyqmc.recover_pyscf(dft_checkfile,
                                          ci_checkfile=ci_checkfile)
        mc.ci = mc.ci[target_root]

    if S is not None:
        mol = pyqmc.get_supercell(mol, np.asarray(S))

    wf, to_opt = pyqmc.generate_wf(mol,
                                   mf,
                                   mc=mc,
                                   jastrow_kws=jastrow_kws,
                                   slater_kws=slater_kws)
    if start_from is not None:
        pyqmc.read_wf(wf, start_from)

    configs = pyqmc.initial_guess(mol, nconfig)
    acc = pyqmc.gradient_generator(mol, wf, to_opt)
    if anchors is None:
        pyqmc.line_minimization(wf,
                                configs,
                                acc,
                                verbose=True,
                                hdf_file=output,
                                client=client,
                                npartitions=npartitions,
                                **linemin_kws)
    else:
        wfs = [pyqmc.read_wf(copy.deepcopy(wf), a) for a in anchors]
        wfs.append(wf)
        pyqmc.optimize_orthogonal(
            wfs,
            configs,
            acc,
            # verbose=True,
            hdf_file=output,
            client=client,
            npartitions=npartitions,
            **linemin_kws)
예제 #2
0
def VMC(
    dft_checkfile,
    output,
    nconfig=1000,
    ci_checkfile=None,
    start_from=None,
    S=None,
    client=None,
    npartitions=None,
    jastrow_kws=None,
    slater_kws=None,
    vmc_kws=None,
    accumulators=None,
):
    if vmc_kws is None:
        vmc_kws = {}

    target_root = 0
    if ci_checkfile is None:
        mol, mf = pyqmc.recover_pyscf(dft_checkfile)
        mc = None
    else:
        mol, mf, mc = pyqmc.recover_pyscf(dft_checkfile,
                                          ci_checkfile=ci_checkfile)
        mc.ci = mc.ci[target_root]

    if S is not None:
        print("S", S)
        mol = pyqmc.get_supercell(mol, np.asarray(S))

    if accumulators is None:
        accumulators = {}

    wf, _ = pyqmc.generate_wf(mol,
                              mf,
                              mc=mc,
                              jastrow_kws=jastrow_kws,
                              slater_kws=slater_kws)

    if start_from is not None:
        pyqmc.read_wf(wf, start_from)

    configs = pyqmc.initial_guess(mol, nconfig)

    pyqmc.vmc(wf,
              configs,
              accumulators=generate_accumulators(mol, mf, **accumulators),
              verbose=True,
              hdf_file=output,
              client=client,
              npartitions=npartitions,
              **vmc_kws)
예제 #3
0
파일: recipes.py 프로젝트: kkleiner1/pyqmc
def DMC(dft_checkfile,
        output,
        nconfig=1000,
        start_from=None,
        S=None,
        client=None,
        npartitions=None,
        jastrow_kws=None,
        slater_kws=None,
        dmc_kws=None,
        accumulators=None):
    if dmc_kws is None:
        dmc_kws = {}
    mol, mf = pyqmc.recover_pyscf(dft_checkfile)
    if S is not None:
        mol = pyqmc.get_supercell(mol, np.asarray(S))

    wf, _ = pyqmc.generate_wf(mol,
                              mf,
                              jastrow_kws=jastrow_kws,
                              slater_kws=slater_kws)

    if start_from is not None:
        pyqmc.read_wf(wf, start_from)

    configs = pyqmc.initial_guess(mol, nconfig)

    pyqmc.rundmc(wf,
                 configs,
                 accumulators=generate_accumulators(mol, mf, **accumulators),
                 verbose=True,
                 hdf_file=output,
                 client=client,
                 npartitions=npartitions,
                 **dmc_kws)
예제 #4
0
파일: recipes.py 프로젝트: kkleiner1/pyqmc
def OPTIMIZE(
    dft_checkfile,
    output,
    nconfig=1000,
    start_from=None,
    S=None,
    client=None,
    npartitions=None,
    jastrow_kws=None,
    slater_kws=None,
    linemin_kws=None,
):
    if linemin_kws is None:
        linemin_kws = {}
    mol, mf = pyqmc.recover_pyscf(dft_checkfile)
    if S is not None:
        mol = pyqmc.get_supercell(mol, np.asarray(S))

    wf, to_opt = pyqmc.generate_wf(mol,
                                   mf,
                                   jastrow_kws=jastrow_kws,
                                   slater_kws=slater_kws)
    if start_from is not None:
        pyqmc.read_wf(wf, start_from)

    configs = pyqmc.initial_guess(mol, nconfig)
    acc = pyqmc.gradient_generator(mol, wf, to_opt)
    pyqmc.line_minimization(wf,
                            configs,
                            acc,
                            verbose=True,
                            hdf_file=output,
                            client=client,
                            npartitions=npartitions,
                            **linemin_kws)
예제 #5
0
def test_molecule():
    chkname = "test_recover_pyscf.chk"
    mol = pyscf.gto.M(atom="He 0. 0. 0.",
                      basis="bfd_vdz",
                      ecp="bfd",
                      unit="bohr")
    for scf in [pyscf.scf.rhf.RHF, pyscf.scf.uhf.UHF]:
        if os.path.isfile(chkname):
            os.remove(chkname)
        mf = scf(mol)
        mf.chkfile = chkname
        mf.kernel()
        mol2, mf2 = pyqmc.recover_pyscf(chkname)
        print(type(mf2), scf)
        assert isinstance(mf2, scf)
예제 #6
0
def test_pbc():
    chkname = "test_recover_pyscf.chk"
    mol = pyscf.pbc.gto.M(
        atom="H 0. 0. 0.; H 1. 1. 1.",
        basis="gth-szv",
        pseudo="gth-pade",
        unit="bohr",
        a=(np.ones((3, 3)) - np.eye(3)) * 4,
    )
    for scf in [pyscf.pbc.scf.khf.KRHF, pyscf.pbc.scf.kuhf.KUHF]:
        if os.path.isfile(chkname):
            os.remove(chkname)
        mf = scf(mol, mol.make_kpts((2, 1, 1)))
        mf.chkfile = chkname
        mf.kernel()
        mol2, mf2 = pyqmc.recover_pyscf(chkname)
        print(type(mf2), scf)
        assert isinstance(mf2, scf)
예제 #7
0
def test():
    chkfile = "h2.hdf5"
    optfile = "linemin.hdf5"
    run_scf(chkfile)
    mol, mf = pyqmc.recover_pyscf(chkfile)
    noise = (np.random.random(mf.mo_coeff.shape) - 0.5) * 0.2
    mf.mo_coeff = mf.mo_coeff * 1j + noise

    slater_kws = {"optimize_orbitals": True}
    wf, to_opt = pyqmc.generate_wf(mol, mf, slater_kws=slater_kws)

    configs = pyqmc.initial_guess(mol, 100)
    acc = pyqmc.gradient_generator(mol, wf, to_opt)
    pyqmc.line_minimization(wf,
                            configs,
                            acc,
                            verbose=True,
                            hdf_file=optfile,
                            max_iterations=5)

    assert os.path.isfile(optfile)
    os.remove(chkfile)
    os.remove(optfile)