forked from praxes/praxes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,561 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import sys | ||
import tarfile | ||
|
||
import numpy as np | ||
import h5py | ||
|
||
|
||
def process_henkedb(data, root): | ||
if os.path.isfile(os.path.join(root, 'henkedb.h5')): | ||
return | ||
|
||
try: | ||
archive = tarfile.open(data) | ||
members = archive.getnames() | ||
members.remove('read.me') | ||
|
||
with h5py.File(os.path.join(root, 'henkedb.h5'), 'w') as elements: | ||
for member in members: | ||
el = elements.create_group(member.split('.')[0].capitalize()) | ||
filedata = archive.extractfile(member) | ||
filedata.readline() # skip the header | ||
data = np.array( | ||
[map(np.float64, line.split()) for line in filedata] | ||
) | ||
el['energy'] = data[:,0] | ||
el['energy'].attrs['units'] = 'eV' | ||
el['f1'] = data[:,1] | ||
el['f2'] = data[:,2] | ||
finally: | ||
archive.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
process_henkedb(*sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import sys | ||
import tarfile | ||
|
||
import numpy as np | ||
import h5py | ||
|
||
def process_waasmaierdb(data, root): | ||
if os.path.isfile(os.path.join(root, 'waasmaierdb.h5')): | ||
return | ||
|
||
try: | ||
archive = tarfile.open(data) | ||
lines = archive.extractfile(archive.getnames()[0]).readlines()[19:] | ||
finally: | ||
archive.close() | ||
|
||
with h5py.File(os.path.join(root, 'waasmaierdb.h5'), 'w') as elements: | ||
while 1: | ||
id = lines.pop(0).split()[0] | ||
if id == 'END': | ||
break | ||
|
||
el = elements.create_group(id) | ||
|
||
line = lines.pop(0) | ||
el['a'] = np.zeros(5, dtype='d') | ||
for i in range(5): | ||
el['a'][i], line = np.float64(line[:10]), line[10:] | ||
el['c'] = np.float64(line[:10]) | ||
|
||
line = lines.pop(0) | ||
el['b'] = np.zeros(5, dtype='d') | ||
for i in range(5): | ||
el['b'][i], line = np.float64(line[:10]), line[10:] | ||
|
||
line = lines.pop(0) # skip empty line | ||
|
||
|
||
if __name__ == '__main__': | ||
process_waasmaierdb(*sys.argv[1:]) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from functools import partial, wraps | ||
|
||
|
||
def memoize(f, cache={}): | ||
@wraps(f) | ||
def g(*args, **kwargs): | ||
key = (f, tuple(args), frozenset(kwargs.items())) | ||
if key not in cache: | ||
cache[key] = f(*args, **kwargs) | ||
return cache[key] | ||
return g | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from __future__ import absolute_import | ||
|
||
from .atomic_data import AtomicData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
"""scatteringfactors defines a class for calculating the Q- and energy-dependent | ||
scattering factors for the elements and ions: | ||
f(Q,E) = f₀(Q)+f'(E)+f"(E) | ||
Q-dependence is appproximated as reported by D. Waasmaier and A. Kirfel, | ||
Acta. Cryst. A, v 51, p 416-431 (1995): | ||
f₀ = ∑_i a_i exp[-b_i(|Q|/4π)²] + c | ||
This approximation is valid for |Q| ≤ 75 Å⁻¹ | ||
The dispersion corrections will not be calculated if energy=None is passed to | ||
the anomolous scattering factor method get_f. | ||
Anomolous scattering factors are interpolated based on the values compiled by | ||
the Center for X-Ray Optics (CXRO), at | ||
http://www.cxro.lbl.gov/optical_constants/asf.html | ||
""" | ||
|
||
from __future__ import division | ||
|
||
import numpy as np | ||
import quantities as pq | ||
|
||
from . import base | ||
from ..decorators import memoize | ||
|
||
class AtomicData(base.AtomicData): | ||
|
||
@property | ||
@memoize | ||
def _dispersive(self): | ||
from . import henke | ||
return henke.AtomicData(self.element) | ||
|
||
@property | ||
@memoize | ||
def _fluorescence(self): | ||
from . import elam | ||
return elam.AtomicData(self.element) | ||
|
||
@property | ||
@memoize | ||
def _nondispersive(self): | ||
from . import waasmaier | ||
return waasmaier.AtomicData(self.symbol) | ||
|
||
def __init__(self, symbol): | ||
base.AtomicData.__init__(self, symbol) | ||
|
||
def f(self, Q, energy=None): | ||
if energy is None: | ||
return self.f0(Q) | ||
return self.f0(Q) + self.fprime(energy) + 1j*self.fdoubleprime(energy) | ||
|
||
def f0(self, Q): | ||
return self._nondispersive.f0(Q) | ||
|
||
def fprime(self, energy): | ||
return self._dispersive.fprime(energy) | ||
|
||
def fdoubleprime(self, energy): | ||
return self._dispersive.fdoubleprime(energy) | ||
|
||
def photoabsorption_cross_section(self, energy): | ||
return self._fluorescence.photoabsorption_cross_section(energy) | ||
|
||
def coherent_scattering_cross_section(self, energy): | ||
return self._fluorescence.coherent_scattering_cross_section(energy) | ||
|
||
def incoherent_scattering_cross_section(self, energy): | ||
return self._fluorescence.incoherent_scattering_cross_section(energy) |
Oops, something went wrong.