Skip to content

hecss.planner

__all__ = ['plan_T_scan'] module-attribute

flatten = itertools.chain.from_iterable module-attribute

plan_T_scan(Tlo, Thi, nat, N=1, plot_dist=True)

Plan a geometric ladder of temperatures from Tlo to Thi.

Returns rows of (temperature, width, relative number of samples) for a system of nat atoms; N scales the sample counts and plot_dist draws the corresponding distributions.

Source code in hecss/planner.py
def plan_T_scan(Tlo, Thi, nat, N=1, plot_dist=True):
    """Plan a geometric ladder of temperatures from `Tlo` to `Thi`.

    Returns rows of `(temperature, width, relative number of samples)` for a
    system of `nat` atoms; `N` scales the sample counts and `plot_dist` draws
    the corresponding distributions.
    """
    l = Tlo
    # 1/sqrt(2) adjusts for the shape of the distribution 
    # generated by the HECSS.smple function.
    n = np.sqrt(3*nat/2/2) 
    s0 = l/n
    s = s0
    assert n>1
    a = (n+1)/(n-1)
    r = []
    while l <= Thi:
        sf = s 
        if l * a > Thi:
            sf *= 1.12

        r.append([l, s, sf/s0])
        l *= a
        s = l/n
    ns = 1
    frm = "N=%.1f"
    if N > 1 :
        ns = N/r[-1][-1]
        frm = "N=%.0f"
        r = [[l, s, int(round(ns*sf))] for l, s, sf in r]
    frm = frm + " T=%.0fK"
    if plot_dist:
        f = stats.norm.pdf
        x = np.linspace(Tlo*(1-3/n), Thi*(1+3/n), 600)
        y = np.zeros(x.shape)
        for c, (l, s, sf) in enumerate(r):
            p = sf*f(x, l, s)
            # plt.axvline(l-l/n, ymax=0.5, lw=1, ls='-', color=f'C{c}')
            # plt.axvline(l+l/n, ymin=0.5, lw=1, ls='-', color=f'C{c}')
            plt.plot(x, p, label=(frm % (sf, l))) #f'N={sf*ns:.1f} T={l:.0f}K'
            y += p
        plt.plot(x, y)
        plt.legend(loc='upper right')
        plt.xlabel('Temperature')
        plt.ylabel('Relative density')
        plt.title('Temperature scan. N=relative number of samples')
    return r