import argparse import os import time from dgl.data import QM9Dataset from dgl.dataloading import GraphDataLoader from rdkit import Chem from rdkit import RDLogger; from torch.utils.data import Dataset import torch.nn.functional as F from tqdm import tqdm import ast from QM9_dataset_class import PreprocessedQM9Dataset RDLogger.DisableLog('rdApp.*') import torch import torch.nn as nn import torch.optim as optim QM9_label_keys = ['mu','alpha','homo','lumo','gap','r2','zpve','U0','U','H','G','Cv'] def prepare_main(label_keys=None, cutoff=5.0,save_path="dataset"): assert save_path !="","save_path shouldn't be empty" if label_keys is None: raise ValueError('label_keys cannot be None') for label_key in label_keys: if label_key not in QM9_label_keys: raise ValueError('label_key must be in QM9_label_keys,refer:https://docs.dgl.ai/en/0.8.x/generated/dgl.data.QM9Dataset.html') dataset = QM9Dataset(label_keys=label_keys, cutoff=5.0) dataset_processed = PreprocessedQM9Dataset(dataset) print("Store processed QM9 dataset:",save_path) dataset_processed.save_dataset("dataset") return dataset_processed def main(): parser = argparse.ArgumentParser(description="Prepare QM9 dataset") parser.add_argument('--label_keys', nargs='+', help="label keys in QM9 dataset,like 'mu' 'gap'....") parser.add_argument('--cutoff', type=float, default=5.0, help="cutoff for atom number") parser.add_argument('--save_path', type=str, default="dataset", help="processed_dataset save path") args = parser.parse_args() prepare_main(label_keys=args.label_keys, cutoff=args.cutoff) if __name__ == '__main__': main()