Skip to content

Commit 255c603

Browse files
refactor: rearrange error msg and docstring, update condition in function
1 parent 00f36ad commit 255c603

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/diffpy/utils/tools.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import importlib.metadata
22
import json
3-
import warnings
43
from copy import copy
54
from pathlib import Path
65

@@ -212,11 +211,15 @@ def get_package_info(package_names, metadata=None):
212211

213212

214213
def get_density_from_cloud(sample_composition, mp_token=""):
215-
"""Function to get material density from the MP database.
214+
"""Function to get material density from the MP or COD database.
216215
217216
It is not implemented yet.
218217
"""
219-
raise NotImplementedError
218+
raise NotImplementedError(
219+
"So sorry, density computation from composition is not implemented right now. "
220+
"We hope to have this implemented in the next release. "
221+
"Please rerun specifying a sample mass density."
222+
)
220223

221224

222225
def compute_mu_using_xraydb(sample_composition, energy, sample_mass_density=None, packing_fraction=None):
@@ -250,15 +253,8 @@ def compute_mu_using_xraydb(sample_composition, energy, sample_mass_density=None
250253
"You must specify either sample_mass_density or packing_fraction, but not both. "
251254
"Please rerun specifying only one."
252255
)
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-
)
256+
if packing_fraction is not None:
257+
sample_mass_density = get_density_from_cloud(sample_composition) * packing_fraction
262258
energy_eV = energy * 1000
263259
mu = material_mu(sample_composition, energy_eV, density=sample_mass_density, kind="total") / 10
264260
return mu

0 commit comments

Comments
 (0)