Skip to content
Open
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
10 changes: 9 additions & 1 deletion dpgen2/conf/conf_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ def get_file_content(
for ii in range(len(ms)):
ss = ms[ii]
for jj in range(ss.get_nframes()):
frame = ss[jj]
if fmt in {"lmp", "lammps/lmp"}:
# Exploration inputs always declare ``atom_style atomic``.
# dpdata serializes ABACUS magnetic moments as four extra
# atom columns, which belong to LAMMPS's spin atom style and
# make the resulting atomic-style data file unreadable.
# Remove them only from this per-frame export copy.
frame.data.pop("spins", None)
with tempfile.NamedTemporaryFile() as ft:
tf = Path(ft.name)
ss[jj].to(fmt, tf)
frame.to(fmt, tf)
ret.append(tf.read_text())
return ret

Expand Down
37 changes: 37 additions & 0 deletions tests/conf/test_file_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@
+ "Atoms # atomic\n\n 1 2 0.0000000000 0.0000000000 0.0000000000\n"
)

abacus_stru = """ATOMIC_SPECIES
Si 28.085 Si.upf

NUMERICAL_ORBITAL
Si.orb

LATTICE_CONSTANT
1.0

LATTICE_VECTORS
10.0 0.0 0.0
0.0 10.0 0.0
0.0 0.0 10.0

ATOMIC_POSITIONS
Cartesian

Si
0.0
1
1.0 2.0 3.0 1 1 1 mag 0.0
"""


class TestFileConfGenerator(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -205,6 +228,20 @@ def test_deepmd_mixed(self):


class TestFileConfGeneratorContent(unittest.TestCase):
def test_abacus_spin_metadata_is_not_written_to_atomic_lammps_data(self):
stru = Path("STRU")
stru.write_text(abacus_stru)
self.addCleanup(stru.unlink, missing_ok=True)

content = FileConfGenerator(str(stru), fmt="abacus/stru").get_file_content(
type_map=["Si"]
)[0]
atom_section = content.split("Atoms # atomic", maxsplit=1)[1]
atom_line = next(line for line in atom_section.splitlines() if line.strip())

# Atomic style accepts only ID, type, and xyz coordinates.
self.assertEqual(len(atom_line.split()), 5)

def test_list_1(self):
f0 = Path("f0.POSCAR")
f1 = Path("f1.POSCAR")
Expand Down