Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
98228a2
back to working version
vict0rsch Apr 15, 2022
921f36f
import ocdata
vict0rsch Apr 15, 2022
bab34d2
add command-line sampler
vict0rsch Apr 20, 2022
27bbfe3
improve loadrs
vict0rsch Apr 20, 2022
27e60e6
explore further
vict0rsch May 20, 2022
5b36429
add "important" markers
vict0rsch Jun 6, 2022
fe7de46
parameterize adsorbates from smiles
vict0rsch Jun 7, 2022
c14bde5
more comments
vict0rsch Jun 7, 2022
7223640
print `out_times`
vict0rsch Jun 7, 2022
df7dcae
spacing
vict0rsch Jun 7, 2022
ac0786f
Merge branch 'main' into sample-adslab
vict0rsch Jun 7, 2022
956f030
Merge branch 'main' into sample-adslab
vict0rsch Jun 9, 2022
36db03f
sample adslab catch-all commit (uncertain)
vict0rsch Sep 6, 2022
422da8b
add script to make a slab
AlexDuvalinho Nov 15, 2023
09f210a
WIP w/ PLC
vict0rsch Nov 22, 2023
44f5f63
ignore cosmosis
vict0rsch Nov 22, 2023
7b8c5ad
Merge branch 'sample-adslab' of github.com:RolnickLab/ocp into sample…
vict0rsch Nov 22, 2023
bf03e59
flatslab
vict0rsch Nov 29, 2023
35b5995
Remove debug prints
carriepl-mila Dec 1, 2023
3513665
Allow instantiating Bulk without a bulk database
carriepl-mila Dec 4, 2023
3c5bdf3
Try increasingly large cutoffs when voronoi tesselation fails
carriepl-mila Dec 4, 2023
ada3e7f
Merge branch 'main' into sample-adslab
vict0rsch Jan 10, 2024
2d8f26b
Merge pull request #2 from RolnickLab/sample-adslab
vict0rsch Jan 10, 2024
89010b5
remove cosmosis
vict0rsch Jan 10, 2024
c7e0178
change setup
vict0rsch Jan 10, 2024
9510bc7
SemVer
vict0rsch Jan 10, 2024
9f22a19
install recursively
vict0rsch Jan 10, 2024
a0027b6
Use convert_path
vict0rsch Jan 10, 2024
a329735
dummy print
vict0rsch Jan 10, 2024
3f20c2d
remove print
vict0rsch Jan 10, 2024
faa05fb
is2re stats utils & notebook
vict0rsch Jan 16, 2024
186b357
import changes `fix adsorbates filtering` from `disconnected_gnn`
vict0rsch Jan 16, 2024
c93899a
fix ads filtering for val_ood_cat&both (from `disconnected_gnn`
vict0rsch Jan 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions adslab_parse_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import re
import json
from collections import defaultdict
from pathlib import Path

import matplotlib.cm as cmx
import matplotlib.colors as colors
import matplotlib.pyplot as plt
import numpy as np
from minydra import resolved_args
from tqdm import tqdm

if __name__ == "__main__":

args = resolved_args()

assert args.file is not None
assert Path(args.file).exists()
assert Path(args.file).is_file()

with open(args.file, "r") as f:
lines = f.read()

samples = [
s
for s in lines.split(
"------------------------------\n------------------------------"
)
if "Actions to Data" in s and "ABORTING" not in s
]

times = defaultdict(list)
metadatas = []
time_regex = re.compile(r"(.*) \| Done! \((.*)s\)")
total_adsorbed_regex = re.compile(r"Total adsorbed_surfaces: (\d+)")
non_reasonable_regex = re.compile(r"Non reasonable configs: (\d+)/(\d+)")

metadata_regexs = {
"adsorbate_id": re.compile(
r"args(?:\.actions|)\.adsorbate_id is None, choosing (\d+)"
),
"adsorbate_desc": re.compile(r"# Selected adsorbate: (.+)"),
"bulk_id": re.compile(r"args\.actions\.bulk_id is None, choosing (\d+)"),
"bulk_desc": re.compile(r"# Selected bulk: (.+)"),
"surface_id": re.compile(r"args\.actions\.surface_id is None, choosing (\d+)"),
"surface_desc": re.compile(r"# Selected surface: (.+)"),
"bond_indices": re.compile(r"bond_indices: (.+)"),
}

keys = []
time_keys = []
for s, sample in tqdm(enumerate(samples), total=len(samples)):
metadatas.append({})
matches = time_regex.findall(sample)
if not time_keys:
time_keys = set([k.strip() for k, _ in matches] + ["Actions to Data"])
matches += [
(
"Total adsorbed_surfaces",
int(total_adsorbed_regex.findall(sample)[0]),
),
(
"Proportion of non reasonable adsorbed_surfaces",
float(non_reasonable_regex.findall(sample)[0][0])
/ float(non_reasonable_regex.findall(sample)[0][1]),
),
]

for k, v in matches:
k = k.strip()
if "Actions to Data" in k:
k = "Actions to Data"
times[k].append(float(v))
metadatas[-1][k] = float(v)
if s == 0:
keys.append(k)
for name, reg in metadata_regexs.items():
meta = reg.findall(sample)[0]
if "id" in name:
meta = int(meta)
metadatas[-1][name] = meta

means = {k: m for k, v in times.items() if ((m := np.mean(v)) > 0.1)}
stds = {k: np.std(v) for k, v in times.items() if k in means}
keys = [k for k in keys if k in means]

cmap = plt.get_cmap("viridis")
cnorm = colors.Normalize(vmin=0, vmax=len(samples))
scalar_map = cmx.ScalarMappable(norm=cnorm, cmap=cmap)

n_plots = len(means.keys())

ncols = args.plot_ncols or 3
nrows = n_plots // ncols
if n_plots % ncols != 0:
nrows += 1

fig, axs = plt.subplots(nrows, ncols, figsize=(ncols * 5, nrows * 4))

for i, k in tqdm(enumerate(keys), total=len(keys)):
ax = axs.flat[i]
bars = ax.bar(range(len(times[k])), times[k])
for b, bar in enumerate(bars):
bar.set_color(scalar_map.to_rgba(b))

title = k
if k in time_keys:
title += f" ({means[k]:.2f}s +/- {stds[k]:.2f}s)"
else:
title += " (count)"

ax.set_title(title, fontsize=8)
ax.xaxis.set_tick_params(labelsize=6)
ax.yaxis.set_tick_params(labelsize=6)

plt.suptitle(f"Time (s) for operations or printed counts ({len(samples)} samples)")

plt.savefig(args.out_png or f"{Path(args.file).stem}.png", dpi=150)
with open(args.out_json or f"{Path(args.file).stem}.json", "w") as f:
json.dump(metadatas, f)
115 changes: 115 additions & 0 deletions configs/sample/defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# --------------------------------------------------------------
# ----- minydra default args values for sample_adslab.py -----
# --------------------------------------------------------------

# ------------------
# ----- Data -----
# ------------------
paths:
# path to the bulk_db_flat pickle file
bulk_db_flat: /network/projects/_groups/ocp/oc20/dataset-creation/bulk_db_flat_2021sep20.pkl

# path to the adsorbate_db pickle file
adsorbate_db: /network/projects/_groups/ocp/oc20/dataset-creation/adsorbate_db_2021apr28.pkl

# path to the precomputed_structures pickle file with all surfaces
precomputed_structures: /network/projects/_groups/ocp/oc20/dataset-creation/precomputed_surfaces_2021Sep20
# ------------------------------------
# ----- Adslab parametrization -----
# ------------------------------------

# random seed
seed: 123

# number of runs
nruns: 1

actions:
# adsorbate smiles representation (see end of this file for reference)
# null -> sample uniformly
adsorbate_smiles: null # H2O

# index of the bulk in bulk_db_flat.
# null -> sample uniformly
bulk_id: null

# index of the surface to select for a given bulk
# null -> sample uniformly
surface_id: null

# index of the adsorption site to select for a given surface
# can be -1 (=all), a list of ints or a single int
binding_site_index: -1


# whether or not to use pre-computed surfaces.
# if not they will be computed on the fly but it takes
use_precomputed_surfaces: true

# Loader animation
animate: false
# Ignore loader prints
no_loader: false

# prints
verbose: 0

# avaliable adsorbates smiles (82):
# {chemical_formula: smiles}
# { 'O': ['*O'],
# 'H': ['*H'],
# 'HO': ['*OH'],
# 'H2O': ['*OH2'],
# 'C': ['*C'],
# 'CO': ['*CO'],
# 'CH': ['*CH'],
# 'CHO': ['*CHO', '*COH'],
# 'CH2': ['*CH2'],
# 'CH2O': ['*CH2*O', '*CHOH'],
# 'CH3': ['*CH3'],
# 'CH3O': ['*OCH3', '*CH2OH'],
# 'CH4': ['*CH4'],
# 'CH4O': ['*OHCH3'],
# 'C2': ['*C*C'],
# 'C2O': ['*CCO'],
# 'C2H': ['*CCH'],
# 'C2HO': ['*CHCO', '*CCHO'],
# 'C2HO2': ['*COCHO'],
# 'C2H2O': ['*CCHOH', 'CH2*CO', '*CHCHO', 'CH*COH'],
# 'C2H2': ['*CCH2', '*CH*CH'],
# 'C2H2O2': ['*COCH2O', '*CHO*CHO', '*COHCHO', '*COHCOH'],
# 'C2H3': ['*CCH3', '*CHCH2'],
# 'C2H3O': ['*COCH3', '*OCHCH2', '*COHCH2', '*CHCHOH', '*CCH2OH'],
# 'C2H3O2': ['*CHOCHOH', '*COCH2OH', '*COHCHOH'],
# 'C2H4': ['*CH2*CH2'],
# 'C2H4O': ['*OCHCH3', '*COHCH3', '*CHOHCH2', '*CHCH2OH'],
# 'C2H4O2': ['*OCH2CHOH', '*CHOCH2OH', '*COHCH2OH', '*CHOHCHOH'],
# 'C2H5': ['*CH2CH3'],
# 'C2H5O': ['*OCH2CH3', '*CHOHCH3', '*CH2CH2OH'],
# 'C2H5O2': ['*CHOHCH2OH'],
# 'C2H6O': ['*OHCH2CH3'],
# 'C2H8N2': ['*NH2N(CH3)2'],
# 'C2H6N2O': ['*ONN(CH3)2'],
# 'CH4N2O': ['*OHNNCH3'],
# 'CH3N2': ['*NNCH3'],
# 'HNO': ['*ONH'],
# 'H2N2': ['*NHNH'],
# 'H4N2': ['*NHN2'],
# 'HN2': ['*N*NH'],
# 'N2O3': ['*ONNO2'],
# 'N2O4': ['*NO2NO2'],
# 'N2O': ['*N*NO'],
# 'N2': ['*N2'],
# 'H2N2O': ['*ONNH2'],
# 'H2N': ['*NH2'],
# 'H3N': ['*NH3'],
# 'HN2O': ['*NONH'],
# 'HN': ['*NH'],
# 'NO2': ['*NO2'],
# 'NO': ['*NO'],
# 'N': ['*N'],
# 'NO3': ['*NO3'],
# 'H3NO': ['*OHNH2'],
# 'HNO2': ['*ONOH'],
# 'CN': ['*CN']
# }
Loading