Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exclude: ^(docs/.+|.*lock.*|jupyterlab-extension/.+|.*\.(svg|js|css))|_version.p

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.13.3
hooks:
- id: ruff
args: [--fix, --ignore, D]
Expand All @@ -23,7 +23,7 @@ repos:
# - id: mypy

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-case-conflict
- id: check-symlinks
Expand All @@ -33,14 +33,14 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
stages: [pre-commit, commit-msg]
args: [--ignore-words-list, "nd,te,ois,dscribe", --check-filenames]

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.1
hooks:
- id: nbstripout
args: [--drop-empty-cells, --keep-output]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ If you would like a new-contributor issue assigned, get in touch with project ma

[![Tests](https://github.com/materialsproject/crystaltoolkit/actions/workflows/pytest-docs.yml/badge.svg)](https://github.com/materialsproject/crystaltoolkit/actions/workflows/pytest-docs.yml)
[![Visual Regression Test Status](https://percy.io/static/images/percy-badge.svg)](https://percy.io/6f28436a/crystaltoolkit)
[![Docker Build Status](https://img.shields.io/docker/cloud/build/materialsproject/crystaltoolkit)](https://hub.docker.com/repository/docker/materialsproject/crystaltoolkit/general)
[![Release](https://github.com/materialsproject/crystaltoolkit/actions/workflows/release.yml/badge.svg)](https://github.com/materialsproject/crystaltoolkit/actions/workflows/release.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/materialsproject/crystaltoolkit/main.svg)](https://results.pre-commit.ci/latest/github/materialsproject/crystaltoolkit/main)
[![arXiv link](https://img.shields.io/badge/arXiv-2302.06147-blue)](https://arxiv.org/abs/2302.06147)
Expand Down Expand Up @@ -81,7 +80,7 @@ The [Crystal Toolkit Development Team](https://github.com/materialsproject/cryst
* [Janosh Riebesell](https://github.com/janosh) contributed Phonon band structure component, [3 example apps](https://github.com/materialsproject/crystaltoolkit/blob/main/crystal_toolkit/apps/examples/matbench_dielectric_structure_on_hover.py), tests
* [Stephen Weitzner](https://github.com/sweitzner) contributed POV-Ray integration (in progress)
* [Richard Tran](https://github.com/CifLord) for contributing plotly-powered Wulff shapes to pymatgen, which Crystal Toolkit uses
* [Guy Moore](https://github.com/guymoore13) for contributing magnetic moment visualization
* Guy Moore for contributing magnetic moment visualization
* [Steve Zeltmann](https://github.com/sezelt) for contributing electron diffraction
* [Patrick Huck](https://github.com/tschaume), releases, operations, bugfixes and POC for MP / MPContribs

Expand All @@ -101,7 +100,7 @@ Thank you to all the authors and maintainers of the libraries Crystal Toolkit
depends upon, and in particular [pymatgen](http://pymatgen.org) for crystallographic
analysis and [Dash from Plotly](https://plot.ly/products/dash/) for their web app framework.

Thank you to the [NERSC Spin](https://nersc.gov/systems/spin) service for
Thank you to the [NERSC Spin](https://docs.nersc.gov/services/spin/) service for
hosting the app and for their technical support.

## Contact
Expand Down
8 changes: 4 additions & 4 deletions crystal_toolkit/apps/examples/mpcontribs/catalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,15 @@ def get_search_layout(self, payload=None):
"Surface Formula": unicodeify(contribution["formula"]),
"Surface Material ID": dcc.Link(
contribution["data"]["mpid"],
href=f'/materials/{contribution["data"]["mpid"]}',
href=f"/materials/{contribution['data']['mpid']}",
),
"Adsorbate SMILES": adsorbate_smiles,
"Adsorbate IUPAC Formula": contribution["data"]["adsorbateIUPACFormula"],
"Adsorption Energy": contribution["data"]["adsorptionEnergy"]["value"],
"Miller Index": unicodeify_spacegroup(
f'({int(contribution["data"]["h"]["value"])} '
f'{int(contribution["data"]["k"]["value"])} '
f'{int(contribution["data"]["l"]["value"])})'
f"({int(contribution['data']['h']['value'])} "
f"{int(contribution['data']['k']['value'])} "
f"{int(contribution['data']['l']['value'])})"
),
"Surface Shift": contribution["data"]["surfaceShift"]["value"],
}
Expand Down
4 changes: 2 additions & 2 deletions crystal_toolkit/apps/examples/tests/test_fermi_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from typing import TYPE_CHECKING

from crystal_toolkit.apps.examples.fermi_surface import app

if TYPE_CHECKING:
from crystal_toolkit.apps.examples.tests.typing import DashDuo


def test_diffraction(dash_duo: DashDuo) -> None:
from crystal_toolkit.apps.examples.fermi_surface import app

dash_duo.start_server(app)
dash_duo.clear_storage()

Expand Down
46 changes: 22 additions & 24 deletions crystal_toolkit/apps/examples/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import annotations

import os
from typing import TYPE_CHECKING

import pandas as pd
from dash import dcc
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from tqdm import tqdm

if TYPE_CHECKING:
import pandas as pd
try:
from matminer.datasets import load_dataset
except ImportError:
load_dataset = None


def load_and_store_matbench_dataset(dataset_name: str) -> pd.DataFrame:
Expand All @@ -18,34 +20,30 @@ def load_and_store_matbench_dataset(dataset_name: str) -> pd.DataFrame:
data_path = os.path.join(os.path.dirname(__file__), f"{dataset_name}.json.gz")

if os.path.isfile(data_path):
import pandas as pd

df = pd.read_json(data_path)
else:
try:
from matminer.datasets import load_dataset
if not load_dataset:
raise ImportError(
"matminer is not installed but needed to download a dataset. Run "
"`pip install matminer`"
)

df = load_dataset(dataset_name)
df = load_dataset(dataset_name)

if "structure" in df:
df[["spg_symbol", "spg_num"]] = [
struct.get_space_group_info()
for struct in tqdm(df.structure, desc="Getting space groups")
]
if "structure" in df:
df[["spg_symbol", "spg_num"]] = [
struct.get_space_group_info()
for struct in tqdm(df.structure, desc="Getting space groups")
]

df["crystal_sys"] = [
SpacegroupAnalyzer(x).get_crystal_system() for x in df.structure
]
df["crystal_sys"] = [
SpacegroupAnalyzer(x).get_crystal_system() for x in df.structure
]

df["volume"] = [x.volume for x in df.structure]
df["formula"] = [x.formula for x in df.structure]
df["volume"] = [x.volume for x in df.structure]
df["formula"] = [x.formula for x in df.structure]

df.to_json(data_path, default_handler=lambda x: x.as_dict())
except ImportError:
print(
"matminer is not installed but needed to download a dataset. Run "
"`pip install matminer`"
)
df.to_json(data_path, default_handler=lambda x: x.as_dict())

return df

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@


def get_structure_for_mpid(mpid):
from pymatgen.ext.matproj import MPRester

with MPRester() as mpr:
structure = mpr.get_structure_by_material_id(mpid)

Expand Down
2 changes: 1 addition & 1 deletion crystal_toolkit/apps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def perform_search_on_page_load(
"""
# TODO: could be a client side callback
if n_submit is None:
return 1, int(round(time() * 1000))
return 1, round(time() * 1000)
raise PreventUpdate


Expand Down
4 changes: 2 additions & 2 deletions crystal_toolkit/apps/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import time
from typing import TYPE_CHECKING

from crystal_toolkit.apps.main import app

if TYPE_CHECKING:
from crystal_toolkit.apps.examples.tests.typing import DashDuo


def test_main_app_startup(dash_duo: DashDuo):
from crystal_toolkit.apps.main import app

dash_duo.start_server(app)
# dash_duo.clear_storage()

Expand Down
4 changes: 2 additions & 2 deletions crystal_toolkit/apps/tests/test_pourbaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from playwright.sync_api import Page

from crystal_toolkit.apps.examples.pourbaix import app

def test_pourbaix(page: Page):
from crystal_toolkit.apps.examples.pourbaix import app

def test_pourbaix(page: Page):
thread = threading.Thread(target=app.run)
thread.start()

Expand Down
4 changes: 2 additions & 2 deletions crystal_toolkit/apps/tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from playwright.sync_api import Page, expect

from crystal_toolkit.apps.examples.structure import app

def test_structure(page: Page):
from crystal_toolkit.apps.examples.structure import app

def test_structure(page: Page):
thread = threading.Thread(target=app.run)
thread.start()

Expand Down
6 changes: 3 additions & 3 deletions crystal_toolkit/components/diffraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _sub_layouts(self) -> dict[str, Component]:
help_str="This defines the wavelength of the incident X-ray radiation.",
options=[
{
"label": f'{name.replace("a", "α").replace("b", "β")} ({wavelength:.3f} Å)', # noqa: RUF001
"label": f"{name.replace('a', 'α').replace('b', 'β')} ({wavelength:.3f} Å)", # noqa: RUF001
"value": name,
}
for name, wavelength in WAVELENGTHS.items()
Expand Down Expand Up @@ -375,9 +375,9 @@ def get_figure(
)
sigma = (alpha / np.sqrt(2 * np.log(2))).item()

center_idx = int(round((xp - first) * N_density))
center_idx = round((xp - first) * N_density)
# total broadening window of 2 * num_sigma
half_window = int(round(num_sigma * sigma * N_density))
half_window = round(num_sigma * sigma * N_density)

lb = max(0, (center_idx - half_window))
ub = min(N, (center_idx + half_window))
Expand Down
2 changes: 1 addition & 1 deletion crystal_toolkit/components/diffraction_tem.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def get_plot_2d(
pattern, thickness=thickness, zone_axis_lattice=beam_direction
)

print(f"Generated pattern in {time()-t0:.3f} seconds")
print(f"Generated pattern in {time() - t0:.3f} seconds")

# generate plotly Figure
return self.pointlist_to_spots(pattern, beam_direction, gamma)
Expand Down
3 changes: 1 addition & 2 deletions crystal_toolkit/components/fermi_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import matplotlib.pyplot as plt
from dash import Input, Output
from ifermi.plot import FermiSurfacePlotter

from crystal_toolkit.core.mpcomponent import MPComponent
from crystal_toolkit.helpers.layouts import Box, Column, Columns, Loading, dcc
Expand Down Expand Up @@ -43,8 +44,6 @@ def get_figure(fermi_surface: FermiSurface, **kwargs) -> Figure:
Returns:
A plotly Figure object.
"""
from ifermi.plot import FermiSurfacePlotter

plotter = FermiSurfacePlotter(fermi_surface)
fig = plotter.get_plot(plot_type="plotly", **kwargs)

Expand Down
12 changes: 7 additions & 5 deletions crystal_toolkit/components/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def update_scene(graph, display_options, scene_additions):
raise PreventUpdate
display_options = self.from_data(display_options)
graph = self.from_data(graph)
scene, legend = self.get_scene_and_legend(
scene, _ = self.get_scene_and_legend(
graph, **display_options, scene_additions=scene_additions
)
return scene
Expand All @@ -402,7 +402,7 @@ def update_legend_and_colors(graph, display_options, scene_additions):
raise PreventUpdate
display_options = self.from_data(display_options)
graph = self.from_data(graph)
scene, legend = self.get_scene_and_legend(
_, legend = self.get_scene_and_legend(
graph, **display_options, scene_additions=scene_additions
)
return legend
Expand Down Expand Up @@ -643,9 +643,11 @@ def _make_title(self, legend):
formula = composition.reduced_formula
formula_parts = re.findall(r"[^\d_]+|\d+", formula)
formula_components = [
html.Sub(part.strip())
if part.isnumeric()
else html.Span(part.strip())
(
html.Sub(part.strip())
if part.isnumeric()
else html.Span(part.strip())
)
for part in formula_parts
]
except Exception:
Expand Down
8 changes: 4 additions & 4 deletions crystal_toolkit/components/submit_snl.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ def generate_description(structure, comments, panel_open, url):
contents = get_token_response(token)

structure = self.from_data(structure)
if type(structure) != Structure:
if not isinstance(structure, Structure):
raise PreventUpdate

description = dcc.Markdown(
f"""
> **Structure to upload:** {structure.composition.reduced_formula} ({len(structure)} sites)
> **Name:** {contents['first_name']} {contents['last_name']}
> **Email:** {contents['email']}
> **Name:** {contents["first_name"]} {contents["last_name"]}
> **Email:** {contents["email"]}
> **Comment:** {comments}

This information is stored so that we can give credit to you on the Materials
Expand Down Expand Up @@ -144,7 +144,7 @@ def submit_snl(n_clicks, structure, comments, url):
raise PreventUpdate

structure = self.from_data(structure)
if type(structure) != Structure:
if not isinstance(structure, Structure):
message = (
f"Can only submit structures to Materials Project, "
f"not {type(structure)}"
Expand Down
2 changes: 1 addition & 1 deletion crystal_toolkit/components/transformations/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def update_preview(transformation_data, input_structure):
if (not transformation_data) or (not input_structure):
return html.Div()
input_structure = self.from_data(input_structure)
output_structure, error = apply_transformation(
output_structure, _ = apply_transformation(
transformation_data, input_structure
)
if len(output_structure) > 64:
Expand Down
2 changes: 1 addition & 1 deletion crystal_toolkit/components/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def callback_update_structure(contents, filename, last_modified):
raise PreventUpdate

# assume we only want the first input for now
content_type, content_string = contents.split(",")
_, content_string = contents.split(",")
decoded_contents = b64decode(content_string)

error = None
Expand Down
3 changes: 1 addition & 2 deletions crystal_toolkit/components/xas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dash.dependencies import Component, Input, Output, State
from dash.exceptions import PreventUpdate
from frozendict import frozendict
from mp_api.client import MPRester

from crystal_toolkit.core.mpcomponent import MPComponent
from crystal_toolkit.core.panelcomponent import PanelComponent
Expand Down Expand Up @@ -154,8 +155,6 @@ def pattern_from_mpid(element, mpid, elements):

url_path = f"/materials/{mpid['mpid']}/xas/{element}"

from mp_api.client import MPRester

with MPRester() as mpr:
data = mpr._make_request(url_path) # querying MP database via MAPI

Expand Down
Loading
Loading