Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix write Trajectory XDATACAR with variable lattice #2310

Merged
merged 1 commit into from
Nov 29, 2021
Merged
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
7 changes: 7 additions & 0 deletions pymatgen/core/tests/test_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ def test_variable_lattice(self):
all(np.allclose(struct.lattice.matrix, structures[i].lattice.matrix) for i, struct in enumerate(traj))
)

# Check if the file is written correctly when lattice is not constant.
traj.write_Xdatcar(filename="traj_test_XDATCAR")
# Load trajectory from written xdatcar and compare to original
written_traj = Trajectory.from_file("traj_test_XDATCAR", constant_lattice=False)
self._check_traj_equality(traj, written_traj)
os.remove("traj_test_XDATCAR")

def test_to_from_dict(self):
d = self.traj.as_dict()
traj = Trajectory.from_dict(d)
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def write_Xdatcar(self, filename="XDATCAR", system=None, significant_figures=6):

for si, frac_coords in enumerate(self.frac_coords):
# Only print out the info block if
if self.constant_lattice and si == 0:
if si == 0 or not self.constant_lattice:
lines.extend([system, "1.0"])

if self.constant_lattice:
Expand Down