-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_cross_valid.py
115 lines (71 loc) · 2.78 KB
/
generate_cross_valid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
# coding: utf-8
# # Define Globals
# In[1]:
import os
from pathlib import Path
import numpy as np
import shutil
# In[2]:
# Original database path
database_path = "./"
# Splited validation set rate (only apply to atom_11 and atom_12)
database_split_rate = 0.02
# Splited validation sets
database_split_number = 5
# In[3]:
def makedirs(path):
try:
os.makedirs(path)
except FileExistsError:
pass
# In[4]:
# Make nessary directories
# makedirs(Path(database_destination_path) / "raw" / "dev")
for i in range(database_split_number):
for j in ["11", "12"]:
makedirs(Path(database_path) / "raw" / "valid_{:02d}".format(i) / "sdf" / ("atom_" + j))
# # Copy file by probability
# In[5]:
for j in ["11", "12"]:
np.random.seed(0)
copy_file_idx = np.array([int(i[:-4]) for i in os.listdir(Path(database_path) / "raw-orig" / "valid" / "sdf" / ("atom_" + j))])
np.random.shuffle(copy_file_idx)
copy_batch = int(copy_file_idx.size * database_split_rate) + 1
for i in range(database_split_number):
for k in copy_file_idx[copy_batch * i : copy_batch * (i + 1)]:
shutil.copy(
Path(database_path) / "raw-orig" / "valid" / "sdf" / ("atom_" + j) / (str(k) + ".sdf"),
Path(database_path) / "raw" / "valid_{:02d}".format(i) / "sdf" / ("atom_" + j) / (str(k) + ".sdf"),
)
# # Dev and Test set
# In[8]:
database_crop_rate = 0.01
for j in ["9", "10", "11", "12"]:
makedirs(Path(database_path) / "raw" / "dev" / "sdf" / ("atom_" + j))
# In[10]:
for j in ["9", "10", "11", "12"]:
np.random.seed(0)
copy_file_idx = np.array([int(i[:-4]) for i in os.listdir(Path(database_path) / "raw-orig" / "dev" / "sdf" / ("atom_" + j))])
np.random.shuffle(copy_file_idx)
copy_batch = int(copy_file_idx.size * database_crop_rate) + 1
for k in copy_file_idx[:copy_batch]:
shutil.copy(
Path(database_path) / "raw-orig" / "dev" / "sdf" / ("atom_" + j) / (str(k) + ".sdf"),
Path(database_path) / "raw" / "dev" / "sdf" / ("atom_" + j) / (str(k) + ".sdf"),
)
# In[11]:
database_crop_rate = 0.01
for j in ["11", "12"]:
makedirs(Path(database_path) / "raw" / "test" / "sdf" / ("atom_" + j))
# In[12]:
for j in ["11", "12"]:
np.random.seed(0)
copy_file_idx = np.array([int(i[:-4]) for i in os.listdir(Path(database_path) / "raw-orig" / "test" / "sdf" / ("atom_" + j))])
np.random.shuffle(copy_file_idx)
copy_batch = int(copy_file_idx.size * database_crop_rate) + 1
for k in copy_file_idx[:copy_batch]:
shutil.copy(
Path(database_path) / "raw-orig" / "test" / "sdf" / ("atom_" + j) / (str(k) + ".sdf"),
Path(database_path) / "raw" / "test" / "sdf" / ("atom_" + j) / (str(k) + ".sdf"),
)