pyxem / diffsims

An open-source Python library providing utilities for simulating diffraction
https://diffsims.readthedocs.io
GNU General Public License v3.0
46 stars 26 forks source link

Issue with calculating electron diffraction pattern when using CIF with Ni3+ sites #190

Open lnaglecocco opened 2 years ago

lnaglecocco commented 2 years ago

Description of suspected bug I use structure = diffpy.structure.loadStructure() to import a CIF. This CIF has Ni3+ sites. I attempt to calculate a set of diffraction patterns for this structure, roughly following the code from the tutorial 02 GaAs Nanowire - Phase Mapping - Orientation Mapping. When I run the line diff_lib = lib_gen.get_diffraction_library(...) I get a long error (listed in full at the end of this report) which seems to come up because there isn't an 'Ni3+' key in the scattering_params_dict.

I am very new to Pyxem, and generally very new to electron diffraction too, so I may have misunderstood something here. It seems to me quite important to be able to specify an oxidation state of an element as the scattering cross-section of electrons in a material will surely depend on the oxidation state of the atom (though if I've got that wrong please do correct me). If someone could let me know if I can solve this at my end or if this is indeed a bug, I'd be very grateful

Expected behavior I would have expected 'Ni3+' to have a scattering parameter listed in scattering_params_dict.

Error message in full

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-22-c080fb293ea8> in <module>
      8                                            reciprocal_radius=reciprocal_radius,
      9                                            half_shape=(half_size, half_size),
---> 10                                            max_excitation_error=1/10,with_direct_beam=False)

C:\ProgramData\Anaconda3\lib\site-packages\diffsims\generators\library_generator.py in get_diffraction_library(self, structure_library, calibration, reciprocal_radius, half_shape, with_direct_beam, max_excitation_error, debye_waller_factors)
    112                     with_direct_beam=with_direct_beam,
    113                     max_excitation_error=max_excitation_error,
--> 114                     debye_waller_factors=debye_waller_factors,
    115                 )
    116 

C:\ProgramData\Anaconda3\lib\site-packages\diffsims\generators\diffraction_generator.py in calculate_ed_data(self, structure, reciprocal_radius, rotation, with_direct_beam, max_excitation_error, debye_waller_factors)
    284             prefactor=shape_factor,
    285             scattering_params=self.scattering_params,
--> 286             debye_waller_factors=debye_waller_factors,
    287         )
    288 

C:\ProgramData\Anaconda3\lib\site-packages\diffsims\utils\sim_utils.py in get_kinematical_intensities(structure, g_indices, g_hkls_array, debye_waller_factors, scattering_params, prefactor)
    255         structure=structure,
    256         debye_waller_factors=debye_waller_factors,
--> 257         scattering_params=scattering_params,
    258     )
    259 

C:\ProgramData\Anaconda3\lib\site-packages\diffsims\utils\sim_utils.py in get_vectorized_list_for_atomic_scattering_factors(structure, debye_waller_factors, scattering_params)
    177 
    178     for i, site in enumerate(structure):
--> 179         coeffs[i] = scattering_params_dict[site.element]
    180         dwfactors[i] = debye_waller_factors.get(site.element, 0)
    181         fcoords[i] = site.xyz

KeyError: 'Ni3+'
pc494 commented 2 years ago

Hi, I'm going to move this issue over to diffsims (as it's a simulation, that's handled by them). It's not obvious to me what is wrong at a glance, but we'll have a look.

hakonanes commented 2 years ago

If someone could let me know if I can solve this at my end or if this is indeed a bug, I'd be very grateful

I won't consider this a bug, it's just that we haven't included scattering factors for atoms in oxidized states. I'd be happy to review a contribution of these if they are available.

As far as I know, the absolute kinematical structure factors calculated with diffsims are mostly used in pair distribution function analysis in pyxem, implemented by @JoonatanL.