Author Topic: Taking avg from 3D grid  (Read 2620 times)

0 Members and 1 Guest are viewing this topic.

Offline Sarvesh Agarwal

  • Heavy QuantumATK user
  • ***
  • Posts: 60
  • Country: in
  • Reputation: 0
    • View Profile
Taking avg from 3D grid
« on: March 19, 2013, 07:44 »
Sir please help me to understand, how you are obtaining avg. values from the Electrostatic Difference potential, through the code given in the mannual..
http://www.quantumwise.com/documents/manuals/latest/ReferenceManual/index.html/ref.electrostaticdifferencepotential.html 

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5429
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: Taking avg from 3D grid
« Reply #1 on: March 19, 2013, 13:41 »
You mean how the Python code works, what the different statements mean?
Code: python
# Calculate the mean
v_z = numpy.apply_over_axes(numpy.mean,potential[:,:,:],[0,1]).flatten()
v_z *= potential[:,:,:].unit()

# Print out the result
dX, dY, dZ = potential.volumeElement()
dz = dZ.norm()

shape = potential.shape()
for i in range(shape[2]):
    print dz*i, v_z[i]
Line 2 does almost all the work. potential[:,:,:] could also be written potential.toArray() which is easier to read (but the method was not implemented when the example was written :) ). Line 3 can also be written slightly simpler (see below). Then the numpy "mean" operator is applied to the X and Y directions (axis 0 and 1). The result is then "flattened" to a 1D array, viz. the averaged potential in the Z direction. The flattening is needed because the whole operation returns the vector inside another vector (twice, since we average over 2 directions). The rest of the code is just to put the unit back on and compute the positions in the Z direction. It could be made a bit simpler, since the averaging really only makes sense for the case when XY is perpendicular to Z. Here's another version of the code that does the same thing (in that case, at least), which also makes the units a bit more obvious (the original example prints in Bohr and Hartree):
Code: python
# Calculate the mean
v_z = numpy.apply_over_axes(numpy.mean,potential.toArray(),[0,1]).flatten()
v_z *= potential.unit()

# Print out the result
dz = potential.volumeElement()[2][2].inUnitsOf(Angstrom)

print "Z / Ang    potential / eV"
for i,v in enumerate(v_z.inUnitsOf(eV)):
    print dz*i, v
Which of the construction for the final "print" part you prefer is more a matter of taste :)
« Last Edit: March 19, 2013, 13:58 by Anders Blom »

Offline Sarvesh Agarwal

  • Heavy QuantumATK user
  • ***
  • Posts: 60
  • Country: in
  • Reputation: 0
    • View Profile
Re: Taking avg from 3D grid
« Reply #2 on: March 20, 2013, 09:12 »
Thanku... :) sir

Offline Sarvesh Agarwal

  • Heavy QuantumATK user
  • ***
  • Posts: 60
  • Country: in
  • Reputation: 0
    • View Profile
Re: Taking avg from 3D grid
« Reply #3 on: April 17, 2013, 08:21 »
In the 3-D grid if we need to find the mean over a selected potion and not the whole ... then how we can do that..

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5429
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: Taking avg from 3D grid
« Reply #4 on: April 17, 2013, 09:24 »
You can just call
Code: python
potential.evaluate(x,y,z)
in a loop to evaluate the potential in any position you want, and then do the average.

Offline Sarvesh Agarwal

  • Heavy QuantumATK user
  • ***
  • Posts: 60
  • Country: in
  • Reputation: 0
    • View Profile
Re: Taking avg from 3D grid
« Reply #5 on: April 17, 2013, 12:53 »
THANKS.. :)