From 3355bebde3b3fd91b3681bd57b78e792f1cfc625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cireaml=E2=80=9D?= Date: Thu, 17 Aug 2023 11:55:59 +0100 Subject: [PATCH] move `read_cube_density` --- macrodensity/alpha.py | 28 ---------------------------- macrodensity/io.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/macrodensity/alpha.py b/macrodensity/alpha.py index 31c0e69..4f9a241 100644 --- a/macrodensity/alpha.py +++ b/macrodensity/alpha.py @@ -657,34 +657,6 @@ def create_plotting_mesh(NGX: int,NGY: int,NGZ: int,pc: np.ndarray,grad: np.ndar return plane -def read_cube_density(FILE: str) -> np.ndarray: - """ - Reads a cube density file and extracts relevant information. - - Parameters: - FILE (str): The path to the cube density file. - - Returns: - numpy.ndarray: A 3x3 numpy array representing the lattice. - - Example: - >>> file_path = 'path/to/your/cube_density_file.cube' - >>> # Read the cube density file and get the lattice - >>> lattice = read_cube_density(file_path) - >>> print(lattice) - """ - f = open(FILE,"r") - lines = f.readlines() - f.close() - lattice = np.zeros(shape=(3,3)) - for line in lines: - inp = line.split() - if inp == []: - continue - if len(inp) == 4: - natms = inp[0] - - def points_2_plane(a: np.ndarray, b: np.ndarray, c: np.ndarray) -> np.ndarray: """ Calculates the plane coefficients from three points in space. diff --git a/macrodensity/io.py b/macrodensity/io.py index 1fa0ff5..b7c1cef 100644 --- a/macrodensity/io.py +++ b/macrodensity/io.py @@ -397,4 +397,32 @@ def read_vasp_density(FILE: str, use_pandas: bool=None, quiet: bool=False) -> tu if not quiet: print("Average of the potential = ", np.average(Potential)) - return Potential, NGX, NGY, NGZ, lattice \ No newline at end of file + return Potential, NGX, NGY, NGZ, lattice + + +def read_cube_density(FILE: str) -> np.ndarray: + """ + Reads a cube density file and extracts relevant information. + + Parameters: + FILE (str): The path to the cube density file. + + Returns: + numpy.ndarray: A 3x3 numpy array representing the lattice. + + Example: + >>> file_path = 'path/to/your/cube_density_file.cube' + >>> # Read the cube density file and get the lattice + >>> lattice = read_cube_density(file_path) + >>> print(lattice) + """ + f = open(FILE,"r") + lines = f.readlines() + f.close() + lattice = np.zeros(shape=(3,3)) + for line in lines: + inp = line.split() + if inp == []: + continue + if len(inp) == 4: + natms = inp[0] \ No newline at end of file