Skip to content

Commit

Permalink
Overhauling tutorial 5 to reflect changes to ML
Browse files Browse the repository at this point in the history
  • Loading branch information
elinscott committed Aug 12, 2024
1 parent 6b05f1d commit 4d23632
Show file tree
Hide file tree
Showing 30 changed files with 611 additions and 11,041 deletions.
176 changes: 76 additions & 100 deletions docs/tutorials/tutorial_5.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tutorials/tutorial_4/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ecutwfc*
??-singlepoint-ecutwfc*
3 changes: 1 addition & 2 deletions tutorials/tutorial_5/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
snapshot_*
convergence_analysis/
??-koopmans-dscf-*
446 changes: 446 additions & 0 deletions tutorials/tutorial_5/01-train/h2o_train.out

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.17640523 3.15916572 3.45632380
H 3.50148932 4.19880580 3.51512221
H 3.70180884 2.86571428 2.63122811
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.04105985 3.13355436 3.50387735
H 3.35350377 4.02421750 3.65723632
H 3.64016743 3.03025791 2.62103417
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.03130677 3.03374043 3.10315102
H 3.34276186 4.09849362 3.53863350
H 3.83377546 2.73541343 2.64612585
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.98128161 3.27242792 3.50538588
H 3.29289474 4.04986625 3.52407143
H 3.40872035 2.84605879 2.65718490
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.12302907 3.23938798 3.31971732
H 3.24716972 3.90719470 3.47084821
H 3.43617298 3.07592754 2.59058478
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"ml": {
"predict": true,
"model_file": "../train/h2o_train_ml_model.pkl",
"model_file": "../01-train/h2o_train_ml_model.pkl",
"n_max": 6,
"l_max": 6,
"r_min": 1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

if __name__ == '__main__':
# Extract the eigenvalue information from the .kwf file
wf = io.read('tutorial_5a/predict/h2o_predict.kwf')
calcs = [c for c in wf.calculations if c.prefix == 'ki_final']
wf = io.read('h2o_predict.kwf')
calcs = [c for c in wf.calculations if c.prefix == 'ki_final_ml']
eigenvalues = np.array([c.results['eigenvalues'][0] for c in calcs])

# Create a violin plot figure
Expand All @@ -21,8 +21,8 @@
# Figure aesthetics
n_orbs_occ = 4
n_orbs = 6
labels = [f'HOMO - {n_orbs_occ - i}' for i in range(1, n_orbs_occ)] + ['HOMO',
'LUMO'] + [f'LUMO + {i - n_orbs_occ}' for i in range(n_orbs_occ + 1, n_orbs)]
labels = [f'HOMO - {n_orbs_occ - i}' for i in range(1, n_orbs_occ)] + ['HOMO', 'LUMO'] \
+ [f'LUMO + {i - n_orbs_occ}' for i in range(n_orbs_occ + 1, n_orbs)]
ax.set_yticks(range(1, n_orbs + 1), labels)
ax.set_xlabel('energy (eV)')
plt.tight_layout()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.95619257 2.99387046 3.43619904
H 3.11601022 3.99077597 3.52330334
H 3.64549025 2.82976949 2.52348678
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.99718178 3.16198319 3.36510172
H 3.30764719 3.94861779 3.57657588
H 3.53955396 2.84489468 2.56023537
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.82737174 3.13689261 3.31827191
H 3.11438017 4.05832823 3.52212016
H 3.61199454 2.95375906 2.65444829
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.11394007 2.99566742 3.39868416
H 3.20891899 3.92497029 3.55496503
H 3.57564475 2.88646653 2.52503502
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.09008265 3.16571624 3.20482563
H 3.42622522 4.20163892 3.73072796
H 3.58880752 2.77377474 2.74699517
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.95968231 3.24139451 3.37927750
H 3.37506390 4.04768664 3.68350732
H 3.60785000 3.05943705 2.65424121
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.04019894 3.30746507 3.22367409
H 3.15035150 4.10898967 3.49553766
H 3.80116212 2.83948810 2.56680452
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.19229420 3.26720148 3.54520590
H 3.36800447 3.92592743 3.80385650
H 3.57999966 2.96109564 2.73627520
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.98449899 3.18055794 3.45067067
H 3.31504255 3.90210992 3.64267382
H 3.73943859 2.81139321 2.62658655
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.95648464 3.30407637 3.42567948
H 3.31814618 3.93505839 3.66677492
H 3.53936673 2.88403306 2.57796539
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.06764333 3.17680908 3.33762012
H 3.31700067 3.90274385 3.46372424
H 3.65073917 2.89751735 2.70505314
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.23831448 3.21359795 3.26716778
H 3.38910163 3.88045926 3.56669154
H 3.59997584 3.05218427 2.56707452
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.91735615 3.10930475 3.29210217
H 3.39006359 3.90405685 3.49810313
H 3.56301800 2.83104675 2.83450321
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.09494208 3.12790512 3.23590645
H 3.36183630 3.91202847 3.45837289
H 3.72560298 2.91254426 2.73363588
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.03187277 3.20483306 3.29334744
H 3.17397572 4.08020945 3.53250903
H 3.53784502 2.83529675 2.64329792
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"ml": {
"test": true,
"model_file": "../train/h2o_train_ml_model.pkl",
"model_file": "../01-train/h2o_train_ml_model.pkl",
"n_max": 6,
"l_max": 6,
"r_min": 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import copy

import matplotlib.pyplot as plt
import numpy as np

from koopmans import io, utils
from koopmans.ml import MLModel
from koopmans.workflows import InitializationWorkflow, KoopmansDSCFWorkflow
from koopmans import io

# Load the workflow python object from the .kwf file
wf = io.read('tutorial_5a/test/h2o_test.kwf')
wf = io.read('h2o_test.kwf')

# Select the calculations that correspond to the final KI calculations using predicted/ab initio screening parameters
calculations_with_predicted_alpha = [c for c in wf.calculations if c.prefix == 'ki_final_ml']
Expand All @@ -23,7 +19,7 @@
fig, [ax0, ax1] = plt.subplots(1, 2, figsize=(6, 3))

# Scatterplot
ax0.plot(true_orbital_energies, predicted_orbital_energies, 'o')
ax0.plot(true_orbital_energies, predicted_orbital_energies, 'o', alpha=0.5, markeredgewidth=0)
xylimits = ax0.get_xlim() + ax0.get_ylim()
limits = [min(xylimits), max(xylimits)]
ax0.plot(limits, limits, color='k', linestyle='--', zorder=-1, lw=1)
Expand All @@ -34,10 +30,16 @@
ax0.set_ylabel(r'$\varepsilon^\mathrm{predicted}_i$ (eV)')

# Histogram
ax1.hist(errors, bins=20, orientation='vertical')
errors_meV = errors * 1000
ax1.hist(errors_meV, bins=20, orientation='vertical')
ax1.axvline(0, color='black', linestyle='--', lw=1)
ax1.set_yticks([])
ax1.set_xlabel(r'$\varepsilon^\mathrm{predicted}_i - \varepsilon^\mathrm{true}_i$ (eV)')
ax1.set_xlabel(r'$\varepsilon^\mathrm{predicted}_i - \varepsilon^\mathrm{true}_i$ (meV)')
std = np.std(errors_meV)
ymax = ax1.get_ylim()[1]
ax1.fill_betweenx([0, ymax], -std, std, color='gray', alpha=0.5, lw=0)
ax1.set_ylim(0, ymax)
ax1.text(0.98, 0.98, f'$\sigma = {std:.0f}$ meV', transform=ax1.transAxes, ha='right', va='top')

# Save the figure
plt.subplots_adjust(left=0.12, right=0.99, top=0.98, bottom=0.18, wspace=0.07)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.95619257 2.99387046 3.43619904
H 3.11601022 3.99077597 3.52330334
H 3.64549025 2.82976949 2.52348678
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.99718178 3.16198319 3.36510172
H 3.30764719 3.94861779 3.57657588
H 3.53955396 2.84489468 2.56023537
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.82737174 3.13689261 3.31827191
H 3.11438017 4.05832823 3.52212016
H 3.61199454 2.95375906 2.65444829
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.11394007 2.99566742 3.39868416
H 3.20891899 3.92497029 3.55496503
H 3.57564475 2.88646653 2.52503502
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.09008265 3.16571624 3.20482563
H 3.42622522 4.20163892 3.73072796
H 3.58880752 2.77377474 2.74699517
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.95968231 3.24139451 3.37927750
H 3.37506390 4.04768664 3.68350732
H 3.60785000 3.05943705 2.65424121
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.04019894 3.30746507 3.22367409
H 3.15035150 4.10898967 3.49553766
H 3.80116212 2.83948810 2.56680452
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.19229420 3.26720148 3.54520590
H 3.36800447 3.92592743 3.80385650
H 3.57999966 2.96109564 2.73627520
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.98449899 3.18055794 3.45067067
H 3.31504255 3.90210992 3.64267382
H 3.73943859 2.81139321 2.62658655
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.95648464 3.30407637 3.42567948
H 3.31814618 3.93505839 3.66677492
H 3.53936673 2.88403306 2.57796539
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.06764333 3.17680908 3.33762012
H 3.31700067 3.90274385 3.46372424
H 3.65073917 2.89751735 2.70505314
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.23831448 3.21359795 3.26716778
H 3.38910163 3.88045926 3.56669154
H 3.59997584 3.05218427 2.56707452
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 2.91735615 3.10930475 3.29210217
H 3.39006359 3.90405685 3.49810313
H 3.56301800 2.83104675 2.83450321
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.09494208 3.12790512 3.23590645
H 3.36183630 3.91202847 3.45837289
H 3.72560298 2.91254426 2.73363588
3
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 #=T Configuration=T 1=T pbc="T T T"
Lattice="6.8929 0.0 0.0 0.0 6.8929 0.0 0.0 0.0 6.8929" Properties=species:S:1:pos:R:3 pbc="T T T"
O 3.03187277 3.20483306 3.29334744
H 3.17397572 4.08020945 3.53250903
H 3.53784502 2.83529675 2.64329792
2 changes: 2 additions & 0 deletions tutorials/tutorial_5/04-advanced-testing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ab_initio
ml
Loading

0 comments on commit 4d23632

Please sign in to comment.