Skip to content

Commit

Permalink
Tests: fix_mol_electronic_configuration()
Browse files Browse the repository at this point in the history
and get_atom_theoretical_charge()
  • Loading branch information
alongd committed Oct 2, 2023
1 parent 793fdec commit a841d2c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions arc/species/species_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,38 @@ def test_split_mol(self):
self.assertEqual(m.to_smiles(), 'O')
self.assertEqual(fragments, [[0, 3, 4], [1, 5, 6], [2, 7, 8]])

def test_get_atom_theoretical_charge(self):
"""Test getting the theoretical charge of an atom."""
mol = Molecule(smiles='[O-][S+]([O-])=[OH+]')
charges = [get_atom_theoretical_charge(atom) for atom in mol.atoms]
self.assertEqual(sorted(charges), [-1.0, -1.0, 0.0, 1.0, 1.0])

def test_fix_mol_electronic_configuration(self):
"""Test fixing the electronic configuration of a molecule."""
adjlist = """multiplicity 1
1 O u1 p2 c0 {3,S}
2 O u1 p2 c0 {3,S}
3 N u0 p1 c0 {1,S} {2,S} {4,S}
4 C u0 p0 c0 {3,S} {5,S} {6,S} {7,S}
5 C u0 p0 c0 {4,S} {8,S} {9,S} {10,S}
6 H u0 p0 c0 {4,S}
7 H u0 p0 c0 {4,S}
8 H u0 p0 c0 {5,S}
9 H u0 p0 c0 {5,S}
10 H u0 p0 c0 {5,S}"""
mol_1 = Molecule().from_adjacency_list(adjlist)
self.assertEqual(mol_1.multiplicity, 1)
self.assertNotIn('[N+]', mol_1.to_smiles())
self.assertNotIn('[O-]', mol_1.to_smiles())
charges = [get_atom_theoretical_charge(atom) for atom in mol_1.atoms]
self.assertEqual(list(set((charges))), [0.0])
mol_2 = fix_mol_electronic_configuration(mol_1)
self.assertEqual(mol_2.multiplicity, 1)
self.assertIn('[N+]', mol_2.to_smiles())
self.assertIn('[O-]', mol_2.to_smiles())
charges = [get_atom_theoretical_charge(atom) for atom in mol_2.atoms]
self.assertEqual(sorted(charges), [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0])

@classmethod
def tearDownClass(cls):
"""
Expand Down

0 comments on commit a841d2c

Please sign in to comment.