Esempio n. 1
0
def plot_pair_fits(pair, fits, use_agg=False, ylims=(0, 1)):
    if use_agg:
        import matplotlib as mpl
        mpl.use('Agg')
    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    for state, fit in fits[pair].items():
        ax.plot(fit, label=state)
    ax.set_xlabel('step')
    ax.set_ylabel('relative fit')
    ax.set_ylim(ylims)
    ax.legend(loc='best')
    ax.set_title(pair)
    tpl.timize(ax)
    fig.tight_layout()
    fig.savefig('figures/%s-fit.pdf' % pair, transparent=True)
    plt.close('all')
Esempio n. 2
0
def plot_pair_at_state(t1, t2, state, step, target_dir, 
        potentials_dir='./potentials', rdf_dir='./rdfs', use_agg=False, 
        to_angstrom=6.0, to_kcalpermol=0.1, lw=None):
    """Plot the RDFs (target and CG) and potential on the same plot for a given pair at a
    given state.

    Args
    ----
    t1 : str
        The first type in the pair
    t2 : str
        The second type in the pair
    state : str
        The name of the state
    target_dir : str
        Path to target RDFs
    potentials_dir : str
        Path to potentials from MS IBI optimization
    rdf_dir : str
        Path to RDFs from MS IBI optimization
    use_agg : bool
        Use Agg backend if true, may be useful for clusters with no display
    to_angstrom : float
        Multiply distance units by this to get into Angstrom
    to_kcalpermol : float
        Multiple energy units by this to get into kcal/mol

    Returns
    -------
    Nothing - prints plots in './figures'
    """

    if use_agg:
        import matplotlib as mpl
        mpl.use('Agg')
    import matplotlib.pyplot as plt
    fig, ax =  plt.subplots()
    pot_name = 'step{step}.pot.{t1}-{t2}.txt'.format(**locals())
    pot_file = os.path.join(potentials_dir, pot_name)
    rdf_name = '{t1}-{t2}-{state}.txt'.format(**locals())
    rdf_file = os.path.join(target_dir, rdf_name)
    try:
        potential = np.loadtxt(pot_file)
    except:
        raise IOError('File not found: {pot_file}'.format(**locals()))
    try:
        rdfs = [np.loadtxt(rdf_file)]
    except: 
        raise IOError('File not found: {rdf_file}'.format(**locals()))
    potential[:, 0] *= to_angstrom
    potential[:, 1] *= to_kcalpermol
    rdfs[0][:, 0] *= to_angstrom
    rdf_name = 'pair_{t1}-{t2}-state_{state}-step{step}.txt'.format(**locals())
    rdf_file = os.path.join(rdf_dir, rdf_name)
    rdfs.append(np.loadtxt(rdf_file))
    rdfs[1][:, 0] *= to_angstrom
    for rdf, label in zip(rdfs, ['Target', 'CG']):
        if lw: 
            ax.plot(rdf[:, 0], rdf[:, 1], label=label, lw=lw)
        else:
            ax.plot(rdf[:, 0], rdf[:, 1], label=label)
    ax.set_xlabel(u'r, \u00c5')
    ax.set_ylabel('g(r)')
    ax.set_ylim(bottom=0)
    ax.set_xlim(left=0)
    ax.set_title('{t1}-{t2}, {state}'.format(**locals()))
    pot_ax = ax.twinx()
    pot_ax.plot(potential[:, 0], potential[:, 1], "#0485d1")
    pot_ax.set_ylabel('V(r), kcal/mol')
    pot_ax.set_ylim(bottom=1.1*np.amin(potential[5:, 1]))
    pot_ax.set_ylim(top=-1.1*np.amin(potential[5:, 1]))
    pot_ax.set_xlim(left=0)
    ax.set_xlim(right=rdfs[0][-1, 0])
    extra = [[potential[-1, 0], ax.get_xlim()[1]], [0, 0]]
    pot_ax.plot(extra[0], extra[1], '#0485d1')
    ax.legend(loc=0)
    tpl.timize(ax)
    tpl.timize(pot_ax, legend=False, grid=False)
    fig.tight_layout()
    if not os.path.exists('figures'):
        os.makedirs('figures')
    fig.savefig('figures/{t1}-{t2}-{state}-step{step}.pdf'.format(**locals()),
            transparent=True)
    plt.close('all')