diff --git a/setup.py b/setup.py index 31010c2..70f7be7 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name="pyvalem", - version="2.5.15", + version="2.5.16", description="A package for managing simple chemical species and states", long_description=long_description, long_description_content_type="text/x-rst", diff --git a/src/pyvalem/states/racah_symbol.py b/src/pyvalem/states/racah_symbol.py index c7cdcab..0db7315 100644 --- a/src/pyvalem/states/racah_symbol.py +++ b/src/pyvalem/states/racah_symbol.py @@ -13,6 +13,7 @@ orbital_labels = ("s", "s'", "p", "p'", "d", "d'", "f", "f'") atom_orbital = pp.oneOf(orbital_labels).setResultsName("orbital") +parity_label = pp.Literal("o").setResultsName("parity") atom_k_term = ( integer.setResultsName("k_num") + pp.Suppress("/") + integer.setResultsName("k_den") @@ -25,8 +26,9 @@ + atom_orbital + pp.Suppress("[") + atom_k_term - + pp.Suppress("]_") - + atom_j_term + + pp.Suppress("]") + + pp.Optional(parity_label) + + pp.Optional("_" + atom_j_term) ) @@ -36,7 +38,8 @@ class RacahSymbol(State): This class is currently little more than a stub. The term symbol of the parent configuration must be specified as a separate State; this class - defines nl[K]_J, without the parity label ("superscript-o"). + defines nl[K]_J, where _J is optional to allow for the case where a + state is an average over J levels. """ def __init__(self, state_str): @@ -47,6 +50,7 @@ def __init__(self, state_str): self.k_num = None self.k_den = None self.j_term = None + self.parity = None self._parse_state(state_str) def _parse_state(self, state_str): @@ -62,15 +66,20 @@ def _parse_state(self, state_str): self.parent_rot = 1.5 self.k_num = int(components.k_num) self.k_den = int(components.k_den) - self.j_term = int(components.jterm) + self.parity = "o" if components.parity else "" + if components.jterm != "": + self.j_term = int(components.jterm) def __repr__(self): - parent = "{}{}".format(self.principal, self.orbital) - k = "{}/{}".format(self.k_num, self.k_den) - return "{}[{}]_{}".format(parent, k, self.j_term) + parent = f"{self.principal}{self.orbital}" + k = f"{self.k_num}/{self.k_den}" + s_jterm = f"_{self.j_term}" if self.j_term is not None else "" + return f"{parent}[{k}]{self.parity}{s_jterm}" @property def html(self): - parent = "{}{}".format(self.principal, self.orbital) - k = "{}/{}".format(self.k_num, self.k_den) - return "{}[{}]{}".format(parent, k, self.j_term) + parent = f"{self.principal}{self.orbital}" + k = f"{self.k_num}/{self.k_den}" + s_parity = "o" if self.parity else "" + s_jterm = f"{self.j_term}" if self.j_term is not None else "" + return f"{parent}[{k}]{s_parity}{s_jterm}" diff --git a/tests/test_racah_symbols.py b/tests/test_racah_symbols.py index cc73bc7..2659db9 100644 --- a/tests/test_racah_symbols.py +++ b/tests/test_racah_symbols.py @@ -18,6 +18,7 @@ def test_racah_symbol(self): self.assertEqual(r0.j_term, 1) r1 = RacahSymbol("3p[5/2]_2") + self.assertEqual(repr(r1), "3p[5/2]_2") self.assertEqual(r1.html, "3p[5/2]2") self.assertEqual(r1.principal, 3) self.assertEqual(r1.orbital, "p") @@ -25,6 +26,26 @@ def test_racah_symbol(self): self.assertEqual(r1.k_den, 2) self.assertEqual(r1.j_term, 2) + r2 = RacahSymbol("4d[3/2]") + self.assertEqual(repr(r2), "4d[3/2]") + self.assertEqual(r2.html, "4d[3/2]") + self.assertEqual(r2.principal, 4) + self.assertEqual(r2.orbital, "d") + self.assertEqual(r2.k_num, 3) + self.assertEqual(r2.k_den, 2) + self.assertEqual(r2.j_term, None) + self.assertEqual(r2.parity, "") + + r3 = RacahSymbol("3p[3/2]o_2") + self.assertEqual(repr(r3), "3p[3/2]o_2") + self.assertEqual(r3.html, "3p[3/2]o2") + self.assertEqual(r3.principal, 3) + self.assertEqual(r3.orbital, "p") + self.assertEqual(r3.k_num, 3) + self.assertEqual(r3.k_den, 2) + self.assertEqual(r3.j_term, 2) + self.assertEqual(r3.parity, "o") + if __name__ == "__main__": unittest.main()