-
Notifications
You must be signed in to change notification settings - Fork 0
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
Voronoi featuriser pymatgen #77
Draft
ligerzero-ai
wants to merge
12
commits into
main
Choose a base branch
from
VoronoiStats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bf27d69
Voronoi featuriser pymatgen
780bfba
Add test
66ebfc2
forgot import statement
90992b3
import statement
b561944
import statement
9533fcd
remove useless files
e98fb76
add test that asserts approx on pd series
18c9f4c
add skip condition if pmg not installed
a93e457
lets see if this works...
50e2567
multiple exception parenthesis
baf64f3
black formatting
jan-janssen d476a31
Format black
pyiron-runner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from pymatgen.io.ase import AseAtomsAdaptor | ||
from pymatgen.analysis.local_env import VoronoiNN | ||
from pymatgen.core import Structure, Element | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def get_stats(property_list, property_str): | ||
""" | ||
Calculate statistical properties of a list of values. | ||
Parameters: | ||
property_list (list): A list of numerical values for which statistics are calculated. | ||
property_str (str): A string prefix to be used in the resulting statistical property names. | ||
Returns: | ||
dict: A dictionary containing statistical properties with keys in the format: | ||
"{property_str}_{statistic}" where statistic can be "std" (standard deviation), | ||
"mean" (mean), "min" (minimum), and "max" (maximum). | ||
Example: | ||
>>> values = [1, 2, 3, 4, 5] | ||
>>> get_stats(values, "example") | ||
{'example_std': 1.4142135623730951, | ||
'example_mean': 3.0, | ||
'example_min': 1, | ||
'example_max': 5} | ||
""" | ||
return { | ||
f"{property_str}_std": np.std(property_list), | ||
f"{property_str}_mean": np.mean(property_list), | ||
f"{property_str}_min": np.min(property_list), | ||
f"{property_str}_max": np.max(property_list), | ||
} | ||
|
||
|
||
def VoronoiSiteFeaturiser(structure, site): | ||
""" | ||
Calculate various Voronoi-related features for a specific site in a crystal structure. | ||
Parameters: | ||
structure (ase.Atoms or pymatgen.Structure): The crystal structure. | ||
site (int): The index of the site in the crystal structure. | ||
Returns: | ||
pandas.DataFrame: A DataFrame containing computed Voronoi features for the specified site. | ||
Columns include VorNN_CoordNo, VorNN_tot_vol, VorNN_tot_area, as well as | ||
statistics for volumes, vertices, areas, and distances. | ||
Example: | ||
>>> from pymatgen import Structure | ||
>>> structure = Structure.from_file("example.cif") | ||
>>> VoronoiSiteFeaturiser(structure, 0) | ||
VorNN_CoordNo VorNN_tot_vol VorNN_tot_area volumes_std volumes_mean ... | ||
0 7.0 34.315831 61.556747 10.172586 34.315831 ... | ||
""" | ||
structure = AseAtomsAdaptor().get_structure(structure) | ||
coord_no = VoronoiNN().get_cn(structure=structure, n=site) | ||
site_info_dict = VoronoiNN().get_voronoi_polyhedra(structure, site) | ||
volumes = [site_info_dict[polyhedra]["volume"] for polyhedra in site_info_dict] | ||
vertices = [site_info_dict[polyhedra]["n_verts"] for polyhedra in site_info_dict] | ||
distances = [site_info_dict[polyhedra]["face_dist"] for polyhedra in site_info_dict] | ||
areas = [site_info_dict[polyhedra]["area"] for polyhedra in site_info_dict] | ||
|
||
total_area = np.sum(areas) | ||
total_volume = np.sum(volumes) | ||
|
||
data = { | ||
"VorNN_CoordNo": coord_no, | ||
"VorNN_tot_vol": total_volume, | ||
"VorNN_tot_area": total_area, | ||
} | ||
|
||
data_str_list = ["volumes", "vertices", "areas", "distances"] | ||
|
||
for i, value_list in enumerate([volumes, vertices, areas, distances]): | ||
stats = get_stats(value_list, f"VorNN_{data_str_list[i]}") | ||
data.update(stats) | ||
|
||
df = pd.DataFrame(data, index=[site]) | ||
return df |
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
|
||
|
||
class Strain: | ||
|
||
""" | ||
Calculate local strain of each atom following the Lagrangian strain tensor: | ||
|
||
|
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 |
---|---|---|
|
@@ -24,7 +24,6 @@ | |
|
||
|
||
class Symmetry(dict): | ||
|
||
""" | ||
|
||
Return a class for operations related to box symmetries. Main attributes: | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a function, please use a lower case function name: