Skip to content

Commit 9cd3977

Browse files
committed
do not output spin info for lmp format
1 parent 80d14f1 commit 9cd3977

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

dpdata/lammps/lmp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def rotate_to_lower_triangle(
484484
return cell, coord
485485

486486

487-
def from_system_data(system, f_idx=0):
487+
def from_system_data(system, f_idx=0, output_spins=False):
488488
ret = ""
489489
ret += "\n"
490490
natoms = sum(system["atom_numbs"])
@@ -529,7 +529,7 @@ def from_system_data(system, f_idx=0):
529529
+ "\n"
530530
) # noqa: UP031
531531

532-
if "spins" in system:
532+
if "spins" in system and output_spins:
533533
coord_fmt = (
534534
coord_fmt.strip("\n")
535535
+ " "
@@ -544,7 +544,7 @@ def from_system_data(system, f_idx=0):
544544
) # noqa: UP031
545545
spins_norm = np.linalg.norm(system["spins"][f_idx], axis=1)
546546
for ii in range(natoms):
547-
if "spins" in system:
547+
if "spins" in system and output_spins:
548548
if spins_norm[ii] != 0:
549549
ret += coord_fmt % (
550550
ii + 1,

dpdata/plugins/lammps.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def from_system(
108108
register_charge(data)
109109
return data
110110

111-
def to_system(self, data, file_name: FileType, frame_idx=0, **kwargs):
111+
def to_system(self, data, file_name: FileType, frame_idx=0, output_spins=False, **kwargs):
112112
"""Dump the system in lammps data format.
113113
114114
Parameters
@@ -119,11 +119,14 @@ def to_system(self, data, file_name: FileType, frame_idx=0, **kwargs):
119119
The output file name
120120
frame_idx : int
121121
The index of the frame to dump
122+
output_spins : bool, optional
123+
Whether to output spin information columns. Default is False.
124+
When True, outputs additional columns for spin direction and magnitude.
122125
**kwargs : dict
123126
other parameters
124127
"""
125128
assert frame_idx < len(data["coords"])
126-
w_str = dpdata.lammps.lmp.from_system_data(data, frame_idx)
129+
w_str = dpdata.lammps.lmp.from_system_data(data, frame_idx, output_spins=output_spins)
127130
with open_file(file_name, "w") as fp:
128131
fp.write(w_str)
129132

0 commit comments

Comments
 (0)