forked from scott-norris-math/pycraters
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.py
More file actions
128 lines (83 loc) · 2.83 KB
/
IO.py
File metadata and controls
128 lines (83 loc) · 2.83 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import shelve
class MissingFileError(Exception):
def __init__(self, filename):
self.filename = filename
def __str__(self):
return "File not found: %s" % (filename) #repr(self.value)
def read_value(path, params, quantity):
# Given a directory $path full of moment files, this function
# takes a $params object, reads the associated data file, and returns
# the associated $quantity.
value = None
# specify the target file
targetfile = '%s%s.moms' % (path, params.fname())
print "targetfile is %s" % (targetfile)
if (os.path.isfile(targetfile) == False):
print "File not found: ", targetfile, "\n\n"
raise MissingFileError(targetfile)
# now try and extract the specified value
try:
f = shelve.open(targetfile)
value = f[quantity]
f.close()
except KeyError as ee:
print "Key Error"
print "Working directory is %s." % (os.getcwd())
print "Target file is %s" % (targetfile)
print "Did not find key %s." % (ee)
print "Available keys are", f.keys(), "\n\n"
return value
def array_range(path, params, field, values, quantity):
# Given a directory $path full of moment files, this function
# takes a basic set of $params, sets $params.$field equal to each value
# in the list $values, and retrieves the associated $quantity. Returns
# a list of the same size as $values.
yvals = []
for kk,val in enumerate(values):
setattr(params, field, val)
targetfile = '%s%s.moms' % (path, params.fname())
if (os.path.isfile(targetfile) == False):
print "File not found: ", targetfile, "\n\n"
raise MissingFileError(targetfile)
try:
f = shelve.open(targetfile)
yvals.append(f[quantity])
f.close()
except KeyError as ee:
print "Key Error"
print "Working directory is %s." % (os.getcwd())
print "Target file is %s" % (targetfile)
print "Did not find key %s." % (ee)
print "Available keys are", f.keys(), "\n\n"
return yvals
class AtomicProperties(object):
def __init__(self):
pass
def extract_atomic_properties(atomstring, lines):
#find the beam properties in table1
linenum = 12
while (True):
entries = lines[linenum].split()
species = entries[0]
if (species == atomstring):
break
elif (linenum < 121):
linenum += 1
continue
else:
print "\n\nFatal: Element %s not found.\n\n" % (atomstring)
exit()
ap = AtomicProperties()
# Real Atomic Properties
ap.atomic_number = entries[1]
ap.atomic_mass = entries[2]
ap.density_gcc = entries[3]
ap.density_aa = entries[4]
## BCA Energy Parameters
ap.surf_bind_energy = entries[5]
ap.displ_energy = entries[6]
ap.cutoff_energy = entries[7]
#ap.bulk_bind_energy = entries[12]
ap.bulk_bind_energy = 0.0
return ap