-
Notifications
You must be signed in to change notification settings - Fork 35
Aqueous Iron Chloride Oxidation States #360
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
Open
PKourtis
wants to merge
16
commits into
ddmms:main
Choose a base branch
from
PKourtis:oxidation_states_clean
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.
+3,280
−8
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f4b13f3
Initial ox_state calc directory
e362d65
Test calc script for aqueous iron chloride MD
543c3e4
Core setup of Fe_oxidation_states benchmarks - fix to remove unecessa…
ba819fc
Fix metrics, highlight ref on the plots, fix analysis, add rdf calcul…
28fde44
Apply suggestion from @ElliottKasoar
PKourtis 6ea9158
Applied PR suggestion on highighted_range for the plot scatter decora…
fb343dc
Revert pyproject.toml to upstream version
a91247e
Cleaned up model declaration in the app.py
PKourtis d232e12
Each model has its own directory within outputs and the rdf tests get…
PKourtis dc88674
Updated metrics level of theory to Experimental
PKourtis 174b602
Updated analysis to match outputs/model_name data directory pattern
PKourtis 8b8b807
Added download from S3 bucket function for the input data
PKourtis 3f92003
Added yes/no units
PKourtis 0e1854c
Fixed plot_scatter highlighted range title and plot title mixup
PKourtis e324075
Download MD starting structures from S3 bucket and save outputs in th…
PKourtis 642ad10
Added model name to the scatter title
PKourtis 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
179 changes: 179 additions & 0 deletions
179
ml_peg/analysis/physicality/oxidation_states/analyse_oxidation_states.py
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,179 @@ | ||
| """Analyse aqueous Iron Chloride oxidation states.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from ml_peg.analysis.utils.decorators import build_table, plot_scatter | ||
| from ml_peg.analysis.utils.utils import load_metrics_config | ||
| from ml_peg.app import APP_ROOT | ||
| from ml_peg.calcs import CALCS_ROOT | ||
| from ml_peg.models.get_models import get_model_names | ||
| from ml_peg.models.models import current_models | ||
|
|
||
| MODELS = get_model_names(current_models) | ||
|
|
||
| CALC_PATH = CALCS_ROOT / "physicality" / "oxidation_states" / "outputs" | ||
| OUT_PATH = APP_ROOT / "data" / "physicality" / "oxidation_states" | ||
|
|
||
| METRICS_CONFIG_PATH = Path(__file__).with_name("metrics.yml") | ||
| DEFAULT_THRESHOLDS, DEFAULT_TOOLTIPS, _ = load_metrics_config(METRICS_CONFIG_PATH) | ||
|
|
||
| IRON_SALTS = ["Fe2Cl", "Fe3Cl"] | ||
| TESTS = ["Fe-O RDF Peak Split", "Peak Within Experimental Ref"] | ||
| REF_PEAK_RANGE = { | ||
| "Fe<sup>+2</sup><br>Ref": [2.0, 2.2], | ||
| "Fe<sup>+3</sup><br>Ref": [1.9, 2.0], | ||
| } | ||
|
|
||
|
|
||
| def get_rdf_results( | ||
| model: str, | ||
| ) -> dict[str, tuple[list[float], list[float]]]: | ||
| """ | ||
| Get a model's Fe-O RDFs for the aqueous Fe2Cl and Fe3Cl MD. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| model | ||
| Name of MLIP. | ||
|
|
||
| Returns | ||
| ------- | ||
| results | ||
| RDF Radii and intensities for the aqueous Fe2Cl and Fe3Cl systems. | ||
| """ | ||
| results = {salt: [] for salt in IRON_SALTS} | ||
|
|
||
| model_calc_path = CALC_PATH / model | ||
|
|
||
| for salt in IRON_SALTS: | ||
| rdf_file = model_calc_path / f"O-Fe_{salt}_{model}.rdf" | ||
|
|
||
| fe_o_rdf = np.loadtxt(rdf_file) | ||
| r = list(fe_o_rdf[:, 0]) | ||
| g_r = list(fe_o_rdf[:, 1]) | ||
|
|
||
| results[salt].append(r) | ||
| results[salt].append(g_r) | ||
|
|
||
| return results | ||
|
|
||
|
|
||
| def plot_rdfs(model: str, results: dict[str, tuple[list[float], list[float]]]) -> None: | ||
| """ | ||
| Plot Fe-O RDFs. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| model | ||
| Name of MLIP. | ||
| results | ||
| RDF Radii and intensities for the aqueous Fe2Cl and Fe3Cl systems. | ||
| """ | ||
|
|
||
| @plot_scatter( | ||
| filename=OUT_PATH / f"Fe-O_{model}_RDF_scatter.json", | ||
| title=f"<b>{model} MD</b>", | ||
| x_label="r [Å]", | ||
| y_label="Fe-O G(r)", | ||
| show_line=True, | ||
| show_markers=False, | ||
| highlight_range=REF_PEAK_RANGE, | ||
| ) | ||
| def plot_result() -> dict[str, tuple[list[float], list[float]]]: | ||
| """ | ||
| Plot the RDFs. | ||
|
|
||
| Returns | ||
| ------- | ||
| model_results | ||
| Dictionary of model Fe-O RDFs for the aqueous Fe2Cl and Fe3Cl systems. | ||
| """ | ||
| return results | ||
|
|
||
| plot_result() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def get_oxidation_states_passfail() -> dict[str, dict]: | ||
| """ | ||
| Test whether model RDF peaks are split and they fall within the reference range. | ||
|
|
||
| Returns | ||
| ------- | ||
| oxidation_states_passfail | ||
| Dictionary of pass fail per model. | ||
| """ | ||
| oxidation_state_passfail = {test: {} for test in TESTS} | ||
|
|
||
| fe_2_ref = [2.0, 2.2] | ||
| fe_3_ref = [1.9, 2.0] | ||
|
|
||
| for model in MODELS: | ||
| peak_position = {} | ||
| results = get_rdf_results(model) | ||
| plot_rdfs(model, results) | ||
|
|
||
| for salt in IRON_SALTS: | ||
| r = results[salt][0] | ||
| g_r = results[salt][1] | ||
| peak_position[salt] = r[g_r.index(max(g_r))] | ||
|
|
||
| peak_difference = abs(peak_position["Fe2Cl"] - peak_position["Fe3Cl"]) | ||
|
|
||
| oxidation_state_passfail["Fe-O RDF Peak Split"][model] = 0.0 | ||
| oxidation_state_passfail["Peak Within Experimental Ref"][model] = 0.0 | ||
|
|
||
| if peak_difference > 0.07: | ||
| oxidation_state_passfail["Fe-O RDF Peak Split"][model] = 1.0 | ||
|
|
||
| if fe_2_ref[0] <= peak_position["Fe2Cl"] <= fe_2_ref[1]: | ||
| oxidation_state_passfail["Peak Within Experimental Ref"][model] += 0.5 | ||
|
|
||
| if fe_3_ref[0] <= peak_position["Fe3Cl"] <= fe_3_ref[1]: | ||
| oxidation_state_passfail["Peak Within Experimental Ref"][model] += 0.5 | ||
|
|
||
| return oxidation_state_passfail | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| @build_table( | ||
| filename=OUT_PATH / "oxidation_states_table.json", | ||
| metric_tooltips=DEFAULT_TOOLTIPS, | ||
| thresholds=DEFAULT_THRESHOLDS, | ||
| ) | ||
| def oxidation_states_passfail_metrics( | ||
| get_oxidation_states_passfail: dict[str, dict], | ||
| ) -> dict[str, dict]: | ||
| """ | ||
| Get all oxidation states pass fail metrics. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| get_oxidation_states_passfail | ||
| Dictionary of pass fail per model. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict[str, dict] | ||
| Dictionary of pass fail per model. | ||
| """ | ||
| return get_oxidation_states_passfail | ||
|
|
||
|
|
||
| def test_oxidation_states_passfail_metrics( | ||
| oxidation_states_passfail_metrics: dict[str, dict], | ||
| ) -> None: | ||
| """ | ||
| Run oxidation states test. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| oxidation_states_passfail_metrics | ||
| All oxidation states pass fail. | ||
| """ | ||
| return |
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,13 @@ | ||
| metrics: | ||
| Fe-O RDF Peak Split: | ||
| good: 1.0 | ||
| bad: 0.0 | ||
| unit: Yes(1)/No(0) | ||
| tooltip: Whether there is a split between Fe-O RDF peaks for different iron oxidation states | ||
| level_of_theory: Experimental | ||
| Peak Within Experimental Ref: | ||
| good: 1.0 | ||
| bad: 0.0 | ||
| unit: Yes(1)/No(0) | ||
| tooltip: Whether the RDF peak positions match experimental peaks | ||
| level_of_theory: Experimental | ||
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
89 changes: 89 additions & 0 deletions
89
ml_peg/app/physicality/oxidation_states/app_oxidation_states.py
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,89 @@ | ||
| """Run oxidation states app.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dash import Dash | ||
| from dash.html import Div | ||
|
|
||
| from ml_peg.app import APP_ROOT | ||
| from ml_peg.app.base_app import BaseApp | ||
| from ml_peg.app.utils.build_callbacks import ( | ||
| plot_from_table_cell, | ||
| ) | ||
| from ml_peg.app.utils.load import read_plot | ||
| from ml_peg.calcs import CALCS_ROOT | ||
| from ml_peg.models.get_models import get_model_names | ||
| from ml_peg.models.models import current_models | ||
|
|
||
| MODELS = get_model_names(current_models) | ||
|
|
||
| BENCHMARK_NAME = "Iron Oxidation States" | ||
| DATA_PATH = APP_ROOT / "data" / "physicality" / "oxidation_states" | ||
| REF_PATH = CALCS_ROOT / "physicality" / "oxidation_states" / "data" | ||
|
|
||
|
|
||
| class FeOxidationStatesApp(BaseApp): | ||
| """Fe Oxidation States benchmark app layout and callbacks.""" | ||
|
|
||
| def register_callbacks(self) -> None: | ||
| """Register callbacks to app.""" | ||
| scatter_plots = { | ||
| model: { | ||
| "Fe-O RDF Peak Split": read_plot( | ||
| DATA_PATH / f"Fe-O_{model}_RDF_scatter.json", | ||
| id=f"{BENCHMARK_NAME}-{model}-figure-Fe-O-RDF", | ||
| ), | ||
| "Peak Within Experimental Ref": read_plot( | ||
| DATA_PATH / f"Fe-O_{model}_RDF_scatter.json", | ||
| id=f"{BENCHMARK_NAME}-{model}-figure-Fe-O-RDF", | ||
| ), | ||
| } | ||
| for model in MODELS | ||
| } | ||
|
|
||
| plot_from_table_cell( | ||
| table_id=self.table_id, | ||
| plot_id=f"{BENCHMARK_NAME}-figure-placeholder", | ||
| cell_to_plot=scatter_plots, | ||
| ) | ||
|
|
||
|
|
||
| def get_app() -> FeOxidationStatesApp: | ||
| """ | ||
| Get Fe Oxidation States benchmark app layout and callback registration. | ||
|
|
||
| Returns | ||
| ------- | ||
| FeOxidationStatesApp | ||
| Benchmark layout and callback registration. | ||
| """ | ||
| return FeOxidationStatesApp( | ||
| name=BENCHMARK_NAME, | ||
| description=( | ||
| "Evaluate model ability to capture different oxidation states of Fe" | ||
| "from aqueous Fe 2Cl and Fe 3Cl MD RDFs" | ||
| ), | ||
| # docs_url=DOCS_URL, | ||
| table_path=DATA_PATH / "oxidation_states_table.json", | ||
| extra_components=[ | ||
| Div(id=f"{BENCHMARK_NAME}-figure-placeholder"), | ||
| Div(id=f"{BENCHMARK_NAME}-struct-placeholder"), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| # Create Dash app | ||
| full_app = Dash( | ||
| __name__, | ||
| assets_folder=DATA_PATH.parent.parent, | ||
| suppress_callback_exceptions=True, | ||
| ) | ||
|
|
||
| # Construct layout and register callbacks | ||
| FeOxidationStatesApp = get_app() | ||
| full_app.layout = FeOxidationStatesApp.layout | ||
| FeOxidationStatesApp.register_callbacks() | ||
|
|
||
| # Run app | ||
| full_app.run(port=8054, debug=True) |
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.