NanoLanguage doesn't allow you to subtract two
ElectronDensity objects from each other (it does allow you to add them, however), which means it's not immediately obvious how to calculate e.g. the spin polarization density.
By using some undocumented tricks, it is however possible to do it relatively easily anyway.
Disclaimer: The scripts below use undocumented features, and may not work in future (and/or some old) releases of ATK.
The steps involved are:
1) Extract the actual array data from the ElectronDensity objects. This is easy, just use the
toArray() method on the object.
2) Calculate the difference. This is also easy, because the arrays (not the objects!) support the minus operation.
3) Store the difference. This is the tricky bit, but all we need to know is that the density data is stored in a private property called
_ElectronDensity__electron_density_data.
The second part of the trick is to use the Python module
copy to create a new ElectronDensity object (since this class has no constructor exposed in NanoLanguage).
Putting this together in a utility function, we obtain
def calculateDensityDifference (d1,d2):
import copy
n1 = d1.toArray()
n2 = d2.toArray()
density = copy.copy(d1)
density._ElectronDensity__electron_density_data = (n1-n2)
return density
Calling this with two densities (d1 and d2), the function returns their difference in an ElectronDensity object, which you can put into a VNL file just as normal, and plot in Virtual NanoLab.