From ee9370268deb75487880cad6066681dd7882a5f3 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Sun, 2 Feb 2025 14:16:59 -0500 Subject: [PATCH] add assets/scripts/key_enum_table.py to visualize Key enum attributes with Plotly - new Key enum attributes: protostructure_moyo and protostructure_spglib - bump pre-commit hooks --- .pre-commit-config.yaml | 6 +-- assets/scripts/enums/key_enum_table.py | 61 ++++++++++++++++++++++++++ pymatviz/enums.py | 2 + pymatviz/keys.yml | 7 +++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 assets/scripts/enums/key_enum_table.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e94860fa..a06945ab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] @@ -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$ diff --git a/assets/scripts/enums/key_enum_table.py b/assets/scripts/enums/key_enum_table.py new file mode 100644 index 00000000..d53d9fa1 --- /dev/null +++ b/assets/scripts/enums/key_enum_table.py @@ -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"{h}" 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() diff --git a/pymatviz/enums.py b/pymatviz/enums.py index 4c3c93b5..18a92a1c 100644 --- a/pymatviz/enums.py +++ b/pymatviz/enums.py @@ -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 diff --git a/pymatviz/keys.yml b/pymatviz/keys.yml index 3be59bc1..3311a919 100644 --- a/pymatviz/keys.yml +++ b/pymatviz/keys.yml @@ -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