Skip to content

Commit 881bfbd

Browse files
author
tianhongzhen
committed
add unittests
1 parent 42f0739 commit 881bfbd

File tree

10 files changed

+55750
-2
lines changed

10 files changed

+55750
-2
lines changed

dpdata/pwmat/atomconfig.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def from_system_data(system, f_idx = 0, skip_zeros = True) :
6767
ret += '\n'
6868
ret += 'POSITION'
6969
ret += '\n'
70+
atom_numbs = system['atom_numbs']
71+
atom_names = system['atom_names']
7072
atype = system['atom_types']
7173
posis = system['coords'][f_idx]
7274
# atype_idx = [[idx,tt] for idx,tt in enumerate(atype)]
@@ -77,7 +79,7 @@ def from_system_data(system, f_idx = 0, skip_zeros = True) :
7779
symbal = []
7880
for ii, jj in zip(atom_numbs, atom_names):
7981
for kk in range(ii):
80-
symbal.append(kk)
82+
symbal.append(jj)
8183
ELEMENTS=['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', \
8284
'Sc', 'Ti', 'V', 'Cr','Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', \
8385
'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd',\
@@ -86,13 +88,19 @@ def from_system_data(system, f_idx = 0, skip_zeros = True) :
8688
'Md', 'No', 'Lr']
8789
atomic_numbers = []
8890
for ii in symbal:
89-
atomic_numbers.append(symbal.index(ii)+1)
91+
atomic_numbers.append(ELEMENTS.index(ii)+1)
9092
posi_list = []
9193
for jj, ii in zip(atomic_numbers,posis) :
9294
ii = np.matmul(ii, np.linalg.inv(system['cells'][0]))
9395
posi_list.append('%d %15.10f %15.10f %15.10f 1 1 1' % \
9496
(jj, ii[0], ii[1], ii[2])
9597
)
98+
for kk in range(len(posi_list)):
99+
min = kk
100+
for jj in range(kk,len(posi_list)):
101+
if int(posi_list[jj].split()[0]) < int(posi_list[min].split()[0]):
102+
min = jj
103+
posi_list[min], posi_list[kk] = posi_list[kk],posi_list[min]
96104
posi_list.append('')
97105
ret += '\n'.join(posi_list)
98106
return ret

tests/pwmat/MOVEMENT

Lines changed: 27776 additions & 0 deletions
Large diffs are not rendered by default.

tests/pwmat/atom.config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
5
2+
LATTICE
3+
10.00000000 0.00000000 0.00000000
4+
0.00000000 10.00000000 0.00000000
5+
0.00000000 0.00000000 10.00000000
6+
POSITION
7+
1 0.53815434 0.40686080 0.36057301 1 1 1
8+
1 0.39453966 0.48032057 0.43846884 1 1 1
9+
1 0.55209243 0.56545029 0.44270874 1 1 1
10+
1 0.52818530 0.41641476 0.53918266 1 1 1
11+
6 0.50325059 0.46725516 0.44523234 1 1 1

tests/pwmat/atom.config.oh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2
2+
LATTICE
3+
0.00000000 1.78500000 1.78500000
4+
1.60650000 0.00000000 1.78500000
5+
1.96350000 1.82070000 0.00000000
6+
POSITION
7+
1 0.24727453 0.25272547 0.24777007 1 1 1
8+
8 0.00000000 0.00000000 0.00000000 1 1 1

tests/pwmat/conf.lmp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# LAMMPS data file written by OVITO
2+
2 atoms
3+
2 atom types
4+
0.0 2.5243712 xlo xhi
5+
0.0 2.0430257 ylo yhi
6+
0.0 2.2254033 zlo zhi
7+
1.2621856 1.2874292 0.7485898 xy xz yz
8+
9+
Atoms # atomic
10+
11+
1 1 0.0 0.0 0.0
12+
2 2 1.2621856 0.7018028 0.5513885

tests/pwmat/config_ref_ch4.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import numpy as np
2+
3+
class Testconfigch4 :
4+
5+
def test_atom_numbs(self):
6+
self.assertEqual(self.system.data['atom_numbs'], [4,1])
7+
8+
def test_atom_names(self):
9+
self.assertEqual(self.system.data['atom_names'], ['H','C'])
10+
11+
def test_atom_types(self):
12+
self.assertEqual(self.system.data['atom_types'][0], 0)
13+
self.assertEqual(self.system.data['atom_types'][1], 0)
14+
self.assertEqual(self.system.data['atom_types'][2], 0)
15+
self.assertEqual(self.system.data['atom_types'][3], 0)
16+
self.assertEqual(self.system.data['atom_types'][4], 1)
17+
18+
def test_orig(self):
19+
for d0 in range(3) :
20+
self.assertEqual(self.system.data['orig'][d0], 0)
21+
22+
def test_cell(self):
23+
ovito_cell = np.array([[10.000000, 0.0000000, 0.0000000],
24+
[0.0000000, 10.000000, 0.0000000],
25+
[0.0000000, 0.0000000, 10.000000]])
26+
for ii in range(3) :
27+
for jj in range(3) :
28+
self.assertAlmostEqual(self.system.data['cells'][0][ii][jj],
29+
ovito_cell[ii][jj],
30+
places = 6,
31+
msg = 'cell[%d][%d] failed' % (ii,jj))
32+
33+
def test_frame(self):
34+
ovito_posis = np.array([[0.53815434, 0.40686080, 0.36057301],
35+
[0.39453966, 0.48032057, 0.43846884],
36+
[0.55209243, 0.56545029, 0.44270874],
37+
[0.52818530, 0.41641476, 0.53918266],
38+
[0.50325059, 0.46725516, 0.44523234]])*10
39+
for ii in range(2) :
40+
for jj in range(3) :
41+
self.assertAlmostEqual(self.system.data['coords'][0][ii][jj],
42+
ovito_posis[ii][jj],
43+
places = 6,
44+
msg = 'posis[%d][%d] failed' % (ii,jj))

tests/pwmat/config_ref_oh.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import numpy as np
2+
3+
class Testconfigoh :
4+
5+
def test_atom_numbs(self):
6+
self.assertEqual(self.system.data['atom_numbs'], [1,1])
7+
8+
def test_atom_names(self):
9+
self.assertEqual(self.system.data['atom_names'], ['H','O'])
10+
11+
def test_atom_types(self):
12+
self.assertEqual(self.system.data['atom_types'][0], 0)
13+
self.assertEqual(self.system.data['atom_types'][1], 1)
14+
15+
def test_orig(self):
16+
for d0 in range(3) :
17+
self.assertEqual(self.system.data['orig'][d0], 0)
18+
19+
def test_cell(self):
20+
ovito_cell = np.array([[2.5243712, 0.0000000, 0.0000000],
21+
[1.2621856, 2.0430257, 0.0000000],
22+
[1.2874292, 0.7485898, 2.2254033]])
23+
for ii in range(3) :
24+
for jj in range(3) :
25+
self.assertAlmostEqual(self.system.data['cells'][0][ii][jj],
26+
ovito_cell[ii][jj],
27+
places = 6,
28+
msg = 'cell[%d][%d] failed' % (ii,jj))
29+
30+
def test_frame(self):
31+
ovito_posis = np.array([[1.2621856, 0.7018028, 0.5513885],[0, 0, 0]])
32+
for ii in range(2) :
33+
for jj in range(3) :
34+
self.assertAlmostEqual(self.system.data['coords'][0][ii][jj],
35+
ovito_posis[ii][jj],
36+
places = 6,
37+
msg = 'posis[%d][%d] failed' % (ii,jj))

0 commit comments

Comments
 (0)