mantid icon indicating copy to clipboard operation
mantid copied to clipboard

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

Open RichardWaiteSTFC opened this issue 9 months ago • 0 comments

Description of work

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.]

or equivalent


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 avatar May 09 '24 13:05 RichardWaiteSTFC