def plotMeanSquaredDisplacement(particles,
                                t,
                                N,
                                eps,
                                chartName,
                                plotDiffusionConstant=False,
                                filename="meanSquaredDisplamcent"):

    msd, diffusion_constant = MDFunctions.ComputeMeanSquaredDisplacement(
        t, particles)

    msd, yLabel = MDFunctions.SigmaToAngstrom(msd)
    t, xLabel = MDFunctions.ArgonTimeToSeconds(t)

    plt.title(chartName)
    plt.plot(t, msd, label=f'Mean squared displacement')
    plt.xlabel(xLabel)
    plt.ylabel(f"Mean sq. disp {yLabel}")
    plt.legend()

    plt.savefig(f'./fig/{filename}.jpg')
    plt.show()
    if plotDiffusionConstant:
        plt.title("Diffusion constant")
        plt.plot(t, diffusion_constant, label=f'Diffusion constant')
        plt.xlabel(xLabel)
        plt.ylabel('D')
        plt.legend()

        plt.savefig(f'{filename}_diffusionConstant.jpg')
        plt.show()
Exemple #2
0
def Task4_di_read(t, filename):
    num_bins = 10

    bin_edges = np.linspace(0, 5, num_bins + 1)
    bin_centres = 0.5 * (bin_edges[1:] + bin_edges[:-1])
    V = constants.box**3

    #Read the file prepared by the previous
    particles, maxTindex = MDFileWriter.ReadEverything(filename, N)

    #Convert x-axis units from sigma to Ångstrøm
    bin_centres = MDFunctions.SigmaToAngstrom(bin_centres)

    if t is None:
        t = maxTindex
    elif t > maxTindex:
        raise Exception(
            "Trying to read out rdf from frame {t} which only simulated {maxTindex} frames"
        )

    tInSeconds = MDFunctions.ArgonTimeToSeconds(t)

    count = len(particles)
    x = np.array([[0., 0., 0.] for i in range(count)])  # Velocity

    j = 0
    counter = 0

    for j in range(0, count):
        x[counter] = particles[j].x[t]
        counter += 1

    #x = np.where(x > 0)

    #Bin the distance counts
    data = MDFunctions.rdf(bin_edges, x, V)

    chartName = f"Ar N={count} RDF after {tInSeconds[0]:11.6} {tInSeconds[1]}"
    # def barchart(data,  xlabels, chartName, filename = "barChart"):
    MDPlot.barchart(data, bin_centres, "RDF", chartName, f"RDF_{filename}")

    strLabels = []
    for lb in bin_centres[0]:
        strLabels.append(f"{lb:11.1f}")