Skip to content

Commit

Permalink
Allow IDs to match only on filename and not on full path
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Nov 30, 2023
1 parent 5151728 commit 058b9e0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/mc_optimade/mc_optimade/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,21 @@ def _parse_and_assign_properties(
f"Found {all_property_fields=} in data but {expected_property_fields} in config"
)

for id in parsed_properties:
if id not in optimade_entries:
raise RuntimeError(
f"Found {id=} in properties but not in entries {optimade_entries.keys()=}"
)
# Look for precisely matching IDs, or 'filename' matches
for id in optimade_entries:

property_entry_id = id
if id not in parsed_properties:
property_entry_id = id.split("/")[-1].split(".")[0]
if property_entry_id not in parsed_properties:
raise RuntimeError(
f"Found {id=}/{property_entry_id=} in properties but not in entries {optimade_entries.keys()=}"
)

for property in all_property_fields:
# Loop over all defined properties and assign them to the entry, setting to None if missing
# Also cast types if provided
value = parsed_properties[id].get(property, None)
value = parsed_properties[property_entry_id].get(property, None)
if property not in property_def_dict:
warnings.warn(f"Missing property definition for {property=}")
continue
Expand Down

0 comments on commit 058b9e0

Please sign in to comment.