Plotting#
Plot residues — prolif.plotting.residues#
New in version 2.0.0.
- prolif.plotting.residues.display_residues(mol: Molecule, residues_slice: slice | None = None, *, size: tuple[int, int] = (200, 140), mols_per_row: int = 4, use_svg: bool = True, sanitize: bool = True) Any[source]#
Display a grid image of the residues in the molecule. The hydrogens are stripped and the 3D coordinates removed for a clearer visualisation.
- Parameters:
mol (prolif.Molecule) – The molecule to show residues from.
residues_slice (slice | None = None) – Optionally, a slice of residues to display, e.g.
slice(20)for the first 20 residues, orslice(<start>, <stop>, <step>)for a more complex selection.size (tuple[int, int] = (200, 140)) – Size of each residue image.
mols_per_row (int = 4) – Number of residues displayed per row.
use_svg (bool = True) – Generate an SVG or PNG image.
sanitize (bool = True) – Sanitize the residues before displaying.
versionchanged: (..) – 2.1.0: Added
sanitizeparameter that defaults to False for easier debugging.
Plot interactions as a barcode — prolif.plotting.barcode#
New in version 2.0.0.
- class prolif.plotting.barcode.Barcode(df: DataFrame)[source]#
Creates a barcode plot of interactions.
- Parameters:
df (pandas.DataFrame) – The DataFrame as obtained from
Fingerprint.to_dataframe()
- display(figsize: tuple[int, int] = (8, 10), dpi: int = 100, interactive: bool = False, n_frame_ticks: int = 10, residues_tick_location: Literal['top', 'bottom'] = 'top', xlabel: str = 'Frame', subplots_kwargs: dict | None = None, tight_layout_kwargs: dict | None = None) Axes[source]#
Generate and display the barcode plot.
- Parameters:
figsize (tuple[int, int] = (8, 10)) – Size of the matplotlib figure.
dpi (int = 100) – DPI used for the matplotlib figure.
interactive (bool) – Add hover interactivity to the plot (only relevant for notebooks). You may need to add
%matplotlib notebookor%matplotlib ipymplfor it to work as expected.n_frame_ticks (int = 10) – Number of ticks on the X axis. May use ±1 tick to have them evenly spaced.
residues_tick_location (Literal["top", "bottom"] = "top") – Whether the Y ticks appear at the top or at the bottom of the series of interactions of each residue.
xlabel (str = "Frame") – Label displayed for the X axis.
subplots_kwargs (dict | None = None) – Other parameters passed to
matplotlib.pyplot.subplots().tight_layout_kwargs (dict | None = None) – Other parameters passed to
matplotlib.figure.Figure.tight_layout().
- classmethod from_fingerprint(fp: Fingerprint) Barcode[source]#
Creates a barcode object from a fingerprint.
Plot interactions in 3D — prolif.plotting.complex3d#
New in version 2.0.0.
- class prolif.plotting.complex3d.Complex3D(ifp: IFP, lig_mol: Molecule, prot_mol: Molecule, water_mol: Molecule | None = None)[source]#
Creates a py3Dmol plot of interactions.
- Parameters:
- LIGAND_STYLE#
Style object passed to
3Dmol.jsfor the ligand.
- RESIDUES_STYLE#
Style object passed to
3Dmol.jsfor the protein residues involved in interactions.
- PROTEIN_STYLE#
Style object passed to
3Dmol.jsfor the entire protein.
- PEPTIDE_STYLE#
Style object passed to
3Dmol.jsfor the ligand as a peptide if appropriate.
- PEPTIDE_THRESHOLD#
Ligands with this number of residues or more will be displayed using
PEPTIDE_STYLEin addition to theLIGAND_STYLE.- Type:
int = 5
- LIGAND_DISPLAYED_ATOM#
Which atom should be used to display an atom-to-atom interaction for the ligand. Refers to the order defined in the SMARTS pattern used in interaction definition. Interactions not specified here use
0by default.
- PROTEIN_DISPLAYED_ATOM#
Same as
LIGAND_DISPLAYED_ATOMfor the protein.
- LIGAND_RING_INTERACTIONS#
Which interactions should be displayed using the centroid instead of using
LIGAND_DISPLAYED_ATOMfor the ligand.
- PROTEIN_RING_INTERACTIONS#
Which interactions should be displayed using the centroid instead of using
PROTEIN_DISPLAYED_ATOMfor the protein.
- BRIDGED_INTERACTIONS#
For bridged-interactions such as WaterBridge. The key is the interaction name, and the value is the name of the molecule in the metadata indices dictionary.
- RESIDUE_HOVER_CALLBACK#
JavaScript callback executed when hovering a residue involved in an interaction.
- Type:
- INTERACTION_HOVER_CALLBACK#
JavaScript callback executed when hovering an interaction line.
- Type:
- .. versionchanged:: 2.1.0
Added
water_molparameter to the constructor to display waters involved in WaterBridge interactions. Addedsave_pngmethod to save the current state of the 3D viewer to a PNG. Addedremove_hydrogensparameter to thedisplayandcomparemethods to remove non-polar hydrogens that aren’t involved in an interaction. Addedonly_interactingparameter to thedisplayandcomparemethods to show all protein residues in the vicinity of the ligand, or only the ones participating in an interaction.
- compare(other: Complex3D, *, size: tuple[int, int] = (900, 600), display_all: bool = False, linked: bool = True, color_unique: str | None = 'magentaCarbon', only_interacting: bool = True, remove_hydrogens: Union[bool, Literal['ligand', 'protein', 'water']] = True) Complex3D[source]#
Displays the initial complex side-by-side with a second one for easier comparison.
- Parameters:
other (Complex3D) – Other
Complex3Dobject to compare to.size (tuple[int, int] = (900, 600)) – The size of the py3Dmol widget view.
display_all (bool = False) – Display all occurences for a given pair of residues and interaction, or only the shortest one. Not relevant if
count=Falsein theFingerprintobject.linked (bool = True) – Link mouse interactions (pan, zoom, translate) on both views.
color_unique (str | None = "magentaCarbon",) – Which color to use for residues that have interactions that are found in one complex but not the other. Use
Noneto disable the color override.only_interacting (bool = True) – Whether to show all protein residues in the vicinity of the ligand, or only the ones participating in an interaction.
remove_hydrogens (bool | Literal["ligand", "protein", "water"] = True) – Whether to remove non-polar hydrogens (unless they are involved in an interaction).
versionadded: (..) – 2.0.1:
versionchanged: (..) – 2.1.0: Added
only_interacting=Trueandremove_hydrogens=Trueparameters. Non-polar hydrogen atoms that aren’t involved in interactions are now hidden. Added support for waters involved in WaterBridge interactions.
- display(size: tuple[int, int] = (650, 600), display_all: bool = False, only_interacting: bool = True, remove_hydrogens: Union[bool, Literal['ligand', 'protein', 'water']] = True, sanitize: Union[bool, Literal['ligand', 'protein']] = 'protein') Complex3D[source]#
Display as a py3Dmol widget view.
- Parameters:
size (tuple[int, int] = (650, 600)) – The size of the py3Dmol widget view.
display_all (bool = False) – Display all occurences for a given pair of residues and interaction, or only the shortest one. Not relevant if
count=Falsein theFingerprintobject.only_interacting (bool = True) – Whether to show all protein residues in the vicinity of the ligand, or only the ones participating in an interaction.
remove_hydrogens (bool | Literal["ligand", "protein", "water"] = True) – Whether to remove non-polar hydrogens (unless they are involved in an interaction).
sanitize (bool | Literal["ligand", "protein"] = "protein") – Whether to sanitize the RDKit molecules used for visualization. This is to avoid unkekulization issues that may arise when using the coordinates of the molecule.
Changed in version 2.1.0: Added
only_interacting=Trueandremove_hydrogens=Trueparameters. Non-polar hydrogen atoms that aren’t involved in interactions are now hidden. Added support for waters involved in WaterBridge interactions.Changed in version 2.2.0: Added
sanitizeparameter to allow sanitization of the RDKit molecules used for visualization, which can help avoid unkekulization issues when using the coordinates of the molecule directly.
- classmethod from_fingerprint(fp: Fingerprint, lig_mol: Molecule, prot_mol: Molecule, water_mol: Molecule | None = None, *, frame: int) Complex3D[source]#
Creates a py3Dmol plot of interactions.
- Parameters:
fp (prolif.fingerprint.Fingerprint) – The fingerprint object already executed using one of the
runorrun_from_iterablemethods.frame (int) – The frame number chosen to select which interactions are going to be displayed.
lig_mol (Molecule) – The ligand molecule to display.
prot_mol (Molecule) – The protein molecule to display.
water_mol (Optional[Molecule]) – Additional molecule (e.g. waters) to display.
Plot a Ligand Interaction Network — prolif.plotting.network#
New in version 0.3.2.
Changed in version 2.0.0: Replaced LigNetwork.from_ifp with LigNetwork.from_fingerprint which works
without requiring a dataframe with atom indices.
- class prolif.plotting.network.lignetwork.LigNetwork(df: DataFrame, lig_mol: Mol, use_coordinates: bool = False, flatten_coordinates: bool = True, kekulize: bool = False, molsize: int = 35, rotation: float = 0, carbon: float = 0.16, use_segid: bool = False)[source]#
Creates a ligand interaction diagram
- Parameters:
df (pandas.DataFrame) – Dataframe with a 4-level index (ligand, protein, interaction, atoms) and
weightanddistancecolumns for valueslig_mol (rdkit.Chem.rdChem.Mol) – Ligand molecule
use_coordinates (bool) – If
True, uses the coordinates of the molecule directly, otherwise generates 2D coordinates from scratch. See alsoflatten_coordinates.flatten_coordinates (bool) – If this is
Trueanduse_coordinates=True, generates 2D coordinates that are constrained to fit the 3D conformation of the ligand as best as possible.kekulize (bool) – Kekulize the ligand
molsize (int) – Multiply the coordinates by this number to create a bigger and more readable depiction
rotation (float) – Rotate the structure on the XY plane
carbon (float) – Size of the carbon atom dots on the depiction. Use 0 to hide the carbon dots
use_segid (bool) – If
True, uses the segment ID as the chain identifier of residues.
- COLORS#
Dictionnary of colors used in the diagram. Subdivided in several dictionaries:
“interactions”: mapping between interactions types and colors
“atoms”: mapping between atom symbol and colors
“residues”: mapping between residues types and colors
- Type:
- RESIDUE_TYPES#
Mapping between residue names (3 letter code) and types. The types are then used to define how each residue should be colored.
- Type:
Notes
You can customize the diagram by tweaking
LigNetwork.COLORSandLigNetwork.RESIDUE_TYPESby adding or modifying the dictionaries inplace.Changed in version 2.0.0: Replaced
LigNetwork.from_ifpwithLigNetwork.from_fingerprintwhich works without requiring a dataframe with atom indices. Replacedmatch3Dparameter withuse_coordinatesandflatten_coordinatesto give users more control and allow them to provide their own 2D coordinates. Added support for displaying peptides as the “ligand”. Changed the default color for VanDerWaals.Changed in version 2.1.0: Added the
show_interaction_dataargument and exposed thefontsizeindisplay.- display(**kwargs: Any) LigNetwork[source]#
Prepare and display the network.
- Parameters:
width (str = "100%") –
height (str = "500px") –
fontsize (int = 20) –
show_interaction_data (bool = False) –
- classmethod from_fingerprint(fp: Fingerprint, ligand_mol: Mol, kind: Literal['aggregate', 'frame'] = 'aggregate', frame: int = 0, display_all: bool = False, threshold: float = 0.3, **kwargs: Any) LigNetwork[source]#
Helper method to create a ligand interaction diagram from a
Fingerprintobject.Notes
Two kinds of diagrams can be rendered: either for a designated frame or by aggregating the results on the whole IFP and optionnally discarding interactions that occur less frequently than a threshold. In the latter case (aggregate), only the group of atoms most frequently involved in each interaction is used to draw the edge.
- Parameters:
fp (prolif.fingerprint.Fingerprint) – The fingerprint object already executed using one of the
runorrun_from_iterablemethods.lig (rdkit.Chem.rdChem.Mol) – Ligand molecule
kind (str) – One of
"aggregate"or"frame"frame (int) – Frame number (see
ifp). Only applicable forkind="frame"display_all (bool) – Display all occurences for a given pair of residues and interaction, or only the shortest one. Only applicable for
kind="frame". Not relevant ifcount=Falsein theFingerprintobject.threshold (float) – Frequency threshold, between 0 and 1. Only applicable for
kind="aggregate"kwargs (object) – Other arguments passed to the
LigNetworkclass
Changed in version 2.0.0: Added the
display_allparameter.
- save(fp: Union[str, Path, TextIO], **kwargs: Any) None[source]#
Save the network to an HTML file
- Parameters:
fp (str or file-like object) – Name of the output file, or file-like object
- save_png() Any[source]#
Saves the current state of the ligplot to a PNG. Not available outside of a notebook.
Notes
Requires calling
displayorshowfirst. The legend won’t be exported.New in version 2.1.0.
- show(filename: str, **kwargs: Any) LigNetwork[source]#
Save the network as HTML and display the resulting file