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

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

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 New feature or request 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request plotly Concerning plotly-powered functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant