Skip to content

Conversation

RichardWaiteSTFC
Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC commented Aug 16, 2024

Description of work

There was a bug in the call to MaterialBuilder here

sample = material_builder.setFormula(sample_details.material_object.chemical_formula).build()

The build method requires unit cells with multiple atoms to have a number density set.

The number density is not actually used to calculate the cross-sections required for the PDF normalisation - so here I just set it to an arbitrary number (1).

There is no associated issue.

Report to: Helen Playford

To test:

(1) Unzip these files somewhere and update the script below with the path. Also update the paths in the file polaris_config_example.yaml PR34144Files.zip
(2) Run this script without error

from mantid.simpleapi import *
import matplotlib.pyplot as plt
import numpy as np
from isis_powder import polaris, SampleDetails


config_file_path = r"C:\Total Scattering\polaris_config_example.yaml"
polaris = polaris.Polaris(config_file=config_file_path, user_name="test", mode="PDF")

sam = SampleDetails(height=4.6,radius=0.29855,center=[0,0,0],shape='cylinder')
sam.set_container(radius=0.3175,chemical_formula='V')
sam.set_material(chemical_formula='Pb-Sn-F4',
number_density=0.059, packing_fraction=0.5)
polaris.set_sample_details(sample=sam)

polaris.create_vanadium(first_cycle_run_no="98532", multiple_scattering=True, do_absorb_corrections=True, mayers_mult_scat_events=1)
polaris.focus(run_number="98533", input_mode='Summed', do_absorb_corrections=True,multiple_scattering=False,
              do_van_normalisation=True, van_normalisation_method="Absolute",
              keep_raw_workspace=False, mayers_mult_scat_events=1)

# q_lim from script on https://github.com/mantidproject/mantid/pull/28447
q_lim = [[2.5, 3, 4, 6, 7], [3.5, 5, 7, 11, 40]]
polaris.create_total_scattering_pdf(run_number="98533", merge_banks=True,q_lims=q_lim, 
                                    freq_params=[1.0], pdf_type="g(r)", merge_banks=True,)

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 this to the Release 6.11 milestone Aug 16, 2024
@RichardWaiteSTFC RichardWaiteSTFC added Diffraction Issues and pull requests related to diffraction Powder Issues and pull requests related to powder diffraction ISIS: Diffraction Issue and pull requests relating to Diffraction at ISIS labels Aug 16, 2024
@sf1919
Copy link
Contributor

sf1919 commented Aug 20, 2024

As the test failures don't seem to be related to libopenblas issues we've been seeing I will not re-run these tests

Copy link
Contributor

@GuiMacielPereira GuiMacielPereira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is straight forward, looks good.

However, I am trying to run the script but I think I am getting an unrelated error:

ValueError: You must set multiple_scattering=True and do_absorb_corrections=True when creating the vanadium run.

So I tried running it with both of the arguments set to True but I get another error later down the line:

NotImplementedError: Multiple scattering absorption corrections are not yet implemented for anisotropic samples

So I am not sure how I can bypass this?

@RichardWaiteSTFC
Copy link
Contributor Author

The code is straight forward, looks good.

However, I am trying to run the script but I think I am getting an unrelated error:

ValueError: You must set multiple_scattering=True and do_absorb_corrections=True when creating the vanadium run.

So I tried running it with both of the arguments set to True but I get another error later down the line:

NotImplementedError: Multiple scattering absorption corrections are not yet implemented for anisotropic samples

So I am not sure how I can bypass this?

Sorry @GuiMacielPereira - I copied the wrong testing instructions!
I have updated them - but I had to change the run number as the config/mapping files attached are old - if it doesn't work I'l send you another zip folder. Thanks for testing!

@GuiMacielPereira GuiMacielPereira self-requested a review August 28, 2024 10:24
Copy link
Contributor

@GuiMacielPereira GuiMacielPereira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good and the script now runs without problems 👍

@robertapplin robertapplin self-assigned this Aug 28, 2024
@robertapplin
Copy link
Contributor

Looks like there are some failing tests, so I will unassign myself for now

@robertapplin robertapplin removed their assignment Aug 28, 2024
@RichardWaiteSTFC RichardWaiteSTFC force-pushed the fix_bug_POLARIS_total_Scattering_normalisation branch from 4085f09 to 023b9b3 Compare August 28, 2024 15:40
@RichardWaiteSTFC RichardWaiteSTFC force-pushed the fix_bug_POLARIS_total_Scattering_normalisation branch from 023b9b3 to b55e7ea Compare August 28, 2024 17:41
def validate(self):
self.tolerance_is_rel_err = True
self.tolerance = 1e-6
self.tolerance = 1e-5 # same tolused in FocusTestAbsorptionMayers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.tolerance = 1e-5 # same tolused in FocusTestAbsorptionMayers
self.tolerance = 1e-5 # same tol used in FocusTestAbsorptionMayers

Comment on lines +675 to +677
# define multi-atom cell to stop regression of bug calling MaterialBuilder.build() without setting number density
# which works for one atom cells as number density is automatically calculated
sample_details.set_material(chemical_formula="Si Si", number_density=0.04996)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused, does this mean that now users have to change how they set the chemical_formula argument to get the same behaviour as before?

Copy link
Contributor Author

@RichardWaiteSTFC RichardWaiteSTFC Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, users will set the material as/how they always have. Here I specify the chemical formula as "Si Si" because mantid has a lookup somewhere in MaterialBuilder to find the number density if you specify a single atom formula (e.g "Si") which meant the tests weren't catching the bug found by POLARIS scientists (with real samples containing more atom species). The two formula "Si Si" and "Si" should be equivalent as the default unit for number density in mantid is (for better or worse) atoms/Ang^3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, thanks for clarifying!

@GuiMacielPereira GuiMacielPereira self-requested a review August 30, 2024 11:25
@robertapplin robertapplin merged commit 7549794 into main Aug 30, 2024
10 checks passed
@robertapplin robertapplin deleted the fix_bug_POLARIS_total_Scattering_normalisation branch August 30, 2024 11:57
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: Diffraction Issue and pull requests relating to Diffraction at ISIS Powder Issues and pull requests related to powder diffraction
Projects
Status: Merged
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants