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

element.xu mode is added and displacement is forced to [-0.5,0.5] assuming… #124

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
48 changes: 35 additions & 13 deletions tools/interface/LAMMPS.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ def _print_displacements_and_forces(self, lammps_files, file_offset):

for idata in range(ndata):
disp = x[idata, :, :] - self._x_cartesian - disp_offset
if True:
# force disp vector the small magnitude assuming that the displacement is small.
# change displacemeent to the fractional coordinate
_disp_fracx = self._get_fractional_coordinate(disp, self._inverse_lattice_vector)
# make _fracx in [-0.5,0.5).
_disp_fracx += 0.5
_disp_fracx %= 1 # returns positive fractional part.. [0,1).
_disp_fracx -= 0.5 # adjust the center again
# convert to the cartedian coordinate again
disp = np.dot(_disp_fracx, self._lattice_vector.transpose())
disp *= self._disp_conversion_factor
f = force[idata, :, :] - force_offset
f *= self._force_conversion_factor
Expand Down Expand Up @@ -343,7 +353,7 @@ def _set_unit_conversion_factor(self, str_unit):

def _set_output_flags(self, output_flags):
self._print_disp, self._print_force, \
self._print_energy, self._print_born = output_flags
self._print_energy, self._print_born = output_flags

def _set_number_of_zerofill(self, npattern):

Expand Down Expand Up @@ -380,25 +390,37 @@ def x_fractional(self):
@staticmethod
def _get_coordinate_and_force_lammps(lammps_dump_file):

add_flag = False
add_flag = None
ret = []

with open(lammps_dump_file) as f:
for line in f:
if "ITEM:" in line and "ITEM: ATOMS id xu yu zu fx fy fz" not in line:
add_flag = False
# if "ITEM:" in line and "ITEM: ATOMS id xu yu zu fx fy fz" not in line:
# add_flag = False
# continue
if "ITEM: ATOMS id xu yu zu fx fy fz" in line:
add_flag = "id.xu"
continue
elif "ITEM: ATOMS id xu yu zu fx fy fz" in line:
add_flag = True
elif "ITEM: ATOMS element xu yu zu fx fy fz" in line:
add_flag = "element.xu"
id_ = 0
continue

if add_flag:
if line.strip():
entries = line.strip().split()
data_atom = [int(entries[0]),
[float(t) for t in entries[1:4]],
[float(t) for t in entries[4:]]]

if add_flag is not None:
if add_flag == "id.xu":
if line.strip():
entries = line.strip().split()
data_atom = [int(entries[0]),
[float(t) for t in entries[1:4]],
[float(t) for t in entries[4:]]]
ret.append(data_atom)
elif add_flag == "element.xu":
if line.strip():
entries = line.strip().split()
id_ += 1
data_atom = [int(id_),
[float(t) for t in entries[1:4]],
[float(t) for t in entries[4:]]]
ret.append(data_atom)

# This sort is necessary since the order atoms of LAMMPS dump files
Expand Down