Question on multiple mols2grid instances #19
Replies: 3 comments 3 replies
-
Hi Pat, glad you like the new feature! I had a very quick look at your notebook through Colab and while I could not reproduce this exact issue, something seemingly related happened (a molecule being added to the wrong grid). I think there's a critical race condition at some point, but I'll need to have a better look, probably in two weeks or so. Also what are you using to retrieve the selections? As of now, each grid have their own independent selection (unless they have the same name, in which case they are overwritten). You can get a specific selection through For the |
Beta Was this translation helpful? Give feedback.
-
Hi Cédric, That sounds great, thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi again Pat, I just released the new update (v0.2.0) which includes the grid_list = []
for idx,cluster in tqdm(enumerate(cluster_res), total=len(cluster_res)):
selected_cluster = cluster_res[idx]
selected_df = df.loc(axis=0)[selected_cluster]
grid_list.append(mols2grid.MolGrid(selected_df, name=f"members_{idx}", cache_selection=True))
output = widgets.Output()
@output.capture(clear_output=True, wait=True)
def show_cluster_members(data):
cluster_idx = int(data["Cluster"])
grid = grid_list[cluster_idx]
grid._cached_selection = mols2grid.get_selection(f"members_{cluster_idx}")
view = grid.display(n_rows=3, subset=["img"])
display(view)
center_grid = mols2grid.MolGrid(center_df, name="centers")
center_view = center_grid.display(n_rows=3,
subset=["img", "Cluster"],
selection=False,
callback=show_cluster_members)
display(center_view)
output PS: you don't really need to create the grids beforehand anymore since grid creation is now much faster, so you could directly use something like this: output = widgets.Output()
@output.capture(clear_output=True, wait=True)
def show_cluster_members(data):
cluster_idx = int(data["Cluster"])
cluster_members = cluster_res[cluster_idx]
view = mols2grid.display(df.loc(axis=0)[cluster_members],
name=f"members_{cluster_idx}",
cache_selection=True,
n_rows=3, subset=["img"])
display(view)
center_grid = mols2grid.MolGrid(center_df, name="centers")
center_view = center_grid.display(n_rows=3,
subset=["img", "Cluster"],
selection=False,
callback=show_cluster_members)
display(center_view)
output Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
The callback feature is very useful, thanks! I've been trying to figure out how to implement an enhanced cluster viewer. I've been able to put together an example where I can click on a cluster center in one grid and show the cluster members in a second grid. The part I'm missing is capturing the selections in the cluster member grid. If I click on a cluster in the cluster center grid a second time, the cluster member selections are cleared. Is there a way around this? My example code is in this gist.
https://gist.github.com/PatWalters/ffffa4612e2c143ab7389e539a5c88f7
Also, it would be useful to be able to have a callback in the cluster center grid when checkboxes are not present. However, it appears that when selection=False, clicks in the grid are not recognized.
Beta Was this translation helpful? Give feedback.
All reactions