aidsorb.visualize
This module provides helper functions for visualizing molecular point clouds.
Tip
To visualize a molecular point cloud from the CLI:
$ aidsorb visualize path/to/structure
You can also visualize a structure with ase:
from ase.io import read from ase.visualize import view atoms = read('path/to/file') view(atoms)
- aidsorb.visualize.draw_pcd(pcd, scheme='cpk', feature_to_color=None, colorscale=None, **kwargs)[source]
Visualize molecular point cloud with Plotly.
Each point
pcd[i]is sized based on its atomic numberpcd[i, 3].The color of each point is determined by
feature_to_color. IfNone, the atomic number of each point determines the color. Otherwise,pcd[i, feature_to_color[0]]value determines the color.- Parameters:
pcd (array of shape (N, 4+C))
scheme ({'jmol', 'cpk'}, default='jmol') – Takes effect only if
feature_to_color=None.feature_to_color (tuple of length 2, optional) –
feature_to_color[0] == idx, the index of the feature to be colored.feature_to_color[1] == label, the name of the feature for the colorbar.
colorscale (str, optional) – No effect if
feature_to_color=None. For available options, see colorscale.**kwargs – Valid keword arguments for
plotly.graph_objects.Figure.
- Returns:
fig
- Return type:
Examples
>>> pcd = np.random.randint(1, 30, (100, 5)) >>> fig = draw_pcd(pcd, feature_to_color=(0, 'x coord'), colorscale='viridis')
- aidsorb.visualize.draw_pcd_from_file(filename, render=True, **kwargs)[source]
Visualize molecular point cloud from a file.
- Parameters:
filename (str) – Absolute or relative path to the file.
render (bool, default=True) – Render the point cloud with
plotly.io.renderers.default.**kwargs – Valid keyword arguments for
draw_pcd().
- Returns:
render
- Return type:
Figureifrender=False, elseNone.
- aidsorb.visualize.get_atom_colors(atomic_numbers, scheme='cpk')[source]
Convert atomic numbers to colors based on
scheme.- Parameters:
atomic_numbers (array-like of shape (N,))
scheme ({'jmol', 'cpk'}, default='jmol')
- Returns:
colors
- Return type:
array of shape (N,)
- aidsorb.visualize.get_elements(atomic_numbers)[source]
Convert atomic numbers to element names.
- Parameters:
atomic_numbers (array-like of shape (N,))
- Returns:
elements
- Return type:
array of shape (N,)
Examples
>>> atomic_numbers = np.array([1, 2, 7]) >>> get_elements(atomic_numbers) array(['Hydrogen', 'Helium', 'Nitrogen'], dtype=object)