-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempRangeAnalyze.py
More file actions
106 lines (87 loc) · 3.56 KB
/
Copy pathtempRangeAnalyze.py
File metadata and controls
106 lines (87 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# =============================================================================
# Script for plotting the data generated from the tempRangeSubmit.py script.
# This will plot the ferromagnetic phase transition.
#
# Author: Max Graves
# Last Revision: 2-MAY-2013
# =============================================================================
import subprocess, os, sys, argparse, glob
import pylab as pl
# =============================================================================
def parseCMD():
desc= ('Ising 2D script for plotting phase transition. Takes as its \
argument the directory holding all of the data files that you ,\
want to plot.')
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('direcN', help='name of data directory of interest')
parser.add_argument('--include', '-i', type=float,
default=0.95,
help='fraction of data to include [0.01-0.99]')
return parser.parse_args()
# =============================================================================
def main():
args = parseCMD()
os.chdir(args.direcN)
try:
temps, Es, Ms, Cvs = pl.loadtxt('ising2D_reduced.txt',
unpack=True)
print 'Found a reduced file!'
except:
print 'Didnt find reduced file. Creating one'
# holds all files created by phaseTransSubmit.py
files = glob.glob("*.dat*")
# arrays to hold data
temps, Es, Ms = pl.array([]), pl.array([]), pl.array([])
Cvs = pl.array([])
# fill arrays from data files
for f in files:
estFile = open(f,'r')
estLines = estFile.readlines();
tempT = float(estLines[0].split()[-1])
tempN = float(estLines[1].split()[-1])
tempH = float(estLines[2].split()[-1])
print 'temp: ',tempT
temps = pl.append(temps, float(tempT))
mcSteps, En, Mag, E2 = pl.loadtxt(f, unpack=True)
# take last half of data, no matter size of array
binAfter = int(args.include*En.size)
Cv = (pl.average(E2)-(pl.average(En))**2)/(tempN*tempT**2)
Es = pl.append(Es, pl.average(En[-binAfter:]))
Ms = pl.append(Ms, pl.average(Mag[-binAfter:]))
Cvs = pl.append(Cvs, Cv)
# write temps, Es, Ms to file
filename = 'ising2D_reduced.txt'
fid = open(filename, 'w')
fid.write('# nodes: %s\n'%tempN)
fid.write('# field: %s\n'%tempH)
fid.write('# %15s\t%15s\t%15s\t%15s\n'%('temps','Energies',
'Magnetism','Specific Heat'))
zipped = zip(temps, Es, Ms, Cvs)
pl.savetxt(fid, zipped, fmt='%5.9f\t%5.9f\t%5.9f\t%5.9f')
fid.close()
print 'Data has been saved to: ',filename
# plot energy vs. temp
fig1 = pl.figure(1)
p1 = fig1.add_subplot(111)
pl.scatter(temps, Es)
pl.grid(True)
pl.xlabel('Temperature '+r'$[K]$', size=20)
pl.ylabel('Energy', size=20)
# plot specific heat vs. temp
fig2 = pl.figure(2)
p2 = fig2.add_subplot(111)
pl.scatter(temps, Cvs)
pl.grid(True)
pl.xlabel('Temperature '+r'$[K]$', size=20)
pl.ylabel('Specific Heat', size=20)
# plot magnetization vs. temp
fig3 = pl.figure(3)
p3 = fig3.add_subplot(111)
pl.scatter(temps, pl.absolute(Ms))
pl.grid(True)
pl.xlabel('Temperature '+r'$[K]$', size=20)
pl.ylabel('abs(Magnetization)', size=20)
pl.show()
# =============================================================================
if __name__=='__main__':
main()