Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site shape analysis #166

Merged
merged 27 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b06acf0
shape_analysis
AstyLavrinenko Oct 16, 2023
3d70e84
Merge branch 'main' into shape_analysis
stefsmeets Oct 24, 2023
92499b8
Move notebook out of src dir
stefsmeets Oct 24, 2023
ca8e3db
Add develop notebook
stefsmeets Oct 24, 2023
eb1f7ae
Commit working version
stefsmeets Oct 25, 2023
6861dc7
Commit working plots
stefsmeets Oct 25, 2023
e2e9e66
Fix plots and load sites from cif
stefsmeets Oct 25, 2023
ff580f3
Tweak plots
stefsmeets Oct 25, 2023
cc8f843
Refactor plots
stefsmeets Oct 30, 2023
3c86d44
Refactor notebook
stefsmeets Oct 30, 2023
3359229
Update api
stefsmeets Nov 1, 2023
c1b546f
Update docstrings
stefsmeets Nov 2, 2023
dc79a8d
Move distances to shape method
stefsmeets Nov 2, 2023
76f9eb2
Add ShapeAnalyzer to api
stefsmeets Nov 2, 2023
0c8ae3d
Add integration tests for shape analysis
stefsmeets Nov 2, 2023
cf0376b
Remove notebook
stefsmeets Nov 2, 2023
58968b8
Clean up debug code
stefsmeets Nov 2, 2023
d85670d
Add repr for shape analyzer
stefsmeets Nov 9, 2023
5c648ec
Fix return statement
stefsmeets Nov 9, 2023
161009d
Merge branch 'main' into shape_analysis
stefsmeets Nov 9, 2023
28d6259
Re-organize imports
stefsmeets Nov 9, 2023
1675a18
Fix CI failures
stefsmeets Nov 9, 2023
155ad25
Update docs
stefsmeets Nov 9, 2023
38418d8
Merge branch 'main' into shape_analysis
stefsmeets Nov 20, 2023
a218097
Fix import
stefsmeets Nov 20, 2023
e48ff68
Update pymatgen version to 2023.11.10 for site label propagation
stefsmeets Nov 20, 2023
a4157c6
Fix test
stefsmeets Nov 20, 2023
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
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ nav:
- Simple Example: notebooks/simple.ipynb
- Loading a CIF File: notebooks/CIF.ipynb
- Autogenerated Sites: notebooks/auto.ipynb
- Shape analysis: notebooks/shape_analysis.ipynb
- Pathways: notebooks/paths.ipynb
- Python API:
- gemdat: api/gemdat.md
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
'matplotlib >= 3.6.0',
'MDAnalysis',
'numpy',
'pymatgen >= 2023.8.10',
'pymatgen >= 2023.11.10',
'rich',
'scikit-image',
'scipy',
Expand Down
5 changes: 4 additions & 1 deletion src/gemdat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from __future__ import annotations

from .io import load_known_material, read_cif
from .shape import ShapeAnalyzer
from .simulation_metrics import SimulationMetrics
from .sites import SitesData
from .trajectory import Trajectory
from .volume import trajectory_to_volume
from .volume import Volume, trajectory_to_volume

__version__ = '0.9.4'
__all__ = [
'read_cif',
'load_known_material',
'ShapeAnalyzer',
'SimulationMetrics',
'SitesData',
'Trajectory',
'trajectory_to_volume',
'Volume',
]
35 changes: 16 additions & 19 deletions src/gemdat/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,42 @@
from __future__ import annotations

# Matplotlib plots
from .matplotlib._displacements import displacement_per_site
from .matplotlib._jumps import (
from .matplotlib import (
collective_jumps,
displacement_per_site,
energy_along_path,
frequency_vs_occurence,
jumps_3d,
jumps_3d_animation,
)
from .matplotlib._paths import (
energy_along_path,
path_on_grid,
radial_distribution,
shape,
)
from .matplotlib._rdf import radial_distribution
from .matplotlib._vibration import frequency_vs_occurence

# Plotly plots (matplotlib version might be available)
from .plotly._density import density
from .plotly._displacements import (
from .plotly import (
density,
displacement_histogram,
displacement_per_element,
)
from .plotly._jumps import (
jumps_vs_distance,
jumps_vs_time,
vibrational_amplitudes,
)
from .plotly._paths import path_on_landscape
from .plotly._vibration import vibrational_amplitudes

__all__ = [
'collective_jumps',
'density',
'displacement_per_site',
'displacement_per_element',
'displacement_histogram',
'displacement_per_element',
'displacement_per_site',
'frequency_vs_occurence',
'vibrational_amplitudes',
'jumps_vs_distance',
'jumps_vs_time',
'collective_jumps',
'jumps_3d',
'jumps_3d_animation',
'jumps_vs_distance',
'jumps_vs_time',
'radial_distribution',
'shape',
'vibrational_amplitudes',
'energy_along_path',
'path_on_grid',
'path_on_landscape',
Expand Down
20 changes: 14 additions & 6 deletions src/gemdat/plots/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,30 @@
jumps_vs_distance,
jumps_vs_time,
)
from ._paths import (
energy_along_path,
path_on_grid,
)
from ._rdf import radial_distribution
from ._shape import shape
from ._vibration import (
frequency_vs_occurence,
vibrational_amplitudes,
)

__all__ = [
'displacement_per_site',
'displacement_per_element',
'collective_jumps',
'displacement_histogram',
'displacement_per_element',
'displacement_per_site',
'energy_along_path',
'frequency_vs_occurence',
'vibrational_amplitudes',
'jumps_vs_distance',
'jumps_vs_time',
'collective_jumps',
'jumps_3d',
'jumps_3d_animation',
'jumps_vs_distance',
'jumps_vs_time',
'path_on_grid',
'radial_distribution',
'shape',
'vibrational_amplitudes',
]
65 changes: 65 additions & 0 deletions src/gemdat/plots/matplotlib/_shape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Sequence

import matplotlib.pyplot as plt
import numpy as np

if TYPE_CHECKING:
from gemdat.shape import ShapeData


def shape(shape: ShapeData, bins: int | Sequence[float] = 50) -> plt.Figure:
"""Plot site cluster shapes.

Parameters
----------
shape : ShapeData
Shape data to plot
bins : int | Sequence[float]
Number of bins or sequence of bin edges.
See [hist()][matplotlib.pyplot.hist] for more info.

Returns
-------
fig : matplotlib.figure.Figure
Output figure
"""
x_labels = ('X / Å', 'Y / Å', 'Z / Å')
y_labels = ('Y / Å', 'Z / Å', 'X / Å')

fig, axes = plt.subplots(nrows=2,
ncols=3,
sharex=True,
figsize=(12, 5),
gridspec_kw={'height_ratios': (4, 1)})

distances_sq = shape.distances()**2

msd = np.mean(distances_sq)
std = np.std(distances_sq)
title = f'{shape.name}: MSD = {msd:.3f}$~Å^2$, std = {std:.3f}'

axes[0, 1].set_title(title)

for i, (x, y) in enumerate(
((shape.x, shape.y), (shape.y, shape.z), (shape.z, shape.x))):
ax0 = axes[0, i]
ax1 = axes[1, i]

ax0.hist2d(x=x, y=y, bins=bins)
ax0.set_ylabel(y_labels[i])

circle = plt.Circle((0, 0), msd, color='r', linestyle='--', fill=False)
ax0.add_patch(circle)

ax0.scatter(x=[0], y=[0], color='r', marker='.')
ax0.axis('equal')

ax1.hist(x=x, bins=bins, density=True)
ax1.set_xlabel(x_labels[i])
ax1.set_ylabel('density')

fig.tight_layout()

return fig
24 changes: 24 additions & 0 deletions src/gemdat/plots/plotly/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""This module contains all the plots that Gemdat can generate with plotly."""
from __future__ import annotations

from ._density import density
from ._displacements import (
displacement_histogram,
displacement_per_element,
)
from ._jumps import (
jumps_vs_distance,
jumps_vs_time,
)
from ._paths import path_on_landscape
from ._vibration import vibrational_amplitudes

__all__ = [
'density',
'displacement_histogram',
'displacement_per_element',
'jumps_vs_distance',
'jumps_vs_time',
'path_on_landscape',
'vibrational_amplitudes',
]
Loading