Skip to content

Commit 22b3533

Browse files
authored
Merge devel into master (#389)
2 parents 31e35e5 + d76b098 commit 22b3533

File tree

7 files changed

+47
-11
lines changed

7 files changed

+47
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
**dpdata** is a python package for manipulating data formats of software in computational science, including DeePMD-kit, VASP, LAMMPS, GROMACS, Gaussian.
2-
dpdata only works with python 3.x.
2+
dpdata only works with python 3.7 or above.
33

44

55
# Installation

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Welcome to dpdata's documentation!
1010
:maxdepth: 2
1111
:caption: Contents:
1212

13+
Overview <self>
1314
cli
1415
formats
1516
api/api

dpdata/lammps/dump.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ def get_atype(lines, type_idx_zero = False) :
3131
tidx = keys.index('type') - 2
3232
atype = []
3333
for ii in blk :
34-
atype.append([int(ii.split()[tidx]), int(ii.split()[id_idx])])
35-
# sort with type id
34+
atype.append([int(ii.split()[id_idx]), int(ii.split()[tidx])])
3635
atype.sort()
3736
atype = np.array(atype, dtype = int)
38-
atype = atype[:, ::-1]
3937
if type_idx_zero :
4038
return atype[:,1] - 1
4139
else :
@@ -78,17 +76,15 @@ def safe_get_posi(lines,cell,orig=np.zeros(3), unwrap=False) :
7876
assert coord_tp_and_sf is not None, 'Dump file does not contain atomic coordinates!'
7977
coordtype, sf, uw = coord_tp_and_sf
8078
id_idx = keys.index('id') - 2
81-
tidx = keys.index('type') - 2
8279
xidx = keys.index(coordtype[0])-2
8380
yidx = keys.index(coordtype[1])-2
8481
zidx = keys.index(coordtype[2])-2
85-
sel = (xidx, yidx, zidx)
8682
posis = []
8783
for ii in blk :
8884
words = ii.split()
89-
posis.append([float(words[tidx]), float(words[id_idx]), float(words[xidx]), float(words[yidx]), float(words[zidx])])
85+
posis.append([float(words[id_idx]), float(words[xidx]), float(words[yidx]), float(words[zidx])])
9086
posis.sort()
91-
posis = np.array(posis)[:,2:5]
87+
posis = np.array(posis)[:,1:4]
9288
if not sf:
9389
posis = (posis - orig) @ np.linalg.inv(cell) # Convert to scaled coordinates for unscaled coordinates
9490
if uw and unwrap:
@@ -178,14 +174,16 @@ def system_data(lines, type_map = None, type_idx_zero = True, unwrap=False) :
178174
orig, cell = dumpbox2box(bounds, tilt)
179175
system['orig'] = np.array(orig) - np.array(orig)
180176
system['cells'] = [np.array(cell)]
181-
natoms = sum(system['atom_numbs'])
182177
system['atom_types'] = get_atype(lines, type_idx_zero = type_idx_zero)
183178
system['coords'] = [safe_get_posi(lines, cell, np.array(orig), unwrap)]
184179
for ii in range(1, len(array_lines)) :
185180
bounds, tilt = get_dumpbox(array_lines[ii])
186181
orig, cell = dumpbox2box(bounds, tilt)
187182
system['cells'].append(cell)
188-
system['coords'].append(safe_get_posi(array_lines[ii], cell, np.array(orig), unwrap))
183+
atype = get_atype(array_lines[ii], type_idx_zero = type_idx_zero)
184+
# map atom type; a[as[a][as[as[b]]]] = b[as[b][as^{-1}[b]]] = b[id]
185+
idx = np.argsort(atype)[np.argsort(np.argsort(system['atom_types']))]
186+
system['coords'].append(safe_get_posi(array_lines[ii], cell, np.array(orig), unwrap)[idx])
189187
system['cells'] = np.array(system['cells'])
190188
system['coords'] = np.array(system['coords'])
191189
return system

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ authors = [
1212
]
1313
license = {file = "LICENSE"}
1414
classifiers = [
15-
"Programming Language :: Python :: 3.6",
15+
"Programming Language :: Python :: 3.7",
16+
"Programming Language :: Python :: 3.8",
17+
"Programming Language :: Python :: 3.9",
18+
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
1620
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
1721
]
1822
dependencies = [

tests/poscars/conf2.dump

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ITEM: TIMESTEP
2+
0
3+
ITEM: NUMBER OF ATOMS
4+
2
5+
ITEM: BOX BOUNDS xy xz yz pp pp pp
6+
0.0 5.0739861 1.2621856
7+
0.0 2.7916155 1.2874292
8+
0.0 2.2254033 0.7485898
9+
ITEM: ATOMS id type x y z
10+
1 2 0.0 0.0 0.0
11+
2 1 1.2621856 0.7018028 0.5513885

tests/test_lammps_dump_idx.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The index should map to that in the dump file
2+
3+
import os
4+
import numpy as np
5+
import unittest
6+
from context import dpdata
7+
8+
class TestLmpDumpIdx(unittest.TestCase):
9+
def setUp(self):
10+
self.system = dpdata.System(os.path.join('poscars', 'conf2.dump'))
11+
12+
def test_coords(self):
13+
np.testing.assert_allclose(self.system['coords'], np.array(
14+
[[[0., 0., 0.],
15+
[1.2621856, 0.7018028, 0.5513885]]]
16+
))
17+
18+
def test_type(self):
19+
np.testing.assert_allclose(self.system.get_atom_types(), np.array(
20+
[1, 0], dtype=int,
21+
))

tests/test_lammps_read_from_trajs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def setUp(self):
1010
dpdata.System(os.path.join('lammps', 'traj_with_random_type_id.dump'), fmt = 'lammps/dump', type_map = ["Ta","Nb","W","Mo","V","Al"])
1111

1212
def test_nframes (self) :
13+
self.system.sort_atom_types()
1314
atype = self.system['atom_types'].tolist()
1415
self.assertTrue(atype == [1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5])
1516

0 commit comments

Comments
 (0)