Skip to content

Commit f9d6048

Browse files
committed
Fixed Fragment test
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.
1 parent 89dfb54 commit f9d6048

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

rmgpy/data/kinetics/family.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,9 +1520,10 @@ def apply_recipe(self, reactant_structures, forward=True, unique=True, relabel_a
15201520
# (families with charged substances), the charge of structures will be updated
15211521
if isinstance(struct, Molecule):
15221522
struct.update_charge()
1523-
struct.update(sort_atoms=not self.save_order)
1524-
elif isinstance(struct, Fragment):
1525-
struct.update()
1523+
if isinstance(struct, Fragment):
1524+
struct.update()
1525+
else:
1526+
struct.update(sort_atoms=not self.save_order)
15261527
elif isinstance(struct, Group):
15271528
is_molecule = False
15281529
struct.reset_ring_membership()

rmgpy/molecule/group.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from rmgpy.molecule.atomtype import ATOMTYPES, allElements, nonSpecifics, get_features, AtomType
4545
from rmgpy.molecule.element import PeriodicSystem
4646
from rmgpy.molecule.graph import Vertex, Edge, Graph
47+
from rmgpy.molecule.fragment import CuttingLabel
4748

4849

4950
################################################################################

rmgpy/molecule/molecule.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from rmgpy.molecule.graph import Vertex, Edge, Graph, get_vertex_connectivity_value
5959
from rmgpy.molecule.kekulize import kekulize
6060
from rmgpy.molecule.pathfinder import find_shortest_path
61+
from rmgpy.molecule.fragment import CuttingLabel
6162

6263
################################################################################
6364

rmgpy/reaction.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,33 +1440,31 @@ 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+
for atom in reactant.atoms:
1450+
reactants_net_charge += atom.charge
1451+
reactant_elements[atom.element] += 1
14531452
for product in self.products:
14541453
if isinstance(product, Species):
14551454
molecule = product.molecule[0]
14561455
for atom in molecule.atoms:
14571456
if not isinstance(atom, CuttingLabel):
14581457
products_net_charge += atom.charge
14591458
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
14651459
elif isinstance(product, Fragment):
14661460
for atom in product.atoms:
14671461
if not isinstance(atom, CuttingLabel):
14681462
products_net_charge += atom.charge
14691463
product_elements[atom.element] += 1
1464+
elif isinstance(product, Molecule):
1465+
for atom in product.atoms:
1466+
products_net_charge += atom.charge
1467+
product_elements[atom.element] += 1
14701468

14711469
for element in element_list:
14721470
if reactant_elements[element] != product_elements[element]:

0 commit comments

Comments
 (0)