From 2d876f405c61afd92a569bc21e4cc0ebf04bdf10 Mon Sep 17 00:00:00 2001 From: Dylan Morgan Date: Thu, 21 Nov 2024 01:37:28 +0000 Subject: [PATCH] Continued adding parameter tests --- dfttoolkit/parameters.py | 22 ++- dfttoolkit/utils/__init__.py | 0 tests/__init__.py | 0 tests/conftest.py | 8 + .../manipulated_aims_files/1/control.in | 145 +++++++++++++++++ .../manipulated_aims_files/10/control.in | 88 +++++++++++ .../manipulated_aims_files/2/control.in | 147 +++++++++++++++++ .../manipulated_aims_files/3/control.in | 148 ++++++++++++++++++ .../manipulated_aims_files/4/control.in | 87 ++++++++++ .../manipulated_aims_files/5/control.in | 144 +++++++++++++++++ .../manipulated_aims_files/6/control.in | 88 +++++++++++ .../manipulated_aims_files/7/control.in | 148 ++++++++++++++++++ .../manipulated_aims_files/8/control.in | 92 +++++++++++ .../manipulated_aims_files/9/control.in | 145 +++++++++++++++++ tests/test_parameters.py | 41 ++++- 15 files changed, 1293 insertions(+), 10 deletions(-) delete mode 100644 dfttoolkit/utils/__init__.py delete mode 100644 tests/__init__.py create mode 100644 tests/fixtures/manipulated_aims_files/1/control.in create mode 100644 tests/fixtures/manipulated_aims_files/10/control.in create mode 100644 tests/fixtures/manipulated_aims_files/2/control.in create mode 100644 tests/fixtures/manipulated_aims_files/3/control.in create mode 100644 tests/fixtures/manipulated_aims_files/4/control.in create mode 100644 tests/fixtures/manipulated_aims_files/5/control.in create mode 100644 tests/fixtures/manipulated_aims_files/6/control.in create mode 100644 tests/fixtures/manipulated_aims_files/7/control.in create mode 100644 tests/fixtures/manipulated_aims_files/8/control.in create mode 100644 tests/fixtures/manipulated_aims_files/9/control.in diff --git a/dfttoolkit/parameters.py b/dfttoolkit/parameters.py index 7e73993..d919dd5 100644 --- a/dfttoolkit/parameters.py +++ b/dfttoolkit/parameters.py @@ -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 @@ -75,7 +75,9 @@ 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. @@ -83,6 +85,10 @@ def remove_keywords(self, *args: str) -> None: ---------- *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: @@ -90,8 +96,16 @@ def remove_keywords(self, *args: str) -> None: 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: """ diff --git a/dfttoolkit/utils/__init__.py b/dfttoolkit/utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/conftest.py b/tests/conftest.py index 61840ff..cbe9132 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/fixtures/manipulated_aims_files/1/control.in b/tests/fixtures/manipulated_aims_files/1/control.in new file mode 100644 index 0000000..e6e1181 --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/1/control.in @@ -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 diff --git a/tests/fixtures/manipulated_aims_files/10/control.in b/tests/fixtures/manipulated_aims_files/10/control.in new file mode 100644 index 0000000..1c60dd8 --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/10/control.in @@ -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 diff --git a/tests/fixtures/manipulated_aims_files/2/control.in b/tests/fixtures/manipulated_aims_files/2/control.in new file mode 100644 index 0000000..12bd563 --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/2/control.in @@ -0,0 +1,147 @@ +spin collinear +default_initial_moment 1 +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 diff --git a/tests/fixtures/manipulated_aims_files/3/control.in b/tests/fixtures/manipulated_aims_files/3/control.in new file mode 100644 index 0000000..7d015f1 --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/3/control.in @@ -0,0 +1,148 @@ +spin collinear +default_initial_moment 1 +include_spin_orbit non_self_consistent +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 diff --git a/tests/fixtures/manipulated_aims_files/4/control.in b/tests/fixtures/manipulated_aims_files/4/control.in new file mode 100644 index 0000000..d00339a --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/4/control.in @@ -0,0 +1,87 @@ +################################################################################ +# +# 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 diff --git a/tests/fixtures/manipulated_aims_files/5/control.in b/tests/fixtures/manipulated_aims_files/5/control.in new file mode 100644 index 0000000..286b7b1 --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/5/control.in @@ -0,0 +1,144 @@ +################################################################################ +# +# 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 diff --git a/tests/fixtures/manipulated_aims_files/6/control.in b/tests/fixtures/manipulated_aims_files/6/control.in new file mode 100644 index 0000000..330436c --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/6/control.in @@ -0,0 +1,88 @@ +relax_unit_cell full +################################################################################ +# +# 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 diff --git a/tests/fixtures/manipulated_aims_files/7/control.in b/tests/fixtures/manipulated_aims_files/7/control.in new file mode 100644 index 0000000..fe0b9f0 --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/7/control.in @@ -0,0 +1,148 @@ +sc_accuracy_rho 1e-10 +sc_accuracy_eev 1e-6 +sc_accuracy_etot 1e-12 +sc_accuracy_forces 1e-8 +################################################################################ +# +# 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 diff --git a/tests/fixtures/manipulated_aims_files/8/control.in b/tests/fixtures/manipulated_aims_files/8/control.in new file mode 100644 index 0000000..287e2e9 --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/8/control.in @@ -0,0 +1,92 @@ +sc_iter_limit 10 +sc_accuracy_rho 1e-10 +sc_accuracy_eev 1e-6 +sc_accuracy_etot 1e-12 +sc_accuracy_forces 1e-8 +################################################################################ +# +# 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 diff --git a/tests/fixtures/manipulated_aims_files/9/control.in b/tests/fixtures/manipulated_aims_files/9/control.in new file mode 100644 index 0000000..3dd43b6 --- /dev/null +++ b/tests/fixtures/manipulated_aims_files/9/control.in @@ -0,0 +1,145 @@ +hse_unit b +################################################################################ +# +# 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 diff --git a/tests/test_parameters.py b/tests/test_parameters.py index 48c8d05..5f85a89 100644 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -1,18 +1,47 @@ import os +import shutil import pytest from dfttoolkit.parameters import AimsControl -# TODO Create generic test class with functions for all tests to inherit - - class TestAimsControl: @pytest.fixture(params=range(1, 11), autouse=True) def aims_control(self, request, aims_calc_dir): - - cwd = os.path.dirname(os.path.realpath(__file__)) + self.cwd = os.path.dirname(os.path.realpath(__file__)) self.ac = AimsControl( - control_in=f"{cwd}/fixtures/{aims_calc_dir}/{str(request.param)}/control.in" + control_in=f"{self.cwd}/fixtures/{aims_calc_dir}/{str(request.param)}" + "/control.in" ) + + # Read reference + with open( + f"{self.cwd}/fixtures/manipulated_aims_files/{str(request.param)}" + "/control.in", + "r", + ) as f: + self.removed_keywords_control_ref = f.readlines() + + @property + def _aims_fixture_no(self) -> int: + return int(self.ac.path.split("/")[-2]) + + def test_remove_keywords_overwrite(self, tmp_dir): + control_path = tmp_dir / "control.in" + shutil.copy(self.ac.path, control_path) + ac = AimsControl(control_in=str(control_path)) + ac.remove_keywords("xc", "relax_geometry", "k_grid", output="overwrite") + + assert "".join(self.removed_keywords_control_ref) == control_path.read_text() + + def test_remove_keywords_print(self, capfd): + self.ac.remove_keywords("xc", "relax_geometry", "k_grid", output="print") + + out, err = capfd.readouterr() + + # print(out) + # print("".join(self.removed_keywords_control_ref)) + + assert out == print("".join(self.removed_keywords_control_ref)) + assert err == ""