Visualization#

Tools for visualizing molecules and their interaction profiles.

Visualize pharmacophores and exit vectors with py3dmol.

shepherd_score.visualize.draw(mol, feats={}, pharm_types=None, pharm_ancs=None, pharm_vecs=None, point_cloud=None, esp=None, dummy_atom_pos=None, ev_pos=None, ev_vecs=None, add_SAS=False, view=None, removeHs=False, opacity=1.0, opacity_features=0.9, color_scheme=None, custom_carbon_color=None, width=800, height=400)[source]#

Draw molecule with pharmacophore features and point cloud on surface accessible surface and electrostatics.

Parameters:
  • mol (Chem.Mol | str) – The molecule to draw. Either an RDKit Mol object or a string of the molecule in XYZ format. The XYZ string does not need to be a valid molecular structure.

  • Parameters (Optional)

  • -------------------

  • feats (dict) – The pharmacophores to draw in a dictionary format with features as keys.

  • pharm_types (np.ndarray (N,)) – The pharmacophores types

  • pharm_ancs (np.ndarray (N, 3)) – The pharmacophores positions / anchor points.

  • pharm_vecs (np.ndarray (N, 3)) – The pharmacophores vectors / directions.

  • point_cloud (np.ndarray (N, 3)) – The point cloud positions.

  • esp (np.ndarray (N,)) – The electrostatics values.

  • add_SAS (bool) – Whether to add the SAS surface computed by py3Dmol.

  • view (py3Dmol.view) – The view to draw the molecule to. If None, a new view will be created.

  • removeHs (bool (default: False)) – Whether to remove the hydrogen atoms.

  • color_scheme (str (default: None)) – Provide a py3Dmol color scheme string. Example: ‘whiteCarbon’

  • custom_carbon_color (str (default: None)) – Provide hex color of the carbon atoms. Programmed are ‘dark slate grey’ and ‘light steel blue’.

  • opacity (float (default: 1.0)) – The opacity of the molecule.

  • opacity_features (float (default: 1.0)) – The opacity of the pharmacophore features.

  • width (int (default: 800)) – The width of the view.

  • height (int (default: 400)) – The height of the view.

shepherd_score.visualize.draw_sample(generated_sample, ref_mol=None, only_atoms=False, model_type='all', opacity=0.6, view=None, color_scheme=None, custom_carbon_color=None, width=800, height=400)[source]#

Draw generated ShEPhERD sample with pharmacophore features and point cloud.

Draws on surface accessible surface and electrostatics, optionally overlaid on the reference molecule.

Parameters:
  • generated_sample (dict) –

    The generated sample dictionary. Note that it does NOT use x2 and assumes shape positions are in x3. Expected format:

    {'x1': {'atoms': np.ndarray, 'positions': np.ndarray},
     'x2': {'positions': np.ndarray},
     'x3': {'charges': np.ndarray, 'positions': np.ndarray},
     'x4': {'types': np.ndarray, 'positions': np.ndarray,
            'directions': np.ndarray}}
    

  • ref_mol (Chem.Mol, optional) – The reference molecule with a conformer. Default is None.

  • only_atoms (bool, optional) – Whether to only draw the atoms and ignore the interaction profiles. Default is False.

  • model_type (str, optional) – One of ‘all’, ‘x2’, ‘x3’, ‘x4’. Default is ‘all’.

  • opacity (float, optional) – The opacity of the reference molecule. Default is 0.6.

  • view (py3Dmol.view, optional) – The view to draw the molecule to. If None, a new view will be created.

  • color_scheme (str, optional) – Provide a py3Dmol color scheme string (e.g., ‘whiteCarbon’).

  • custom_carbon_color (str, optional) – Provide hex color of the carbon atoms. Programmed are ‘dark slate grey’ and ‘light steel blue’.

  • width (int, optional) – The width of the view. Default is 800.

  • height (int, optional) – The height of the view. Default is 400.

shepherd_score.visualize.draw_molecule(molecule, dummy_atom_pos=None, add_SAS=False, view=None, removeHs=False, color_scheme=None, custom_carbon_color=None, opacity=1.0, opacity_features=1.0, no_surface_points=False, width=800, height=400)[source]#
Parameters:
  • molecule (Molecule)

  • color_scheme (Optional[str])

  • custom_carbon_color (Optional[str])

  • opacity (float)

  • opacity_features (float)

  • no_surface_points (bool)

shepherd_score.visualize.draw_pharmacophores(mol, view=None, width=800, height=400, opacity=1.0, opacity_features=1.0)[source]#

Generate the pharmacophores and visualize them.

shepherd_score.visualize.chimera_from_mol(mol, mol_id, surf_pos=None, surf_esp=None, ev_pos=None, ev_vecs=None, save_dir='./', surf_point_size=0.05, verbose=True)[source]#

Create SDF file for atoms (x1_{mol_id}.sdf) and BILD file for pharmacophores (x4_{mol_id}.bild). Drag and drop into ChimeraX to visualize.

Parameters:
  • mol (rdkit.Chem.Mol)

  • mol_id (str | int)

  • save_dir (str)

  • surf_point_size (float)

  • verbose (bool)

Return type:

None

shepherd_score.visualize.chimera_from_sample(generated_sample, mol_id, save_dir, model_type='all', esp_norm_factor=2.0, surf_point_size=0.05, verbose=True)[source]#

Create SDF file for atoms (x1_{mol_id}.sdf) and BILD file for pharmacophores (x4_{mol_id}.bild). Drag and drop into ChimeraX to visualize.

Parameters:
Return type:

None

shepherd_score.visualize.chimera_from_molecule(molec, mol_id, save_dir, esp_norm_factor=2.0, surf_point_size=0.05, verbose=True)[source]#

Create SDF file for atoms (x1_{mol_id}.sdf) and BILD file for pharmacophores (x4_{mol_id}.bild) from a Molecule object. Drag and drop into ChimeraX to visualize.

Parameters:
Return type:

None

shepherd_score.visualize.draw_2d_valid(ref_mol, mols, mols_per_row=5, use_svg=True, find_atomic_overlap=True)[source]#

Draw 2D grid image of the reference molecule and a list of corresponding molecules. It will align the molecules to the reference molecule using the MCS and highlight the maximum common substructure between the reference molecule and the other molecules.

Parameters:
  • ref_mol (Chem.Mol) – The reference molecule to align the other molecules to.

  • mols (List[Chem.Mol | None]) – The list of molecules to draw.

  • mols_per_row (int) – The number of molecules to draw per row.

  • use_svg (bool) – Whether to use SVG for the image.

  • find_atomic_overlap (bool)

Returns:

  • MolsToGridImage – The image of the molecules.

  • Credit

  • ——

  • https (//github.com/PatWalters/practical_cheminformatics_tutorials/)

shepherd_score.visualize.draw_2d_highlight(mol, atom_sets, colors=None, label=None, compute_2d_coords=True, add_stereo_annotation=True, width=800, height=600, embed_display=True)[source]#

Create an SVG representation of the molecule with highlighted atom sets.

Parameters:
  • mol (Chem.Mol) – The molecule to draw.

  • atom_sets (List[List[int]]) – The list of atom sets to highlight.

  • colors (List[str]) – The list of colors to use for the atom sets.

  • label (Literal['atomLabel', 'molAtomMapNumber', 'atomNote']) – The label to use for the atom indices.

  • width (int) – The width of the SVG image.

  • height (int) – The height of the SVG image.

  • compute_2d_coords (bool)

  • add_stereo_annotation (bool)

  • embed_display (bool)

Returns:

SVG

Return type:

The SVG representation of the molecule with highlighted atom sets.

shepherd_score.visualize.mol_with_atom_index(mol, label='atomLabel')[source]#
Parameters:
  • mol (rdkit.Chem.Mol)

  • label (Literal['atomLabel', 'molAtomMapNumber', 'atomNote'])

shepherd_score.visualize.view_sample_trajectory(generated_sample, trajectory='x', frame_sleep=0.05, ref_mol=None, only_atoms=True, opacity=0.6, color_scheme=None, custom_carbon_color=None, width=800, height=400)[source]#

View the trajectory of the generated sample. Must set store_trajectory=True or store_trajectory_x0=True in the generate function.

Parameters:
  • trajectory (Literal['x', 'x0'])

  • frame_sleep (float)

  • color_scheme (str | None)

  • custom_carbon_color (str | None)