Utilities

Utility functions.

Overview

ConservedWaterSearch.utils.get_orientations_from_positions

Returns orientations from coordinates.

ConservedWaterSearch.utils.read_results

Read results from files.

ConservedWaterSearch.utils.visualise_nglview

Creates a nglview visualisation widget for results.

ConservedWaterSearch.utils.visualise_pymol

Visualises results via pymol.

ConservedWaterSearch.utils.visualise_pymol_from_pdb

Make a pymol session from a pdb file.

Details

ConservedWaterSearch.utils.get_orientations_from_positions(coordsO: ndarray, coordsH: ndarray) tuple[ndarray, ndarray, ndarray][source]

Returns orientations from coordinates.

Calculates relative orientations of hydrogen atoms from their positions. The output of this function can be used as input for water clustering.

Parameters:
  • coordsO (np.ndarray) – Oxygen coordinates - shape (N_waters, 3)

  • coordsH (np.ndarray) – Hydrogen coordinates - two hydrogens bound to the same oxygen have to be placed one after another in the array. Shape: (2*N_waters, 3).

Returns:

returns oxygen coordinates array and two hydrogen orientation arrays.

Return type:

tuple[np.ndarray, np.ndarray, np.ndarray]

ConservedWaterSearch.utils.read_results(fname: str) tuple[list[str], list[ndarray], list[ndarray], list[ndarray]][source]

Read results from files.

Read results from files and return them in order for further processing.

Parameters:

fname (str) – Name of the file containing results.

Returns:

returns list of strings which represents water types, and arrays of locations of oxygen and two hydrogens. If only oxygens were saved returned hydrogen coordinates are empty arrays

Return type:

tuple[ list[str], list[np.ndarray], list[np.ndarray], list[np.ndarray] ]

Examples:

water_types, coord_O, coord_H1, coord_H2 = read_results(
    fname = "Clust_res.dat",
)
ConservedWaterSearch.utils.visualise_nglview(water_type: list[str], waterO: list[list[float]], waterH1: list[list[float]], waterH2: list[list[float]], aligned_protein: str | None = None, active_site_ids: list[int] | None = None, crystal_waters: str | None = None, density_map_file: str | None = None) NGLWidget[source]

Creates a nglview visualisation widget for results.

Starts a nglview visualisation instance from clustering results.

Parameters:
  • water_type (list) – List containing water type results from water clustering.

  • waterO (list) – Coordiantes of Oxygen atom in water molecules.

  • waterH1 (list) – Coordinates of Hydrogen1 atom in water molecules.

  • waterH2 (list) – Coordinates of Hydrogen2 atom in water molecules.

  • aligned_protein (str, optional) – file name containing protein configuration trajectory was aligned to. Defaults to None.

  • active_site_ids (list[int] | None, optional) – Residue ids - numbers of aminoacids in active site. These are visualised as licorice. Defaults to None.

  • crystal_waters (str | None, optional) – PDBid from which crystal waters will attempted to be extracted. Defaults to None.

  • density_map_file (str | None, optional) – Water density map to add to visualisation session (usually .dx file). Defaults to None.

Returns:

Returns nglview Widget for visualisation of the results.

Return type:

NGLWidget

Example:

# read results and visualise them using nglview
water_types, coord_O, coord_H1, coord_H2 = read_results(
    fname = "Clust_res.dat",
)
view = visualise_nglview(
    water_type = water_types,
    waterO = coord_O,
    waterH1 = coord_H1,
    waterH2 = coord_H2,
    aligned_protein = "aligned.pdb",
    active_site_ids = [1,5,77,98],
    crystal_waters = "3t73",
)
# initialise widget
view
ConservedWaterSearch.utils.visualise_pymol(water_type: list[str], waterO: list[list[float]], waterH1: list[list[float]], waterH2: list[list[float]], aligned_protein: str | None = None, output_file: str | None = None, active_site_ids: list[int] | None = None, crystal_waters: str | None = None, ligand_resname: str | None = None, dist: float = 10.0, density_map: str | None = None, polar_contacts: bool = False, lunch_pymol: bool = True, reinitialize: bool = True) None[source]

Visualises results via pymol.

Visualises results using pymol in a pymol session or saves to a file. On mac OS the interactive pymol session will fail to lunch. If output_file is None, a visualisation state will be saved to pymol_water_visualization.pse in this case on mac OS.

Parameters:
  • water_type (list) – List containing water type results from water clustering.

  • waterO (list) – Coordinates of Oxygen atom in water molecules.

  • waterH1 (list) – Coordinates of Hydrogen1 atom in water molecules.

  • waterH2 (list) – Coordinates of Hydrogen2 atom in water molecules.

  • aligned_protein (str | None, optional) – file name containing protein configuration trajectory was aligned to. If None no protein will be shown. Defaults to None.

  • output_file (str | None, optional) – File to save the visualisation state. If None, a pymol session is started (this probably doesn’t work on Mac OSX). Defaults to None.

  • active_site_ids (list[int] | None, optional) – Residue ids - numbers of aminoacids in active site. These are visualised as licorice. Defaults to None.

  • crystal_waters (str | None, optional) – PDBid from which crystal waters will attempted to be extracted. Defaults to None.

  • ligand_resname (str | None, optional) – Residue name of the ligand around which crystal waters (oxygens) shall be selected. Defaults to None.

  • dist (float) – distance from the centre of ligand around which crystal waters shall be selected. Defaults to 10.0.

  • density_map (str | None, optional) – Water density map to add to visualisation session (usually .dx file). Defaults to None.

  • polar_contacts (bool, optional) – If True polar contacts between waters and protein will be visualised. Defaults to False.

  • lunch_pymol (bool, optional) – If True pymol will be lunched in interactive mode. If False pymol will be imported without lunching. Defaults to True.

  • reinitialize (bool, optional) – If True pymol will be reinitialized (defaults restored and objects cleaned). Defaults to True.

Example:

# Read the results from files
water_types, coord_O, coord_H1, coord_H2 = read_results(
    fname = "Clust_res.dat",
)
visualise_pymol(
    water_type = water_types,
    waterO = coord_O,
    waterH1 = coord_H1,
    waterH2 = coord_H2,
    aligned_protein = "aligned.pdb",
    output_file = "results.pse",
    active_site_ids = [1,5,77,98],
    crystal_waters = "3t73",
    ligand_resname = "UBX",
    dist = 8.0,
)
ConservedWaterSearch.utils.visualise_pymol_from_pdb(pdbfile: str, active_site_ids: list[int] | None = None, crystal_waters: str | None = None, ligand_resname: str | None = None, dist: float = 10.0, density_map: str | None = None, polar_contacts: bool = False, lunch_pymol: bool = True, reinitialize: bool = True) None[source]

Make a pymol session from a pdb file.

Visualises a pdb made by make_results_pdb_MDA() file with water clustering results in pymol.

Parameters:
  • pdbfile (str) – Name of the pdb file to read, should end in .pdb

  • active_site_ids (list[int] | None, optional) – Residue ids - numbers of aminoacids in active site. These are visualised as licorice. Defaults to None.

  • crystal_waters (str | None, optional) – PDBid from which crystal waters will attempted to be extracted. Defaults to None.

  • ligand_resname (str | None, optional) – Residue name of the ligand around which crystal waters (oxygens) shall be selected. Defaults to None.

  • dist (float) – distance from the centre of ligand around which crystal waters shall be selected. Defaults to 10.0.

  • density_map (str | None, optional) – Water density map to add to visualisation session (usually .dx file). Defaults to None.

  • polar_contacts (bool, optional) – If True polar contacts between waters and protein will be visualised. Defaults to False.

  • lunch_pymol (bool, optional) – If True pymol will be lunched in interactive mode. If False pymol will be imported without lunching. Defaults to True.

  • reinitialize (bool, optional) – If True pymol will be reinitialized (defaults restored and objects cleaned). Defaults to True.

Example:

visualise_pymol_from_pdb(
    pdbfile = "results.pdb",
    active_site_ids = [1,5,77,98],
    crystal_waters = "3t73",
    ligand_resname = "UBX",
    dist = 8.0,
    density_map = "waters.dx"
)