macrodensity.potential module#

Module Description#

This module contains functions for calculating different types of averages from the dataset.

macrodensity.averages.macroscopic_average(potential: ndarray, periodicity: float, resolution: float) ndarray#

Calculate the macroscopic average of a 1D potential field with periodicity.

Parameters:

potential (np.ndarray): 1D array representing the potential field.

periodicity (float): Periodicity of the field.

resolution (float): Spacing between potential data points.

Returns:

np.ndarray: 1D array containing the macroscopic average of the potential field.

Example:
>>> potential = np.random.rand(20)
>>> periodicity = 2.0
>>> resolution = 0.1
>>> macro_avg_result = macroscopic_average(potential, periodicity, resolution)
>>> print("Macroscopic Average Result:")
>>> print(macro_avg_result)
macrodensity.averages.planar_average(grid: ndarray, nx: int, ny: int, nz: int, axis: str = 'z') ndarray#

Calculate the planar average of a 3D grid along a specified axis.

Parameters:

grid (np.ndarray): 3D array representing the data grid.

nx (int): Number of points along the x-axis in the grid.

ny (int): Number of points along the y-axis in the grid.

nz (int): Number of points along the z-axis in the grid.

axis (str, optional): Axis along which to calculate the average

(‘x’, ‘y’, or ‘z’). Default is ‘z’.

Returns:

np.ndarray: 1D array containing the planar average along the specified axis.

Example:
>>> axis = 'z'
>>> planar_avg = planar_average(grid, nx, ny, nz, axis)
>>> print("Planar Average along axis", axis)
>>> print(planar_avg)
macrodensity.averages.spherical_average(cube_size: list, cube_origin: list, input_file: str = 'LOCPOT', print_output: bool = True) -> (<class 'float'>, <class 'float'>)#

Calculate the volume average of the electronic potential within a spherical region.

This function calculates the volume average of the electronic potential within a spherical region defined by a specific size and origin. The size of the spherical region is specified by the cube_size parameter, which determines the number of mesh points along each direction (NGX/Y/Z). The origin of the sphere is given by the cube_origin parameter, specified in fractional coordinates. The function reads the electronic potential data from the specified input file (e.g., LOCPOT) and calculates the potential and variance within the spherical region.

Parameters:

cube_size (list): The size of the spherical region in units of mesh points (NGX/Y/Z).

cube_origin (list): The origin of the spherical region in fractional coordinates.

input_file (str, optional): The filename of the file containing the electronic potential (e.g., LOCPOT). Default is ‘LOCPOT’.

print_output (bool, optional): If True, the function prints the calculated potential and variance. Default is True.

Returns:

tuple: A tuple containing the volume-averaged potential and the variance within the spherical region.

Outputs:

cube_potential, cube_variance

macrodensity.averages.travelling_volume_average(grid: ndarray, cube: tuple, origin: tuple, vector: list, nx: int, ny: int, nz: int, magnitude: int) ndarray#

Calculate the volume average at multiple positions along a given vector.

Parameters:

grid (np.ndarray): 3D array representing the data grid.

cube (tuple): Dimensions of the cube (x, y, z).

origin (tuple): Coordinates of the origin point.

vector (list): 3D vector representing the direction of travel.

nx (int): Number of points along the x-axis in the grid.

ny (int): Number of points along the y-axis in the grid.

nz (int): Number of points along the z-axis in the grid.

magnitude (int): Number of positions to travel along the vector.

Returns:
np.ndarray: 1D array containing the volume averages at each position

along the vector.

Example:
>>> vector = (0.1, 0.2, 0.3)
>>> magnitude = 5
>>> travelling_avg = travelling_volume_average(grid, cube, origin, vector,
    nx, ny, nz, magnitude)
>>> print("Travelling volume Average:")
>>> print(travelling_avg)
macrodensity.averages.volume_average(origin: tuple, cube: tuple, grid: ndarray, nx: int, ny: int, nz: int, travelled: list = [0, 0, 0]) tuple#

Calculate the volume average and variance of a cube in a 3D grid.

Parameters:

origin (tuple): Coordinates of the origin point.

cube (tuple): Dimensions of the cube (x, y, z).

grid (np.ndarray): 3D array representing the data grid.

nx (int): Number of points along the x-axis in the grid.

ny (int): Number of points along the y-axis in the grid.

nz (int): Number of points along the z-axis in the grid.

travelled (list, optional): Distance travelled from the origin in each

direction (x, y, z). Default is [0, 0, 0].

Returns:

tuple: A tuple containing the volume average and variance of the cube.

Example:
>>> origin = (0.5, 0.5, 0.5)
>>> cube = (3, 3, 3)
>>> grid = np.random.rand(10, 10, 10)
>>> nx, ny, nz = 10, 10, 10
>>> travelled = [1, 2, 3]
>>> avg, variance = volume_average(origin, cube, grid, nx, ny, nz, travelled)
>>> print("volume Average:", avg)
>>> print("Variance:", variance)