-
Notifications
You must be signed in to change notification settings - Fork 33
[WIP] ElementEmbeddings integration #442
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
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c8a7c57
[WIP] ElementEmbeddings integration
AntObi 403bcea
pre-commit auto-fixes
pre-commit-ci[bot] a34e4e8
Backwards compatible StrEnum
AntObi 2570fb5
Add unit tests for ElementEmbeddings and refactor duplicated match bl…
KingaMas 37c0435
Merge origin/master and resolve import conflicts
KingaMas 6630d7c
pre-commit auto-fixes
pre-commit-ci[bot] 70ec054
Fix pre-commit lint errors: top-level imports and pytest.raises
KingaMas 97f2f93
Rename SmactFilterOutputs.dict to composition_dict and fix lazy imports
KingaMas 0561a0e
Merge branch 'develop' into feat/io_element_embeddings
KingaMas 7929cc1
Fix PLC0415 lazy imports and remove defunct PD901 ruff ignore
KingaMas 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 @@ | ||
| """External packages.""" |
This file contains hidden or 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,102 @@ | ||
| """Interface to ElementEmbeddings. See https://github.com/WMD-group/ElementEmbeddings.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from enum import StrEnum, auto | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from elementembeddings.composition import composition_featuriser as ee_composition_featuriser | ||
| from elementembeddings.composition import species_composition_featuriser as ee_species_composition_featuriser | ||
|
|
||
| if TYPE_CHECKING: | ||
| import pandas as pd | ||
| from elementembeddings.composition import CompositionalEmbedding | ||
| from elementembeddings.core import Embedding | ||
|
|
||
|
|
||
| # Should be moved to element embeddings codebase | ||
| class AllowedElementEmbeddings(StrEnum): | ||
| """ElementEmbeddings implemented in ElementEmbeddings.""" | ||
|
|
||
| magpie = auto() | ||
| mat2vec = auto() | ||
| skipatom = auto() | ||
| cgnf = auto() | ||
| xenonpy = auto() | ||
| random = auto() | ||
| oliynyk = auto() | ||
| matscholar = auto() | ||
| crystallm = auto() | ||
| megnet = auto() | ||
|
|
||
|
|
||
| class AllowedSpeciesEmbeddings(StrEnum): | ||
| """Allowed Species Embeddings.""" | ||
|
|
||
| skipspecies = auto() | ||
|
|
||
|
|
||
| # Should be moved to element embeddings codebase | ||
| class PoolingStats(StrEnum): | ||
| """Pooling statistical operations.""" | ||
|
|
||
| mean = auto() | ||
| variance = auto() | ||
| minpool = auto() | ||
| maxpool = auto() | ||
| range = auto() | ||
| sum = auto() | ||
| geometric_mean = auto() | ||
| harmonic_mean = auto() | ||
|
|
||
|
|
||
| def composition_featuriser( | ||
| composition_data: pd.DataFrame | pd.Series | CompositionalEmbedding | list, | ||
| formula_column: str = "formula", | ||
| embedding: Embedding | AllowedElementEmbeddings = AllowedElementEmbeddings.magpie, | ||
| stats: PoolingStats | list[PoolingStats] = PoolingStats.mean, | ||
| inplace: bool = False, | ||
| ) -> pd.DataFrame: | ||
| """Wrapper to `composition_featuriser` in ElementEmbeddings.""" | ||
| return ee_composition_featuriser( | ||
| data=composition_data, | ||
| formula_column=formula_column, | ||
| embedding=embedding, | ||
| stats=stats, | ||
| inplace=inplace, | ||
| ) | ||
|
|
||
|
|
||
| def species_composition_featuriser( | ||
| composition_data: list[dict[str, float]], | ||
| embedding: AllowedSpeciesEmbeddings | str = AllowedSpeciesEmbeddings.skipspecies, | ||
| stats: PoolingStats | list[PoolingStats] = PoolingStats.mean, | ||
| to_dataframe: bool = False, | ||
| ) -> list | pd.DataFrame: | ||
| """Compute a feature vector for a composition. | ||
|
|
||
| The feature vector is based on the statistics specified | ||
| in the stats argument. | ||
|
|
||
| Args: | ||
| ---- | ||
| composition_data: list[dict[str, float]]: | ||
| a list of composition dictionaries | ||
| embedding (Union[AllowedSpeciesEmbeddings, str], optional): An AllowedSpeciesEmbeddings class | ||
| or a string | ||
| stats (Union[str, list], optional): A list of statistics to be computed. | ||
| The default is ['mean']. | ||
| to_dataframe (bool, optional): Whether to return the feature vectors | ||
| as a DataFrame. The default is False. | ||
|
|
||
| Returns: | ||
| ------- | ||
| Union[pd.DataFrame,list]: A pandas DataFrame containing the feature vector, | ||
| or a list of feature vectors is returned | ||
| """ | ||
| return ee_species_composition_featuriser( | ||
| data=composition_data, | ||
| embedding=embedding, | ||
| stats=stats, | ||
| to_dataframe=to_dataframe, | ||
| ) |
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.