Skip to content

Commit

Permalink
Continued adding parameter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbmorgan committed Nov 21, 2024
1 parent e6d245e commit 2d876f4
Show file tree
Hide file tree
Showing 15 changed files with 1,293 additions and 10 deletions.
22 changes: 18 additions & 4 deletions dfttoolkit/parameters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Literal, Union

import dfttoolkit.utils.file_utils as fu
from dfttoolkit.base_parser import BaseParser
Expand Down Expand Up @@ -75,23 +75,37 @@ def add_keywords(self, **kwargs: dict) -> None:
# TODO finish this
raise NotImplementedError

def remove_keywords(self, *args: str) -> None:
def remove_keywords(
self, *args: str, output: Literal["overwrite", "print", "return"] = "return"
) -> Union[None, List[str]]:
"""
Remove keywords from the control.in file.
Parameters
----------
*args : str
Keywords to be removed from the control.in file.
output : Literal['overwrite', 'print', 'return'], default='overwrite'
Overwrite the original file, print the modified file to STDOUT, or return
the modified file as a list of '\\n' separated strings.
"""

for keyword in args:
for i, line in enumerate(self.lines):
if keyword in line:
self.lines.pop(i)

with open(self.path, "w") as f:
f.writelines(self.lines)
match output:
case "overwrite":
with open(self.path, "w") as f:
f.writelines(self.lines)

case "print":
print(*self.lines, sep="")

case "return":
return self.lines

def get_keywords(self) -> dict:
"""
Expand Down
Empty file removed dfttoolkit/utils/__init__.py
Empty file.
Empty file removed tests/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ def aims_calc_dir(run_aims):
return "custom_bin_aims_calcs"
else:
return "default_aims_calcs"


@pytest.fixture(scope="session")
def tmp_dir(tmp_path_factory):
"""Temporary directory for all tests to write files to"""

d = tmp_path_factory.mktemp("tmp")
return d
145 changes: 145 additions & 0 deletions tests/fixtures/manipulated_aims_files/1/control.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
output_level full
################################################################################
#
# FHI-aims code project
# VB, Fritz-Haber Institut, 2009
#
# Suggested "light" defaults for O atom (to be pasted into control.in file)
# Be sure to double-check any results obtained with these settings for post-processing,
# e.g., with the "tight" defaults and larger basis sets.
#
################################################################################
species O
# global species definitions
nucleus 8
mass 15.9994
#
l_hartree 4
#
cut_pot 3.5 1.5 1.0
basis_dep_cutoff 1e-4
#
radial_base 36 5.0
radial_multiplier 1
angular_grids specified
division 0.2659 50
division 0.4451 110
division 0.6052 194
division 0.7543 302
# division 0.8014 434
# division 0.8507 590
# division 0.8762 770
# division 0.9023 974
# division 1.2339 1202
# outer_grid 974
outer_grid 302
################################################################################
#
# Definition of "minimal" basis
#
################################################################################
# valence basis states
valence 2 s 2.
valence 2 p 4.
# ion occupancy
ion_occ 2 s 1.
ion_occ 2 p 3.
################################################################################
#
# Suggested additional basis functions. For production calculations,
# uncomment them one after another (the most important basis functions are
# listed first).
#
# Constructed for dimers: 1.0 A, 1.208 A, 1.5 A, 2.0 A, 3.0 A
#
################################################################################
# "First tier" - improvements: -699.05 meV to -159.38 meV
hydro 2 p 1.8
hydro 3 d 7.6
hydro 3 s 6.4
# "Second tier" - improvements: -49.91 meV to -5.39 meV
# hydro 4 f 11.6
# hydro 3 p 6.2
# hydro 3 d 5.6
# hydro 5 g 17.6
# hydro 1 s 0.75
# "Third tier" - improvements: -2.83 meV to -0.50 meV
# ionic 2 p auto
# hydro 4 f 10.8
# hydro 4 d 4.7
# hydro 2 s 6.8
# "Fourth tier" - improvements: -0.40 meV to -0.12 meV
# hydro 3 p 5
# hydro 3 s 3.3
# hydro 5 g 15.6
# hydro 4 f 17.6
# hydro 4 d 14
# Further basis functions - -0.08 meV and below
# hydro 3 s 2.1
# hydro 4 d 11.6
# hydro 3 p 16
# hydro 2 s 17.2
################################################################################
#
# FHI-aims code project
# VB, Fritz-Haber Institut, 2009
#
# Suggested "light" defaults for H atom (to be pasted into control.in file)
# Be sure to double-check any results obtained with these settings for post-processing,
# e.g., with the "tight" defaults and larger basis sets.
#
################################################################################
species H
# global species definitions
nucleus 1
mass 1.00794
#
l_hartree 4
#
cut_pot 3.5 1.5 1.0
basis_dep_cutoff 1e-4
#
radial_base 24 5.0
radial_multiplier 1
angular_grids specified
division 0.2421 50
division 0.3822 110
division 0.4799 194
division 0.5341 302
# division 0.5626 434
# division 0.5922 590
# division 0.6542 770
# division 0.6868 1202
# outer_grid 770
outer_grid 302
################################################################################
#
# Definition of "minimal" basis
#
################################################################################
# valence basis states
valence 1 s 1.
# ion occupancy
ion_occ 1 s 0.5
################################################################################
#
# Suggested additional basis functions. For production calculations,
# uncomment them one after another (the most important basis functions are
# listed first).
#
# Basis constructed for dimers: 0.5 A, 0.7 A, 1.0 A, 1.5 A, 2.5 A
#
################################################################################
# "First tier" - improvements: -1014.90 meV to -62.69 meV
hydro 2 s 2.1
hydro 2 p 3.5
# "Second tier" - improvements: -12.89 meV to -1.83 meV
# hydro 1 s 0.85
# hydro 2 p 3.7
# hydro 2 s 1.2
# hydro 3 d 7
# "Third tier" - improvements: -0.25 meV to -0.12 meV
# hydro 4 f 11.2
# hydro 3 p 4.8
# hydro 4 d 9
# hydro 3 s 3.2
88 changes: 88 additions & 0 deletions tests/fixtures/manipulated_aims_files/10/control.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
hse_unit b
################################################################################
#
# FHI-aims code project
# VB, Fritz-Haber Institut, 2009
#
# Suggested "light" defaults for Si atom (to be pasted into control.in file)
# Be sure to double-check any results obtained with these settings for post-processing,
# e.g., with the "tight" defaults and larger basis sets.
#
# 2020/09/08 Added f function to "light" after reinspection of Delta test outcomes.
# This was done for all of Al-Cl and is a tricky decision since it makes
# "light" calculations measurably more expensive for these elements.
# Nevertheless, outcomes for P, S, Cl (and to some extent, Si) appear
# to justify this choice.
#
################################################################################
species Si
# global species definitions
nucleus 14
mass 28.0855
#
l_hartree 4
#
cut_pot 3.5 1.5 1.0
basis_dep_cutoff 1e-4
#
radial_base 42 5.0
radial_multiplier 1
angular_grids specified
division 0.5866 50
division 0.9616 110
division 1.2249 194
division 1.3795 302
# division 1.4810 434
# division 1.5529 590
# division 1.6284 770
# division 1.7077 974
# division 2.4068 1202
# outer_grid 974
outer_grid 302
################################################################################
#
# Definition of "minimal" basis
#
################################################################################
# valence basis states
valence 3 s 2.
valence 3 p 2.
# ion occupancy
ion_occ 3 s 1.
ion_occ 3 p 1.
################################################################################
#
# Suggested additional basis functions. For production calculations,
# uncomment them one after another (the most important basis functions are
# listed first).
#
# Constructed for dimers: 1.75 A, 2.0 A, 2.25 A, 2.75 A, 3.75 A
#
################################################################################
# "First tier" - improvements: -571.96 meV to -37.03 meV
hydro 3 d 4.2
hydro 2 p 1.4
hydro 4 f 6.2
ionic 3 s auto
# "Second tier" - improvements: -16.76 meV to -3.03 meV
# hydro 3 d 9
# hydro 5 g 9.4
# hydro 4 p 4
# hydro 1 s 0.65
# "Third tier" - improvements: -3.89 meV to -0.60 meV
# ionic 3 d auto
# hydro 3 s 2.6
# hydro 4 f 8.4
# hydro 3 d 3.4
# hydro 3 p 7.8
# "Fourth tier" - improvements: -0.33 meV to -0.11 meV
# hydro 2 p 1.6
# hydro 5 g 10.8
# hydro 5 f 11.2
# hydro 3 d 1
# hydro 4 s 4.5
# Further basis functions that fell out of the optimization - noise
# level... < -0.08 meV
# hydro 4 d 6.6
# hydro 5 g 16.4
# hydro 4 d 9
Loading

0 comments on commit 2d876f4

Please sign in to comment.