Skip to content

Commit a841d2c

Browse files
committed
Tests: fix_mol_electronic_configuration()
and get_atom_theoretical_charge()
1 parent 793fdec commit a841d2c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

arc/species/species_test.py

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

2636+
def test_get_atom_theoretical_charge(self):
2637+
"""Test getting the theoretical charge of an atom."""
2638+
mol = Molecule(smiles='[O-][S+]([O-])=[OH+]')
2639+
charges = [get_atom_theoretical_charge(atom) for atom in mol.atoms]
2640+
self.assertEqual(sorted(charges), [-1.0, -1.0, 0.0, 1.0, 1.0])
2641+
2642+
def test_fix_mol_electronic_configuration(self):
2643+
"""Test fixing the electronic configuration of a molecule."""
2644+
adjlist = """multiplicity 1
2645+
1 O u1 p2 c0 {3,S}
2646+
2 O u1 p2 c0 {3,S}
2647+
3 N u0 p1 c0 {1,S} {2,S} {4,S}
2648+
4 C u0 p0 c0 {3,S} {5,S} {6,S} {7,S}
2649+
5 C u0 p0 c0 {4,S} {8,S} {9,S} {10,S}
2650+
6 H u0 p0 c0 {4,S}
2651+
7 H u0 p0 c0 {4,S}
2652+
8 H u0 p0 c0 {5,S}
2653+
9 H u0 p0 c0 {5,S}
2654+
10 H u0 p0 c0 {5,S}"""
2655+
mol_1 = Molecule().from_adjacency_list(adjlist)
2656+
self.assertEqual(mol_1.multiplicity, 1)
2657+
self.assertNotIn('[N+]', mol_1.to_smiles())
2658+
self.assertNotIn('[O-]', mol_1.to_smiles())
2659+
charges = [get_atom_theoretical_charge(atom) for atom in mol_1.atoms]
2660+
self.assertEqual(list(set((charges))), [0.0])
2661+
mol_2 = fix_mol_electronic_configuration(mol_1)
2662+
self.assertEqual(mol_2.multiplicity, 1)
2663+
self.assertIn('[N+]', mol_2.to_smiles())
2664+
self.assertIn('[O-]', mol_2.to_smiles())
2665+
charges = [get_atom_theoretical_charge(atom) for atom in mol_2.atoms]
2666+
self.assertEqual(sorted(charges), [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0])
2667+
26362668
@classmethod
26372669
def tearDownClass(cls):
26382670
"""

0 commit comments

Comments
 (0)