Issue with vtkMoleculeMapper and VTK.js

Hi, I’m trying to use vtkMoleculeMapper but I get a blank canvas and a javascript error (Jupyter Lab, pyvista & Panel ). Can anyone reproduce this? Most likely I made a mistake setting up the pipeline; I would be grateful for any pointers.

import vtk


import panel as pn
pn.extension('vtk')

import numpy as np
import pyvista as pv


N=10
a=np.random.rand(N,3)*10
b=pv.wrap(a)

ids=np.ones(N,dtype=np.uint8)
b['atomic_number']=ids
b.set_active_scalars('atomic_number')
poly = b

ps2mf=vtk.vtkPointSetToMoleculeFilter()

ps2mf.SetInputData(poly)

moleculeMapper=vtk.vtkMoleculeMapper()
# moleculeMapper.UseFastSettings()
moleculeMapper.SetRenderAtoms(True)

moleculeMapper.SetInputConnection(ps2mf.GetOutputPort())


mapper = moleculeMapper

actor = vtk.vtkActor()
actor.SetMapper(moleculeMapper)

ren = vtk.vtkRenderer()
ren.AddActor(actor)

ren.ResetCamera()


win = vtk.vtkRenderWindow()
win.AddRenderer(ren)


geom_pane = pn.pane.VTK(win, width=500, height=500)

# should show some molecules, and yet I get on the javascript console:
# Uncaught (in promise) TypeError: t.oglmapper is undefined
#     traverseOpaquePass index.js:63
#     traverse index.js:27
#     traverse index.js:35
#     traverse index.js:75
#     traverseAllPasses index.js:1066
#     u index.js:348
#     render index.js:741
#     render index.js:57
#     l index.js:257

geom_pane

The vtkOpenGLMoleculeMapper is missing from the VTK python wheels, therefore the vtkMoleculeMapper is unable to render.

You can check this:

>>> vtk.vtkOpenGLMoleculeMapper
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'vtkmodules.all' has no attribute 'vtkOpenGLMoleculeMapper'

Compare to the vtkOpenGLActor, which is probably present:

>>> vtk.vtkOpenGLActor
<class 'vtkmodules.vtkRenderingOpenGL2.vtkOpenGLActor'>

This should be fixed for the next VTK release, but until then the use of molecule rendering requires building VTK from source with the vtkDomainsChemistryOpenGL2 module enabled.

On top of what @dgobbi is saying, I’m not sure Panel/vtk.js will properly handle the conversion of such mapper. But vtk.js can render molecules directly if need be but the integration with JupyterLab does not exist.

Thanks to both for the clarification. I will look into compiling, or wait.
Meanwhile I tried the next best method, ‘vtkGlyph3DMapper’. The OpenGL class for this one does exist, however I get the same javascript error. I posted it here: vtkGlyph3DMapper on Panel + JupyterLab gives javascript error, blank screen

Hi, vtk 9.01 is out, on conda-forge too. However vtkOpenGLMoleculeMapper is still not present on the python module. At the time of your reply I assumed vtk was moving the MoleculeMapper into its main code base, but I guess it still requires including the vtkDomainsChemistryOpenGL2 in the build. Is this the case?

In the main code base, !7646 placed vtkDomainsChemistryOpenGL2 into the default build. But the next release (9.1.0) is still a ways off, several weeks at least, no date has been set.

When building 9.0.1, vtkDomainsChemistryOpenGL2 must still be explicitly enabled in the build.

Thanks, I’ll keep an eye out for 9.1.0 .