Skip to content

Commit

Permalink
Fixed Fragment test failure
Browse files Browse the repository at this point in the history
The `Fragment` class is now a subclass of
`Molecule`. As such, some if statements for
checking atom charges no longer work for Fragments
since CuttingLabels don't have defined charges.

These if statements were modified such that charge
checks for `Fragments` ignore CuttingLabels, and
will skip charge checks for `Molecules` if the
species is an instance `Fragments`.
  • Loading branch information
ssun30 committed Oct 9, 2024
1 parent 07eba73 commit 913d42c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions rmgpy/data/kinetics/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,10 +1519,9 @@ def apply_recipe(self, reactant_structures, forward=True, unique=True, relabel_a
# If product structures are Group objects and the reaction is in certain families
# (families with charged substances), the charge of structures will be updated
if isinstance(struct, Molecule):
struct.update_charge()
if not isinstance(struct, Fragment):
struct.update_charge()
struct.update(sort_atoms=not self.save_order)
elif isinstance(struct, Fragment):
struct.update()
elif isinstance(struct, Group):
is_molecule = False
struct.reset_ring_membership()
Expand Down
20 changes: 10 additions & 10 deletions rmgpy/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,33 +1440,33 @@ def is_balanced(self):
if not isinstance(atom, CuttingLabel):
reactants_net_charge += atom.charge
reactant_elements[atom.element] += 1
elif isinstance(reactant, Molecule):
molecule = reactant
for atom in molecule.atoms:
reactants_net_charge += atom.charge
reactant_elements[atom.element] += 1
elif isinstance(reactant, Fragment):
for atom in reactant.atoms:
if not isinstance(atom, CuttingLabel):
reactants_net_charge += atom.charge
reactant_elements[atom.element] += 1
elif isinstance(reactant, Molecule):
molecule = reactant
for atom in molecule.atoms:
reactants_net_charge += atom.charge
reactant_elements[atom.element] += 1
for product in self.products:
if isinstance(product, Species):
molecule = product.molecule[0]
for atom in molecule.atoms:
if not isinstance(atom, CuttingLabel):
products_net_charge += atom.charge
product_elements[atom.element] += 1
elif isinstance(product, Molecule):
molecule = product
for atom in molecule.atoms:
products_net_charge += atom.charge
product_elements[atom.element] += 1
elif isinstance(product, Fragment):
for atom in product.atoms:
if not isinstance(atom, CuttingLabel):
products_net_charge += atom.charge
product_elements[atom.element] += 1
elif isinstance(product, Molecule):
molecule = product
for atom in molecule.atoms:
products_net_charge += atom.charge
product_elements[atom.element] += 1

for element in element_list:
if reactant_elements[element] != product_elements[element]:
Expand Down

0 comments on commit 913d42c

Please sign in to comment.