Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions rmgpy/data/kinetics/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,11 +1670,17 @@ def is_molecule_forbidden(self, molecule):
return True

# forbid vdw multi-dentate molecules for surface families
surface_sites = []
if "surface" in self.label.lower():
if molecule.get_num_atoms('X') > 1:
for atom in molecule.atoms:
if atom.atomtype.label == 'Xv':
return True
if "surface_monodentate_to_vdw_bidentate" in self.label.lower() and molecule.get_num_atoms('X') > 1:
surface_sites = [atom.atomtype.label for atom in molecule.atoms if 'X' in atom.atomtype.label]
if all(site == 'Xv' for site in surface_sites):
return True
else:
if molecule.get_num_atoms('X') > 1:
for atom in molecule.atoms:
if atom.atomtype.label == 'Xv':
return True
Comment on lines 1674 to +1683
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a behavior switch based on a hard-coded substring match of self.label, which makes the forbidden-structure logic depend on naming conventions rather than an explicit family attribute/configuration. This is fragile (label changes become behavior changes). Prefer exposing an explicit flag/attribute on the family (or configuring this in the family definition/data) to control whether mixed covalent+vdW multidentate surface bindings are allowed.

Copilot uses AI. Check for mistakes.

return False

Expand Down
2 changes: 1 addition & 1 deletion rmgpy/molecule/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def to_rdkit_mol(mol, remove_h=True, return_mapping=False, sanitize=True, save_o
label_dict[label] = [saved_index]
rd_bonds = Chem.rdchem.BondType
orders = {'S': rd_bonds.SINGLE, 'D': rd_bonds.DOUBLE, 'T': rd_bonds.TRIPLE, 'B': rd_bonds.AROMATIC,
'Q': rd_bonds.QUADRUPLE}
'Q': rd_bonds.QUADRUPLE, 'vdW': rd_bonds.UNSPECIFIED}
Comment on lines 99 to +100
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mapping vdW to BondType.UNSPECIFIED may interact poorly with RDKit sanitization and downstream chemistry perception (some RDKit operations treat UNSPECIFIED as query/unknown and can fail or behave unexpectedly on “normal” molecules). Consider either (a) skipping creation of vdW bonds in RDKit and encoding connectivity via properties/atom maps, or (b) conditionally disabling sanitization (or clearly documenting expected sanitizer behavior) when vdW bonds are present.

Copilot uses AI. Check for mistakes.
# Add the bonds
for atom1 in mol.vertices:
for atom2, bond in atom1.edges.items():
Expand Down
3 changes: 3 additions & 0 deletions rmgpy/molecule/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,9 @@ def _render_bond(self, atom1, atom2, bond, cr):
elif bond.is_hydrogen_bond():
# Draw a dashed line
self._draw_line(cr, x1, y1, x2, y2, dashed=True, dash_sizes=[0.5, 3.5])
elif bond.is_van_der_waals():
# Draw a dashed line
self._draw_line(cr, x1, y1, x2, y2, dashed=True, dash_sizes=[0.5, 3.5])
Comment on lines 1214 to +1219
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hydrogen_bond and van_der_waals rendering blocks are identical. Combine these branches (e.g., one condition for “draw dashed bond”) to reduce duplication and keep styling consistent if dash parameters change later.

Suggested change
elif bond.is_hydrogen_bond():
# Draw a dashed line
self._draw_line(cr, x1, y1, x2, y2, dashed=True, dash_sizes=[0.5, 3.5])
elif bond.is_van_der_waals():
# Draw a dashed line
self._draw_line(cr, x1, y1, x2, y2, dashed=True, dash_sizes=[0.5, 3.5])
elif bond.is_hydrogen_bond() or bond.is_van_der_waals():
# Draw a dashed line for hydrogen bonds and van der Waals interactions
self._draw_line(cr, x1, y1, x2, y2, dashed=True, dash_sizes=[0.5, 3.5])

Copilot uses AI. Check for mistakes.
else:
self._draw_line(cr, x1, y1, x2, y2)
else:
Expand Down
20 changes: 16 additions & 4 deletions rmgpy/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

################################################################################

bond_orders = {'S': 1, 'D': 2, 'T': 3, 'B': 1.5}
bond_orders = {'S': 1, 'D': 2, 'T': 3, 'B': 1.5, 'vdW': 0}

globals().update({
'bond_orders': bond_orders,
Expand Down Expand Up @@ -1258,9 +1258,19 @@ def remove_van_der_waals_bonds(self):
Remove all van der Waals bonds.
"""
cython.declare(bond=Bond)
for bond in self.get_all_edges():
if bond.is_van_der_waals():
self.remove_bond(bond)
if self.is_multidentate():
#bond_types =
#possible_bonds_with_resonance = #TODO: Include possible nitrogen bonds
if any([k in ['O-X', 'C#X', 'C=X', 'C-X'] for k in self.enumerate_bonds()]):
pass
Comment on lines +1261 to +1265
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is hard to reason about and brittle due to (1) reliance on hard-coded bond “signature” strings, (2) order-dependence (e.g., if enumeration yields X-O instead of O-X), (3) the placeholder pass, and (4) commented-out partial lines. Consider refactoring to a clearly named boolean like has_covalent_surface_bond, avoid constructing a list inside any(...), and make the surface-bond detection order-independent (or use atom/bond properties rather than string signatures).

Copilot uses AI. Check for mistakes.
else:
for bond in self.get_all_edges():
if bond.is_van_der_waals():
self.remove_bond(bond)
else:
for bond in self.get_all_edges():
if bond.is_van_der_waals():
self.remove_bond(bond)
Comment on lines 1258 to +1273
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says this method “Remove[s] all van der Waals bonds”, but the new multidentate branch intentionally preserves vdW bonds for certain structures. Update the docstring (or rename/parameterize the method) so callers and future maintainers don’t rely on outdated semantics.

Copilot uses AI. Check for mistakes.

def sort_atoms(self):
"""
Expand Down Expand Up @@ -2942,6 +2952,8 @@ def get_desorbed_molecules(self):
bonded_atom.increment_radical()
bonded_atom.increment_lone_pairs()
bonded_atom.label = '*4'
elif bond.is_van_der_waals():
bonded_atom.label = '*5'
Comment on lines +2955 to +2956
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new '*5' label is a magic value with no explanation in this method. If *1*4 have established meanings elsewhere, please document what *5 represents (and why it’s safe), or define/centralize these labels as named constants to prevent drift and collisions.

Copilot uses AI. Check for mistakes.
else:
raise NotImplementedError("Can't remove surface bond of type {}".format(bond.order))
desorbed_molecule.remove_atom(site)
Expand Down
Loading