Skip to content

Conversation

@pkienzle
Copy link
Contributor

@pkienzle pkienzle commented Mar 10, 2025

Random Hayter MSA model generation was failing because of a typo in one of the parameter names. On further investigation I noticed that the salt concentration was not randomized, and the temperature range was too extreme.

Test using:

python -m sasmodels.compare hayter_msa -midq -pars -highq -sets=10

Many random models are failing (see #143). We should either address the instabilities in the calculation that lead to bad values, or limit the ranges on the parameters to exclude those values.

The generator is using the following parameter distributions:

  • radius_effective ~ 10^U(1, 4.7) ≈ [10, 50000] nm
  • volfraction ~ 10^U(-2, -0.3) ≈ [0.01, 0.5]
  • charge ~ round(10^U(0, 2.3)) ≈ [1, 200] e
  • temperature ~ U(270, 450) = [270, 450] K
  • concentration_salt ~ 10^U(-3, 2) ≈ [0.001, 100] M
  • dielectconst ~ 10^U(0, 2.3) ≈ [1, 200]

@pkienzle pkienzle changed the title Fix hayter msa random model Fix random model generator for Hayter MSA Mar 11, 2025
@butlerpd butlerpd requested review from butlerpd and yunliu01 April 22, 2025 13:46
Copy link
Contributor

@yunliu01 yunliu01 left a comment

Choose a reason for hiding this comment

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

Discussed with @krzywon. Based on what Jeff mentioned, the newly set boundary for the random model generator is only used for the unit test. Therefore, it is supposed not to affect the data fitting and model calculation. Therefore, I will go ahead to approve it.

However, be noted that if the code will use the random generator model to set the boundary during the fitting, there will be potential problems as it is possible that the users may have systems for which the fitting parameters are outside of the boundary listed here. The newly set boundary parameters for the random function generator are as following:

radius_effective ~ 10^U(1, 4.7) ≈ [10, 50000] nm
volfraction ~ 10^U(-2, -0.3) ≈ [0.01, 0.5]
charge ~ round(10^U(0, 2.3)) ≈ [1, 200] e
temperature ~ U(270, 450) = [270, 450] K
concentration_salt ~ 10^U(-3, 2) ≈ [0.001, 100] M
dielectconst ~ 10^U(0, 2.3) ≈ [1, 200]

First the radius could be smaller than 10 nm.

The volume fraction can be smaller than 0.01. (Well, technically speaking Hayter_msa will not be reliable at low concentrations due to the intrinsic deficiency of the theory. But the code can generate a structure factor in this volume fraction region.)

Boundary for the charge number is tricky one. A fractional charge could be possible. In principle, the charge can be allowed to be zero for the theory so that the theory becomes the hard sphere system model. However, I haven't gone through the code so I am not sure if the code can handle zero charge.

@pkienzle
Copy link
Contributor Author

I adjusted the limits to the following:

radius_effective ~ 10^U(1, 4.7) ≈ [1, 50000] nm
volfraction ~ 10^U(-2, -0.3) ≈ [0.001, 0.5]
charge ~ 10^U(0, 2.3) ≈ [0.01, 200] e
temperature ~ U(270, 450) = [270, 450] K
concentration_salt ~ 10^U(-3, 2) ≈ [0.001, 100] M
dielectconst ~ 10^U(0, 2.3) ≈ [1, 200]

About 40% of the random models fail. No single parameter seems to be responsible.

Charge=0 produces NaN. Charge=0.01 matches hard sphere within 0.5% or better when it is defined, but there are still high fail rates from some parameter combinations.

I added these comments to #143

@krzywon krzywon changed the base branch from master to sasmodels_1.0.10 May 13, 2025 12:25
@krzywon krzywon merged commit efe5f0f into sasmodels_1.0.10 May 13, 2025
18 checks passed
@krzywon krzywon deleted the fix-hayter-msa-random-model branch May 13, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants