Kindfield
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends Pages
plot_three_particle_states.py
Go to the documentation of this file.
1 import h5py
2 from pylab import *
3 from glob import glob
4 from scipy.interpolate import griddata
5 from collections import OrderedDict
6 import os
7 from argparse import ArgumentParser
8 
9 parser = ArgumentParser()
10 parser.add_argument("states_files", nargs="+")
11 parser.add_argument("--id", default="tmp")
12 args = parser.parse_args()
13 output_dir = os.path.abspath("tmp")
14 
15 if args.id != "tmp":
16  try:
17  from sumatra.projects import load_project
18  output_dir = os.path.join(os.path.abspath(load_project().data_store.root), args.id)
19  except ImportError:
20  pass
21 
22 states_files = args.states_files
23 if len(states_files) == 1:
24  states_files = glob(states_files[0])
25 
26 if not os.path.exists(output_dir):
27  os.makedirs(output_dir)
28 
29 output_file = os.path.join(output_dir, "three_particle_plot")
30 
31 plots = {}
32 
33 energy_min = inf
34 energy_max = -inf
35 
36 print "Reading", len(states_files), "files..."
37 for statesFile in states_files:
38  f = h5py.File(statesFile, "r")
39  atomsMeta = f.get("atomMeta")
40  energyOffset = atomsMeta.attrs["energyOffset"]
41  states = f.get("/states")
42  print "Reading", len(states), "states..."
43  for stateName in states:
44  atoms = states.get(stateName)
45  #r12 = atoms[1]["x"] - atoms[0]["x"]
46  #r13 = sqrt((atoms[2]["x"] - atoms[0]["x"])**2 + (atoms[2]["y"] - atoms[0]["y"])**2)
47  #angle = arctan2(atoms[2]["y"], atoms[2]["x"])
48  r12 = atoms.attrs["r12"]
49  r13 = atoms.attrs["r13"]
50  angle = atoms.attrs["angle"]
51  plot_name = "%.4f" % angle
52  energy = atoms.attrs["energy"] - energyOffset
53  if not plots.has_key(plot_name):
54  plots[plot_name] = {"r12s_r13s": [], "energies": []}
55  plots[plot_name]["r12s_r13s"].append([r12, r13])
56  plots[plot_name]["energies"].append(energy)
57 
58  r12_min = atomsMeta.attrs["r12Min"]
59  r12_max = atomsMeta.attrs["r12Max"]
60  r13_min = atomsMeta.attrs["r13Min"]
61  r13_max = atomsMeta.attrs["r13Max"]
62  angle_min = atomsMeta.attrs["angleMin"]
63  angle_max = atomsMeta.attrs["angleMax"]
64 
65  energy_min = min(energy_min, energy)
66  energy_max = max(energy_max, energy)
67  f.close()
68 
69 print "Angle min:", angle_min, "max:", angle_max
70 print "r13 min:", r13_min, "max:", r13_max
71 
72 
73 r12s = linspace(r12_min, r12_max, 20)
74 r13s = linspace(r13_min, r13_max, 20)
75 grid_r12s, grid_r13s = meshgrid(r12s, r13s)
76 n_plots = len(plots)
77 n_plots_per_dim = int(sqrt(n_plots) + 1)
78 plot_counter = 1
79 plots = OrderedDict(sorted(plots.items()))
80 
81 #energy_max = energy_min + (energy_max - energy_min) * 0.1
82 vmin = energy_min
83 #vmax = energy_max
84 vmax = energy_min + (energy_max - energy_min) * 0.5
85 print "vmin,vmax: ", vmin, vmax
86 
87 fig = figure(figsize=(10,10))
88 for plot_name in plots:
89 
90  ax = fig.add_subplot(n_plots_per_dim, n_plots_per_dim, plot_counter)
91  title(plot_name)
92 
93  values = plots[plot_name]
94 
95  grid_energies = griddata(array(values["r12s_r13s"]), array(values["energies"]), (grid_r12s, grid_r13s), method="nearest")
96 
97  img = imshow(grid_energies, origin="lower", vmin=vmin, vmax=vmax,
98  extent=[r12_min, r12_max, r13_min, r13_max],
99  interpolation="nearest",
100  aspect=(r12_max - r12_min) / (r13_max - r13_min))
101  colorbar()
102 
103  plot_counter += 1
104 
105 fig.tight_layout()
106 savefig(output_file + ".pdf")
107 savefig(output_file + ".png")
108