Skip to content

Commit 21b8b28

Browse files
authored
Merge pull request #76 from amcadmus/devel
fix the bug of energy file with comments, warning when ibrav is nor supported
2 parents 132c1cf + fc2c785 commit 21b8b28

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

dpdata/qe/traj.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python3
22

33
import numpy as np
4-
import dpdata
4+
import dpdata,warnings
55

66
ry2ev = 13.605693009
77
hartree2ev = 27.211386018
@@ -36,8 +36,10 @@ def convert_celldm(ibrav, celldm) :
3636
return celldm[0] * 0.5 * np.array([[1,1,1], [-1,1,1], [-1,-1,1]])
3737
elif ibrav == -3 :
3838
return celldm[0] * 0.5 * np.array([[-1,1,1], [1,-1,1], [1,1,-1]])
39-
else :
40-
raise RuntimeError('unsupported ibrav ' + str(ibrav))
39+
else :
40+
warnings.warn('unsupported ibrav ' + str(ibrav) + ' if no .cel file, the cell convertion may be wrong. ')
41+
return np.eye(3)
42+
#raise RuntimeError('unsupported ibrav ' + str(ibrav))
4143

4244
def load_cell_parameters(lines) :
4345
blk = load_block(lines, 'CELL_PARAMETERS', 3)
@@ -152,11 +154,13 @@ def load_energy(fname, begin = 0, step = 1) :
152154
for ii in data[begin::step,0]:
153155
steps.append('%d'%ii)
154156
with open(fname) as fp:
155-
line = fp.readline()
156-
if line :
157-
nw = len(line.split())
158-
else :
159-
return None
157+
while True:
158+
line = fp.readline()
159+
if not line :
160+
return None
161+
if line.split()[0][0] != '#':
162+
nw = len(line.split())
163+
break
160164
data = np.reshape(data, [-1, nw])
161165
return energy_convert * data[begin::step,5], steps
162166

tests/qe.traj/traj6.evp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# comments here
12
195 9.433649E-03 1.290500E-05 0.000000E+00 1.057182E-02 -1100.03076389 -1100.03076389 -1100.03075434 -1100.03073209 1.300606E+04 -3.31610
23
200 9.675537E-03 7.090171E-05 0.000000E+00 1.257319E+00 -1100.03189493 -1100.03189493 -1100.03076015 -1100.03068120 1.300606E+04 -3.31683
34
201 9.675537E-03 7.090171E-05 0.000000E+00 2.257319E+00 -1100.03189493 -1100.03189493 -1100.03076015 -1100.03068120 1.300606E+04 -3.31683

tests/test_qe_cp_traj.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from context import dpdata
55

66

7-
class TestPWSCFProps :
7+
class TestCPTRAJProps :
88
def test_atom_names(self) :
99
self.assertEqual(self.system.data['atom_names'], ['O','H'])
1010

@@ -44,18 +44,25 @@ def test_coord(self) :
4444
self.assertAlmostEqual(self.system['coords'][-1][ii][jj], coords[ii][jj])
4545

4646

47-
class TestPWSCFTraj(unittest.TestCase, TestPWSCFProps):
47+
class TestCPTRAJTraj(unittest.TestCase, TestCPTRAJProps):
4848

4949
def setUp(self):
5050
self.system = dpdata.System('qe.traj/oh-md', fmt = 'qe/cp/traj')
5151

5252

53-
class TestPWSCFLabeledTraj(unittest.TestCase, TestPWSCFProps):
53+
class TestCPTRAJLabeledTraj(unittest.TestCase, TestCPTRAJProps):
5454

5555
def setUp(self):
5656
self.system = dpdata.LabeledSystem('qe.traj/oh-md', fmt = 'qe/cp/traj')
5757

5858

59+
class TestConverCellDim(unittest.TestCase):
60+
def test_case_null(self):
61+
cell = dpdata.qe.traj.convert_celldm(8, [1, 1, 1])
62+
ref = np.eye(3)
63+
for ii in range(3):
64+
for jj in range(3):
65+
self.assertAlmostEqual(cell[ii][jj], ref[ii][jj])
5966

6067

6168
if __name__ == '__main__':

0 commit comments

Comments
 (0)