Skip to content

Commit 941a8a7

Browse files
committed
Update exclude
1 parent 9794099 commit 941a8a7

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

docs/source/morphpy.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ excluded with the apply or exclude parameters.
102102

103103
apply: bool
104104
Apply morphs but do not refine.
105-
exclude: str
106-
Exclude a manipulation from refinement by name.
105+
exclude: list of str
106+
Exclude a manipulations from refinement by name
107+
(e.g. exclude=["scale", "stretch"] excludes the scale and stretch morphs).
107108
scale: float
108109
Apply scale factor. This multiplies the function ordinate by scale.
109110
stretch: float

src/diffpy/morph/morphpy.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ def get_args(parser, params, kwargs):
1313
inputs.append(f"{value}")
1414
for key, value in kwargs.items():
1515
key = key.replace("_", "-")
16-
inputs.append(f"--{key}")
17-
inputs.append(f"{value}")
16+
if key == "exclude":
17+
for param in value:
18+
inputs.append(f"--{key}")
19+
inputs.append(f"{param}")
20+
else:
21+
inputs.append(f"--{key}")
22+
inputs.append(f"{value}")
1823
(opts, pargs) = parser.parse_args(inputs)
1924
return opts, pargs
2025

tests/test_morphpy.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,48 @@ class Chain:
148148
morphapp_params[key], abs=1e-08
149149
)
150150

151+
def test_exclude(self, setup_morph):
152+
morph_file = self.testfiles[0]
153+
target_file = self.testfiles[-1]
154+
morph_info, _ = morph(
155+
morph_file,
156+
target_file,
157+
scale=1,
158+
stretch=0,
159+
exclude=["scale", "stretch"],
160+
sort_by="temperature",
161+
)
162+
163+
# Nothing should be refined
164+
assert pytest.approx(morph_info["scale"]) == 1
165+
assert pytest.approx(morph_info["stretch"]) == 0
166+
167+
morph_info, _ = morph(
168+
morph_file,
169+
target_file,
170+
scale=1,
171+
stretch=0,
172+
exclude=["scale"],
173+
sort_by="temperature",
174+
)
175+
176+
# Stretch only should be refined
177+
assert pytest.approx(morph_info["scale"]) == 1
178+
assert pytest.approx(morph_info["stretch"]) != 0
179+
180+
morph_info, _ = morph(
181+
morph_file,
182+
target_file,
183+
scale=1,
184+
stretch=0,
185+
exclude=["stretch"],
186+
sort_by="temperature",
187+
)
188+
189+
# Scale only should be refined
190+
assert pytest.approx(morph_info["scale"]) != 1
191+
assert pytest.approx(morph_info["stretch"]) == 0
192+
151193
def test_morphpy(self, setup_morph):
152194
morph_results = {}
153195
morph_file = self.testfiles[0]

0 commit comments

Comments
 (0)