Skip to content

Commit

Permalink
Merge pull request #2734 to Draw Hydrogen bonds (again)
Browse files Browse the repository at this point in the history
Pull request  #1961  introduced the ability to draw hydrogen bonds.

To do so, Hydrogen atoms that have H bonds shouldn't be removed from the drawings.
This check was  removed without explanation in ec95153
which was designed to make drawing work for fragments.
That broke drawing of hydrogen bonds. This pull request fixes it, and also removes some code duplication.
  • Loading branch information
rwest authored Nov 21, 2024
2 parents b30535b + 6f5c1c8 commit 5397e7f
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions rmgpy/molecule/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def draw(self, molecule, file_format, target=None):
surface_sites = []
for atom in self.molecule.atoms:
if isinstance(atom, Atom) and atom.is_hydrogen() and atom.label == '':
atoms_to_remove.append(atom)
if not any(bond.is_hydrogen_bond() for bond in atom.bonds.values()):
atoms_to_remove.append(atom)
elif atom.is_surface_site():
surface_sites.append(atom)
if len(atoms_to_remove) < len(self.molecule.atoms) - len(surface_sites):
Expand Down Expand Up @@ -417,17 +418,6 @@ def _generate_coordinates(self, fix_surface_sites=True):
coordinates[i1, 1] -= 0.2
coordinates[i2, 1] += 0.2

# If two atoms lie on top of each other, push them apart a bit
# This is ugly, but at least the mess you end up with isn't as misleading
# as leaving everything piled on top of each other at the origin
for atom1, atom2 in itertools.combinations(backbone, 2):
i1, i2 = atoms.index(atom1), atoms.index(atom2)
if np.linalg.norm(coordinates[i1, :] - coordinates[i2, :]) < 0.5:
coordinates[i1, 0] -= 0.3
coordinates[i2, 0] += 0.3
coordinates[i1, 1] -= 0.2
coordinates[i2, 1] += 0.2

# Center backbone at origin
xmin = np.min(coordinates[:, 0])
xmax = np.max(coordinates[:, 0])
Expand Down

0 comments on commit 5397e7f

Please sign in to comment.