@@ -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+
214222def 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
0 commit comments