dataset script
Browse files- sagan-mc.py +107 -0
sagan-mc.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
_CITATION = """
|
7 |
+
@inproceedings{gebhard2022inferring,
|
8 |
+
title={Inferring molecular complexity from mass spectrometry data using machine learning},
|
9 |
+
author={Gebhard, Timothy D and Bell, Aaron C and Gong, Jian and Hastings, Jaden J. A. and Fricke, G. Matthew and Cabrol, Nathalie and Sandford, Scott and Phillips, Michael and Warren-Rhodes, Kimberley and Baydin, Atilim Gunes},
|
10 |
+
booktitle={NeurIPS Workshop on Machine Learning and the Physical Sciences},
|
11 |
+
year={2022}
|
12 |
+
}
|
13 |
+
"""
|
14 |
+
|
15 |
+
_DESCRIPTION = """
|
16 |
+
SaganMC is a molecular dataset designed to support machine learning research in molecular complexity inference. It includes over 400,000 molecules with computed structural, physico-chemical, and complexity descriptors, and a subset of ~16k molecules that additionally include experimental mass spectra.
|
17 |
+
"""
|
18 |
+
|
19 |
+
_HOMEPAGE = "https://huggingface.co/datasets/oxai4science/sagan-mc"
|
20 |
+
_LICENSE = "CC-BY-4.0"
|
21 |
+
|
22 |
+
_URLS = {
|
23 |
+
"sagan-mc-400k": "https://huggingface.co/datasets/oxai4science/sagan-mc/resolve/main/sagan-mc-400k.csv",
|
24 |
+
"sagan-mc-spectra-16k": "https://huggingface.co/datasets/oxai4science/sagan-mc/resolve/main/sagan-mc-spectra-16k.csv",
|
25 |
+
}
|
26 |
+
|
27 |
+
class SaganMC(datasets.GeneratorBasedBuilder):
|
28 |
+
VERSION = datasets.Version("1.0.0")
|
29 |
+
|
30 |
+
BUILDER_CONFIGS = [
|
31 |
+
datasets.BuilderConfig(name="sagan-mc-400k", version=VERSION, description="Full dataset with ~400k molecules"),
|
32 |
+
datasets.BuilderConfig(name="sagan-mc-spectra-16k", version=VERSION, description="Subset with mass spectra (~16k molecules)"),
|
33 |
+
]
|
34 |
+
|
35 |
+
DEFAULT_CONFIG_NAME = "sagan-mc-400k"
|
36 |
+
|
37 |
+
def _info(self):
|
38 |
+
features = datasets.Features({
|
39 |
+
"inchi": datasets.Value("string"),
|
40 |
+
"inchikey": datasets.Value("string"),
|
41 |
+
"selfies": datasets.Value("string"),
|
42 |
+
"smiles": datasets.Value("string"),
|
43 |
+
"smiles_scaffold": datasets.Value("string"),
|
44 |
+
"formula": datasets.Value("string"),
|
45 |
+
"fingerprint_morgan": datasets.Value("string"),
|
46 |
+
"num_atoms": datasets.Value("int32"),
|
47 |
+
"num_atoms_all": datasets.Value("int32"),
|
48 |
+
"num_bonds": datasets.Value("int32"),
|
49 |
+
"num_bonds_all": datasets.Value("int32"),
|
50 |
+
"num_rings": datasets.Value("int32"),
|
51 |
+
"num_aromatic_rings": datasets.Value("int32"),
|
52 |
+
"physchem_mol_weight": datasets.Value("float"),
|
53 |
+
"physchem_logp": datasets.Value("float"),
|
54 |
+
"physchem_tpsa": datasets.Value("float"),
|
55 |
+
"physchem_qed": datasets.Value("float"),
|
56 |
+
"physchem_h_acceptors": datasets.Value("int32"),
|
57 |
+
"physchem_h_donors": datasets.Value("int32"),
|
58 |
+
"physchem_rotatable_bonds": datasets.Value("int32"),
|
59 |
+
"physchem_fraction_csp3": datasets.Value("float"),
|
60 |
+
"mass_spectrum_nist": datasets.Value("string"),
|
61 |
+
"complex_ma_score": datasets.Value("int32"),
|
62 |
+
"complex_ma_runtime": datasets.Value("float"),
|
63 |
+
"complex_bertz_score": datasets.Value("float"),
|
64 |
+
"complex_bertz_runtime": datasets.Value("float"),
|
65 |
+
"complex_boettcher_score": datasets.Value("float"),
|
66 |
+
"complex_boettcher_runtime": datasets.Value("float"),
|
67 |
+
"synth_sa_score": datasets.Value("float"),
|
68 |
+
"meta_cas_number": datasets.Value("string"),
|
69 |
+
"meta_names": datasets.Value("string"),
|
70 |
+
"meta_iupac_name": datasets.Value("string"),
|
71 |
+
"meta_comment": datasets.Value("string"),
|
72 |
+
"meta_origin": datasets.Value("string"),
|
73 |
+
"meta_reference": datasets.Value("string"),
|
74 |
+
"split": datasets.ClassLabel(names=["train", "val", "test"])
|
75 |
+
})
|
76 |
+
return datasets.DatasetInfo(
|
77 |
+
description=_DESCRIPTION,
|
78 |
+
features=features,
|
79 |
+
homepage=_HOMEPAGE,
|
80 |
+
license=_LICENSE,
|
81 |
+
citation=_CITATION,
|
82 |
+
)
|
83 |
+
|
84 |
+
def _split_generators(self, dl_manager):
|
85 |
+
url = _URLS[self.config.name]
|
86 |
+
data_path = dl_manager.download_and_extract(url)
|
87 |
+
return [
|
88 |
+
datasets.SplitGenerator(
|
89 |
+
name=datasets.Split.TRAIN,
|
90 |
+
gen_kwargs={"filepath": data_path, "split_name": "train"},
|
91 |
+
),
|
92 |
+
datasets.SplitGenerator(
|
93 |
+
name=datasets.Split.VALIDATION,
|
94 |
+
gen_kwargs={"filepath": data_path, "split_name": "val"},
|
95 |
+
),
|
96 |
+
datasets.SplitGenerator(
|
97 |
+
name=datasets.Split.TEST,
|
98 |
+
gen_kwargs={"filepath": data_path, "split_name": "test"},
|
99 |
+
),
|
100 |
+
]
|
101 |
+
|
102 |
+
def _generate_examples(self, filepath, split_name):
|
103 |
+
with open(filepath, encoding="utf-8") as f:
|
104 |
+
reader = csv.DictReader(f)
|
105 |
+
for idx, row in enumerate(reader):
|
106 |
+
if row["split"] == split_name:
|
107 |
+
yield idx, row
|