Skip to content

Commit e165591

Browse files
committed
add tests and fix pathfinderTest
1 parent 89d134a commit e165591

File tree

3 files changed

+122
-4
lines changed

3 files changed

+122
-4
lines changed

test/rmgpy/molecule/moleculeTest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,26 @@ def test_surface_molecules(self):
21392139
assert adsorbed.number_of_surface_sites() == 1
21402140
assert bidentate.number_of_surface_sites() == 2
21412141

2142+
def test_is_multidentate(self):
2143+
"""
2144+
Test that we can identify a multidentate adsorbate
2145+
"""
2146+
monodentate = Molecule().from_adjacency_list(
2147+
"""
2148+
1 H u0 p0 c0 {2,S}
2149+
2 X u0 p0 c0 {1,S}
2150+
"""
2151+
)
2152+
adjlist = """
2153+
1 X u0 p0 c0 {3,S}
2154+
2 X u0 p0 c0 {4,S}
2155+
3 C u0 p0 c0 {1,S} {4,T}
2156+
4 C u0 p0 c0 {2,S} {3,T}
2157+
"""
2158+
bidentate = Molecule().from_adjacency_list(adjlist)
2159+
assert not monodentate.is_multidentate()
2160+
assert bidentate.is_multidentate()
2161+
21422162
def test_malformed_augmented_inchi(self):
21432163
"""Test that augmented inchi without InChI layer raises Exception."""
21442164
malform_aug_inchi = "foo"

test/rmgpy/molecule/pathfinderTest.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
find_lone_pair_multiple_bond_paths,
4242
find_N5dc_radical_delocalization_paths,
4343
find_shortest_path,
44+
find_adsorbate_delocalization_paths,
45+
find_adsorbate_conjugate_delocalization_paths,
4446
)
4547

4648

@@ -458,7 +460,7 @@ def test_h2nnoo(self):
458460
assert paths
459461

460462

461-
class FindAdjLonePairRadicalDelocalizationPaths:
463+
class FindAdjLonePairRadicalDelocalizationPathsTest:
462464
"""
463465
test the find_lone_pair_radical_delocalization_paths method
464466
"""
@@ -490,7 +492,7 @@ def test_double_bond(self):
490492
assert paths
491493

492494

493-
class FindAdjLonePairMultipleBondDelocalizationPaths:
495+
class FindAdjLonePairMultipleBondDelocalizationPathsTest:
494496
"""
495497
test the find_lone_pair_multiple_bond_delocalization_paths method
496498
"""
@@ -502,7 +504,7 @@ def test_sho3(self):
502504
assert paths
503505

504506

505-
class FindAdjLonePairRadicalMultipleBondDelocalizationPaths:
507+
class FindAdjLonePairRadicalMultipleBondDelocalizationPathsTest:
506508
"""
507509
test the find_lone_pair_radical_multiple_bond_delocalization_paths method
508510
"""
@@ -520,7 +522,7 @@ def test_hso3(self):
520522
assert paths
521523

522524

523-
class FindN5dcRadicalDelocalizationPaths:
525+
class FindN5dcRadicalDelocalizationPathsTest:
524526
"""
525527
test the find_N5dc_radical_delocalization_paths method
526528
"""
@@ -530,3 +532,41 @@ def test_hnnoo(self):
530532
mol = Molecule().from_smiles(smiles)
531533
paths = find_N5dc_radical_delocalization_paths(mol.atoms[1])
532534
assert paths
535+
536+
class FindAdsorbateDelocalizationPathsTest:
537+
"""
538+
test the find_adsorbate_delocalization_paths method
539+
"""
540+
541+
def test_cch(self):
542+
adjlist = """
543+
1 X u0 p0 c0 {3,D}
544+
2 X u0 p0 c0 {4,S}
545+
3 C u0 p0 c0 {1,D} {4,D}
546+
4 C u0 p0 c0 {2,S} {3,D} {5,S}
547+
5 H u0 p0 c0 {4,S}
548+
"""
549+
550+
mol = Molecule().from_adjacency_list(adjlist)
551+
paths = find_adsorbate_delocalization_paths(mol.atoms[0])
552+
assert paths
553+
554+
class FindAdsorbateConjugateDelocalizationPathsTest:
555+
"""
556+
test the find_adsorbate_conjugate_delocalization_paths
557+
"""
558+
559+
def test_chchc(self):
560+
adjlist = """
561+
1 X u0 p0 c0 {3,T}
562+
2 X u0 p0 c0 {5,S}
563+
3 C u0 p0 c0 {1,T} {4,S}
564+
4 C u0 p0 c0 {3,S} {5,D} {6,S}
565+
5 C u0 p0 c0 {2,S} {4,D} {7,S}
566+
6 H u0 p0 c0 {4,S}
567+
7 H u0 p0 c0 {5,S}
568+
"""
569+
570+
mol = Molecule().from_adjacency_list(adjlist)
571+
paths = find_adsorbate_conjugate_delocalization_paths(mol.atoms[0])
572+
assert paths

test/rmgpy/molecule/resonanceTest.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,64 @@ def test_resonance_without_changing_atom_order2(self):
13631363
atom2_nb = {nb.id for nb in list(atom2.bonds.keys())}
13641364
assert atom1_nb == atom2_nb
13651365

1366+
def test_adsorbate_resonance_cc1(self):
1367+
"""Test if all three resonance structures for X#CC#X are generated"""
1368+
adjlist = """
1369+
1 X u0 p0 c0 {3,T}
1370+
2 X u0 p0 c0 {4,T}
1371+
3 C u0 p0 c0 {1,T} {4,S}
1372+
4 C u0 p0 c0 {2,T} {3,S}
1373+
"""
1374+
1375+
mol = Molecule().from_adjacency_list(adjlist)
1376+
1377+
mol_list = generate_resonance_structures(mol)
1378+
assert len(mol_list) == 3
1379+
1380+
def test_adsorbate_resonance_cc2(self):
1381+
"""Test if all three resonance structures for X=C=C=X are generated"""
1382+
adjlist = """
1383+
1 X u0 p0 c0 {3,D}
1384+
2 X u0 p0 c0 {4,D}
1385+
3 C u0 p0 c0 {1,D} {4,D}
1386+
4 C u0 p0 c0 {2,D} {3,D}
1387+
"""
1388+
1389+
mol = Molecule().from_adjacency_list(adjlist)
1390+
1391+
mol_list = generate_resonance_structures(mol)
1392+
assert len(mol_list) == 3
1393+
1394+
def test_adsorbate_resonance_cc3(self):
1395+
"""Test if all three resonance structures for XC#CX are generated"""
1396+
adjlist = """
1397+
1 X u0 p0 c0 {3,S}
1398+
2 X u0 p0 c0 {4,S}
1399+
3 C u0 p0 c0 {1,S} {4,T}
1400+
4 C u0 p0 c0 {2,S} {3,T}
1401+
"""
1402+
1403+
mol = Molecule().from_adjacency_list(adjlist)
1404+
1405+
mol_list = generate_resonance_structures(mol)
1406+
assert len(mol_list) == 3
1407+
1408+
def test_adsorbate_resonance_chchc(self):
1409+
"""Test if both resonance structures for XCHCHXC are generated"""
1410+
adjlist = """
1411+
1 X u0 p0 c0 {3,T}
1412+
2 X u0 p0 c0 {5,S}
1413+
3 C u0 p0 c0 {1,T} {4,S}
1414+
4 C u0 p0 c0 {3,S} {5,D} {6,S}
1415+
5 C u0 p0 c0 {2,S} {4,D} {7,S}
1416+
6 H u0 p0 c0 {4,S}
1417+
7 H u0 p0 c0 {5,S}
1418+
"""
1419+
1420+
mol = Molecule().from_adjacency_list(adjlist)
1421+
1422+
mol_list = generate_resonance_structures(mol)
1423+
assert len(mol_list) == 2
13661424

13671425
class ClarTest:
13681426
"""

0 commit comments

Comments
 (0)