Skip to content

Fix allowed vectors when (hkl) are slightly off integers#191

Merged
pc494 merged 11 commits intopyxem:mainfrom
hakonanes:fix-allowed-vectors
Jan 26, 2023
Merged

Fix allowed vectors when (hkl) are slightly off integers#191
pc494 merged 11 commits intopyxem:mainfrom
hakonanes:fix-allowed-vectors

Conversation

@hakonanes
Copy link
Member

Description of the change

This patch fixes calculation of allowed vectors in ReciprocalLatticeVector.allowed when vectors (hkl) are slightly off integers. A test has been added that only passes with this patch. See example below for a demonstration.

I suggest to make a patch release v0.5.1 immediately after this branch has been merged onto main (I renamed the main branch from master to main). There has been no activity since the v0.5.0 release, so that should be OK.

Other changes I've made:

  • Run tests in parallel on two threads on GitHub actions with pytest-xdist (test dependency). Should reduce the test time by about half.
  • Ran make linkcheck on the docs and updated some links (had to remove some since I couldn't find a replacement).

Progress of the PR

Minimal example of the bug fix or new feature

Only all odd or all even (hkl) are allowed in face-centered cubic lattices. Below we create a set of vectors which all should be allowed.

>>> from diffpy.structure import Atom, Lattice, Structure
>>> from orix.crystal_map import Phase
>>> from diffsims.crystallography import ReciprocalLatticeVector
>>> phase = Phase(
...     name="nickel",
...     space_group=225,
...     structure=Structure(
...         lattice=Lattice(3.5236, 3.5236, 3.5236, 90, 90, 90),
...         atoms=[Atom(xyz=[0, 0, 0], atype="Ni", Uisoequiv=0.006332)],
...     ),
... )
>>> rlv = ReciprocalLatticeVector.from_min_dspacing(phase)
>>> rlv.sanitise_phase()
>>> rlv.calculate_structure_factor()
>>> structure_factor = abs(rlv.structure_factor)
>>> rlv = rlv[structure_factor > 0.4 * structure_factor.max()]
>>> rlv.print_table()
 h k l      d     |F|_hkl   |F|^2   |F|^2_rel   Mult 
 1 1 1    2.034    11.8     140.0     100.0      8   
 2 0 0    1.762    10.4     108.2      77.3      6   
 2 2 0    1.246     7.4     55.0       39.3      12  
 3 1 1    1.062     6.2     38.6       27.6      24  
 2 2 2    1.017     5.9     34.7       24.8      8   
 4 0 0    0.881     4.9     23.9       17.1      6   

# Before this fix

>>> rlv.allowed
array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True, False,  True, False,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True, False,  True,  True,  True,  True, False,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True, False,  True, False,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True])

# After this fix

array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True])

For reviewers

  • The PR title is short, concise, and will make sense 1 year later.
  • New functions are imported in corresponding __init__.py.
  • New features, API changes, and deprecations are mentioned in the
    unreleased section in CHANGELOG.rst.
  • Contributor(s) are listed correctly in credits in diffsims/release_info.py and
    in .zenodo.json.

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes added the bug Something isn't working label Jan 24, 2023
@hakonanes hakonanes added this to the v0.5.1 milestone Jan 24, 2023
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes force-pushed the fix-allowed-vectors branch from 4f09624 to 8dce703 Compare January 24, 2023 17:19
@hakonanes
Copy link
Member Author

A build failed due to Python 3.6 not being available on the Ubuntu 22.04 test architecture (it is available on 20.04). The oldest-version-build now uses 20.04. An alternative is to take the hint and discontinue support for Python 3.6 for diffsims.

@hakonanes hakonanes requested a review from pc494 January 24, 2023 21:20
@pc494
Copy link
Member

pc494 commented Jan 25, 2023

Just dropping by, will review it a little later - hopefully tomorrow. I think you're right, this is sensible housekeeping and can go out as a patch almost immediately.

I wIll update the copyright dates and do some other small sweeps and then package up.

Happy to leave the Py3.6 fix in for now and then post-release drop it (and probably 3.7 at the same time)

@hakonanes
Copy link
Member Author

Great!

update the copyright dates

From the package root, using licenseheaders -y 2017-2023 should do the trick (https://pypi.org/project/licenseheaders/). I'll do this now.

(and probably 3.7 at the same time)

Packages depending on diffsims, like pyxem, kikuchipy and others, should be notified, via e.g. the changelog, and drop support for 3.7 themselves before it is dropped in diffsims. kikuchipy e.g. supports 3.7.

I'll add a statement in the changelog under deprecations that 3.6 support will be dropped in Python 3.6.

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@pc494
Copy link
Member

pc494 commented Jan 26, 2023

I'm merging now, are you happy to make the release @hakonanes?

@pc494 pc494 merged commit 715ea14 into pyxem:main Jan 26, 2023
@hakonanes
Copy link
Member Author

Thank you! Yes, I'll get to it within the next hour.

@hakonanes hakonanes deleted the fix-allowed-vectors branch January 26, 2023 15:43
@hakonanes
Copy link
Member Author

Patch release is available from PyPI, and Zenodo and the docs were updated successfully. The conda-forge release should be ready by tomorrow afternoon.

@hakonanes
Copy link
Member Author

It's out on conda-forge. Thank you for the quick review, Phillip!

@pc494
Copy link
Member

pc494 commented Jan 27, 2023

lovely, just had the ping from conda forge :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants