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
6 changes: 3 additions & 3 deletions dpdata/lammps/lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def rotate_to_lower_triangle(
return cell, coord


def from_system_data(system, f_idx=0):
def from_system_data(system, f_idx=0, output_spins=False):
ret = ""
ret += "\n"
natoms = sum(system["atom_numbs"])
Expand Down Expand Up @@ -529,7 +529,7 @@ def from_system_data(system, f_idx=0):
+ "\n"
) # noqa: UP031

if "spins" in system:
if "spins" in system and output_spins:
coord_fmt = (
coord_fmt.strip("\n")
+ " "
Expand All @@ -544,7 +544,7 @@ def from_system_data(system, f_idx=0):
) # noqa: UP031
spins_norm = np.linalg.norm(system["spins"][f_idx], axis=1)
for ii in range(natoms):
if "spins" in system:
if "spins" in system and output_spins:
if spins_norm[ii] != 0:
ret += coord_fmt % (
ii + 1,
Expand Down
5 changes: 4 additions & 1 deletion dpdata/plugins/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ def to_system(self, data, file_name: FileType, frame_idx=0, **kwargs):
other parameters
"""
assert frame_idx < len(data["coords"])
w_str = dpdata.lammps.lmp.from_system_data(data, frame_idx)
output_spins = bool(kwargs.pop("output_spins", False))
w_str = dpdata.lammps.lmp.from_system_data(
data, frame_idx, output_spins=output_spins
)
with open_file(file_name, "w") as fp:
fp.write(w_str)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_lammps_spin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def setUp(self):
def tearDown(self):
pass # if os.path.isfile(self.lmp_coord_name):os.remove(self.lmp_coord_name)

def test_dump_input(self):
self.tmp_system.to("lammps/lmp", self.lmp_coord_name)
def test_dump_input(self, output_spins=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add any parameter options to the test function.

self.tmp_system.to("lammps/lmp", self.lmp_coord_name, output_spins=output_spins)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the lammps spin tests ,please set output_spins to True.

self.assertTrue(os.path.isfile(self.lmp_coord_name))
with open(self.lmp_coord_name) as f:
c = f.read()
Expand All @@ -58,9 +58,9 @@ def test_dump_input(self):
2 2 1.2621856000 0.7018028000 0.5513885000 0.0000000000 0.8000000000 0.6000000000 5.0000000000"""
self.assertTrue(coord_ref in c)

def test_dump_input_zero_spin(self):
def test_dump_input_zero_spin(self, output_spins=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add any parameter options to the test function.

self.tmp_system.data["spins"] = [[[0, 0, 0], [0, 0, 0]]]
self.tmp_system.to("lammps/lmp", self.lmp_coord_name)
self.tmp_system.to("lammps/lmp", self.lmp_coord_name, output_spins=output_spins)
self.assertTrue(os.path.isfile(self.lmp_coord_name))
with open(self.lmp_coord_name) as f:
c = f.read()
Expand Down
Loading