Skip to content

Commit

Permalink
fixup! added electronLabel for rxn family and recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfarinajr committed Jan 24, 2021
1 parent 235bb03 commit bb32d7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
23 changes: 9 additions & 14 deletions rmgpy/data/kinetics/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ class ReactionRecipe(object):

def __init__(self, actions=None):
self.actions = actions or []
self.electron_label = None

def add_action(self, action):
"""
Expand Down Expand Up @@ -359,8 +358,7 @@ def _apply(self, struct, forward, unique):
electron.lone_pairs = 0
elif isinstance(struct, Group):
electron = GroupAtom(atomtype=['e'])
#struct = struct.merge(Group(atoms=[GroupAtom(atomtype=['e'])]))
electron.label = self.electron_label
electron.label = '*'
struct.add_atom(electron)

elif action[0] in ['LOSE_PAIR', 'GAIN_PAIR']:
Expand Down Expand Up @@ -681,7 +679,6 @@ def load(self, path, local_context=None, global_context=None, depository_labels=
local_context['reverseMap'] = None
local_context['reactantNum'] = None
local_context['productNum'] = None
local_context['electronLabel'] = None
local_context['autoGenerated'] = False
self.groups = KineticsGroups(label='{0}/groups'.format(self.label))
logging.debug("Loading kinetics family groups from {0}".format(os.path.join(path, 'groups.py')))
Expand All @@ -693,7 +690,6 @@ def load(self, path, local_context=None, global_context=None, depository_labels=

self.reactant_num = local_context.get('reactantNum', None)
self.product_num = local_context.get('productNum', None)
self.electron_label = local_context.get('electronLabel', None)

self.auto_generated = local_context.get('autoGenerated', False)

Expand All @@ -708,7 +704,6 @@ def load(self, path, local_context=None, global_context=None, depository_labels=
self.forward_template.products = self.forward_template.reactants[:]
self.reverse_template = None
self.reverse_recipe = self.forward_recipe.get_reverse()
self.reverse_recipe.electron_label = self.electron_label
else:
self.reverse = local_context.get('reverse', None)
self.reversible = True if local_context.get('reversible', None) is None else local_context.get('reversible', None)
Expand All @@ -717,11 +712,9 @@ def load(self, path, local_context=None, global_context=None, depository_labels=
self.reverse_template = Reaction(reactants=self.forward_template.products,
products=self.forward_template.reactants)
self.reverse_recipe = self.forward_recipe.get_reverse()
self.reverse_recipe.electron_label = self.electron_label
if self.reverse is None:
self.reverse = '{0}_reverse'.format(self.label)

self.forward_recipe.electron_label = self.electron_label
self.rules = KineticsRules(label='{0}/rules'.format(self.label))
logging.debug("Loading kinetics family rules from {0}".format(os.path.join(path, 'rules.py')))
self.rules.load(os.path.join(path, 'rules.py'), local_context, global_context)
Expand Down Expand Up @@ -986,8 +979,6 @@ def save_groups(self, path):
f.write('reactantNum = {0}\n\n'.format(self.reactant_num))
if self.product_num is not None:
f.write('productNum = {0}\n\n'.format(self.product_num))
if self.electron_label is not None:
f.write('electronLabel = "{0}"\n\n'.format(self.electron_label))

if self.auto_generated is not None:
f.write('autoGenerated = {0}\n\n'.format(self.auto_generated))
Expand Down Expand Up @@ -1580,10 +1571,14 @@ def apply_recipe(self, reactant_structures, forward=True, unique=True):
lowest_labels = []
for struct in product_structures:
# Extract digits from labels and convert others (e.g., "*") to empty strings
labels = [''.join(c for c in label if c.isdigit()) for label in struct.get_all_labeled_atoms().keys()]
# Convert digits to integers and remove empty strings
labels = [int(label) for label in labels if label]
lowest_labels.append(min(labels))
labels = [label for label in struct.get_all_labeled_atoms().keys()]
if labels == ['*']:
lowest_labels.append(0)
else:
labels = [''.join(c for c in label if c.isdigit()) for label in labels]
# Convert digits to integers and remove empty strings
labels = [int(label) for label in labels if label]
lowest_labels.append(min(labels))
product_structures = [s for _, s in sorted(zip(lowest_labels, product_structures))]

# Return the product structures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
longDesc = u"""
*1 *1-*3H
|| + *3H+ + *4e- ----> |
|| + *3H+ + *e- ----> |
~*2~ ~*2~~
The rate, which should be in mol/m2/s,
Expand All @@ -20,7 +20,6 @@

reactantNum = 3
productNum = 1
electronLabel = '*4'

recipe(actions=[
['LOSE_CHARGE', '*3', 1],
Expand Down Expand Up @@ -54,7 +53,7 @@
label = "Electron",
group =
"""
1 *4 e u0 p0 c-1
1 * e u0 p0 c-1
""",
kinetics = None,
)
Expand Down

0 comments on commit bb32d7e

Please sign in to comment.