From ce72ac97c5d9cf183014a3146f394b53f7ad34f6 Mon Sep 17 00:00:00 2001 From: Richard West Date: Tue, 19 Nov 2024 23:10:04 -0500 Subject: [PATCH 1/2] Don't remove H atoms when drawing Hydrogen bonds This was added in PR #1961 which indroduced the ability to draw hydrogen bonds. It was removed without explanation in ec9515351ea9964a5a8499c1f4066378544eca41 which made drawing work for fragments. That broke drawing of hydrogen bonds. The unit test for drawing hydrogen bonds exists, but just checks that a PDF is made, not what it looks like. So this wasn't detected. --- rmgpy/molecule/draw.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rmgpy/molecule/draw.py b/rmgpy/molecule/draw.py index 3792772af3..b7a66cc861 100644 --- a/rmgpy/molecule/draw.py +++ b/rmgpy/molecule/draw.py @@ -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): From 6f5c1c83ad66b0702d6e8c10dc88ecbaa72909f0 Mon Sep 17 00:00:00 2001 From: Bjarne Kreitz Date: Tue, 19 Nov 2024 14:33:44 -0500 Subject: [PATCH 2/2] Remove code duplicate --- rmgpy/molecule/draw.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/rmgpy/molecule/draw.py b/rmgpy/molecule/draw.py index b7a66cc861..d38c519197 100644 --- a/rmgpy/molecule/draw.py +++ b/rmgpy/molecule/draw.py @@ -418,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])