Skip to content

Commit 92aa1d9

Browse files
committed
A (failing) isomorphism test.
The problem this identifies is that if you give it two different molecules but the only difference is in a set of atoms that you have already passed in as a map (eg. because of their labels) then they are thought to be isomorphic. I.e the initial mapping you pass is not checked.
1 parent cc9bb3b commit 92aa1d9

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

rmgpy/molecule/isomorphismTest.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,49 @@ def test_isotope_subgraph_isomorphism_molecule_and_group():
485485
assert_true(methanei.is_subgraph_isomorphic(group_methane))
486486
assert_true(methane.is_subgraph_isomorphic(group_methane))
487487
assert_false(methanei.is_isomorphic(methane))
488+
489+
def test_isomorphism_wrong_mapping():
490+
"""
491+
Checks isomorphism finds things not isomorphic if given a wrong mapping.
492+
"""
493+
# These molecules are not isomorphic
494+
n1butane = Molecule().from_adjacency_list("""
495+
1 *1 X u0 p0 c0 {2,S}
496+
2 *2 C u0 p0 c0 {1,S} {3,S} {5,S} {6,S}
497+
3 *3 C u0 p0 c0 {2,S} {4,S} {7,S} {8,S}
498+
4 *4 H u0 p0 c0 {3,S}
499+
5 H u0 p0 c0 {2,S}
500+
6 H u0 p0 c0 {2,S}
501+
7 H u0 p0 c0 {3,S}
502+
8 C u0 p0 c0 {3,S} {9,S} {10,S} {11,S}
503+
9 H u0 p0 c0 {8,S}
504+
10 H u0 p0 c0 {8,S}
505+
11 C u0 p0 c0 {8,S} {12,S} {13,S} {14,S}
506+
12 H u0 p0 c0 {11,S}
507+
13 H u0 p0 c0 {11,S}
508+
14 H u0 p0 c0 {11,S}
509+
""")
510+
511+
n2butane = Molecule().from_adjacency_list("""
512+
1 *1 X u0 p0 c0 {3,S}
513+
2 *2 C u0 p0 c0 {3,S} {5,S} {6,S} {4,S}
514+
3 *3 C u0 p0 c0 {2,S} {1,S} {7,S} {8,S}
515+
4 *4 H u0 p0 c0 {2,S}
516+
5 H u0 p0 c0 {2,S}
517+
6 H u0 p0 c0 {2,S}
518+
7 H u0 p0 c0 {3,S}
519+
8 C u0 p0 c0 {3,S} {9,S} {10,S} {11,S}
520+
9 H u0 p0 c0 {8,S}
521+
10 H u0 p0 c0 {8,S}
522+
11 C u0 p0 c0 {8,S} {12,S} {13,S} {14,S}
523+
12 H u0 p0 c0 {11,S}
524+
13 H u0 p0 c0 {11,S}
525+
14 H u0 p0 c0 {11,S}
526+
""")
527+
assert_false(n1butane.is_isomorphic(n2butane))
528+
assert_false(n1butane.is_isomorphic(n2butane, generate_initial_map=True))
529+
530+
mapping = {}
531+
for label in ['*1', '*2', '*3', '*4']:
532+
mapping[n1butane.get_labeled_atoms(label)[0]] = n2butane.get_labeled_atoms(label)[0]
533+
assert_false(n1butane.is_isomorphic(n2butane, initial_map=mapping))

0 commit comments

Comments
 (0)