# Change opacity of a single atom in vtkMoleculeMapper

**URL:** https://discourse.vtk.org/t/change-opacity-of-a-single-atom-in-vtkmoleculemapper/1612
**Category:** Support
**Created:** [August 19, 2019, 11:29am UTC](https://discourse.vtk.org/t/change-opacity-of-a-single-atom-in-vtkmoleculemapper/1612 "2019-08-19T11:29:14Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Jellby](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jellby/32/135_2.png) [@Jellby](https://discourse.vtk.org/u/Jellby)
#### Post date: [August 19, 2019, 11:29am UTC](https://discourse.vtk.org/t/change-opacity-of-a-single-atom-in-vtkmoleculemapper/1612/1 "2019-08-19T11:29:14Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicolas.vuaille/32/5363_2.png) [@nicolas.vuaille](https://discourse.vtk.org/u/nicolas.vuaille)
#### Post date: [August 20, 2019, 9:17am UTC](https://discourse.vtk.org/t/change-opacity-of-a-single-atom-in-vtkmoleculemapper/1612/2 "2019-08-20T09:17:20Z")

</div>

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](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](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.

---

<div class="post-metadata">

### Author: ![Jellby](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jellby/32/135_2.png) [@Jellby](https://discourse.vtk.org/u/Jellby)
#### Post date: [August 20, 2019, 12:30pm UTC](https://discourse.vtk.org/t/change-opacity-of-a-single-atom-in-vtkmoleculemapper/1612/3 "2019-08-20T12:30:51Z")

</div>

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`…

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicolas.vuaille/32/5363_2.png) [@nicolas.vuaille](https://discourse.vtk.org/u/nicolas.vuaille)
#### Post date: [August 20, 2019, 2:59pm UTC](https://discourse.vtk.org/t/change-opacity-of-a-single-atom-in-vtkmoleculemapper/1612/4 "2019-08-20T14:59:56Z")

</div>

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

> [@Jellby](#):
>
> does not support `vtkMoleculeMapper.PeriodicTable` …

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.

---

<div class="post-metadata">

### Author: ![Jellby](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jellby/32/135_2.png) [@Jellby](https://discourse.vtk.org/u/Jellby)
#### Post date: [August 21, 2019, 7:39am UTC](https://discourse.vtk.org/t/change-opacity-of-a-single-atom-in-vtkmoleculemapper/1612/5 "2019-08-21T07:39:15Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![Shree\_Lakshmi\_Ramesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/shree_lakshmi_ramesh/32/4785_2.png) [@Shree\_Lakshmi\_Ramesh](https://discourse.vtk.org/u/Shree_Lakshmi_Ramesh)
#### Post date: [March 4, 2022, 5:12am UTC](https://discourse.vtk.org/t/change-opacity-of-a-single-atom-in-vtkmoleculemapper/1612/6 "2022-03-04T05:12:26Z")

</div>

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