-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RDFs calculation based on species (#338)
* Add RDFs calculation based on species not transitions information Currently, the RDFs can be calculated for floating species, requiring sites data or transition information. Could you please additionally implement a version that calculates RDFs between specified species without the need for transition data. I have provided the code we use for this calculation, which includes parallelization. * Update rdf.py * Refactor rdf between species * Move plotting code and add boilerplate for plotly * Add test for matplotlib version * Add plotly version --------- Co-authored-by: Stef Smeets <s.smeets@esciencecenter.nl>
- Loading branch information
1 parent
7744b28
commit 6aab085
Showing
11 changed files
with
203 additions
and
1 deletion.
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
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
62 changes: 62 additions & 0 deletions
62
src/gemdat/plots/matplotlib/_radial_distribution_between_species.py
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,62 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from .._shared import _get_radial_distribution_between_species | ||
|
||
if TYPE_CHECKING: | ||
from typing import Collection | ||
|
||
import matplotlib.figure | ||
|
||
from gemdat import Trajectory | ||
|
||
|
||
def radial_distribution_between_species( | ||
*, | ||
trajectory: Trajectory, | ||
specie_1: str | Collection[str], | ||
specie_2: str | Collection[str], | ||
max_dist: float = 5.0, | ||
resolution: float = 0.1, | ||
) -> matplotlib.figure.Figure: | ||
"""Calculate RDFs from specie_1 to specie_2. | ||
Parameters | ||
---------- | ||
trajectory: Trajectory | ||
Input trajectory. | ||
specie_1: str | list[str] | ||
Name of specie or list of species | ||
specie_2: str | list[str] | ||
Name of specie or list of species | ||
max_dist: float, optional | ||
Max distance for rdf calculation | ||
resolution: float, optional | ||
Width of the bins | ||
Returns | ||
------- | ||
fig : matplotlib.figure.Figure | ||
Output figure | ||
""" | ||
bins, rdf = _get_radial_distribution_between_species( | ||
trajectory=trajectory, | ||
specie_1=specie_1, | ||
specie_2=specie_2, | ||
max_dist=max_dist, | ||
resolution=resolution, | ||
) | ||
|
||
fig, ax = plt.subplots() | ||
ax.plot(bins[:-1], rdf) | ||
str1 = specie_1 if isinstance(specie_1, str) else ' / '.join(specie_1) | ||
str2 = specie_1 if isinstance(specie_2, str) else ' / '.join(specie_2) | ||
ax.set( | ||
title=f'RDF between {str1} and {str2}', | ||
xlabel='Radius (Å)', | ||
ylabel='Nr. of atoms', | ||
) | ||
return fig |
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
66 changes: 66 additions & 0 deletions
66
src/gemdat/plots/plotly/_radial_distribution_between_species.py
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,66 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import plotly.graph_objects as go | ||
|
||
from .._shared import _get_radial_distribution_between_species | ||
|
||
if TYPE_CHECKING: | ||
from typing import Collection | ||
|
||
from gemdat import Trajectory | ||
|
||
|
||
def radial_distribution_between_species( | ||
trajectory: Trajectory, | ||
specie_1: str | Collection[str], | ||
specie_2: str | Collection[str], | ||
max_dist: float = 5.0, | ||
resolution: float = 0.1, | ||
) -> go.Figure: | ||
"""Calculate RDFs from specie_1 to specie_2. | ||
Parameters | ||
---------- | ||
trajectory: Trajectory | ||
Input trajectory. | ||
specie_1: str | list[str] | ||
Name of specie or list of species | ||
specie_2: str | list[str] | ||
Name of specie or list of species | ||
max_dist: float, optional | ||
Max distance for rdf calculation | ||
resolution: float, optional | ||
Width of the bins | ||
Returns | ||
------- | ||
fig : matplotlib.figure.Figure | ||
Output figure | ||
""" | ||
bins, rdf = _get_radial_distribution_between_species( | ||
trajectory=trajectory, | ||
specie_1=specie_1, | ||
specie_2=specie_2, | ||
max_dist=max_dist, | ||
resolution=resolution, | ||
) | ||
|
||
fig = go.Figure() | ||
fig.add_trace( | ||
go.Scatter( | ||
x=bins, | ||
y=rdf, | ||
name='Radial distribution', | ||
mode='lines', | ||
) | ||
) | ||
str1 = specie_1 if isinstance(specie_1, str) else ' / '.join(specie_1) | ||
str2 = specie_1 if isinstance(specie_2, str) else ' / '.join(specie_2) | ||
fig.update_layout( | ||
title=f'RDF between {str1} and {str2}', | ||
xaxis_title='Radius (Å)', | ||
yaxis_title='Nr. of atoms', | ||
) | ||
return fig |
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
Binary file added
BIN
+16.4 KB
...tegration/baseline_images/plot_mpl_test/radial_distribution_between_species.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.8 KB
...ration/baseline_images/plot_plotly_test/radial_distribution_between_species.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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