Preprocess & I/O#
Engine-aware input discovery and trajectory normalization for PHENOMS.
This module converts replicate folders from GROMACS/OpenMM/AMBER layouts into normalized multi-frame protein-only PDBs consumable by SimulationSet.
- class phenoms.preprocess.ReplicateInput(replicate_dir: 'Path', engine: 'str', trajectory_path: 'Path', topology_path: 'Path | None')[source]#
Bases:
object
- phenoms.preprocess.detect_replicate_input(replicate_dir)[source]#
Detect simulation engine and enforce required files for one replicate folder.
Required files:
gromacs: trajectory (.xtc/.trr) + topology (.tpr preferred, else .gro/.pdb). Reading .tpr requires the optional MDAnalysis dependency (
pip install "phenoms[gromacs]"); without it, use a .gro/.pdb topology instead.openmm: trajectory (.dcd/.xtc) + topology (.pdb/.prmtop)
amber: trajectory (.nc/.mdcrd) + topology (.prmtop/.parm7)
pdb: one multi-model .pdb trajectory (already normalized input)
- Parameters:
- Return type:
- phenoms.preprocess.discover_replicate_dirs(input_dir)[source]#
Directory policy: - if input_dir itself looks like one replicate, use it - otherwise treat each direct child directory as a replicate
- phenoms.preprocess.normalize_replicate_to_pdb(replicate, out_pdb_path, *, frame_dt_ps=1000.0, start_ps=None, end_ps=None, apply_imaging=True, center=True, fit=True)[source]#
Normalize one replicate: image/unwrap (best-effort) -> center -> fit -> protein-only -> save PDB.
- phenoms.preprocess.prepare_set_from_dir(input_dir, prepared_dir, *, frame_dt_ps=1000.0, start_ps=None, end_ps=None, apply_imaging=True, center=True, fit=True)[source]#
Prepare one set directory into normalized PDB replicates. Returns sorted list of prepared PDB paths.
I/O and trajectory loading for PHENOMS.
Supports multi-frame PDBs (simple path) and native MD formats (trajectory + topology).
- phenoms.io.tpr_to_mdtraj_topology(tpr_path, traj_path)[source]#
Convert a GROMACS .tpr into a throwaway PDB that MDTraj can use as a topology.
Uses MDAnalysis’s pure-Python .tpr parser (no GROMACS binary required) to read atoms/bonds/resids. The trajectory is loaded alongside it purely so MDAnalysis has a coordinate set to write out (whether a bare .tpr carries usable coordinates on its own varies by MDAnalysis version); the actual frame data used for analysis always comes from
traj_pathvia MDTraj afterward. Caller is responsible for deleting the returned path.- Return type:
- phenoms.io.load_trajectory(path, top=None, max_frames=None)[source]#
Load a trajectory from a PDB or from a native trajectory + topology pair.
- Parameters:
path (str or path-like) – Trajectory file (
.pdb,.xtc,.trr,.dcd,.nc, …).top (str or path-like or None) – Topology for non-PDB trajectories (
.pdb,.prmtop,.gro,.tpr, …)..tpris converted on the fly via MDAnalysis (optional dependency). Ignored whenpathis already a multi-frame PDB with topology embedded.max_frames (int or None) – If set, only the first
max_framesframes are read from disk (viamdtraj.iterload) instead of loading the entire trajectory first. Pass the same value you intend to pass assub_framesdownstream to cut peak memory when a trajectory has far more frames than you need.
- Return type:
mdtraj.Trajectory
- phenoms.io.load_and_select_residues(path, resid_range=None, top=None, max_frames=None)[source]#
Load trajectory and optionally select a residue range.
If
resid_rangeis None, select all protein atoms (whole protein).- Parameters:
- Returns:
Loaded (and optionally sliced) trajectory.
- Return type:
mdtraj.Trajectory