|
2 | 2 |
|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 |
| -import os |
6 | 5 | from collections import defaultdict
|
7 | 6 | from dataclasses import dataclass, field
|
8 | 7 | from importlib.resources import files as get_mod_path
|
|
12 | 11 | import numpy as np
|
13 | 12 | from monty.serialization import loadfn
|
14 | 13 | from pymatgen.core.units import ang_to_bohr, eV_to_Ha
|
15 |
| -from pymatgen.io.core import InputGenerator, InputSet |
16 |
| -from pymatgen.io.jdftx.inputs import JDFTXInfile, JDFTXStructure |
| 14 | +from pymatgen.io.core import InputGenerator |
| 15 | +from pymatgen.io.jdftx.inputs import JDFTXInfile |
| 16 | +from pymatgen.io.jdftx.sets import JdftxInputSet |
17 | 17 | from pymatgen.io.vasp import Kpoints
|
18 | 18 |
|
19 | 19 | from atomate2 import SETTINGS
|
20 | 20 |
|
21 | 21 | if TYPE_CHECKING:
|
22 | 22 | from pymatgen.core import Structure
|
23 |
| - from pymatgen.util.typing import Kpoint, PathLike |
24 | 23 |
|
25 | 24 |
|
26 |
| -_BASE_JDFTX_SET = loadfn(get_mod_path("atomate2.jdftx.sets") / "BaseJdftxSet.yaml") |
27 |
| -_BEAST_CONFIG = loadfn(get_mod_path("atomate2.jdftx.sets") / "BeastConfig.yaml") |
| 25 | +_BASE_JDFTX_SET = loadfn(get_mod_path("pymatgen.io.jdftx.sets") / "BaseJdftxSet.yaml") |
| 26 | +_GENERATION_CONFIG = loadfn( |
| 27 | + get_mod_path("atomate2.jdftx.sets") / "GenerationConfig.yaml" |
| 28 | +) |
28 | 29 | _PSEUDO_CONFIG = loadfn(get_mod_path("atomate2.jdftx.sets") / "PseudosConfig.yaml")
|
29 |
| -FILE_NAMES = {"in": "init.in", "out": "jdftx.out"} |
30 |
| - |
31 |
| - |
32 |
| -class JdftxInputSet(InputSet): |
33 |
| - """ |
34 |
| - A class to represent a JDFTx input file as a JDFTx InputSet. |
35 |
| -
|
36 |
| - Parameters |
37 |
| - ---------- |
38 |
| - jdftxinput |
39 |
| - A JdftxInput object |
40 |
| - """ |
41 |
| - |
42 |
| - def __init__(self, jdftxinput: JDFTXInfile, jdftxstructure: JDFTXStructure) -> None: |
43 |
| - self.jdftxstructure = jdftxstructure |
44 |
| - self.jdftxinput = jdftxinput |
45 |
| - |
46 |
| - def write_input( |
47 |
| - self, |
48 |
| - directory: str | Path, |
49 |
| - infile: PathLike = FILE_NAMES["in"], |
50 |
| - make_dir: bool = True, |
51 |
| - overwrite: bool = True, |
52 |
| - ) -> None: |
53 |
| - """Write JDFTx input file to a directory. |
54 |
| -
|
55 |
| - Parameters |
56 |
| - ---------- |
57 |
| - directory |
58 |
| - Directory to write input files to. |
59 |
| - make_dir |
60 |
| - Whether to create the directory if it does not already exist. |
61 |
| - overwrite |
62 |
| - Whether to overwrite an input file if it already exists. |
63 |
| - """ |
64 |
| - directory = Path(directory) |
65 |
| - if make_dir: |
66 |
| - os.makedirs(directory, exist_ok=True) |
67 |
| - |
68 |
| - if not overwrite and (directory / infile).exists(): |
69 |
| - raise FileExistsError(f"{directory / infile} already exists.") |
70 |
| - |
71 |
| - jdftxinput = condense_jdftxinputs(self.jdftxinput, self.jdftxstructure) |
72 |
| - |
73 |
| - jdftxinput.write_file(filename=(directory / infile)) |
74 |
| - |
75 |
| - @staticmethod |
76 |
| - def from_directory( |
77 |
| - directory: str | Path, |
78 |
| - ) -> JdftxInputSet: |
79 |
| - """Load a set of JDFTx inputs from a directory. |
80 |
| -
|
81 |
| - Parameters |
82 |
| - ---------- |
83 |
| - directory |
84 |
| - Directory to read JDFTx inputs from. |
85 |
| - """ |
86 |
| - directory = Path(directory) |
87 |
| - jdftxinput = JDFTXInfile.from_file(directory / "input.in") |
88 |
| - jdftxstructure = jdftxinput.to_JDFTXStructure(jdftxinput) |
89 |
| - return JdftxInputSet(jdftxinput=jdftxinput, jdftxstructure=jdftxstructure) |
90 | 30 |
|
91 | 31 |
|
92 | 32 | @dataclass
|
@@ -123,7 +63,7 @@ class JdftxInputGenerator(InputGenerator):
|
123 | 63 | potential: None | float = None
|
124 | 64 | calc_type: str = "bulk"
|
125 | 65 | pseudopotentials: str = "GBRV"
|
126 |
| - config_dict: dict = field(default_factory=lambda: _BEAST_CONFIG) |
| 66 | + config_dict: dict = field(default_factory=lambda: _GENERATION_CONFIG) |
127 | 67 | default_settings: dict = field(default_factory=lambda: _BASE_JDFTX_SET)
|
128 | 68 |
|
129 | 69 | def __post_init__(self) -> None:
|
@@ -172,13 +112,11 @@ def get_input_set(
|
172 | 112 | self.set_magnetic_moments(structure=structure)
|
173 | 113 | self._apply_settings(self.settings)
|
174 | 114 |
|
175 |
| - jdftx_structure = JDFTXStructure(structure) |
176 |
| - jdftxinputs = self.settings |
177 |
| - jdftxinput = JDFTXInfile.from_dict(jdftxinputs) |
| 115 | + jdftxinput = JDFTXInfile.from_dict(self.settings) |
178 | 116 |
|
179 |
| - return JdftxInputSet(jdftxinput=jdftxinput, jdftxstructure=jdftx_structure) |
| 117 | + return JdftxInputSet(jdftxinput=jdftxinput, structure=structure) |
180 | 118 |
|
181 |
| - def set_kgrid(self, structure: Structure) -> Kpoint: |
| 119 | + def set_kgrid(self, structure: Structure) -> None: |
182 | 120 | """Get k-point grid.
|
183 | 121 |
|
184 | 122 | Parameters
|
@@ -267,7 +205,7 @@ def set_nbands(self, structure: Structure) -> None:
|
267 | 205 | for atom in structure.species:
|
268 | 206 | nelec += _PSEUDO_CONFIG[self.pseudopotentials][str(atom)]
|
269 | 207 | nbands_add = int(nelec / 2) + 10
|
270 |
| - nbands_mult = int(nelec / 2) * _BEAST_CONFIG["bands_multiplier"] |
| 208 | + nbands_mult = int(nelec / 2) * self.config_dict["bands_multiplier"] |
271 | 209 | self.settings["elec-n-bands"] = max(nbands_add, nbands_mult)
|
272 | 210 |
|
273 | 211 | def set_pseudos(
|
@@ -297,7 +235,7 @@ def set_mu(self) -> None:
|
297 | 235 | if "target-mu" in self.settings or self.potential is None:
|
298 | 236 | return
|
299 | 237 | solvent_model = self.settings["pcm-variant"]
|
300 |
| - ashep = _BEAST_CONFIG["ASHEP"][solvent_model] |
| 238 | + ashep = self.config_dict["ASHEP"][solvent_model] |
301 | 239 | # calculate absolute potential in Hartree
|
302 | 240 | mu = -(ashep - self.potential) / eV_to_Ha
|
303 | 241 | self.settings["target-mu"] = {"mu": mu}
|
@@ -358,37 +296,6 @@ def set_magnetic_moments(self, structure: Structure) -> None:
|
358 | 296 | return
|
359 | 297 |
|
360 | 298 |
|
361 |
| -def condense_jdftxinputs( |
362 |
| - jdftxinput: JDFTXInfile, jdftxstructure: JDFTXStructure |
363 |
| -) -> JDFTXInfile: |
364 |
| - """ |
365 |
| - Combine JDFTXInfile and JDFTxStructure into complete JDFTXInfile. |
366 |
| -
|
367 |
| - Function combines a JDFTXInfile class with calculation |
368 |
| - settings and a JDFTxStructure that defines the structure |
369 |
| - into one JDFTXInfile instance. |
370 |
| -
|
371 |
| - Parameters |
372 |
| - ---------- |
373 |
| - jdftxinput: JDFTXInfile |
374 |
| - A JDFTXInfile object with calculation settings. |
375 |
| -
|
376 |
| - jdftxstructure: JDFTXStructure |
377 |
| - A JDFTXStructure object that defines the structure. |
378 |
| -
|
379 |
| - Returns |
380 |
| - ------- |
381 |
| - JDFTXInfile |
382 |
| - A JDFTXInfile that includes the calculation |
383 |
| - parameters and input structure. |
384 |
| - """ |
385 |
| - # force Cartesian coordinates |
386 |
| - coords_type = jdftxinput.get("coords-type") |
387 |
| - return jdftxinput + JDFTXInfile.from_str( |
388 |
| - jdftxstructure.get_str(in_cart_coords=(coords_type == "Cartesian")) |
389 |
| - ) |
390 |
| - |
391 |
| - |
392 | 299 | def center_of_mass(structure: Structure) -> np.ndarray:
|
393 | 300 | """
|
394 | 301 | Calculate center of mass.
|
|
0 commit comments