Format Mapping
hsd-data converts between formats by mapping each format’s data model to the
canonical hsd_table / hsd_value tree. This page documents how HSD
structures map to each supported format.
Core Concepts
hsd-fortran Type |
Role |
|---|---|
|
Container node with named children (like a dict/object) |
|
Leaf node holding a scalar, array, or matrix |
Attributes |
Metadata attached to any node (e.g., units, modifiers) |
HSD ↔ XML
HSD maps naturally to XML since both are hierarchical with named elements and attributes.
Table Nodes
HSD |
XML |
|---|---|
Hamiltonian = DFTB {
SCC = Yes
}
|
<Hamiltonian method="DFTB">
<SCC>Yes</SCC>
</Hamiltonian>
|
Value Nodes
HSD |
XML |
|---|---|
|
|
|
|
Attributes
HSD modifiers (in square brackets) become XML attributes:
HSD |
XML Attribute |
|---|---|
|
|
Anonymous Values
HSD inline text becomes XML text content of the parent element.
HSD ↔ JSON
JSON represents the tree using nested objects. Special keys handle HSD concepts that JSON lacks natively.
Table Nodes
HSD |
JSON |
|---|---|
Hamiltonian = DFTB {
SCC = Yes
}
|
{
"Hamiltonian": {
"_choice": "DFTB",
"SCC": "Yes"
}
}
|
Value Nodes
HSD |
JSON |
|---|---|
|
|
|
|
|
|
Arrays
HSD |
JSON |
|---|---|
|
|
Attributes
Attributes are stored as sibling keys with __attrib suffix:
HSD |
JSON |
|---|---|
|
|
Anonymous Values
Anonymous text content uses the _value key:
HSD |
JSON |
|---|---|
|
|
HSD ↔ YAML
YAML’s indentation-based structure maps naturally to HSD’s hierarchy.
Table Nodes
HSD |
YAML |
|---|---|
Hamiltonian = DFTB {
SCC = Yes
}
|
Hamiltonian:
_choice: DFTB
SCC: true
|
Value Nodes
HSD |
YAML |
|---|---|
|
|
|
|
|
|
Arrays
HSD |
YAML |
|---|---|
|
|
Attributes
Same convention as JSON — sibling key with __attrib suffix:
HSD |
YAML |
|---|---|
|
|
Anonymous Values
Anonymous text content uses the _value key:
HSD |
YAML |
|---|---|
|
|
HSD ↔ TOML
TOML’s table-based structure maps well to HSD’s hierarchy.
Table Nodes
HSD |
TOML |
|---|---|
Hamiltonian = DFTB {
SCC = Yes
}
|
[Hamiltonian]
_choice = "DFTB"
SCC = true
|
Value Nodes
HSD |
TOML |
|---|---|
|
|
|
|
|
|
Arrays
HSD |
TOML |
|---|---|
|
|
Attributes
Same convention as JSON — sibling key with __attrib suffix:
HSD |
TOML |
|---|---|
|
|
Complex Values
HSD |
TOML |
|---|---|
|
|
HSD ↔ HDF5
HDF5 provides a rich binary format with groups, datasets, and attributes.
Table Nodes
HSD |
HDF5 |
|---|---|
|
HDF5 group |
Value Nodes
HSD Value Type |
HDF5 Representation |
|---|---|
Scalar integer |
Scalar dataset (H5T_NATIVE_INTEGER) |
Scalar real |
Scalar dataset (H5T_NATIVE_DOUBLE) |
Scalar string |
Fixed-length string dataset |
Logical |
Integer dataset (0/1) with |
1-D array |
1-D dataset |
2-D matrix |
2-D dataset |
Complex scalar |
Compound type dataset with |
Complex array |
1-D compound type dataset |
Attributes
HSD attributes become HDF5 string attributes on the corresponding dataset or group:
HSD |
HDF5 |
|---|---|
|
Dataset |
Round-Trip Considerations
Lossless Round-Trips
HSD → HSD: Fully lossless (comments and formatting may change).
XML → XML: Fully lossless.
JSON → JSON: Fully lossless.
YAML → YAML: Fully lossless.
Potentially Lossy Conversions
HSD → JSON → HSD: The
__attrib/_valueconventions ensure attribute preservation, but HSD formatting details (comments, whitespace) are lost.HSD → TOML: TOML does not support mixed content or ordered duplicate keys. Data is preserved but ordering may change.
Any → HDF5 → Any: Binary format preserves types precisely, but HDF5 does not store the original text representation.