Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ireaml committed Sep 13, 2023
1 parent 2dfa78e commit 61e64b9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 32 deletions.
4 changes: 2 additions & 2 deletions macrodensity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""
MacroDensity is a package to read, process and plot electrostatic potential and electron density
MacroDensity is a package to read, process and plot electrostatic potential and electron density
files from electronic structure calculations.
"""
import math

import numpy as np
from scipy import interpolate

from macrodensity.averages import *
from macrodensity.density import *
from macrodensity.io import *
from macrodensity.plotting import *
from macrodensity.tools import *
from macrodensity.utils import *
from macrodensity.averages import *
10 changes: 5 additions & 5 deletions macrodensity/averages.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'''
"""
This module contains functions for calculating different types of averages from the dataset.
'''
"""
from __future__ import division, print_function

import numpy as np

from macrodensity.io import read_vasp_density, read_gulp_potential
from macrodensity.utils import matrix_2_abc, density_2_grid
from macrodensity.io import read_gulp_potential, read_vasp_density
from macrodensity.utils import density_2_grid, matrix_2_abc


def macroscopic_average(
Expand Down Expand Up @@ -328,4 +328,4 @@ def planar_average(
z_plane[:, :] = grid[:, :, z_value]
average[z_value] = z_plane.mean()

return average
return average
7 changes: 3 additions & 4 deletions macrodensity/density.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
macrodensity.density contains functions to calculate the electron
density of a structure, as well as functions to calculate the electrostatic potential
and the electrostatic potential gradients of a structure.
macrodensity.density contains functions to calculate the electron
density of a structure, as well as functions to calculate the electrostatic potential
and the electrostatic potential gradients of a structure.
"""

from __future__ import division, print_function
Expand Down Expand Up @@ -75,4 +75,3 @@ def element_vol(vol: float, nx: int, ny: int, nz: int) -> float:
ele_vol = vol / number_of_elements

return ele_vol

20 changes: 9 additions & 11 deletions macrodensity/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,27 @@

import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import cm

import numpy as np
import pandas as pd
from scipy.interpolate import interp1d

from ase.io import cube, vasp
from matplotlib import cm
from scipy.interpolate import interp1d

from macrodensity.averages import (
macroscopic_average,
planar_average,
travelling_volume_average,
volume_average,
)
from macrodensity.density import (
gradient_magnitude,
)
from macrodensity.density import gradient_magnitude
from macrodensity.io import read_gulp_potential, read_vasp_density
from macrodensity.tools import _find_active_space, create_plotting_mesh
from macrodensity.utils import (
density_2_grid,
matrix_2_abc,
numbers_2_grid,
points_2_plane,
vector_2_abscissa,
density_2_grid
)

MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -82,9 +78,9 @@ def energy_band_alignment_diagram(
edge (None or str, optional): The edge color for the bars.
If None, there will be no edge color. Default is None.
fig_format (str, optional): The format used to save the image.
fig_format (str, optional): The format used to save the image.
Default is "pdf".
Returns:
Figure: A matplotlib figure object containing the energy band alignment
diagram.
Expand Down Expand Up @@ -697,7 +693,9 @@ def plot_field_at_point(
# grad_mag=np.linalg.norm( [grad_y,grad_y,grad_z], axis=3)

## This function in Macrodensity averages Efield ACROSS Z for Slab calculations
xx,yy,grd = md.create_plotting_mesh(NGX,NGY,NGZ,plane_coeff,grad_mag) #AVG over full volume
xx, yy, grd = md.create_plotting_mesh(
NGX, NGY, NGZ, plane_coeff, grad_mag
) # AVG over full volume

# Here we construct the same xx,yy,grd variables with a SLICE, forming a plane in XY at particular ZSLICE
xx, yy = np.mgrid[0:NGX, 0:NGY]
Expand Down
6 changes: 3 additions & 3 deletions macrodensity/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python
"""
macrodensity.tools contains functions to read and manipulate the electronic
"""
macrodensity.tools contains functions to read and manipulate the electronic
density data from a material.
"""

Expand All @@ -11,7 +11,7 @@

from macrodensity.averages import volume_average
from macrodensity.io import get_band_extrema, read_vasp_density
from macrodensity.utils import matrix_2_abc, density_2_grid
from macrodensity.utils import density_2_grid, matrix_2_abc


def bulk_interstitial_alignment(
Expand Down
1 change: 1 addition & 0 deletions macrodensity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def get_third_coordinate(plane_coeff: np.ndarray, NGX: int, NGY: int) -> list:

return zz


def density_2_grid(
density: np.ndarray,
nx: int,
Expand Down
13 changes: 6 additions & 7 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import sys
import unittest
from os.path import join as path_join

import matplotlib as mpl
import matplotlib.pyplot as plt
import pytest


import numpy as np
import pandas as pd
import pkg_resources
import pytest

import macrodensity as md

Expand Down Expand Up @@ -343,7 +342,7 @@ def test_moving_cube(self):


class TestPlottingFunctions(unittest.TestCase):

def test_plot_planar_average(self):
"""Tests the plot_planar_average function"""
locpot = pkg_resources.resource_filename(
Expand Down Expand Up @@ -429,7 +428,7 @@ def test_plot_planar_cube(self):
self.addCleanup(os.remove, "planar_average.csv")
self.addCleanup(os.remove, "planar_average.png")


@pytest.mark.mpl_image_compare(
baseline_dir=f"{_file_path}/testIm",
filename="BandAlignment.png",
Expand All @@ -450,10 +449,10 @@ def test_energy_band_alignment_diagram(self):
"TiO2": [4.8, 7.8],
},
ylims=(-10, 0.0),
arrowhead=0.15,
arrowhead=0.15,
fig_format='png'
)

if os.path.exists("BandAlignment.png"):
self.addCleanup(os.remove, "BandAlignment.png")
return fig
Expand Down

0 comments on commit 61e64b9

Please sign in to comment.