From f14166517af9ec75fc96489e4998946d4570ea3c Mon Sep 17 00:00:00 2001 From: Vincent Favre-Nicolin Date: Tue, 28 Jul 2026 13:30:09 +0200 Subject: [PATCH] Fix displ_transl refinement toggle in quick_fit_profile Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- news/83.rst | 23 +++++++++++++++++++ src/pyobjcryst/powderpattern.py | 4 ++-- tests/test_powderpattern.py | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 news/83.rst diff --git a/news/83.rst b/news/83.rst new file mode 100644 index 0000000..57ea1e8 --- /dev/null +++ b/news/83.rst @@ -0,0 +1,23 @@ +**Added:** + +* None. + +**Changed:** + +* None. + +**Deprecated:** + +* None. + +**Removed:** + +* None. + +**Fixed:** + +* `quick_fit_profile(displ_transl=True)` now correctly enables refinement of `2ThetaDispl` and `2ThetaTransp` by unfixing both parameters. + +**Security:** + +* None. diff --git a/src/pyobjcryst/powderpattern.py b/src/pyobjcryst/powderpattern.py index f930482..2803693 100644 --- a/src/pyobjcryst/powderpattern.py +++ b/src/pyobjcryst/powderpattern.py @@ -425,8 +425,8 @@ def quick_fit_profile( if zero: lsq.SetParIsFixed("Zero", False) if displ_transl: - lsq.SetParIsFixed("2ThetaDispl", True) - lsq.SetParIsFixed("2ThetaTransp", True) + lsq.SetParIsFixed("2ThetaDispl", False) + lsq.SetParIsFixed("2ThetaTransp", False) if lsqr.GetNbParNotFixed(): lsq.SafeRefine(nbCycle=10, useLevenbergMarquardt=True, silent=True) pdiff.ExtractLeBail(10) diff --git a/tests/test_powderpattern.py b/tests/test_powderpattern.py index 7acb666..5efb1f6 100644 --- a/tests/test_powderpattern.py +++ b/tests/test_powderpattern.py @@ -15,6 +15,7 @@ """Unit tests for pyobjcryst.powderpattern (with indexing &""" import unittest +from unittest.mock import MagicMock, patch import numpy as np import pytest @@ -185,6 +186,44 @@ def test_quick_fit(self): p.SetMaxSinThetaOvLambda(0.3) p.quick_fit_profile(auto_background=True, verbose=False, plot=False) + def test_quick_fit_profile_displ_transl_unfixes_refinement_parameters( + self, + ): + fake_powder_pattern = MagicMock() + fake_diffraction = MagicMock() + fake_lsqr = MagicMock() + fake_lsqr.GetNbParNotFixed.return_value = 0 + fake_lsq = MagicMock() + fake_lsq.GetCompiledRefinedObj.return_value = fake_lsqr + + with patch("pyobjcryst.powderpattern.LSQ", return_value=fake_lsq): + PowderPattern.quick_fit_profile( + fake_powder_pattern, + pdiff=fake_diffraction, + auto_background=False, + init_profile=False, + plot=False, + zero=False, + constant_width=False, + width=False, + eta=False, + cell=False, + asym=False, + backgd=False, + displ_transl=True, + verbose=False, + ) + + displ_transl_calls = [ + call.args + for call in fake_lsq.SetParIsFixed.call_args_list + if call.args[0] in ("2ThetaDispl", "2ThetaTransp") + ] + self.assertEqual( + displ_transl_calls, + [("2ThetaDispl", False), ("2ThetaTransp", False)], + ) + def test_peaklist_index(self): c = self.loadcifdata("paracetamol.cif") p = PowderPattern()