fdmnes-util 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fdmnes_util/__init__.py +2 -0
- fdmnes_util/analyze_fdm_average.py +122 -0
- fdmnes_util/analyze_fdm_log.py +61 -0
- fdmnes_util/analyze_fdm_xas.py +225 -0
- fdmnes_util/athena_nor.py +129 -0
- fdmnes_util/atomic_symbols.list +103 -0
- fdmnes_util/cif.py +85 -0
- fdmnes_util/cli.py +122 -0
- fdmnes_util/dos_plot_sample.py +277 -0
- fdmnes_util/fdm_bav.py +101 -0
- fdmnes_util/fdm_bav_2016.py +205 -0
- fdmnes_util/fdm_bav_2020.py +208 -0
- fdmnes_util/fdm_conv.py +111 -0
- fdmnes_util/fdm_convolution_inputs.py +80 -0
- fdmnes_util/fdm_inp.py +612 -0
- fdmnes_util/fdm_photoenergy.py +64 -0
- fdmnes_util/fdm_result_files.py +105 -0
- fdmnes_util/fdm_sd.py +187 -0
- fdmnes_util/fdm_sd_2016.py +343 -0
- fdmnes_util/fdm_sd_2020.py +338 -0
- fdmnes_util/fdm_structure.py +249 -0
- fdmnes_util/fdm_txt.py +198 -0
- fdmnes_util/fdm_xyz.py +83 -0
- fdmnes_util/fdmfile.py +127 -0
- fdmnes_util/pdb.py +89 -0
- fdmnes_util/plot/__init__.py +2 -0
- fdmnes_util/plot/_figure.py +33 -0
- fdmnes_util/plot/plot_fdm_average.py +154 -0
- fdmnes_util/plot/plot_fdm_dos.py +593 -0
- fdmnes_util/plot/plot_fdm_xas.py +294 -0
- fdmnes_util/plot/plot_fdm_xas_ldos.py +163 -0
- fdmnes_util/structure_conversion.py +60 -0
- fdmnes_util/vasp_poscar.py +52 -0
- fdmnes_util/xyz.py +77 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDbav2xyz.py +74 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDcif2fdm.py +64 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDclean.py +61 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDconv_e2photoe.py +73 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDfdm2vasp.py +79 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDgetfermi.py +64 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDmakeCconvAllsite.py +59 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDmove.py +62 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDpbd2fdm.py +57 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDplot_LDOS.py +52 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDplot_PDOS.py +62 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDplot_XAS.py +441 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDplot_XAS_LDOS.py +95 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDplot_XASs.py +115 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDvasp2fdm.py +52 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDvasp2fdm_BUG.py +84 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDvasp2fdm_NEW_20151125_BUGversion.py +84 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/FDxyz2fdm.py +46 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdExp_comp_XAS.py +73 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdLDOS.py +41 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdLDOS0_specified.py +74 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdLDOS_color.py +60 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdLDOSmulti.py +86 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdMulti_2_XAS+LDOS+EXP.py +118 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdMulti_3.py +76 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdPDOS_XAS_av.py +248 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdXAS.py +35 -0
- fdmnes_util-0.0.0.data/data/share/fdmnes_util/scripts/fdXAS_specified.py +68 -0
- fdmnes_util-0.0.0.dist-info/METADATA +157 -0
- fdmnes_util-0.0.0.dist-info/RECORD +67 -0
- fdmnes_util-0.0.0.dist-info/WHEEL +5 -0
- fdmnes_util-0.0.0.dist-info/entry_points.txt +2 -0
- fdmnes_util-0.0.0.dist-info/top_level.txt +1 -0
fdmnes_util/__init__.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Average corresponding FDMNES spectra without changing their energy grids.
|
|
3
|
+
|
|
4
|
+
SAE source: ``sae/commands/fdPDOS_XAS_av.py`` (2015-09-09; Python 2/3
|
|
5
|
+
update 2018-08-17). The original script averages three calculations.
|
|
6
|
+
This module extracts that numerical operation into a reusable class.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AnalyzeFdmAverage:
|
|
13
|
+
"""Average data from independent calculations on a shared energy grid."""
|
|
14
|
+
|
|
15
|
+
def energy_reference(self, input_file, spectrum, fermi=False):
|
|
16
|
+
"""Determine the shared energy shift used by the SAE average plot.
|
|
17
|
+
|
|
18
|
+
The source script distinguishes FDMNES Fermi-relative and photon-energy
|
|
19
|
+
calculation modes. Its photon-energy-to-Fermi branch contains a
|
|
20
|
+
subtraction without assignment; this implementation corrects that
|
|
21
|
+
specific defect rather than reproducing an undefined offset.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
input_file: FdmInp instance describing the calculation mode.
|
|
25
|
+
spectrum: FdmTxt instance containing edge and Fermi energies.
|
|
26
|
+
fermi: If True, use the Fermi-relative energy reference.
|
|
27
|
+
Otherwise, use photon energy.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
tuple[float, float]: Energy-axis shift and absolute Fermi
|
|
31
|
+
position in the photon-energy reference, both in eV.
|
|
32
|
+
|
|
33
|
+
Raises:
|
|
34
|
+
ValueError: If the required energy metadata is not finite.
|
|
35
|
+
"""
|
|
36
|
+
edge_energy = float(spectrum.get_eedge())
|
|
37
|
+
fermi_energy = float(spectrum.get_efermi())
|
|
38
|
+
|
|
39
|
+
if not np.isfinite(edge_energy):
|
|
40
|
+
raise ValueError("The absorption-edge energy must be finite")
|
|
41
|
+
if not np.isfinite(fermi_energy):
|
|
42
|
+
raise ValueError("The Fermi energy must be finite")
|
|
43
|
+
|
|
44
|
+
absolute_fermi = edge_energy + fermi_energy
|
|
45
|
+
photon_mode = input_file.get_energygpho()
|
|
46
|
+
|
|
47
|
+
if photon_mode:
|
|
48
|
+
if fermi:
|
|
49
|
+
energy_shift = -absolute_fermi
|
|
50
|
+
else:
|
|
51
|
+
energy_shift = 0.0
|
|
52
|
+
else:
|
|
53
|
+
if fermi:
|
|
54
|
+
energy_shift = -fermi_energy
|
|
55
|
+
else:
|
|
56
|
+
energy_shift = edge_energy
|
|
57
|
+
|
|
58
|
+
return energy_shift, absolute_fermi
|
|
59
|
+
|
|
60
|
+
def average(self, readers, value_method, *, divisor=None, **kwargs):
|
|
61
|
+
"""Return the common energy axis and arithmetic mean of a quantity.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
readers: Nonempty sequence of FDMNES output objects.
|
|
65
|
+
value_method: Name of the data access method on each object.
|
|
66
|
+
divisor: Optional positive divisor for the sum, used for SAE's
|
|
67
|
+
per-atom normalization. Defaults to the number of readers.
|
|
68
|
+
**kwargs: Arguments passed to the selected data access method.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
tuple[numpy.ndarray, numpy.ndarray]: Energy and mean values.
|
|
72
|
+
|
|
73
|
+
Raises:
|
|
74
|
+
ValueError: If readers are missing, grids disagree, or numerical
|
|
75
|
+
values are non-finite or have inconsistent dimensions.
|
|
76
|
+
AttributeError: If the requested accessor is unavailable.
|
|
77
|
+
"""
|
|
78
|
+
if not readers:
|
|
79
|
+
raise ValueError("At least one calculation is required")
|
|
80
|
+
if divisor is None:
|
|
81
|
+
divisor = len(readers)
|
|
82
|
+
if not np.isfinite(divisor) or divisor <= 0:
|
|
83
|
+
raise ValueError("The averaging divisor must be positive and finite")
|
|
84
|
+
|
|
85
|
+
reference_energy = np.asarray(readers[0].get_eng(), dtype=float)
|
|
86
|
+
if reference_energy.ndim != 1:
|
|
87
|
+
raise ValueError("Energy grid must be one-dimensional")
|
|
88
|
+
if reference_energy.size == 0:
|
|
89
|
+
raise ValueError("Energy grid must not be empty")
|
|
90
|
+
if not np.all(np.isfinite(reference_energy)):
|
|
91
|
+
raise ValueError("Energy grid contains non-finite values")
|
|
92
|
+
|
|
93
|
+
sum_values = None
|
|
94
|
+
|
|
95
|
+
for reader in readers:
|
|
96
|
+
energy = np.asarray(reader.get_eng(), dtype=float)
|
|
97
|
+
if energy.ndim != 1:
|
|
98
|
+
raise ValueError("Energy grid must be one-dimensional")
|
|
99
|
+
if not np.all(np.isfinite(energy)):
|
|
100
|
+
raise ValueError("Energy grid contains non-finite values")
|
|
101
|
+
if energy.shape != reference_energy.shape:
|
|
102
|
+
raise ValueError("Energy grid lengths differ between calculations")
|
|
103
|
+
if not np.allclose(energy, reference_energy, rtol=0.0, atol=1e-8):
|
|
104
|
+
raise ValueError("Energy grids differ between calculations")
|
|
105
|
+
|
|
106
|
+
accessor = getattr(reader, value_method)
|
|
107
|
+
values = np.asarray(accessor(**kwargs), dtype=float)
|
|
108
|
+
if values.ndim == 0:
|
|
109
|
+
raise ValueError("Spectrum values must have an energy dimension")
|
|
110
|
+
if not np.all(np.isfinite(values)):
|
|
111
|
+
raise ValueError("Spectrum contains non-finite values")
|
|
112
|
+
if values.shape[0] != reference_energy.shape[0]:
|
|
113
|
+
raise ValueError("Energy and data lengths differ")
|
|
114
|
+
|
|
115
|
+
if sum_values is None:
|
|
116
|
+
sum_values = np.zeros_like(values, dtype=float)
|
|
117
|
+
if values.shape != sum_values.shape:
|
|
118
|
+
raise ValueError("Data shapes differ between calculations")
|
|
119
|
+
sum_values += values
|
|
120
|
+
|
|
121
|
+
mean_values = sum_values / divisor
|
|
122
|
+
return reference_energy.copy(), mean_values
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Extract cluster coordinates from FDMNES calculation logs."""
|
|
3
|
+
|
|
4
|
+
from importlib.resources import files
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AnalyzeFdmLog:
|
|
10
|
+
"""Analyze the cluster block of a year-specific FDMNES BAV reader."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, reader):
|
|
13
|
+
"""Store the parsed log.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
reader: BAV reader exposing the source lines in file order.
|
|
17
|
+
"""
|
|
18
|
+
self.reader = reader
|
|
19
|
+
|
|
20
|
+
def positions(self):
|
|
21
|
+
"""Read the atomic symbols and Cartesian positions of the cluster.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
A list of chemical symbols and an array of XYZ coordinates.
|
|
25
|
+
|
|
26
|
+
Raises:
|
|
27
|
+
ValueError: If the cluster section is absent or has no atom rows.
|
|
28
|
+
"""
|
|
29
|
+
table = files("fdmnes_util").joinpath("atomic_symbols.list")
|
|
30
|
+
periodic = {}
|
|
31
|
+
for row in table.read_text(encoding="utf-8").splitlines():
|
|
32
|
+
atomic_number, symbol = row.split()[:2]
|
|
33
|
+
periodic[int(atomic_number)] = symbol
|
|
34
|
+
|
|
35
|
+
source = iter(self.reader.lines)
|
|
36
|
+
for line in source:
|
|
37
|
+
if "Cluster: atom positions in order" in line:
|
|
38
|
+
break
|
|
39
|
+
else:
|
|
40
|
+
raise ValueError("Cluster: atom positions section is missing")
|
|
41
|
+
|
|
42
|
+
# The first four columns contain Z, x, y, and z. Some revisions use
|
|
43
|
+
# Fortran D exponents. Skip headings and stop after the final atom row.
|
|
44
|
+
symbols = []
|
|
45
|
+
positions = []
|
|
46
|
+
for line in source:
|
|
47
|
+
parts = line.split()
|
|
48
|
+
try:
|
|
49
|
+
if len(parts) < 4:
|
|
50
|
+
raise ValueError("Incomplete cluster row")
|
|
51
|
+
symbol = periodic[int(parts[0])]
|
|
52
|
+
point = [float(value.replace("D", "E")) for value in parts[1:4]]
|
|
53
|
+
except (ValueError, KeyError):
|
|
54
|
+
if symbols:
|
|
55
|
+
break
|
|
56
|
+
continue
|
|
57
|
+
symbols.append(symbol)
|
|
58
|
+
positions.append(point)
|
|
59
|
+
if not symbols:
|
|
60
|
+
raise ValueError("No atom positions in log cluster")
|
|
61
|
+
return symbols, np.asarray(positions, dtype=float)
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""XAS numerical operations that do not depend on Matplotlib or CLI options."""
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from .fdm_conv import FdmConv
|
|
9
|
+
from .fdm_txt import FdmTxt
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AnalyzeFdmXas:
|
|
13
|
+
"""Numerical analysis of FDMNES absorption spectra."""
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def average(spectra, weights=None):
|
|
17
|
+
"""Average the first absorption channel across spectra.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
spectra: Iterable of spectra sampled at exactly the same energies.
|
|
21
|
+
weights: One relative weight per spectrum. The default is uniform.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
tuple[numpy.ndarray, numpy.ndarray]: Common energy grid and mean XAS.
|
|
25
|
+
|
|
26
|
+
Raises:
|
|
27
|
+
ValueError: If no spectra are supplied, energy grids differ, or
|
|
28
|
+
weights are invalid.
|
|
29
|
+
"""
|
|
30
|
+
spectra = list(spectra)
|
|
31
|
+
if not spectra:
|
|
32
|
+
raise ValueError("No spectra")
|
|
33
|
+
|
|
34
|
+
energy = np.asarray(spectra[0].energy)
|
|
35
|
+
for spectrum in spectra[1:]:
|
|
36
|
+
if not np.array_equal(energy, spectrum.energy):
|
|
37
|
+
raise ValueError(
|
|
38
|
+
"Energy grids are different; interpolation not requested"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
if weights is None:
|
|
42
|
+
weights = np.ones(len(spectra))
|
|
43
|
+
else:
|
|
44
|
+
weights = np.asarray(weights, dtype=float)
|
|
45
|
+
|
|
46
|
+
if weights.shape != (len(spectra),) or not np.all(np.isfinite(weights)):
|
|
47
|
+
raise ValueError("Invalid weights")
|
|
48
|
+
if np.sum(weights) == 0:
|
|
49
|
+
raise ValueError("Invalid weights")
|
|
50
|
+
|
|
51
|
+
intensities = []
|
|
52
|
+
for spectrum in spectra:
|
|
53
|
+
intensities.append(spectrum.xas[:, 0])
|
|
54
|
+
|
|
55
|
+
values = np.stack(intensities)
|
|
56
|
+
average = np.average(values, axis=0, weights=weights)
|
|
57
|
+
return energy, average
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
def photon_energy(
|
|
61
|
+
convolution,
|
|
62
|
+
raw_xas,
|
|
63
|
+
*,
|
|
64
|
+
subtract_fermi=False,
|
|
65
|
+
fermi_energy=None,
|
|
66
|
+
):
|
|
67
|
+
"""Convert a convolved XAS spectrum to photon-energy coordinates.
|
|
68
|
+
|
|
69
|
+
The convolution file supplies both the energy and intensity columns.
|
|
70
|
+
Using the raw-XAS energy array instead would misalign the spectrum
|
|
71
|
+
whenever the convolution and raw grids have different lengths.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
convolution: ``FdmConv`` containing the convolved energy grid.
|
|
75
|
+
raw_xas: ``FdmTxt`` supplying the absorption-edge energy.
|
|
76
|
+
subtract_fermi: Subtract the Fermi-energy offset when True.
|
|
77
|
+
fermi_energy: Fermi-energy offset in eV, when subtraction is used.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
tuple[numpy.ndarray, numpy.ndarray]: Converted energy and XAS.
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
ValueError: If the required edge or Fermi energy is missing.
|
|
84
|
+
"""
|
|
85
|
+
if raw_xas.edge_energy is None:
|
|
86
|
+
raise ValueError("Missing E_edge")
|
|
87
|
+
|
|
88
|
+
if subtract_fermi and fermi_energy is None:
|
|
89
|
+
raise ValueError("Missing Fermi energy")
|
|
90
|
+
|
|
91
|
+
zero = 0.0
|
|
92
|
+
if subtract_fermi:
|
|
93
|
+
zero = fermi_energy
|
|
94
|
+
|
|
95
|
+
energy = convolution.energy + raw_xas.edge_energy - zero
|
|
96
|
+
intensity = convolution.xas[:, 0]
|
|
97
|
+
return energy, intensity
|
|
98
|
+
|
|
99
|
+
@staticmethod
|
|
100
|
+
def fermi_relative_convolution(convolution, raw_xas):
|
|
101
|
+
"""Convert a convolved spectrum to the Fermi-relative energy axis.
|
|
102
|
+
|
|
103
|
+
The original ``fdXAS_specified.py`` subtracts the Fermi energy
|
|
104
|
+
from the energy column in ``*_conv.txt``. It does not add the
|
|
105
|
+
absorption-edge energy in this particular plotting operation.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
convolution: Reader for the convolved FDMNES spectrum.
|
|
109
|
+
raw_xas: Reader for the corresponding non-convolved spectrum.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
tuple[numpy.ndarray, numpy.ndarray]: Fermi-relative energy
|
|
113
|
+
and absorption intensity, in the original row order.
|
|
114
|
+
"""
|
|
115
|
+
energy = convolution.get_eng().copy()
|
|
116
|
+
intensity = convolution.get_xas().copy()
|
|
117
|
+
fermi_energy = raw_xas.get_efermi()
|
|
118
|
+
energy -= fermi_energy
|
|
119
|
+
return energy, intensity
|
|
120
|
+
|
|
121
|
+
@staticmethod
|
|
122
|
+
def energy_reference(energy, raw_xas, *, input_is_photon, fermi):
|
|
123
|
+
"""Apply the energy-axis rules used by the original FDplot_XASs script.
|
|
124
|
+
|
|
125
|
+
For non-photon-energy input the calculation's axis is relative to the
|
|
126
|
+
absorption edge. With ``-f``, the axis becomes relative to E_Fermi.
|
|
127
|
+
When input is already photon energy, the original script subtracts
|
|
128
|
+
both E_edge and E_Fermi to produce the Fermi-relative axis.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
energy: Energy values in the file's original reference frame.
|
|
132
|
+
raw_xas: Raw spectrum providing edge and Fermi energies.
|
|
133
|
+
input_is_photon: Whether the input uses the Energpho keyword.
|
|
134
|
+
fermi: Whether to return a Fermi-relative energy grid.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
numpy.ndarray: Energy grid in the requested reference frame, in eV.
|
|
138
|
+
|
|
139
|
+
Raises:
|
|
140
|
+
ValueError: If the raw XAS header lacks an edge energy.
|
|
141
|
+
"""
|
|
142
|
+
energy = np.asarray(energy)
|
|
143
|
+
edge_energy = raw_xas.get_eedge()
|
|
144
|
+
fermi_energy = raw_xas.get_efermi()
|
|
145
|
+
|
|
146
|
+
if edge_energy is None:
|
|
147
|
+
raise ValueError("The raw XAS file has no edge energy")
|
|
148
|
+
|
|
149
|
+
if input_is_photon:
|
|
150
|
+
if fermi:
|
|
151
|
+
return energy - fermi_energy - edge_energy
|
|
152
|
+
return energy.copy()
|
|
153
|
+
|
|
154
|
+
if fermi:
|
|
155
|
+
return energy - fermi_energy
|
|
156
|
+
|
|
157
|
+
return energy + edge_energy
|
|
158
|
+
|
|
159
|
+
@classmethod
|
|
160
|
+
def site_spectra(
|
|
161
|
+
cls,
|
|
162
|
+
base_name,
|
|
163
|
+
site_indices,
|
|
164
|
+
*,
|
|
165
|
+
convolved=True,
|
|
166
|
+
input_is_photon=None,
|
|
167
|
+
fermi=None,
|
|
168
|
+
):
|
|
169
|
+
"""Read individual allsite outputs without changing site ordering.
|
|
170
|
+
|
|
171
|
+
``input_is_photon`` and ``fermi`` must be passed together to request
|
|
172
|
+
an energy-axis conversion. Omission of both retains the file's axis.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
base_name: Filout prefix, optionally with a directory.
|
|
176
|
+
site_indices: One-based absorbing-site indices in plot order.
|
|
177
|
+
convolved: Select convolved instead of raw site spectra.
|
|
178
|
+
input_is_photon: Whether the original calculation used Energpho.
|
|
179
|
+
fermi: Whether to return Fermi-relative energy values.
|
|
180
|
+
|
|
181
|
+
Returns:
|
|
182
|
+
list[tuple]: Tuples of energy, intensity, and site label.
|
|
183
|
+
|
|
184
|
+
Raises:
|
|
185
|
+
ValueError: If site indices or energy-reference options are invalid.
|
|
186
|
+
OSError: If a requested spectrum cannot be opened.
|
|
187
|
+
"""
|
|
188
|
+
indices = list(site_indices)
|
|
189
|
+
if not indices:
|
|
190
|
+
raise ValueError("At least one absorbing site is required")
|
|
191
|
+
if len(set(indices)) != len(indices):
|
|
192
|
+
raise ValueError("Duplicate absorbing-site numbers")
|
|
193
|
+
|
|
194
|
+
if (input_is_photon is None) != (fermi is None):
|
|
195
|
+
raise ValueError("Specify both energy-reference options")
|
|
196
|
+
|
|
197
|
+
result = []
|
|
198
|
+
for index in indices:
|
|
199
|
+
if not isinstance(index, int) or index < 1:
|
|
200
|
+
raise ValueError(f"Invalid absorbing-site number: {index!r}")
|
|
201
|
+
|
|
202
|
+
prefix = Path(f"{base_name}_{index}")
|
|
203
|
+
if convolved:
|
|
204
|
+
output_path = Path(f"{prefix}_conv.txt")
|
|
205
|
+
reader = FdmConv(output_path)
|
|
206
|
+
else:
|
|
207
|
+
output_path = Path(f"{prefix}.txt")
|
|
208
|
+
reader = FdmTxt(output_path)
|
|
209
|
+
|
|
210
|
+
energy = reader.get_eng().copy()
|
|
211
|
+
intensity = reader.get_xas().copy()
|
|
212
|
+
|
|
213
|
+
if input_is_photon is not None:
|
|
214
|
+
raw_xas = FdmTxt(Path(f"{prefix}.txt"))
|
|
215
|
+
energy = cls.energy_reference(
|
|
216
|
+
energy,
|
|
217
|
+
raw_xas,
|
|
218
|
+
input_is_photon=input_is_photon,
|
|
219
|
+
fermi=fermi,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
label = f"absorber={index}"
|
|
223
|
+
result.append((energy, intensity, label))
|
|
224
|
+
|
|
225
|
+
return result
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# SAE source: sae/athena/nor.py
|
|
3
|
+
# ---- SAE original header ----
|
|
4
|
+
# -*- coding: utf-8 -*-
|
|
5
|
+
###############################################################################
|
|
6
|
+
# K.NAKADA, kengo.nakada@gmail.com
|
|
7
|
+
#
|
|
8
|
+
# Read Athena Normalize Data ( *.txt.nor )
|
|
9
|
+
#
|
|
10
|
+
# コメントアウトを除いて energy, XANES 形式に並んだだけのファイル
|
|
11
|
+
# Athena の Normlized Data の読み込みプロット
|
|
12
|
+
#
|
|
13
|
+
###############################################################################
|
|
14
|
+
#
|
|
15
|
+
# 2020.08.10: カプセル化
|
|
16
|
+
#
|
|
17
|
+
# 2018.08.15
|
|
18
|
+
# Python2/3 両対応
|
|
19
|
+
#
|
|
20
|
+
# 2015.06.30
|
|
21
|
+
# == Noneo --> is None
|
|
22
|
+
#
|
|
23
|
+
# 2015.05.21
|
|
24
|
+
# ファイル名の自動取得&基本プロットのサンプル追加
|
|
25
|
+
#
|
|
26
|
+
# 2015.03.30
|
|
27
|
+
# startup
|
|
28
|
+
#
|
|
29
|
+
###############################################################################
|
|
30
|
+
###############################################################################
|
|
31
|
+
# import gzip
|
|
32
|
+
# import optparse
|
|
33
|
+
# sys.path.append('../..')
|
|
34
|
+
# import SpaceGroupEnvironment as SGE
|
|
35
|
+
###############################################################################
|
|
36
|
+
###############################################################################
|
|
37
|
+
# ラベル等のフォントサイズ
|
|
38
|
+
# レジェンドのフォントサイズ
|
|
39
|
+
# 軸の太さを設定。目盛りは変わらない
|
|
40
|
+
# for portrait
|
|
41
|
+
# plt.axvline(x=0,color='black',linewidth=1)
|
|
42
|
+
###############################################################################
|
|
43
|
+
###############################################################################
|
|
44
|
+
# plot_athena_nor(spec.eng,spec.nor)
|
|
45
|
+
# for i in range(ndata):
|
|
46
|
+
# print eng[i],nor[i]
|
|
47
|
+
# Copyright Kengo NAKADA; SAE class library.
|
|
48
|
+
# ---- End of SAE original header ----
|
|
49
|
+
"""Read an Athena normalized XAFS spectrum from a ``*.nor`` file."""
|
|
50
|
+
|
|
51
|
+
from pathlib import Path
|
|
52
|
+
import re
|
|
53
|
+
|
|
54
|
+
import numpy as np
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class AthenaNor:
|
|
58
|
+
"""Read the energy axis and normalized absorption from an Athena file.
|
|
59
|
+
|
|
60
|
+
Attributes:
|
|
61
|
+
path: Path to the source file.
|
|
62
|
+
energy: Photon energies in eV.
|
|
63
|
+
normalized: Normalized absorption values.
|
|
64
|
+
e0: Optional absorption-edge energy from the header.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(self, filename):
|
|
68
|
+
"""Load an Athena normalized spectrum.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
filename: Path to a ``*.nor`` text file.
|
|
72
|
+
|
|
73
|
+
Raises:
|
|
74
|
+
ValueError: If a data row has fewer than two numeric columns.
|
|
75
|
+
"""
|
|
76
|
+
self.path = Path(filename)
|
|
77
|
+
energies = []
|
|
78
|
+
normalized = []
|
|
79
|
+
self.e0 = None
|
|
80
|
+
|
|
81
|
+
with self.path.open(encoding="utf-8", errors="replace") as stream:
|
|
82
|
+
for line in stream:
|
|
83
|
+
stripped = line.strip()
|
|
84
|
+
if not stripped:
|
|
85
|
+
continue
|
|
86
|
+
|
|
87
|
+
if stripped.startswith("#"):
|
|
88
|
+
self._read_e0_comment(stripped)
|
|
89
|
+
continue
|
|
90
|
+
|
|
91
|
+
values = stripped.split()
|
|
92
|
+
if len(values) < 2:
|
|
93
|
+
raise ValueError(
|
|
94
|
+
f"Invalid Athena data row in {self.path}: {stripped}"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# SAE uses the first two columns as photon energy and
|
|
98
|
+
# normalized absorption. Athena may append other quantities.
|
|
99
|
+
energies.append(float(values[0]))
|
|
100
|
+
normalized.append(float(values[1]))
|
|
101
|
+
|
|
102
|
+
self.energy = np.asarray(energies, dtype=float)
|
|
103
|
+
self.normalized = np.asarray(normalized, dtype=float)
|
|
104
|
+
|
|
105
|
+
def _read_e0_comment(self, comment):
|
|
106
|
+
"""Extract the optional ``E0=`` field from an Athena comment.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
comment: One comment line from the source file.
|
|
110
|
+
"""
|
|
111
|
+
match = re.search(r"\bE0\s*=\s*([-+]?\d+(?:\.\d*)?(?:[eE][-+]?\d+)?)", comment)
|
|
112
|
+
if match is not None:
|
|
113
|
+
self.e0 = float(match.group(1))
|
|
114
|
+
|
|
115
|
+
def get_eng(self):
|
|
116
|
+
"""Return the photon-energy axis.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
numpy.ndarray: Photon-energy values.
|
|
120
|
+
"""
|
|
121
|
+
return self.energy
|
|
122
|
+
|
|
123
|
+
def get_nor(self):
|
|
124
|
+
"""Return the normalized absorption spectrum.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
numpy.ndarray: Normalized absorption values.
|
|
128
|
+
"""
|
|
129
|
+
return self.normalized
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
1 H
|
|
2
|
+
2 He
|
|
3
|
+
3 Li
|
|
4
|
+
4 Be
|
|
5
|
+
5 B
|
|
6
|
+
6 C
|
|
7
|
+
7 N
|
|
8
|
+
8 O
|
|
9
|
+
9 F
|
|
10
|
+
10 Ne
|
|
11
|
+
11 Na
|
|
12
|
+
12 Mg
|
|
13
|
+
13 Al
|
|
14
|
+
14 Si
|
|
15
|
+
15 P
|
|
16
|
+
16 S
|
|
17
|
+
17 Cl
|
|
18
|
+
18 Ar
|
|
19
|
+
19 K
|
|
20
|
+
20 Ca
|
|
21
|
+
21 Sc
|
|
22
|
+
22 Ti
|
|
23
|
+
23 V
|
|
24
|
+
24 Cr
|
|
25
|
+
25 Mn
|
|
26
|
+
26 Fe
|
|
27
|
+
27 Co
|
|
28
|
+
28 Ni
|
|
29
|
+
29 Cu
|
|
30
|
+
30 Zn
|
|
31
|
+
31 Ga
|
|
32
|
+
32 Ge
|
|
33
|
+
33 As
|
|
34
|
+
34 Se
|
|
35
|
+
35 Br
|
|
36
|
+
36 Kr
|
|
37
|
+
37 Rb
|
|
38
|
+
38 Sr
|
|
39
|
+
39 Y
|
|
40
|
+
40 Zr
|
|
41
|
+
41 Nb
|
|
42
|
+
42 Mo
|
|
43
|
+
43 Tc
|
|
44
|
+
44 Ru
|
|
45
|
+
45 Rh
|
|
46
|
+
46 Pd
|
|
47
|
+
47 Ag
|
|
48
|
+
48 Cd
|
|
49
|
+
49 In
|
|
50
|
+
50 Sn
|
|
51
|
+
51 Sb
|
|
52
|
+
52 Te
|
|
53
|
+
53 I
|
|
54
|
+
54 Xe
|
|
55
|
+
55 Cs
|
|
56
|
+
56 Ba
|
|
57
|
+
57 La
|
|
58
|
+
58 Ce
|
|
59
|
+
59 Pr
|
|
60
|
+
60 Nd
|
|
61
|
+
61 Pm
|
|
62
|
+
62 Sm
|
|
63
|
+
63 Eu
|
|
64
|
+
64 Gd
|
|
65
|
+
65 Tb
|
|
66
|
+
66 Dy
|
|
67
|
+
67 Ho
|
|
68
|
+
68 Er
|
|
69
|
+
69 Tm
|
|
70
|
+
70 Yb
|
|
71
|
+
71 Lu
|
|
72
|
+
72 Hf
|
|
73
|
+
73 Ta
|
|
74
|
+
74 W
|
|
75
|
+
75 Re
|
|
76
|
+
76 Os
|
|
77
|
+
77 Ir
|
|
78
|
+
78 Pt
|
|
79
|
+
79 Au
|
|
80
|
+
80 Hg
|
|
81
|
+
81 Tl
|
|
82
|
+
82 Pb
|
|
83
|
+
83 Bi
|
|
84
|
+
84 Po
|
|
85
|
+
85 At
|
|
86
|
+
86 Rn
|
|
87
|
+
87 Fr
|
|
88
|
+
88 Ra
|
|
89
|
+
89 Ac
|
|
90
|
+
90 Th
|
|
91
|
+
91 Pa
|
|
92
|
+
92 U
|
|
93
|
+
93 Np
|
|
94
|
+
94 Pu
|
|
95
|
+
95 Am
|
|
96
|
+
96 Cm
|
|
97
|
+
97 Bk
|
|
98
|
+
98 Cf
|
|
99
|
+
99 Es
|
|
100
|
+
100 Fm
|
|
101
|
+
101 Md
|
|
102
|
+
102 No
|
|
103
|
+
103 Lr
|