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()
def plotVelocityAutoCorrelation(particles,
                                t,
                                N,
                                chartName,
                                includeDiffusionCoefficientSubPlot=False,
                                filename="velocityAutoCorrelation"):

    vac, diffusion_coefficcient = MDFunctions.ComputeVelocityAutoCorrelation(
        t, particles)

    t, timeUnits = MDFunctions.ArgonTimeToSeconds(t)

    plt.subplot(1, 1, 1)
    plt.title(f"{chartName} Velocity correlation")
    plt.plot(t, vac, label=f'Velocity auto correlation')
    plt.xlabel(f"time ({timeUnits})")
    plt.ylabel('Vel. Autocorrelation')
    plt.legend()

    plt.savefig(f'{filename}_velcorr.jpg')
    plt.show()
    if includeDiffusionCoefficientSubPlot:
        plt.subplot(2, 1, 1)
        plt.title(f"{chartName} Diffusion Coefficient")
        plt.plot(t, diffusion_coefficcient, label=f'Diffusion coefficient')
        plt.xlabel('time(s)')
        plt.ylabel('Diffusion coefficient')

    plt.legend()

    plt.savefig(f'{filename}_diffcoeff.jpg')
    plt.show()
def plotTemperature(particles, t, N, chartName, filename="plotTemperature"):

    tPrime = MDFunctions.ComputeTemperatureReduced(N, particles)

    tKelvin = MDFunctions.ArgonTPrimeToKelvin(tPrime)

    tToSeconds, xLabel = MDFunctions.ArgonTimeToSeconds(t)

    plt.title(chartName)
    plt.plot(tToSeconds, tKelvin, label=f'Temperature (K)')
    plt.xlabel(xLabel)
    plt.ylabel('Kelvin (K)')
    plt.legend()

    plt.savefig(f'./fig/{filename}.jpg')
    plt.show()
Exemple #4
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}")