Skip to content

Commit 45af7c4

Browse files
authored
Merge pull request #33 from cote3804/main
Moved sets to pymatgen
2 parents 0ec9bdd + 62d93e6 commit 45af7c4

File tree

8 files changed

+18
-278
lines changed

8 files changed

+18
-278
lines changed

jdftxcov.xml

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/atomate2/jdftx/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
from custodian.jdftx.jobs import JDFTxJob
88
from jobflow.utils import ValueEnum
9+
from pymatgen.io.jdftx.sets import FILE_NAMES
910

1011
from atomate2 import SETTINGS
1112
from atomate2.jdftx.schemas.enums import JDFTxStatus
12-
from atomate2.jdftx.sets.base import FILE_NAMES
1313

1414
if TYPE_CHECKING:
1515
from atomate2.jdftx.schemas.task import TaskDoc

src/atomate2/jdftx/schemas/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from custodian.jdftx.jobs import JDFTxJob # Waiting on Sophie's PR
1010
from emmet.core.structure import StructureMetadata
1111
from pydantic import BaseModel, Field
12+
from pymatgen.io.jdftx.sets import FILE_NAMES
1213
from typing_extensions import Self
1314

1415
from atomate2.jdftx.schemas.calculation import (
@@ -18,7 +19,6 @@
1819
RunStatistics,
1920
)
2021
from atomate2.jdftx.schemas.enums import JDFTxStatus, TaskType
21-
from atomate2.jdftx.sets.base import FILE_NAMES
2222
from atomate2.utils.datetime import datetime_str
2323

2424
__author__ = "Cooper Tezak <cooper.tezak@colorado.edu>"

src/atomate2/jdftx/sets/BaseJdftxSet.yaml

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/atomate2/jdftx/sets/base.py

Lines changed: 13 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import os
65
from collections import defaultdict
76
from dataclasses import dataclass, field
87
from importlib.resources import files as get_mod_path
@@ -12,81 +11,22 @@
1211
import numpy as np
1312
from monty.serialization import loadfn
1413
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
1717
from pymatgen.io.vasp import Kpoints
1818

1919
from atomate2 import SETTINGS
2020

2121
if TYPE_CHECKING:
2222
from pymatgen.core import Structure
23-
from pymatgen.util.typing import Kpoint, PathLike
2423

2524

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+
)
2829
_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)
9030

9131

9232
@dataclass
@@ -123,7 +63,7 @@ class JdftxInputGenerator(InputGenerator):
12363
potential: None | float = None
12464
calc_type: str = "bulk"
12565
pseudopotentials: str = "GBRV"
126-
config_dict: dict = field(default_factory=lambda: _BEAST_CONFIG)
66+
config_dict: dict = field(default_factory=lambda: _GENERATION_CONFIG)
12767
default_settings: dict = field(default_factory=lambda: _BASE_JDFTX_SET)
12868

12969
def __post_init__(self) -> None:
@@ -172,13 +112,11 @@ def get_input_set(
172112
self.set_magnetic_moments(structure=structure)
173113
self._apply_settings(self.settings)
174114

175-
jdftx_structure = JDFTXStructure(structure)
176-
jdftxinputs = self.settings
177-
jdftxinput = JDFTXInfile.from_dict(jdftxinputs)
115+
jdftxinput = JDFTXInfile.from_dict(self.settings)
178116

179-
return JdftxInputSet(jdftxinput=jdftxinput, jdftxstructure=jdftx_structure)
117+
return JdftxInputSet(jdftxinput=jdftxinput, structure=structure)
180118

181-
def set_kgrid(self, structure: Structure) -> Kpoint:
119+
def set_kgrid(self, structure: Structure) -> None:
182120
"""Get k-point grid.
183121
184122
Parameters
@@ -267,7 +205,7 @@ def set_nbands(self, structure: Structure) -> None:
267205
for atom in structure.species:
268206
nelec += _PSEUDO_CONFIG[self.pseudopotentials][str(atom)]
269207
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"]
271209
self.settings["elec-n-bands"] = max(nbands_add, nbands_mult)
272210

273211
def set_pseudos(
@@ -297,7 +235,7 @@ def set_mu(self) -> None:
297235
if "target-mu" in self.settings or self.potential is None:
298236
return
299237
solvent_model = self.settings["pcm-variant"]
300-
ashep = _BEAST_CONFIG["ASHEP"][solvent_model]
238+
ashep = self.config_dict["ASHEP"][solvent_model]
301239
# calculate absolute potential in Hartree
302240
mu = -(ashep - self.potential) / eV_to_Ha
303241
self.settings["target-mu"] = {"mu": mu}
@@ -358,37 +296,6 @@ def set_magnetic_moments(self, structure: Structure) -> None:
358296
return
359297

360298

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-
392299
def center_of_mass(structure: Structure) -> np.ndarray:
393300
"""
394301
Calculate center of mass.

tests/jdftx/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
from jobflow import CURRENT_JOB
1212
from monty.os.path import zpath as monty_zpath
1313
from pymatgen.io.jdftx.inputs import JDFTXInfile
14+
from pymatgen.io.jdftx.sets import FILE_NAMES
1415

1516
import atomate2.jdftx.jobs.base
1617
import atomate2.jdftx.run
17-
from atomate2.jdftx.sets.base import FILE_NAMES, JdftxInputGenerator
18+
from atomate2.jdftx.sets.base import JdftxInputGenerator
1819

1920
if TYPE_CHECKING:
2021
from collections.abc import Sequence

0 commit comments

Comments
 (0)