-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from jmmshn/jmmshn/patch_vol
Automatic iso surface determination and example
- Loading branch information
Showing
3 changed files
with
97 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# %% | ||
from __future__ import annotations | ||
|
||
import dash | ||
from dash import html | ||
from dash_mp_components import CrystalToolkitScene | ||
from pymatgen.io.vasp import Chgcar | ||
|
||
import crystal_toolkit.components as ctc | ||
from crystal_toolkit.settings import SETTINGS | ||
|
||
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH) | ||
|
||
chgcar = Chgcar.from_file("../../../tests/test_files/chgcar.vasp") | ||
scene = chgcar.get_scene(isolvl=0.0001) | ||
|
||
layout = html.Div( | ||
[CrystalToolkitScene(data=scene.to_json())], | ||
style={"width": "100px", "height": "100px"}, | ||
) | ||
# %% | ||
# as explained in "preamble" section in documentation | ||
ctc.register_crystal_toolkit(app=app, layout=layout) | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True, port=8050) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from pymatgen.io.vasp import Chgcar | ||
|
||
|
||
def test_volumetric(test_files): | ||
chgcar = Chgcar.from_file(test_files / "chgcar.vasp") | ||
max_val = chgcar.data["total"].max() | ||
|
||
scene = chgcar.get_scene(isolvl=10, normalization=None) | ||
assert scene is not None | ||
|
||
# out of range | ||
with pytest.raises(ValueError, match="Isosurface level is not within data range"): | ||
scene = chgcar.get_scene(isolvl=max_val * 2, normalization=None) | ||
|
||
# cannot be computed | ||
with pytest.raises(RuntimeError): | ||
scene = chgcar.get_scene(isolvl=max_val / 2, normalization=None) | ||
|
||
# vesta units | ||
scene = chgcar.get_scene(isolvl=0.001, normalization="vesta") |