molclusters.report¶
report
¶
Provides the format of the JSON report (molclusters.jsonl), and its reader.
The report, written by analysis.JsonReport, is JSON Lines: one JSON object per
line, compressed with zstd (molclusters.jsonl.zst, the default), gzip
(.jsonl.gz) or not at all (.jsonl), as the config's report_compression
says. It's written frame by frame, so a run never holds it in memory, and an
interrupted run leaves every frame it analysed readable.
The first line is the header::
{"format": "molclusters-report", "version": 4, "software": "MolClusters x.y.z",
"trajectory": <absolute path, or null for an in-memory trajectory>,
"topology": <absolute path, or null>, "n_frames": <frames in the run>,
"decimals": 6, "units": {<quantity>: <unit>, ...},
"connection_columns": ["i", "j", "distance", "angle", "n_hbonds"],
"analyses": [<every analysis of the run, in the order they ran>],
"contributors": [<the analyses that add fields, see below>],
"config": <the effective configuration>}
Then one line per frame::
{"frame": <trajectory frame number>, "time": <ps>, "clusters": [<cluster>, ...]}
and each cluster is::
{
"id": 3,
"birth_time": 120.0,
"size": 3,
"resids": [107, 169, 171],
"composition": {"MAL": 3},
"mass": 402.260990,
"volume": 834.555760,
"radius": 5.840575,
"radius_of_gyration": 3.981872,
"diameter": 11.681149,
"density": 0.800390,
"charge": 0.0,
"dipole_moment": 15.696198,
"sphericity": 0.738690,
"shape_parameter": 0.138796,
"connections": [[169, 107, 2.684737, 171.434846, 1], ...],
}
with birth_time the time of the frame the cluster first appeared in (the
run's first frame's for the clusters already there), and each connection a row of
connection_columns: the two resids, then the connection's distance (and, for
H-bonds, the D-H-A angle and the number of H-bonds between the pair; null for "cm"
rules). radius is the equivalent sphere's (see MolGroup.radius), and
radius_of_gyration the mass-weighted Rg it derives from.
Other analyses add fields of their own (see FrameAnalysis.report_frame and
report_cluster), under their class name in a frame's or a cluster's record. The
Nucleus analysis adds to each cluster "Nucleus": {"nuclei": [<group>, ...],
"combined_dipole_moment": <dipole of all its nuclei together, or null>}, a group
being a cluster without its id, birth_time and connections. The
Lineage analysis adds to each frame how its clusters came from the previous
frame's (see tracker.Transition)::
"Lineage": {"flows": [[<previous id>, <current id>, <molecules>], ...],
"born": [<id>, ...], "merged": [[<absorbed id>, <into id>], ...],
"dissolved": [<id>, ...]}
where id 0 in a flow stands for no cluster (free molecules), and on the first frame every cluster is born.
Floats are rounded to DECIMALS decimal places, what other analyses add included,
and NaN is written as null (a bare NaN isn't valid JSON). Units are those of UNITS.
Classes:
- Report: A report file, read frame by frame, or as tables.
Functions:
- read_report: Open a report file.
- report_name: The report's file name for a compression.
- dumps: Encode a record as one line of the report.
- rounded: Round every float in a value, as the report's are.
- group_record: Encode a group of molecules and its properties.
- cluster_record: Encode a cluster, its properties and connections.
Report
¶
A report file, read frame by frame, or as tables.
The file is read again by each call, frame by frame, so even a report too large for memory can be gone through. Its compression is told from its first bytes, not its name.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
The report file. |
header |
dict[str, Any]
|
The header: the software, inputs, units and configuration of the run. |
Open a report, reading its header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The report, compressed or not. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file isn't a MolClusters report this version can read. |
Source code in src/molclusters/report.py
__lines
¶
Open the file, decompressed, as lines.
Yields:
| Type | Description |
|---|---|
Iterator[bytes]
|
The file's lines, newlines included. |
Source code in src/molclusters/report.py
frames
¶
Read the frames, one at a time.
A report that ends early (the run was interrupted, or killed) gives the frames it has, with a warning.
Yields:
| Type | Description |
|---|---|
dict[str, Any]
|
Each frame's record (see the module's docstring). |
Source code in src/molclusters/report.py
__iter__
¶
clusters
¶
clusters() -> DataFrame
Tabulate the clusters: one row per cluster per frame.
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in src/molclusters/report.py
connections
¶
connections() -> DataFrame
Tabulate the connections: one row per connection per frame.
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in src/molclusters/report.py
report_name
¶
report_name(compression: ReportCompression) -> str
Give the report's file name for a compression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compression
|
ReportCompression
|
"zstd", "gzip" or "none". |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in src/molclusters/report.py
dumps
¶
rounded
¶
Round every float in a value to DECIMALS decimal places, however nested.
For what analyses add to the report, whose floats are rounded as the report's own are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
JSON types (mappings, sequences, numbers, strings, None), numpy scalars or arrays. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The value, mappings as dicts, other sequences as lists, float arrays rounded. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the value holds something that can't be written as JSON. |
Source code in src/molclusters/report.py
group_record
¶
Encode a group of molecules and its properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
MolGroup
|
The group, e.g. a nucleus. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Its size, resids, composition and properties (see the module's docstring). |
Source code in src/molclusters/report.py
connection_rows
¶
Encode the connections of a cluster, as rows of CONNECTION_COLUMNS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster
|
Cluster
|
The cluster. |
required |
Returns:
| Type | Description |
|---|---|
list[list[int | float | None]]
|
One row per connection, in the order of the cluster's graph. |
Source code in src/molclusters/report.py
cluster_record
¶
Encode a cluster, its properties and connections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster
|
Cluster
|
The cluster. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Its id and birth time, then |