Skip to content

Commit

Permalink
remove superscript 1 from AtomicConfiguration output of singly-occupi…
Browse files Browse the repository at this point in the history
…ed AOs and remove semicolons from HTML output of StatefulSpecies
  • Loading branch information
xnx committed Feb 10, 2022
1 parent 66abfc1 commit beeecd0
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 31 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ As ``Formula``, also ``StatefulSpecies`` have ``html`` and ``latex`` attributes.
\mathrm{Ne}^{+} \; 1s^{2}2s^{2}2p^{5}; \; {}^{2}P_{1/2}
>>> StatefulSpecies('(52Cr)(1H) 1sigma2.2sigma1.1delta2.1pi2; 6SIGMA+; v=0; J=2').html
'<sup>52</sup>Cr<sup>1</sup>H 1σ<sup>2</sup>.2σ<sup>1</sup>.1δ<sup>2</sup>.1π<sup>2</sup>; <sup>6</sup>Σ<sup>+</sup>; v=0; J=2'
'<sup>52</sup>Cr<sup>1</sup>H 1σ<sup>2</sup>.2σ<sup>1</sup>.1δ<sup>2</sup>.1π<sup>2</sup> <sup>6</sup>Σ<sup>+</sup> v=0 J=2'
Reaction
Expand All @@ -155,13 +155,13 @@ separated by ``' -> '``, such as
>>> from pyvalem.reaction import Reaction
>>> reaction = Reaction('He+2 + H -> He+ 3p1 + H+ + hv')
>>> reaction
He+2 + H → He+ 3p1 + H+ + hν
He+2 + H → He+ 3p + H+ + hν
>>> reaction.html
'He<sup>2+</sup> + H → He<sup>+</sup> 3p<sup>1</sup> + H<sup>+</sup> + hν'
'He<sup>2+</sup> + H → He<sup>+</sup> 3p + H<sup>+</sup> + hν'
>>> print(reaction.latex)
\mathrm{He}^{2+} + \mathrm{H} \rightarrow \mathrm{He}^{+} \; 3p^{1} + \mathrm{H}^{+} + h\nu
\mathrm{He}^{2+} + \mathrm{H} \rightarrow \mathrm{He}^{+} \; 3p + \mathrm{H}^{+} + h\nu
The ``Reaction`` class also watches out for charge balance and stoichiometry
conservation during instantiation.
Expand Down Expand Up @@ -216,4 +216,4 @@ Always make sure to format your code before submitting a pull request, by runnin

.. _GitHub: https://github.com/xnx/pyvalem
.. _PyPI: https://pypi.org/project/pyvalem/
.. _numpydoc: https://numpydoc.readthedocs.io/en/latest/format.html
.. _numpydoc: https://numpydoc.readthedocs.io/en/latest/format.html
12 changes: 6 additions & 6 deletions doc/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ As ``Formula``, also ``StatefulSpecies`` have ``html`` and ``latex`` attributes.
\mathrm{Ne}^{+} \; 1s^{2}2s^{2}2p^{5}; \; {}^{2}P_{1/2}
>>> StatefulSpecies('(52Cr)(1H) 1sigma2.2sigma1.1delta2.1pi2; 6SIGMA+; v=0; J=2').html
'<sup>52</sup>Cr<sup>1</sup>H 1σ<sup>2</sup>.2σ<sup>1</sup>.1δ<sup>2</sup>.1π<sup>2</sup>; <sup>6</sup>Σ<sup>+</sup>; v=0; J=2'
'<sup>52</sup>Cr<sup>1</sup>H 1σ<sup>2</sup>.2σ<sup>1</sup>.1δ<sup>2</sup>.1π<sup>2</sup> <sup>6</sup>Σ<sup>+</sup> v=0 J=2'
These two examples render as:

.. raw:: html

Ne<sup>+</sup> 1s<sup>2</sup>2s<sup>2</sup>2p<sup>5</sup>; <sup>2</sup>P<sub>1/2</sub><br>
<sup>52</sup>Cr<sup>1</sup>H 1σ<sup>2</sup>.2σ<sup>1</sup>.1δ<sup>2</sup>.1π<sup>2</sup>; <sup>6</sup>Σ<sup>+</sup>; v=0; J=2
Ne<sup>+</sup> 1s<sup>2</sup>2s<sup>2</sup>2p<sup>5</sup> <sup>2</sup>P<sub>1/2</sub><br>
<sup>52</sup>Cr<sup>1</sup>H 1σ<sup>2</sup>.2σ<sup>1</sup>.1δ<sup>2</sup>.1π<sup>2</sup> <sup>6</sup>Σ<sup>+</sup> v=0 J=2


Reaction
Expand All @@ -148,13 +148,13 @@ separated by ``' -> '``, such as
>>> from pyvalem.reaction import Reaction
>>> reaction = Reaction('He+2 + H -> He+ 3p1 + H+ + hv')
>>> reaction
He+2 + H → He+ 3p1 + H+ + hν
He+2 + H → He+ 3p + H+ + hν
>>> reaction.html
'He<sup>2+</sup> + H → He<sup>+</sup> 3p<sup>1</sup> + H<sup>+</sup> + hν'
'He<sup>2+</sup> + H → He<sup>+</sup> 3p + H<sup>+</sup> + hν'
>>> print(reaction.latex)
\mathrm{He}^{2+} + \mathrm{H} \rightarrow \mathrm{He}^{+} \; 3p^{1} + \mathrm{H}^{+} + h\nu
\mathrm{He}^{2+} + \mathrm{H} \rightarrow \mathrm{He}^{+} \; 3p + \mathrm{H}^{+} + h\nu
The ``Reaction`` class also watches out for charge balance and stoichiometry
conservation during instantiation.
Expand Down
2 changes: 1 addition & 1 deletion doc/reaction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Examples
An HTML representation of the reaction is stored as the ``html`` attribute::

>>> print(r2.html)
CO v=1 + O<sub>2</sub> J=2; X<sup>3</sup>Σ<sup>-</sup><sub>g</sub> → CO<sub>2</sub> + O
CO v=1 + O<sub>2</sub> J=2 X<sup>3</sup>Σ<sup>-</sup><sub>g</sub> → CO<sub>2</sub> + O
>>> print(r4.html)
C<sub>6</sub>H<sub>5</sub>OH + 7O<sub>2</sub> → 6CO<sub>2</sub> + 3H<sub>2</sub>O

Expand Down
6 changes: 3 additions & 3 deletions doc/stateful_species.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ An HTML representation is accessible through the ``html`` attribute:
.. code-block:: pycon
>>> print(ss4.html)
CrH 1σ<sup>2</sup>.2σ<sup>1</sup>.1π<sup>4</sup>.3σ<sup>1</sup>; <sup>6</sup>Σ<sup>+</sup>
CrH 1σ<sup>2</sup>.2σ<sup>1</sup>.1π<sup>4</sup>.3σ<sup>1</sup> <sup>6</sup>Σ<sup>+</sup>
This example renders as:

.. raw:: html

CrH 1σ<sup>2</sup>.2σ<sup>1</sup>.1π<sup>4</sup>.3σ<sup>1</sup>; <sup>6</sup>Σ<sup>+</sup>
CrH 1σ<sup>2</sup>.2σ<sup>1</sup>.1π<sup>4</sup>.3σ<sup>1</sup> <sup>6</sup>Σ<sup>+</sup>


The ``Formula`` object and a list of the parse ``State`` objects are returned by the
Expand Down Expand Up @@ -70,4 +70,4 @@ This is checked for:
>>> StatefulSpecies('Li 1s2.2s1; 1s2.2p1')
Traceback (most recent call last):
...
pyvalem.stateful_species.StatefulSpeciesError: Multiple states of type AtomicConfiguration specified for Li 1s2.2p1;1s2.2s1
pyvalem.stateful_species.StatefulSpeciesError: Multiple states of type AtomicConfiguration specified for Li 1s2.2p;1s2.2s
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="pyvalem",
version="2.5.2",
version="2.5.3",
description="A package for managing simple chemical species and states",
long_description=long_description,
long_description_content_type="text/x-rst",
Expand Down
2 changes: 1 addition & 1 deletion src/pyvalem/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Reaction:
>>> # HTML attribute
>>> r1.html
'CO v=1 + O<sub>2</sub> J=2; X<sup>3</sup>Σ<sup>-</sup><sub>g</sub> → CO<sub>2</sub> + O'
'CO v=1 + O<sub>2</sub> J=2 X<sup>3</sup>Σ<sup>-</sup><sub>g</sub> → CO<sub>2</sub> + O'
>>> # Consistency checks
>>> Reaction('BeH+ + I2 <-> BeI + HI')
Expand Down
2 changes: 1 addition & 1 deletion src/pyvalem/stateful_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def verify_multiple_key_value_pairs(self):
def html(self):
if not self.states:
return self.formula.html
return "{} {}".format(self.formula.html, "; ".join(s.html for s in self.states))
return "{} {}".format(self.formula.html, " ".join(s.html for s in self.states))

@property
def latex(self):
Expand Down
18 changes: 12 additions & 6 deletions src/pyvalem/states/atomic_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AtomicOrbital:
l : int, optional
The azimuthal quantum number (0, 1, 2, ..., n-1)
At least one of {`l`, `lletter`} must be passed.
nocc : int, default: 0
nocc : int, default: 1
Number of occupied electrons.
lletter : str, optional
The letter corresponding to l: 's', 'p', 'd', ... for l = 0, 1, 2, ...
Expand Down Expand Up @@ -115,7 +115,9 @@ def __init__(self, n, l=None, nocc=0, lletter=None):
self._validate_atomic_orbital()

def __repr__(self):
return "{}{}{}".format(self.n, self.lletter, self.nocc)
if self.nocc != 1:
return "{}{}{}".format(self.n, self.lletter, self.nocc)
return "{}{}".format(self.n, self.lletter)

@property
def html(self):
Expand All @@ -125,7 +127,9 @@ def html(self):
-------
str
"""
return "{}{}<sup>{}</sup>".format(self.n, self.lletter, self.nocc)
if self.nocc != 1:
return "{}{}<sup>{}</sup>".format(self.n, self.lletter, self.nocc)
return "{}{}".format(self.n, self.lletter)

@property
def latex(self):
Expand All @@ -135,7 +139,9 @@ def latex(self):
-------
str
"""
return "{}{}^{{{}}}".format(self.n, self.lletter, self.nocc)
if self.nocc != 1:
return "{}{}^{{{}}}".format(self.n, self.lletter, self.nocc)
return "{}{}".format(self.n, self.lletter)

def _validate_atomic_orbital(self):
"""Validator method for the atomic orbital class.
Expand Down Expand Up @@ -209,11 +215,11 @@ class AtomicConfiguration(State):
(3, 1, 1)
>>> repr(ac1)
'1s2.2s2.2p6.3p1'
'1s2.2s2.2p6.3p'
>>> ac2 = AtomicConfiguration("[Ne].3p")
>>> repr(ac2)
'1s2.2s2.2p6.3p1'
'1s2.2s2.2p6.3p'
"""

def __init__(self, state_str):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_atomic_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_atomic_configuration(self):
c2 = AtomicConfiguration("1s2.2s2.2p6")
c3 = AtomicConfiguration("1s2.2s2.2p6.3s2.3d10")
c4 = AtomicConfiguration("[He].2s1")
c5 = AtomicConfiguration("2s2.2p1.3s1")
c5 = AtomicConfiguration("2s2.2p1.3s")

self.assertRaises(AtomicConfigurationError, AtomicConfiguration, "s4.w2")
self.assertRaises(AtomicConfigurationError, AtomicConfiguration, "1s 2.2s2")
Expand Down Expand Up @@ -71,8 +71,8 @@ def test_excited_atomic_configuration(self):
def test_atomic_configuration_repr(self):
c1 = AtomicConfiguration("1s2.2s2.2p6.3s2.3p6.4s2.3d")
c2 = AtomicConfiguration("[Ar].4s2.3d1")
self.assertEqual(repr(c1), "1s2.2s2.2p6.3s2.3p6.4s2.3d1")
self.assertEqual(repr(c2), "1s2.2s2.2p6.3s2.3p6.4s2.3d1")
self.assertEqual(repr(c1), "1s2.2s2.2p6.3s2.3p6.4s2.3d")
self.assertEqual(repr(c2), "1s2.2s2.2p6.3s2.3p6.4s2.3d")

def test_atomic_configuration_default_nocc(self):
c1 = AtomicConfiguration("1s")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_reaction_parsing(self):
self.assertEqual(r2.reactants[1][1].states[1].__repr__(), "X(3Σ-g)")
self.assertEqual(
r2.html,
"CO v=1 + O<sub>2</sub> J=2; "
"CO v=1 + O<sub>2</sub> J=2 "
"X<sup>3</sup>Σ<sup>-</sup><sub>g</sub> → "
"CO<sub>2</sub> + O",
)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_stateful_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_atomic_configuration_verification(self):
self.assertTrue(ss1.verify_atomic_configuration())
ss2 = StatefulSpecies("Ar+ 1s2.2s2.2p6.3s2.3p6")
ss3 = StatefulSpecies("Ar+ [Ne].3s2.3p6")
ss4 = StatefulSpecies("Ar+ [Ne].3s2.3p6.4s1")
ss4 = StatefulSpecies("Ar+ [Ne].3s2.3p6.4s")
for ss in (ss2, ss3, ss4):
self.assertRaises(StatefulSpeciesError, ss.verify_atomic_configuration)

Expand Down Expand Up @@ -97,10 +97,10 @@ def test_stateful_species_repr(self):
self.assertEqual(repr(ss2), "(235U) 3*;l=0;n=1")

for ss_text in ["C+ 4P;2s2.2p1", "C+ 2s2.2p1;4P"]:
self.assertEqual(repr(StatefulSpecies(ss_text)), "C+ 2s2.2p1;4P")
self.assertEqual(repr(StatefulSpecies(ss_text)), "C+ 2s2.2p;4P")

for ss_text in ["C+ 2P;2s2.2p1", "C+ 2s2.2p1;2P"]:
self.assertEqual(repr(StatefulSpecies(ss_text)), "C+ 2s2.2p1;2P")
self.assertEqual(repr(StatefulSpecies(ss_text)), "C+ 2s2.2p;2P")


if __name__ == "__main__":
Expand Down

0 comments on commit beeecd0

Please sign in to comment.