import json, os, re, sys, numpy as np, pandas as pd W=sys.argv[1] def legacy(i): p,_,b=i.rpartition("-") if not re.fullmatch(r"[a-z]+",b): return i n=0 for c in b: n=n*26+ord(c)-97 return f"{p or 'mp'}-{n}" core={d["material_id"]:d for d in json.load(open(W+"/core_lemat.json"))} tasks={t["task_id"]:t for t in json.load(open(W+"/tasks_meta.json"))} m=pd.read_parquet(W+"/mp_vs_thermo.parquet") # LeMat ids that MP has merged into another material: follow them to the parent material alias=json.load(open(W+"/core_alias.json")) if os.path.exists(W+"/core_alias.json") else {} thermo={d["material_id"]:d for d in json.load(open(W+"/thermo_gga.json"))} for i,parent in alias.items(): if i in core: continue core[i]=core[parent] th=thermo.get(parent) if th and th.get("origins"): m.loc[m.immutable_id==i,"thermo_task"]=th["origins"][0]["task_id"] rows=[] for r in m.itertuples(index=False): d=core.get(r.immutable_id); rec={"immutable_id":r.immutable_id} if d is None: rec["status"]="material_not_found"; rows.append(rec); continue dep={legacy(t) for t in d.get("deprecated_tasks") or []} rec["material_deprecated"]=d["deprecated"] cands=[] for k,ct in (d.get("calc_types") or {}).items(): t=tasks.get(legacy(k)) if t is None or (t.get("output") or {}).get("energy") is None: continue cands.append((legacy(k),t)) rec["n_cand"]=len(cands) best=None for tid,t in cands: dE=t["output"]["energy"]-r.energy if best is None or abs(dE)