Change opacity of a single atom in vtkMoleculeMapper

I’m using vtkMolecule, with vtkSimpleBondPerceiver and vtkMoleculeMapper to draw simple molecules. Everything works fine, but I would like to change the opacity (or alpha) of a single or a few selected atoms (and associated bonds). Can this be done? Or would I need to split the molecule in two and draw each group separately?

I thought that maybe I could change the atomic numbers of the target atoms to Z+1000 and then extend the corresponding lookup tables copying the same values as for Z, except for the color alpha. But I don’t know how to do this (and I’m fearing the color would only accept RGB anyway).

Hello !
Which version of VTK do you use ?
There were several improvements concerning molecule coloring since the last release (8.2.0).

  1. With an official release I think the lookup table approach is the one that may work. Look at this to see an example of lookuptable for molecule : https://gitlab.kitware.com/vtk/vtk/blob/v8.2.0/Domains/Chemistry/vtkPeriodicTable.cxx#L207
    This example is RGB but RGBA is also supported:
    vtkLookupTable::SetTableValue(vtkIdType indx, const double rgba[4]);
    Note that using an inexisting atomic number (>118 in vtk) is not recommended and may lead to some problems.(it is also used for atomic radius for instance)

  2. Second approach, but with a dev version of VTK (will work with next release) : Put your RGBA values in an AtomData array and set it as the inputArrayToProcess.
    Here is an example : https://gitlab.kitware.com/vtk/vtk/blob/master/Domains/Chemistry/Testing/Cxx/TestMoleculeMapperColors.cxx#L66
    Again, it is RGB example but the API support a 4th component to have RGBA.

Thank you for your reply. I’m using VTK 8.1.2 (because it’s the one available through pip).

I don’t quite follow the first method. The file you linked looks like the definition of the generic method to assign color per atomic number, but I don’t see how I can change the color of a specific atom. At most, I could change the color of all atoms of a given atomic number (that’s why I was suggesting to use some Z>118, but extending the other tables, such as the one used for radii). But in any case, 8.1.2 apparently does not support vtkMoleculeMapper.PeriodicTable

Indeed, the first method use a fake atomic number, as you suggested.

Indeed, I missed that point, sorry.

So you may try the second method (not sure of the result with vtk 8.1.2, but maybe …) : create an array with one RGBA entry per atom, add it in your molecule AtomData. Then call SetInputArrayToProcess on your molecule mapper.

It looks like the array set with SetInputArrayToProcess is interpreted (in this version) as “atomic numbers”, and not as an explicit color. So I’m back to square one (although at least this changes only the atom color, and not the radius or the bond color).

Hi, is there any solution to how to get this working?