Datasets:
Tasks:
Tabular Regression
Sub-tasks:
tabular-single-column-regression
Languages:
English
Size:
100K<n<1M
ArXiv:
License:
Upload convert_odac25_aselmdb_to_is2re.py
Browse files
data/original_data/ODAC25/convert_odac25_aselmdb_to_is2re.py
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import csv
|
| 7 |
+
import math
|
| 8 |
+
import pickle
|
| 9 |
+
import random
|
| 10 |
+
from dataclasses import dataclass
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
MAP_SIZE = 512 * 1024**3
|
| 16 |
+
OUTLIER_MIN = -2.0
|
| 17 |
+
OUTLIER_MAX = 2.0
|
| 18 |
+
SPLIT_SEED = 42
|
| 19 |
+
TRAIN_FRACTION = 0.9
|
| 20 |
+
COMMIT_INTERVAL = 1000
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@dataclass(frozen=True)
|
| 24 |
+
class ValidSample:
|
| 25 |
+
index: int
|
| 26 |
+
sid: int
|
| 27 |
+
payload: bytes
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@dataclass
|
| 31 |
+
class ConversionStats:
|
| 32 |
+
total_records_scanned: int = 0
|
| 33 |
+
records_with_fid_zero: int = 0
|
| 34 |
+
outliers_filtered: int = 0
|
| 35 |
+
valid_samples: int = 0
|
| 36 |
+
unique_sids: int = 0
|
| 37 |
+
train_samples: int = 0
|
| 38 |
+
train_unique_sids: int = 0
|
| 39 |
+
val_samples: int = 0
|
| 40 |
+
val_unique_sids: int = 0
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def parse_args() -> argparse.Namespace:
|
| 44 |
+
parser = argparse.ArgumentParser(
|
| 45 |
+
description=(
|
| 46 |
+
"Convert ODAC25 ASE LMDB files into IS2RE-style LMDB datasets "
|
| 47 |
+
"compatible with fairchem LmdbDataset."
|
| 48 |
+
)
|
| 49 |
+
)
|
| 50 |
+
parser.add_argument(
|
| 51 |
+
"--src-dir",
|
| 52 |
+
required=True,
|
| 53 |
+
type=Path,
|
| 54 |
+
help="Path to a directory containing .aselmdb files.",
|
| 55 |
+
)
|
| 56 |
+
parser.add_argument(
|
| 57 |
+
"--out-dir",
|
| 58 |
+
required=True,
|
| 59 |
+
type=Path,
|
| 60 |
+
help="Directory where train/val LMDBs and logs will be written.",
|
| 61 |
+
)
|
| 62 |
+
return parser.parse_args()
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def import_dependencies() -> dict[str, Any]:
|
| 66 |
+
missing: list[str] = []
|
| 67 |
+
|
| 68 |
+
try:
|
| 69 |
+
import lmdb # type: ignore
|
| 70 |
+
except ImportError:
|
| 71 |
+
missing.append("lmdb")
|
| 72 |
+
lmdb = None
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
import torch # type: ignore
|
| 76 |
+
except ImportError:
|
| 77 |
+
missing.append("torch")
|
| 78 |
+
torch = None
|
| 79 |
+
|
| 80 |
+
try:
|
| 81 |
+
from fairchem.core.datasets import AseDBDataset # type: ignore
|
| 82 |
+
except ImportError:
|
| 83 |
+
missing.append("fairchem-core")
|
| 84 |
+
AseDBDataset = None
|
| 85 |
+
|
| 86 |
+
try:
|
| 87 |
+
from fairchem.core.datasets import LmdbDataset # type: ignore
|
| 88 |
+
except ImportError:
|
| 89 |
+
LmdbDataset = None
|
| 90 |
+
|
| 91 |
+
try:
|
| 92 |
+
from torch_geometric.data import Data # type: ignore
|
| 93 |
+
except ImportError:
|
| 94 |
+
missing.append("torch_geometric")
|
| 95 |
+
Data = None
|
| 96 |
+
|
| 97 |
+
try:
|
| 98 |
+
from tqdm import tqdm # type: ignore
|
| 99 |
+
except ImportError:
|
| 100 |
+
missing.append("tqdm")
|
| 101 |
+
tqdm = None
|
| 102 |
+
|
| 103 |
+
if missing:
|
| 104 |
+
required = "fairchem-core lmdb torch torch_geometric numpy tqdm"
|
| 105 |
+
missing_str = ", ".join(sorted(set(missing)))
|
| 106 |
+
raise SystemExit(
|
| 107 |
+
f"Missing dependencies: {missing_str}. "
|
| 108 |
+
f"Install them with: pip install {required}"
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
return {
|
| 112 |
+
"lmdb": lmdb,
|
| 113 |
+
"torch": torch,
|
| 114 |
+
"AseDBDataset": AseDBDataset,
|
| 115 |
+
"LmdbDataset": LmdbDataset,
|
| 116 |
+
"Data": Data,
|
| 117 |
+
"tqdm": tqdm,
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def emit(message: str, log_file: Path) -> None:
|
| 122 |
+
print(message)
|
| 123 |
+
with log_file.open("a", encoding="utf-8") as handle:
|
| 124 |
+
handle.write(message + "\n")
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def require_sid(info: dict[str, Any], record_index: int) -> int:
|
| 128 |
+
sid = info.get("sid")
|
| 129 |
+
if sid is None:
|
| 130 |
+
raise KeyError(f"Record {record_index} is missing required info['sid'].")
|
| 131 |
+
return int(sid)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def to_float_or_none(value: Any) -> float | None:
|
| 135 |
+
if value is None:
|
| 136 |
+
return None
|
| 137 |
+
try:
|
| 138 |
+
parsed = float(value)
|
| 139 |
+
except (TypeError, ValueError):
|
| 140 |
+
return None
|
| 141 |
+
if not math.isfinite(parsed):
|
| 142 |
+
return None
|
| 143 |
+
return parsed
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def scan_dataset(
|
| 147 |
+
dataset: Any,
|
| 148 |
+
outliers_csv: Path,
|
| 149 |
+
torch_module: Any,
|
| 150 |
+
data_cls: Any,
|
| 151 |
+
tqdm_cls: Any,
|
| 152 |
+
) -> tuple[list[ValidSample], list[int], ConversionStats]:
|
| 153 |
+
valid_samples: list[ValidSample] = []
|
| 154 |
+
valid_sids: list[int] = []
|
| 155 |
+
stats = ConversionStats(total_records_scanned=len(dataset))
|
| 156 |
+
|
| 157 |
+
with outliers_csv.open("w", newline="", encoding="utf-8") as handle:
|
| 158 |
+
writer = csv.DictWriter(
|
| 159 |
+
handle,
|
| 160 |
+
fieldnames=["sid", "mof_id", "mof_type", "energy_ads_corrected"],
|
| 161 |
+
)
|
| 162 |
+
writer.writeheader()
|
| 163 |
+
|
| 164 |
+
for index in tqdm_cls(range(len(dataset)), desc="Scanning records"):
|
| 165 |
+
atoms = dataset.get_atoms(index)
|
| 166 |
+
info = dict(atoms.info)
|
| 167 |
+
fid = info.get("fid")
|
| 168 |
+
|
| 169 |
+
if fid != 0:
|
| 170 |
+
continue
|
| 171 |
+
|
| 172 |
+
stats.records_with_fid_zero += 1
|
| 173 |
+
energy_ads = to_float_or_none(info.get("energy_ads_corrected"))
|
| 174 |
+
if energy_ads is None:
|
| 175 |
+
continue
|
| 176 |
+
|
| 177 |
+
sid = require_sid(info, index)
|
| 178 |
+
if energy_ads < OUTLIER_MIN or energy_ads > OUTLIER_MAX:
|
| 179 |
+
writer.writerow(
|
| 180 |
+
{
|
| 181 |
+
"sid": sid,
|
| 182 |
+
"mof_id": str(info.get("mof_name", "")),
|
| 183 |
+
"mof_type": str(info.get("mof_type", "")),
|
| 184 |
+
"energy_ads_corrected": energy_ads,
|
| 185 |
+
}
|
| 186 |
+
)
|
| 187 |
+
stats.outliers_filtered += 1
|
| 188 |
+
continue
|
| 189 |
+
|
| 190 |
+
data = atoms_to_data(atoms, torch_module=torch_module, data_cls=data_cls)
|
| 191 |
+
payload = pickle.dumps(data, protocol=pickle.HIGHEST_PROTOCOL)
|
| 192 |
+
valid_samples.append(ValidSample(index=index, sid=sid, payload=payload))
|
| 193 |
+
valid_sids.append(sid)
|
| 194 |
+
|
| 195 |
+
stats.valid_samples = len(valid_samples)
|
| 196 |
+
stats.unique_sids = len(set(valid_sids))
|
| 197 |
+
return valid_samples, valid_sids, stats
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def split_sids(valid_sids: list[int]) -> tuple[set[int], set[int]]:
|
| 201 |
+
unique_sids = sorted(set(valid_sids))
|
| 202 |
+
random.seed(SPLIT_SEED)
|
| 203 |
+
random.shuffle(unique_sids)
|
| 204 |
+
split_index = int(len(unique_sids) * TRAIN_FRACTION)
|
| 205 |
+
train_sids = set(unique_sids[:split_index])
|
| 206 |
+
val_sids = set(unique_sids[split_index:])
|
| 207 |
+
return train_sids, val_sids
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
class LMDBWriter:
|
| 211 |
+
def __init__(self, lmdb_module: Any, output_path: Path) -> None:
|
| 212 |
+
self.output_path = output_path
|
| 213 |
+
self.env = lmdb_module.open(
|
| 214 |
+
str(output_path),
|
| 215 |
+
map_size=MAP_SIZE,
|
| 216 |
+
subdir=False,
|
| 217 |
+
meminit=False,
|
| 218 |
+
map_async=True,
|
| 219 |
+
lock=True,
|
| 220 |
+
readahead=False,
|
| 221 |
+
create=True,
|
| 222 |
+
)
|
| 223 |
+
self.txn = self.env.begin(write=True)
|
| 224 |
+
self.count = 0
|
| 225 |
+
|
| 226 |
+
def write(self, payload: bytes) -> None:
|
| 227 |
+
self.txn.put(str(self.count).encode("ascii"), payload)
|
| 228 |
+
self.count += 1
|
| 229 |
+
if self.count % COMMIT_INTERVAL == 0:
|
| 230 |
+
self.txn.commit()
|
| 231 |
+
self.txn = self.env.begin(write=True)
|
| 232 |
+
|
| 233 |
+
def close(self) -> int:
|
| 234 |
+
self.txn.put(b"length", pickle.dumps(self.count, protocol=pickle.HIGHEST_PROTOCOL))
|
| 235 |
+
self.txn.commit()
|
| 236 |
+
self.env.sync()
|
| 237 |
+
self.env.close()
|
| 238 |
+
return self.count
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def atoms_to_data(atoms: Any, torch_module: Any, data_cls: Any) -> Any:
|
| 242 |
+
info = dict(atoms.info)
|
| 243 |
+
energy_ads = to_float_or_none(info.get("energy_ads_corrected"))
|
| 244 |
+
if energy_ads is None:
|
| 245 |
+
raise ValueError("energy_ads_corrected is required for valid samples.")
|
| 246 |
+
|
| 247 |
+
data = data_cls()
|
| 248 |
+
data.pos = torch_module.tensor(atoms.positions, dtype=torch_module.float32)
|
| 249 |
+
data.atomic_numbers = torch_module.tensor(atoms.numbers, dtype=torch_module.long)
|
| 250 |
+
data.cell = torch_module.tensor(atoms.cell[:], dtype=torch_module.float32).unsqueeze(0)
|
| 251 |
+
data.natoms = torch_module.tensor(len(atoms), dtype=torch_module.long)
|
| 252 |
+
data.pbc = torch_module.tensor(atoms.get_pbc(), dtype=torch_module.bool)
|
| 253 |
+
data.tags = torch_module.tensor(atoms.get_tags(), dtype=torch_module.long)
|
| 254 |
+
data.y_relaxed = torch_module.tensor(energy_ads, dtype=torch_module.float32)
|
| 255 |
+
data.sid = int(info["sid"])
|
| 256 |
+
data.mof_id = str(info.get("mof_name", ""))
|
| 257 |
+
data.mof_type = str(info.get("mof_type", ""))
|
| 258 |
+
data.nco2 = int(info.get("nco2", 0))
|
| 259 |
+
data.nh2o = int(info.get("nh2o", 0))
|
| 260 |
+
data.nn2 = int(info.get("nn2", 0))
|
| 261 |
+
data.no2 = int(info.get("no2", 0))
|
| 262 |
+
return data
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
def write_lmdbs(
|
| 266 |
+
valid_samples: list[ValidSample],
|
| 267 |
+
train_sids: set[int],
|
| 268 |
+
val_sids: set[int],
|
| 269 |
+
train_path: Path,
|
| 270 |
+
val_path: Path,
|
| 271 |
+
lmdb_module: Any,
|
| 272 |
+
tqdm_cls: Any,
|
| 273 |
+
) -> tuple[int, int]:
|
| 274 |
+
train_writer = LMDBWriter(lmdb_module, train_path)
|
| 275 |
+
val_writer = LMDBWriter(lmdb_module, val_path)
|
| 276 |
+
|
| 277 |
+
try:
|
| 278 |
+
for sample in tqdm_cls(valid_samples, desc="Writing LMDB"):
|
| 279 |
+
if sample.sid in train_sids:
|
| 280 |
+
train_writer.write(sample.payload)
|
| 281 |
+
elif sample.sid in val_sids:
|
| 282 |
+
val_writer.write(sample.payload)
|
| 283 |
+
else:
|
| 284 |
+
raise KeyError(f"SID {sample.sid} was not assigned to train or val.")
|
| 285 |
+
finally:
|
| 286 |
+
train_count = train_writer.close()
|
| 287 |
+
val_count = val_writer.close()
|
| 288 |
+
|
| 289 |
+
return train_count, val_count
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def verify_outputs(
|
| 293 |
+
out_dir: Path,
|
| 294 |
+
lmdb_module: Any,
|
| 295 |
+
) -> list[str]:
|
| 296 |
+
def read_lmdb(path: Path) -> tuple[int, Any | None]:
|
| 297 |
+
env = lmdb_module.open(
|
| 298 |
+
str(path),
|
| 299 |
+
subdir=False,
|
| 300 |
+
readonly=True,
|
| 301 |
+
lock=False,
|
| 302 |
+
)
|
| 303 |
+
try:
|
| 304 |
+
with env.begin() as txn:
|
| 305 |
+
length_raw = txn.get(b"length")
|
| 306 |
+
if length_raw is None:
|
| 307 |
+
raise RuntimeError(f"Auto-check failed: missing length key in {path}")
|
| 308 |
+
length = pickle.loads(length_raw)
|
| 309 |
+
sample = None
|
| 310 |
+
if length > 0:
|
| 311 |
+
sample_raw = txn.get(b"0")
|
| 312 |
+
if sample_raw is None:
|
| 313 |
+
raise RuntimeError(f"Auto-check failed: missing sample key b'0' in {path}")
|
| 314 |
+
sample = pickle.loads(sample_raw)
|
| 315 |
+
return length, sample
|
| 316 |
+
finally:
|
| 317 |
+
env.close()
|
| 318 |
+
|
| 319 |
+
train_len, train_sample = read_lmdb(out_dir / "odac25_is2re_train.lmdb")
|
| 320 |
+
val_len, val_sample = read_lmdb(out_dir / "odac25_is2re_val.lmdb")
|
| 321 |
+
|
| 322 |
+
if train_len == 0 and val_len == 0:
|
| 323 |
+
raise RuntimeError("Auto-check failed: both train and val datasets are empty.")
|
| 324 |
+
|
| 325 |
+
sample = train_sample if train_len > 0 else val_sample
|
| 326 |
+
|
| 327 |
+
assert hasattr(sample, "y_relaxed"), "y_relaxed missing"
|
| 328 |
+
assert hasattr(sample, "pos"), "pos missing"
|
| 329 |
+
assert OUTLIER_MIN <= sample.y_relaxed.item() <= OUTLIER_MAX, (
|
| 330 |
+
"outlier leaked into dataset!"
|
| 331 |
+
)
|
| 332 |
+
|
| 333 |
+
return [
|
| 334 |
+
f"Train size: {train_len}, Val size: {val_len}",
|
| 335 |
+
f"Sample y_relaxed: {sample.y_relaxed.item():.4f} eV",
|
| 336 |
+
"OK: dataset is compatible with fairchem LmdbDataset",
|
| 337 |
+
]
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
def format_summary(src_dir: Path, out_dir: Path, stats: ConversionStats) -> list[str]:
|
| 341 |
+
return [
|
| 342 |
+
f"Source directory: {src_dir}",
|
| 343 |
+
f"Output directory: {out_dir}",
|
| 344 |
+
f"Total records scanned: {stats.total_records_scanned}",
|
| 345 |
+
f"Records with fid==0: {stats.records_with_fid_zero}",
|
| 346 |
+
(
|
| 347 |
+
"Outliers filtered: "
|
| 348 |
+
f"{stats.outliers_filtered} "
|
| 349 |
+
f"(energy_ads_corrected outside [{OUTLIER_MIN:.1f}, {OUTLIER_MAX:.1f}] eV)"
|
| 350 |
+
),
|
| 351 |
+
f"Valid samples: {stats.valid_samples}",
|
| 352 |
+
f"Unique SIDs: {stats.unique_sids}",
|
| 353 |
+
(
|
| 354 |
+
f"Train samples: {stats.train_samples} "
|
| 355 |
+
f"(unique SIDs: {stats.train_unique_sids})"
|
| 356 |
+
),
|
| 357 |
+
(
|
| 358 |
+
f"Val samples: {stats.val_samples} "
|
| 359 |
+
f"(unique SIDs: {stats.val_unique_sids})"
|
| 360 |
+
),
|
| 361 |
+
]
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def main() -> None:
|
| 365 |
+
args = parse_args()
|
| 366 |
+
args.src_dir = args.src_dir.expanduser().resolve()
|
| 367 |
+
args.out_dir = args.out_dir.expanduser().resolve()
|
| 368 |
+
|
| 369 |
+
if not args.src_dir.is_dir():
|
| 370 |
+
raise SystemExit(f"--src-dir does not exist or is not a directory: {args.src_dir}")
|
| 371 |
+
|
| 372 |
+
args.out_dir.mkdir(parents=True, exist_ok=True)
|
| 373 |
+
log_file = args.out_dir / "conversion.log"
|
| 374 |
+
log_file.write_text("", encoding="utf-8")
|
| 375 |
+
|
| 376 |
+
deps = import_dependencies()
|
| 377 |
+
dataset = deps["AseDBDataset"]({"src": str(args.src_dir)})
|
| 378 |
+
|
| 379 |
+
outliers_csv = args.out_dir / "outliers.csv"
|
| 380 |
+
train_lmdb = args.out_dir / "odac25_is2re_train.lmdb"
|
| 381 |
+
val_lmdb = args.out_dir / "odac25_is2re_val.lmdb"
|
| 382 |
+
|
| 383 |
+
valid_samples, valid_sids, stats = scan_dataset(
|
| 384 |
+
dataset=dataset,
|
| 385 |
+
outliers_csv=outliers_csv,
|
| 386 |
+
torch_module=deps["torch"],
|
| 387 |
+
data_cls=deps["Data"],
|
| 388 |
+
tqdm_cls=deps["tqdm"],
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
train_sids, val_sids = split_sids(valid_sids)
|
| 392 |
+
stats.train_unique_sids = len(train_sids)
|
| 393 |
+
stats.val_unique_sids = len(val_sids)
|
| 394 |
+
|
| 395 |
+
train_count, val_count = write_lmdbs(
|
| 396 |
+
valid_samples=valid_samples,
|
| 397 |
+
train_sids=train_sids,
|
| 398 |
+
val_sids=val_sids,
|
| 399 |
+
train_path=train_lmdb,
|
| 400 |
+
val_path=val_lmdb,
|
| 401 |
+
lmdb_module=deps["lmdb"],
|
| 402 |
+
tqdm_cls=deps["tqdm"],
|
| 403 |
+
)
|
| 404 |
+
stats.train_samples = train_count
|
| 405 |
+
stats.val_samples = val_count
|
| 406 |
+
|
| 407 |
+
for line in format_summary(args.src_dir, args.out_dir, stats):
|
| 408 |
+
emit(line, log_file)
|
| 409 |
+
|
| 410 |
+
for line in verify_outputs(out_dir=args.out_dir, lmdb_module=deps["lmdb"]):
|
| 411 |
+
emit(line, log_file)
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
if __name__ == "__main__":
|
| 415 |
+
main()
|