Skip to content

Commit

Permalink
Fixed Fragment test
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.
  • Loading branch information
ssun30 committed Nov 21, 2024
1 parent 27449c4 commit 7ec54b2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions rmgpy/data/kinetics/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,10 @@ def apply_recipe(self, reactant_structures, forward=True, unique=True, relabel_a
# (families with charged substances), the charge of structures will be updated
if isinstance(struct, Molecule):
struct.update_charge()
struct.update(sort_atoms=not self.save_order)
elif isinstance(struct, Fragment):
struct.update()
if isinstance(struct, Fragment):
struct.update()
else:
struct.update(sort_atoms=not self.save_order)
elif isinstance(struct, Group):
is_molecule = False
struct.reset_ring_membership()
Expand Down
1 change: 1 addition & 0 deletions rmgpy/molecule/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from rmgpy.molecule.atomtype import ATOMTYPES, allElements, nonSpecifics, get_features, AtomType
from rmgpy.molecule.element import PeriodicSystem
from rmgpy.molecule.graph import Vertex, Edge, Graph
from rmgpy.molecule.fragment import CuttingLabel


################################################################################
Expand Down
1 change: 1 addition & 0 deletions rmgpy/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from rmgpy.molecule.graph import Vertex, Edge, Graph, get_vertex_connectivity_value
from rmgpy.molecule.kekulize import kekulize
from rmgpy.molecule.pathfinder import find_shortest_path
from rmgpy.molecule.fragment import CuttingLabel

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

Expand Down
18 changes: 8 additions & 10 deletions rmgpy/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,33 +1440,31 @@ 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):
for atom in reactant.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):
for atom in product.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 7ec54b2

Please sign in to comment.