<jupyter_start><jupyter_text>Datasets Dataset* One-hot-encoding atoms: types = {'H': 0, 'C': 1, 'N': 2, 'O': 3, 'F': 4}* Atomic number* Position in xyz * Type of hybridization * Types of bounds Label Description|Index | Name | Units | Description| |:-----|-------|-------|-----------:|  |0  |index  |   -            |Consecutive, 1-based integer identifier of molecule|  |1  |mu     |   Debye        |Dipole moment|  |2  |alpha  |   Bohr^3       |Isotropic polarizability|  |3  |homo   |   Hartree      |Energy of Highest occupied molecular orbital (HOMO)|  |4  |lumo   |   Hartree      |Energy of Lowest unoccupied molecular orbital (LUMO)| |5 | gap   |    Hartree     | Gap, difference between LUMO and HOMO| |6 | r2    |    Bohr^2      | Electronic spatial extent| |7 | zpve  |    Hartree     | Zero point vibrational energy| |8 | U0    |    Hartree     | Internal energy at 0 K| |9 | U     |    Hartree     | Internal energy at 298.15 K| |10 | H     |    Hartree     | Enthalpy at 298.15 K| |11 | G     |    Hartree     | Free energy at 298.15 K| |12 | Cv    |    cal/(mol K) | Heat capacity at 298.15 K|<jupyter_code>targets = ["mu", "alpha", "homo", "lumo", "gap", "r2", "ZPVE", "U0", "U", "H", "G", "Cv"]<jupyter_output><empty_output><jupyter_text>Calculate MEA based on median<jupyter_code>from shared import QM9MainDatamodule

datamodule = QM9MainDatamodule()
datamodule.setup()
from shared import calculate_metrics
ys =  datamodule.train_set.data.y
ys = (ys - ys.mean(axis=0))/ ys.std(axis=0)
ms = ys.median(axis=0).values

maes, std_maes, _, std_mae = calculate_metrics(ms, ys)
print("std. MAE in % based on median:", std_mae * 100)
medians = pd.DataFrame({"target":targets, "always_median_model":maes})
from ipynb.fs.full.train_dimenet import GraphQM9Datamodule, DimeNet
from ipynb.fs.full.train_schnet import SchNetModule
from ipynb.fs.full.train_ff import FeedforwadModule, FlattenQM9Datamodule

def get_dict_with_prefix(d, prefix):
    return {k[len(prefix):]: v for k, v in d.items() if k.startswith(prefix)}
path = "/home/azapala/quantum_mechanics_of_molecules/lightning_logs/schnet/with_gradient_clip/checkpoints/schnet-epoch199-val_loss0.00.ckpt"
logger = pl.loggers.tensorboard.TensorBoardLogger("./lightning_logs/", name='schnet', version='with_gradient_clip')

datamodule = GraphQM9Datamodule()
model = SchNetModule.load_from_checkpoint(path)
trainer = pl.Trainer(gpus=[1], logger=logger)
res = trainer.test(model, datamodule)

schnet = pd.DataFrame.from_dict(get_dict_with_prefix(res[0], "maes/"), orient="index",columns=["%maes_shcnet"])
import torch.nn.functional as F
from shared import Module

class DimeNetModule(Module):
    def __init__(self, **kwargs):
        super().__init__()
        kwargs.pop('lr',0)
        self.net = DimeNet(**kwargs)
        
    def step(self, batch, batch_idx):
        z, pos, y, g_batch = batch.z, batch.pos, batch.y, batch.batch
        output = self.net(z, pos, g_batch)
        loss = F.l1_loss(output, y)
        return loss, output.detach(), y.detach()
path = "/home/azapala/quantum_mechanics_of_molecules/lightning_logs/dimenet/with_gradient_clip/checkpoints/dimenet-epoch53-val_loss0.00.ckpt"
logger = pl.loggers.tensorboard.TensorBoardLogger("./lightning_logs/", name='dimenet', version='with_gradient_clip')

datamodule = GraphQM9Datamodule()
model = DimeNetModule.load_from_checkpoint(path)
trainer = pl.Trainer(gpus=[1], logger=logger)
res = trainer.test(model, datamodule)

dimenet = pd.DataFrame.from_dict(get_dict_with_prefix(res[0], "maes/"), orient="index",columns=["%maes_dimenet"])
path = "/home/azapala/quantum_mechanics_of_molecules/lightning_logs/feedforward_2_hidden_layers/version_0/checkpoints/feedforward-epoch42-val_loss0.00.ckpt"
logger = pl.loggers.tensorboard.TensorBoardLogger("./lightning_logs/", name='feedforward_2_hidden_layers', version='version_0')

datamodule = FlattenQM9Datamodule()
model = FeedforwadModule.load_from_checkpoint(path)
trainer = pl.Trainer(gpus=[1], logger=logger)
res = trainer.test(model, datamodule)

ff = pd.DataFrame.from_dict(get_dict_with_prefix(res[0], "maes/"), orient="index",columns=["%maes_ff"])
df_res = pd.concat([dimenet, schnet, medians.set_index('target'), ff], axis=1)
df_res
df_res.mean().to_frame("std_mea")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14553111839026672, 'fraction_numerical': 0.02129153018249883, 'mean_word_length': 4.5519480519480515, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '169668', 'license': 'MIT', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1562, 'n_words': 316, 'path': 'results.ipynb', 'repo_name': 'a-zapala/quantum_chemistry', 'size': '4274'}