Skip to content

Commit

Permalink
Better drawing of polydentate (n>2) adsorbates.
Browse files Browse the repository at this point in the history
Surface sites are connected to each other in a better order, based
on how close they are in the molecule.
  • Loading branch information
rwest committed Jul 30, 2024
1 parent 70896be commit e10a101
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions rmgpy/molecule/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from rdkit.Chem import AllChem

from rmgpy.molecule.molecule import Atom, Molecule, Bond
from rmgpy.molecule.pathfinder import find_shortest_path
from rmgpy.qm.molecule import Geometry


Expand Down Expand Up @@ -1634,18 +1635,15 @@ def _connect_surface_sites(self):
"""
for atom1 in self.molecule.atoms:
if atom1.is_surface_site():
for atom2 in self.molecule.atoms:
if atom2.is_surface_site() and atom1 != atom2:
# if atom2 is already bonded to a surface site, don't also bond it to atom1
for atom3 in atom2.bonds:
if atom3.is_surface_site():
break
else: # didn't break
bond = atom1.bonds.get(atom2)
if bond is None:
bond = Bond(atom1, atom2, 1)
atom1.bonds[atom2] = bond
atom2.bonds[atom1] = bond
other_sites = [a for a in self.molecule.atoms if a.is_surface_site() and a != atom1]
if not other_sites: break
nearest_sites = sorted(other_sites, key=lambda a: len(find_shortest_path(atom1, a)))
atom2 = nearest_sites[0]
bond = atom1.bonds.get(atom2)
if bond is None:
bond = Bond(atom1, atom2, 1)
atom1.bonds[atom2] = bond
atom2.bonds[atom1] = bond

def _disconnect_surface_sites(self):
"""
Expand Down

0 comments on commit e10a101

Please sign in to comment.