|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""TODO: File Description""" |
|
|
|
import json |
|
import gzip |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@article{Irwin2020, |
|
doi = {10.1021/acs.jcim.0c00675}, |
|
url = {https://doi.org/10.1021/acs.jcim.0c00675}, |
|
year = {2020}, |
|
month = oct, |
|
publisher = {American Chemical Society ({ACS})}, |
|
volume = {60}, |
|
number = {12}, |
|
pages = {6065--6073}, |
|
author = {John J. Irwin and Khanh G. Tang and Jennifer Young and Chinzorig Dandarchuluun and Benjamin R. Wong and Munkhzul Khurelbaatar and Yurii S. Moroz and John Mayfield and Roger A. Sayle}, |
|
title = {{ZINC}20{\textemdash}A Free Ultralarge-Scale Chemical Database for Ligand Discovery}, |
|
journal = {Journal of Chemical Information and Modeling} |
|
} |
|
|
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
This dataset contains ~1B molecules from ZINC20, with their SMILES and SELFIES representations. |
|
""" |
|
|
|
_HOMEPAGE = "https://zinc20.docking.org/" |
|
|
|
_LICENSE = "Open Data Commons Open Database License" |
|
|
|
|
|
FILES = [ |
|
"zinc_processed/smiles_all_01_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_57_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_86_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_90_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_66_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_37_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_98_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_24_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_69_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_95_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_42_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_13_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_70_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_58_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_67_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_94_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_54_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_89_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_41_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_15_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_81_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_33_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_25_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_07_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_28_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_20_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_05_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_74_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_84_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_34_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_02_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_43_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_62_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_72_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_16_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_64_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_63_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_59_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_35_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_21_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_04_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_39_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_78_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_96_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_08_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_52_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_09_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_56_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_44_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_77_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_32_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_30_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_40_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_23_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_82_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_53_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_46_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_18_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_60_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_19_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_50_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_31_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_65_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_10_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_55_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_48_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_27_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_17_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_29_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_88_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_99_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_45_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_49_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_92_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_36_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_11_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_85_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_26_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_76_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_83_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_97_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_93_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_87_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_79_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_06_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_12_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_71_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_73_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_68_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_00_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_61_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_14_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_51_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_80_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_47_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_22_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_75_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_38_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_03_clean.jsonl.gz", |
|
"zinc_processed/smiles_all_91_clean.jsonl.gz" |
|
] |
|
|
|
class PubchemSelfies(datasets.GeneratorBasedBuilder): |
|
"""A dataset of ZINC20 molecules represented as SELFIES.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
|
|
BUILDER_CONFIG = datasets.BuilderConfig( |
|
version=VERSION, description="A dataset of PubChem molecules represented as SELFIES." |
|
) |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
"selfies": datasets.Value("string"), |
|
"smiles": datasets.Value("string"), |
|
"id": datasets.Value("string"), |
|
} |
|
), |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_files = dl_manager.download(FILES) |
|
|
|
train_len = int(len(downloaded_files) * 0.8) |
|
valid_len = int(len(downloaded_files) * 0.1) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"subdirs": downloaded_files[:train_len], |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"subdirs": downloaded_files[train_len : train_len + valid_len], |
|
"split": "valid", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"subdirs": downloaded_files[-valid_len:], |
|
"split": "test", |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, subdirs, split): |
|
|
|
for filepath in subdirs: |
|
with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f: |
|
for row_idx, row in enumerate(f): |
|
data = json.loads(row) |
|
key = f"{os.path.basename(filepath)}_{row_idx}" |
|
yield key, { |
|
"smiles": data["smiles"], |
|
"selfies": data["selfies"], |
|
"id": data["id"], |
|
} |