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
4 changes: 3 additions & 1 deletion dpdata/formats/pwmat/atomconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def from_system_data(system, f_idx=0, skip_zeros=True):
atomic_numbers.append(ELEMENTS.index(ii) + 1)
posi_list = []
for jj, ii in zip(atomic_numbers, posis):
ii = np.matmul(ii, np.linalg.inv(system["cells"][0]))
# Fractional coordinates must be computed in the same frame's cell;
# frame zero is only valid for a fixed-cell trajectory.
ii = np.matmul(ii, np.linalg.inv(system["cells"][f_idx]))
posi_list.append("%d %15.10f %15.10f %15.10f 1 1 1" % (jj, ii[0], ii[1], ii[2])) # noqa: UP031
for kk in range(len(posi_list)):
min = kk
Expand Down
15 changes: 15 additions & 0 deletions tests/test_pwmat_config_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import os
import unittest

import numpy as np
from pwmat.config_ref_oh import Testconfigoh

import dpdata
from dpdata.formats.pwmat.atomconfig import from_system_data


def myfilecmp(test, f0, f1):
Expand Down Expand Up @@ -58,5 +60,18 @@ def test_dump_pwmat_type_map(self):
myfilecmp(self, "atom.config.tmp.1", "atom.config.tmp.2")


class TestAtomconfigFrameCell(unittest.TestCase):
def test_fractional_coordinates_use_selected_frame_cell(self):
system = {
"atom_names": ["H"],
"atom_numbs": [1],
"atom_types": np.array([0]),
"cells": np.array([np.eye(3), np.eye(3) * 2.0]),
"coords": np.array([[[1.0, 0.0, 0.0]], [[1.0, 0.0, 0.0]]]),
}
output = from_system_data(system, f_idx=1)
self.assertIn("0.5000000000 0.0000000000 0.0000000000", output)


if __name__ == "__main__":
unittest.main()
Loading