From 941a8a7e95be8e735a79566cd127775efdf5b840 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Thu, 17 Jul 2025 11:00:43 -0500 Subject: [PATCH 1/2] Update exclude --- docs/source/morphpy.rst | 5 +++-- src/diffpy/morph/morphpy.py | 9 ++++++-- tests/test_morphpy.py | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/docs/source/morphpy.rst b/docs/source/morphpy.rst index 34050fd..8031b3b 100644 --- a/docs/source/morphpy.rst +++ b/docs/source/morphpy.rst @@ -102,8 +102,9 @@ excluded with the apply or exclude parameters. apply: bool Apply morphs but do not refine. -exclude: str - Exclude a manipulation from refinement by name. +exclude: list of str + Exclude a manipulations from refinement by name + (e.g. exclude=["scale", "stretch"] excludes the scale and stretch morphs). scale: float Apply scale factor. This multiplies the function ordinate by scale. stretch: float diff --git a/src/diffpy/morph/morphpy.py b/src/diffpy/morph/morphpy.py index 80e792f..f623815 100644 --- a/src/diffpy/morph/morphpy.py +++ b/src/diffpy/morph/morphpy.py @@ -13,8 +13,13 @@ def get_args(parser, params, kwargs): inputs.append(f"{value}") for key, value in kwargs.items(): key = key.replace("_", "-") - inputs.append(f"--{key}") - inputs.append(f"{value}") + if key == "exclude": + for param in value: + inputs.append(f"--{key}") + inputs.append(f"{param}") + else: + inputs.append(f"--{key}") + inputs.append(f"{value}") (opts, pargs) = parser.parse_args(inputs) return opts, pargs diff --git a/tests/test_morphpy.py b/tests/test_morphpy.py index 643216e..4308ca8 100644 --- a/tests/test_morphpy.py +++ b/tests/test_morphpy.py @@ -148,6 +148,48 @@ class Chain: morphapp_params[key], abs=1e-08 ) + def test_exclude(self, setup_morph): + morph_file = self.testfiles[0] + target_file = self.testfiles[-1] + morph_info, _ = morph( + morph_file, + target_file, + scale=1, + stretch=0, + exclude=["scale", "stretch"], + sort_by="temperature", + ) + + # Nothing should be refined + assert pytest.approx(morph_info["scale"]) == 1 + assert pytest.approx(morph_info["stretch"]) == 0 + + morph_info, _ = morph( + morph_file, + target_file, + scale=1, + stretch=0, + exclude=["scale"], + sort_by="temperature", + ) + + # Stretch only should be refined + assert pytest.approx(morph_info["scale"]) == 1 + assert pytest.approx(morph_info["stretch"]) != 0 + + morph_info, _ = morph( + morph_file, + target_file, + scale=1, + stretch=0, + exclude=["stretch"], + sort_by="temperature", + ) + + # Scale only should be refined + assert pytest.approx(morph_info["scale"]) != 1 + assert pytest.approx(morph_info["stretch"]) == 0 + def test_morphpy(self, setup_morph): morph_results = {} morph_file = self.testfiles[0] From bee81f8675f7fc7c43e6a296d6599f43ecdb137d Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Thu, 17 Jul 2025 11:29:01 -0500 Subject: [PATCH 2/2] News --- news/exclude.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/exclude.rst diff --git a/news/exclude.rst b/news/exclude.rst new file mode 100644 index 0000000..dd0173b --- /dev/null +++ b/news/exclude.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* Exclude option in morphpy now takes in a list of morphs to exclude rather than excluding a single morph. + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +*