Add tests that Multislice matches py_multislice's CBED
The Multislice module is designed to compute a single CBED pattern directly from a probe and potential. This differs only slightly from pyms.Premixed_routines.CBED which takes a periodic crystalline structure instead and computes a single CBED. Also, by default CBED()
performs frozen phonon iterations by perturbing atoms to simulate thermal diffuse scattering, whereas Multislice
does not (cannot, since it operates on voxelized potentials instead of atoms).
In order to prevent our code drifting away from pyms, which we believe to be pretty reliable, we should implement some simple tests that we can recover exactly, or near exactly, the CBED patterns generated by pyms using our own ptychopath code. These tests can be added directly to tests/test_multislice.py
and run using the pytest
command.
We can extend with more tests in the future, including comparing to adorym and other libraries, but for this issue we should implement at least the following test:
- Load a structure using pyms. Use one of the structures that ships with the pyms Demos. We can add it to our repo in the tests/ directory.
- Create a probe using pyms.
- Simulate a single CBED pattern without frozen phonon displacements using pyms. This should use subslicing but not multiple unit cell thickness (we can but that will complicate the test).
- Simulate a corresponding CBED pattern using our
ptychopath.multislice.Multislice
module. Care must be taken here to set the right gridspacing and other parameters. This is the importance of this test, as it will be our reference for how to set those parameters consistently between libraries in the future. - Assert that the two CBEDs match using
torch.allclose()
.
The first few steps above can be copied directly from the CBED.ipynb demo from pyms. The rest can be inferred from the ptychopath documentation and a little experimentation. Please document any non-obvious code within the test.