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/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:** + +* 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]