Skip to content

Commit af80472

Browse files
authored
Update exclude morphs option (#246)
* Update exclude * News
1 parent 9794099 commit af80472

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-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

news/exclude.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* Exclude option in morphpy now takes in a list of morphs to exclude rather than excluding a single morph.
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

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)