Skip to content

Commit

Permalink
add assets/scripts/key_enum_table.py to visualize Key enum attributes…
Browse files Browse the repository at this point in the history
… with Plotly

- new Key enum attributes: protostructure_moyo and protostructure_spglib
- bump pre-commit hooks
  • Loading branch information
janosh committed Feb 2, 2025
1 parent 7909afa commit ee93702
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ default_install_hook_types: [pre-commit, commit-msg]

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
rev: v0.9.4
hooks:
- id: ruff
args: [--fix]
Expand Down Expand Up @@ -80,12 +80,12 @@ repos:
- "@stylistic/eslint-plugin"

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.392.post0
rev: v1.1.393
hooks:
- id: pyright

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.31.0
rev: 0.31.1
hooks:
- id: check-jsonschema
files: ^pymatviz/keys\.yml$
Expand Down
61 changes: 61 additions & 0 deletions assets/scripts/enums/key_enum_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""This script plots the keys, labels, symbols, units, descriptions, and categories of
pymatviz.enums.Key enum to visually inspect how they render in plotly.
"""

import numpy as np
import plotly.graph_objects as go

from pymatviz.enums import Key


key_data = [
(key.name, key.label, key.symbol, key.unit, key.desc, key.category) for key in Key
]
# Sort by category then name
key_data.sort(key=lambda x: (x[5], x[0]))
headers: dict[str, float] = {
"": 0.7,
"Key": 4,
"Label": 4,
"Symbol": 2,
"Unit": 2,
"Description": 4,
"Category": 2.5,
}
table_rows = list(
zip(
*[(idx, *tup) for idx, tup in enumerate(key_data, start=1)],
strict=True,
)
)

table = go.Table(
header=dict(
values=[f"<b>{h}</b>" for h in headers],
line_color="darkslategray",
fill_color="#4169E1",
# align="left",
font=dict(color="white", size=12),
),
cells=dict(
values=table_rows,
line_color="#ddd",
# alternate row colors for better readability
fill_color=np.where(
np.arange(len(key_data))[None, :] % 2 == 0, "white", "#F5F5F5"
),
align="left",
font=dict(color="#333", size=11),
height=22,
),
columnwidth=list(headers.values()),
)
fig = go.Figure(data=[table])

fig.layout.title = dict(
text="pymatviz.enums.Key Attributes", x=0.5, y=0.99, yanchor="top"
)
fig.layout.margin = dict(l=0, r=0, t=25, b=0)
fig.layout.paper_bgcolor = "white"

fig.show()
2 changes: 2 additions & 0 deletions pymatviz/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ def __reduce_ex__(self, proto: object) -> tuple[type, tuple[str]]:

# Structure Prototyping
protostructure = "protostructure"
protostructure_moyo = "protostructure_moyo"
protostructure_spglib = "protostructure_spglib"
prototype = "prototype"

# Composition
Expand Down
7 changes: 7 additions & 0 deletions pymatviz/keys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ crystal_symmetry_properties:
structure_prototyping:
protostructure:
label: Protostructure Label
description: AFLOW-style protostructure label
protostructure_moyo:
label: Protostructure Label (Moyo)
description: AFLOW-style protostructure label using Moyopy for symmetry detection
protostructure_spglib:
label: Protostructure Label (Spglib)
description: AFLOW-style protostructure label using Spglib for symmetry detection
prototype:
label: Prototype Label

Expand Down

0 comments on commit ee93702

Please sign in to comment.