Skip to content

Commit

Permalink
Allow molecular term symbol labels 1, 2, 3, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
xnx committed Apr 25, 2022
1 parent 50a2c08 commit e7f9ccf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pyvalem/states/molecular_term_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,16 @@
molecule_term = (
molecule_Smult + molecule_irrep + pp.Optional(pp.Suppress("_") + molecule_Omegastr)
)
term_label = pp.Combine(

# Term Symbol label can be a single letter (perhaps followed by ' or ") ...
term_label_let = pp.Combine(
pp.Word(pp.srange("[A-Za-z]")) + pp.Optional(pp.oneOf(("'", '"')))
).setResultsName("term_label")
# ... or a number. The open bracket is required but suppressed to distinguish
# this type of term label from the spin multiplicity.
term_label_num = integer.setResultsName("term_label") + pp.Suppress("(")
term_label = term_label_let | term_label_num

molecule_term_with_label = (
pp.Optional(term_label)
+ pp.Suppress(pp.Optional("("))
Expand Down
7 changes: 7 additions & 0 deletions tests/test_molecular_term_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def test_molecular_term_symbol_repr(self):
m4 = MolecularTermSymbol("4DELTA")
self.assertTrue(repr(m3) == repr(m4) == "4Δ")

def test_term_symbol_label(self):
m1 = MolecularTermSymbol("1(2B1)")
self.assertEqual(repr(m1), "1(2B1)")
self.assertEqual(m1.term_label, "1")
self.assertRaises(MolecularTermSymbolError, MolecularTermSymbol, "1'(A\")")
self.assertRaises(MolecularTermSymbolError, MolecularTermSymbol, '-2(A")')


if __name__ == "__main__":
unittest.main()

0 comments on commit e7f9ccf

Please sign in to comment.