4 from scipy.interpolate
import griddata
5 from collections
import OrderedDict
7 from argparse
import ArgumentParser
10 idx = (np.abs(array-value)).argmin()
13 parser = ArgumentParser()
14 parser.add_argument(
"--three_body_states", nargs=
"+")
15 parser.add_argument(
"--two_body_states", nargs=
"+")
16 parser.add_argument(
"--id", default=
"tmp")
17 args = parser.parse_args()
18 output_dir = os.path.abspath(
"tmp")
22 from sumatra.projects
import load_project
23 output_dir = os.path.join(os.path.abspath(load_project().data_store.root), args.id)
27 if not os.path.exists(output_dir):
28 os.makedirs(output_dir)
30 states_files = args.two_body_states
31 if len(states_files) == 1:
32 states_files = glob(states_files[0])
40 for statesFile
in states_files:
41 f = h5py.File(statesFile,
"r")
42 atomsMeta = f.get("atomMeta")
43 energyOffset = atomsMeta.attrs[
"energyOffset"]
44 if len(atomsMeta) != 2:
45 raise Exception(
"Wrong number of atoms in atomsMeta. Found %d, should be 2." % len(atomsMeta))
46 states = f.get(
"/states")
47 for stateName
in states:
48 atoms = states.get(stateName)
52 r12 = atoms.attrs[
"r12"]
53 energy = atoms.attrs[
"energy"] - energyOffset
56 energies.append(energy)
58 energy_min = min(energy_min, energy)
59 energy_max = max(energy_max, energy)
63 r12s, energies = [list(x)
for x
in zip(*sorted(zip(r12s, energies), key=
lambda pair: pair[0]))]
65 two_body_r12s = array(r12s)
66 two_body_energies = array(energies)
68 states_files = args.three_body_states
69 if len(states_files) == 1:
70 states_files = glob(states_files[0])
77 energy_differences_min = inf
78 energy_differences_max = -inf
80 for statesFile
in states_files:
81 f = h5py.File(statesFile,
"r")
82 atomsMeta = f.get("atomMeta")
83 states = f.get(
"/states")
84 energyOffset = atomsMeta.attrs[
"energyOffset"]
85 for stateName
in states:
86 atoms = states.get(stateName)
90 r12 = atoms.attrs[
"r12"]
91 r13 = atoms.attrs[
"r13"]
93 angle = atoms.attrs[
"angle"]
94 plot_name =
"%.4f" % angle
95 energy = atoms.attrs[
"energy"] - energyOffset
99 atom3_x = cos(angle) * r13
100 atom3_y = sin(angle) * r13
102 r23_vector = array([atom3_x - atom2_x, atom3_y - 0.0, 0.0 - 0.0])
103 r23 = linalg.norm(r23_vector)
109 energy_difference = energy - two_body_energies[index12] - two_body_energies[index13] - two_body_energies[index23]
111 if r12 < 6.0
and r13 < 6.0:
112 energy_difference = 0.0
114 if not plots.has_key(plot_name):
115 plots[plot_name] = {
"r12s_r13s": [],
"energies": [],
"energy_differences": []}
116 plots[plot_name][
"r12s_r13s"].append([r12, r13])
117 plots[plot_name][
"energies"].append(energy)
118 plots[plot_name][
"energy_differences"].append(energy_difference)
120 r12_min = atomsMeta.attrs[
"r12Min"]
121 r12_max = atomsMeta.attrs[
"r12Max"]
122 r13_min = atomsMeta.attrs[
"r13Min"]
123 r13_max = atomsMeta.attrs[
"r13Max"]
124 angle_min = atomsMeta.attrs[
"angleMin"]
125 angle_max = atomsMeta.attrs[
"angleMax"]
127 energy_min = min(energy_min, energy)
128 energy_max = max(energy_max, energy)
130 energy_differences_min = min(energy_differences_min, energy_difference)
131 energy_differences_max = max(energy_differences_max, energy_difference)
134 print "Angle min:", angle_min,
"max:", angle_max
135 print "r13 min:", r13_min,
"max:", r13_max
138 r12s = linspace(r12_min, r12_max, 25)
139 r13s = linspace(r13_min, r13_max, 25)
140 grid_r12s, grid_r13s = meshgrid(r12s, r13s)
142 n_plots_per_dim = int(sqrt(n_plots) + 1)
144 plots = OrderedDict(sorted(plots.items()))
148 vmin = energy_differences_min
149 vmax = energy_differences_max
153 print "vmin,vmax: ", vmin, vmax
155 fig = figure(figsize=(10,10))
156 for plot_name
in plots:
158 ax = fig.add_subplot(n_plots_per_dim, n_plots_per_dim, plot_counter)
159 ax.set_aspect(
"equal")
162 values = plots[plot_name]
164 grid_energies = griddata(array(values[
"r12s_r13s"]), array(values[
"energies"]), (grid_r12s, grid_r13s), method=
"nearest")
165 grid_energy_differences = griddata(array(values[
"r12s_r13s"]), array(values[
"energy_differences"]), (grid_r12s, grid_r13s), method=
"nearest")
173 img = contour(r12s, r13s, grid_energy_differences, 50, vmin=vmin, vmax=vmax)