Skip to content

Commit

Permalink
Added comments explaining the handling of radicals in the kekulization.
Browse files Browse the repository at this point in the history
  • Loading branch information
robpollice committed Dec 31, 2024
1 parent 979f221 commit a264e97
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions selfies/mol_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,17 @@ def _prune_from_ds(self, node):
else:
valence = valences[-1] - atom.charge
used_electrons += atom.h_count

# count the total number of bound electrons of each atom
bound_electrons = (max(0, atom.charge) + atom.h_count
+ int(self._bond_counts[node])
+ int(2 * (self._bond_counts[node] % 1)))

# calculate the number of unpaired electrons of each atom
radical_electrons = (max(0, VALENCE_ELECTRONS[atom.element]
- bound_electrons) % 2)

# unpaired electrons do not contribute to the aromatic system
free_electrons = valence - used_electrons - radical_electrons

if any(used_electrons == v - atom.charge for v in valences):
Expand Down

0 comments on commit a264e97

Please sign in to comment.