Skip to content

Commit

Permalink
add tests and fix pathfinderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
bjkreitz authored and rwest committed Nov 13, 2024
1 parent 6e4353c commit 3ae851e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 4 deletions.
20 changes: 20 additions & 0 deletions test/rmgpy/molecule/moleculeTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,26 @@ def test_surface_molecules(self):
assert adsorbed.number_of_surface_sites() == 1
assert bidentate.number_of_surface_sites() == 2

def test_is_multidentate(self):
"""
Test that we can identify a multidentate adsorbate
"""
monodentate = Molecule().from_adjacency_list(
"""
1 H u0 p0 c0 {2,S}
2 X u0 p0 c0 {1,S}
"""
)
adjlist = """
1 X u0 p0 c0 {3,S}
2 X u0 p0 c0 {4,S}
3 C u0 p0 c0 {1,S} {4,T}
4 C u0 p0 c0 {2,S} {3,T}
"""
bidentate = Molecule().from_adjacency_list(adjlist)
assert not monodentate.is_multidentate()
assert bidentate.is_multidentate()

def test_malformed_augmented_inchi(self):
"""Test that augmented inchi without InChI layer raises Exception."""
malform_aug_inchi = "foo"
Expand Down
48 changes: 44 additions & 4 deletions test/rmgpy/molecule/pathfinderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
find_lone_pair_multiple_bond_paths,
find_N5dc_radical_delocalization_paths,
find_shortest_path,
find_adsorbate_delocalization_paths,
find_adsorbate_conjugate_delocalization_paths,
)


Expand Down Expand Up @@ -458,7 +460,7 @@ def test_h2nnoo(self):
assert paths


class FindAdjLonePairRadicalDelocalizationPaths:
class FindAdjLonePairRadicalDelocalizationPathsTest:
"""
test the find_lone_pair_radical_delocalization_paths method
"""
Expand Down Expand Up @@ -490,7 +492,7 @@ def test_double_bond(self):
assert paths


class FindAdjLonePairMultipleBondDelocalizationPaths:
class FindAdjLonePairMultipleBondDelocalizationPathsTest:
"""
test the find_lone_pair_multiple_bond_delocalization_paths method
"""
Expand All @@ -502,7 +504,7 @@ def test_sho3(self):
assert paths


class FindAdjLonePairRadicalMultipleBondDelocalizationPaths:
class FindAdjLonePairRadicalMultipleBondDelocalizationPathsTest:
"""
test the find_lone_pair_radical_multiple_bond_delocalization_paths method
"""
Expand All @@ -520,7 +522,7 @@ def test_hso3(self):
assert paths


class FindN5dcRadicalDelocalizationPaths:
class FindN5dcRadicalDelocalizationPathsTest:
"""
test the find_N5dc_radical_delocalization_paths method
"""
Expand All @@ -530,3 +532,41 @@ def test_hnnoo(self):
mol = Molecule().from_smiles(smiles)
paths = find_N5dc_radical_delocalization_paths(mol.atoms[1])
assert paths

class FindAdsorbateDelocalizationPathsTest:
"""
test the find_adsorbate_delocalization_paths method
"""

def test_cch(self):
adjlist = """
1 X u0 p0 c0 {3,D}
2 X u0 p0 c0 {4,S}
3 C u0 p0 c0 {1,D} {4,D}
4 C u0 p0 c0 {2,S} {3,D} {5,S}
5 H u0 p0 c0 {4,S}
"""

mol = Molecule().from_adjacency_list(adjlist)
paths = find_adsorbate_delocalization_paths(mol.atoms[0])
assert paths

class FindAdsorbateConjugateDelocalizationPathsTest:
"""
test the find_adsorbate_conjugate_delocalization_paths
"""

def test_chchc(self):
adjlist = """
1 X u0 p0 c0 {3,T}
2 X u0 p0 c0 {5,S}
3 C u0 p0 c0 {1,T} {4,S}
4 C u0 p0 c0 {3,S} {5,D} {6,S}
5 C u0 p0 c0 {2,S} {4,D} {7,S}
6 H u0 p0 c0 {4,S}
7 H u0 p0 c0 {5,S}
"""

mol = Molecule().from_adjacency_list(adjlist)
paths = find_adsorbate_conjugate_delocalization_paths(mol.atoms[0])
assert paths
58 changes: 58 additions & 0 deletions test/rmgpy/molecule/resonanceTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,64 @@ def test_resonance_without_changing_atom_order2(self):
atom2_nb = {nb.id for nb in list(atom2.bonds.keys())}
assert atom1_nb == atom2_nb

def test_adsorbate_resonance_cc1(self):
"""Test if all three resonance structures for X#CC#X are generated"""
adjlist = """
1 X u0 p0 c0 {3,T}
2 X u0 p0 c0 {4,T}
3 C u0 p0 c0 {1,T} {4,S}
4 C u0 p0 c0 {2,T} {3,S}
"""

mol = Molecule().from_adjacency_list(adjlist)

mol_list = generate_resonance_structures(mol)
assert len(mol_list) == 3

def test_adsorbate_resonance_cc2(self):
"""Test if all three resonance structures for X=C=C=X are generated"""
adjlist = """
1 X u0 p0 c0 {3,D}
2 X u0 p0 c0 {4,D}
3 C u0 p0 c0 {1,D} {4,D}
4 C u0 p0 c0 {2,D} {3,D}
"""

mol = Molecule().from_adjacency_list(adjlist)

mol_list = generate_resonance_structures(mol)
assert len(mol_list) == 3

def test_adsorbate_resonance_cc3(self):
"""Test if all three resonance structures for XC#CX are generated"""
adjlist = """
1 X u0 p0 c0 {3,S}
2 X u0 p0 c0 {4,S}
3 C u0 p0 c0 {1,S} {4,T}
4 C u0 p0 c0 {2,S} {3,T}
"""

mol = Molecule().from_adjacency_list(adjlist)

mol_list = generate_resonance_structures(mol)
assert len(mol_list) == 3

def test_adsorbate_resonance_chchc(self):
"""Test if both resonance structures for XCHCHXC are generated"""
adjlist = """
1 X u0 p0 c0 {3,T}
2 X u0 p0 c0 {5,S}
3 C u0 p0 c0 {1,T} {4,S}
4 C u0 p0 c0 {3,S} {5,D} {6,S}
5 C u0 p0 c0 {2,S} {4,D} {7,S}
6 H u0 p0 c0 {4,S}
7 H u0 p0 c0 {5,S}
"""

mol = Molecule().from_adjacency_list(adjlist)

mol_list = generate_resonance_structures(mol)
assert len(mol_list) == 2

class ClarTest:
"""
Expand Down

0 comments on commit 3ae851e

Please sign in to comment.