Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New algorithm to find multiple UB matrices in case of multiple domains or spurious peaks #37309

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

RichardWaiteSTFC
Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC commented May 9, 2024

Description of work

To-Do:

  • Change release notes to 6.11

FindMultipleUMatrices will use the lattice parameters and spacegroup provided to optimise a number (NumberOfUBs)
of UB matrices (B is hard-coded due to the lattice parameters provided) and return a group of peak workspaces
one for each UB, containing the peaks that are indexed most accurately by that UB.

This algorithm is useful for finding a single UB in the presence of spurious peaks, or finding multiple UBs when there
are multiple domains.

Fixes #35711

To test:

(1) Run the doc test code locally

from scipy.spatial.transform import Rotation as rot

ws = LoadEmptyInstrument(InstrumentName='SXD', OutputWorkspace='empty_SXD')
axis = ws.getAxis(0)
axis.setUnit("TOF")

# create a peak tables of orthorhombic domains with lattice parameters a=4, b=5, c=10
alatt = {'a': 4, 'b': 5, 'c': 9, 'alpha': 90, 'beta': 90, 'gamma': 90}
ubs = [np.diag([1/alatt['a'], 1/alatt['b'], 1/alatt['c']])]
ubs.append(rot.from_rotvec([0,0,90], degrees=True).as_matrix()  @ ubs[0])

peaks = CreatePeaksWorkspace(InstrumentWorkspace=ws, NumberOfPeaks=0, OutputWorkspace=f"peaks")
for iub, ub in enumerate(ubs):
    SetUB(peaks, UB=ub)
    for h in range(1, 3):
        for k in range(1, 3):
            for l in range(2,4):
                pk = peaks.createPeakHKL([h, k ,l])
                if pk.getDetectorID() > 0:
                    peaks.addPeak(pk)

peaks_out = FindMultipleUMatrices(PeaksWorkspace=peaks, OutputWorkspace='peaks_out', **alatt, 
                                  MinDSpacing=1.25, MaxDSpacing=3.5, Spacegroup='P m m m',
                                  NumberOfUBs=2)

for ipk, pks in enumerate(peaks_out):
    print("HKL along x-axis of QLab = ", np.round(pks.sample().getOrientedLattice().getvVector()))

It should print

HKL along x-axis of QLab =  [ 4. -0.  0.]
HKL along x-axis of QLab =  [-0. -5.  0.]

Reviewer

Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.

Code Review

  • Is the code of an acceptable quality?
  • Does the code conform to the coding standards?
  • Are the unit tests small and test the class in isolation?
  • If there is GUI work does it follow the GUI standards?
  • If there are changes in the release notes then do they describe the changes appropriately?
  • Do the release notes conform to the release notes guide?

Functional Tests

  • Do changes function as described? Add comments below that describe the tests performed?
  • Do the changes handle unexpected situations, e.g. bad input?
  • Has the relevant (user and developer) documentation been added/updated?

Does everything look good? Mark the review as Approve. A member of @mantidproject/gatekeepers will take care of it.

Gatekeeper

If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.

@RichardWaiteSTFC RichardWaiteSTFC added Diffraction Issues and pull requests related to diffraction Single Crystal Issues and pull requests related to single crystal ISIS Team: Diffraction Issue and pull requests managed by the Diffraction subteam at ISIS labels May 9, 2024
@RichardWaiteSTFC RichardWaiteSTFC added this to the Release 6.10 milestone May 9, 2024
@RichardWaiteSTFC RichardWaiteSTFC marked this pull request as draft May 9, 2024 14:23
PReviously using angles but due to point group some UBs were not purelyt transformed by rotation but also included reflection.
@RichardWaiteSTFC RichardWaiteSTFC force-pushed the 35711_new_algorithm_to_find_multiple_UB branch from f722081 to a043f91 Compare May 13, 2024 09:15
@RichardWaiteSTFC RichardWaiteSTFC force-pushed the 35711_new_algorithm_to_find_multiple_UB branch from facd7cd to 0fe3c05 Compare May 13, 2024 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Diffraction Issues and pull requests related to diffraction ISIS Team: Diffraction Issue and pull requests managed by the Diffraction subteam at ISIS Single Crystal Issues and pull requests related to single crystal
Projects
Status: Unassigned
Status: No status
Development

Successfully merging this pull request may close these issues.

Algorithm to find multiple UBs in a peak table
1 participant