Skip to content

Commit 00f36ad

Browse files
add notimplementederror
1 parent 0bdbbb4 commit 00f36ad

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/diffpy/utils/tools.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ def get_package_info(package_names, metadata=None):
211211
return metadata
212212

213213

214+
def get_density_from_cloud(sample_composition, mp_token=""):
215+
"""Function to get material density from the MP database.
216+
217+
It is not implemented yet.
218+
"""
219+
raise NotImplementedError
220+
221+
214222
def compute_mu_using_xraydb(sample_composition, energy, sample_mass_density=None, packing_fraction=None):
215223
"""Compute the attenuation coefficient (mu) using the XrayDB database.
216224
@@ -242,14 +250,15 @@ def compute_mu_using_xraydb(sample_composition, energy, sample_mass_density=None
242250
"You must specify either sample_mass_density or packing_fraction, but not both. "
243251
"Please rerun specifying only one."
244252
)
245-
if sample_mass_density is not None:
246-
mu = material_mu(sample_composition, energy * 1000, density=sample_mass_density, kind="total") / 10
247-
else:
248-
warnings.warn(
249-
"Warning: Density is set to None if a packing fraction is specified, "
250-
"which may cause errors for some materials. "
251-
"We recommend specifying sample mass density for now. "
252-
"Auto-density calculation is coming soon."
253-
)
254-
mu = material_mu(sample_composition, energy * 1000, density=None, kind="total") * packing_fraction / 10
253+
if packing_fraction is None:
254+
packing_fraction = 1
255+
try:
256+
sample_mass_density = get_density_from_cloud(sample_composition) * packing_fraction
257+
except NotImplementedError:
258+
warnings.warn(
259+
"Density computation is not implemented right now. "
260+
"Please rerun specifying a sample mass density."
261+
)
262+
energy_eV = energy * 1000
263+
mu = material_mu(sample_composition, energy_eV, density=sample_mass_density, kind="total") / 10
255264
return mu

tests/test_tools.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,6 @@ def test_get_package_info(monkeypatch, inputs, expected):
184184
},
185185
1.2522,
186186
),
187-
( # C2: Composition, energy, and packing fraction provided, expect to get mu based on packing fraction
188-
# Reuse pattern from C1.1 here
189-
{
190-
"sample_composition": "quartz",
191-
"energy": 10,
192-
"packing_fraction": 0.5,
193-
},
194-
2.5184,
195-
),
196187
],
197188
)
198189
def test_compute_mu_using_xraydb(inputs, expected_mu):

0 commit comments

Comments
 (0)