Skip to content

Commit ed23df2

Browse files
fix(test): account for Masses section in dpdata>=1.0.2 lammps output (deepmodeling#343)
1 parent 5083026 commit ed23df2

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

tests/conf/test_alloy_conf.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import random
4+
import re
45
import shutil
56
import tempfile
67
import unittest
@@ -23,8 +24,20 @@
2324
# isort: on
2425

2526

27+
# dpdata >= 1.0.2 emits a "Masses" section in the lammps/lmp output
28+
_dpdata_ver = tuple(int(x) for x in re.findall(r"\d+", dpdata.__version__)[:3])
29+
_lmp_masses = (
30+
"Masses\n\n 1 26.9815386000 # Al\n 2 24.3050000000 # Mg\n\n"
31+
if _dpdata_ver >= (1, 0, 2)
32+
else ""
33+
)
34+
2635
ofc0 = "\n1 atoms\n2 atom types\n 0.0000000000 2.0000000000 xlo xhi\n 0.0000000000 2.0000000000 ylo yhi\n 0.0000000000 2.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\nAtoms # atomic\n\n 1 1 0.0000000000 0.0000000000 0.0000000000\n"
27-
ofc1 = "\n1 atoms\n2 atom types\n 0.0000000000 3.0000000000 xlo xhi\n 0.0000000000 3.0000000000 ylo yhi\n 0.0000000000 3.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\nAtoms # atomic\n\n 1 2 0.0000000000 0.0000000000 0.0000000000\n"
36+
ofc1 = (
37+
"\n1 atoms\n2 atom types\n 0.0000000000 3.0000000000 xlo xhi\n 0.0000000000 3.0000000000 ylo yhi\n 0.0000000000 3.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\n"
38+
+ _lmp_masses
39+
+ "Atoms # atomic\n\n 1 2 0.0000000000 0.0000000000 0.0000000000\n"
40+
)
2841
ofc2 = "\n1 atoms\n2 atom types\n 0.0000000000 4.0000000000 xlo xhi\n 0.0000000000 4.0000000000 ylo yhi\n 0.0000000000 4.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\nAtoms # atomic\n\n 1 2 0.0000000000 0.0000000000 0.0000000000\n"
2942

3043

tests/conf/test_file_conf.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import random
4+
import re
45
import shutil
56
import tempfile
67
import textwrap
@@ -22,6 +23,14 @@
2223

2324
# isort: on
2425

26+
# dpdata >= 1.0.2 emits a "Masses" section in the lammps/lmp output
27+
_dpdata_ver = tuple(int(x) for x in re.findall(r"\d+", dpdata.__version__)[:3])
28+
_lmp_masses = (
29+
"Masses\n\n 1 26.9815386000 # Al\n 2 24.3050000000 # Mg\n\n"
30+
if _dpdata_ver >= (1, 0, 2)
31+
else ""
32+
)
33+
2534
pos0 = textwrap.dedent(
2635
"""POSCAR file written by OVITO
2736
1
@@ -58,7 +67,11 @@
5867
cartesian
5968
0.0000000000 0.0000000000 0.0000000000
6069
"""
61-
ofc0 = "\n1 atoms\n2 atom types\n 0.0000000000 2.0000000000 xlo xhi\n 0.0000000000 2.0000000000 ylo yhi\n 0.0000000000 2.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\nAtoms # atomic\n\n 1 1 0.0000000000 0.0000000000 0.0000000000\n"
70+
ofc0 = (
71+
"\n1 atoms\n2 atom types\n 0.0000000000 2.0000000000 xlo xhi\n 0.0000000000 2.0000000000 ylo yhi\n 0.0000000000 2.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\n"
72+
+ _lmp_masses
73+
+ "Atoms # atomic\n\n 1 1 0.0000000000 0.0000000000 0.0000000000\n"
74+
)
6275

6376
ifc1 = """Mg1
6477
1.0
@@ -70,7 +83,11 @@
7083
cartesian
7184
0.0000000000 0.0000000000 0.0000000000
7285
"""
73-
ofc1 = "\n1 atoms\n2 atom types\n 0.0000000000 3.0000000000 xlo xhi\n 0.0000000000 3.0000000000 ylo yhi\n 0.0000000000 3.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\nAtoms # atomic\n\n 1 2 0.0000000000 0.0000000000 0.0000000000\n"
86+
ofc1 = (
87+
"\n1 atoms\n2 atom types\n 0.0000000000 3.0000000000 xlo xhi\n 0.0000000000 3.0000000000 ylo yhi\n 0.0000000000 3.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\n"
88+
+ _lmp_masses
89+
+ "Atoms # atomic\n\n 1 2 0.0000000000 0.0000000000 0.0000000000\n"
90+
)
7491

7592
ifc2 = """Mg1
7693
1.0
@@ -82,7 +99,11 @@
8299
cartesian
83100
0.0000000000 0.0000000000 0.0000000000
84101
"""
85-
ofc2 = "\n1 atoms\n2 atom types\n 0.0000000000 4.0000000000 xlo xhi\n 0.0000000000 4.0000000000 ylo yhi\n 0.0000000000 4.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\nAtoms # atomic\n\n 1 2 0.0000000000 0.0000000000 0.0000000000\n"
102+
ofc2 = (
103+
"\n1 atoms\n2 atom types\n 0.0000000000 4.0000000000 xlo xhi\n 0.0000000000 4.0000000000 ylo yhi\n 0.0000000000 4.0000000000 zlo zhi\n 0.0000000000 0.0000000000 0.0000000000 xy xz yz\n\n"
104+
+ _lmp_masses
105+
+ "Atoms # atomic\n\n 1 2 0.0000000000 0.0000000000 0.0000000000\n"
106+
)
86107

87108

88109
class TestFileConfGenerator(unittest.TestCase):

0 commit comments

Comments
 (0)