Skip to content

Commit 7aeadea

Browse files
committed
Tests: fix_mol_electronic_configuration()
and get_atom_theoretical_charge() and add_missing_radicals()
1 parent 296ffdf commit 7aeadea

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

arc/species/species_test.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,58 @@ def test_split_mol(self):
26322632
self.assertEqual(m.to_smiles(), 'O')
26332633
self.assertEqual(fragments, [[0, 3, 4], [1, 5, 6], [2, 7, 8]])
26342634

2635+
def test_get_atom_theoretical_charge(self):
2636+
"""Test getting the theoretical charge of an atom."""
2637+
mol = Molecule(smiles='[O-][S+]([O-])=[OH+]')
2638+
charges = [get_atom_theoretical_charge(atom) for atom in mol.atoms]
2639+
self.assertEqual(sorted(charges), [-1.0, -1.0, 0.0, 1.0, 1.0])
2640+
2641+
def test_add_missing_radicals(self):
2642+
"""Test adding missing radicals to a molecule."""
2643+
adjlist = """1 C u0 p0 c0 {2,S} {6,S} {7,S} {8,S}
2644+
2 C u0 p0 c0 {1,S} {3,S} {9,S} {10,S}
2645+
3 N u0 p1 c0 {2,S} {4,S} {5,S}
2646+
4 O u1 p2 c0 {3,S}
2647+
5 O u1 p2 c0 {3,S}
2648+
6 H u0 p0 c0 {1,S}
2649+
7 H u0 p0 c0 {1,S}
2650+
8 H u0 p0 c0 {1,S}
2651+
9 H u0 p0 c0 {2,S}
2652+
10 H u0 p0 c0 {2,S}"""
2653+
mol = Molecule().from_adjacency_list(adjlist)
2654+
for atom in mol.atoms:
2655+
atom.radical_electrons = 0
2656+
self.assertEqual(mol.get_radical_count(), 0)
2657+
add_missing_radicals(mol)
2658+
self.assertEqual(mol.get_radical_count(), 2)
2659+
2660+
2661+
def test_fix_mol_electronic_configuration(self):
2662+
"""Test fixing the electronic configuration of a molecule."""
2663+
adjlist = """multiplicity 1
2664+
1 O u1 p2 c0 {3,S}
2665+
2 O u1 p2 c0 {3,S}
2666+
3 N u0 p1 c0 {1,S} {2,S} {4,S}
2667+
4 C u0 p0 c0 {3,S} {5,S} {6,S} {7,S}
2668+
5 C u0 p0 c0 {4,S} {8,S} {9,S} {10,S}
2669+
6 H u0 p0 c0 {4,S}
2670+
7 H u0 p0 c0 {4,S}
2671+
8 H u0 p0 c0 {5,S}
2672+
9 H u0 p0 c0 {5,S}
2673+
10 H u0 p0 c0 {5,S}"""
2674+
mol_1 = Molecule().from_adjacency_list(adjlist)
2675+
self.assertEqual(mol_1.multiplicity, 1)
2676+
self.assertNotIn('[N+]', mol_1.to_smiles())
2677+
self.assertNotIn('[O-]', mol_1.to_smiles())
2678+
charges = [get_atom_theoretical_charge(atom) for atom in mol_1.atoms]
2679+
self.assertEqual(list(set((charges))), [0.0])
2680+
mol_2 = fix_mol_electronic_configuration(mol_1)
2681+
self.assertEqual(mol_2.multiplicity, 1)
2682+
self.assertIn('[N+]', mol_2.to_smiles())
2683+
self.assertIn('[O-]', mol_2.to_smiles())
2684+
charges = [get_atom_theoretical_charge(atom) for atom in mol_2.atoms]
2685+
self.assertEqual(sorted(charges), [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0])
2686+
26352687
@classmethod
26362688
def tearDownClass(cls):
26372689
"""

0 commit comments

Comments
 (0)