Esempio n. 1
0
    A.append(arr[::2, 1])
    arrE.append(arr[::2, 2:] / V)
    arrM.append(arr[1::2, 2:] / V)
    E.append(np.mean(arrE[i], axis=1))
    M.append(np.mean(arrM[i], axis=1))
    errE.append(errorAll(binning, arrE[i], Binning_K[i]))
    errM.append(errorAll(binning, arrM[i], Binning_K[i]))
    U.append(binderpar(arrM[i]))

print "Finished calculations."

# PLOTS ###################################################################################################
print "\n==Plots=="

p.new(title="Mean energy", xlabel="Temperature", ylabel="Energy")
p.plot(T_exact, E_exact, label="for L = 4, exact")
for i in range(len(Ising_L)):
    p.errorbar(T[i], E[i], yerr=errE[i], label="L=%s, MC" % Ising_L[i])

p.new(title="Mean absolute magnetization", xlabel="Temperature", ylabel=r"$\vert Magnetization \vert$")
p.plot(T_exact, M_exact, label="for L = 4, exact")
for i in range(len(Ising_L)):
    p.errorbar(T[i], M[i], yerr=errM[i], label="L=%s, MC" % Ising_L[i])
# p.make(ncols=1,show=False)

for i in range(len(Ising_L)):
    p.new(title="Frequency of energies (L=%s)" % Ising_L[i], xlabel="Energy", ylabel="Temperature")
    temp = (T[i] * np.ones_like(arrE[i]).T).T
    H, xedges, yedges = np.histogram2d(temp.flatten(), arrE[i].flatten(), bins=(len(T[i]), 100))
    p.imshow(
        H,
Esempio n. 2
0
    MC_M = arrayM.ravel()
    MC_P = arrayP
    print 'Finished metropolis calculation (acceptance=%s).' % (MC_acceptance)

    MC_errmE = errorAll(binning, arrayE)
    MC_errmM = errorAll(binning, arrayM)
    MC_errmMabs = errorAll(binning, abs(arrayM))

    print 'Finished error calculation.'
'''
=== PLOTS ===
'''

p.new(title='Mean energy', xlabel='Temperature', ylabel='Energy')
if useExact:
    p.plot(T, meanE, label='exact')
if useMC:
    p.errorbar(T, MC_meanE, yerr=MC_errmE, label='metropolis')

p.new(title='Mean magnetization', xlabel='Temperature', ylabel='Magnetization')
if useExact:
    p.plot(T, meanM, label='exact')
if useMC:
    p.errorbar(T, MC_meanM, yerr=MC_errmM, label='metropolis')

p.new(title='Mean absolute magnetization',
      xlabel='Temperature',
      ylabel=r'$\vert Magnetization \vert$')
if useExact:
    p.plot(T, meanMabs, label='exact')
if useMC:
Esempio n. 3
0
# open the trajectory file
vtffile = open('./plots/vmd_4_ljfluid/ljfluid.vtf', 'w')
# write the structure of the system into the file: 
# N particles ("atoms") with a radius of 0.5
vtffile.write('atom 0:%s radius 0.5\n' % (N-1))
vtffile.write('pbc %s %s %s\n' % (L, L, L))

# main loop
f = compute_forces(x, L)
while t < tmax:
    x, v, f = step_vv(x, v, f, dt)
    t += dt

    E = compute_energy(x, v, L)
    print "t=%s, E=%s" % (t, E)

    ts.append(t)
    Es.append(E)
    
    # write out that a new timestep starts
    vtffile.write('timestep\n')
    # write out the coordinates of the particles
    for i in range(N):
        vtffile.write("%s %s %s\n" % (x[0,i], x[1,i], x[2,i]))

vtffile.close()

p.new()
p.plot(ts, Es)
p.make(ncols=1)
Esempio n. 4
0
U = []

for i in range(len(Ising_L)):
    arr = load(Ising_L[i])
    V = Ising_L[i]**2 
    T.append(arr[::2,0])
    A.append(arr[::2,1])
    arrE.append(arr[::2,2:]/V)
    arrM.append(arr[1::2,2:]/V)
    E.append(np.mean(arrE[i],axis=1))
    M.append(np.mean(arrM[i],axis=1))
    errE.append(errorAll(binning,arrE[i],Binning_K[i]))
    errM.append(errorAll(binning,arrM[i],Binning_K[i]))
    U.append(binderpar(arrM[i]))

print 'Finished calculations.'

# PLOTS ###################################################################################################
print '\n==Plots=='

for bm in np.linspace(-0.14,-0.07,8):
    p.new(title='bm=%s'%bm,xlabel=r't*L^{-v}',ylabel=r'M*L^{bm/v}')
    for i in range(len(Ising_L)):
        X = (1-T[i]/Tc)*Ising_L[i]**(-v)
        Y = M[i]*Ising_L[i]**(bm/v)
        inx = np.abs(X)<20
        p.plot(X[inx],Y[inx],'o',alpha=0.75,label='L=%s'%Ising_L[i])

p.make(ncols=2,savewindow=True)

print 'Finished plots.'
Esempio n. 5
0
# main loop
while t < tmax:    
    x, v, f = step_vv(x, v, f, dt)
    t += dt
    
    traj.append(x.copy())
    Es.append(compute_energy(x, v))
    
    # write out that a new timestep starts
    vtffile.write('timestep\n')
    # write out the coordinates of the particles
    for i in range(N):
        vtffile.write("%s %s %s\n" % (x[0,i], x[1,i], x[2,i]))

vtffile.close()

traj = np.array(traj)

# ==== PLOTTING ====
# plot the trajectory
p.new(aspect='equal')
traj -= np.floor(traj/L)*L  #BECAUSE OF PBC
for i in range(N):
    p.plot(traj[:,0,i], traj[:,1,i], ",", label='%s'%i)

# plot the total energy
p.new()
p.plot(Es, label='energy')

p.make()
Esempio n. 6
0
# open the trajectory file
vtffile = open('./plots/vmd_4_ljfluid/ljfluid.vtf', 'w')
# write the structure of the system into the file:
# N particles ("atoms") with a radius of 0.5
vtffile.write('atom 0:%s radius 0.5\n' % (N - 1))
vtffile.write('pbc %s %s %s\n' % (L, L, L))

# main loop
f = compute_forces(x, L)
while t < tmax:
    x, v, f = step_vv(x, v, f, dt)
    t += dt

    E = compute_energy(x, v, L)
    print "t=%s, E=%s" % (t, E)

    ts.append(t)
    Es.append(E)

    # write out that a new timestep starts
    vtffile.write('timestep\n')
    # write out the coordinates of the particles
    for i in range(N):
        vtffile.write("%s %s %s\n" % (x[0, i], x[1, i], x[2, i]))

vtffile.close()

p.new()
p.plot(ts, Es)
p.make(ncols=1)
Esempio n. 7
0
    E = compute_energy(x, v)
    
    print "t=%s, E=%s" % (t, E)

    ts.append(t)
    Es.append(E)

    # write out that a new timestep starts
    vtffile.write('timestep\n')
    # write out the coordinates of the particles
    for i in range(N):
        vtffile.write("%s %s %s\n" % (x[0,i], x[1,i], x[2,i]))
    
    # for plotting
    traj = np.append(traj,[x[0:2,:] - np.floor(x[0:2,:]/L)*L],axis=0)

vtffile.close()

p.new()
for n in range(1,traj.shape[0]):
    i = (traj[n-1,0,:] - traj[n,0,:])**2+(traj[n-1,1,:] - traj[n,1,:])**2 > 1
    traj[n,:,i] = [None,None]
p.plot(traj[:,0,:],traj[:,1,:],'-', lw = 2, alpha=0.3)
p.plot(traj[0,0,:],traj[0,1,:],'ko', alpha=0.5 ,ms=10, mew = 4, label = 'start position')
p.plot(traj[-1,0,:],traj[-1,1,:],'wo', alpha=0.5 ,ms=10, mew = 4, label = 'end position')

p.new()
p.plot(ts, Es)
p.make(ncols=1)
Esempio n. 8
0
    MC_P = arrayP
    print 'Finished metropolis calculation.'

    MC_errmE = binningAll(arrayE)
    MC_errmM = binningAll(arrayM)
    MC_errmMabs = binningAll(abs(arrayM))

    print 'Finished error calculation.'
'''
=== PLOTS ===
'''
p = Plotter(show=True, pdf=False, pgf=False, name='ising')

p.new(name='Mean energy', xlabel='Temperature', ylabel='Energy')
if useExact:
    p.plot(T, meanE, label='exact')
if useMC:
    p.errorbar(T, MC_meanE, yerr=MC_errmE, label='metropolis')

p.new(name='Mean magnetization', xlabel='Temperature', ylabel='Magnetization')
if useExact:
    p.plot(T, meanM, label='exact')
if useMC:
    p.errorbar(T, MC_meanM, yerr=MC_errmM, label='metropolis')

p.new(name='Mean absolute magnetization',
      xlabel='Temperature',
      ylabel=r'\vertMagnetization\vert')
if useExact:
    p.plot(T, meanMabs, label='exact')
if useMC:
Esempio n. 9
0
print "... total energy"
jks0 = jke_seq(s0)
print "... potential energy"
jks1 = jke_seq(s1)
print "... kinetic energy"
jks2 = jke_seq(s2)
print "... temperature"
jks3 = jke_seq(s3)
print "... pressure"
jks4 = jke_seq(s4)
"""==== PLOTTING ===="""
print "Plotting..."

# first 1000 values of the data series s0, s1, s2, s3, s4 over time
p.new(xlabel='time', ylabel='value')
p.plot(s0, label='total energy')
p.plot(s1, label='potential energy')
p.plot(s2, label='kinetic energy')
p.plot(s3, label='temperature')
p.plot(s4, label='pressure')

s0 = Es
s1 = Epots
s2 = Ekins
s3 = Ts
s4 = Ps

# plot autocorrelation of s0, s1, s2, s3, s4 over k
p.new(xlabel='k', ylabel='normalized autocorrelation')
p.plot(acfn0, label='acf of total energy')
p.plot(acfn1, label='acf of potential energy')
Esempio n. 10
0
jks1 = jke_seq(s1)
print "... dataset 3"
jks2 = jke_seq(s2)
print "... dataset 4"
jks3 = jke_seq(s3)
print "... dataset 5"
jks4 = jke_seq(s4)



"""==== PLOTTING ===="""
print "Plotting..."

# first 1000 values of the data series s0, s1, s2, s3, s4 over time
p.new(xlabel='time',ylabel='value')
p.plot(s0[0:1000], label='dataset 1')
p.plot(s1[0:1000], label='dataset 2')
p.plot(s2[0:1000], label='dataset 3')
p.plot(s3[0:1000], label='dataset 4')
p.plot(s4[0:1000], label='dataset 5')

# plot autocorrelation of s0, s1, s2, s3, s4 over k
p.new(xlabel='k',ylabel='normalized autocorrelation')
p.plot(acfn0[0:100000], label='acf of dataset 1')
p.plot(acfn1[0:100000], label='acf of dataset 2')
p.plot(acfn2[0:100000], label='acf of dataset 3')
p.plot(acfn3[0:100000], label='acf of dataset 4')
p.plot(acfn4[0:100000], label='acf of dataset 5')

# plot autocorrelation via fft  of s0, s1, s2, s3, s4 over k
p.new(xlabel='k',ylabel='normalized autocorrelation via fft')
Esempio n. 11
0
U = []

for i in range(len(Ising_L)):
    arr = load(Ising_L[i])
    V = Ising_L[i]**2
    T.append(arr[::2, 0])
    A.append(arr[::2, 1])
    arrE.append(arr[::2, 2:] / V)
    arrM.append(arr[1::2, 2:] / V)
    E.append(np.mean(arrE[i], axis=1))
    M.append(np.mean(arrM[i], axis=1))
    errE.append(errorAll(binning, arrE[i], Binning_K[i]))
    errM.append(errorAll(binning, arrM[i], Binning_K[i]))
    U.append(binderpar(arrM[i]))

print 'Finished calculations.'

# PLOTS ###################################################################################################
print '\n==Plots=='

for bm in np.linspace(-0.14, -0.07, 8):
    p.new(title='bm=%s' % bm, xlabel=r't*L^{-v}', ylabel=r'M*L^{bm/v}')
    for i in range(len(Ising_L)):
        X = (1 - T[i] / Tc) * Ising_L[i]**(-v)
        Y = M[i] * Ising_L[i]**(bm / v)
        inx = np.abs(X) < 20
        p.plot(X[inx], Y[inx], 'o', alpha=0.75, label='L=%s' % Ising_L[i])

p.make(ncols=2, savewindow=True)

print 'Finished plots.'
Esempio n. 12
0
for i in range(len(Ising_L)):
    arr = load(Ising_L[i])
    V = Ising_L[i]**2 
    T.append(arr[::2,0])
    A.append(arr[::2,1])
    arrE.append(arr[::2,2:]/V)
    arrM.append(arr[1::2,2:]/V)
    E.append(np.mean(arrE[i],axis=1))
    M.append(np.mean(arrM[i],axis=1))
    errE.append(errorAll(binning,arrE[i],Binning_K[i]))
    errM.append(errorAll(binning,arrM[i],Binning_K[i]))
    U.append(binderpar(arrM[i]))

print 'Finished calculations.'

# PLOTS ###################################################################################################
print '\n==Plots=='

p.new(title='Binder parameter',xlabel='Temperature',ylabel='Binder parameter')
n = np.shape(T)[0]
for i in range(n): p.plot(T[i],U[i],label='for L = %s'%Ising_L[i])

p.new(title='Binder parameter',xlabel='1/Temperature = beta*k_B',ylabel='Binder parameter')
n = np.shape(T)[0]
for i in range(n): p.plot(1./T[i],U[i],label='for L = %s'%Ising_L[i])

p.make(ncols=2)

print 'Finished plots.'
Esempio n. 13
0
    MC_errmM = calcError(MC_meanM)
    MC_errmMabs = calcError(MC_meanMabs)
    print "error of MC mean E:", MC_errmE
    print "error of MC mean M:", MC_errmM
    print "error of MC mean |M|:", MC_errmMabs
    
    print 'Finished metropolis calculation.'

'''
=== PLOTS ===
'''
p = Plotter(show = True, pdf = False, pgf = False, name='ising')

p.new(name='Mean energy',xlabel='Temperature',ylabel='Energy')
if useExact:
    p.plot(T,meanE,label='exact')
if useMC:
    p.errorbar(T, MC_meanE, yerr=MC_errmE, label='metropolis')

p.new(name='Mean magnetization',xlabel='Temperature',ylabel='Magnetization')
if useExact:
    p.plot(T,meanM,label='exact')
if useMC:
    p.errorbar(T, MC_meanM, yerr=MC_errmM, label='metropolis')

p.new(name='Mean absolute magnetization',xlabel='Temperature',ylabel=r'\vertMagnetization\vert')
if useExact:
    p.plot(T,meanMabs,label='exact')
if useMC:
    p.errorbar(T, MC_meanMabs, yerr=MC_errmMabs, label='metropolis')
Esempio n. 14
0
    MC_P = arrayP
    print 'Finished metropolis calculation (acceptance=%s).'%(MC_acceptance)

    MC_errmE = errorAll(binning,arrayE)
    MC_errmM = errorAll(binning,arrayM)
    MC_errmMabs = errorAll(binning,abs(arrayM))
    
    print 'Finished error calculation.'

'''
=== PLOTS ===
'''

p.new(title='Mean energy',xlabel='Temperature',ylabel='Energy')
if useExact:
    p.plot(T,meanE,label='exact')
if useMC:
    p.errorbar(T, MC_meanE, yerr=MC_errmE, label='metropolis')

p.new(title='Mean magnetization',xlabel='Temperature',ylabel='Magnetization')
if useExact:
    p.plot(T,meanM,label='exact')
if useMC:
    p.errorbar(T, MC_meanM, yerr=MC_errmM, label='metropolis')

p.new(title='Mean absolute magnetization',xlabel='Temperature',ylabel=r'$\vert Magnetization \vert$')
if useExact:
    p.plot(T,meanMabs,label='exact')
if useMC:
    p.errorbar(T, MC_meanMabs, yerr=MC_errmMabs, label='metropolis')
Esempio n. 15
0
errM = []
U = []

for i in range(len(Ising_L)):
    arr = load(Ising_L[i])
    V = Ising_L[i]**2 
    T.append(arr[::2,0])
    A.append(arr[::2,1])
    arrE.append(arr[::2,2:]/V)
    arrM.append(arr[1::2,2:]/V)
    E.append(np.mean(arrE[i],axis=1))
    M.append(np.mean(arrM[i],axis=1))
    errE.append(errorAll(binning,arrE[i],Binning_K[i]))
    errM.append(errorAll(binning,arrM[i],Binning_K[i]))
    U.append(binderpar(arrM[i]))

print 'Finished calculations.'

# PLOTS ###################################################################################################
print '\n==Plots=='
p.new(title='magnetization',xlabel='L',ylabel='magnetization M',xscale='log',yscale='log')
func = lambda x, *p: x**(-p[0]/v)*p[1]
f = Fitter(func, [-0.25,1])
f.loadData(np.array(Ising_L), np.array(M).ravel(), scale='linear')
p.plot(Ising_L,M,'o',label='Output of the simulation')
p.plot(f.x,f.y,'-',label=r'Fitt M = L^-{bm/v)*C with ...'+'\n'+'bm = %.4f, v = %.4f, C = %.4f'%(f.params[0],v,f.params[1]))

p.make(ncols=2)

print 'Finished plots.'
Esempio n. 16
0
# ==== DEFINITIONS ====
EPS = 1
SIG = 1
NParticles = 1000

# ==== FUNCTIONS ====
def compute_lj_potential(rij, eps=EPS, sig=SIG):
    q = sig / np.linalg.norm(rij)
    return 4 * eps * (q ** 12 - q ** 6)


def compute_lj_force(rij, eps=EPS, sig=SIG):
    norm = np.linalg.norm(rij)
    q = sig / norm
    return 4 * eps * (12 * q ** 11 - 6 * q ** 5) * q / norm ** 2 * rij


# ==== CALCULATION ====
d = np.zeros((NParticles, 3))
d[:, 0] = np.linspace(0.85, 2.5, NParticles)
potential = np.array(map(compute_lj_potential, d))
force = np.array(map(compute_lj_force, d))

# ==== PLOTTING ====
p.new(title=u"LJ potential", xlabel="distance", ylabel="potential")
p.plot(d[:, 0], potential, "-", label=u"potential")
p.new(title=u"LJ force", xlabel="distance", ylabel="1st component of force")
p.plot(d[:, 0], force[:, 0], "-", label=u"force")
p.make()
Esempio n. 17
0
Ekins = np.append(Ekins_old, Ekins, axis=0)
Ts = np.append(Ts_old, Ts, axis=0)
Ps = np.append(Ps_old, Ps, axis=0)
traj = np.append(traj_old, traj, axis=0)
datafile = open(datafilename, "w")
pickle.dump([ts, Es, Epots, Ekins, Ts, Ps, traj], datafile)
datafile.close()

"""==== PLOTTING ===="""
print "Plotting..."

# Trajectories
p.new(aspect="equal", xlabel="x-coordinate", ylabel="y-coordinate")
traj -= np.floor(traj / L) * L

p.plot([0, L, L, 0, 0], [0, 0, L, L, 0], "b-", lw=2)
p.plot(traj[-1, 0, :], traj[-1, 1, :], "wo", alpha=0.1, ms=7, mew=2)
p.plot(traj[0, 0, :], traj[0, 1, :], "+", c=[0.8, 0.8, 0.8], alpha=0.5)

i = range(traj.shape[2])
np.random.shuffle(i)
tpart = np.array(traj[:, :, i[:3]])
for n in range(1, tpart.shape[0]):
    i = (tpart[n - 1, 0, :] - tpart[n, 0, :]) ** 2 + (tpart[n - 1, 1, :] - tpart[n, 1, :]) ** 2 > L * L * 0.5
    tpart[n, :, i] = [None, None, None]
nmax = tpart.shape[2]
cm = cm.get_cmap("Dark2")
colors = [cm(1.0 * i / nmax) for i in range(nmax)]
for n in range(nmax):
    p.plot(tpart[:, 0, n], tpart[:, 1, n], "-", c=colors[n], alpha=0.8)
    p.plot(tpart[-1, 0, n], tpart[-1, 1, n], "o", c=colors[n], alpha=0.8, ms=7, mew=2)
Esempio n. 18
0
vtffile.write('atom 0:%s radius 0.5\n' % (N-1))

# main loop
while t < tmax:
    x, v, f = step_vv(x, v, f, dt)
    t += dt

    traj.append(x.copy())
    Es.append(compute_energy(x, v))
    
    # write out that a new timestep starts
    vtffile.write('timestep\n')
    # write out the coordinates of the particles
    for i in range(N):
        vtffile.write("%s %s %s\n" % (x[0,i], x[1,i], x[2,i]))

vtffile.close()

traj = np.array(traj)

# ==== PLOTTING ====
# plot the trajectory
p.new(aspect='equal')
for i in range(N):
    p.plot(traj[:,0,i], traj[:,1,i], label='%s'%i)

# plot the total energy
p.new()
p.plot(Es, label='energy')

p.make()
Esempio n. 19
0
meanEpots=np.mean(Epots[:10])
print "meanEpots=", meanEpots
meanEkins=np.mean(Ekins[:10])
print "meanEkins=", meanEkins
meanTs=np.mean(Ts[:10])
print "meanTs=", meanTs
meanPs=np.mean(Ps[:10])
print "meanPs=", meanPs

print "Plotting..."

# Trajectories
p.new(title='Trajectories', aspect='equal',xlabel='x-coordinate',ylabel='y-coordinate')
traj -= np.floor(traj/L)*L

p.plot([0,L,L,0,0],[0,0,L,L,0],'b-', lw=2)
p.plot(traj[-1,0,:],traj[-1,1,:],'wo', alpha=0.1 ,ms=7, mew = 2)
p.plot(traj[0,0,:],traj[0,1,:],'+', c=[0.8,0.8,0.8], alpha=0.1)

i = range(traj.shape[2])
np.random.shuffle(i)
tpart = np.array(traj[:,:,i[:3]])
for n in range(1,tpart.shape[0]):
    i = (tpart[n-1,0,:] - tpart[n,0,:])**2+(tpart[n-1,1,:] - tpart[n,1,:])**2 > 50
    tpart[n,:,i] = [None,None,None]
nmax = tpart.shape[2]
cm = cm.get_cmap('Dark2')
colors=[cm(1.*i/nmax) for i in range(nmax)]
for n in range(nmax):
    p.plot(tpart[:,0,n],tpart[:,1,n],'-', c = colors[n], alpha=0.8)
    p.plot(tpart[-1,0,n],tpart[-1,1,n],'o', c = colors[n], alpha=0.8 ,ms=7, mew = 2)
Esempio n. 20
0
    A.append(arr[::2,1])
    arrE.append(arr[::2,2:]/V)
    arrM.append(arr[1::2,2:]/V)
    E.append(np.mean(arrE[i],axis=1))
    M.append(np.mean(arrM[i],axis=1))
    errE.append(errorAll(binning,arrE[i],Binning_K[i]))
    errM.append(errorAll(binning,arrM[i],Binning_K[i]))
    U.append(binderpar(arrM[i]))

print 'Finished calculations.'

# PLOTS ###################################################################################################
print '\n==Plots=='

p.new(title='Mean energy',xlabel='Temperature',ylabel='Energy')
p.plot(T_exact,E_exact,label='for L = 4, exact')
for i in range(len(Ising_L)): p.errorbar(T[i], E[i], yerr=errE[i], label='L=%s, MC'%Ising_L[i])

p.new(title='Mean absolute magnetization',xlabel='Temperature',ylabel=r'$\vert Magnetization \vert$')
p.plot(T_exact,M_exact,label='for L = 4, exact')
for i in range(len(Ising_L)): p.errorbar(T[i], M[i], yerr=errM[i], label='L=%s, MC'%Ising_L[i])
#p.make(ncols=1,show=False)

for i in range(len(Ising_L)):
    p.new(title='Frequency of energies (L=%s)'%Ising_L[i],xlabel='Energy',ylabel='Temperature')
    temp = (T[i]*np.ones_like(arrE[i]).T).T
    H, xedges, yedges = np.histogram2d(temp.flatten(), arrE[i].flatten(), bins=(len(T[i]),100))
    p.imshow(H, extent=[yedges[0], yedges[-1], xedges[0], xedges[-1]], interpolation='nearest',aspect='auto',origin='lower',norm=LogNorm())
    
    p.new(title='Frequency of magnetizations (L=%s)'%Ising_L[i],xlabel='Absolute magnetization',ylabel='Temperature')
    temp = (T[i]*np.ones_like(arrM[i]).T).T
Esempio n. 21
0
    print "Finished metropolis calculation."

    MC_errmE = binningAll(arrayE)
    MC_errmM = binningAll(arrayM)
    MC_errmMabs = binningAll(abs(arrayM))

    print "Finished error calculation."

"""
=== PLOTS ===
"""
p = Plotter(show=True, pdf=False, pgf=False, name="ising")

p.new(name="Mean energy", xlabel="Temperature", ylabel="Energy")
if useExact:
    p.plot(T, meanE, label="exact")
if useMC:
    p.errorbar(T, MC_meanE, yerr=MC_errmE, label="metropolis")

p.new(name="Mean magnetization", xlabel="Temperature", ylabel="Magnetization")
if useExact:
    p.plot(T, meanM, label="exact")
if useMC:
    p.errorbar(T, MC_meanM, yerr=MC_errmM, label="metropolis")

p.new(name="Mean absolute magnetization", xlabel="Temperature", ylabel=r"\vertMagnetization\vert")
if useExact:
    p.plot(T, meanMabs, label="exact")
if useMC:
    p.errorbar(T, MC_meanMabs, yerr=MC_errmMabs, label="metropolis")
Esempio n. 22
0
    T.append(arr[::2,0])
    A.append(arr[::2,1])
    arrE.append(arr[::2,2:]/V)
    arrM.append(arr[1::2,2:]/V)
    E.append(np.mean(arrE[i],axis=1))
    M.append(np.mean(arrM[i],axis=1))
    errE.append(errorAll(binning,arrE[i],Binning_K[i]))
    errM.append(errorAll(binning,arrM[i],Binning_K[i]))

print 'Finished calculations.'

# PLOTS ###################################################################################################
print '\n==Plots=='

p.new(title='Mean energy',xlabel='Temperature',ylabel='Energy')
p.plot(T_exact,E_exact,label='L = 4, exact')
for i in range(len(Ising_L)): p.errorbar(T[i], E[i], yerr=errE[i], label='L=%s, MC'%Ising_L[i])

p.new(title='Mean absolute magnetization',xlabel='Temperature',ylabel=r'$\vert Magnetization \vert$')
p.plot(T_exact,M_exact,label='L = 4, exact')
for i in range(len(Ising_L)): p.errorbar(T[i], M[i], yerr=errM[i], label='L=%s, MC'%Ising_L[i])
#p.make(ncols=1,show=False)

for i in range(len(Ising_L)):
    p.new(title='Frequency of energies (L=%s)'%Ising_L[i],xlabel='Energy',ylabel='Temperature')
    temp = (T[i]*np.ones_like(arrE[i]).T).T
    H, xedges, yedges = np.histogram2d(temp.flatten(), arrE[i].flatten(), bins=(len(T[i]),100))
    p.imshow(H, extent=[yedges[0], yedges[-1], xedges[0], xedges[-1]], interpolation='nearest',aspect='auto',origin='lower',norm=LogNorm())
    
    p.new(title='Frequency of magnetizations (L=%s)'%Ising_L[i],xlabel='Absolute magnetization',ylabel='Temperature')
    temp = (T[i]*np.ones_like(arrM[i]).T).T
Esempio n. 23
0
    T.append(arr[::2, 0])
    A.append(arr[::2, 1])
    arrE.append(arr[::2, 2:] / V)
    arrM.append(arr[1::2, 2:] / V)
    E.append(np.mean(arrE[i], axis=1))
    M.append(np.mean(arrM[i], axis=1))
    errE.append(errorAll(binning, arrE[i], Binning_K[i]))
    errM.append(errorAll(binning, arrM[i], Binning_K[i]))

print 'Finished calculations.'

# PLOTS ###################################################################################################
print '\n==Plots=='

p.new(title='Mean energy', xlabel='Temperature', ylabel='Energy')
p.plot(T_exact, E_exact, label='L = 4, exact')
for i in range(len(Ising_L)):
    p.errorbar(T[i], E[i], yerr=errE[i], label='L=%s, MC' % Ising_L[i])

p.new(title='Mean absolute magnetization',
      xlabel='Temperature',
      ylabel=r'$\vert Magnetization \vert$')
p.plot(T_exact, M_exact, label='L = 4, exact')
for i in range(len(Ising_L)):
    p.errorbar(T[i], M[i], yerr=errM[i], label='L=%s, MC' % Ising_L[i])
#p.make(ncols=1,show=False)

for i in range(len(Ising_L)):
    p.new(title='Frequency of energies (L=%s)' % Ising_L[i],
          xlabel='Energy',
          ylabel='Temperature')
Esempio n. 24
0
Epots = np.append(Epots_old, Epots, axis=0)
Ekins = np.append(Ekins_old, Ekins, axis=0)
Ts = np.append(Ts_old, Ts, axis=0)
Ps = np.append(Ps_old, Ps, axis=0)
traj = np.append(traj_old, traj, axis=0)
datafile = open(datafilename, 'w')
pickle.dump([ts, Es, Epots, Ekins, Ts, Ps, traj], datafile)
datafile.close()
"""==== PLOTTING ===="""
print "Plotting..."

# Trajectories
p.new(aspect='equal', xlabel='x-coordinate', ylabel='y-coordinate')
traj -= np.floor(traj / L) * L

p.plot([0, L, L, 0, 0], [0, 0, L, L, 0], 'b-', lw=2)
p.plot(traj[-1, 0, :], traj[-1, 1, :], 'wo', alpha=0.1, ms=7, mew=2)
p.plot(traj[0, 0, :], traj[0, 1, :], '+', c=[0.8, 0.8, 0.8], alpha=0.5)

i = range(traj.shape[2])
np.random.shuffle(i)
tpart = np.array(traj[:, :, i[:3]])
for n in range(1, tpart.shape[0]):
    i = (tpart[n - 1, 0, :] - tpart[n, 0, :])**2 + (
        tpart[n - 1, 1, :] - tpart[n, 1, :])**2 > L * L * 0.5
    tpart[n, :, i] = [None, None, None]
nmax = tpart.shape[2]
cm = cm.get_cmap('Dark2')
colors = [cm(1. * i / nmax) for i in range(nmax)]
for n in range(nmax):
    p.plot(tpart[:, 0, n], tpart[:, 1, n], '-', c=colors[n], alpha=0.8)
Esempio n. 25
0
# ==== DEFINITIONS ====
EPS = 1
SIG = 1
NParticles = 1000


# ==== FUNCTIONS ====
def compute_lj_potential(rij, eps=EPS, sig=SIG):
    q = sig / np.linalg.norm(rij)
    return 4 * eps * (q**12 - q**6)


def compute_lj_force(rij, eps=EPS, sig=SIG):
    norm = np.linalg.norm(rij)
    q = sig / norm
    return 4 * eps * (12 * q**11 - 6 * q**5) * q / norm**2 * rij


# ==== CALCULATION ====
d = np.zeros((NParticles, 3))
d[:, 0] = np.linspace(0.85, 2.5, NParticles)
potential = np.array(map(compute_lj_potential, d))
force = np.array(map(compute_lj_force, d))

# ==== PLOTTING ====
p.new(title=u'LJ potential', xlabel='distance', ylabel='potential')
p.plot(d[:, 0], potential, '-', label=u'potential')
p.new(title=u'LJ force', xlabel='distance', ylabel='1st component of force')
p.plot(d[:, 0], force[:, 0], '-', label=u'force')
p.make()
Esempio n. 26
0
    E = compute_energy(x, v)

    print "t=%s, E=%s" % (t, E)

    ts.append(t)
    Es.append(E)

    # write out that a new timestep starts
    vtffile.write("timestep\n")
    # write out the coordinates of the particles
    for i in range(N):
        vtffile.write("%s %s %s\n" % (x[0, i], x[1, i], x[2, i]))

    # for plotting
    traj = np.append(traj, [x[0:2, :] - np.floor(x[0:2, :] / L) * L], axis=0)

vtffile.close()

p.new()
for n in range(1, traj.shape[0]):
    i = (traj[n - 1, 0, :] - traj[n, 0, :]) ** 2 + (traj[n - 1, 1, :] - traj[n, 1, :]) ** 2 > 1
    traj[n, :, i] = [None, None]
p.plot(traj[:, 0, :], traj[:, 1, :], "-", lw=2, alpha=0.3)
p.plot(traj[0, 0, :], traj[0, 1, :], "ko", alpha=0.5, ms=10, mew=4, label="start position")
p.plot(traj[-1, 0, :], traj[-1, 1, :], "wo", alpha=0.5, ms=10, mew=4, label="end position")

p.new()
p.plot(ts, Es)
p.make(ncols=1)
Esempio n. 27
0
print "... potential energy"
jks1 = jke_seq(s1)
print "... kinetic energy"
jks2 = jke_seq(s2)
print "... temperature"
jks3 = jke_seq(s3)
print "... pressure"
jks4 = jke_seq(s4)


"""==== PLOTTING ===="""
print "Plotting..."

# first 1000 values of the data series s0, s1, s2, s3, s4 over time
p.new(xlabel='time',ylabel='value')
p.plot(s0, label='total energy')
p.plot(s1, label='potential energy')
p.plot(s2, label='kinetic energy')
p.plot(s3, label='temperature')
p.plot(s4, label='pressure')

s0 = Es
s1 = Epots
s2 = Ekins
s3 = Ts
s4 = Ps



# plot autocorrelation of s0, s1, s2, s3, s4 over k
p.new(xlabel='k',ylabel='normalized autocorrelation')