HUANGYIFEI
commited on
add prepare_QM9_dataset.py
Browse files
Graph/GraphMAE_MQ9/prepare_QM9_dataset.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import os
|
3 |
+
import time
|
4 |
+
|
5 |
+
from dgl.data import QM9Dataset
|
6 |
+
from dgl.dataloading import GraphDataLoader
|
7 |
+
from rdkit import Chem
|
8 |
+
from rdkit import RDLogger;
|
9 |
+
from torch.utils.data import Dataset
|
10 |
+
import torch.nn.functional as F
|
11 |
+
from tqdm import tqdm
|
12 |
+
import ast
|
13 |
+
|
14 |
+
from QM9_dataset_class import PreprocessedQM9Dataset
|
15 |
+
|
16 |
+
RDLogger.DisableLog('rdApp.*')
|
17 |
+
import torch
|
18 |
+
import torch.nn as nn
|
19 |
+
import torch.optim as optim
|
20 |
+
|
21 |
+
|
22 |
+
QM9_label_keys = ['mu','alpha','homo','lumo','gap','r2','zpve','U0','U','H','G','Cv']
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
def prepare_main(label_keys=None, cutoff=5.0,save_path="dataset"):
|
27 |
+
assert save_path !="","save_path shouldn't be empty"
|
28 |
+
if label_keys is None:
|
29 |
+
raise ValueError('label_keys cannot be None')
|
30 |
+
for label_key in label_keys:
|
31 |
+
if label_key not in QM9_label_keys:
|
32 |
+
raise ValueError('label_key must be in QM9_label_keys,refer:https://docs.dgl.ai/en/0.8.x/generated/dgl.data.QM9Dataset.html')
|
33 |
+
dataset = QM9Dataset(label_keys=label_keys, cutoff=5.0)
|
34 |
+
dataset_processed = PreprocessedQM9Dataset(dataset)
|
35 |
+
print("Store processed QM9 dataset:",save_path)
|
36 |
+
dataset_processed.save_dataset("dataset")
|
37 |
+
return dataset_processed
|
38 |
+
|
39 |
+
def main():
|
40 |
+
parser = argparse.ArgumentParser(description="Prepare QM9 dataset")
|
41 |
+
parser.add_argument('--label_keys', nargs='+', help="label keys in QM9 dataset,like 'mu' 'gap'....")
|
42 |
+
parser.add_argument('--cutoff', type=float, default=5.0, help="cutoff for atom number")
|
43 |
+
parser.add_argument('--save_path', type=str, default="dataset", help="processed_dataset save path")
|
44 |
+
args = parser.parse_args()
|
45 |
+
prepare_main(label_keys=args.label_keys, cutoff=args.cutoff)
|
46 |
+
|
47 |
+
if __name__ == '__main__':
|
48 |
+
main()
|