Kindfield
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends Pages
create_two_particle_states.py
Go to the documentation of this file.
1 import h5py
2 import numpy
3 from numpy import dtype, zeros, linspace, pi, cos, sin
4 from sys import argv
5 import os, os.path
6 import yaml
7 from argparse import ArgumentParser
8 
9 parser = ArgumentParser()
10 parser.add_argument("config_filename")
11 parser.add_argument("--id", nargs='?', default="tmp")
12 args = parser.parse_args()
13 
14 output_dir = os.path.abspath("tmp")
15 
16 if args.id != "tmp":
17  try:
18  from sumatra.projects import load_project
19  output_dir = os.path.join(os.path.abspath(load_project().data_store.root), args.id)
20  except ImportError:
21  pass
22 
23 if not os.path.exists(output_dir):
24  os.makedirs(output_dir)
25 
26 config_file = open(args.config_filename, "r")
27 config = yaml.load(config_file)
28 
29 atom_type_1 = config["type1"]
30 atom_type_2 = config["type2"]
31 basis_name = config["basisName"]
32 
33 r12_min = config["r12Min"]
34 r12_max = config["r12Max"]
35 configuration_count = config["n"]
36 r12_ground_state = config["r12GroundState"]
37 
38 #f = h5py.File("states_atom_" + str(atom_type_1) + "_atom_" + str(atom_type_2) + "_basis_" + basis_name + ".h5", "w")
39 file_name = "states_atom_%d_atom_%d_basis_%s.h5" % (atom_type_1, atom_type_2, basis_name)
40 file_path = os.path.join(output_dir, file_name)
41 f = h5py.File(file_path, "w")
42 
43 atom_type = dtype([("x", float), ("y", float), ("z", float)])
44 atoms = zeros(2, dtype=atom_type)
45 
46 atom_metaType = dtype([("type", int), ("basisName", "S64")])
47 atom_meta = zeros(2, dtype=atom_metaType)
48 
49 atom_meta[0]["type"] = atom_type_1
50 atom_meta[0]["basisName"] = basis_name
51 atom_meta[1]["type"] = atom_type_2
52 atom_meta[1]["basisName"] = basis_name
53 
54 atom_meta_dataset = f.create_dataset("atomMeta", data = atom_meta)
55 atom_meta_dataset.attrs["r12Min"] = r12_min
56 atom_meta_dataset.attrs["r12Max"] = r12_max
57 atom_meta_dataset.attrs["method"] = config["method"]
58 
59 r12s = linspace(r12_min, r12_max, configuration_count)
60 
61 if r12_ground_state > 0.0:
62  atoms[0]["x"] = -r12_ground_state / 2
63  atoms[0]["y"] = 0.0
64  atoms[0]["z"] = 0.0
65 
66  atoms[1]["x"] = r12_ground_state / 2
67  atoms[1]["y"] = 0.0
68  atoms[1]["z"] = 0.0
69  dataset = f.create_dataset("groundState", data=atoms)
70  dataset.attrs["r12"] = r12_ground_state
71 
72 stateCounter = 0
73 states_group = f.create_group("states")
74 for j in range(len(r12s)):
75  atoms[0]["x"] = -r12s[j] / 2
76  atoms[0]["y"] = 0.0
77  atoms[0]["z"] = 0.0
78 
79  atoms[1]["x"] = r12s[j] / 2
80  atoms[1]["y"] = 0.0
81  atoms[1]["z"] = 0.0
82 
83  dataset = states_group.create_dataset("state%010d" % stateCounter, data=atoms)
84  dataset.attrs["r12"] = r12s[j]
85  stateCounter += 1
86 
87 f.close()
88 print "States saved to:\n", os.path.abspath(file_path)