Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xnx committed Feb 3, 2022
2 parents 6164a25 + db0a8b5 commit 664f1aa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/pyvalem/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ def _parse_formula(self, formula):
# photons, electrons, positrons and "M", denoting an unspecified
# "third-body" in many reactions. Note that M does not have a defined
# charge or mass.
if formula == "e":
# Quietly convert e to e-.
self.formula = formula = "e-"
if formula in special_cases:
for attr, val in special_cases[formula].items():
setattr(self, attr, val)
Expand Down
1 change: 1 addition & 0 deletions src/pyvalem/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def _parse_species(self, lhs_str, rhs_str):
)
ss = StatefulSpecies(ss_str)
species.append((n, ss))
ss_str = str(ss)
if ss_str not in species_map:
species_map[ss_str] = 0
species_map[ss_str] += n
Expand Down
1 change: 1 addition & 0 deletions tests/test_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def test_special_formulas(self):
),
"hv": ("hν", "hν", r"h\nu", "hv", 0, None, 0, {}),
}
f["e"] = f["e-"]
f["hν"] = f["hv"]

for f_str in f:
Expand Down
14 changes: 11 additions & 3 deletions tests/test_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def test_reaction_equality(self):
],
["H + H + M -> H2 + M", "2H + M -> H2 + M"],
["Kr + hv -> Kr + 2hv", "Kr + hv -> Kr + hv + hv"],
["Kr + hv -> Kr *", "Kr + hν -> Kr *"],
["Kr + e- -> Kr- *", "Kr + e -> Kr- *"],
]
for r1, r2 in equal:
self.assertEqual(Reaction(r1), Reaction(r2))
Expand Down Expand Up @@ -186,14 +188,20 @@ def test_reaction_species_map(self):
self.assertEqual(r.reactants_text_count_map, {"e-": 2, "C2": 1})
self.assertEqual(r.products_text_count_map, {"C-": 2})
r = Reaction("e- + e- + hv -> ", strict=False)
self.assertEqual(r.reactants_text_count_map, {"e-": 2, "hv": 1})
self.assertEqual(r.reactants_text_count_map, {"e-": 2, "": 1})
self.assertEqual(r.products_text_count_map, {})
r = Reaction("1e- + 1e- + 2hv -> ", strict=False)
self.assertEqual(r.reactants_text_count_map, {"e-": 2, "hv": 2})
self.assertEqual(r.reactants_text_count_map, {"e-": 2, "": 2})
r = Reaction("e- + O2 X(3Σ-g) -> ", strict=False)
self.assertEqual(r.reactants_text_count_map, {"e-": 1, "O2 X(3Σ-g)": 1})
r = Reaction("e- + O2 X(3SIGMA-g) -> ", strict=False)
self.assertEqual(r.reactants_text_count_map, {"e-": 1, "O2 X(3SIGMA-g)": 1})
self.assertEqual(r.reactants_text_count_map, {"e-": 1, "O2 X(3Σ-g)": 1})

def test_reaction_with_e(self):
r = Reaction("e + C2 + e -> C- + C-")
self.assertEqual(r.reactants_text_count_map, {"e-": 2, "C2": 1})
self.assertEqual(r.products_text_count_map, {"C-": 2})
self.assertEqual(repr(r), "2e- + C2 → C- + C-")


if __name__ == "__main__":
Expand Down

0 comments on commit 664f1aa

Please sign in to comment.