Skip to content

Commit 464f116

Browse files
committed
Clean up run and test modules.
1 parent 2ce16fd commit 464f116

File tree

2 files changed

+22
-48
lines changed

2 files changed

+22
-48
lines changed

atomdb/datasets/nist/run.py

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -105,42 +105,39 @@ def get_energy(atnum, nelec, ip, datafile):
105105
106106
Returns
107107
-------
108-
float
109-
Ground state energy of the species (in Ha).
108+
float or None
109+
Ground state energy of the species (in Ha). Returns None if data is unavailable.
110110
111111
Notes
112-
-----
113-
Dianion species get a default energy value of None. For anions with charge=-1, the energy is computed
114-
as E_anion = E_neutral - IP_anion, where E_neutral is the ground state energy of the neutral species
115-
and IP_anion is the ionization potential of the anion. The IP_anion is obtained from the conceptual-DFT
116-
data in the file data/c6cp04533b1.csv.
117-
112+
-----
113+
- Dianion species (charge = -2) return None.
114+
- Anion energy (charge = -1) is computed as:
115+
:math:`E_{anion} = E_{neutral} - IP_{anion}`
116+
where :math:`IP_{anion}` is obtained from the conceptual-DFT data in the file data/c6cp04533b1.csv.
118117
"""
119-
# Set an energy default value in case there isn't available NIST data
120-
energy = None
118+
default_energy = None
121119
charge = atnum - nelec
122120
hdf5_path = os.path.join(MODULE_DATAPATH, datafile)
123121

124-
# Load NIST atomic spectra database data (contains neutral and cationic species).
122+
# Return None for dianions (charge = -2)
125123
if charge == -2:
126-
return energy
127-
128-
if charge == -1:
129-
nelec = atnum
124+
return default_energy
125+
126+
# Load NIST atomic spectra database data (contains neutral and cationic species).
127+
# For anions, load data for the neutral species (nelec = atnum)
128+
nelec = nelec if charge != -1 else atnum
130129
spectra_data = load_nist_spectra_data(atnum, nelec, hdf5_path)
131130
energies = spectra_data["energy"]
132131

133-
# Energy for neutral or cationic species
132+
# Return energy (in Hartree) for neutral and cationic species (charge ≥ 0)
134133
if charge >= 0:
135-
# energies = spectra_data["energy"]
136-
# Convert energy to Hartree from cm^{-1} if available
137-
return energies[0] / CMINV if len(energies) != 0 else energy
134+
return energies[0] / CMINV if len(energies) != 0 else default_energy
135+
136+
# Compute anion energy (charge = -1), ensuring ip is not zero or None
137+
if charge == -1 and ip not in [None, 0]:
138+
return (energies[0] / CMINV - ip) if len(energies) != 0 else default_energy
138139

139-
# Energy for anions with charge=-1
140-
elif charge == -1 and ip not in [None, 0]: # check IP is not zero or None
141-
# neutral_energy = load_nist_spectra_data(atnum, atnum, hdf5_path)["energy"]
142-
# Convert energy to Hartree from cm^{-1} if available
143-
return (energies[0] / CMINV - ip) if len(energies) != 0 else energy
140+
return default_energy
144141

145142

146143
def run(elem, charge, mult, nexc, dataset, datapath):
@@ -203,26 +200,7 @@ def run(elem, charge, mult, nexc, dataset, datapath):
203200
colid = table_etas[0].index(str(charge))
204201
eta = float(table_etas[atnum][colid]) * EV if len(table_etas[atnum][colid]) > 1 else None
205202

206-
# # Get the ground state energy from database_beta_1.3.0.h5.
207-
# # Set an energy default value since there is no data for anions in database_beta_1.3.0.h5.
208-
# energy = None
209-
# h5path = os.path.join(MODULE_DATAPATH, "database_beta_1.3.0.h5")
210-
# if charge >= 0: # neutral or cationic species
211-
# spectra_data = load_nist_spectra_data(atnum, nelec, h5path)
212-
# energies = spectra_data["energy"]
213-
# # Convert energy to Hartree from cm^{-1} if available
214-
# energy = energies[0] / CMINV if len(energies) != 0 else energy
215-
216-
# # Compute the ground state energy for anions with charge=-1
217-
# # Use the ground state energy of the neutral species from database_beta_1.3.0.h5
218-
# # and subtract the ionization potential of the anion from the conceptual-DFT data c6cp04533b1.csv
219-
# # This is: E_anion = E_neutral - IP_anion.
220-
# # This procedure does not work if there is no GS data for the neutral species, or if the anion's IP
221-
# # is zero or None.
222-
# if charge == -1 and ip not in [None, 0]: # check IP is not zero or None
223-
# neutral_energy = load_nist_spectra_data(atnum, atnum, h5path)["energy"]
224-
# # Convert energy to Hartree from cm^{-1} if available
225-
# energy = (neutral_energy[0] / CMINV - ip) if len(neutral_energy) != 0 else energy
203+
# Get the ground state energy from NIST database_beta_1.3.0.h5.
226204
energy = get_energy(atnum, nelec, ip, "database_beta_1.3.0.h5")
227205

228206
# Return Species instance

atomdb/test/test_nist.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,4 @@ def test_nist_data(case):
158158

159159
for attr, value in case.items():
160160
data_value = getattr(sp, attr)
161-
# try:
162-
# data_value = getattr(sp, attr)
163-
# except AttributeError:
164-
# data_value = getattr(sp._data, attr)
165161
assert data_value == pytest.approx(value), f"{elem} {attr} is not as expected."

0 commit comments

Comments
 (0)