Skip to content

Commit 913d42c

Browse files
committed
Fixed Fragment test failure
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`.
1 parent 07eba73 commit 913d42c

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

rmgpy/data/kinetics/family.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,10 +1519,9 @@ def apply_recipe(self, reactant_structures, forward=True, unique=True, relabel_a
15191519
# If product structures are Group objects and the reaction is in certain families
15201520
# (families with charged substances), the charge of structures will be updated
15211521
if isinstance(struct, Molecule):
1522-
struct.update_charge()
1522+
if not isinstance(struct, Fragment):
1523+
struct.update_charge()
15231524
struct.update(sort_atoms=not self.save_order)
1524-
elif isinstance(struct, Fragment):
1525-
struct.update()
15261525
elif isinstance(struct, Group):
15271526
is_molecule = False
15281527
struct.reset_ring_membership()

rmgpy/reaction.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,33 +1440,33 @@ def is_balanced(self):
14401440
if not isinstance(atom, CuttingLabel):
14411441
reactants_net_charge += atom.charge
14421442
reactant_elements[atom.element] += 1
1443-
elif isinstance(reactant, Molecule):
1444-
molecule = reactant
1445-
for atom in molecule.atoms:
1446-
reactants_net_charge += atom.charge
1447-
reactant_elements[atom.element] += 1
14481443
elif isinstance(reactant, Fragment):
14491444
for atom in reactant.atoms:
14501445
if not isinstance(atom, CuttingLabel):
14511446
reactants_net_charge += atom.charge
14521447
reactant_elements[atom.element] += 1
1448+
elif isinstance(reactant, Molecule):
1449+
molecule = reactant
1450+
for atom in molecule.atoms:
1451+
reactants_net_charge += atom.charge
1452+
reactant_elements[atom.element] += 1
14531453
for product in self.products:
14541454
if isinstance(product, Species):
14551455
molecule = product.molecule[0]
14561456
for atom in molecule.atoms:
14571457
if not isinstance(atom, CuttingLabel):
14581458
products_net_charge += atom.charge
14591459
product_elements[atom.element] += 1
1460-
elif isinstance(product, Molecule):
1461-
molecule = product
1462-
for atom in molecule.atoms:
1463-
products_net_charge += atom.charge
1464-
product_elements[atom.element] += 1
14651460
elif isinstance(product, Fragment):
14661461
for atom in product.atoms:
14671462
if not isinstance(atom, CuttingLabel):
14681463
products_net_charge += atom.charge
14691464
product_elements[atom.element] += 1
1465+
elif isinstance(product, Molecule):
1466+
molecule = product
1467+
for atom in molecule.atoms:
1468+
products_net_charge += atom.charge
1469+
product_elements[atom.element] += 1
14701470

14711471
for element in element_list:
14721472
if reactant_elements[element] != product_elements[element]:

0 commit comments

Comments
 (0)