Skip to content

Commit

Permalink
Updating minushalf to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hentt30 committed Mar 11, 2023
1 parent 6d371ed commit 11dc281
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 105 deletions.
2 changes: 1 addition & 1 deletion minushalf/commands/band_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
import click
from minushalf.data.softwares import Softwares
from minushalf.softwares.vasp import Vasp
from minushalf.softwares.vasp_factory import Vasp
from minushalf.utils.cli_messages import welcome_message,end_message
from minushalf.utils.projection_to_df import projection_to_df
from minushalf.utils.band_structure import BandStructure
Expand Down
2 changes: 1 addition & 1 deletion minushalf/commands/band_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import click
from minushalf.softwares.vasp import Vasp
from minushalf.softwares.vasp_factory import Vasp
from minushalf.data.softwares import Softwares
from minushalf.utils.cli_messages import welcome_message,end_message
from minushalf.utils.band_structure import BandStructure
Expand Down
2 changes: 1 addition & 1 deletion minushalf/commands/cbm_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
import click
from minushalf.data.softwares import Softwares
from minushalf.softwares.vasp import Vasp
from minushalf.softwares.vasp_factory import Vasp
from minushalf.utils.cli_messages import welcome_message,end_message
from minushalf.utils.projection_to_df import projection_to_df
from minushalf.utils.band_structure import BandStructure
Expand Down
2 changes: 1 addition & 1 deletion minushalf/commands/correct_potfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import click
from loguru import logger
from minushalf.softwares.vasp import Vasp
from minushalf.softwares.vasp_factory import Vasp
from minushalf.data.softwares import Softwares
from minushalf.io.vtotal import (Vtotal)
from minushalf.utils.cli_messages import welcome_message,end_message
Expand Down
2 changes: 1 addition & 1 deletion minushalf/commands/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from minushalf.utils.cli_messages import welcome_message,end_message
from minushalf.utils.get_correction_params import get_valence_correction_params, get_conduction_correction_params

from minushalf.softwares.vasp import (Vasp)
from minushalf.softwares.vasp_factory import (Vasp)
from minushalf.corrections.correction import (DFTCorrection)
from minushalf.data.minushalf_yaml_default_configuration import CorrectionDefaultParams
from minushalf.data.softwares import (Softwares)
Expand Down
2 changes: 1 addition & 1 deletion minushalf/commands/vbm_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Aims to show how the last valence band are composed by the orbitals of each atom.
"""
import click
from minushalf.softwares.vasp import Vasp
from minushalf.softwares.vasp_factory import Vasp
from minushalf.data.softwares import Softwares
from minushalf.utils.cli_messages import welcome_message,end_message
from minushalf.utils.projection_to_df import projection_to_df
Expand Down
32 changes: 5 additions & 27 deletions minushalf/data/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,8 @@ class Constants:
Johannes Rydberg, is a physical constant relating to the
electromagnetic spectra of an atom
"""
@property
def pi_constant(self):
"""
Constant PI
"""
return 3.1415926548

@property
def trimming_exponent(self):
"""
Expoent for trimming function
"""
return 8

@property
def bohr_radius(self):
"""
Bohr radius
"""
return 0.529177068

@property
def rydberg(self):
"""
Rydberg constant
"""
return 13.6058038
def __init__(self) -> None:
self.pi_constant = 3.1415926548
self.trimming_exponent = 8
self.bohr_radius = 0.529177068
self.rydberg = 13.6058038
50 changes: 2 additions & 48 deletions minushalf/utils/correct_potential_fourier_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,17 @@ def correct_potential_fourier_transform(
occupation_potential: np.array,
cut: float,
) -> np.array:
r"""
The pseudopotential is given in terms of the radial distance, and is only defined for r >= 0,
as expected. Since it is only evaluated inside an integral from 0 to infinity, it does not
matter what values it assumes for r < 0. A natural choice is to define the function to be
zero for negative values, but a more convenient choice is to choose
v(-r)=-v(r) and n(-r)=-n(r), since purely real and odd functions have purely imaginary Fourier transforms.
Let v' and n' be the odd extensions of the potential and the number density, respectively.
.. math::
E_{v} = \int_{0}^{\infty}v(r)n(r)dr = \int_{0}^{\infty}v'(r)n'(r)dr =
\frac{1}{2}\cdot\int_{-\infty}^{\infty}v'(r)n'(r)dr = -\frac{1}{2}\cdot\int_{-\infty}^{\infty}V(k)N(k)dk
On the third equalitty, we used the fact that the product of two odd
functions is even, and in the last step we have applied Parseval's theorem,
considering that the Fourier transforms are purely imaginary. Even though
the function may not pass through the origin, we can still make an odd extension, by making it discontinuous.
The data stored on POTCAR corresponds to the Fourier transform of the odd extension of v. It can be approximated
by the summation on the right, where the prefactors were ommited.
.. math::
V(k) = i\cdot \sqrt{\frac{2}{\pi}}\cdot\int_{0}^{\infty}v(r)sin(b\cdot k\cdot r)dr
\Rightarrow V(k)\sim \sum^{N_{r}}_{i=1}
\frac{(v[i]\cdot sin(b\cdot k\cdot r[i])+v[i-1]\cdot sin(b\cdot k\cdot r[i-1]))}{2\cdot (r[i]-r[i-1])}
Computes the opposite of the imaginary part of the j-th fourier transform coefficient
through numerical integrationIndex zero stands for the r=DeltaR, and the function is
assumed to be zero at the origin. Thus, the first trapezium of the numerical integration is
degenerated to a triangulum, and its area must be calculated as so.
Args:
coefficient (np.array): Fourier transform of the potential for the atom in its ground state
k (np.array): The wave vector in reciprocal space
rays(np.array): List of rays on which pseudopotential calculations were made
occupation_potential (np.arraygit): Potential of fractional electron occupation at the exact level to be corrected
cut(float): Cutting parameter to cancel the potential
Returns:
Fourier transform of the potential for the state with fractional occupation of the crystal
"""
const = Constants()

k = np.reshape(k, (len(k), 1))

if not k[0][0]:
k[0][0] = 10**(-12)

try:
filter_rays = rays[np.where(rays < cut)]
except ValueError as cut_error:
raise ValueError(
"the cut is smaller than all the rays passed") from cut_error

radius = filter_rays[1:].astype(float)
lazy_radius = filter_rays[:-1].astype(float)
potential = occupation_potential[1:len(filter_rays)].astype(float)
Expand Down
3 changes: 2 additions & 1 deletion minushalf/utils/get_correction_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from minushalf.interfaces.minushalf_yaml import MinushalfYaml
from minushalf.interfaces.software_abstract_factory import SoftwaresAbstractFactory
from minushalf.utils.cut_initial_guess import CutInitialGuess
from minushalf.utils.get_correction_params import get_fractionary_correction_indexes,get_simple_correction_indexes
from minushalf.utils.fractionary_correction_indexes import get_fractionary_correction_indexes
from minushalf.utils.simple_correction_indexes import get_simple_correction_indexes
from minushalf.data.cut_initial_guess_methods import (CutInitialGuessMethods)
from minushalf.utils.band_structure import BandStructure
from minushalf.utils.projection_to_df import projection_to_df
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ install_command = python -m pip install .
deps=
pytest==6.2.1
pytest-mock==3.0.0
pandas==1.3.4
pandas==1.4.0
fortranformat==0.2.5
Click==7.1.2
pyfiglet==0.8.post1
loguru==0.5.3
tabulate==0.8.7
tabulate==0.9.0
pyyaml
scipy==1.7.3
aenum==3.0.0
numpy==1.21.0
numpy==1.22.0
usedevelop=False
commands=
python -m pytest
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pandas==1.3.4
pandas==1.4.0
fortranformat==0.2.5
Click==7.1.2
pyfiglet==0.8.post1
loguru==0.5.3
tabulate==0.8.7
tabulate==0.9.0
pyyaml
scipy==1.7.3
aenum==3.0.0
numpy==1.21.0
numpy==1.22.0
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
long_description=long_description,
license="GPL",
install_requires=[
"pandas==1.3.4",
"pandas==1.4.0",
"fortranformat==0.2.5",
"Click==7.1.2",
"pyfiglet==0.8.post1",
"loguru==0.5.3",
"tabulate==0.8.7",
"numpy==1.21.0",
"tabulate==0.9.0",
"numpy==1.22.0",
"pyyaml",
"scipy==1.7.3",
"aenum==3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_band_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test band character command
"""
from click.testing import CliRunner
from minushalf.commands import band_character
from minushalf.commands.band_character import band_character


def test_band_character_gan_3d(file_path):
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_band_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test band gap command
"""
from click.testing import CliRunner
from minushalf.commands import band_gap
from minushalf.commands.band_gap import band_gap


def test_band_gap_gan_3d(file_path):
Expand Down
6 changes: 4 additions & 2 deletions tests/cli/test_cbm_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test cbm character command
"""
from click.testing import CliRunner
from minushalf.commands import cbm_character
from minushalf.commands.cbm_character import cbm_character


def test_cbm_character_gan_3d(file_path):
Expand All @@ -14,7 +14,9 @@ def test_cbm_character_gan_3d(file_path):
result_path = file_path("/gan-3d/result_cbm_character.txt")
runner = CliRunner()
result = runner.invoke(cbm_character, ['-b', base_path])

print(result.output)
import os
os.system(f"echo {result.output} > a.txt")
with open(result_path) as file:
assert file.read() == result.output

Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_correct_potfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import numpy as np
from click.testing import CliRunner
from minushalf.commands import correct_potfile
from minushalf.commands.correct_potfile import correct_potfile


def test_correct_potfile_ga_first(file_path):
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/test_create_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import os
from click.testing import CliRunner
from minushalf import atomic_program
from minushalf.commands import create_input
from minushalf.data import ElectronicDistribution
from minushalf.io import InputFile
from minushalf.commands.create_input import create_input
from minushalf.data.electronic_distribution import ElectronicDistribution
from minushalf.io.input_file import InputFile


def test_create_input_with_all_elements():
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/test_occupation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pytest
from click.testing import CliRunner
from minushalf import atomic_program
from minushalf.io import InputFile
from minushalf.commands import occupation
from minushalf.io.input_file import InputFile
from minushalf.commands.fractional_occupation import occupation


def test_occupation_with_default_params_O():
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/test_run_atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from unittest import mock
from click.testing import CliRunner
from minushalf import atomic_program
from minushalf.commands import run_atomic
from minushalf.data import ElectronicDistribution
from minushalf.io import InputFile
from minushalf.commands.run_atomic_program import run_atomic
from minushalf.data.electronic_distribution import ElectronicDistribution
from minushalf.io.input_file import InputFile


def test_atomic_run_workflow():
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_vbm_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test vbm character command
"""
from click.testing import CliRunner
from minushalf.commands import vbm_character
from minushalf.commands.vbm_character import vbm_character


def test_vbm_character_gan_3d(file_path):
Expand Down

0 comments on commit 11dc281

Please sign in to comment.