• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

maurergroup / dfttoolkit / 12448697655

21 Dec 2024 09:47PM UTC coverage: 24.863% (+3.1%) from 21.747%
12448697655

push

github

a7cc32
web-flow
Merge pull request #24 from maurergroup/dependabot/pip/sphinx-8.1.3

Bump sphinx from 7.4.7 to 8.1.3

773 of 3109 relevant lines covered (24.86%)

0.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.49
dfttoolkit/parameters.py
1
from typing import List, Literal, Union
1✔
2

3
import dfttoolkit.utils.file_utils as fu
1✔
4
from dfttoolkit.base_parser import BaseParser
1✔
5

6

7
class Parameters(BaseParser):
1✔
8
    """
9
    Handle files that control parameters for electronic structure calculations.
10

11
    If contributing a new parser, please subclass this class, add the new supported file
12
    type to _supported_files, call the super().__init__ method, include the new file
13
    type as a kwarg in the super().__init__ call. Optionally include the self.lines line
14
    in examples.
15

16
    ...
17

18
    Attributes
19
    ----------
20
    _supported_files : list
21
        List of supported file types.
22
    """
23

24
    def __init__(self, **kwargs: str):
1✔
25
        # FHI-aims, ...
26
        self._supported_files = ["control_in"]
1✔
27

28
        # Check that only supported files were provided
29
        for val in kwargs.keys():
1✔
30
            fu.check_required_files(self._supported_files, val)
1✔
31

32
        super().__init__(self._supported_files, **kwargs)
1✔
33

34
    @property
1✔
35
    def supported_files(self) -> List[str]:
1✔
36
        return self._supported_files
1✔
37

38

39
class AimsControl(Parameters):
1✔
40
    """
41
    FHI-aims control file parser.
42

43
    ...
44

45
    Attributes
46
    ----------
47
    lines : List[str]
48
        The contents of the control.in file.
49
    path : str
50
        The path to the control.in file.
51
    """
52

53
    def __init__(self, control_in: str = "control.in", parse_file: bool = True):
1✔
54
        if parse_file:
1✔
55
            super().__init__(control_in=control_in)
1✔
56
            self.lines = self.file_contents["control_in"]
1✔
57
            self.path = self.file_paths["control_in"]
1✔
58

59
            # Check if the control.in file was provided
60
            fu.check_required_files(self._supported_files, "control_in")
1✔
61

62
    def add_keywords(self, **kwargs: dict) -> None:
1✔
63
        """
64
        Add keywords to the control.in file.
65

66
        Parameters
67
        ----------
68
        **kwargs : dict
69
            Keywords to be added to the control.in file.
70
        """
71

72
        for keyword in kwargs:
×
73
            self.lines.append(keyword + "\n")
×
74

75
        # TODO finish this
76
        raise NotImplementedError
×
77

78
    def remove_keywords(
1✔
79
        self, *args: str, output: Literal["overwrite", "print", "return"] = "return"
80
    ) -> Union[None, List[str]]:
81
        """
82
        Remove keywords from the control.in file.
83

84
        Parameters
85
        ----------
86
        *args : str
87
            Keywords to be removed from the control.in file.
88
        output : Literal["overwrite", "print", "return"], default="overwrite"
89
            Overwrite the original file, print the modified file to STDOUT, or return
90
            the modified file as a list of '\\n' separated strings.
91

92
        Returns
93
        -------
94
        Union[None, List[str]]
95
            If output is "return", the modified file is returned as a list of '\\n'
96
            separated strings.
97
        """
98

99
        for keyword in args:
1✔
100
            for i, line in enumerate(self.lines):
1✔
101
                if keyword in line:
1✔
102
                    self.lines.pop(i)
1✔
103

104
        match output:
1✔
105
            case "overwrite":
1✔
106
                with open(self.path, "w") as f:
1✔
107
                    f.writelines(self.lines)
1✔
108

109
            case "print":
1✔
110
                print(*self.lines, sep="")
1✔
111

112
            case "return":
1✔
113
                return self.lines
1✔
114

115
    def get_keywords(self) -> dict:
1✔
116
        """
117
        Get the keywords from the control.in file.
118

119
        Returns
120
        -------
121
        dict
122
            A dictionary of the keywords in the control.in file.
123
        """
124

125
        keywords = {}
1✔
126

127
        for line in self.lines:
1✔
128
            spl = line.split()
1✔
129

130
            if "#" * 80 in line:
1✔
131
                break
1✔
132

133
            if len(spl) > 0 and spl[0] != "#":
1✔
134
                if len(spl) == 1:
1✔
135
                    keywords[spl[0]] = None
×
136
                else:
137
                    keywords[spl[0]] = " ".join(spl[1:])
1✔
138

139
        return keywords
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc