Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
12 changes: 12 additions & 0 deletions src/koopmans/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Pydantic base model to use throughout `koopmans`."""

from pydantic import BaseModel as _BaseModel
from pydantic import ConfigDict


class BaseModel(_BaseModel):
"""Base model with a modified default configuration."""

model_config = ConfigDict(extra="forbid",
arbitrary_types_allowed=True,
validate_assignment=True)
16 changes: 1 addition & 15 deletions src/koopmans/calculators/_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CalculatorExt(utils.HasDirectory):
ext_in: str = ''
ext_out: str = ''
parent_process: Workflow | None
code: str = ''

def __init__(self, parent_process=None, engine=None, skip_qc: bool = False, **kwargs: Any):
super().__init__(parent_process=parent_process, engine=engine)
Expand Down Expand Up @@ -205,9 +206,6 @@ def _pre_calculate(self):
if self.directory.exists():
utils.remove(self.directory)

# By default, check the corresponding program is installed
self.check_code_is_installed()

# Copy over all files linked to this calculation
self._fetch_linked_files()

Expand Down Expand Up @@ -249,18 +247,6 @@ def read_input(self, input_file: Optional[Path] = None):
self.atoms = calc.atoms
self.atoms.calc = self

def check_code_is_installed(self):
"""Check that the corresponding code is installed."""
if self.command.path == Path():
executable_with_path = utils.find_executable(self.command.executable)
if executable_with_path is None:
raise OSError(f'`{self.command.executable}` is not installed')
self.command.path = executable_with_path.parent
else:
if not (self.command.path / self.command.executable).is_file():
raise OSError(f'`{self.command.executable}` is not installed')
return

def write_alphas(self):
"""Write the screening parameters to a file."""
raise NotImplementedError(
Expand Down
6 changes: 1 addition & 5 deletions src/koopmans/calculators/_koopmans_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import copy
import math
import os
import pickle
import xml.etree.ElementTree as ET
from pathlib import Path
Expand All @@ -18,7 +17,6 @@

from koopmans import bands, pseudopotentials, settings, utils
from koopmans.cell import cell_follows_qe_conventions, cell_to_parameters
from koopmans.commands import ParallelCommand
from koopmans.files import File

from ._calculator import (CalculatorABC, CalculatorCanEnforceSpinSym,
Expand Down Expand Up @@ -82,6 +80,7 @@ class KoopmansCPCalculator(CalculatorCanEnforceSpinSym, CalculatorExt, Espresso_

ext_in = '.cpi'
ext_out = '.cpo'
code = 'kcp'

def __init__(self, atoms: Atoms, alphas: Optional[List[List[float]]] = None,
filling: Optional[List[List[bool]]] = None, **kwargs):
Expand All @@ -104,9 +103,6 @@ def __init__(self, atoms: Atoms, alphas: Optional[List[List[float]]] = None,
if 'neldw' not in self.parameters:
self.parameters.neldw = self.parameters.nelec // 2

if not isinstance(self.command, ParallelCommand):
self.command = ParallelCommand(os.environ.get('ASE_ESPRESSO_KCP_COMMAND', self.command))

if alphas is not None:
self.alphas = alphas
if filling is not None:
Expand Down
4 changes: 1 addition & 3 deletions src/koopmans/calculators/_koopmans_ham.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from ase_koopmans.dft.kpoints import BandPath

from koopmans import settings, utils
from koopmans.commands import ParallelCommand

from ._calculator import CalculatorABC, KCWannCalculator, ReturnsBandStructure

Expand All @@ -18,6 +17,7 @@ class KoopmansHamCalculator(KCWannCalculator, KoopmansHam, ReturnsBandStructure,

ext_in = '.khi'
ext_out = '.kho'
code = "kcw_ham"

def __init__(self, atoms: Atoms, alphas: Optional[List[float]] = None, *args, **kwargs):
# Define the valid settings
Expand All @@ -27,8 +27,6 @@ def __init__(self, atoms: Atoms, alphas: Optional[List[float]] = None, *args, **
KoopmansHam.__init__(self, atoms=atoms)
KCWannCalculator.__init__(self, *args, **kwargs)

self.command = ParallelCommand(f'kcw.x -in PREFIX{self.ext_in} > PREFIX{self.ext_out} 2>&1')

# Store the alphas
self.alphas = alphas

Expand Down
4 changes: 1 addition & 3 deletions src/koopmans/calculators/_koopmans_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ase_koopmans.calculators.espresso import KoopmansScreen

from koopmans import settings, utils
from koopmans.commands import ParallelCommandWithPostfix

from ._calculator import CalculatorABC, KCWannCalculator

Expand All @@ -15,6 +14,7 @@ class KoopmansScreenCalculator(KCWannCalculator, KoopmansScreen, CalculatorABC):

ext_in = '.ksi'
ext_out = '.kso'
code = "kcw_screen"

def __init__(self, atoms: Atoms, *args, **kwargs):
# Define the valid settings
Expand All @@ -25,8 +25,6 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
KCWannCalculator.__init__(self, *args, **kwargs)
super().__init__(*args, **kwargs)

self.command = ParallelCommandWithPostfix(f'kcw.x -in PREFIX{self.ext_in} > PREFIX{self.ext_out} 2>&1')

def _pre_calculate(self):
# Check eps infinity
kpoints = [self.parameters.mp1, self.parameters.mp2, self.parameters.mp3]
Expand Down
4 changes: 1 addition & 3 deletions src/koopmans/calculators/_ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from ase_koopmans import Atoms
from ase_koopmans.calculators.espresso import EspressoPh

from koopmans.commands import ParallelCommand
from koopmans.settings import PhSettingsDict

from ._calculator import CalculatorABC, CalculatorExt
Expand All @@ -15,6 +14,7 @@ class PhCalculator(CalculatorExt, EspressoPh, CalculatorABC):

ext_in = '.phi'
ext_out = '.pho'
code = "ph"

def __init__(self, atoms: Atoms, *args, **kwargs):
self.parameters = PhSettingsDict()
Expand All @@ -24,8 +24,6 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
EspressoPh.__init__(self, atoms=atoms)
CalculatorExt.__init__(self, *args, **kwargs)

self.command = ParallelCommand(f'ph.x -in PREFIX{self.ext_in} > PREFIX{self.ext_out} 2>&1')

def is_converged(self):
"""Return True; a ph calculation is never not "converged"."""
return True
Expand Down
6 changes: 1 addition & 5 deletions src/koopmans/calculators/_projwfc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""projwfc.x calculator module for koopmans."""

import copy
import os
import re
from pathlib import Path
from typing import Dict, List, Optional
Expand All @@ -14,7 +13,6 @@
from upf_tools import UPFDict

from koopmans import pseudopotentials
from koopmans.commands import Command, ParallelCommand
from koopmans.files import File
from koopmans.settings import ProjwfcSettingsDict

Expand All @@ -26,6 +24,7 @@ class ProjwfcCalculator(CalculatorExt, Projwfc, CalculatorABC):

ext_in = '.pri'
ext_out = '.pro'
code = "projwfc"

def __init__(self, atoms: Atoms, *args, **kwargs):
# Define the valid settings
Expand All @@ -36,9 +35,6 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
Projwfc.__init__(self, atoms=atoms)
CalculatorExt.__init__(self, *args, **kwargs)

if not isinstance(self.command, Command):
self.command = ParallelCommand(os.environ.get('ASE_PROJWFC_COMMAND', self.command))

# We need pseudopotentials and pseudo dir in order to work out the number of valence electrons for each
# element, and therefore what pDOS files to expect. We also need spin-polarized to know if the pDOS files will
# contain columns for each spin channel
Expand Down
8 changes: 1 addition & 7 deletions src/koopmans/calculators/_pw.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"""pw calculator module for koopmans."""

import os

import numpy as np
from ase_koopmans import Atoms
from ase_koopmans.calculators.espresso import Espresso
from ase_koopmans.dft.kpoints import BandPath

from koopmans.cell import cell_follows_qe_conventions, cell_to_parameters
from koopmans.commands import Command, ParallelCommandWithPostfix
from koopmans.settings import PWSettingsDict

from ._calculator import CalculatorABC, CalculatorExt, ReturnsBandStructure
Expand All @@ -19,6 +16,7 @@ class PWCalculator(CalculatorExt, Espresso, ReturnsBandStructure, CalculatorABC)

ext_in = '.pwi'
ext_out = '.pwo'
code = "pw"

def __init__(self, atoms: Atoms, *args, **kwargs):
# Define the valid settings
Expand All @@ -28,10 +26,6 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
Espresso.__init__(self, atoms=atoms)
CalculatorExt.__init__(self, *args, **kwargs)

if not isinstance(self.command, Command):
self.command = ParallelCommandWithPostfix(os.environ.get(
'ASE_ESPRESSO_COMMAND', self.command))

def _pre_calculate(self):
# Update ibrav and celldms
if cell_follows_qe_conventions(self.atoms.cell):
Expand Down
6 changes: 1 addition & 5 deletions src/koopmans/calculators/_pw2wannier.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""pw2wannier calculator module for koopmans."""

import os

from ase_koopmans import Atoms
from ase_koopmans.calculators.espresso import PW2Wannier

from koopmans.commands import ParallelCommand
from koopmans.settings import PW2WannierSettingsDict

from ._calculator import CalculatorABC, CalculatorExt
Expand All @@ -16,6 +13,7 @@ class PW2WannierCalculator(CalculatorExt, PW2Wannier, CalculatorABC):

ext_in = '.p2wi'
ext_out = '.p2wo'
code = "pw2wannier90"

def __init__(self, atoms: Atoms, *args, **kwargs):
self.parameters = PW2WannierSettingsDict()
Expand All @@ -24,8 +22,6 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
PW2Wannier.__init__(self, atoms=atoms)
CalculatorExt.__init__(self, *args, **kwargs)

self.command = ParallelCommand(os.environ.get('ASE_PW2WANNIER_COMMAND', self.command))

def is_converged(self):
"""Return True; a PW2Wannier calculation is never not "converged"."""
return True
Expand Down
4 changes: 1 addition & 3 deletions src/koopmans/calculators/_wann2kc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ase_koopmans import Atoms
from ase_koopmans.calculators.espresso import Wann2KC

from koopmans.commands import ParallelCommandWithPostfix
from koopmans.settings import Wann2KCSettingsDict

from ._calculator import CalculatorABC, KCWannCalculator
Expand All @@ -14,6 +13,7 @@ class Wann2KCCalculator(KCWannCalculator, Wann2KC, CalculatorABC):

ext_in = '.w2ki'
ext_out = '.w2ko'
code = "kcw_wannier"

def __init__(self, atoms: Atoms, *args, **kwargs):
# Define the valid settings
Expand All @@ -23,8 +23,6 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
Wann2KC.__init__(self, atoms=atoms)
KCWannCalculator.__init__(self, *args, **kwargs)

self.command = ParallelCommandWithPostfix(f'kcw.x -in PREFIX{self.ext_in} > PREFIX{self.ext_out} 2>&1')

def is_converged(self):
"""Return True; a Wann2KC calculation is never not "converged"."""
return True
Expand Down
6 changes: 1 addition & 5 deletions src/koopmans/calculators/_wann2kcp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""wann2kcp calculator module for koopmans."""

import os

from ase_koopmans import Atoms
from ase_koopmans.calculators.espresso import Wann2KCP

from koopmans.commands import ParallelCommand
from koopmans.settings import Wann2KCPSettingsDict

from ._calculator import CalculatorABC, CalculatorExt
Expand All @@ -16,6 +13,7 @@ class Wann2KCPCalculator(CalculatorExt, Wann2KCP, CalculatorABC):

ext_in = '.wki'
ext_out = '.wko'
code = "wann2kcp"

def __init__(self, atoms: Atoms, *args, **kwargs):
self.parameters = Wann2KCPSettingsDict()
Expand All @@ -24,8 +22,6 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
Wann2KCP.__init__(self, atoms=atoms)
CalculatorExt.__init__(self, *args, **kwargs)

self.command = ParallelCommand(os.environ.get('ASE_WANN2KCP_COMMAND', self.command))

def is_converged(self):
"""Return True; a Wann2KCP calculation is never not "converged"."""
return True
Expand Down
7 changes: 1 addition & 6 deletions src/koopmans/calculators/_wannier90.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""wannier90 calculator module for koopmans."""

import os

from ase_koopmans import Atoms
from ase_koopmans.calculators.wannier90 import Wannier90

from koopmans.commands import Command
from koopmans.settings import Wannier90SettingsDict
from koopmans.utils import CalculatorNotConvergedWarning, warn

Expand All @@ -17,6 +14,7 @@ class Wannier90Calculator(CalculatorExt, Wannier90, CalculatorABC):

ext_in = '.win'
ext_out = '.wout'
code = "wannier90"

def __init__(self, atoms: Atoms, *args, **kwargs):
# Define the list of parameters
Expand All @@ -26,9 +24,6 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
Wannier90.__init__(self, atoms=atoms)
CalculatorExt.__init__(self, *args, **kwargs)

# Set up the command for running this calculator
self.command = Command(os.environ.get('ASE_WANNIER90_COMMAND', self.command))

def is_converged(self):
"""Return True if the calculation is converged."""
return self.results['convergence']
Expand Down
Loading