4 from scipy.interpolate
import griddata
5 from collections
import OrderedDict
7 from argparse
import ArgumentParser
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")
17 from sumatra.projects
import load_project
18 output_dir = os.path.join(os.path.abspath(load_project().data_store.root), args.id)
22 states_files = args.states_files
23 if len(states_files) == 1:
24 states_files = glob(states_files[0])
26 if not os.path.exists(output_dir):
27 os.makedirs(output_dir)
29 output_file = os.path.join(output_dir,
"three_particle_plot")
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)
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)
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"]
65 energy_min = min(energy_min, energy)
66 energy_max = max(energy_max, energy)
69 print "Angle min:", angle_min,
"max:", angle_max
70 print "r13 min:", r13_min,
"max:", r13_max
73 r12s = linspace(r12_min, r12_max, 20)
74 r13s = linspace(r13_min, r13_max, 20)
75 grid_r12s, grid_r13s = meshgrid(r12s, r13s)
77 n_plots_per_dim = int(sqrt(n_plots) + 1)
79 plots = OrderedDict(sorted(plots.items()))
84 vmax = energy_min + (energy_max - energy_min) * 0.5
85 print "vmin,vmax: ", vmin, vmax
87 fig = figure(figsize=(10,10))
88 for plot_name
in plots:
90 ax = fig.add_subplot(n_plots_per_dim, n_plots_per_dim, plot_counter)
93 values = plots[plot_name]
95 grid_energies = griddata(array(values[
"r12s_r13s"]), array(values[
"energies"]), (grid_r12s, grid_r13s), method=
"nearest")
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))
106 savefig(output_file +
".pdf")
107 savefig(output_file +
".png")