add preprocess scripts
Browse filesFiles changed (3)
- .gitignoreAdded+4
- jobs.pyAdded+37
- preprocess.pyAdded+84
1234**/.ipynb_checkpoints/**/__pycache__**.out**.err12345678910111213141516171819202122232425262728293031323334353637"""Module for submitting jobs"""
import subprocess
def submit_slurm( cmd: str, time: str, partition: str, nodes: int, ntasks_per_node: int, job_name: str, account: str, **kwargs,): """Submit a job to the slurm scheduler.""" scmd = [ *f"""sbatch --time={time} --account={account} --qos={partition} --job-name={job_name} --output=%x-%j.out --error=%x-%j.err --nodes={nodes} --ntasks-per-node={ntasks_per_node}""".replace("'", "").split(), ]
if kwargs.get("constraint", False): scmd += [f"--constraint={kwargs['constraint']}"]
if kwargs.get("exclude", False): scmd += ["--exclude"]
scmd += ["--wrap", cmd]
return subprocess.run(scmd, check=True)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384# # %%# from datasets import load_dataset
# dataset = load_dataset("atomind/alexandria", name='1D', streaming=True)
# print(dataset)# # %%import argparseimport bz2import jsonfrom pathlib import Path
from tqdm.auto import tqdm
from ase import Atomsfrom ase.calculators.singlepoint import SinglePointCalculatorfrom ase.io import write, readfrom pymatgen.core import Structure
def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--src_path", type=str, required=True) parser.add_argument("--dst_dir", type=str, required=True) return parser.parse_args()
def main(src_path: Path | str, dst_dir: Path | str): """Extracts the structures from a bz2 compressed json file and writes them to an extended xyz file."""
if isinstance(src_path, str): src_path = Path(src_path)
if isinstance(dst_dir, str): dst_dir = Path(dst_dir)
dst_dir.mkdir(exist_ok=True, parents=True)
with bz2.open(src_path, "rb") as f: data = json.load(f)
assert isinstance(data, dict)
for alex_id, u in tqdm(data.items(), desc="Extracting structures"): for calc_id, v in enumerate(u): for ionic_step, w in enumerate(v["steps"]): atoms = Structure.from_dict(w["structure"]).to_ase_atoms()
results = { "energy": w["energy"], "forces": w["forces"], "stress": w["stress"], }
atoms.calc = SinglePointCalculator(atoms=atoms, **results)
atoms.info = { "alex_id": alex_id, "calc_id": calc_id, "ionic_step": ionic_step, }
traj_file = dst_dir / f"{atoms.get_chemical_formula()}.traj"
exist = False if traj_file.exists(): traj = read(traj_file, index=":") for frame in traj: assert isinstance(frame, Atoms) if frame.info == atoms.info: exist = True break
if not exist: write( traj_file, atoms, append=True, )
if __name__ == "__main__": args = parse_args() main(args.src_path, args.dst_dir).gitignoreAdded+4
jobs.pyAdded+37
preprocess.pyAdded+84