Skip to content

Commit

Permalink
Strip HTML tags from electronic_structure. Fixes #1847.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed May 13, 2020
1 parent 4e138b9 commit 632a79a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def __init__(self, symbol: str):
.. attribute:: electronic_structure
Electronic structure. Simplified form with HTML formatting.
Electronic structure.
E.g., The electronic structure for Fe is represented as
[Ar].3d<sup>6</sup>.4s<sup>2</sup>
[Ar].3d6.4s2
.. attribute:: atomic_orbitals
Expand Down Expand Up @@ -459,8 +459,7 @@ def __getattr__(self, item):
if item in ["mendeleev_no", "electrical_resistivity",
"velocity_of_sound", "reflectivity",
"refractive_index", "poissons_ratio", "molar_volume",
"electronic_structure", "thermal_conductivity",
"boiling_point", "melting_point",
"thermal_conductivity", "boiling_point", "melting_point",
"critical_temperature", "superconduction_temperature",
"liquid_range", "bulk_modulus", "youngs_modulus",
"brinell_hardness", "rigidity_modulus",
Expand Down Expand Up @@ -517,6 +516,10 @@ def data(self):
"""
return self._data.copy()

@property
def electronic_structure(self):
return re.sub("</*sup>", "", self._data["Electronic structure"])

@property
def average_ionic_radius(self):
"""
Expand Down Expand Up @@ -618,10 +621,10 @@ def full_electronic_structure(self):
[(1, "s", 2), (2, "s", 2), (2, "p", 6), (3, "s", 2), (3, "p", 6),
(3, "d", 6), (4, "s", 2)]
"""
estr = self._data["Electronic structure"]
estr = self.electronic_structure

def parse_orbital(orbstr):
m = re.match(r"(\d+)([spdfg]+)<sup>(\d+)</sup>", orbstr)
m = re.match(r"(\d+)([spdfg]+)(\d+)", orbstr)
if m:
return int(m.group(1)), m.group(2), int(m.group(3))
return orbstr
Expand Down
2 changes: 2 additions & 0 deletions pymatgen/core/tests/test_periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def test_full_electronic_structure(self):
for k, v in testsets.items():
self.assertEqual(Element(k).full_electronic_structure, v)

self.assertEqual(Element.Ac.electronic_structure, '[Rn].6d1.7s2')

def test_valence(self):
testsets = {"O": (1, 4),
"Fe": (2, 6),
Expand Down

0 comments on commit 632a79a

Please sign in to comment.