Given two cube file, one with the real part, one with the imaginary part, of a complex molecular orbital, this notebook will plot an isosurface of the absolute value of the orbital and color the surface with the complex phase. If you use this notebook, or code based on it, for your own research, please cite the reference below and provide the URL from where you obtained this notebook.
Define the cube file on the next line, without the file name extension .cube. You can also define the file name extension, to accommodate .cub vs .cube
The next set of commands import the cube file data and visualize the molecule that’s defined in the cube file. Available PlotThemes are HeavyAtom BallAndStick SpaceFilling Tubes WireFrame
Check that data ranges in the Re and Im cube file are the same. Otherwise, we definitely have a problem with incompatible grids for the two cube files.
next: should be the step sizes shown in the cube file, in case you want to cross check that
In[]:=
step/0.529177
Out[]=
{0.16,0.16,0.16}
create interpolation function for the array with the phases (this step can be a bit slow) The idea comes from https://mathematica.stackexchange.com/questions/105623/color-a-single-contour-from-a-listcontourplot3d-using-values-from-a-list (the second option from that posting uses ListSliceDensityPlot3D, but there seems to be no easy option to set the opacity of the surface, and the plot takes longer to make) Note that Mathematica 12.3 gives a warning(?) with that example
when you execute the example from that web page, but the result looks exactly like the one on StackExchange. We get the same warning below, but the plots definitely look OK.
Rotate unless you are happy with the display, then export. After the Export, white space should be removed from the plot, e.g. with an ImageMagick tool: mogrify -trim <filename>