Skip to content

Commit

Permalink
Don't add radicals or lone pairs to surface sites.
Browse files Browse the repository at this point in the history
This may hide bugs, or it may be exactly the right
thing to do. I'm not entirely sure.
But it currently seems like a good idea.

The presumption is:
surface sites of metals should not have unpaired
or pairs of electrons - they just have a big sea
of delocalized electrons at their disposal.

See ReactionMechanismGenerator#1820
  • Loading branch information
rwest committed Mar 9, 2020
1 parent 657ecb2 commit 16094f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions rmgpy/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ def increment_radical(self):
where `radical` specifies the number of radical electrons to add.
"""
# Set the new radical electron count
if self.is_surface_site(): return # do nothing
self.radical_electrons += 1
if self.radical_electrons <= 0:
raise gr.ActionError('Unable to update Atom due to GAIN_RADICAL action: '
Expand All @@ -421,6 +422,7 @@ def decrement_radical(self):
where `radical` specifies the number of radical electrons to remove.
"""
cython.declare(radical_electrons=cython.short)
if self.is_surface_site(): return # do nothing
# Set the new radical electron count
radical_electrons = self.radical_electrons = self.radical_electrons - 1
if radical_electrons < 0:
Expand All @@ -443,6 +445,7 @@ def increment_lone_pairs(self):
Update the lone electron pairs pattern as a result of applying a GAIN_PAIR action.
"""
# Set the new lone electron pairs count
if self.is_surface_site(): return # do nothing
self.lone_pairs += 1
if self.lone_pairs <= 0:
raise gr.ActionError('Unable to update Atom due to GAIN_PAIR action: '
Expand All @@ -453,6 +456,7 @@ def decrement_lone_pairs(self):
"""
Update the lone electron pairs pattern as a result of applying a LOSE_PAIR action.
"""
if self.is_surface_site(): return # do nothing
# Set the new lone electron pairs count
self.lone_pairs -= 1
if self.lone_pairs < 0:
Expand Down
10 changes: 8 additions & 2 deletions rmgpy/molecule/moleculeTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ def test_apply_action_gain_radical(self):
atom = atom0.copy()
atom.apply_action(action)
self.assertEqual(atom0.element, atom.element)
self.assertEqual(atom0.radical_electrons, atom.radical_electrons - 1)
if element.symbol == 'X':
self.assertEqual(atom0.radical_electrons, atom.radical_electrons)
else:
self.assertEqual(atom0.radical_electrons, atom.radical_electrons - 1)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)

Expand All @@ -326,7 +329,10 @@ def test_apply_action_lose_radical(self):
atom = atom0.copy()
atom.apply_action(action)
self.assertEqual(atom0.element, atom.element)
self.assertEqual(atom0.radical_electrons, atom.radical_electrons + 1)
if element.symbol == 'X':
self.assertEqual(atom0.radical_electrons, atom.radical_electrons)
else:
self.assertEqual(atom0.radical_electrons, atom.radical_electrons + 1)
self.assertEqual(atom0.charge, atom.charge)
self.assertEqual(atom0.label, atom.label)

Expand Down

0 comments on commit 16094f9

Please sign in to comment.