Skip to content

Commit

Permalink
Don't modify bond dict while iterating over it.
Browse files Browse the repository at this point in the history
Fixes this problem:

Error: Problem family: Surface_Adsorption_vdW
Error: Problem reactants: (Molecule(smiles="[Pt]"), Molecule(smiles="CO"))
Traceback (most recent call last):
snip
  File "/Users/rwest/Code/Cat/RMG-Py/rmgpy/data/kinetics/family.py", line 1567, in _generate_product_structures
    product_structures = self.apply_recipe(reactant_structures, forward=forward)
  File "/Users/rwest/Code/Cat/RMG-Py/rmgpy/data/kinetics/family.py", line 1483, in apply_recipe
    struct.remove_van_der_waals_bonds()
  File "rmgpy/molecule/molecule.py", line 1091, in rmgpy.molecule.molecule.Molecule.remove_van_der_waals_bonds
  File "rmgpy/molecule/molecule.py", line 1097, in rmgpy.molecule.molecule.Molecule.remove_van_der_waals_bonds
RuntimeError: dictionary changed
  • Loading branch information
rwest committed Nov 7, 2019
1 parent ffe0907 commit 473fe62
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rmgpy/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,11 +1092,14 @@ def remove_van_der_waals_bonds(self):
"""
Remove all van der Waals bonds.
"""
cython.declare(atom=Atom, bond=Bond)
cython.declare(atom=Atom, bond=Bond, to_remove=list)
for atom in self.atoms:
to_remove = []
for bond in atom.edges.values():
if bond.is_van_der_waals():
self.remove_bond(bond)
to_remove.append(bond)
for bond in to_remove:
self.remove_bond(bond)

def sort_atoms(self):
"""
Expand Down

0 comments on commit 473fe62

Please sign in to comment.