def calculate(model, domain_size, buffer_size=0, diis=True):
    hf = dchf.DCHF(model)
    assign_chain_domains(hf, domain_size, buffer_size)

    # Since the convergence criterion is never met an exception will be raised
    try:
        hf.kernel(tolerance=0, maxiter=maxiter, fock_hook="diis" if diis else None)
    except RuntimeError:
        pass
    return hf.convergence_history
times = []
titles = []
errors = []

pyplot.figure(figsize=(12, 4.8))
pyplot.subplot(121)
for domain_size in [2, 4, 6, 8, 12, 24]:
    print "Size={:d}".format(domain_size)
    x = list(sorted(set([0, 2, (domain_size // 4) * 2, domain_size])))
    y = []
    for buffer_size in x:
        print "  buff={:d}".format(buffer_size)

        t = time.time()
        hf = dchf.DCHF(model)
        assign_chain_domains(hf, domain_size, buffer_size)
        hf.kernel(tolerance=1e-9, maxiter=30)
        t = time.time() - t
        times.append(t)

        error = abs(ref_e - hf.e_tot)

        titles.append("{:d}({:d})".format(domain_size, buffer_size))
        errors.append(error)
        y.append(error)

        if buffer_size + domain_size >= N:
            break

    pyplot.semilogy(x[:len(y)],
                    y,
ref_hf_energy = []
errors_dm = []
errors_dm_intrinsic = []

for alt in spacing:

    print "Alt =", alt

    model = atomic_chain(N, alt_spacing=alt)
    ref_hf = scf.RHF(model)
    ref_hf.conv_tol = tolerance
    ref_hf.kernel()
    dm_ref = ref_hf.make_rdm1()

    hf = dchf.DCHF(model)
    assign_chain_domains(hf, 4, 2)
    hf.kernel(tolerance=tolerance)

    mask = numpy.logical_not(hf.domains_pattern(2))

    hf_energy.append(hf.e_tot)
    ref_hf_energy.append(ref_hf.e_tot)
    errors_dm.append(abs(dm_ref - hf.dm).max())
    errors_dm_intrinsic.append(abs(dm_ref * mask).max())

pyplot.figure(figsize=(12, 4.8))
pyplot.subplot(121)
pyplot.scatter(spacing - 1.4, hf_energy, label="DCHF")
pyplot.scatter(spacing - 1.4, ref_hf_energy, label="HF")

pyplot.xlabel("Dimerization parameter (A)")
from test_common import atomic_chain
from test_dchf import assign_chain_domains

import fake
pyplot = fake.pyplot()

N = 24
tolerance = 1e-5

model = atomic_chain(N, alt_spacing=2.3)
hf_dimer = scf.RHF(model)
hf_dimer.conv_tol = tolerance
hf_dimer.kernel()

dchf_dimer = DCHF(model)
assign_chain_domains(dchf_dimer, 2, 2)
dchf_dimer.kernel(tolerance=tolerance)

model = atomic_chain(N, alt_spacing=1.53)
hf_uniform = scf.RHF(model)
hf_uniform.conv_tol = tolerance
hf_uniform.kernel()

dchf_uniform = DCHF(model)
assign_chain_domains(dchf_uniform, 2, 2)
dchf_uniform.kernel(tolerance=tolerance)

pyplot.figure(figsize=(12, 10))
for hf, subplot, title in (
        (hf_dimer, 221, "HF dimerized chain"),
        (hf_uniform, 222, "HF uniform chain"),
def setup_full(model):
    hf = dchf.DCHF(model)
    assign_chain_domains(hf, model.natm, 0)
    return hf
def setup(model):
    hf = dchf.DCHF(model)
    assign_chain_domains(hf, 1, 0)
    return hf
Exemple #7
0
    (dchf.DCCCSD, 122, "DC-CCSD", ref_ccsd_e2),
):
    print "==", title, "=="
    pyplot.subplot(subplot)

    for wocc in (1, 0.5, 0):
        print "wocc={:.1f}".format(wocc)
        y = []
        for c in configurations:
            print "  config={}".format(repr(c))

            if c in mf_cache:
                hf = mf_cache[c]
            else:
                hf = dchf.DCHF(model)
                assign_chain_domains(hf, *c)
                hf.kernel(tolerance=tolerance)
                mf_cache[c] = hf

            mp = driver(hf, w_occ=wocc)
            mp.kernel()

            y.append(abs(reference - mp.e2))
            print "  {:.3e}".format(y[-1])

        pyplot.semilogy(x, y, marker="x", label="w_occ={:.1f}".format(wocc))

    pyplot.xticks(x, list("{:d}({:d})".format(*i) for i in configurations))
    pyplot.ylabel("Absolute error (Ry)")
    pyplot.xlabel("Domain size (buffer size)")
    pyplot.legend()