### Install ProLIF with Tutorial Dependencies
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/tutorials.rst
Install ProLIF along with the necessary dependencies for running the tutorials. This command ensures all required packages are available for the examples.
```bash
pip install prolif[tutorials]
```
--------------------------------
### Install ProLIF with Optional Tutorial Dependencies
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/installation.rst
Install ProLIF along with optional dependencies required for running the tutorials using pip.
```bash
pip install prolif[tutorials]
```
--------------------------------
### Install ProLIF with Pip
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/installation.rst
Install ProLIF and its core dependency RDKit using pip. This is an alternative to conda installation.
```bash
pip install rdkit prolif
```
--------------------------------
### Install Development Version of ProLIF
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/installation.rst
Install the latest development version of ProLIF directly from its GitHub repository using pip. Use with caution as it may be unstable.
```bash
pip install git+https://github.com/chemosim-lab/ProLIF.git
```
--------------------------------
### Install ProLIF with Conda
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/installation.rst
Install the ProLIF library from the conda-forge channel using the conda package manager.
```bash
conda install -c conda-forge prolif
```
--------------------------------
### List Available Interactions in ProLIF
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Use this command to see all interaction types that ProLIF can calculate. No setup is required beyond importing the library.
```python
plf.Fingerprint.list_available()
```
--------------------------------
### Create and Activate Conda Environment
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/installation.rst
Use these commands to create a new conda environment named 'prolif' and activate it for isolated ProLIF installation.
```bash
conda create -n prolif
```
```bash
conda activate prolif
```
--------------------------------
### Load and Display Ligand from PDB with Hydrogens
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Loads a ligand from a PDB file that already contains explicit hydrogen atoms using MDAnalysis and converts it to a ProLIF molecule for display. Requires MDAnalysis to be installed.
```python
# load PDB with explicit hydrogens
ligand_file = str(plf.datafiles.datapath / "vina" / "lig.pdb")
u = mda.Universe(ligand_file)
ligand_mol = plf.Molecule.from_mda(u)
# display ligand
plf.display_residues(ligand_mol, size=(400, 200))
```
--------------------------------
### Load Molecular Structures
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Reads protein and ligand files using MDAnalysis and Prolif. Ensure MDAnalysis is installed and molecular files are accessible.
```python
import MDAnalysis as mda
from prolif import Molecule
from prolif.datafiles import datapath
# Read the protonated protein file
data_path = datapath / "implicitHbond"
protein_path = data_path / "receptor_ph7_amber.pdb"
u = mda.Universe(str(protein_path))
protein_mol = Molecule.from_mda(u)
plf.display_residues(protein_mol, slice(100, 108))
```
```python
# Read the protonated ligand file
ligand = plf.sdf_supplier(str(data_path / "1.D_protonated.sdf"))[0]
plf.display_residues(ligand, size=(400, 200))
```
--------------------------------
### Select Protein Components Over Trajectory
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Uses `select_over_trajectory` to perform selections dynamically across frames, ensuring all relevant residues are captured even if the ligand or protein moves significantly. This example selects atoms every 10 frames.
```python
large_protein_selection = plf.select_over_trajectory(
u,
u.trajectory[::10],
"protein and byres around 6.0 group peptide",
peptide=small_protein_selection,
)
```
--------------------------------
### Build Project Documentation
Source: https://github.com/chemosim-lab/prolif/blob/master/CONTRIBUTING.md
Generate the HTML documentation files for the project. Open `docs/_build/html/index.html` to view.
```bash
uv run poe docs
```
--------------------------------
### Create Development Environment with uv
Source: https://github.com/chemosim-lab/prolif/blob/master/CONTRIBUTING.md
Use uv to synchronize dependencies and set up a Python 3.11 virtual environment for development.
```bash
uv sync --python 3.11
```
--------------------------------
### Load Protein and Ligand Files with ProLIF
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Sets up protein and ligand files using MDAnalysis and ProLIF for subsequent use cases. Ensures necessary data files are accessible.
```python
import MDAnalysis as mda
import prolif as plf
# load protein
protein_file = str(plf.datafiles.datapath / "vina" / "rec.pdb")
u = mda.Universe(protein_file)
protein_mol = plf.Molecule.from_mda(u)
# load docking poses
poses_path = str(plf.datafiles.datapath / "vina" / "vina_output.sdf")
pose_iterable = plf.sdf_supplier(poses_path)
# load 1 ligand from poses
ligand_mol = pose_iterable[0]
```
--------------------------------
### Run Test Suite
Source: https://github.com/chemosim-lab/prolif/blob/master/CONTRIBUTING.md
Execute the entire test suite for the ProLIF project.
```bash
uv run poe test
```
--------------------------------
### Load Docking Poses from PDBQT Files
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Loads docking poses from a list of PDBQT files using ProLIF's pdbqt_supplier. A template molecule (e.g., from RDKit) is required to assign bond orders and charges.
```python
# load list of ligands
pdbqt_files = sorted(plf.datafiles.datapath.glob("vina/*.pdbqt"))
pdbqt_files
```
```python
pose_iterable = plf.pdbqt_supplier(pdbqt_files, template)
```
--------------------------------
### Hide Interaction Type in DataFrame
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Remove a specific interaction type, such as 'HBAcceptor', from the DataFrame view by using the `drop` method. This example shows the first 5 frames.
```python
# hide an interaction type (HBAcceptor)
df.drop("HBAcceptor", level="interaction", axis=1).head(5)
```
--------------------------------
### Show Single Protein Residue Interactions
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Filter the DataFrame to display interactions involving only a specific protein residue, like 'LYS191.A', using the `xs` method. This example shows the first 5 frames.
```python
# show only one protein residue (LYS191.A)
df.xs("LYS191.A", level="protein", axis=1).head(5)
```
--------------------------------
### Run All Project Checks
Source: https://github.com/chemosim-lab/prolif/blob/master/CONTRIBUTING.md
Execute all defined checks, including tests, linting, and type checking, using poethepoet via uv.
```bash
uv run poe check
```
--------------------------------
### Check Code Formatting and Linting
Source: https://github.com/chemosim-lab/prolif/blob/master/CONTRIBUTING.md
Verify if the code adheres to the project's style standards and linting rules.
```bash
uv run poe style-check
```
--------------------------------
### Create and Display Ligand Molecule
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Create a ProLIF Molecule object from an MDAnalysis selection of the ligand. This molecule can then be visualized. Ensure all atoms, including hydrogens, are present in the input file for accurate bond order and charge inference.
```python
# create a molecule from the MDAnalysis selection
ligand_mol = plf.Molecule.from_mda(ligand_selection)
# display
plf.display_residues(ligand_mol, size=(400, 200))
```
--------------------------------
### Initialize and Draw Network Graph
Source: https://github.com/chemosim-lab/prolif/blob/master/prolif/plotting/network/network.html
Initializes the network graph using provided nodes, edges, and options. Requires a target div ID for rendering. Also creates a legend for the network.
```javascript
var ifp, legend, nodes, edges, legend_buttons;
nodes = %(nodes)s;
edges = %(edges)s;
ifp = drawGraph('%(div_id)s', nodes, edges, %(options)s);
createLegend('networklegend', %(buttons)s);
```
--------------------------------
### Load Docking Poses from MOL2
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Loads docking poses from a MOL2 file using ProLIF's mol2_supplier. Ensure the poses_path points to your MOL2 file.
```python
# load ligands
poses_path = str(plf.datafiles.datapath / "vina" / "vina_output.mol2")
pose_iterable = plf.mol2_supplier(poses_path)
```
--------------------------------
### Load Docking Poses from SDF
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Loads docking poses from an SDF file using ProLIF's sdf_supplier. Ensure the poses_path points to your SDF file.
```python
# load ligands
poses_path = str(plf.datafiles.datapath / "vina" / "vina_output.sdf")
pose_iterable = plf.sdf_supplier(poses_path)
```
--------------------------------
### Read and Display Ligand from SDF
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Reads a ligand molecule from an SDF file and displays it. Ensure the SDF file is correctly formatted.
```python
# read SDF
ligand_file = str(plf.datafiles.datapath / "vina" / "vina_output.sdf")
ligand_mol = plf.sdf_supplier(ligand_file)[0]
# display ligand
plf.display_residues(ligand_mol, size=(400, 200))
```
--------------------------------
### Load Reference Ligand for Comparison
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Loads a reference ligand structure from a PDB file using MDAnalysis and converts it into a Prolif Molecule object. The reference ligand must contain explicit hydrogens.
```python
# load the reference
ref = mda.Universe(plf.datafiles.datapath / "vina" / "lig.pdb")
ref_mol = plf.Molecule.from_mda(ref)
```
--------------------------------
### Create Ligand Poses and Solvated Protein Molecule
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/water-bridge.ipynb
Generate a list of ligand poses for each frame in the MD trajectory and create a ProLIF Molecule object for the solvated protein (protein + water).
```python
# create list of ligand poses for each frame in the MD trajectory
ligand_poses = [plf.Molecule.from_mda(ligand_selection) for ts in u.trajectory]
# create protein with waters
solvated_protein_mol = plf.Molecule.from_mda(protein_selection + water_selection)
```
--------------------------------
### Prepare Ligand from SMILES and PDB Coordinates
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Combines a SMILES string with coordinates from a PDB file to create a molecule object for ProLIF. This method adds explicit hydrogens and may require a subsequent minimization step for optimal hydrogen bonding.
```python
from rdkit import Chem
from rdkit.Chem.AllChem import AssignBondOrdersFromTemplate
pdb_ligand = Chem.MolFromPDBFile(str(plf.datafiles.datapath / "vina" / "lig.pdb"))
smiles_mol = Chem.MolFromSmiles("C[NH+]1CC(C(=O)NC2(C)OC3(O)C4CCCN4C(=O)C(Cc4ccccc4)N3C2=O)C=C2c3cccc4[nH]cc(c34)CC21")
mol = AssignBondOrdersFromTemplate(smiles_mol, pdb_ligand)
mol_h = Chem.AddHs(mol)
ligand_mol = plf.Molecule.from_rdkit(mol_h)
```
--------------------------------
### Load Topology and Trajectory with MDAnalysis
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Load the topology and trajectory files using MDAnalysis. This step is essential for accessing simulation data. Ensure the paths to TOP and TRAJ are correctly set for your system.
```python
import MDAnalysis as mda
import prolif as plf
# load topology and trajectory
u = mda.Universe(plf.datafiles.TOP, plf.datafiles.TRAJ)
# create selections for the ligand and protein
ligand_selection = u.select_atoms("resname LIG")
protein_selection = u.select_atoms("protein")
ligand_selection, protein_selection
```
--------------------------------
### Configure Fingerprint Generator with Counting Enabled
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Initializes a ProLIF Fingerprint generator with the 'count' parameter enabled to enumerate all occurrences of interactions. This allows for displaying interactions with the smallest distance or all occurrences.
```python
fp_count = plf.Fingerprint(count=True)
fP_count.run(u.trajectory[0:1], small_protein_selection, large_protein_selection)
```
--------------------------------
### Load and Apply MoleculeStandardizer Templates
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Loads residue templates (ACE, TPO, NME) using CIF or RDKit Mol formats and initializes the MoleculeStandardizer. This prepares the standardizer to fix bond orders in a molecule.
```python
from prolif.datafiles import datapath
from prolif.io import MoleculeStandardizer, cif_template_reader
# load templates
ace_template = ("ACE", Chem.MolFromSmiles("CC=O"))
tpo_template = ("TPO", Chem.MolFromSmiles("C[C@H]([C@@H](C(=O))N)OP(=O)(O)O"))
# tpo_template = cif_template_reader(
# datapath / "molecule_standardizer/templates/TPO.cif"
# ) # alternative
nme_template = cif_template_reader(datapath / "molecule_standardizer/templates/NME.cif")
# fix molecule by the templates
standardizer = MoleculeStandardizer(
templates=[ace_template, tpo_template, nme_template]
)
```
--------------------------------
### Run and Display Fingerprint Analysis
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
This snippet shows how to run the fingerprint analysis using the defined interactions and then display the results. It involves creating a Fingerprint object, running it on molecular data, and converting the results to a pandas DataFrame for inspection.
```python
# run analysis
fp = plf.Fingerprint(["CloseContact"])
fp.run_from_iterable([ligand_mol], protein_mol)
# show results
df = fp.to_dataframe()
df
```
--------------------------------
### Load Topology and Trajectory with MDAnalysis
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Load the topology and trajectory files using MDAnalysis. This is a prerequisite for processing simulation data with ProLIF.
```python
import MDAnalysis as mda
import prolif as plf
# load topology and trajectory
u = mda.Universe(plf.datafiles.TOP, plf.datafiles.TRAJ)
```
--------------------------------
### List Available Poe Tasks
Source: https://github.com/chemosim-lab/prolif/blob/master/CONTRIBUTING.md
Display a list of all available tasks defined in poethepoet for the development environment.
```bash
uv run poe --help
```
--------------------------------
### Run Docking Pose Analysis
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/water-bridge.ipynb
Analyze a collection of docking poses by providing an iterable of poses and the protein molecule. Ensure ligand poses and protein molecule are correctly formatted.
```python
fp.run_from_iterable(ligand_poses, protein_mol)
```
--------------------------------
### Compare VdW Elements Between Presets
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Shows elements present in the RDKit preset but not the default. Useful for understanding preset differences and deciding on appropriate presets for calculations.
```python
print(sorted(rdkit_vdw_elements - default_vdw_elements))
```
--------------------------------
### Prepare PDBQT Ligand Template with RDKit
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Loads a ligand structure from a SMILES string using RDKit to serve as a template for PDBQT files. This template is used to assign bond orders and charges.
```python
from rdkit import Chem
template = Chem.MolFromSmiles(
"C[NH+]1CC(C(=O)NC2(C)OC3(O)C4CCCN4C(=O)C(Cc4ccccc4)N3C2=O)C=C2c3cccc4[nH]cc(c34)CC2=O"
)
template
```
--------------------------------
### Configure Implicit H-bond Parameters
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Configures advanced parameters for implicit H-bond detection, including water inclusion, tolerance for atom and plane angles, and option to ignore geometry checks. This allows for fine-tuning the interaction detection sensitivity.
```python
fp_i = plf.Fingerprint(
interactions=["ImplicitHBAcceptor", "ImplicitHBDonor"],
count=True,
parameters={
"ImplicitHBAcceptor": {
"include_water": True, # include water residues in the detection
"tolerance_dev_daa": 30, # atom angle deviation tolerance for donor
"tolerance_dev_dpa": 30, # plane angle deviation tolerance for donor
"ignore_geometry_checks": True, # to skip geometry checks
},
"ImplicitHBDonor": {
"include_water": True, # include water residues in the detection
"tolerance_dev_daa": 30, # atom angle deviation tolerance for donor
"tolerance_dev_dpa": 30, # plane angle deviation tolerance for donor
"ignore_geometry_checks": False, # not to skip geometry checks
},
},
)
```
--------------------------------
### List Available Interactions
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Lists all interaction types that ProLIF can calculate by default. Use this to understand the available options for fingerprint generation.
```python
plf.Fingerprint.list_available()
```
--------------------------------
### Instantiate ProLIF Fingerprint
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Creates a ProLIF Fingerprint object with specified interaction types. The interaction classes are then attached as methods to the fingerprint object.
```python
fp = plf.Fingerprint(["Hydrophobic", "HBDonor", "HBAcceptor"])
fp.hydrophobic
```
--------------------------------
### Calculate Water Bridge Interactions with ProLIF
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/water-bridge.ipynb
Initialize a ProLIF Fingerprint with the WaterBridge interaction, specifying the water selection and the maximum order of water molecules in the bridge (e.g., order=3).
```python
# for docking poses, replace water_selection with water_mol
fp = plf.Fingerprint(
["WaterBridge"],
parameters={"WaterBridge": {"water": water_selection, "order": 3}},
)
```
--------------------------------
### Visualize 3D Interactions
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Creates a 3D visualization of H-bond interactions between the ligand and protein for a given frame. Setting `display_all=False` might hide certain interactions, and `remove_hydrogens=False` ensures all atoms are considered.
```python
view = fp_count.plot_3d(
ligand, protein_mol, frame=0, display_all=False, remove_hydrogens=False
)
view
```
--------------------------------
### Compare Two Poses in 3D
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Compares two different docking poses in a 3D view, highlighting differences in magenta. Requires `Complex3D` from `prolif.plotting.complex3d`.
```python
from prolif.plotting.complex3d import Complex3D
pose_index = 0
comp3D = Complex3D.from_fingerprint(
fp, pose_iterable[pose_index], protein_mol, frame=pose_index
)
pose_index = 4
other_comp3D = Complex3D.from_fingerprint(
fp, pose_iterable[pose_index], protein_mol, frame=pose_index
)
view = comp3D.compare(other_comp3D)
view
```
--------------------------------
### Visualize Water-Mediated Interactions in 3D
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/water-bridge.ipynb
Generates a 3D visualization of water-mediated interactions between the protein and ligand for a specific frame. Requires pre-prepared plf.Molecule objects for protein, ligand, and water.
```python
frame = 2
view = fp.plot_3d(ligand_mol, protein_mol, water_mol, frame=frame)
view
```
--------------------------------
### Prepare Molecules for 3D Visualization
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/water-bridge.ipynb
Prepares the protein, ligand, and water molecules as plf.Molecule objects for 3D visualization. This step is necessary when using MD trajectories and requires updating coordinates for the specified frame.
```python
# preparation for MD trajectories only
frame = 2
u.trajectory[frame] # seek frame to update coordinates of atomgroup objects
ligand_mol = plf.Molecule.from_mda(ligand_selection, use_segid=fp.use_segid)
protein_mol = plf.Molecule.from_mda(protein_selection, use_segid=fp.use_segid)
water_mol = plf.Molecule.from_mda(water_selection, use_segid=fp.use_segid)
```
--------------------------------
### Visualize Ligand-Protein Interactions in 3D
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Generates an interactive 3D visualization of ligand-protein interactions using `plot_3d`. This view allows for detailed inspection of atomic and interaction information.
```python
view = fp_count.plot_3d(ligand_mol, protein_mol, frame=0, display_all=False)
view
```
--------------------------------
### Create and Display Protein Molecule from Selection
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Converts an MDAnalysis atom selection into a ProLIF molecule and displays the first 20 residues. Ensure your input file contains all atoms, including hydrogens, for correct bond inference.
```python
# create a molecule from the MDAnalysis selection
small_protein_mol = plf.Molecule.from_mda(small_protein_selection)
# display (remove `slice(20)` to show all residues)
plf.display_residues(small_protein_mol, slice(20))
```
--------------------------------
### Generate Interactive Network Visualization
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Generates an interactive network visualization from a NetworkX graph and displays it within a notebook environment. Nodes are colored based on their degree, with ligands in red and proteins in blue.
```python
data = df.T.groupby(level=["ligand", "protein"], sort=False).sum().T.astype(bool).mean()
G = make_graph(data, df, width_multiplier=8)
# color each node based on its degree
max_nbr = len(max(G.adj.values(), key=lambda x: len(x)))
blues = colormaps.get_cmap("Blues")
reds = colormaps.get_cmap("Reds")
for n, d in G.nodes(data=True):
n_neighbors = len(G.adj[n])
# show the smaller domain in red and the larger one in blue
palette = reds if d["dtype"] == "ligand" else blues
d["color"] = colors.to_hex(palette(n_neighbors / max_nbr))
# convert to pyvis network
width, height = (700, 700)
net = Network(width=f"{width}px", height=f"{height}px", notebook=True, heading="")
net.from_nx(G)
html_doc = net.generate_html(notebook=True)
iframe =
f''
HTML(iframe.format(html_doc=escape(html_doc)))
```
--------------------------------
### Compare Explicit and Implicit H-bond Methods
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Compares explicit and implicit H-bond interaction fingerprints using Prolif's Complex3D objects. This visualization highlights differences in detected interactions between the two methods.
```python
from prolif.plotting.complex3d import Complex3D
# create Complex3D objects (explicit, left)
comp3D = Complex3D.from_fingerprint(fp_count, ligand, protein_mol, frame=0)
# (implicit, right)
other_comp3D = Complex3D.from_fingerprint(fp_i, ligand_i, protein_mol_i, frame=0)
# compare the two Complex3D objects
view = comp3D.compare(other_comp3D, display_all=True)
view
```
--------------------------------
### Interaction Fingerprint Module Overview
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/modules/interaction-fingerprint.rst
This section provides an overview of the interaction fingerprint module, detailing its members and functionalities.
```APIDOC
## Interaction Fingerprint
This module provides the core functionality for generating interaction fingerprints.
### Modules Documented
- `prolif.fingerprint`: Main module for interaction fingerprinting.
- `prolif.ifp`: Alias or related module for interaction fingerprints.
- `prolif.interactions.interactions`: Defines various interaction types.
- `prolif.interactions.water_bridge`: Specific module for water bridge interactions.
- `prolif.interactions.base`: Base classes for interaction definitions.
- `prolif.parallel`: Utilities for parallel computation.
```
--------------------------------
### Display Ligand-Network Diagram
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Renders a 2D interactive diagram of ligand-protein interactions. This is most effective for small peptides. The diagram supports zooming, panning, residue rearrangement, and interaction filtering.
```python
view = fp.plot_lignetwork(small_protein_mol)
view
```
--------------------------------
### Create and Display Protein Residues
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Create a ProLIF Molecule object from an MDAnalysis selection of protein residues and display them. By default, it shows the first 20 residues to keep the output concise. Remove the slice(20) to display all residues.
```python
protein_mol = plf.Molecule.from_mda(protein_selection)
# remove the `slice(20)` part to show all residues
plf.display_residues(protein_mol, slice(20))
```
--------------------------------
### Run Fingerprint with Modified Presets
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Executes the fingerprint calculation using both default and modified presets to compare their effects on van der Waals contact detection.
```python
# run fingerprint
fp.run_from_iterable(pose_iterable, protein_mol)
fp_modified.run_from_iterable(pose_iterable, protein_mol)
```
--------------------------------
### Generate Default ProLIF Fingerprint
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Initializes a ProLIF Fingerprint object with default interaction types. By default, it tracks the first group of atoms satisfying constraints per interaction type.
```python
# use default interactions
fp = plf.Fingerprint()
```
--------------------------------
### Visualize Ligand Network
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Generates a network visualization of H-bond interactions for a specific frame of the ligand within the protein. `display_all=True` shows all detected interactions.
```python
view = fp_count.plot_lignetwork(ligand, kind="frame", frame=0, display_all=True)
view
```
--------------------------------
### Compare VdW Preset Elements
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Identifies and prints elements present in the default 'mdanalysis' VdW radii preset but absent in the 'rdkit' preset. This helps in understanding the coverage of different element types between presets.
```python
# show the elements that are in the default preset but not in the rdkit preset
print(sorted(default_vdw_elements - rdkit_vdw_elements))
```
--------------------------------
### Save and Load Fingerprint Object
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Persist a computed fingerprint object to disk using `to_pickle` and reload it later with `from_pickle`. This avoids recomputing fingerprints for analysis.
```python
fp.to_pickle("fingerprint.pkl")
fP = plf.Fingerprint.from_pickle("fingerprint.pkl")
```
--------------------------------
### Guess Bonds for MDAnalysis Selections
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Attempts to infer bond information for MDAnalysis selections. This is crucial if the input file lacks explicit bond orders and formal charges. It should be placed after creating selections.
```python
small_protein_selection.guess_bonds()
large_protein_selection.guess_bonds()
```
--------------------------------
### Read Ligand from SDF File
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Reads a ligand molecule from an SDF file using prolif.sdf_supplier. This function is used for loading ligand structures in SDF format.
```python
# Read the ligand
ligand_i = plf.sdf_supplier(data_path / "1.D.sdf")[0]
plf.display_residues(ligand_i, size=(400, 200))
```
--------------------------------
### Troubleshoot MOL2 Aromatic Bonds with MDAnalysis
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Workaround for RDKit errors like 'Can't kekulize mol' or 'non-ring atom marked aromatic' when reading MOL2 files. Redefines unconventional aromatic bonds as single bonds in the MDAnalysis Universe object.
```python
u = mda.Universe("protein.mol2")
# replace aromatic bonds with single bonds
for i, bond_order in enumerate(u._topology.bonds.order):
# you may need to replace double bonds ("2") as well
if bond_order == "ar":
u._topology.bonds.order[i] = 1
# clear the bond cache, just in case
u._topology.bonds._cache.pop("bd", None)
```
--------------------------------
### Read PDB and Convert to ProLIF Molecule
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Reads a PDB file using RDKit, determines connectivity, and converts it to a ProLIF Molecule object. Ensure no implicit hydrogens are set to false.
```python
from rdkit import Chem
from rdkit.Chem.rdDetermineBonds import DetermineConnectivity
from prolif import Molecule
from prolif.datafiles import datapath
protein_path = datapath / "molecule_standardizer/tpo.pdb"
# Read the data with RDKit
mol = Chem.MolFromPDBFile(str(protein_path), removeHs=False)
DetermineConnectivity(mol, useHueckel=True)
for atm in mol.GetAtoms():
atm.SetNoImplicit(False) # set no implicit to False
# Convert to ProLIF Molecule
mol = Molecule.from_rdkit(mol)
print([res for res in mol.residues])
mol
```
--------------------------------
### Visualizing Protein-Ligand Interactions in 3D
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Explore protein-ligand interactions in a 3D view using the `plot_3d` function. This function allows for detailed visualization, including styling options for specific molecules like water.
```python
view = fp_i.plot_3d(
ligand_i, protein_mol_i, frame=0, display_all=True, remove_hydrogens=False
)
view.setStyle(
{
"resn": "HOH",
},
{"sphere": {"radius": 0.5, "color": "red"}},
)
view
```
--------------------------------
### Generate Reference Fingerprint and DataFrame
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Generates an interaction fingerprint for a reference molecule and converts it to a pandas DataFrame. Renames index and columns for consistency.
```python
fp_ref = plf.Fingerprint(list(fp.interactions))
fp_ref.run_from_iterable([ref_mol], protein_mol)
df_ref = fp_ref.to_dataframe(index_col="Pose")
# set the "pose index" to -1
df_ref.rename(index={0: -1}, inplace=True)
# set the ligand name to be the same as poses
df_ref.rename(columns={str(ref_mol[0].resid): df.columns.levels[0][0]}, inplace=True)
df_ref
```
--------------------------------
### Initialize Fingerprint for Implicit Hydrogens
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Initializes a ProLIF Fingerprint object with the 'implicit_hydrogens=True' flag. This is crucial when working with systems that do not have explicit hydrogen atoms, as it ensures the correct interaction definitions are used.
```python
fp = plf.Fingerprint(implicit_hydrogens=True)
```
--------------------------------
### Generate Default Fingerprint
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Instantiate the default Fingerprint object and run it on a trajectory slice. Ensure you have imported 'u' for the trajectory and defined 'ligand_selection' and 'protein_selection'.
```python
# use default interactions
fp = plf.Fingerprint()
# run on a slice of the trajectory frames: from begining to end with a step of 10
fp.run(u.trajectory[::10], ligand_selection, protein_selection)
```
--------------------------------
### Generate Default Fingerprint
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Generates a fingerprint using the default interaction types. This snippet shows how to initialize the Fingerprint object and run it on ligand and protein molecules.
```python
# use default interactions
fp = plf.Fingerprint()
# run on your poses
fp.run_from_iterable([ligand_mol], protein_mol)
```
--------------------------------
### Count and Display All Ligand-Protein Interactions in 2D
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Enables counting all occurrences of interactions using `Fingerprint(count=True)` and displays them in a 2D interactive network plot with `display_all=True`. This provides a comprehensive view of all interaction types.
```python
fp_count = plf.Fingerprint(count=True)
fp_count.run_from_iterable([ligand_mol], protein_mol)
view = fp_count.plot_lignetwork(ligand_mol, frame=0, display_all=True)
view
```
--------------------------------
### Calculate Percentage of Poses with Interactions
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Calculates and displays the percentage of poses where each interaction type is present. Results are sorted in descending order. The `.T * 100` scales the results to percentages.
```python
# percentage of poses where each interaction is present
(df.mean().sort_values(ascending=False).to_frame(name="%").T * 100)
```
--------------------------------
### Automatically Format Code and Fix Linting Errors
Source: https://github.com/chemosim-lab/prolif/blob/master/CONTRIBUTING.md
Apply automatic code formatting and fix linting issues to comply with project standards.
```bash
uv run poe style-fix
```
--------------------------------
### Standardize Molecule with Ligand Template
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Creates a MoleculeStandardizer with a ligand template provided as an RDKit Mol object from SMILES. This standardizer is then used to fix bond orders in the input molecule.
```python
import prolif as plf
from prolif.io import MoleculeStandardizer
from rdkit import Chem
lig_smi = "C[NH+]1CC(C(=O)NC2(C)OC3(O)C4CCCN4C(=O)C(Cc4ccccc4)N3C2=O)C=C2c3cccc4[nH]cc(c34)CC21"
lig_template = ("LIG", Chem.MolFromSmiles(lig_smi))
standardizer = MoleculeStandardizer(templates=[lig_template])
system_mol_std = standardizer(system_mol)
```
--------------------------------
### Accessing Interaction Metadata
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Use the `.ifp` attribute to access detailed metadata for specific interactions, identified by ligand and protein residue IDs. This metadata includes geometric checks and hydrogen bond potentials.
```python
fp_i.ifp[0][("UNL1", "TYR167.B")]
```
--------------------------------
### Plot Ligand-Network with All Interactions
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Displays all occurrences of interactions in a frame, useful when using a count fingerprint. Set `display_all=True`.
```python
fp_count = plf.Fingerprint(count=True)
fp_count.run(u.trajectory[0:1], ligand_selection, protein_selection)
view = fp_count.plot_lignetwork(ligand_mol, kind="frame", frame=0, display_all=True)
```
--------------------------------
### Compare Complex3D Objects
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Generates and compares 3D representations of molecular complexes using fingerprints calculated with different presets. This helps visualize the impact of preset choices on interactions.
```python
from prolif.plotting.complex3d import Complex3D
pose_index = 4 # change this to see different poses
# create Complex3D objects (default)
comp3D = Complex3D.from_fingerprint(
fp, pose_iterable[pose_index], protein_mol, frame=pose_index
)
# (modified)
other_comp3D = Complex3D.from_fingerprint(
fp_modified, pose_iterable[pose_index], protein_mol, frame=pose_index
)
# compare the two Complex3D objects
view = comp3D.compare(other_comp3D)
view
```
--------------------------------
### List Available Interactions in ProLIF
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Retrieves a list of all available interaction classes within ProLIF, including hidden ones. Useful for understanding the full range of interactions that can be configured.
```python
plf.Fingerprint.list_available(show_hidden=True)
```
--------------------------------
### Display 2D Interactive Ligand-Protein Network
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
Use `plot_lignetwork` to display an interactive 2D diagram of ligand-protein interactions. This is useful for exploring interactions within a notebook environment.
```python
view = fp.plot_lignetwork(ligand_mol, kind="frame", frame=0)
view
```
--------------------------------
### Percentage of Poses with Each Interaction Type (Grouped)
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Calculates the percentage of poses where each interaction type is present, after grouping by interaction type. Results are sorted by frequency. The `.T * 100` scales the results to percentages.
```python
# percentage of poses where each interaction type is present
(
df.T.groupby(level="interaction")
.sum()
.T.astype(bool)
.mean()
.sort_values(ascending=False)
.to_frame(name="%")
.T
* 100
)
```
--------------------------------
### Compute and Visualize Tanimoto Similarity Matrix
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Generates a Tanimoto similarity matrix for all frames and visualizes it as a heatmap. Requires pandas, seaborn, and matplotlib.
```python
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
bitvectors = fp.to_bitvectors()
similarity_matrix = []
for bv in bitvectors:
similarity_matrix.append(DataStructs.BulkTanimotoSimilarity(bv, bitvectors))
similarity_matrix = pd.DataFrame(similarity_matrix, index=df.index, columns=df.index)
fig, ax = plt.subplots(figsize=(3, 3), dpi=200)
colormap = sns.diverging_palette(
300, 145, s=90, l=80, sep=30, center="dark", as_cmap=True
)
sns.heatmap(
similarity_matrix,
ax=ax,
square=True,
cmap=colormap,
vmin=0,
vmax=1,
center=0.5,
xticklabels=5,
yticklabels=5,
)
ax.invert_yaxis()
plt.yticks(rotation="horizontal")
fig.patch.set_facecolor("white")
```
--------------------------------
### Inspect Default VdW Radii Preset
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Examines the default van der Waals radii ('mdanalysis' preset) used by the VdWContact interaction. Shows the first 5 elements and the total count of elements defined in this preset.
```python
fp = plf.Fingerprint(["VdWContact"])
default_vdwradii = fp.vdwcontact.vdwradii
# show the first 5 vdwradii of the dictionary
print(dict(list(default_vdwradii.items())[:5]))
# show the number of elements in the preset
default_vdw_elements = set(default_vdwradii.keys())
print(len(default_vdw_elements))
```
--------------------------------
### Prolif Molecule and Residue Handling
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/modules/input.rst
This section covers the core classes for handling molecules and residues within the Prolif library, including integration with RDKit.
```APIDOC
## Prolif Molecule and Residue Classes
### Description
This documentation outlines the classes used for representing and manipulating molecules and residues in the Prolif library. It includes details on RDKit molecule integration and the `Residue` class.
### Modules and Classes
- **`prolif.rdkitmol`**: This module provides functionalities for integrating RDKit molecules within Prolif.
- **Members**: Includes all public members of the `rdkitmol` module.
- **Inheritance**: Shows classes that inherit from base classes.
- **`prolif.molecule`**: This module contains the core `Molecule` class for representing chemical compounds.
- **Members**: Includes all public members of the `molecule` module.
- **Inheritance**: Shows classes that inherit from base classes.
- **`prolif.residue.Residue`**: This class represents a residue within a larger molecular structure.
- **Members**: Includes all public members of the `Residue` class.
- **Inheritance**: Shows classes that inherit from base classes.
```
--------------------------------
### Run MD Trajectory Analysis
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/water-bridge.ipynb
Use this function to analyze molecular dynamics trajectories. It requires trajectory, ligand, and protein selections.
```python
fp.run(u.trajectory, ligand_selection, protein_selection)
```
--------------------------------
### Include Water Molecules in Protein Selection
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Expands the protein selection to include water molecules (resname WAT) within a specified distance of the peptide group.
```python
large_protein_selection = u.select_atoms(
"(protein or resname WAT) and byres around 20.0 group peptide",
peptide=small_protein_selection,
)
large_protein_selection
```
--------------------------------
### Plot 2D Interaction Network (Single Pose)
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Visualizes interactions for a single docking pose in a 2D interactive diagram. Allows zooming, panning, residue rearrangement, and interaction filtering.
```python
view = fp.plot_lignetwork(pose_iterable[0])
view
```
--------------------------------
### Plot Ligand-Network Diagram
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Displays an interactive 2D diagram of ligand-protein interactions. Interactions can be zoomed, panned, and filtered by hovering or clicking legend items.
```python
view = fp.plot_lignetwork(ligand_mol)
```
```python
view = fp.plot_lignetwork(ligand_mol, threshold=0.0)
```
--------------------------------
### Plotting Ligand Network in 2D
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/implicit-hbond.ipynb
Generate a 2D ligand-centered network plot using the `plot_lignetwork` function. This is useful for visualizing interactions from the ligand's perspective.
```python
view = fp_i.plot_lignetwork(ligand_i, kind="frame", frame=0, display_all=True)
view
```
--------------------------------
### Create Network Graph from Interaction Data
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-protein-protein.ipynb
Converts interaction data between ligands and proteins into a NetworkX graph. This function is a prerequisite for generating interactive network visualizations with pyvis.
```python
from html import escape
import networkx as nx
import pandas as pd
from IPython.display import HTML
from matplotlib import colormaps, colors
from pyvis.network import Network
def make_graph(
values: pd.Series,
df: pd.DataFrame,
node_color=["#FFB2AC", "#ACD0FF"],
node_shape="dot",
edge_color="#a9a9a9",
width_multiplier=1,
) -> nx.Graph:
"""Convert a pandas DataFrame to a NetworkX object
Parameters
----------
values : pandas.Series
Series with 'ligand' and 'protein' levels, and a unique value for
each lig-prot residue pair that will be used to set the width and weigth
of each edge. For example:
ligand protein
LIG1.G ALA216.A 0.66
ALA343.B 0.10
df : pandas.DataFrame
DataFrame obtained from the fp.to_dataframe() method
Used to label each edge with the type of interaction
node_color : list
Colors for the ligand and protein residues, respectively
node_shape : str
One of ellipse, circle, database, box, text or image, circularImage,
diamond, dot, star, triangle, triangleDown, square, icon.
edge_color : str
Color of the edge between nodes
width_multiplier : int or float
Each edge's width is defined as `width_multiplier * value`
"""
lig_res = values.index.get_level_values("ligand").unique().tolist()
prot_res = values.index.get_level_values("protein").unique().tolist()
G = nx.Graph()
# add nodes
# https://pyvis.readthedocs.io/en/latest/documentation.html#pyvis.network.Network.add_node
for res in lig_res:
G.add_node(
res, title=res, shape=node_shape, color=node_color[0], dtype="ligand"
)
for res in prot_res:
G.add_node(
res, title=res, shape=node_shape, color=node_color[1], dtype="protein"
)
for resids, value in values.items():
label = "{} - {}
{}".format(
*resids,
"\n".join(
[
f"{k}: {v}"
for k, v in (
df.xs(resids, level=["ligand", "protein"], axis=1)
.sum()
.to_dict()
.items()
)
]
),
)
# https://pyvis.readthedocs.io/en/latest/documentation.html#pyvis.network.Network.add_edge
G.add_edge(
*resids,
title=label,
color=edge_color,
weight=value,
width=value * width_multiplier,
)
return G
```
--------------------------------
### Parallel Processing Utilities
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/source/modules/interaction-fingerprint.rst
Information regarding the parallel processing capabilities available in Prolif for faster computations.
```APIDOC
## Parallel Processing
This module offers utilities to accelerate calculations by leveraging parallel processing.
### Module
- `prolif.parallel`: Contains functions and classes for parallel execution.
```
--------------------------------
### Specify Residues for Fingerprint Calculation
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
You can manually specify a list of residues to include in the fingerprint calculation by passing them to the `run` method. This overrides the default vicinity cutoff.
```python
fp.run(, residues=["TYR38.A", "ASP129.A"])
```
--------------------------------
### Read Protein PDB with RDKit
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/pdb.ipynb
This snippet demonstrates reading a protein PDB file using RDKit. Note that RDKit may not correctly parse all protonated residues, potentially affecting interaction detection.
```python
from rdkit import Chem
rdkit_prot = Chem.MolFromPDBFile(protein_file, removeHs=False)
rdkit_protein_mol = plf.Molecule(rdkit_prot)
```
--------------------------------
### Manually Update VdW Radii
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
Demonstrates how to manually update van der Waals radii for specific atoms within a Fingerprint object. It is generally recommended to use presets instead of manual adjustments.
```python
fp = plf.Fingerprint(
["VdWContact"],
parameters={
"VdWContact": {
"vdwradii": {"C": 1.65, "H": 1.13}
}
}
)
>>> fp.vdwcontact.vdwradii # {'H': 1.13, ..., 'C': 1.65, ...}
```
--------------------------------
### Run Type Checks on Entire Codebase
Source: https://github.com/chemosim-lab/prolif/blob/master/CONTRIBUTING.md
Perform type checking across the entire project using mypy to ensure type correctness.
```bash
uv run poe type-check
```
--------------------------------
### Access Detailed Fingerprint Results by Residue
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/advanced.ipynb
This demonstrates accessing the complete, deeply nested fingerprint results stored in the `fp.ifp` attribute. It shows how to query interaction data for a specific frame and pair of ligand and protein residues.
```python
frame_number = 0
ligand_residue = "UNL1"
protein_residue = "VAL200.A"
fp.ifp[frame_number][(ligand_residue, protein_residue)]
```
--------------------------------
### Plot 3D Interaction Visualization
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/docking.ipynb
Generates a 3D visualization of interactions using a count fingerprint. `display_all=False` shows the shortest distance occurrence for each interaction.
```python
view = fp_count.plot_3d(
pose_iterable[pose_index], protein_mol, frame=pose_index, display_all=False
)
view
```
--------------------------------
### Compare Two Frames in 3D
Source: https://github.com/chemosim-lab/prolif/blob/master/docs/notebooks/md-ligand-protein.ipynb
Compares interactions between two different frames in a 3D view. Protein residues with different interactions or missing interactions in the compared frame are highlighted in magenta.
```python
from prolif.plotting.complex3d import Complex3D
frame = 0
u.trajectory[frame]
ligand_mol = plf.Molecule.from_mda(ligand_selection)
protein_mol = plf.Molecule.from_mda(protein_selection)
comp3D = Complex3D.from_fingerprint(fp, ligand_mol, protein_mol, frame=frame)
frame = 120
u.trajectory[frame]
ligand_mol = plf.Molecule.from_mda(ligand_selection)
protein_mol = plf.Molecule.from_mda(protein_selection)
other_comp3D = Complex3D.from_fingerprint(fp, ligand_mol, protein_mol, frame=frame)
view = comp3D.compare(other_comp3D)
```