Skip to content

Commit 5cb38b1

Browse files
committed
Ensure directories are ignored when using multiple morphs/targets
1 parent 4914488 commit 5cb38b1

21 files changed

+50
-14
lines changed

news/bugfix.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* Swap colors for morph and target. Morph is now blue and target red.
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* Multiple morphs/targets used to break given multiple subdirectories.
20+
* Fixed the Rw calculation. Previously returned an analogue to chi square.
21+
22+
**Security:**
23+
24+
* <news item>

src/diffpy/morph/morphapp.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,14 @@ def single_morph(parser, opts, pargs, stdout_flag=True):
588588
parser.custom_error(save_fail_message)
589589

590590
if opts.plot:
591-
pairlist = [chain.xy_morph_out, chain.xy_target_out]
592-
labels = [pargs[0], pargs[1]] # Default is to use file names
591+
pairlist = [chain.xy_target_out, chain.xy_morph_out]
592+
labels = [pargs[1], pargs[0]] # Default is to use file names
593593

594594
# If user chooses labels
595595
if opts.mlabel is not None:
596-
labels[0] = opts.mlabel
596+
labels[1] = opts.mlabel
597597
if opts.tlabel is not None:
598-
labels[1] = opts.tlabel
598+
labels[0] = opts.tlabel
599599

600600
# Plot extent defaults to calculation extent
601601
pmin = opts.pmin if opts.pmin is not None else opts.rmin
@@ -644,9 +644,12 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True):
644644

645645
# Get list of files from target directory
646646
target_list = list(target_directory.iterdir())
647+
to_remove = []
647648
for target in target_list:
648649
if target.is_dir():
649-
target_list.remove(target)
650+
to_remove.append(target)
651+
for target in to_remove:
652+
target_list.remove(target)
650653

651654
# Do not morph morph_file against itself if it is in the same directory
652655
if morph_file in target_list:
@@ -828,9 +831,12 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True):
828831

829832
# Get list of files from morph directory
830833
morph_list = list(morph_directory.iterdir())
834+
to_remove = []
831835
for morph in morph_list:
832836
if morph.is_dir():
833-
morph_list.remove(morph)
837+
to_remove.append(morph)
838+
for morph in to_remove:
839+
morph_list.remove(morph)
834840

835841
# Do not morph target_file against itself if it is in the same directory
836842
if target_file in morph_list:

tests/test_morphapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
nickel_PDF = testdata_dir.joinpath("nickel_ss0.01.cgr")
1919
serial_JSON = testdata_dir.joinpath("testsequence_serialfile.json")
2020

21-
testsaving_dir = testdata_dir.joinpath("testsaving")
21+
testsaving_dir = testsequence_dir.joinpath("testsaving")
2222
test_saving_succinct = testsaving_dir.joinpath("succinct")
2323
test_saving_verbose = testsaving_dir.joinpath("verbose")
2424
tssf = testdata_dir.joinpath("testsequence_serialfile.json")

tests/test_morphio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
testdata_dir = tests_dir.joinpath("testdata")
2222
testsequence_dir = testdata_dir.joinpath("testsequence")
2323

24-
testsaving_dir = testdata_dir.joinpath("testsaving")
24+
testsaving_dir = testsequence_dir.joinpath("testsaving")
2525
test_saving_succinct = testsaving_dir.joinpath("succinct")
2626
test_saving_verbose = testsaving_dir.joinpath("verbose")
2727
tssf = testdata_dir.joinpath("testsequence_serialfile.json")

tests/test_tools.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ def test_nn_value(self, setup):
6060
pytest.approx(tools.nn_value(-value, name=None), abs(-value))
6161

6262
def test_field_sort(self, setup):
63-
sequence_files = [*os.listdir(testsequence_dir)]
63+
sequence_files = [file for file in Path(testsequence_dir).iterdir()]
64+
to_remove = []
65+
for file in sequence_files:
66+
if file.is_dir():
67+
to_remove.append(file)
68+
for d in to_remove:
69+
sequence_files.remove(d)
6470
absolute_sf = []
6571
for file in sequence_files:
66-
absolute_sf.append(os.path.join(testsequence_dir, file))
72+
absolute_sf.append(Path(testsequence_dir) / file.name)
6773

6874
# Fisher-Yates randomization
6975
import random
@@ -87,8 +93,8 @@ def test_field_sort(self, setup):
8793

8894
# Temperature sort should produce same result as alphanumerical if
8995
# leading character is removed
90-
sequence_files.sort(key=lambda entry: entry[2:])
91-
assert sequence_files == sorted_sequence
96+
sequence_files.sort(key=lambda entry: entry.name[2:])
97+
assert [file.name for file in sequence_files] == sorted_sequence
9298

9399
# Check temperatures are correct
94100
assert fvs == [174, 180, 186, 192, 198, 204, 210]
@@ -103,7 +109,7 @@ def test_field_sort(self, setup):
103109

104110
# Reversed sort should match alphanumerical sort
105111
sequence_files.sort()
106-
assert sequence_files == reversed_sequence
112+
assert [file.name for file in sequence_files] == reversed_sequence
107113

108114
# Check we get the same sequence when we load header information from
109115
# a serial file
@@ -116,7 +122,7 @@ def test_field_sort(self, setup):
116122
metadata_sequence = []
117123
for path in metadata_path_sequence:
118124
metadata_sequence.append(path.name)
119-
assert sequence_files == metadata_sequence
125+
assert [file.name for file in sequence_files] == metadata_sequence
120126

121127
# Check error thrown when field does not exist
122128
with pytest.raises(KeyError):

0 commit comments

Comments
 (0)