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

Dev #46

Merged
merged 3 commits into from
Sep 6, 2023
Merged

Dev #46

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
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
=======
History
=======
2023.9.6 -- Corrected issues with final coordinates; added velocities
* There was a problem with getting the final coordinates from a dump file.
* Added saving and reusing velocities so now a second LAMMPS step will by default use
the velocities from the previous step, which is what you would expect.

2023.8.31 -- Bugfix: not reading structure correctly after dynamics

2023.8.27 -- Added support for tabulated angle potentials.
Expand Down
159 changes: 114 additions & 45 deletions lammps_step/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,16 +594,22 @@
base = "lammps"

restart = base + ".restart.*"
dump = base + ".dump.*"
dump = base + ".dump"

Check warning on line 597 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L597

Added line #L597 was not covered by tests
input_file = base + ".dat"
new_input_data = []
new_input_data.append("run 0")
new_input_data.append(f"write_restart {restart}")

new_input_data.append(
f"write_dump all custom {dump} id "
"xu yu zu modify flush yes sort id"
)
if configuration.periodicity == 0:
new_input_data.append(

Check warning on line 604 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L603-L604

Added lines #L603 - L604 were not covered by tests
f"write_dump all custom {dump} id xu yu zu vx vy vz"
" modify flush yes sort id"
)
else:
new_input_data.append(

Check warning on line 609 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L609

Added line #L609 was not covered by tests
f"write_dump all custom {dump} id xsu ysu zsu vx vy vz"
" modify flush yes sort id"
)
new_input_data.append("")
new_input_data.append("info computes fixes dumps log out")

Expand Down Expand Up @@ -632,9 +638,10 @@

self._trajectory = []

if "dump" in files:
dump_file = Path(self.directory) / "final.dump"
if dump_file.exists:

Check warning on line 642 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L641-L642

Added lines #L641 - L642 were not covered by tests
try:
self.read_dump(os.path.join(self.directory, files["dump"]["filename"]))
self.read_dump(dump_file)

Check warning on line 644 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L644

Added line #L644 was not covered by tests
except Exception as e:
printer.normal("Warning: unable to read the LAMMPS dumpfile")
logger.warning(f"The was a problem reading the LAMMPS dumpfile: {e}")
Expand Down Expand Up @@ -670,6 +677,7 @@
"trajectory_*.seamm_trj",
"*.trj",
"*.restart.*",
"*.dump",
"*.dump.*",
"*.log",
"*.dat",
Expand Down Expand Up @@ -833,11 +841,11 @@
else:
if "ngpus" in batch:
printer.important(
f" LAMMPS using MPI with {np} processes and "
f" LAMMPS using MPI with {np} processes and "
f"{batch['ngpus']} gpus.\n"
)
else:
printer.important(f" LAMMPS using MPI with {np} processes")
printer.important(f" LAMMPS using MPI with {np} processes")

Check warning on line 848 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L848

Added line #L848 was not covered by tests

result = local.run(
cmd=cmd,
Expand Down Expand Up @@ -868,13 +876,6 @@
else:
self._add_lammps_citations(result["stdout"])

# base = os.path.basename(files["input"]["filename"][0:-4])
# dump_file = base + ".dump.0"

# files["dump"] = {}
# files["dump"]["filename"] = dump_file
# files["dump"]["data"] = None

files["input"] = {}
files["input"]["filename"] = None
initialization_header, eex = self._get_node_input(
Expand All @@ -898,6 +899,7 @@
write_restart=False,
extras=None,
):
_, configuration = self.get_system_configuration()

Check warning on line 902 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L902

Added line #L902 was not covered by tests
python_script = None
postscript = None
if isinstance(nodes, list) is False:
Expand All @@ -921,11 +923,7 @@
python_script = todo["python script"]

# base = "lammps_substep_%s_iter_%d" % ("_".join(node_ids), iteration)
base = "lammps"

input_file = base + ".dat"
# restart = base + ".restart.*"
dump = base + ".dump.*"

# if read_restart:
# new_input_data.insert(
Expand All @@ -936,29 +934,37 @@
# new_input_data.append(f"write_restart {restart}")

if postscript is None:
new_input_data.append("reset_timestep 0")
new_input_data.append("run 0")
new_input_data.append(
f"write_dump all custom {dump} id xu yu zu "
"modify flush yes sort id"
)
if configuration.periodicity == 0:
new_input_data.append(

Check warning on line 938 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L937-L938

Added lines #L937 - L938 were not covered by tests
"write_dump all custom final.dump id xu yu zu vx vy vz"
" modify flush yes sort id"
)
else:
new_input_data.append(

Check warning on line 943 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L943

Added line #L943 was not covered by tests
"write_dump all custom final.dump id xsu ysu zsu vx vy vz"
" modify flush yes sort id"
)
new_input_data.append("")
new_input_data.append("")
new_input_data.append("info computes fixes dumps out log")

files["input"]["data"] += new_input_data

files["input"]["filename"] = input_file
files["input"]["filename"] = "input.dat"

Check warning on line 953 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L953

Added line #L953 was not covered by tests
files["input"]["data"] = "\n".join(files["input"]["data"])
self.logger.debug(files["input"]["filename"] + ":\n" + files["input"]["data"])

if postscript is not None:
postscript.append("reset_timestep 0")
postscript.append("run 0")
postscript.append(
f"write_dump all custom {dump} id xu yu zu "
"modify flush yes sort id"
)
if configuration.periodicity == 0:
postscript.append(

Check warning on line 959 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L958-L959

Added lines #L958 - L959 were not covered by tests
"write_dump all custom final.dump id xu yu zu vx vy vz"
" modify flush yes sort id"
)
else:
postscript.append(

Check warning on line 964 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L964

Added line #L964 was not covered by tests
"write_dump all custom final.dump id xsu ysu zsu vx vy vz"
" modify flush yes sort id"
)
postscript.append("")
postscript.append("info computes fixes dumps out log")
files["postscript"] = {
Expand Down Expand Up @@ -1092,6 +1098,17 @@
x, y, z, index = xyz_index
lines.append(f"{i+1:6d} {index:6d} {x:12.7f} {y:12.7f} {z:12.7f}")

_, configuration = self.get_system_configuration()
if configuration.atoms.have_velocities:
lines.append("")
lines.append("Velocities")
lines.append("")
for i, vxyz in enumerate(

Check warning on line 1106 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L1101-L1106

Added lines #L1101 - L1106 were not covered by tests
configuration.atoms.get_velocities(fractionals=False), start=1
):
vx, vy, vz = vxyz
lines.append(f"{i:6d} {vx:12.7f} {vy:12.7f} {vz:12.7f}")

Check warning on line 1110 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L1109-L1110

Added lines #L1109 - L1110 were not covered by tests

lines.append("")
lines.append("Masses")
lines.append("")
Expand Down Expand Up @@ -1826,6 +1843,8 @@
}

# Process the trajectory data
# temporary until we sort out multiple runs
self._trajectory = []

Check warning on line 1847 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L1847

Added line #L1847 was not covered by tests
with path.open() as fd:
file_data = pandas.read_csv(
fd,
Expand Down Expand Up @@ -2303,9 +2322,6 @@

section = ""
section_lines = []
xs = []
ys = []
zs = []
with open(dumpfile, "r") as fd:
lineno = 0
for line in fd:
Expand Down Expand Up @@ -2369,28 +2385,81 @@
)
)
elif "ATOMS" in section:
for tmp in section_lines:
id, x, y, z = tmp.split()
xs.append(float(x))
ys.append(float(y))
zs.append(float(z))
xyz = []
vxyz = []
keys = section.split()[1:]
if keys[1:4] == ["x", "y", "z"] or keys[1:4] == [

Check warning on line 2391 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2388-L2391

Added lines #L2388 - L2391 were not covered by tests
"xu",
"yu",
"zu",
]:
fractional = False
elif keys[1:4] == ["xs", "ys", "zs"] or keys[1:4] == [

Check warning on line 2397 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2396-L2397

Added lines #L2396 - L2397 were not covered by tests
"xsu",
"ysu",
"zsu",
]:
fractional = True

Check warning on line 2402 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2402

Added line #L2402 was not covered by tests
else:
logger.error(f"Can't handle dump file, {keys=}")
if len(keys) >= 7 and keys[4:7] == ["vx", "vy", "vz"]:
have_velocities = True
factor = lammps_step.from_lammps_units(1, "fs").magnitude
factor = 1 / factor
for tmp in section_lines:
x, y, z, vx, vy, vz = tmp.split()[1:7]
xyz.append([float(x), float(y), float(z)])
vxyz.append(

Check warning on line 2412 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2404-L2412

Added lines #L2404 - L2412 were not covered by tests
[
factor * float(vx),
factor * float(vy),
factor * float(vz),
]
)
else:
have_velocities = False
for tmp in section_lines:
x, y, z = tmp.split()[1:4]
xyz.append([float(x), float(y), float(z)])

Check warning on line 2423 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2420-L2423

Added lines #L2420 - L2423 were not covered by tests
section = line[6:].strip()
section_lines = []
else:
section_lines.append(line)

# Clean up the last section
xyz = []
vxyz = []

Check warning on line 2431 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2431

Added line #L2431 was not covered by tests
if "ATOMS" in section:
self.logger.debug(" processing section '{}'".format(section))
self.logger.debug(" handling the atoms")
for tmp in section_lines:
id, x, y, z = tmp.split()
xyz.append([float(x), float(y), float(z)])
keys = section.split()[1:]
if keys[1:4] == ["x", "y", "z"] or keys[1:4] == ["xu", "yu", "zu"]:
fractional = False
elif keys[1:4] == ["xs", "ys", "zs"] or keys[1:4] == ["xsu", "ysu", "zsu"]:
fractional = True

Check warning on line 2439 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2435-L2439

Added lines #L2435 - L2439 were not covered by tests
else:
logger.error(f"Can't handle dump file, {keys=}")
if len(keys) >= 7 and keys[4:7] == ["vx", "vy", "vz"]:
have_velocities = True
factor = 1.0 / lammps_step.from_lammps_units(1, "fs").magnitude
for tmp in section_lines:
x, y, z, vx, vy, vz = tmp.split()[1:7]
xyz.append([float(x), float(y), float(z)])
vxyz.append(

Check warning on line 2448 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2441-L2448

Added lines #L2441 - L2448 were not covered by tests
[factor * float(vx), factor * float(vy), factor * float(vz)]
)
else:
have_velocities = False
for tmp in section_lines:
x, y, z = tmp.split()[1:4]
xyz.append([float(x), float(y), float(z)])

Check warning on line 2455 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2452-L2455

Added lines #L2452 - L2455 were not covered by tests

if periodicity == 3:
configuration.cell.parameters = cell
configuration.atoms.set_coordinates(xyz, fractionals=False)
configuration.atoms.set_coordinates(xyz, fractionals=fractional)
if have_velocities:

Check warning on line 2460 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2459-L2460

Added lines #L2459 - L2460 were not covered by tests
# LAMMPS only has Cartesian velocities
configuration.atoms.set_velocities(vxyz, fractionals=False)

Check warning on line 2462 in lammps_step/lammps.py

View check run for this annotation

Codecov / codecov/patch

lammps_step/lammps.py#L2462

Added line #L2462 was not covered by tests

def _add_lammps_citations(self, text, cite=None):
"""Add the two main citations for LAMMPS, getting the version from stdout
Expand Down
2 changes: 1 addition & 1 deletion lammps_step/tk_velocities.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def reset_dialog(self, widget=None):
widgets.append(self[key])
row += 1

if "scaling" in method:
if "scaling" not in method:
self["seed"].grid(row=row, column=0, sticky=tk.EW)
widgets.append(self["seed"])
row += 1
Expand Down
Loading