Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/source/morphpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions news/exclude.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Exclude option in morphpy now takes in a list of morphs to exclude rather than excluding a single morph.

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
9 changes: 7 additions & 2 deletions src/diffpy/morph/morphpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 42 additions & 0 deletions tests/test_morphpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading