hermanhugging commited on
Commit
c98b336
·
verified ·
1 Parent(s): 76fa170

Upload 2 files

Browse files
data/util/prepare_dataset_co2.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Prepare dataset_CO2: copies _init.cif files, writes id_prop.csv without .cif extension.
4
+ Filters by |adsorption_energy| <= 2.
5
+ """
6
+
7
+ import shutil
8
+ import csv
9
+ from pathlib import Path
10
+
11
+ def main():
12
+ base_dir = Path("/media/herman/New Volume/Aixelo/DatasetAix/ODAC")
13
+ pristine_co2_dir = base_dir / "pristine_CO2" / "pristine_CO2"
14
+ adsorption_energy_file = base_dir / "adsorption_energy.txt"
15
+ output_dir = base_dir / "dataset_CO2"
16
+ raw_dir = output_dir / "raw"
17
+
18
+ raw_dir.mkdir(parents=True, exist_ok=True)
19
+
20
+ print("Reading adsorption_energy.txt...")
21
+ energy_data = {}
22
+ with open(adsorption_energy_file, 'r') as f:
23
+ for line in f:
24
+ line = line.strip()
25
+ if not line:
26
+ continue
27
+ parts = line.split()
28
+ if len(parts) >= 2:
29
+ try:
30
+ energy_data[parts[0]] = float(parts[1])
31
+ except ValueError:
32
+ continue
33
+ print(f"Loaded {len(energy_data)} entries")
34
+
35
+ print("Finding _init.cif files...")
36
+ init_files = list(pristine_co2_dir.rglob("*_init.cif"))
37
+ print(f"Found {len(init_files)} _init.cif files")
38
+
39
+ matched_files = []
40
+ for cif_path in init_files:
41
+ filename = cif_path.name # e.g. ABEFUL_w_CO2_1_init.cif
42
+ if not filename.endswith("_init.cif"):
43
+ continue
44
+ base_name = filename[:-9] # remove "_init.cif" (9 chars) → ABEFUL_w_CO2_1
45
+ if base_name in energy_data:
46
+ energy = energy_data[base_name]
47
+ if abs(energy) <= 2:
48
+ matched_files.append((cif_path, base_name, energy))
49
+
50
+ print(f"Matched {len(matched_files)} files with |energy| <= 2")
51
+
52
+ csv_data = []
53
+ for cif_path, base_name, energy in matched_files:
54
+ dest_path = raw_dir / f"{base_name}.cif" # rename: убираем _init суффикс тоже (опционально)
55
+ shutil.copy2(cif_path, dest_path)
56
+ csv_data.append((base_name, energy)) # БЕЗ .cif расширения
57
+
58
+ csv_path = output_dir / "id_prop.csv"
59
+ print(f"Writing {csv_path}...")
60
+ with open(csv_path, 'w', newline='') as f:
61
+ writer = csv.writer(f)
62
+ writer.writerow(['odac_id', 'adsorption_energy'])
63
+ for odac_id, energy in csv_data:
64
+ writer.writerow([odac_id, energy])
65
+
66
+ print(f"Done! {len(csv_data)} entries written.")
67
+ print(f" raw/ → {raw_dir}")
68
+ print(f" csv → {csv_path}")
69
+
70
+ if __name__ == "__main__":
71
+ main()
data/util/prepare_dataset_h2o.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Prepare dataset_H2O: copies _init.cif files, writes id_prop.csv without .cif extension.
4
+ Filters by |adsorption_energy| <= 2.
5
+ """
6
+
7
+ import shutil
8
+ import csv
9
+ from pathlib import Path
10
+
11
+ def main():
12
+ base_dir = Path("/media/herman/New Volume/Aixelo/DatasetAix/ODAC")
13
+ pristine_h2o_dir = base_dir / "pristine_H2O" / "pristine_H2O"
14
+ adsorption_energy_file = base_dir / "adsorption_energy.txt"
15
+ output_dir = base_dir / "dataset_H2O"
16
+ raw_dir = output_dir / "raw"
17
+
18
+ raw_dir.mkdir(parents=True, exist_ok=True)
19
+
20
+ print("Reading adsorption_energy.txt...")
21
+ energy_data = {}
22
+ with open(adsorption_energy_file, 'r') as f:
23
+ for line in f:
24
+ line = line.strip()
25
+ if not line:
26
+ continue
27
+ parts = line.split()
28
+ if len(parts) >= 2:
29
+ try:
30
+ energy_data[parts[0]] = float(parts[1])
31
+ except ValueError:
32
+ continue
33
+ print(f"Loaded {len(energy_data)} entries")
34
+
35
+ print("Finding _init.cif files...")
36
+ init_files = list(pristine_h2o_dir.rglob("*_init.cif"))
37
+ print(f"Found {len(init_files)} _init.cif files")
38
+
39
+ matched_files = []
40
+ for cif_path in init_files:
41
+ filename = cif_path.name # e.g. ABEFUL_w_H2O_1_init.cif
42
+ if not filename.endswith("_init.cif"):
43
+ continue
44
+ base_name = filename[:-9] # remove "_init.cif" → ABEFUL_w_H2O_1
45
+ if base_name in energy_data:
46
+ energy = energy_data[base_name]
47
+ if abs(energy) <= 2:
48
+ matched_files.append((cif_path, base_name, energy))
49
+
50
+ print(f"Matched {len(matched_files)} files with |energy| <= 2")
51
+
52
+ csv_data = []
53
+ for cif_path, base_name, energy in matched_files:
54
+ dest_path = raw_dir / f"{base_name}.cif"
55
+ shutil.copy2(cif_path, dest_path)
56
+ csv_data.append((base_name, energy))
57
+
58
+ csv_path = output_dir / "id_prop.csv"
59
+ print(f"Writing {csv_path}...")
60
+ with open(csv_path, 'w', newline='') as f:
61
+ writer = csv.writer(f)
62
+ writer.writerow(['odac_id', 'adsorption_energy'])
63
+ for odac_id, energy in csv_data:
64
+ writer.writerow([odac_id, energy])
65
+
66
+ print(f"Done! {len(csv_data)} entries written.")
67
+ print(f" raw/ → {raw_dir}")
68
+ print(f" csv → {csv_path}")
69
+
70
+ if __name__ == "__main__":
71
+ main()