Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
77aee1e
Show box cell
samwaseda Aug 8, 2023
c1e2442
Merge remote-tracking branch 'origin' into plotly_draw_frame
samwaseda Aug 8, 2023
90af2b3
make _get_frame easier to follow?
samwaseda Jan 12, 2024
1f95b7d
change default of show_cell
samwaseda Jan 12, 2024
357303b
add tests for get_frame
samwaseda Jan 12, 2024
47a65f6
satisfy Black
samwaseda Jan 12, 2024
a6853bd
Update pyproject.toml
jan-janssen Jan 22, 2024
7ba3d65
Update environment.yml
jan-janssen Jan 22, 2024
c6f9917
Update environment_mini.yml
jan-janssen Jan 22, 2024
b27285c
Merge pull request #129 from pyiron/scipy
jan-janssen Jan 22, 2024
c82b615
Update pyproject.toml
jan-janssen Jan 27, 2024
274e8fe
Update environment.yml
jan-janssen Jan 27, 2024
2f7127c
Format black
pyiron-runner Jan 27, 2024
ee0b4a0
Merge pull request #130 from pyiron/pymatgen
jan-janssen Jan 27, 2024
d2dcda0
Bump spglib from 2.2.0 to 2.3.0
dependabot[bot] Jan 29, 2024
1419d55
[dependabot skip] Update environment
pyiron-runner Jan 29, 2024
9b64064
Merge pull request #131 from pyiron/dependabot/pip/spglib-2.3.0
jan-janssen Jan 29, 2024
1125da7
rename method
samwaseda Feb 8, 2024
a2fab2e
Update structuretoolkit/visualize.py
samwaseda Feb 8, 2024
2786aaf
Format black
pyiron-runner Feb 8, 2024
79291b6
I don't know how to write in English
samwaseda Feb 8, 2024
31d7c45
Merge branch 'plotly_draw_frame' of github.com:pyiron/structuretoolki…
samwaseda Feb 8, 2024
5a98833
add itemsizing to maintain marker size
samwaseda Feb 8, 2024
b86dd00
Format black
pyiron-runner Feb 8, 2024
5528873
add messages
samwaseda Feb 8, 2024
636a691
Merge pull request #49 from pyiron/plotly_draw_frame
samwaseda Feb 8, 2024
533ca57
Update pyproject.toml
jan-janssen Feb 9, 2024
676bd34
Update environment.yml
jan-janssen Feb 9, 2024
fb80c40
Merge pull request #133 from pyiron/pyxtal
jan-janssen Feb 9, 2024
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 .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ dependencies:
- numpy =1.26.3
- phonopy =2.21.0
- plotly =5.18.0
- pymatgen =2023.12.18
- pymatgen =2024.1.27
- pyscal =2.10.18
- pyxtal =0.6.1
- pyxtal =0.6.2
- scikit-learn =1.4.0
- scipy =1.11.4
- spglib =2.2.0
- scipy =1.12.0
- spglib =2.3.0
- sqsgenerator =0.3
2 changes: 1 addition & 1 deletion .ci_support/environment_mini.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ dependencies:
- ase =3.22.1
- coverage
- numpy =1.26.3
- scipy =1.11.4
- scipy =1.12.0
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
dependencies = [
"ase==3.22.1",
"numpy==1.26.3",
"scipy==1.11.4",
"scipy==1.12.0",
]
dynamic = ["version"]

Expand All @@ -38,23 +38,23 @@ Repository = "https://github.com/pyiron/structuretoolkit"
[project.optional-dependencies]
grainboundary = [
"aimsgb==1.1.0",
"pymatgen==2023.12.18",
"pymatgen==2024.1.27",
]
pyscal = ["pyscal2==2.10.18"]
nglview = ["nglview==3.1.1"]
matplotlib = ["matplotlib==3.8.2"]
plotly = ["plotly==5.18.0"]
clusters = ["scikit-learn==1.4.0"]
symmetry = ["spglib==2.2.0"]
symmetry = ["spglib==2.3.0"]
surface = [
"spglib==2.2.0",
"pymatgen==2023.12.18",
"spglib==2.3.0",
"pymatgen==2024.1.27",
]
phonopy = [
"phonopy==2.21.0",
"spglib==2.2.0",
"spglib==2.3.0",
]
pyxtal = ["pyxtal==0.6.1"]
pyxtal = ["pyxtal==0.6.2"]

[tool.setuptools.packages.find]
include = ["structuretoolkit*"]
Expand Down
1 change: 0 additions & 1 deletion structuretoolkit/analyse/strain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Strain:

"""
Calculate local strain of each atom following the Lagrangian strain tensor:

Expand Down
1 change: 0 additions & 1 deletion structuretoolkit/analyse/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class Symmetry(dict):

"""

Return a class for operations related to box symmetries. Main attributes:
Expand Down
22 changes: 22 additions & 0 deletions structuretoolkit/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def plot3d(
elif mode == "plotly":
return _plot3d_plotly(
structure=structure,
show_cell=show_cell,
camera=camera,
particle_size=particle_size,
select_atoms=select_atoms,
Expand All @@ -143,8 +144,20 @@ def plot3d(
raise ValueError("plot method not recognized")


def _get_box_skeleton(cell):
lines_dz = np.stack(np.meshgrid(*3 * [[0, 1]], indexing="ij"), axis=-1)
# eight corners of a unit cube, paired as four z-axis lines

all_lines = np.reshape(
[np.roll(lines_dz, i, axis=-1) for i in range(3)], (-1, 2, 3)
)
# All 12 two-point lines on the unit square
return all_lines @ cell


def _plot3d_plotly(
structure,
show_cell=True,
scalar_field=None,
select_atoms=None,
particle_size=1.0,
Expand Down Expand Up @@ -177,6 +190,7 @@ def _plot3d_plotly(
"""
try:
import plotly.express as px
import plotly.graph_objects as go
except ModuleNotFoundError:
raise ModuleNotFoundError("plotly not installed - use plot3d instead")
if select_atoms is None:
Expand All @@ -196,6 +210,13 @@ def _plot3d_plotly(
scale=particle_size / (0.1 * structure.get_volume() ** (1 / 3)),
),
)
if show_cell:
data = fig.data
for lines in _get_box_skeleton(structure.cell):
fig = px.line_3d(**{xx: vv for xx, vv in zip(["x", "y", "z"], lines.T)})
fig.update_traces(line_color="#000000")
data = fig.data + data
fig = go.Figure(data=data)
fig.layout.scene.camera.projection.type = camera
rot = _get_orientation(view_plane).T
rot[0, :] *= distance_from_camera * 1.25
Expand All @@ -206,6 +227,7 @@ def _plot3d_plotly(
fig.update_layout(scene_camera=angle)
fig.update_traces(marker=dict(line=dict(width=0.1, color="DarkSlateGrey")))
fig.update_scenes(aspectmode="data")
fig.update_layout(legend={"itemsizing": "constant"})
return fig


Expand Down
21 changes: 20 additions & 1 deletion tests/test_visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import unittest
import numpy as np
from structuretoolkit.visualize import _get_flattened_orientation
from structuretoolkit.visualize import _get_flattened_orientation, _get_box_skeleton


class TestAtoms(unittest.TestCase):
Expand All @@ -21,6 +21,25 @@ def test_get_flattened_orientation(self):
R = np.array(_get_flattened_orientation(R, 1)).reshape(4, 4)
self.assertAlmostEqual(np.linalg.det(R), 1)

def test_get_frame(self):
frame = _get_box_skeleton(np.eye(3))
self.assertLessEqual(
np.unique(frame.reshape(-1, 6), axis=0, return_counts=True)[1].max(),
1
)
dx, counts = np.unique(
np.diff(frame, axis=-2).squeeze().astype(int), axis=0, return_counts=True
)
self.assertEqual(
dx.ptp(), 1, msg="Frames not drawn along the nearest edges"
)
msg = (
"There must be four lines along each direction"
+ " (4 x [1, 0, 0], 4 x [0, 1, 0] and 4 x [0, 0, 1])"
)
self.assertEqual(counts.min(), 4, msg=msg)
self.assertEqual(counts.max(), 4, msg=msg)


if __name__ == "__main__":
unittest.main()