-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
The CompoundLSCoupling class, representing a complex atomic state with | ||
multiple configurations coupling within the LS formulism to several | ||
intermediate terms, e.g. "4f(2Fo)5d2(1G)6s(2G)". The final term should | ||
be given as its own AtomicTermSymbol. The full CompoundLSCoupling state | ||
should contain no spaces; NB the different interaction strength cases | ||
detailed in Martin et al. (sec. 11.8.1) are not yet implemented. | ||
W. C. Martin, W. Wiese, A. Kramida, "Atomic Spectroscopy" in "Springer | ||
Handbook of Atomic, Molecular and Optical Physics", G. W. F. Drake (ed.), | ||
https://doi.org/10.1007/978-3-030-73893-8_11 | ||
Includes methods for parsing a string into quantum numbers and labels, | ||
creating an HTML representation of the term symbol, etc. | ||
""" | ||
|
||
import re | ||
|
||
from pyvalem.states._base_state import State, StateParseError | ||
from .atomic_term_symbol import AtomicTermSymbol, AtomicTermSymbolError | ||
from .atomic_configuration import AtomicConfiguration, AtomicConfigurationError | ||
|
||
term_patt = r"\((.*?)\)" | ||
|
||
|
||
class CompoundLSCouplingError(StateParseError): | ||
pass | ||
|
||
|
||
class CompoundLSCoupling(State): | ||
def __init__(self, state_str): | ||
self.state_str = state_str | ||
self.atomic_configurations = [] | ||
self.term_symbols = [] | ||
self._parse_state(self.state_str) | ||
|
||
def _parse_state(self, state_str): | ||
terms = re.findall(term_patt, state_str) | ||
configs = state_str.split("(") | ||
|
||
if len(configs) == 0 or len(terms) == 0: | ||
raise CompoundLSCouplingError | ||
|
||
try: | ||
for i, config in enumerate(configs[1:], start=1): | ||
configs[i] = configs[i][len(terms[i - 1]) + 1 :] | ||
except IndexError: | ||
raise CompoundLSCouplingError | ||
|
||
if not configs[-1]: | ||
configs = configs[:-1] | ||
|
||
try: | ||
self.terms = [AtomicTermSymbol(term) for term in terms] | ||
self.atomic_configurations = [ | ||
AtomicConfiguration(config) for config in configs | ||
] | ||
except (AtomicTermSymbolError, AtomicConfigurationError): | ||
raise CompoundLSCouplingError | ||
|
||
def __repr__(self): | ||
return self.state_str | ||
|
||
@property | ||
def html(self): | ||
html_chunks = [] | ||
for config, term in zip(self.atomic_configurations, self.terms): | ||
html_chunks.append(config.html) | ||
html_chunks.append(f"({term.html})") | ||
if len(self.atomic_configurations) > len(self.terms): | ||
html_chunks.append(self.atomic_configurations[-1].html) | ||
return "".join(html_chunks) | ||
|
||
@property | ||
def latex(self): | ||
latex_chunks = [] | ||
for config, term in zip(self.atomic_configurations, self.terms): | ||
latex_chunks.append(config.latex) | ||
latex_chunks.append(f"({term.latex})") | ||
if len(self.atomic_configurations) > len(self.terms): | ||
latex_chunks.append(self.atomic_configurations[-1].latex) | ||
return "".join(latex_chunks) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Unit tests for the Compound LS Coupling module of PyValem | ||
""" | ||
|
||
import unittest | ||
|
||
from pyvalem.states.atomic_configuration import AtomicConfiguration | ||
from pyvalem.states.atomic_term_symbol import AtomicTermSymbol | ||
from pyvalem.states.compound_LS_coupling import CompoundLSCoupling | ||
|
||
|
||
class CompoundLSCouplingTest(unittest.TestCase): | ||
def test_compound_LS_coupling(self): | ||
s0 = CompoundLSCoupling("3d10.4f7(8So)4p6.5d(9Do)6s(8Do)7s") | ||
a0 = AtomicConfiguration("3d10.4f7") | ||
a1 = AtomicConfiguration("4p6.5d") | ||
a2 = AtomicConfiguration("6s") | ||
a3 = AtomicConfiguration("7s") | ||
for i, ac in enumerate((a0, a1, a2, a3)): | ||
self.assertEqual(ac, s0.atomic_configurations[i]) | ||
self.assertEqual( | ||
s0.html, | ||
"""3d<sup>10</sup>4f<sup>7</sup>(<sup>8</sup>S<sup>o</sup>)4p<sup>6</sup>5d(<sup>9</sup>D<sup>o</sup>)6s(<sup>8</sup>D<sup>o</sup>)7s""", | ||
) | ||
self.assertEqual( | ||
s0.latex, | ||
r"3d^{10}4f^{7}({}^{8}\mathrm{S}^o)4p^{6}5d({}^{9}\mathrm{D}^o)6s({}^{8}\mathrm{D}^o)7s", | ||
) | ||
|
||
s1 = CompoundLSCoupling("4f10(3K{2})6s.6p(1Po)") | ||
t0 = AtomicTermSymbol("3K{2}") | ||
t1 = AtomicTermSymbol("1Po") | ||
for i, ts in enumerate((t0, t1)): | ||
self.assertEqual(ts, s1.terms[i]) | ||
self.assertEqual(s1.terms[0].seniority, 2) | ||
self.assertEqual( | ||
s1.html, | ||
"""4f<sup>10</sup>(<sup>3</sup>K2)6s6p(<sup>1</sup>P<sup>o</sup>)""", | ||
) | ||
self.assertEqual( | ||
s1.latex, r"4f^{10}({}^{3}\mathrm{K}2)6s6p({}^{1}\mathrm{P}^o)" | ||
) | ||
|
||
s2 = CompoundLSCoupling("4d9(2P)5d2(3Fo)") | ||
self.assertEqual( | ||
s2.html, | ||
"""4d<sup>9</sup>(<sup>2</sup>P)5d<sup>2</sup>(<sup>3</sup>F<sup>o</sup>)""", | ||
) | ||
self.assertEqual( | ||
s2.latex, r"4d^{9}({}^{2}\mathrm{P})5d^{2}({}^{3}\mathrm{F}^o)" | ||
) | ||
|
||
s3 = CompoundLSCoupling("5p5(2Po_3/2)6d") | ||
self.assertEqual( | ||
s3.html, """5p<sup>5</sup>(<sup>2</sup>P<sup>o</sup><sub>3/2</sub>)6d""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters