Skip to content

Commit

Permalink
fix Read qe/cp/traj with unit angstrom without .cel file (deepmodelin…
Browse files Browse the repository at this point in the history
  • Loading branch information
Han Wang committed May 26, 2022
1 parent 5c4008d commit efc3813
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 4 deletions.
30 changes: 26 additions & 4 deletions dpdata/qe/traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ def load_block(lines, key, nlines) :
break
return lines[idx+1:idx+1+nlines]

def load_unit(lines, key):
for idx,ii in enumerate(lines):
if key in ii:
break
line = lines[idx].lower()
if 'angstrom' in line:
return 'angstrom'
elif 'bohr' in line:
return bohr
elif 'alat' in ii or 'crystal' in ii or 'crystal_sg' in ii:
raise RuntimeError('unsupported unit', 'alat')
else:
return None

def convert_celldm(ibrav, celldm) :
if ibrav == 1 :
return celldm[0] * np.eye(3)
Expand All @@ -41,10 +55,11 @@ def convert_celldm(ibrav, celldm) :

def load_cell_parameters(lines) :
blk = load_block(lines, 'CELL_PARAMETERS', 3)
unit = load_unit(lines, 'CELL_PARAMETERS')
ret = []
for ii in blk :
ret.append([float(jj) for jj in ii.split()[0:3]])
return np.array(ret)
return np.array(ret), unit


def load_atom_names(lines, ntypes) :
Expand Down Expand Up @@ -83,10 +98,17 @@ def load_param_file(fname) :
ibrav = int(load_key(lines, 'ibrav'))
celldm = load_celldm(lines)
if ibrav == 0 :
cell = load_cell_parameters(lines)
cell, unit = load_cell_parameters(lines)
else :
cell = convert_celldm(ibrav, celldm)
cell = cell * length_convert
cell = convert_celldm(ibrav, celldm)
unit = 'bohr'
if unit == 'bohr':
# bohr to angstrom
cell = cell * length_convert
elif unit == 'angstrom':
pass
else:
raise RuntimeError('unsupported unit', unit)
# print(atom_names)
# print(atom_numbs)
# print(atom_types)
Expand Down
67 changes: 67 additions & 0 deletions tests/qe.traj/traj_alat.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
&CONTROL
title = "water 63mol+OH- PBE 330K",
calculation = 'cp-wf',
restart_mode = "restart",
prefix = "oh-scan",
pseudo_dir = '/global/homes/l/lxzheng/Pseudo_Potentials/',
outdir = './SimulationFiles/',
nstep = 10000,
isave = 100,
dt = 2.D0,
tstress = .true.,
tprnfor = .true.,
iprint = 5,
!ndr = 68,
!ndw = 68,
ekin_conv_thr = 1.D-6,
max_seconds = 3000,
/
&SYSTEM
ibrav = 0,
celldm(1) = 23.5170,
nat = 2,
ntyp = 2,
ecutwfc = 85.00D0,
ecfixed = 130.D0, ! effective cutoff value
q2sigma = 15.D0,
qcutz = 200.D0,
input_dft = 'scan',
tot_charge = -1
/
&ELECTRONS
electron_dynamics = "verlet",
emass = 100.D0,
emass_cutoff = 25.D0,
ortho_max = 800,
electron_maxstep = 500,
/
&IONS
ion_dynamics = "verlet",
ion_temperature = 'nose',
fnosep = 60,
tempw = 330,
nhpcl = 4,
nhptyp = 2,
ndega = -3
ion_radius(1) = 1.4
ion_radius(2) = 1.4
/
&WANNIER
nit = 60,
calwf = 3,
tolw = 1.D-6, nsteps = 50,
adapt = .FALSE.
wfdt = 2.0D0,
wf_q = 500.D0,
wf_friction = 0.3d0,
/
CELL_PARAMETERS {alat}
24.0 0.00 0.00
0.00 24.0 0.00
0.00 0.00 24.0
ATOMIC_SPECIES
O 15.9994 O_HSCV_PBE-1.0.UPF
H 2.01410178 H_HSCV_PBE-1.0.UPF
ATOMIC_POSITIONS {bohr}
O 0.298803E+02 0.153223E+02 -0.419200E+01
H 0.503917E+01 0.486667E+01 0.163637E+02
18 changes: 18 additions & 0 deletions tests/qe.traj/traj_alat.pos
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
195 0.00943365
0.32121827416246E+02 0.17164743320147E+02 -0.36182564198624E+01
0.14320529568791E+01 0.54323288734215E+01 0.16038550911723E+02
200 0.00967554
0.32121855340601E+02 0.17164728967776E+02 -0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
201 0.00967554
2.32121855340601E+02 0.17164728967776E+02 -0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
202 0.00967554
3.32121855340601E+02 0.17164728967776E+02 -0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
203 0.00967554
4.32121855340601E+02 0.17164728967776E+02 -0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
204 0.00967554
0.32121855340601E+02 0.17164728967776E+02 0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
67 changes: 67 additions & 0 deletions tests/qe.traj/traj_angs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
&CONTROL
title = "water 63mol+OH- PBE 330K",
calculation = 'cp-wf',
restart_mode = "restart",
prefix = "oh-scan",
pseudo_dir = '/global/homes/l/lxzheng/Pseudo_Potentials/',
outdir = './SimulationFiles/',
nstep = 10000,
isave = 100,
dt = 2.D0,
tstress = .true.,
tprnfor = .true.,
iprint = 5,
!ndr = 68,
!ndw = 68,
ekin_conv_thr = 1.D-6,
max_seconds = 3000,
/
&SYSTEM
ibrav = 0,
celldm(1) = 23.5170,
nat = 2,
ntyp = 2,
ecutwfc = 85.00D0,
ecfixed = 130.D0, ! effective cutoff value
q2sigma = 15.D0,
qcutz = 200.D0,
input_dft = 'scan',
tot_charge = -1
/
&ELECTRONS
electron_dynamics = "verlet",
emass = 100.D0,
emass_cutoff = 25.D0,
ortho_max = 800,
electron_maxstep = 500,
/
&IONS
ion_dynamics = "verlet",
ion_temperature = 'nose',
fnosep = 60,
tempw = 330,
nhpcl = 4,
nhptyp = 2,
ndega = -3
ion_radius(1) = 1.4
ion_radius(2) = 1.4
/
&WANNIER
nit = 60,
calwf = 3,
tolw = 1.D-6, nsteps = 50,
adapt = .FALSE.
wfdt = 2.0D0,
wf_q = 500.D0,
wf_friction = 0.3d0,
/
CELL_PARAMETERS {angstrom}
24.0 0.00 0.00
0.00 24.0 0.00
0.00 0.00 24.0
ATOMIC_SPECIES
O 15.9994 O_HSCV_PBE-1.0.UPF
H 2.01410178 H_HSCV_PBE-1.0.UPF
ATOMIC_POSITIONS {bohr}
O 0.298803E+02 0.153223E+02 -0.419200E+01
H 0.503917E+01 0.486667E+01 0.163637E+02
18 changes: 18 additions & 0 deletions tests/qe.traj/traj_angs.pos
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
195 0.00943365
0.32121827416246E+02 0.17164743320147E+02 -0.36182564198624E+01
0.14320529568791E+01 0.54323288734215E+01 0.16038550911723E+02
200 0.00967554
0.32121855340601E+02 0.17164728967776E+02 -0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
201 0.00967554
2.32121855340601E+02 0.17164728967776E+02 -0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
202 0.00967554
3.32121855340601E+02 0.17164728967776E+02 -0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
203 0.00967554
4.32121855340601E+02 0.17164728967776E+02 -0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
204 0.00967554
0.32121855340601E+02 0.17164728967776E+02 0.36182628967521E+01
0.14321036136090E+01 0.54322965963498E+01 0.16038534464162E+02
21 changes: 21 additions & 0 deletions tests/test_qe_cp_traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ def test_case_null(self):
for jj in range(3):
self.assertAlmostEqual(cell[ii][jj], ref[ii][jj])

class TestCPTRAJTrajCellParamAngstrom(unittest.TestCase):
def test(self):
ss = dpdata.System('qe.traj/traj_angs', fmt = 'qe/cp/traj')
expected_cell = 24 * np.eye(3)
expected_coord5 = \
[0.32121855340601E+02, 0.17164728967776E+02, 0.36182628967521E+01,
0.14321036136090E+01, 0.54322965963498E+01, 0.16038534464162E+02,]
expected_coord5 = np.array(expected_coord5).reshape([2,3]) * bohr2ang
self.assertEqual(ss.get_natoms(), 2)
self.assertEqual(ss.get_nframes(), 6)
self.assertEqual(ss['atom_names'], ['O','H'])
self.assertEqual(ss['atom_numbs'], [1,1])
np.testing.assert_equal(ss['atom_types'], [0,1])
for ii in range(6):
np.testing.assert_almost_equal(expected_cell, ss['cells'][ii])
np.testing.assert_almost_equal(expected_coord5, ss['coords'][5])

class TestCPTRAJTrajCellParamAngstrom(unittest.TestCase):
def test(self):
with self.assertRaises(RuntimeError) as ee:
ss = dpdata.System('qe.traj/traj_alat', fmt = 'qe/cp/traj')

if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit efc3813

Please sign in to comment.