Skip to content

KeyError in ThermoML parsing stops file-parsing on first error, ignoring later properties #65

Description

@lilyminium

The KeyError raised in add_properties stops on the first duplicate ID, meaning that later entries don't get parsed. I suspect this is the majority of the failure to read most properties in #62 .

for node in root_node.findall("ThermoML:PureOrMixtureData", namespace):
properties = _PureOrMixtureData.from_xml_node(node, namespace, compounds)
if properties is None or len(properties) == 0:
raise Exception(
f"No properties parsed from {node=}, {namespace=}, {compounds=}. "
"This likely means the entry was skipped due to an unsupported phase / property "
"type, or a failure to parse the compound information."
)
for measured_property in properties:
unit_to_use = _property_unit_map[measured_property.type_string]
assert Unit(measured_property.default_unit).is_compatible_with(unit_to_use) # type: ignore[attr-defined]
# Could wrap this into a Source.__repr__()? Kinda ugly ...
if source.doi is not None:
stringified_source = source.doi
elif source.reference is not None:
stringified_source = source.reference
else:
stringified_source = ""
# https://github.com/openforcefield/openff-evaluator/blob/c9b55687be3381768d75afdea01e9e18b5a35fac/openff/evaluator/datasets/datasets.py#L105-L110
entry = DataEntry(
id=measured_property._get_raw_property_hash(),
tag=_property_tag_map[measured_property.type_string],
smiles=[component.smiles for component in measured_property.substance.components],
x=[value for value in measured_property.substance.amounts.values()],
temperature=_standardize_temperature(measured_property.temperature), # type: ignore[typeddict-item]
pressure=_standardize_pressure(measured_property.pressure), # type: ignore[typeddict-item]
value=measured_property.value.m_as(unit_to_use),
std=measured_property.uncertainty.m_as(unit_to_use)
if measured_property.uncertainty is not None
else None,
units=unit_to_use,
source=stringified_source, # This is fragile, but really preferable for pyarrow compatiblity
)
return_value.add_properties(entry)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions