Skip to content

Commit a01acaa

Browse files
authored
Fix UTs destroyed by pymatgen's update (#1471)
There are 2 changes in pymatgen which destroy the previous unittests: 1. materialsproject/pymatgen#3542 Previously we set the type of DummySpecies to "Type", which is forbidden by pymatgen through this PR. Here we replace "Type" with "X". 2. materialsproject/pymatgen#3561 The functions from_string and get_string have been replaced with from_str and get_str. We should keep up to date with these changes.
1 parent 7392650 commit a01acaa

File tree

7 files changed

+27
-12
lines changed

7 files changed

+27
-12
lines changed

dpgen/data/surf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ def poscar_scale(poscar_in, poscar_out, scale):
415415
except AttributeError:
416416
poscar = Poscar.from_str("".join(lines))
417417
with open(poscar_out, "w") as fout:
418-
fout.write(poscar.get_string(direct=False))
418+
try:
419+
fout.write(poscar.get_string(direct=False))
420+
except AttributeError:
421+
fout.write(poscar.get_str(direct=False))
419422

420423

421424
def make_scale(jdata):

dpgen/data/tools/bcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def poscar_unit(latt):
1717
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
1818
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
1919
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
20-
ret += "Type\n"
20+
ret += "X\n"
2121
ret += "%d\n" % numb_atoms()
2222
ret += "Direct\n"
2323
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"

dpgen/data/tools/diamond.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def poscar_unit(latt):
2222
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
2323
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
2424
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
25-
ret += "Type\n"
25+
ret += "X\n"
2626
ret += "%d\n" % numb_atoms()
2727
ret += "Direct\n"
2828
ret += f"{0.12500000000000:.16f} {0.12500000000000:.16f} {0.12500000000000:.16f}\n"

dpgen/data/tools/fcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def poscar_unit(latt):
1717
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
1818
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
1919
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
20-
ret += "Type\n"
20+
ret += "X\n"
2121
ret += "%d\n" % numb_atoms()
2222
ret += "Direct\n"
2323
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"

dpgen/data/tools/hcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def poscar_unit(latt):
2020
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
2121
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
2222
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
23-
ret += "Type\n"
23+
ret += "X\n"
2424
ret += "%d\n" % numb_atoms()
2525
ret += "Direct\n"
2626
ret += f"{0:.16f} {0:.16f} {0:.16f}\n"

dpgen/data/tools/sc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def poscar_unit(latt):
1717
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
1818
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
1919
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
20-
ret += "Type\n"
20+
ret += "X\n"
2121
ret += "%d\n" % numb_atoms()
2222
ret += "Direct\n"
2323
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"

tests/generator/test_make_fp.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ def _check_kpoints(testCase, idx):
414414
ret = make_kspacing_kpoints(
415415
os.path.join(os.path.join(ii, "POSCAR")), kspacing, gamma
416416
)
417-
kpoints_ref = Kpoints.from_string(ret)
417+
try:
418+
kpoints_ref = Kpoints.from_string(ret)
419+
except AttributeError:
420+
kpoints_ref = Kpoints.from_str(ret)
418421
testCase.assertEqual(repr(kpoints), repr(kpoints_ref))
419422

420423

@@ -496,12 +499,21 @@ def _check_incar_ele_temp(testCase, idx, ele_temp):
496499
tidx = int(bname.split(".")[2])
497500
with open("INCAR") as fp:
498501
incar = fp.read()
499-
incar0 = Incar.from_string(incar)
502+
try:
503+
incar0 = Incar.from_string(incar)
504+
except AttributeError:
505+
incar0 = Incar.from_str(incar)
500506
# make_fake_md: the frames in a system shares the same ele_temp
501-
incar1 = Incar.from_string(
502-
vasp_incar_ele_temp_ref
503-
% (ele_temp[sidx][0] * pc.Boltzmann / pc.electron_volt)
504-
)
507+
try:
508+
incar1 = Incar.from_string(
509+
vasp_incar_ele_temp_ref
510+
% (ele_temp[sidx][0] * pc.Boltzmann / pc.electron_volt)
511+
)
512+
except AttributeError:
513+
incar1 = Incar.from_str(
514+
vasp_incar_ele_temp_ref
515+
% (ele_temp[sidx][0] * pc.Boltzmann / pc.electron_volt)
516+
)
505517
for ii in incar0.keys():
506518
# skip checking nbands...
507519
if ii == "NBANDS":

0 commit comments

Comments
 (0)