Skip to content

Commit

Permalink
add WIP PotcarSingle.__repr__
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 25, 2023
1 parent bdadbf7 commit a35f8a8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2184,18 +2184,23 @@ def get_potcar_hash(self):
md5.update(hash_str.lower().encode("utf-8"))
return md5.hexdigest()

def __getattr__(self, a):
"""
Delegates attributes to keywords. For example, you can use
potcarsingle.enmax to get the ENMAX of the POTCAR.
def __getattr__(self, attr: str) -> Any:
"""Delegates attributes to keywords. For example, you can use potcarsingle.enmax to get the ENMAX of the POTCAR.
For float type properties, they are converted to the correct float. By
default, all energies in eV and all length scales are in Angstroms.
"""
try:
return self.keywords[a.upper()]
return self.keywords[attr.upper()]
except Exception:
raise AttributeError(a)
raise AttributeError(attr)

def __repr__(self) -> str:
cls_name = type(self).__name__
symbol, functional = self.symbol, self.functional
TITEL, VRHFIN = self.keywords["TITEL"], self.keywords["VRHFIN"]
TITEL, VRHFIN, n_valence_elec = (self.keywords.get(key) for key in ("TITEL", "VRHFIN", "ZVAL"))
return f"{cls_name}({symbol=}, {functional=}, {TITEL=}, {VRHFIN=}, {n_valence_elec=:.0f})"


class Potcar(list, MSONable):
Expand Down

0 comments on commit a35f8a8

Please sign in to comment.