Skip to content

Commit

Permalink
Merge pull request #1 from benrich37/input_cov
Browse files Browse the repository at this point in the history
Input cov
  • Loading branch information
benrich37 authored Sep 25, 2024
2 parents 8c5768f + 8e21488 commit 0127c44
Show file tree
Hide file tree
Showing 9 changed files with 681 additions and 202 deletions.
333 changes: 155 additions & 178 deletions src/pymatgen/io/jdftx/generic_tags.py

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/pymatgen/io/jdftx/jdftxinfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
get_tag_object,
)
from pymatgen.util.io_utils import clean_lines
from pymatgen.util.typing import SpeciesLike

if TYPE_CHECKING:
from typing import Any
Expand Down Expand Up @@ -745,6 +746,22 @@ def __post_init__(self) -> None:
Post init function for JDFTXStructure. Asserts self.structure is
ordered, and adds selective dynamics if needed.
"""
# TODO: Remove integers from species name (ie convert Si0 -> Si)
# TODO: Test if this fix works
for i in range(len(self.structure.species)):
name = ""
if isinstance(self.structure.species[i], str):
name_str = self.structure.species[i]
elif isinstance(self.structure.species[i], SpeciesLike):
name_str = self.structure.species[i].symbol
if not isinstance(name_str, str):
name_str = name_str.symbol
else:
raise TypeError("Species must be a string or SpeciesLike object")
for j in range(len(name_str)):
if not name_str[j].isdigit():
name += name_str[j]
self.structure.species[i] = name
if self.structure.is_ordered:
site_properties = {}
if self.selective_dynamics is not None:
Expand Down
7 changes: 6 additions & 1 deletion src/pymatgen/io/jdftx/jdftxinfile_master_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from copy import deepcopy
from typing import Any

from pymatgen.io.jdftx.data import atom_valence_electrons
from pymatgen.io.jdftx.generic_tags import (
AbstractTag,
BoolTag,
Expand Down Expand Up @@ -83,7 +84,11 @@
optional=False,
allow_list_representation=True,
subtags={
"species-id": StrTag(write_tagname=False, optional=False),
"species-id": StrTag(
write_tagname=False,
optional=False,
options=list(atom_valence_electrons.keys()), # Required in case bad species names gets fed
),
"x0": FloatTag(write_tagname=False, optional=False, prec=12),
"x1": FloatTag(write_tagname=False, optional=False, prec=12),
"x2": FloatTag(write_tagname=False, optional=False, prec=12),
Expand Down
39 changes: 17 additions & 22 deletions src/pymatgen/io/jdftx/jdftxoutfileslice.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class JDFTXOutfileSlice(ClassPrintFormatter):
has_solvation: bool = False
fluid: str | None = None
is_gc: bool | None = None
is_bgw: bool = False

@property
def t_s(self) -> float | None:
Expand Down Expand Up @@ -632,19 +633,19 @@ def get_truncationvars(self, text: list[str]) -> tuple[str, float] | tuple[None,
truncation_radius = None
if line is not None:
truncation_type = text[line].split()[1]
if truncation_type not in maptypes:
raise ValueError("Problem with this truncation!")
truncation_type = maptypes[truncation_type]
direc = None
if len(text[line].split()) == 3:
direc = text[line].split()[2]
if truncation_type == "slab" and direc != "001":
raise ValueError("BGW slab Coulomb truncation must be along z!")
if truncation_type == "wire" and direc != "001":
raise ValueError(
"BGW wire Coulomb truncation must be periodic \
in z!"
)
if truncation_type == "error":
raise ValueError("Problem with this truncation!")
if self.is_bgw:
if truncation_type == "slab" and direc != "001":
raise ValueError("BGW slab Coulomb truncation must be along z!")
if truncation_type == "wire" and direc != "001":
raise ValueError("BGW wire Coulomb truncation must be periodic in z!")
# if truncation_type == "error":
# raise ValueError("Problem with this truncation!")
if truncation_type == "spherical":
line = find_key("Initialized spherical truncation of radius", text)
truncation_radius = float(text[line].split()[5]) / ang_to_bohr
Expand Down Expand Up @@ -763,10 +764,7 @@ def get_eigstats_varsdict(self, text: list[str], prefix: str | None) -> dict[str
lines2 = find_all_key("eigStats' ...", text)
lines3 = [lines1[i] for i in range(len(lines1)) if lines1[i] in lines2]
if not len(lines3):
raise ValueError(
'Must run DFT job with "dump End EigStats" to get summary gap\
information!'
)
raise ValueError('Must run DFT job with "dump End EigStats" to get summary gap information!')
line = lines3[-1]
varsdict["emin"] = float(text[line + 1].split()[1]) * Ha_to_eV
varsdict["homo"] = float(text[line + 2].split()[1]) * Ha_to_eV
Expand Down Expand Up @@ -811,7 +809,7 @@ def get_pp_type(self, text: list[str]) -> str:
"""
skey = "Reading pseudopotential file"
line = find_key(skey, text)
ppfile_example = text[line].split(skey)[1].split(":")[0].strip("'")
ppfile_example = text[line].split(skey)[1].split(":")[0].strip("'").strip()
pptype = None
readable = ["GBRV", "SG15"]
for _pptype in readable:
Expand All @@ -824,10 +822,7 @@ def get_pp_type(self, text: list[str]) -> str:
else:
pptype = _pptype
if pptype is None:
raise ValueError(
f"Could not determine pseudopotential type from file name\
{ppfile_example}"
)
raise ValueError(f"Could not determine pseudopotential type from file name {ppfile_example}")
return pptype

def set_pseudo_vars(self, text: list[str]) -> None:
Expand Down Expand Up @@ -1070,7 +1065,7 @@ def set_orb_fillings(self) -> None:
else:
self.set_orb_fillings_nobroad(self.nspin)
else:
raise ValueError(" Cannot set homo/lumo filling with self.nspin as None")
raise ValueError("Cannot set homo/lumo filling with self.nspin as None")

def set_fluid(self, text: list[str]) -> None: # Is this redundant to the fluid settings?
"""Set the fluid class variable.
Expand Down Expand Up @@ -1251,7 +1246,7 @@ def determine_is_metal(self) -> bool:
if self.lumo_filling is not None:
return self._determine_is_metal(tol_partial, self.nspin, self.homo_filling, self.lumo_filling)
raise ValueError("Cannot determine if system is metal - self.lumo_filling undefined")
raise ValueError("Cannot determine if system is metal - self.homo_fillig undefined")
raise ValueError("Cannot determine if system is metal - self.homo_filling undefined")
raise ValueError("Cannot determine if system is metal - self.nspin undefined")

def check_solvation(self) -> bool:
Expand All @@ -1266,13 +1261,13 @@ def check_solvation(self) -> bool:
"""
return self.fluid is not None

def write(self) -> NotImplementedError:
def write(self) -> None:
"""Return an error.
Return an error. (pre-commit needs a docustring here)
"""
# don't need a write method since will never do that
return NotImplementedError("There is no need to write a JDFTx out file")
raise NotImplementedError("There is no need to write a JDFTx out file")

def to_dict(self) -> dict:
"""Convert dataclass to dictionary representation.
Expand Down
4 changes: 4 additions & 0 deletions src/pymatgen/io/jdftx/jdftxoutfileslice_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def get_start_lines(
start_lines.append(i)
if add_end and i is not None:
start_lines.append(i)
if i is None:
raise ValueError("Outfile parser fed an empty file.")
if not len(start_lines):
raise ValueError("No JDFTx calculations found in file.")
return start_lines


Expand Down
Loading

0 comments on commit 0127c44

Please sign in to comment.