def temperature_evolution(*args, labels, title, save=False):
    """Plot MSD for the given simnames"""
    fig = plt.figure(figsize=(8, 8), dpi=150)
    ax = fig.add_subplot(1, 1, 1)
    df1, df2 = extract.extract_def(args[0])
    strain = np.linspace(0, 1.718, df1.shape[0])
    for index, filename in enumerate(args):
        df1, df2 = extract.extract_def(filename)
        ax.plot(strain, df1.iloc[:, 7], label=labels[index], linewidth=2)
    ax.legend(fontsize=16)
    ax = set_x_props(ax, 'Strain')
    ax = set_y_props(ax, 'Temperature')
    props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
    textstr = '\n'.join(('Parallel electric field', 'Electric field = 1.2'))
    ax.text(0.40,
            0.70,
            textstr,
            transform=ax.transAxes,
            fontsize=14,
            verticalalignment='top',
            bbox=props)
    ax.set_xlim(0, 1.71)
    if save:
        plt.tight_layout()
        full_path = imagesavepath + 'temperature-' + title + '.png'
        plt.savefig(full_path, dpi=300)
def energy_all_evolution(*args, labels, title, save=False):
    """Plot energy for the given simnames"""
    energy = [9, 12, 13, 14]
    ene_label = ['Bonded-energy', 'Ecoul', 'Van-der-Waal', 'Total']
    df1, df2 = extract.extract_def(args[0])
    strain = np.linspace(0, 1.718, df1.shape[0])
    label_fname = ''
    for element in labels:
        label_fname += element
    for i in range(4):
        fig = plt.figure(figsize=(8, 8), dpi=150)
        ax = fig.add_subplot(1, 1, 1)
        for index, filename in enumerate(args):
            df1, df2 = extract.extract_def(filename)
            ene_temp = (df1.iloc[:, energy[i]] - df1.iloc[0, energy[i]]).values
            ax.plot(strain, ene_temp, label=labels[index], linewidth=2)
        ax.legend(fontsize=16)
        ax.set_title(title, fontsize=20)
        ax = set_x_props(ax, 'Strain')
        ax = set_y_props(ax, ene_label[i])
        ax.set_xlim(0, 1.71)
        if save:
            plt.tight_layout()
            full_path = imagesavepath + 'v20/energy_during_deformation/32C_128DP_energy_' + str(
                ene_label[i]) + label_fname + '.png'
            plt.savefig(full_path, dpi=300)
def return_mean_stress(*args):
    """Read stress for the each of the given files and return the mean stress.
    Typically used for finding out the mean stress for a deformation of
    the same system along different directions or at different equilibration
    times.

    Args:
    *args (str): file name for the deformation.

    Returns:
    m_stress (list): a list containing the mean stress for the given deformations.
    """
    df1, df2 = extract.extract_def(args[0])
    m_stress = np.zeros((df1.shape[0], len(args)))
    for index, arg in enumerate(args):
        df1, df2 = extract.extract_def(arg)
        df1 = df1.values
        df2 = df2.values
        deformation_along = np.argmax(
            np.array([np.std(df1[:, 1]),
                      np.std(df1[:, 2]),
                      np.std(df1[:, 3])]))
        m_stress[:, index] = df1[:, deformation_along + 1]
    m_stress = np.mean(m_stress, axis=1)
    return m_stress
def energy_evolution_single(simname, save=False):
    """
    Find out energy evolution during the deformation of the given simulation.

    Args:
    simname (string): Name of the simulation
    save (bool): Whether to save the plot
    """
    def1, def2 = extract.extract_def(simname)
    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_subplot(1, 1, 1)
    #epair = (def1.iloc[:,8] - def1.iloc[0,8]).values
    ebond = (def1.iloc[:, 9] - def1.iloc[0, 9]).values
    ecoul = (def1.iloc[:, 12] - def1.iloc[0, 12]).values
    evdwl = (def1.iloc[:, 13] - def1.iloc[0, 13]).values
    etotal = (def1.iloc[:, 14] - def1.iloc[0, 14]).values
    strain = np.linspace(0, 1.718, len(etotal))
    #ax.plot(strain, epair, label = 'pairwise')
    ax.plot(strain, ebond, label='bonded')
    ax.plot(strain, ecoul, label='coulombic')
    ax.plot(strain, evdwl, label='Van der Waals')
    ax.plot(strain, etotal, label='total')
    ax = set_x_props(ax, 'Strain')
    ax = set_y_props(ax, 'Energy')
    ax.set_xlim(0, 1.71)
    ax.legend(fontsize=14)
    plt.tight_layout()
    if save:
        curr_name = simname + '_energy_evolution_deformation.png'
        full_path = imagesavepath + curr_name
        plt.savefig(full_path)
def return_mean_temperature(*args):
    """Read temperature for the each of the given files and return the mean temperature.
    Typically used for finding out the mean temperature for a deformation of
    the same system along different directions or at different equilibration
    times.

    Args:
    *args (str): file name for the deformation.

    Returns:
    m_temperature (list): a list containing the mean stress for the given deformations.
    """
    df1, df2 = extract.extract_def(args[0])
    m_temperature = np.zeros((df1.shape[0], len(args)))
    for index, arg in enumerate(args):
        df1, df2 = extract.extract_def(arg)
        df1 = df1.values
        df2 = df2.values
        m_temperature[:, index] = df1[:, 7]
    m_temperature = np.mean(m_temperature, axis=1)
    return m_temperature
def energy_evolution_comparison(simname, ids, save=False):
    """
    Compare energy evolution along different directions for the 
    given simulation.

    Args:
    simname (string): Name of the simulation
    ids: if '2_x', '3_x' then [2,3]
    save (bool): Whether to save the plot
    """
    dirs = ['x', 'y', 'z', 'x', 'y', 'z']
    df1 = {}
    df2 = {}
    col_nums = [8, 9, 12, 13, 14, 17, 7, 15, 16]
    col_labels = [
        'pairwise', 'bonded', 'coulombic', 'Van der Waals', 'total', 'density',
        'temp', 'pe', 'ke'
    ]
    for index in range(6):
        fname = simname + '_' + str(ids[int(index / 3)]) + '_' + dirs[index]
        df1[index], df2[index] = extract.extract_def(fname)
    fig = plt.figure(figsize=(20, 18))
    strain = np.arange(0, 1.718, 0.001)
    for index in range(9):
        ax = fig.add_subplot(3, 3, index + 1)
        for inner_index in range(6):
            #curr_energy = (df1[inner_index].iloc[:,col_nums[index]] - df1[inner_index].iloc[0,col_nums[index]]).values
            #ax.plot(strain, curr_energy, label = dirs[inner_index])
            ax.plot(strain,
                    df1[inner_index].iloc[:, col_nums[index]],
                    label=dirs[inner_index])
            ax.legend(fontsize=16)
            ax.set_title(col_labels[index], fontsize=20)
            ax = set_x_props(ax, 'Strain')
            ax = set_y_props(ax, 'Energy')
            ax.set_xlim(0, 1.71)
    if save:
        curr_name = simname + '_energy_evolution_deformation_comparison.png'
        full_path = imagesavepath + curr_name
        plt.tight_layout()
        plt.savefig(full_path)
def understand_variation(*args,
                         labels,
                         smoothed=False,
                         save=False,
                         msd=False,
                         deformation_strain_end=1.72002,
                         plot_strain_end=1.0,
                         units='lj'):
    """
    Plot data for repeats of same simulation to understand intra-model
    variation.

    Args:
    fname (str) : Names of the simulation.
    smoothed (=False) : Apply a Savgol filter to smooth curves
    """
    fig1 = plt.figure(figsize=[8, 8], dpi=100)
    for index, arg in enumerate(args):
        df1, df2 = extract.extract_def(arg)
        df1 = df1.values
        df2 = df2.values
        deformation_along = np.argmax(
            np.array([np.std(df1[:, 1]),
                      np.std(df1[:, 2]),
                      np.std(df1[:, 3])]))
        plt.figure(1)
        till = len(df1[:, deformation_along + 1])
        strain = np.linspace(0, deformation_strain_end, till)
        if smoothed:
            if units == 'real':
                y_noise = df1[:till, deformation_along + 1] * 1000
            elif units == 'lj':
                y_noise = df1[:till, deformation_along + 1]
            y = signal.savgol_filter(
                y_noise,
                357,  # window size used for filtering
                1,
                mode='nearest')  # order of polynomial
            y = np.asarray(y)
            plt.plot(strain[:till], y.T, linewidth=2, label=arg)
        else:
            #strain=np.arange(0,1.718,0.00)
            if units == 'real':
                plt.plot(strain[:till],
                         df1[:till, deformation_along + 1] * 1000,
                         linewidth=2,
                         label=arg)
            elif units == 'lj':
                plt.plot(strain[:till],
                         df1[:till, deformation_along + 1],
                         linewidth=2,
                         label=labels[index])
        if msd:
            plt.figure(2)
            ax2 = plt.gca()
            ax2.plot(strain, df2[:, 4], label='positive')
            ax2.plot(strain, df2[:, 8], label='negative')
            ax2.plot(strain, df2[:, 12], label='ions')
            ax2.plot(strain,
                     df2[:, 16],
                     label='neutral',
                     linestyle=':',
                     linewidth=2)
        #ax2.plot(strain,df2[:,20],label=arg,linewidth=2)
        #ax3.plot(df2[:,0],df2[:,19],label='positive')
        #ax3.plot(df2[:,0],df2[:,22],label='negative')
        #ax3.plot(df2[:,0],df2[:,25],label='ions')
        #ax3.plot(df2[:,0],df2[:,28],label='neutral')
        #plt.figure(3)
        #plt.plot(strain,df2[:,35],label=arg)
    plt.figure(1)
    plt.xlabel('Strain', fontsize=20, fontfamily='serif')

    if units == 'real':
        plt.ylabel('Stress (MPa)', fontsize=20, fontfamily='serif')
    elif units == 'lj':
        plt.ylabel('Stress', fontsize=20, fontfamily='serif')
    ax = plt.gca()
    ax = set_strain_props(ax)
    fontProperties = {'family': 'serif', 'size': 16}
    ax.set_yticklabels(ax.get_yticks(), fontProperties)
    plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%g'))
    plt.legend(fontsize=16)
    ax.set_xlim(0, plot_strain_end)
    plt.tight_layout()
    if msd:
        ax2 = set_strain_props(ax2)
        plt.ylabel('MSD ($\AA ^2$)', fontsize=20, fontfamily='serif')
        plt.legend()
        plt.close()
        plt.figure(3)
        plt.xlabel('Strain', fontsize=20, fontfamily='Serif')
        plt.ylabel('Non Gaussian Parameter', fontsize=20, fontfamily='Serif')
        plt.legend()
        plt.close()
    full_path = imagesavepath + str(args[0])[:-4]
    if save:
        if smoothed:
            fname = full_path + '_smoothed.png'
            print(fname)
            fig1.savefig(fname, dpi=300)
        else:
            fname = full_path + '.png'
            print(fname)
            fig1.savefig(fname, dpi=300)