Very much like you have it in the formula. Look at the small Python script at the end of http://quantumwise.com/publications/tutorials/mini-tutorials/141 where we compute pup-pdown. You would just add the denominator, and end up with a corresponding script like
e_down = ElectronDensity(config, spin=Spin.Down)
e_up = ElectronDensity(config, spin=Spin.Up)
nlsave("file.nc", (e_up-e_down)/(e_up+e_down), object_id="Spin Polarization Density")
Anything is possible in Python - but not always so easy :)
Try this:
import NLEngine
# Compute the electron density for spin up and down
eu = ElectronDensity(config, spin=Spin.Up)
ed = ElectronDensity(config, spin=Spin.Down)
# Calculate the polarization density
e_diff = (eu-ed)/(eu+ed)
# Extract the raw numbers - and take the absolute
data = numpy.abs(e_diff.toArray().flatten())
# Insert the absolute numbers back into the object
grid_descriptor = e_diff._GridValues__grid3d.gridDescriptor()
e_diff._GridValues__grid3d = NLEngine.RealGrid3D(grid_descriptor,NLEngine.doubleSequenceToRealVector(data),True)
# Save
nlsave("file.nc", e_diff)