# Rg Plugin Reference For a step-by-step guide to running Rg analysis, see {doc}`../how_to/analysis_rg_quickstart`. ## Configuration Reference All fields for `RgRunSettings`: | Field | Type | Default | Description | |-------|------|---------|-------------| | `label` | `str` | *required* | Human-readable run label (must be unique) | | `selection` | `str` | *required* | MDAnalysis selection for Rg calculation | | `calculation_mode` | `str` | `"selection"` | `"selection"` for whole-group Rg, `"fragments"` for per-fragment reduction | | `fragment_weighting` | `str` | `"equal"` | `"equal"` (arithmetic mean) or `"mass"` (mass-weighted mean). Only valid when `calculation_mode="fragments"` | | `save_fragment_distribution` | `bool` | `true` | Save per-fragment Rg values in NPZ sidecar for distribution analysis | | `histogram_bins` | `int` | `50` | Number of bins for fragment/reduced distribution histograms (minimum 2) | Top-level `RgSettings` contains a single field: | Field | Type | Default | Description | |-------|------|---------|-------------| | `runs` | `list[RgRunSettings]` | *required* | One or more named Rg runs (at least one required) | ```{note} Run labels must be unique within a single `comparison.yaml`. Duplicate labels raise a validation error. ``` ```{warning} Unlike RMSD (which defaults `selection` to `"protein and name CA"`), Rg has **no default selection**. You must always specify `selection` explicitly for each run. ``` ## Fragment Mode Reference ```{versionadded} 1.3.0 Fragment-aware Rg calculation was added in PolyzyMD 1.3.0. ``` Standard selection mode computes one Rg value per frame for the full atom group matched by `selection`. Fragment mode first computes Rg for each disconnected topological fragment, then reduces those per-fragment values to one per-frame value. Use fragment mode when your selection includes many independent molecules and you care about the average fragment size rather than the size of the entire multi-molecule cloud. ### Fragment mode configuration ```yaml plugins: rg: runs: - label: protein_rg selection: protein - label: polymer_blob_rg selection: "resname SBM or resname EGM or resname EGP" calculation_mode: fragments fragment_weighting: equal ``` | Setting | Meaning | |---------|---------| | `calculation_mode: "selection"` | Whole-group Rg | | `calculation_mode: "fragments"` | Per-fragment Rg with reduction | | `fragment_weighting: "equal"` | Arithmetic mean over fragments | | `fragment_weighting: "mass"` | Mass-weighted mean over fragments | ### How fragment mode reduction works 1. Identify disconnected fragments within the selected atom group 2. Compute fragment-level Rg for each frame 3. Reduce fragment values to one per-frame value using equal or mass weighting 4. Use the reduced timeseries for summary statistics and comparisons 5. Optionally save pooled fragment values in NPZ sidecars for distribution plots ## Why Rg Has No Alignment or Reference Fields Rg is based on mass-weighted distances from the center of mass, so it is translation and rotation invariant. Because of that, Rg runs do not use RMSD-style fields such as `alignment_selection`, `reference_mode`, `reference_file`, or `reference_frame`. ## Output Files Results are saved as canonical v1.3 artifacts. JSON files use framework-owned artifact envelopes, and per-frame or distribution arrays are stored as NPZ sidecars. ```text / ├── analysis/ │ └── / │ └── rg/ │ ├── run_1/ │ │ ├── result.json │ │ └── sidecars/ │ │ ├── rg_protein_rg_timeseries.npz │ │ └── rg_polymer_blob_rg_timeseries.npz │ ├── run_2/ │ │ └── ... │ ├── run_3/ │ │ └── ... │ └── aggregated/ │ ├── result.json │ └── sidecars/ │ └── rg_polymer_blob_rg_distribution.npz └── comparison/ └── rg/ └── result.json ``` The canonical paths are: | Level | Artifact | Path | |-------|----------|------| | Per replicate | `ReplicateArtifact` | `analysis//rg/run_/result.json` | | Per condition | `ConditionArtifact` | `analysis//rg/aggregated/result.json` | | Cross condition | Comparison result | `comparison/rg/result.json` | | Large arrays | NPZ sidecars | `analysis//rg/**/sidecars/*.npz` | Each replicate artifact contains JSON summaries for all configured runs. NPZ sidecars store per-frame Rg timeseries and optional fragment distributions. ### Artifact envelope fields | Field | Description | |-------|-------------| | `payload` | Rg run summaries, scalar metrics, fragment statistics, and relative sidecar paths | | `metadata` | Run settings, calculation modes, equilibration labels, and units | | `provenance` | Input topology/trajectory identity and workflow details | | `sidecars` | Validated references to `sidecars/*.npz` arrays with hashes and sizes | Use `ArtifactStore` for programmatic access: ```python from pathlib import Path from polyzymd.analyses.mda import ArtifactStore replicate = ArtifactStore(Path("analysis/PEGylated/rg/run_1")).read_replicate_result() condition = ArtifactStore(Path("analysis/PEGylated/rg/aggregated")).read_condition_result() print(replicate.payload["runs"][0]["mean_rg"]) print(condition.payload["runs"][0]["metrics"]["mean_rg"]) ``` ### NPZ sidecar arrays Each `rg_