Skip to content

Commit

Permalink
Beginning to tweak tests to work with new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
elinscott committed Jul 31, 2024
1 parent 9373f05 commit 8e6caa8
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/koopmans/calculators/_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def directory(self) -> Path:

@directory.setter
def directory(self, value: Path | str | None):
if value is None or value in ['', '.', 'None']:
if value is None or value == 'None':
return
if not isinstance(value, Path):
value = Path(value)
Expand Down
6 changes: 6 additions & 0 deletions src/koopmans/calculators/_koopmans_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,17 @@ def convert_wavefunction_1to2(self):
@property
def read_directory(self) -> Path:
assert isinstance(self.parameters.outdir, Path)
assert self.parameters.ndr is not None
assert self.parameters.prefix is not None
assert self.parameters.outdir is not None
return self.parameters.outdir / f'{self.parameters.prefix}_{self.parameters.ndr}.save'

@property
def write_directory(self):
assert isinstance(self.parameters.outdir, Path)
assert self.parameters.ndw is not None
assert self.parameters.prefix is not None
assert self.parameters.outdir is not None
return self.parameters.outdir / f'{self.parameters.prefix}_{self.parameters.ndw}.save'


Expand Down
18 changes: 9 additions & 9 deletions tests/calculators/test_koopmans_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from hypothesis import given
from hypothesis import strategies as st

from koopmans import settings, utils, workflows
from koopmans.calculators._koopmans_cp import (allowed,
from koopmans import settings, utils
from koopmans.calculators._koopmans_cp import (KoopmansCPCalculator, allowed,
convert_flat_alphas_for_kcp,
good_fft)

Expand All @@ -32,9 +32,9 @@ def test_convert_flat_alphas_for_kcp():

def test_read_write_ham_pkl(water, tmp_path):
with utils.chdir(tmp_path):
# Create a kcp calculator to match the one that was used to generate the pdos files
wf = workflows.KoopmansDSCFWorkflow(**water)
calc = wf.new_kcp_calculator('ki_final')
# Create a kcp calculator
calc = KoopmansCPCalculator(outdir='tmp', nspin=2, **water)
calc.directory = '.'

# generate a random array for our "Hamiltonian", making sure to set the random seed in order to always
# generate the same random array
Expand All @@ -52,12 +52,12 @@ def test_read_write_ham_pkl(water, tmp_path):

def test_read_ham(water, datadir, tmp_path):
with utils.chdir(tmp_path):
# Create a kcp calculator to match the one that was used to generate the pdos files
wf = workflows.KoopmansDSCFWorkflow(**water)
calc = wf.new_kcp_calculator('ki_final')
# Create a kcp calculator
calc = KoopmansCPCalculator(outdir='tmp', nspin=2, nelec=8, ndw=50, prefix='test_read_ham', **water)
calc.directory = '.'

# Copy over the XML Hamiltonian files
destdir = calc.parameters.outdir / f'{calc.parameters.prefix}_{calc.parameters.ndw}.save' / 'K00001'
destdir = calc.write_directory / 'K00001'
destdir.mkdir(parents=True)
for f in (datadir / 'kcp').glob('ham*'):
shutil.copy(f, destdir)
Expand Down
11 changes: 8 additions & 3 deletions tests/calculators/test_projwfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ def test_generate_dos(silicon, tmp_path, datadir, pytestconfig):
wf = workflows.DFTBandsWorkflow(
parameters={'pseudo_library': 'pseudo_dojo_standard', 'base_functional': 'pbesol', 'from_scratch': True},
name='si', **silicon)

calc = wf.new_calculator('projwfc')
calc.pseudo_dir = Path(koopmans_src[0]) / 'pseudopotentials/pseudo_dojo_standard_v0.4.1/pbesol'

# Make sure the pseudopotential files exist where the calculator will expect them to be
pseudo_dir = calc.directory / calc.parameters.outdir / (calc.parameters.prefix + '.save')
pseudo_dir.mkdir(parents=True)
assert wf.parameters.pseudo_directory is not None
for psp in wf.pseudopotentials.values():
utils.copy(wf.parameters.pseudo_directory / psp, pseudo_dir)

# Copy over pdos files
for f in (datadir / 'projwfc').glob('*.pdos*'):
shutil.copy(f, f.name)
utils.copy(f, f.name)

# Attempt to read pdos files
calc.generate_dos()
Expand Down
2 changes: 1 addition & 1 deletion tests/data/kcp/ki_final.cpi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
verbosity = 'low'
restart_mode = 'restart'
iprint = 1
outdir = '/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_h2o_ki_dscf_e0/TMP-CP/'
outdir = 'TMP-CP/'
prefix = 'kc'
disk_io = 'high'
pseudo_dir = '/home/elinscott/code/koopmans/src/koopmans/pseudopotentials/sg15_v1.2/pbe/'
Expand Down
2 changes: 1 addition & 1 deletion tests/data/kcw/kc.khi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
&CONTROL
prefix = 'kc'
outdir = '/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/TMP/'
outdir = 'TMP/'
kcw_iverbosity = 1
kcw_at_ks = .false.
calculation = 'ham'
Expand Down
2 changes: 1 addition & 1 deletion tests/data/kcw/kc.ksi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
&CONTROL
prefix = 'kc'
outdir = '/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/TMP/'
outdir = 'TMP/'
kcw_iverbosity = 1
kcw_at_ks = .false.
calculation = 'screen'
Expand Down
2 changes: 1 addition & 1 deletion tests/data/kcw/kc.w2ki
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
&CONTROL
prefix = 'kc'
outdir = '/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/TMP/'
outdir = 'TMP/'
kcw_iverbosity = 1
kcw_at_ks = .false.
calculation = 'wann2kcw'
Expand Down
4 changes: 2 additions & 2 deletions tests/data/ph/eps.phi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
&inputph
outdir = '/home/elinscott/code/koopmans/tests/tmp/test_dftph_tio20/TMP'
outdir = 'TMP'
prefix = 'kc'
epsil = .true.
tr2_ph = 1e-14
fildyn = 'tio2.dynG'
amass(1) = 15.999
amass(2) = 47.867
/
0.0 0.0 0.0
0.0 0.0 0.0
2 changes: 1 addition & 1 deletion tests/data/pw/scf.pwi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
&CONTROL
calculation = 'scf'
verbosity = 'high'
outdir = '/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/wannier/TMP/'
outdir = 'wannier/TMP/'
prefix = 'kc'
pseudo_dir = '/home/elinscott/code/koopmans/src/koopmans/pseudopotentials/sg15_v1.2/pbe/'
/
Expand Down
2 changes: 1 addition & 1 deletion tests/data/pw2wannier/pw2wan.p2wi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
&inputpp
outdir = '/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/wannier/TMP'
outdir = 'wannier/TMP'
prefix = 'kc'
seedname = 'wann'
wan_mode = 'standalone'
Expand Down
8 changes: 4 additions & 4 deletions tests/data/ui/ki.uii
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
2
],
"do_dos": true,
"kc_ham_file": "/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/hamiltonian/kc.kcw_hr_occ.dat",
"w90_seedname": "/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/wannier/occ/wann",
"dft_smooth_ham_file": "/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/postproc/wannier/occ/wann_hr.dat",
"dft_ham_file": "/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_si_ki_dfpt_ex0/wannier/occ/wann_hr.dat"
"kc_ham_file": "hamiltonian/kc.kcw_hr_occ.dat",
"w90_seedname": "wannier/occ/wann",
"dft_smooth_ham_file": "postproc/wannier/occ/wann_hr.dat",
"dft_ham_file": "wannier/occ/wann_hr.dat"
},
"kpoints": {
"grid": [
Expand Down
2 changes: 1 addition & 1 deletion tests/data/wann2kcp/w2kcp.wki
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
&inputpp
outdir = '/home/elinscott/code/koopmans/tests/tmp/test_singlepoint_gaas_wan2odd0/init/wannier/TMP'
outdir = 'init/wannier/TMP'
prefix = 'kc'
seedname = 'wann'
wan_mode = 'wannier2kcp'
Expand Down
11 changes: 4 additions & 7 deletions tests/helpers/patches/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@
BenchGenMLFittingWorkflow, BenchGenPhCalculator,
BenchGenProjwfcCalculator,
BenchGenPW2WannierCalculator, BenchGenPWCalculator,
BenchGenUnfoldAndInterpolateCalculator,
BenchGenWann2KCCalculator, BenchGenWann2KCPCalculator,
BenchGenWannier90Calculator)
from ._check import (CheckEnvironCalculator, CheckKoopmansCPCalculator,
CheckKoopmansHamCalculator, CheckKoopmansScreenCalculator,
CheckMLFittingWorkflow, CheckPhCalculator,
CheckProjwfcCalculator, CheckPW2WannierCalculator,
CheckPWCalculator, CheckUnfoldAndInterpolateCalculator,
CheckWann2KCCalculator, CheckWann2KCPCalculator,
CheckWannier90Calculator)
CheckPWCalculator, CheckWann2KCCalculator,
CheckWann2KCPCalculator, CheckWannier90Calculator)
from ._mock import (MockEnvironCalculator, MockKoopmansCPCalculator,
MockKoopmansDSCFWorkflow, MockKoopmansHamCalculator,
MockKoopmansScreenCalculator, MockMLFittingWorkflow,
MockPhCalculator, MockProjwfcCalculator,
MockPW2WannierCalculator, MockPWCalculator,
MockUnfoldAndInterpolateCalculator, MockWann2KCCalculator,
MockWann2KCPCalculator, MockWannier90Calculator,
MockWannierizeWorkflow)
MockWann2KCCalculator, MockWann2KCPCalculator,
MockWannier90Calculator, MockWannierizeWorkflow)
from ._stumble import (StumblingConvergenceMLWorkflow,
StumblingConvergenceWorkflow, StumblingDeltaSCFWorkflow,
StumblingDFTCPWorkflow, StumblingDFTPhWorkflow,
Expand Down
9 changes: 2 additions & 7 deletions tests/helpers/patches/_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
KoopmansHamCalculator,
KoopmansScreenCalculator, PhCalculator,
ProjwfcCalculator, PW2WannierCalculator,
PWCalculator, UnfoldAndInterpolateCalculator,
Wann2KCCalculator, Wann2KCPCalculator,
Wannier90Calculator)
PWCalculator, Wann2KCCalculator,
Wann2KCPCalculator, Wannier90Calculator)
from koopmans.io import write_kwf as write_encoded_json
from koopmans.workflows import MLFittingWorkflow

Expand Down Expand Up @@ -102,10 +101,6 @@ class BenchGenEnvironCalculator(BenchmarkGenCalc, EnvironCalculator):
pass


class BenchGenUnfoldAndInterpolateCalculator(BenchmarkGenCalc, UnfoldAndInterpolateCalculator):
pass


class BenchGenWann2KCCalculator(BenchmarkGenCalc, Wann2KCCalculator):
pass

Expand Down
10 changes: 2 additions & 8 deletions tests/helpers/patches/_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
KoopmansCPCalculator, KoopmansHamCalculator,
KoopmansScreenCalculator, PhCalculator,
ProjwfcCalculator, PW2WannierCalculator,
PWCalculator, UnfoldAndInterpolateCalculator,
Wann2KCCalculator, Wann2KCPCalculator,
Wannier90Calculator)
PWCalculator, Wann2KCCalculator,
Wann2KCPCalculator, Wannier90Calculator)
from koopmans.io import read_kwf as read_encoded_json
from koopmans.workflows import MLFittingWorkflow

Expand Down Expand Up @@ -331,11 +330,6 @@ class CheckWann2KCPCalculator(CheckCalc, Wann2KCPCalculator):
pass


class CheckUnfoldAndInterpolateCalculator(CheckCalc, UnfoldAndInterpolateCalculator):
results_for_qc = ['band structure', 'dos']
pass


class CheckWann2KCCalculator(CheckCalc, Wann2KCCalculator):
results_for_qc: List[str] = []
pass
Expand Down
11 changes: 2 additions & 9 deletions tests/helpers/patches/_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
KoopmansCPCalculator, KoopmansHamCalculator,
KoopmansScreenCalculator, PhCalculator,
ProjwfcCalculator, PW2WannierCalculator,
PWCalculator, UnfoldAndInterpolateCalculator,
Wann2KCCalculator, Wann2KCPCalculator,
Wannier90Calculator)
PWCalculator, Wann2KCCalculator,
Wann2KCPCalculator, Wannier90Calculator)
from koopmans.io import read_kwf as read_encoded_json
from koopmans.workflows import (ConvergenceMLWorkflow, KoopmansDSCFWorkflow,
MLFittingWorkflow, WannierizeWorkflow)
Expand Down Expand Up @@ -150,12 +149,6 @@ class MockWann2KCPCalculator(MockCalc, Wann2KCPCalculator):
pass


class MockUnfoldAndInterpolateCalculator(MockCalc, UnfoldAndInterpolateCalculator):
def write_results(self, *args, **kwargs):
# Do nothing when it goes to write out the results (because this relies on self.bg, among others)
return


class MockWann2KCCalculator(MockCalc, Wann2KCCalculator):
pass

Expand Down
5 changes: 3 additions & 2 deletions tests/helpers/patches/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
def benchmark_filename(calc: calculators.CalculatorExt) -> Path:
base_directory = Path(__file__).parents[3]
benchmark_dir = base_directory / 'tests' / 'benchmarks'
if base_directory / 'tests' / 'tmp' in calc.directory.parents:
abs_calc_directory = calc.directory.resolve()
if base_directory / 'tests' / 'tmp' in abs_calc_directory.parents:
parent = base_directory / 'tests' / 'tmp'
else:
parent = base_directory
benchmark_name = calc.directory.relative_to(parent) / calc.prefix
benchmark_name = abs_calc_directory.relative_to(parent) / calc.prefix
return benchmark_dir / (str(benchmark_name).replace(os.path.sep, '-') + '.json')


Expand Down
2 changes: 0 additions & 2 deletions tests/io/test_io_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
KoopmansHamCalculator,
KoopmansScreenCalculator, PhCalculator,
PW2WannierCalculator, PWCalculator,
UnfoldAndInterpolateCalculator,
Wann2KCCalculator, Wann2KCPCalculator,
Wannier90Calculator)
from koopmans.io._calculators import read_calculator
Expand All @@ -21,7 +20,6 @@
PW2WannierCalculator: 'pw2wannier/pw2wan',
PhCalculator: 'ph/eps',
PWCalculator: 'pw/scf',
UnfoldAndInterpolateCalculator: 'ui/ki',
Wann2KCCalculator: ['kcw/kc.w2ki', 'kcw/kc.w2ko'],
Wann2KCPCalculator: 'wann2kcp/w2kcp',
Wannier90Calculator: 'w90/wann'}
Expand Down
Empty file added tests/processes/test_ui.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import numpy as np
import pytest

from koopmans.processes.wannier import merge_wannier_hr_file_contents
from koopmans.utils import (chdir, parse_wannier_hr_file_contents,
read_wannier_hr_file)
from koopmans.workflows._merge_wannier import merge_wannier_hr_file_contents


def test_wannierize_merge_hr_file_contents(tmp_path, datadir):
Expand Down

0 comments on commit 8e6caa8

Please sign in to comment.