Skip to content

Commit

Permalink
Better handling of IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Oct 2, 2023
1 parent 28b6bab commit 50c029a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id": "part_1.json.bz2/0", "type": "structures", "links": null, "meta": null, "attributes": {"immutable_id": null, "last_modified": null, "elements": ["Ac"], "nelements": 1, "elements_ratios": [1.0], "chemical_formula_descriptive": "Ac4", "chemical_formula_reduced": "Ac", "chemical_formula_hill": null, "chemical_formula_anonymous": "A", "dimension_types": [1, 1, 1], "nperiodic_dimensions": 3, "lattice_vectors": [[3.92252914, 0.0, 0.0], [-1.96126457, 3.39700988, 0.0], [0.0, 0.0, 12.69499244]], "cartesian_site_positions": [[0.0, 0.0, 0.0], [-1.961264582666056e-08, 2.2646732646567, 3.17374811], [0.0, 0.0, 6.34749622], [1.9612645896126455, 1.1323366153433003, 9.52124433]], "nsites": 4, "species": [{"name": "Ac", "chemical_symbols": ["Ac"], "concentration": [1.0], "mass": null, "original_name": null, "attached": null, "nattached": null}], "species_at_sites": ["Ac", "Ac", "Ac", "Ac"], "assemblies": null, "structure_features": [], "mat_id": "agm003188153", "prototype_id": "A_22_spg194", "location": "database/batch-000/Ac/Ac/xxx_02s-00_agm003188153_spg194", "formula": "Ac", "spg": 194, "stress": [[0.8811667, 0.0, 0.0], [0.0, 0.8811667, 0.0], [0.0, 0.0, -0.06628691]], "energy_total": -18.01479609, "total_mag": 0.0001825, "band_gap_ind": 0.0, "band_gap_dir": 0.0056, "dos_ef": 6.1911793, "energy_corrected": -18.014795, "e_above_hull": 0.0, "e_form": 0.0, "e_phase_separation": 0.0, "decomposition": " Ac ", "energy": null, "hull_distance": true, "formation_energy": true, "space_group_number": true}, "relationships": null}
{"id": "agm003188153", "type": "structures", "links": null, "meta": null, "attributes": {"immutable_id": null, "last_modified": null, "elements": ["Ac"], "nelements": 1, "elements_ratios": [1.0], "chemical_formula_descriptive": "Ac4", "chemical_formula_reduced": "Ac", "chemical_formula_hill": null, "chemical_formula_anonymous": "A", "dimension_types": [1, 1, 1], "nperiodic_dimensions": 3, "lattice_vectors": [[3.92252914, 0.0, 0.0], [-1.96126457, 3.39700988, 0.0], [0.0, 0.0, 12.69499244]], "cartesian_site_positions": [[0.0, 0.0, 0.0], [-1.961264582666056e-08, 2.2646732646567, 3.17374811], [0.0, 0.0, 6.34749622], [1.9612645896126455, 1.1323366153433003, 9.52124433]], "nsites": 4, "species": [{"name": "Ac", "chemical_symbols": ["Ac"], "concentration": [1.0], "mass": null, "original_name": null, "attached": null, "nattached": null}], "species_at_sites": ["Ac", "Ac", "Ac", "Ac"], "assemblies": null, "structure_features": [], "mat_id": "agm003188153", "prototype_id": "A_22_spg194", "location": "database/batch-000/Ac/Ac/xxx_02s-00_agm003188153_spg194", "formula": "Ac", "spg": 194, "stress": [[0.8811667, 0.0, 0.0], [0.0, 0.8811667, 0.0], [0.0, 0.0, -0.06628691]], "energy_total": -18.01479609, "total_mag": 0.0001825, "band_gap_ind": 0.0, "band_gap_dir": 0.0056, "dos_ef": 6.1911793, "energy_corrected": -18.014795, "e_above_hull": 0.0, "e_form": 0.0, "e_phase_separation": 0.0, "decomposition": " Ac ", "energy": null, "hull_distance": true, "formation_energy": true, "space_group_number": true}, "relationships": null}
3 changes: 2 additions & 1 deletion src/mc_optimade/mc_optimade/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ def construct_entries(
if not isinstance(entry, dict):
entry = entry.dict()

entry["id"] = entry_id
if not entry["id"]:
entry["id"] = entry_id

if entry_id in optimade_entries:
raise RuntimeError(f"Duplicate entry ID found: {entry_id}")
Expand Down
6 changes: 4 additions & 2 deletions src/mc_optimade/mc_optimade/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ def parse_computed_structure_entry(
entry["attributes"]["energy"] = pmg_entry.energy
# try to find any unique ID fields and use it to overwrite the generated one
for key in ("id", "mat_id", "task_id"):
entry["id"] = pmg_entry.data.get(key, entry["id"])
break
id = pmg_entry.data.get(key)
if id:
entry["id"] = id
break

for p in properties or []:
# loop through any property aliases, saving the value if found and only checking
Expand Down

0 comments on commit 50c029a

Please sign in to comment.