This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Equi(Kit)Script for workflows that compute, transform, join representations and estimate properties #10
Draft
agoscinski
wants to merge
17
commits into
main
Choose a base branch
from
equikit
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
Equi(Kit)Script for workflows that compute, transform, join representations and estimate properties #10
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0a5dba6
first draft
agoscinski d7ee21c
Slight restructure
PicoCentauri 423c0e4
Allow floats for Ridge
PicoCentauri 1c07eda
a lot of fixes
agoscinski b59a769
hack for scoring
agoscinski 8e4e93b
tuples -> dict; hack for scoring
agoscinski ce69b11
transforming has to havppen after moving keys
agoscinski 9e172a1
adding partially working example
agoscinski e931335
added md calculator
agoscinski 97cf6aa
fix typos
agoscinski 61cd5d9
change example to something working with i-pi
agoscinski 4f04538
fixing stuff
agoscinski b9f03fb
Merge branch 'main' into equikit
PicoCentauri d8dae73
Merge branch 'main' into equikit
PicoCentauri 1a35b9b
fixing the multi_spectra_script notebook for thorben
agoscinski bccd644
updates required to do CV with thes script module
agoscinski 82aa2d5
fix for forces hist
agoscinski 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,9 @@ | ||
7 | ||
Lattice='100 0 0 0 100 0 0 0 100' | ||
O 5.40450e-01 -9.74850e-01 -2.16580e-01 | ||
O 2.92484e+00 -8.39252e-01 1.52397e-01 | ||
H 1.83860e-01 -1.25804e+00 -1.07875e+00 | ||
H 1.74329e+00 -9.09278e-01 -1.00395e-01 | ||
H 3.29707e+00 -1.59324e+00 6.47253e-01 | ||
H 3.53033e+00 -6.08138e-01 -5.76078e-01 | ||
H 4.23316e-02 -1.94860e-01 9.22810e-02 |
Binary file not shown.
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,227 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "c86f17cd", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import rascaline\n", | ||
"rascaline._c_lib._get_library()\n", | ||
"\n", | ||
"from copy import deepcopy\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"from equisolve.numpy.scripts import MultiSpectraScript\n", | ||
"from equisolve.numpy.models.linear_model import Ridge\n", | ||
"from equisolve.numpy.preprocessing import StandardScaler\n", | ||
"from equisolve.utils.convert import ase_to_tensormap\n", | ||
"\n", | ||
"import ase.io\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "a199029f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"frames = ase.io.read(\"water_converted.extxyz\", \":20\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "baca7fb8", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"HYPERS = {\n", | ||
" \"cutoff\": 3.0,\n", | ||
" \"max_radial\": 6,\n", | ||
" \"max_angular\": 4,\n", | ||
" \"atomic_gaussian_width\": 0.3,\n", | ||
" \"center_atom_weight\": 1.0,\n", | ||
" \"radial_basis\": {\"Gto\": {}},\n", | ||
" \"cutoff_function\": {\"ShiftedCosine\": {\"width\": 0.5}},\n", | ||
"}\n", | ||
"multi_spectra_hypers = {}\n", | ||
"#multi_spectra_hypers['Composition'] = {}\n", | ||
"multi_spectra_hypers['SoapRadialSpectrum'] = deepcopy(HYPERS)\n", | ||
"multi_spectra_hypers['SoapRadialSpectrum'].pop('max_angular')\n", | ||
"multi_spectra_hypers['SoapPowerSpectrum'] = deepcopy(HYPERS)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "0233bbb9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"y = ase_to_tensormap(frames, energy=\"TotEnergy\", forces=\"force\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "cdf7caa4", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"671.9636307759672" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Because all frames have the same species, we cannot scale, so we just subtract the mean\n", | ||
"#transformer_composition = StandardScaler(parameter_keys=[\"values\", \"positions\"], with_mean=True, with_std=False)\n", | ||
"# THIS IS BUGGY, something wrong in the standardizer when setting these flags to False\n", | ||
"\n", | ||
"transformer = StandardScaler(parameter_keys=[\"values\", \"positions\"])\n", | ||
"estimator = Ridge(parameter_keys=[\"values\", \"positions\"])\n", | ||
"script = MultiSpectraScript(multi_spectra_hypers,\n", | ||
" #transformer_X=transformer,\n", | ||
" #transformer_y=transformer,\n", | ||
" estimator=estimator)\n", | ||
"Xi = script.compute(systems=frames, gradients=[\"positions\"])\n", | ||
"script.fit(Xi, y, **{\"estimator_kwargs\": {\"alpha\": 1e-15}})\n", | ||
"script.score(Xi, y)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "902e9517", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pickle\n", | ||
"with open(\"multi_spectra_script-water.pickle\", \"wb\") as file:\n", | ||
" pickle.dump(script, file)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "3b640034", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# RESTART NOTEBOOK" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "99a94bf0", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pickle\n", | ||
"with open(\"multi_spectra_script-water.pickle\", \"rb\") as file:\n", | ||
" script = pickle.load(file)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "5369b107", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"-29201.186821558364\n", | ||
"\n", | ||
"[[-295.60671847 -4.62718863 -55.59864334]\n", | ||
" [ 298.54620907 4.04942317 37.15507667]\n", | ||
" [-221.68776379 -150.28232975 -242.81915489]\n", | ||
" [ -7.67013877 1.6028996 48.61326349]\n", | ||
" [ 176.03569875 -146.94124088 179.13481445]\n", | ||
" [ 286.69810363 136.65180697 -172.50009028]\n", | ||
" [-220.83316507 156.29491821 107.1942928 ]]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# in ipi\n", | ||
"\n", | ||
"import ase.io\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"structure = ase.io.read(\"h5o2+.extxyz\", \"0\")\n", | ||
"\n", | ||
"Xi = script.compute(systems=structure, gradients=[\"positions\"])\n", | ||
"y_pred = script.forward(Xi) # implicitely done in score function\n", | ||
"energy = y_pred.block().values[0][0]\n", | ||
"forces = np.array(y_pred.block().gradient(\"positions\").data.reshape(-1, 3))\n", | ||
"\n", | ||
"print(energy)\n", | ||
"print()\n", | ||
"print(forces)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "995fe798", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"<equisolve.numpy.scripts.md_calculator.GenericMDCalculator at 0x7f8d31a0d6a0>" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from equisolve.numpy.scripts import GenericMDCalculator\n", | ||
"\n", | ||
"from ipi.utils.mathtools import det_ut3x3\n", | ||
"from ipi.utils.units import unit_to_internal, unit_to_user\n", | ||
"\n", | ||
"\n", | ||
"md_calc = GenericMDCalculator(\"multi_spectra_script-water.pickle\",\n", | ||
" is_periodic=True,\n", | ||
" structure_template=\"h5o2+.extxyz\",\n", | ||
" atomic_numbers=[1,8])" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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.
didn't we said that we didn't want notebooks in the examples?