Author Topic: calculate the absolute value of spin polarized density  (Read 4192 times)

0 Members and 1 Guest are viewing this topic.

Offline jerry

  • Heavy QuantumATK user
  • ***
  • Posts: 85
  • Reputation: 0
    • View Profile
calculate the absolute value of spin polarized density
« on: October 10, 2012, 13:17 »
Dear,

I want to calculate the absolute value of spin polarized density, which is the absolute value of (Pup-Pdown)/(Pup+Pdown). How to use python script to code this?

Thank you very much!

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: calculate the absolute value of spin polarized density
« Reply #1 on: October 10, 2012, 13:27 »
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
Code: python
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")

Offline jerry

  • Heavy QuantumATK user
  • ***
  • Posts: 85
  • Reputation: 0
    • View Profile
Re: calculate the absolute value of spin polarized density
« Reply #2 on: October 10, 2012, 14:47 »
First of all, thank you very much for your replying.

Actually, i have known how to calculate the normalized spin density difference. But this value can be both positive and negative, I want to change the negative part to be positive (The absolute value of the spin density difference). I have try the command abs, it does bot work because the spin density difference is a function rather than a number. Can you help me on this?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: calculate the absolute value of spin polarized density
« Reply #3 on: October 10, 2012, 23:26 »
Anything is possible in Python - but not always so easy :) Try this:
Code: python
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)

Offline jerry

  • Heavy QuantumATK user
  • ***
  • Posts: 85
  • Reputation: 0
    • View Profile
Re: calculate the absolute value of spin polarized density
« Reply #4 on: October 11, 2012, 13:59 »
Thank you very much! It works well :)