Skip to content

Commit

Permalink
Update {Elastic,run,surf,Vasp,vasp}.py: To be compatible with Pymatgen (
Browse files Browse the repository at this point in the history
#1302)

To be compatible with old and new versions of Pymatgen
(materialsproject/pymatgen#3158)

---------

Signed-off-by: Levi Zhou  <31941107+ZhouXY-PKU@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ZhouXY-PKU and pre-commit-ci[bot] committed Oct 31, 2023
1 parent 4b69200 commit d58530b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
5 changes: 4 additions & 1 deletion dpgen/auto_test/Elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ def post_process(self, task_list):
kspacing = incar.get("KSPACING")
kgamma = incar.get("KGAMMA", False)
ret = vasp.make_kspacing_kpoints(poscar_start, kspacing, kgamma)
kp = Kpoints.from_string(ret)
try:
kp = Kpoints.from_string(ret)
except AttributeError:
kp = Kpoints.from_str(ret)
if os.path.isfile("KPOINTS"):
os.remove("KPOINTS")
kp.write_file("KPOINTS")
Expand Down
5 changes: 4 additions & 1 deletion dpgen/auto_test/VASP.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ def make_input_file(self, output_dir, task_type, task_param):
os.symlink("../INCAR", "INCAR")
os.chdir(cwd)
ret = vasp.make_kspacing_kpoints(self.path_to_poscar, kspacing, kgamma)
kp = Kpoints.from_string(ret)
try:
kp = Kpoints.from_string(ret)
except AttributeError:
kp = Kpoints.from_str(ret)
kp.write_file(os.path.join(output_dir, "KPOINTS"))

def compute(self, output_dir):
Expand Down
10 changes: 8 additions & 2 deletions dpgen/auto_test/lib/vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,10 @@ def make_vasp_kpoints_from_incar(work_dir, jdata):
assert os.path.exists("INCAR")
with open("INCAR") as fp:
incar = fp.read()
standard_incar = incar_upper(Incar.from_string(incar))
try:
standard_incar = incar_upper(Incar.from_string(incar))
except AttributeError:
standard_incar = incar_upper(Incar.from_str(incar))
if fp_aniso_kspacing is None:
try:
kspacing = standard_incar["KSPACING"]
Expand All @@ -533,6 +536,9 @@ def make_vasp_kpoints_from_incar(work_dir, jdata):
assert os.path.exists("POSCAR")
# make kpoints
ret = make_kspacing_kpoints("POSCAR", kspacing, gamma)
kp = Kpoints.from_string(ret)
try:
kp = Kpoints.from_string(ret)
except AttributeError:
kp = Kpoints.from_str(ret)
kp.write_file("KPOINTS")
os.chdir(cwd)
5 changes: 4 additions & 1 deletion dpgen/data/surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ def poscar_scale(poscar_in, poscar_out, scale):
else:
raise RuntimeError("Unknow poscar style at line 7: %s" % lines[7])

poscar = Poscar.from_string("".join(lines))
try:
poscar = Poscar.from_string("".join(lines))
except AttributeError:
poscar = Poscar.from_str("".join(lines))
with open(poscar_out, "w") as fout:
fout.write(poscar.get_string(direct=False))

Expand Down
20 changes: 16 additions & 4 deletions dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2924,14 +2924,20 @@ def make_pwmat_input(jdata, filename):
def make_vasp_incar_ele_temp(jdata, filename, ele_temp, nbands_esti=None):
with open(filename) as fp:
incar = fp.read()
incar = incar_upper(Incar.from_string(incar))
try:
incar = incar_upper(Incar.from_string(incar))
except AttributeError:
incar = incar_upper(Incar.from_str(incar))
incar["ISMEAR"] = -1
incar["SIGMA"] = ele_temp * pc.Boltzmann / pc.electron_volt
incar.write_file("INCAR")
if nbands_esti is not None:
nbands = nbands_esti.predict(".")
with open(filename) as fp:
incar = Incar.from_string(fp.read())
try:
incar = Incar.from_string(fp.read())
except AttributeError:
incar = Incar.from_str(fp.read())
incar["NBANDS"] = nbands
incar.write_file("INCAR")

Expand Down Expand Up @@ -3008,7 +3014,10 @@ def make_fp_vasp_kp(iter_index, jdata):
assert os.path.exists("INCAR")
with open("INCAR") as fp:
incar = fp.read()
standard_incar = incar_upper(Incar.from_string(incar))
try:
standard_incar = incar_upper(Incar.from_string(incar))
except AttributeError:
standard_incar = incar_upper(Incar.from_str(incar))
if fp_aniso_kspacing is None:
try:
kspacing = standard_incar["KSPACING"]
Expand All @@ -3031,7 +3040,10 @@ def make_fp_vasp_kp(iter_index, jdata):
assert os.path.exists("POSCAR")
# make kpoints
ret = make_kspacing_kpoints("POSCAR", kspacing, gamma)
kp = Kpoints.from_string(ret)
try:
kp = Kpoints.from_string(ret)
except AttributeError:
kp = Kpoints.from_str(ret)
kp.write_file("KPOINTS")
os.chdir(cwd)

Expand Down

0 comments on commit d58530b

Please sign in to comment.