Skip to content

element_pair_rdfs plots radial distribution functions (RDFs) for element pairs in a structure #203

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

Merged
merged 6 commits into from
Sep 19, 2024

Conversation

janosh
Copy link
Owner

@janosh janosh commented Sep 19, 2024

minimal example

import pymatviz as pmv

pmv.set_plotly_template("pymatviz_white")
# Create a sample structure (e.g., a simple cubic lattice of Fe and O)
lattice = [[3.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]]
species = ["Fe", "O", "Fe", "O"]
coords = [[0, 0, 0], [0.5, 0.5, 0.5], [0, 0.5, 0.5], [0.5, 0, 0]]
structure = Structure(lattice, species, coords)

fig = pmv.element_pair_rdfs(structure, n_bins=75)
fig.show()

pmv.save_fig(fig, "element-pair-rdfs.svg")

element-pair-rdfs

@janosh janosh added enhancement Improvement to existing features/functionality plotly Concerning plotly-powered functions labels Sep 19, 2024
@janosh janosh changed the title Add support for plotting RDFs for pairs of elements in a Structure element_pair_rdfs plots radial distribution functions (RDFs) for element pairs in a structure Sep 19, 2024
@janosh
Copy link
Owner Author

janosh commented Sep 19, 2024

slightly more elaborate example

from matminer.datasets import load_dataset

import pymatviz as pmv
from pymatviz.enums import Key


pmv.set_plotly_template("pymatviz_white")

df_phonons = load_dataset("matbench_phonons")


# get the 2 largest structures
df_phonons[Key.n_sites] = df_phonons[Key.structure].apply(len)

# plot element-pair RDFs for each structure
for struct in df_phonons.nlargest(2, Key.n_sites)[Key.structure]:
    fig = pmv.element_pair_rdfs(struct, n_bins=100, cutoff=10)
    formula = struct.formula
    fig.layout.title.update(text=f"Pairwise RDFs - {formula}", x=0.5, y=0.98)
    fig.layout.margin = dict(l=40, r=0, t=50, b=0)

    fig.show()
    pmv.save_fig(fig, f"element-pair-rdfs-{formula.replace(' ', '')}.svg")

element-pair-rdfs-Na8Nb8O24
element-pair-rdfs-Si16O32

@janosh janosh merged commit b551581 into main Sep 19, 2024
21 of 22 checks passed
@janosh janosh deleted the rdf branch September 19, 2024 22:41
janosh added a commit that referenced this pull request Sep 20, 2024
* `element_pair_rdfs` plots radial distribution functions (RDFs) for element pairs in a structure (#203)

* improve set_plotly_template auto-complete with Literal type

* add element_pair_rdfs(structure) -> go.Figure in new pymatviz/rdf.py module

* add tests/test_rdf.py

* remove ase.Atoms conversion to avoid new pkg dep

* show element_pair_rdfs examples in readme

* should have used save_and_compress_svg

* fix rds svg path

---------

Co-authored-by: Janosh Riebesell <[email protected]>
@janosh janosh added the rdf Radial distribution functions label Sep 24, 2024
@janosh janosh added feature Entirely new features, not improvements to existing ones local env Local environment plots to visualize structural features and removed enhancement Improvement to existing features/functionality labels Oct 7, 2024
janosh added a commit that referenced this pull request Mar 28, 2025
…ement pairs in a structure (#203)

* improve set_plotly_template auto-complete with Literal type

* add element_pair_rdfs(structure) -> go.Figure in new pymatviz/rdf.py module

* add tests/test_rdf.py

* remove ase.Atoms conversion to avoid new pkg dep

* show element_pair_rdfs examples in readme

* should have used save_and_compress_svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Entirely new features, not improvements to existing ones local env Local environment plots to visualize structural features plotly Concerning plotly-powered functions rdf Radial distribution functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant