Skip to content

Analysis

autopath.ap_PLIP.ProteinLigandAnalyzer

Simple analysis class for protein-ligand or protein-protein MD simulations.

Features: - load multiple trajectories (replicas). Should have same topology - compute interactions with ProLif - compute LIE using pytraj. Optional selection of residues based on ProLif results.

concat_trajectories

concat_trajectories()

Concatenate all replica trajectories into a single MDAnalysis Universe.

Returns:

Type Description
Universe

A new Universe whose trajectory is the in-memory concatenation of all replicas.

write_combined_trajectory staticmethod

write_combined_trajectory(topology: str, trajectories: List[str], output_traj: str, start: Optional[int] = None, stop: Optional[int] = None, step: Optional[int] = None) -> str

Combine multiple trajectory files into a single output trajectory.

Each input trajectory is sliced with start/stop/step independently before being appended to the output.

Parameters:

Name Type Description Default
topology str

Topology file (PRMTOP, PSF, PDB, etc.)

required
trajectories list of str

Input trajectory files (DCD, XTC, etc.)

required
output_traj str

Output trajectory filename.

required
start int or None

Slicing applied independently to each input trajectory.

None
stop int or None

Slicing applied independently to each input trajectory.

None
step int or None

Slicing applied independently to each input trajectory.

None

Returns:

Type Description
str

Path to the combined output trajectory file (output_traj).

find_interfacial_waters

find_interfacial_waters(u: Universe, ligand_sel: str = 'resname UNK', protein_sel: str = 'protein', traj_slice: tuple = None, cutoff: float = 3.5, fraction_persistence: float = 0.5, pdb_fname: str = None)

Identify persistent interfacial water molecules across a trajectory.

A water residue is considered interfacial in a frame when at least one of its atoms is within cutoff Å of the protein and within cutoff Å of the ligand simultaneously. Only waters that are interfacial in at least fraction_persistence of all analyzed frames are returned.

Parameters:

Name Type Description Default
u Universe

MDAnalysis Universe with topology and trajectory loaded.

required
ligand_sel str

MDAnalysis selection string for the ligand.

'resname UNK'
protein_sel str

MDAnalysis selection string for the protein.

'protein'
traj_slice tuple of (int, int, int) or None

(start, end, step) frame slice. If None, all frames are analyzed.

None
cutoff float

Distance threshold (Å) for the protein–water and ligand–water contacts.

3.5
fraction_persistence float

Minimum fraction of frames in which a water must be interfacial to be included in the returned set (e.g. 0.9 means present in >= 90% of frames). Interfacial water exchanges fast enough that 0.9 can return nothing at all; 0.5 keeps the structural core without admitting bulk.

0.5
pdb_fname str or None

If provided, write a PDB containing the protein, ligand, and persistent waters from the last trajectory frame to this path.

None

Returns:

Type Description
dict

{resid: persistence_fraction} for waters that meet the threshold, sorted by descending persistence.

get_persistent_interactions

get_persistent_interactions(fp_interactions: Optional[List[str]] = None, frequency_cutoff: float = 0.5, stride: int = 1, n_jobs: int = 1)

Identify most persistent interactions across replicas using ProLif.

Parameters:

Name Type Description Default
fp_interactions list of str or None

ProLIF interaction types to fingerprint. If None, ProLIF defaults are used.

None
frequency_cutoff float

Fraction of frames in [0, 1]; only interactions present in at least this fraction are kept (0.5 means 50%).

0.5
stride int

Analyse every stride-th frame of each replica trajectory. Must be >= 1. Ignored for replicas whose fingerprint is read from cache.

1
n_jobs int

Number of parallel workers for ProLIF. See Warning below.

1

Returns:

Name Type Description
important_resids list of int

Sorted residue IDs whose interaction frequency exceeds frequency_cutoff, pooled over all replicas. These are numbered as in the TOPOLOGY that was loaded. A prmtop renumbers sequentially from 1, so they are generally offset from the original PDB author numbering (e.g. 5 for a structure whose first modelled residue is 6) -- convert before comparing against crystal-structure residue numbers.

persistence_byRes DataFrame

Interaction persistence in percent, grouped by residue (all interaction types merged), for every replica stacked with a replica column.

persistence_byRes_byType DataFrame

Same, broken down by residue and interaction type.

Warning

The n_jobs parameter is currently non-functional due to serialization incompatibilities (dill/multiprocess version conflicts in ProLIF). All fingerprint computations run serially regardless of the value passed.

plot_tanimoto_similarity staticmethod

plot_tanimoto_similarity(query_fp, reference_fp, use_frame: int = None, outdir: str = None)

Plot Tanimoto similarity between ProLIF fingerprints and save the figure(s).

Parameters:

Name Type Description Default
query_fp Fingerprint

Fingerprint to compare against (all frames).

required
reference_fp Fingerprint or None

Reference fingerprint. If None, query_fp is used as its own reference (self-similarity matrix).

required
use_frame int or None

If provided, compute similarity of every query frame to this reference frame and plot a line graph. If None, compute and plot the full similarity matrix.

None
outdir str or None

Directory for output figures. Defaults to current directory.

None

Returns:

Type Description
list of float or pd.DataFrame

If use_frame is set: list of per-frame Tanimoto similarities. Otherwise: symmetric similarity matrix as a DataFrame.

compute_LIE

compute_LIE(prmtop: Optional[str] = None, use_residues: Optional[List[int]] = None, ligand_amber_selection: str = ':UNK', exclude_amber_selection: Optional[str] = DEFAULT_LIE_EXCLUDE, cutoff: float = 6.0, stride: int = 1, lie_options: str = 'nopbc cutvdw 10.0 cutelec 10.0')

Compute Linear Interaction Energy (LIE) for each replica using pytraj.

LIE approximates binding free energy as a linear combination of electrostatic and van der Waals interaction energies between the ligand and the surrounding environment. See:

  • https://ambermd.org/tutorials/advanced/tutorial24/liew.php
  • https://pubs.acs.org/doi/10.1021/acs.jcim.9b00609
  • https://pmc.ncbi.nlm.nih.gov/articles/PMC7311763/

.. important:: Bound state only, so what is returned is a ligand/partner interaction energy suitable for ranking, not a binding free energy. Solvent, ions and lipids are excluded from the surroundings by default (:data:DEFAULT_LIE_EXCLUDE); see :func:environment_resids. Explicit solvent must still be present in the trajectory.

.. note:: With use_residues=None the environment is picked once from frame 0 and held fixed, which is only sound for residues that stay put. Passing use_residues explicitly avoids both the cutoff and the frame-0 dependence.

Parameters:

Name Type Description Default
prmtop str or None

Amber PRMTOP topology for pytraj. Defaults to self.top.

None
use_residues list of int or None

Explicit list of 1-based residue numbers to include in the LIE environment mask. If None, residues within cutoff Å of the ligand are selected automatically from frame 0. Passing the binding partner's residues explicitly is the most defensible option: no cutoff, no frame-0 dependence.

None
ligand_amber_selection str

Amber mask for the ligand (e.g. ":UNK").

':UNK'
exclude_amber_selection str or None

Amber mask removed from the auto-selected environment. Defaults to :data:DEFAULT_LIE_EXCLUDE (ions + water + lipids), leaving the biomolecular binding partner. Pass None to include everything else, which is only correct if you also simulate the free ligand and subtract. Ignored when use_residues is given.

DEFAULT_LIE_EXCLUDE
cutoff float

Distance cutoff (Å) used to auto-select environment residues when use_residues is None.

6.0
stride int

Frame stride passed to pt.iterload.

1
lie_options str

Additional options string passed to pt.analysis.energy_analysis.lie (e.g. 'nopbc cutvdw 10.0 cutelec 10.0').

'nopbc cutvdw 10.0 cutelec 10.0'

Returns:

Type Description
DataFrame

Combined LIE results for all replicas with columns EELEC, VDW, Total, and run. Also saved to {outdir}/LIE_results.csv.

plot_lie_components

plot_lie_components(lie_df: DataFrame) -> None

Plot LIE energy components (Total, EELEC, VDW) over time and save the figure.

Parameters:

Name Type Description Default
lie_df DataFrame

Output of :meth:compute_LIE, with columns Total, EELEC, VDW.

required

prepare_mmgbsa_batch staticmethod

prepare_mmgbsa_batch(sysname: str = None, prmtop: str = None, traj_fname: str = None, ligand_amber_selection: str = ':UNK', ligand_mda_selection: str = 'resname UNK', strip_amber_selection: str = ':POP:HOH:WAT:NA:CL:K:MG', traj_slice: tuple = None, persistent_waters_cutoff: float = None, mmpbsa_in: str = 'mmgbsa.in', radii: str = 'mbondi2', output_folder: str = 'mmgbsa_results', bash_fname: str = 'run_mmgbsa_batch.sh', mpi_threads: int = 222, slurm_template_fname: str = None, partition: str = 'forli,forli-pro,shared,highmem,gpu', time: str = '1-0')

Prepare a per-system MMPBSA SLURM qfile and a master batch script.

Writes a modified MMPBSA input file (with correct frame range and optional persistent-water strip mask) and a SLURM submission script, then updates a master bash script that submits all qfiles in the qfiles_mmgbsa/ directory with sbatch.

Parameters:

Name Type Description Default
sysname str

Identifier for this system (used in output filenames).

None
prmtop str

Amber topology file (.prmtop).

None
traj_fname str

Trajectory file (DCD, XTC, NC, …).

None
ligand_amber_selection str

Amber mask for the ligand (e.g. ":UNK").

':UNK'
ligand_mda_selection str or None

MDAnalysis selection string for the ligand. Derived from ligand_amber_selection if not provided.

'resname UNK'
strip_amber_selection str

Amber mask of residues to strip before MMPBSA (waters, ions, lipids).

':POP:HOH:WAT:NA:CL:K:MG'
traj_slice tuple of (int, int, int) or None

(start, end, step) frame slice applied to the trajectory.

None
persistent_waters_cutoff float or None

If provided, waters whose occupancy at the protein–ligand interface exceeds this fraction are kept in the MMPBSA calculation. Waters are identified with :meth:find_interfacial_waters.

None
mmpbsa_in str

Path to the MMPBSA input template file.

'mmgbsa.in'
radii str

Implicit-solvent radii set (e.g. 'mbondi2').

'mbondi2'
output_folder str

Directory for MMPBSA output and the modified input file.

'mmgbsa_results'
bash_fname str

Filename of the master sbatch batch script.

'run_mmgbsa_batch.sh'
mpi_threads int

Maximum number of MPI threads. Capped at the number of frames.

222
slurm_template_fname str or None

Path to a custom SLURM template. Defaults to the bundled template.

None
partition str

SLURM partition(s) written to the qfile.

'forli,forli-pro,shared,highmem,gpu'
time str

SLURM wall-time limit written to the qfile.

'1-0'

Returns:

Type Description
str

Path to the written master batch script (bash_fname).

parse_mmpbsa_differences_table staticmethod

parse_mmpbsa_differences_table(path: str) -> pd.DataFrame

Parse the 'Differences' table from an AMBER MMPBSA results file.

Reads the Differences (Complex - Receptor - Ligand): section from FINAL_RESULTS_mmpbsa.dat and returns one row per energy component.

Parameters:

Name Type Description Default
path str

Path to FINAL_RESULTS_mmpbsa.dat.

required

Returns:

Type Description
DataFrame

Columns: Component, Average, Std_Dev, Std_Err_Mean.

Raises:

Type Description
ValueError

If the Differences section is not found, or if no data rows are parsed.

parse_mmpbsa_deltas_all_components staticmethod

parse_mmpbsa_deltas_all_components(filepath: str = None) -> pd.DataFrame

Parse the DELTAS section of an AMBER MMPBSA per-residue decomposition file.

Reads the CSV-formatted DELTAS: block produced by AMBER's MMPBSA per-residue decomposition (PB or GB), and returns one row per residue.

Parameters:

Name Type Description Default
filepath str

Path to the MMPBSA per-residue decomposition output file (typically FINAL_DECOMP_MMPBSA.dat).

None

Returns:

Type Description
DataFrame

Columns: resname, resid, location, and one {Component}_Avg, {Component}_StdDev, {Component}_StdErr column per energy group (e.g. Internal, van_der_Waals, Electrostatic, etc.). An additional label column is appended (resname + resid).

Raises:

Type Description
ValueError

If the DELTAS: section is not found or the header format is unexpected.

plot_mmpbsa_byresidue staticmethod

plot_mmpbsa_byresidue(df_decomp: DataFrame, top_residues: int = 10, out_dir: str = None)

Plot per-residue MMGBSA energy decomposition as bar charts.

For each energy component and each molecular location (receptor, ligand), saves one bar chart showing the top_residues most favorable and most unfavorable residues.

Parameters:

Name Type Description Default
df_decomp DataFrame

Output of :meth:parse_mmpbsa_deltas_all_components.

required
top_residues int

Number of top and bottom residues to display per component.

10
out_dir str or None

Output directory for PNG files. Defaults to the current directory.

None
Note

The 'L' (ligand) location is included for protein–protein interaction studies where both partners are decomposed.

paint_mmpbsa_byresidue staticmethod

paint_mmpbsa_byresidue(df_decomp, pdb_file: str = None, prmtop_file: str = None, mmpbsa_component: str = 'all', normalize: bool = False, outdir: str = None)

Color a PDB structure by per-residue MMGBSA decomposition values via B-factor.

Parameters:

Name Type Description Default
df_decomp DataFrame

Output of :meth:parse_mmpbsa_deltas_all_components, containing per-residue MMGBSA energy components.

required
pdb_file str

Path to the PDB file to paint.

None
prmtop_file str

Path to the Amber topology file (.prmtop).

None
mmpbsa_component str

Energy component column to write into the B-factor field. Use 'all' to iterate over all standard components. One of {'TOTAL_Avg', 'Electrostatic_Avg', 'van_der_Waals_Avg', 'Polar_Solvation_Avg', 'Non_Polar_Solv_Avg', 'all'}.

'all'
normalize bool

If True, rescale B-factors to [0, 100] for easier VMD/PyMOL visualization.

False
outdir str or None

Directory for output PDB files. Defaults to current directory.

None

Raises:

Type Description
ValueError

If pdb_file or prmtop_file is None, or if mmpbsa_component is not a recognized component name.

autopath.ap_PLIP.ligand_rmsf_contacts

ligand_rmsf_contacts(u, ligand_selection: str = 'resname UNK', start: int = None, stop: int = None, step: int = None, pocket_cutoff: float = 5.0, contact_cutoff: float = 3.5) -> pd.DataFrame

Per-atom RMSF and pocket-contact frequency of the ligand heavy atoms.

The trajectory must already be centred and superposed on the protein (e.g. the *_aligned.dcd written by :func:autopath.utils.wrap_align_save_traj).

Parameters:

Name Type Description Default
u Universe

Universe with the aligned trajectory.

required
ligand_selection str

MDAnalysis selection string for the ligand.

'resname UNK'
start int

Frame slice to analyse (default: whole trajectory). The pocket is defined on the first frame of the slice.

None
stop int

Frame slice to analyse (default: whole trajectory). The pocket is defined on the first frame of the slice.

None
step int

Frame slice to analyse (default: whole trajectory). The pocket is defined on the first frame of the slice.

None
pocket_cutoff float

Protein heavy atoms within this distance (Å) of the ligand define the pocket.

5.0
contact_cutoff float

Ligand–pocket heavy-atom distance (Å) counted as a contact.

3.5

Returns:

Type Description
DataFrame

One row per ligand heavy atom with columns atom_name, element, rmsf (Å) and contact_freq (fraction of analysed frames).

autopath.ap_PLIP.cw_rmsf

cw_rmsf(per_atom: DataFrame, atom_set='polar') -> float

Contact-weighted RMSF, sum(c_i * RMSF_i) / sum(c_i), over one set of ligand atoms.

Parameters:

Name Type Description Default
per_atom DataFrame

Columns element, rmsf and contact_freq, as returned by :func:ligand_rmsf_contacts (or read from <sys>_RMSF.csv).

required
atom_set str or list of str

A key of CW_RMSF_ATOM_SETS ('polar', 'nonpolar', 'all') or an explicit list of element symbols.

'polar'

Returns:

Type Description
float

cw-RMSF in Å.

Raises:

Type Description
ValueError

If no atom of the set is ever in contact with the pocket (score undefined).

autopath.ap_PLIP.cw_rmsf_scores

cw_rmsf_scores(per_atom: DataFrame, atom_sets=tuple(CW_RMSF_ATOM_SETS), on_undefined: str = 'raise') -> dict

cw-RMSF for several atom sets (see :func:cw_rmsf).

Parameters:

Name Type Description Default
per_atom DataFrame

Output of :func:ligand_rmsf_contacts.

required
atom_sets iterable of str

Keys of CW_RMSF_ATOM_SETS.

tuple(CW_RMSF_ATOM_SETS)
on_undefined ('raise', nan)

For a set with no pocket contact: raise ValueError or report NaN (logged).

'raise'

Returns:

Type Description
dict

{'cw_rmsf_<set>': value}.

autopath.ap_PLIP.cw_rmsf_windows

cw_rmsf_windows(u, ligand_selection: str, state_csv: str, protocol, component: str = 'ligand')

cw-RMSF over the whole run and over the free window of an equilibration.

Parameters:

Name Type Description Default
u Universe

Universe with the aligned equilibration trajectory.

required
ligand_selection str

MDAnalysis selection string for the ligand.

required
state_csv str

Passed to :func:autopath.equilibration.free_window_start.

required
protocol str

Passed to :func:autopath.equilibration.free_window_start.

required
component str

Passed to :func:autopath.equilibration.free_window_start.

required

Returns:

Name Type Description
table DataFrame

Indexed by window ('whole', 'free') with first_frame and cw_rmsf_<set> columns (NaN for a set with no pocket contact). The 'free' row is absent when the protocol has no free window.

per_atom dict of pd.DataFrame

:func:ligand_rmsf_contacts output per window.

autopath.ap_PLIP.plot_atomic_property

plot_atomic_property(u, weights: ndarray, lig_resname: str = 'resname UNK', outname: str = 'property.png', ref_mol=None, color=None, colormap=None) -> None

Plot a per-atom scalar property on the ligand 2D structure and save as image.

color: any matplotlib color ('blue', '#1f77b4', (r,g,b,a)) — sets the fill gradient highlight for high positive values (white → color). Takes precedence over colormap. colormap: full 3-color colourMap as a matplotlib colormap object/string, or a list of three RGBA tuples for [negative, zero, positive].