Skip to content

Commit ddf96bf

Browse files
authored
Add support for use_structure_charge keyword in FHI-aims input generator (#4111)
1 parent f4e2838 commit ddf96bf

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/pymatgen/io/aims/sets/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,14 @@ class AimsInputGenerator(InputGenerator):
186186
parameters for the FHI-aims calculator
187187
user_kpoints_settings (dict[str, Any]): The settings
188188
used to create the k-grid parameters for FHI-aims
189+
use_structure_charge (bool): If set to True, then the overall charge of the
190+
structure (structure.charge) is used to set the `charge` variable in the
191+
`control.in`. Default is False.
189192
"""
190193

191194
user_params: dict[str, Any] = field(default_factory=dict)
192195
user_kpoints_settings: dict[str, Any] = field(default_factory=dict)
196+
use_structure_charge: bool = False
193197

194198
def get_input_set(
195199
self,
@@ -321,6 +325,9 @@ def _get_input_parameters(
321325

322326
parameter_updates = self.get_parameter_updates(structure, prev_parameters)
323327
params = recursive_update(params, parameter_updates)
328+
# Add the structure charge (useful for defect workflows)
329+
if self.use_structure_charge:
330+
params["charge"] = structure.charge
324331

325332
# Override default parameters with user_params
326333
params = recursive_update(params, self.user_params)

tests/io/aims/sets/test_static_generator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ def test_static_si(tmp_path):
1616
comp_system(Si, parameters, "static-si", tmp_path, REF_PATH, StaticSetGenerator)
1717

1818

19+
def test_static_o2_charge(tmp_path):
20+
parameters = {
21+
"species_dir": "light",
22+
"k_grid": [2, 2, 2],
23+
}
24+
Si.set_charge(1)
25+
generator = StaticSetGenerator(parameters, use_structure_charge=True)
26+
input_set = generator.get_input_set(Si)
27+
assert "charge 1" in input_set.control_in
28+
29+
1930
def test_static_si_no_kgrid(tmp_path):
2031
parameters = {"species_dir": "light"}
2132
Si_supercell = Si.make_supercell([1, 2, 3], in_place=False)

0 commit comments

Comments
 (0)