Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions dpdata/qe/traj.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3

import numpy as np
import dpdata
import dpdata,warnings

ry2ev = 13.605693009
hartree2ev = 27.211386018
Expand Down Expand Up @@ -36,8 +36,10 @@ def convert_celldm(ibrav, celldm) :
return celldm[0] * 0.5 * np.array([[1,1,1], [-1,1,1], [-1,-1,1]])
elif ibrav == -3 :
return celldm[0] * 0.5 * np.array([[-1,1,1], [1,-1,1], [1,1,-1]])
else :
raise RuntimeError('unsupported ibrav ' + str(ibrav))
else :
warnings.warn('unsupported ibrav ' + str(ibrav) + ' if no .cel file, the cell convertion may be wrong. ')
return np.eye(3)
#raise RuntimeError('unsupported ibrav ' + str(ibrav))

def load_cell_parameters(lines) :
blk = load_block(lines, 'CELL_PARAMETERS', 3)
Expand Down Expand Up @@ -152,11 +154,13 @@ def load_energy(fname, begin = 0, step = 1) :
for ii in data[begin::step,0]:
steps.append('%d'%ii)
with open(fname) as fp:
line = fp.readline()
if line :
nw = len(line.split())
else :
return None
while True:
line = fp.readline()
if not line :
return None
if line.split()[0][0] != '#':
nw = len(line.split())
break
data = np.reshape(data, [-1, nw])
return energy_convert * data[begin::step,5], steps

Expand Down
1 change: 1 addition & 0 deletions tests/qe.traj/traj6.evp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# comments here
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
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
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
Expand Down
13 changes: 10 additions & 3 deletions tests/test_qe_cp_traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from context import dpdata


class TestPWSCFProps :
class TestCPTRAJProps :
def test_atom_names(self) :
self.assertEqual(self.system.data['atom_names'], ['O','H'])

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


class TestPWSCFTraj(unittest.TestCase, TestPWSCFProps):
class TestCPTRAJTraj(unittest.TestCase, TestCPTRAJProps):

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


class TestPWSCFLabeledTraj(unittest.TestCase, TestPWSCFProps):
class TestCPTRAJLabeledTraj(unittest.TestCase, TestCPTRAJProps):

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


class TestConverCellDim(unittest.TestCase):
def test_case_null(self):
cell = dpdata.qe.traj.convert_celldm(8, [1, 1, 1])
ref = np.eye(3)
for ii in range(3):
for jj in range(3):
self.assertAlmostEqual(cell[ii][jj], ref[ii][jj])


if __name__ == '__main__':
Expand Down