GridValues¶
- class GridValues(data=None, unit=None, spin=None, spin_type=None, up_component_is_sum=None)¶
Constructor - for internal use.
- Parameters:
data (
NLEngine.RealGrid3D
|NLEngine.ComplexGrid3D
) – The underlying backengine grid.unit (
PhysicalQuantity
) – The unit of the quantity stored on the grid.spin (
Spin.All
|Spin.Up
|Spin.Down
|Spin.RealUpDown
|Spin.ImagUpDown
|Spin.X
|Spin.Y
|Spin.Z
|Spin.Sum
) – The spin component. Default:Spin.All
spin_type (
NLEngine.UNPOLARIZED
|NLEngine.POLARIZED
|NLEngine.NONCOLLINEAR
) – The spin type of the GridValues object. Default:NLEngine.UNPOLARIZED
up_component_is_sum (bool) –
In the case that spin_type is UNPOLARIZED, GridValues always assumes that the given data grid is the Spin.Sum grid. This flag determines how the Spin.Up/Spin.Down components are extracted from that grid.
If this flag is true, the GridValues assumes the Spin.Up component is identical to the Spin.Sum component (as is e.g. the case for potential-type GridValues). As a result, a spin projection to Spin.Up or Spin.Down will return the originally given Spin.Sum data unchanged.
If the flag is False, the Spin.Sum data will be divided by two when projecting to Spin.up or Spin.Down (as is the case for density-type GridValues).
No effect if spin_type is not UNPOLARIZED.
Default: False
- absolute()¶
- Returns:
A new grid containing the absolute values (or modulus) of the current field.
- Return type:
- axisProjection(projection_type='sum', axis='c', spin=None, projection_point=None, coordinate_type=<class 'NL.ComputerScienceUtilities.NLFlag._NLFlag.Fractional'>)¶
Get the values projected on one of the grid axes.
- Parameters:
projection_type (str) –
- The type of projection to perform. Should be either
’sum’ for the sum over the plane spanned by the two other axes.
’average’ or ‘avg’ for the average value over the plane spanned by the two other axes.
’line’ for the value along a line parallel to the axis and through a point specified by the projection_point parameter.
Default: ‘sum’
axis (str) – The axis to project the data onto. Should be either ‘a’, ‘b’ or ‘c’. Default: ‘c’
spin (
Spin.Sum
|Spin.Z
|Spin.X
|Spin.Y
|Spin.Up
|Spin.Down
|Spin.RealUpDown
|Spin.ImagUpDown
) – Which spin component to project on. Default:Spin.All
projection_point (sequence,
PhysicalQuantity
) – Axis coordinates of the point through which to take a line ifprojection_type
is ‘projection_point’. Must be given as a sequence of three coordinates [a, b, c]. It the numbers have units of length, they are first divided by the length of the respective primitive vectors [A, B, C], and then interpreted as fractional coordinates. Unitless coordinates are immidiately interpreted as fractional.coordinate_type (
Fractional
|Cartesian
) – Flag to toggle if the returned axis values should be given in units of Angstrom (NLFlag.Cartesian) or in units of the norm of the axis primitive vector (NLFlag.Fractional). Default:Fractional
- Returns:
A 2-tuple of 1D numpy.arrays containing the axis values and the projected data. For Cartesian coordinate type the grid offset is added to the axis values.
- Return type:
tuple.
- derivatives(x, y, z, spin=None)¶
Calculate the derivative in the point (x, y, z).
- Parameters:
x (PhysicalQuantity with type length.) – The Cartesian x coordinate.
y (PhysicalQuantity with type length.) – The Cartesian y coordinate.
z (PhysicalQuantity with type length.) – The Cartesian z coordinate.
spin (
Spin.All
|Spin.Sum
|Spin.X
|Spin.Y
|Spin.Z
|Spin.Up
|Spin.Down
|Spin.RealUpDown
|Spin.ImagUpDown
) – The spin component to project on. Default: The spin that the object was constructed with.
- Returns:
The gradient at the specified point for the given spin. An error is raised, if the underlying data does not contain the spin projection of the requested type. In case that
Spin.All
is used, a tuple with (Spin.Sum
,Spin.X
,Spin.Y
,Spin.Z
) components is returned. Note that in the spin unpolarized case theSpin.X
,Spin.Y
andSpin.Z
entries are zero, and for the spin polarized case theSpin.X
andSpin.Y
are zero.- Return type:
- downsample(downsampling_a=None, downsampling_b=None, downsampling_c=None)¶
Generate a new GridValues object where the grid is downsampled. Along periodic directions an FFT downsampling is performed. Along non-periodic directions antialiasing and downsampling is performed.
- Parameters:
downsampling_a (int) – The new number of grid points along the A direction. Default: No downsampling.
downsampling_b (int) – The new number of grid points along the B direction. Default: No downsampling.
downsampling_c (int) – The new number of grid points along the C direction. Default: No downsampling.
- evaluate(x, y, z, spin=None)¶
Evaluate in the point (x, y, z).
- Parameters:
x (PhysicalQuantity with type length) – The Cartesian x coordinate.
y (PhysicalQuantity with type length) – The Cartesian y coordinate.
z (PhysicalQuantity with type length) – The Cartesian z coordinate.
spin (
Spin.All
|Spin.Sum
|Spin.X
|Spin.Y
|Spin.Z
|Spin.Up
|Spin.Down
|Spin.RealUpDown
|Spin.ImagUpDown
) – The spin component to project on. Default: The spin that the object was constructed with.
- Returns:
The value at the specified point for the given spin. An error is raised, if the underlying data does not spin projection of the requested type. In case
Spin.All
is used, a tuple with (Spin.Sum
,Spin.X
,Spin.Y
,Spin.Z
) components is returned. Note that in the spin unpolarized case theSpin.X
,Spin.Y
andSpin.Z
entries are zero, and for the spin polarized case theSpin.X
andSpin.Y
are zero.- Return type:
- gridCoordinate(i, j, k)¶
Return the coordinate for a given grid index.
- Parameters:
i (int) – The grid index in the A direction.
j (int) – The grid index in the B direction.
k (int) – The grid index in the C direction.
- Returns:
The Cartesian coordinate of the given grid index.
- Return type:
PhysicalQuantity of type length.
- metatext()¶
- Returns:
The metatext of the object or None if no metatext is present.
- Return type:
str | None
- nlprint(stream=None)¶
Print a string containing an ASCII table useful for plotting the AnalysisSpin object.
- Parameters:
stream (python stream) – The stream the table should be written to. Default:
NLPrintLogger()
- primitiveVectors()¶
- Returns:
The primitive vectors of the grid.
- Return type:
PhysicalQuantity of type length.
- scale(scale)¶
Scale the field with a float.
- Parameters:
scale (float) – The parameter to scale with.
- setMetatext(metatext)¶
Set a given metatext string on the object.
- Parameters:
metatext (str | None) – The metatext string that should be set. A value of “None” can be given to remove the current metatext.
- shape()¶
- Returns:
The number of grid points in each direction.
- Return type:
tuple of three int.
- spinProjection(spin=None)¶
Construct a new
GridValues
object with the values of this object projected on a given spin component.- Parameters:
spin (
Spin.All
|Spin.Sum
|Spin.X
|Spin.Y
|Spin.Z
|Spin.Up
|Spin.Down
|Spin.RealUpDown
|Spin.ImagUpDown
) – The spin component to project on. Default: The spin the object was created with. If the spin wasSpin.All
,Spin.Sum
will be used for the projection.- Returns:
A new
GridValues
object for the specified spin.- Return type:
- toArray()¶
- Returns:
The values of the grid as a numpy array slicing off any units.
- Return type:
numpy.array
- uniqueString()¶
Return a unique string representing the state of the object.
- unit()¶
- Returns:
The unit of the data in the grid.
- Return type:
A physical unit.
- unitCell()¶
- Returns:
The unit cell of the grid.
- Return type:
PhysicalQuantity of type length.
- volumeElement()¶
- Returns:
The volume element of the grid represented by three vectors.
- Return type:
PhysicalQuantity of type length.
Usage Examples¶
We distinguish between three types of spin treatment: Unpolarized, polarized
and non-collinear. In the spin-unpolarized calculations we have no
explicit treatment of spin and we assign the same values to the Spin.Up
and Spin.Down
projections. In spin-polarized calculation we treat spin in a collinear
fashion and we distinguish between Spin.Up
and Spin.Down
components. Using the up and
down components, the projection in z-direction can be computed, which can be accessed with Spin.Z
.
In the case of non-collinear calculations, we have spinors as solutions, and the spin is no longer aligned along
a quantization axis. Non-collinear grid data can have four parts, up(-up), down(-down), the
real part of up-down, and the imaginary part of up-down, accessible with the
spin projections Spin.Up
, Spin.Down
, Spin.RealUpDown
and Spin.ImagUpDown
.
Using these four components, the spin projection along the x-, y-, and z-direction can be
computed. They can be retrieved using Spin.X
, Spin.Y
, and Spin.Z
.
For all three spin-types the Spin.All
and Spin.Sum
is supported.
Polarized example:
# Extract spin components from electron density.
spin_up = electron_density.spinProjection(spin=Spin.Up)
spin_down = electron_density.spinProjection(spin=Spin.Down)
spin_sum = electron_density.spinProjection(spin=Spin.Sum)
# Get data as numpy arrays.
up = spin_up.toArray()
down = spin_down.toArray()
sums = spin_sum.toArray()
# Print the total electron density for each component.
print "Up ", (up).sum()
print "Down ", (down).sum()
print
print "Up + Down", (up + down).sum()
print "Sum ", (sums).sum()
The GridValues
constructor is made for internal use. Constructing a
generic grid must be done using the gridValues()
function:
# Setup generic grid values object with random data.
data = numpy.random.random([30, 30, 30]) * Angstrom**-3
cell = SimpleCubic(4.0*Angstrom)
grid_values = gridValues(data, cell)
Notes¶
The following classes inherit from the GridValues
object: