Utilities¶
autopath.utils ¶
setup_logging ¶
setup_logging(logfile: str = 'autopath.log', logname: str = 'autopath', log_level: str = 'INFO') -> logging.Logger
Set up logging at the entry point; repeated calls reconfigure it.
load_system ¶
load_system(system_path: str) -> System
Loads the desired system.
Args: system_path (str): path to the system file
Returns: System: system
save_pdb ¶
save_pdb(topology: Topology, positions: list, out_path: str) -> None
Saves the specified topology and position to the out_path file.
Args: topology (app.Topology): topology used positions (list): list of 3D coords out_path (str): path to where to save the file
wrap_align_save_traj ¶
wrap_align_save_traj(traj_files, topology, remove_original=True, is_membrane=False, reference=None, align_select='backbone', out_dir=None)
Centre, image and superpose trajectories, writing *_aligned.dcd.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traj_files
|
str or list of str
|
Trajectory path(s). Each is processed independently. |
required |
topology
|
str
|
Topology for all of traj_files. |
required |
remove_original
|
bool
|
Delete each input after writing its aligned copy (default True). Set False when the inputs are read-only or shared. |
True
|
is_membrane
|
bool
|
Skip imaging: |
False
|
reference
|
str or Trajectory
|
Structure whose first frame is the superposition target. Default (None) superposes each trajectory onto its own first frame; pass a reference when several trajectories must share one Cartesian frame. Must have a topology compatible with align_select. |
None
|
align_select
|
str
|
MDTraj selection used for the superposition (default |
'backbone'
|
out_dir
|
str
|
Write aligned trajectories here instead of next to the inputs. |
None
|
Returns:
| Type | Description |
|---|---|
list of str
|
Paths of the aligned trajectories. |
Notes
Superposition rotates the coordinates but not the box, so do not run PBC-dependent calculations (minimum image, re-imaging) on aligned output.
compute_rmsd ¶
compute_rmsd(u, u_ref, alig_select: str = 'backbone', groupselections: dict = {}, aligned_fname: str = None, plots_outdir: str = None, suffix: str = None) -> pd.DataFrame
Compute RMSD of one or more atom groups relative to a reference structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Universe
|
Mobile trajectory universe. |
required |
u_ref
|
Universe
|
Reference universe (single frame). |
required |
alig_select
|
str
|
MDAnalysis selection string used for alignment (default |
'backbone'
|
groupselections
|
dict
|
Mapping of label -> MDAnalysis selection string for additional RMSD groups to track beyond the alignment selection. |
{}
|
aligned_fname
|
str
|
If provided, write the aligned trajectory to this path. |
None
|
plots_outdir
|
str
|
If provided, save per-group RMSD line plots to this directory. |
None
|
suffix
|
str
|
Appended to plot filenames to distinguish runs. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns: |
get_pocket_atoms_idxs ¶
get_pocket_atoms_idxs(u: Universe = None, pocket_selection: str = None, ligand_selection: str = None, cutoff: float = 8.0) -> List[int]
Return atom indices defining the binding pocket.
Exactly one of pocket_selection or ligand_selection must be provided. When pocket_selection is given it is used directly. When ligand_selection is given, the pocket is the protein CA atoms within cutoff Å of any ligand heavy atom (evaluated at the last trajectory frame).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Universe
|
MDAnalysis Universe containing the system. |
None
|
pocket_selection
|
str
|
Arbitrary MDAnalysis selection string for the pocket atoms. |
None
|
ligand_selection
|
str
|
MDAnalysis selection string for the ligand; used to identify pocket residues by proximity. |
None
|
cutoff
|
float
|
Distance cutoff in Angstroms for proximity-based pocket detection. |
8.0
|
Returns:
| Type | Description |
|---|---|
list of int
|
Atom indices of the pocket atoms. |
get_ligand_anchor_atoms ¶
get_ligand_anchor_atoms(u, lig_selection: str, pocket_sel: str = None, mode: str = 'murcko', frames: int = 100, n_atoms: int = 5, reduce_before: bool = False, expand_rings: bool = True, out_dir: str = None, verbose: bool = True, ref_mol=None)
Select anchor atoms on the ligand for COM-based pulling and optionally visualize them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Universe
|
MDAnalysis Universe (trajectory should be loaded). |
required |
lig_selection
|
str
|
MDAnalysis selection string identifying the ligand. |
required |
pocket_sel
|
str
|
Selection string for the binding pocket; defaults to protein atoms within 5 Å of the ligand (heavy atoms only). |
None
|
mode
|
str
|
Strategy for picking anchor atoms. Options:
|
'murcko'
|
frames
|
int
|
Number of frames to sample, evenly spaced over the second half of the trajectory, for contact-based modes. |
100
|
n_atoms
|
int
|
Maximum number of anchor atoms for COM/contact/inertia modes. |
5
|
reduce_before
|
bool
|
If True, reduce the ligand to its Murcko scaffold before applying the chosen mode. |
False
|
expand_rings
|
bool
|
If True, expand the anchor selection to include all atoms in any ring that contains at least one anchor atom (heavy atoms only). |
True
|
out_dir
|
str
|
Directory where the 2D highlight image is saved. |
None
|
verbose
|
bool
|
Log ring-expansion details at DEBUG level. |
True
|
ref_mol
|
Mol
|
Reference RDKit molecule for 2D visualization alignment. |
None
|
Returns:
| Type | Description |
|---|---|
list of int
|
MDAnalysis atom indices of the selected anchor atoms. |
min_image_distance ¶
min_image_distance(u: Universe, sel_a: str, sel_b: Optional[str] = None, start: Optional[int] = None, stop: Optional[int] = None, step: Optional[int] = None) -> np.ndarray
Per-frame minimum distance from sel_a to the periodic images of sel_b.
Each molecule (chain, else bonded fragment) is first shifted to the image
nearest the first molecule of sel_b, so a ligand wrapped to the far side
of the box counts as bound. The distance is then taken over the 26
neighbouring images of sel_b. With sel_b=None the selection is
compared with its own images (e.g. protein self-contact across the box).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Universe
|
Universe with a periodic box consistent with its coordinates. |
required |
sel_a
|
str
|
MDAnalysis selection. |
required |
sel_b
|
str
|
MDAnalysis selection of the imaged group (default: |
None
|
start
|
int
|
Frame slice. |
None
|
stop
|
int
|
Frame slice. |
None
|
step
|
int
|
Frame slice. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Minimum image distance per analysed frame (Å). |
Raises:
| Type | Description |
|---|---|
ValueError
|
On superposed ( |
periodic_image_report ¶
periodic_image_report(u: Universe, system, ligand_sel: Optional[str] = None, protein_sel: str = 'protein and not name H*', step: Optional[int] = None) -> pd.DataFrame
Per-frame closest approach to a periodic image, flagged against the nonbonded cutoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Universe
|
Non-superposed trajectory (see :func: |
required |
system
|
System
|
System whose NonbondedForce cutoff is the threshold. |
required |
ligand_sel
|
str
|
Ligand selection; adds a ligand-to-protein-images column. |
None
|
protein_sel
|
str
|
Protein selection. |
'protein and not name H*'
|
step
|
int
|
Frame stride. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
add_variants ¶
add_variants(modeller: Modeller, variants_dict: dict = None) -> Modeller
Apply user-specified protonation-state variants and add hydrogens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modeller
|
Modeller
|
OpenMM Modeller to modify. |
required |
variants_dict
|
dict
|
Mapping of |
None
|
Returns:
| Type | Description |
|---|---|
Modeller
|
The same Modeller object after |
autopath.autopath_core.AutoPath ¶
Main orchestrator for the AutoPath binding-free-energy pipeline.
AutoPath runs a four-stage protocol that takes a protein-ligand PDB as input and produces steered-MD unbinding free-energy profiles:
- System preparation — parametrises the protein + ligand, solvates,
adds ions, and writes
system.xml/system.pdbvia :class:~autopath.preparation.SystemPreparation. - Equilibration — multi-stage NPT/NVT equilibration via
:class:
~autopath.equilibration.Equilibration. Saves a checkpoint and an equilibrated PDB used by all downstream stages. - Steered MD (sMD) — pulls the ligand out of the pocket along the COM
distance at multiple speeds via :class:
~autopath.pulling.SteeredMD. Replicas can be run until convergence (sMD_converge_speeds=True) or to a fixed count. A hard cap (sMD_max_replicas) prevents infinite loops. - Path clustering & PMF estimation — :class:
~autopath.pulling.SMDAnalysisclusters trajectories with DTW-based path models, estimates the PMF via cumulant and Jarzynski estimators, and identifies medoid trajectories.
Subcomponents
:class:~autopath.preparation.SystemPreparation,
:class:~autopath.equilibration.Equilibration,
:class:~autopath.pulling.SteeredMD,
:class:~autopath.pulling.SMDAnalysis
Parameter groups
General
VS_mode, pdb_path, do_fix_pdb, pocket_selection,
temperature, random_state, platform
System preparation
run_preparation, forcefield, hydrogenMass, timestep,
lig_ff, boxShape, padding, ionicStrength, ions,
variants, is_membrane, lipid_type
Equilibration
run_equilibration, protocol_fname
Steered MD
run_sMDpulling, sMD_outdir, sMD_pulling_dir,
sMD_pulling_speeds, sMD_max_pulling_dist, sMD_max_r_offset,
sMD_autostop_nc, sMD_autostop_nc_window,
sMD_autostop_min_displacement, sMD_autostop_unbound_nm, sMD_converge_speeds,
sMD_time, sMD_steps_per_move, sMD_dx_per_move,
sMD_spring_cte, sMD_ligand_anchor_mode, sMD_max_replicas,
sMD_run_analysis, sMD_align_trajs, sMD_clust_selection, sMD_features,
sMD_log_geom_features, sMD_plateau_frac,
sMD_cluster_to_boundary, sMD_boundary_buffer_frac,
sMD_kramers_abs, sMD_kramers_bound,
cluster_across_speeds, sMD_min_replicas_per_path
run ¶
run(ligand_file: str = None, ligand_selection: str = 'resname UNK')
Execute the full AutoPath pipeline for one ligand.
Stages are run in order: system preparation → equilibration →
steered MD → path clustering.
Each stage can be skipped by setting the corresponding run_* flag
to False in the constructor; the stage will read outputs written by
a previous run instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ligand_file
|
str
|
Path to the ligand SDF file. The stem of this filename is used as
the system name (output subdirectory). If |
None
|
ligand_selection
|
str
|
MDAnalysis / OpenMM selection string identifying the ligand residue.
Default |
'resname UNK'
|
Returns:
| Type | Description |
|---|---|
None
|
All results are written to disk under the system-name subdirectory. |