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

Adding LAMMPS backend #110

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
74e0a4f
Google Colab integration (#102)
InnocentBug Feb 22, 2022
00b934f
Adding lammps backend
ndtrung81 Feb 22, 2022
3247ff8
Added some notes for lammps.py for the needed work with LAMMPS
ndtrung81 Feb 22, 2022
123b2f5
Merge branch 'main' into lammps-backend
ndtrung81 May 6, 2022
bb3e228
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 6, 2022
2936383
Added lammps.py and the supported backend name in core.py
ndtrung81 Sep 1, 2022
c8a624b
Merge branch 'main' into lammps-backend-updated
ndtrung81 Oct 19, 2022
e6bcd7d
Merge branch 'main' into lammps-backend-updated
ndtrung81 Feb 7, 2023
b1dc43f
Updated lammps backend
ndtrung81 Feb 9, 2023
f20e928
Added examples for lammps backend, first try unbiased
ndtrung81 Feb 9, 2023
d0bf895
Added a python script simple.py for testing the LAMMPS python module …
ndtrung81 Feb 13, 2023
0bfae4e
Updated lammps backend: box matrix info, run method and query of the …
ndtrung81 Feb 17, 2023
6bc971e
Updated lammps unbiased.py example: setup the context inside the scri…
ndtrung81 Feb 17, 2023
6c6388d
Working on lammps.py to connect with DLExtSampler imported from lammp…
ndtrung81 Feb 21, 2023
31a7a42
Added more comments to lammps.py
ndtrung81 Feb 28, 2023
0e75241
Moved initialization and snapshot into Sampler for now, will revisit …
ndtrung81 Mar 15, 2023
353ee39
Updated unbiased.py with the new API from lammps-dlext
ndtrung81 Apr 26, 2023
9d8d43e
Updated unbiased.py with the new LAMMPSView and FixDLExt interfaces
May 30, 2023
6f48710
Merge branch 'lammps-backend-updated' into lammps-backend
May 30, 2023
f487d9e
Update the lammps backend interface
pabloferz Jun 27, 2023
58d07dd
Update examples/lammps/unbiased/unbiased.py
ndtrung81 Jun 27, 2023
38fc917
Update again the lammps backend interface
pabloferz Jul 12, 2023
b49943c
Merge branch 'main' into lammps-backend
pabloferz Jul 12, 2023
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
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Examples for Methods using OpenMM can be found in the subfolder [openmm](openmm)
## Installation of the Environment

We have a Google Colab that shows how the MD engines and PySAGES can be installed together as a guide to install PySAGES.

This notebook has a final step that sets up precompiled environments for all the other notebooks as well.
[![Install Env](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/SSAGESLabs/PySAGES/blob/main/examples/Install_PySAGES_Environment.ipynb)

Expand Down
2 changes: 2 additions & 0 deletions examples/hoomd-blue/harmonic_bias/harmonic_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def validate_hist(xi_hist, target, epsilon=0.1):
def get_target_dist(center, k, lim, bins):
x = np.linspace(lim[0], lim[1], bins)
p = np.exp(-0.5 * k * (x - center) ** 2)

# norm numerically
p *= (lim[1] - lim[0]) / np.sum(p)
return p
Expand All @@ -55,6 +56,7 @@ def generate_context(**kwargs):
nl = hoomd.md.nlist.cell()
dpd = hoomd.md.pair.dpd(r_cut=1, nlist=nl, seed=42, kT=1.0)
dpd.pair_coeff.set("A", "A", A=kwargs.get("A", 5.0), gamma=kwargs.get("gamma", 1.0))

return context


Expand Down
1 change: 1 addition & 0 deletions examples/hoomd-blue/umbrella_integration/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def plot_hist(result, bins=50):
ax[x, y].plot(edges, histo, label=f"center {center}")
ax[x, y].legend(loc="best", fontsize="xx-small")
ax[x, y].set_yscale("log")

counter += hist_per
while counter < len(result["centers"]):
center = np.asarray(result["centers"][counter])
Expand Down
30 changes: 30 additions & 0 deletions examples/lammps/unbiased/in.lj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 3d Lennard-Jones melt

variable x index 1
variable y index 1
variable z index 1

variable xx equal 20*$x
variable yy equal 20*$y
variable zz equal 20*$z

units lj
atom_style atomic

lattice fcc 0.8442
region box block 0 ${xx} 0 ${yy} 0 ${zz}
create_box 1 box
create_atoms 1 box
mass 1 1.0

velocity all create 1.44 87287 loop geom

pair_style lj/cut 2.5
pair_coeff 1 1 1.0 1.0 2.5

neighbor 0.3 bin
neigh_modify delay 0 every 20 check no

fix 1 all nve

run 100
160 changes: 160 additions & 0 deletions examples/lammps/unbiased/log.lammps.8Feb2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
LAMMPS (8 Feb 2023)
KOKKOS mode is enabled (src/KOKKOS/kokkos.cpp:106)
will use up to 1 GPU(s) per node
package kokkos
# 3d Lennard-Jones melt



variable x index 1

variable y index 1

variable z index 1



variable xx equal 20*$x

variable xx equal 20*1

variable yy equal 20*$y

variable yy equal 20*1

variable zz equal 20*$z

variable zz equal 20*1



units lj

atom_style atomic



lattice fcc 0.8442

Lattice spacing in x,y,z = 1.6795962 1.6795962 1.6795962
region box block 0 ${xx} 0 ${yy} 0 ${zz}

region box block 0 20 0 ${yy} 0 ${zz}

region box block 0 20 0 20 0 ${zz}

region box block 0 20 0 20 0 20

create_box 1 box

Created orthogonal box = (0 0 0) to (33.591924 33.591924 33.591924)
1 by 1 by 1 MPI processor grid
create_atoms 1 box

Created 32000 atoms
using lattice units in orthogonal box = (0 0 0) to (33.591924 33.591924 33.591924)
create_atoms CPU = 0.005 seconds
mass 1 1.0



velocity all create 1.44 87287 loop geom



pair_style lj/cut 2.5

pair_coeff 1 1 1.0 1.0 2.5



neighbor 0.3 bin

neigh_modify delay 0 every 20 check no



fix 1 all nve



run 100

Generated 0 of 0 mixed pair_coeff terms from geometric mixing rule
Neighbor list info ...
update: every = 20 steps, delay = 0 steps, check = no
max neighbors/atom: 2000, page size: 100000
master list distance cutoff = 2.8
ghost atom cutoff = 2.8
binsize = 2.8, bins = 12 12 12
1 neighbor lists, perpetual/occasional/extra = 1 0 0
(1) pair lj/cut/kk, perpetual
attributes: full, newton off, kokkos_device
pair build: full/bin/kk/device
stencil: full/bin/3d
bin: kk/device
Per MPI rank memory allocation (min/avg/max) = 7.475 | 7.475 | 7.475 Mbytes
Step Temp E_pair E_mol TotEng Press
0 1.44 -6.7733681 0 -4.6134356 -5.0197073
100 0.7574531 -5.7585055 0 -4.6223613 0.20726105
Loop time of 0.0285314 on 1 procs for 100 steps with 32000 atoms

Performance: 1514122.080 tau/day, 3504.912 timesteps/s, 112.157 Matom-step/s
95.5% CPU use with 1 MPI tasks x 1 OpenMP threads

MPI task timing breakdown:
Section | min time | avg time | max time |%varavg| %total
---------------------------------------------------------------
Pair | 0.001557 | 0.001557 | 0.001557 | 0.0 | 5.46
Neigh | 0.0051532 | 0.0051532 | 0.0051532 | 0.0 | 18.06
Comm | 0.0032644 | 0.0032644 | 0.0032644 | 0.0 | 11.44
Output | 4.0139e-05 | 4.0139e-05 | 4.0139e-05 | 0.0 | 0.14
Modify | 0.017342 | 0.017342 | 0.017342 | 0.0 | 60.78
Other | | 0.001175 | | | 4.12

Nlocal: 32000 ave 32000 max 32000 min
Histogram: 1 0 0 0 0 0 0 0 0 0
Nghost: 19657 ave 19657 max 19657 min
Histogram: 1 0 0 0 0 0 0 0 0 0
Neighs: 0 ave 0 max 0 min
Histogram: 1 0 0 0 0 0 0 0 0 0
FullNghs: 2.40567e+06 ave 2.40567e+06 max 2.40567e+06 min
Histogram: 1 0 0 0 0 0 0 0 0 0

Total # of neighbors = 2405666
Ave neighs/atom = 75.177063
Neighbor list builds = 5
Dangerous builds not checked
run 0
Generated 0 of 0 mixed pair_coeff terms from geometric mixing rule
Per MPI rank memory allocation (min/avg/max) = 7.556 | 7.556 | 7.556 Mbytes
Step Temp E_pair E_mol TotEng Press
100 0.7574531 -5.7585055 0 -4.6223613 0.20726105
Loop time of 0.00049331 on 1 procs for 0 steps with 32000 atoms

99.9% CPU use with 1 MPI tasks x 1 OpenMP threads

MPI task timing breakdown:
Section | min time | avg time | max time |%varavg| %total
---------------------------------------------------------------
Pair | 0 | 0 | 0 | 0.0 | 0.00
Neigh | 0 | 0 | 0 | 0.0 | 0.00
Comm | 0 | 0 | 0 | 0.0 | 0.00
Output | 0 | 0 | 0 | 0.0 | 0.00
Modify | 0 | 0 | 0 | 0.0 | 0.00
Other | | 0.0004933 | | |100.00

Nlocal: 32000 ave 32000 max 32000 min
Histogram: 1 0 0 0 0 0 0 0 0 0
Nghost: 19657 ave 19657 max 19657 min
Histogram: 1 0 0 0 0 0 0 0 0 0
Neighs: 0 ave 0 max 0 min
Histogram: 1 0 0 0 0 0 0 0 0 0
FullNghs: 2.40567e+06 ave 2.40567e+06 max 2.40567e+06 min
Histogram: 1 0 0 0 0 0 0 0 0 0

Total # of neighbors = 2405666
Ave neighs/atom = 75.177063
Neighbor list builds = 0
Dangerous builds not checked
Total wall time: 0:00:00
110 changes: 110 additions & 0 deletions examples/lammps/unbiased/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env python3
# preceding line should have path for Python on your machine
#
# simple.py
# Serial syntax: ./simple.py in.lj
# in.lj = LAMMPS input script
#
# LAMMPS build with the following configuration to enable the KOKKOS and PYTHON packages:
# ccmake -S cmake -B build -D PKG_KOKKOS=on -D Kokkos_ENABLE_CUDA=on -D Kokkos_ARCH_AMPERE80=on \
# -D PKG_MOLECULE=on -D PKG_KSPACE=on -D BUILD_SHARED_LIBS=on -D PKG_PYTHON=on -D FFT=KISS \
# -D CMAKE_INSTALL_PREFIX=`python3 -c "import sys; print(sys.prefix)"` -D Python_EXECUTABLE=`which python3`
#
# If the build succeeds, the shared library liblammps.so is installed into $CMAKE_INSTALL_PREFIX/lib64.
# We also need the shared lib libpython3.x.so.1, which is under $CMAKE_INSTALL_PREFIX/lib.
# Finally, libdlext.so installed by lammps.dlext is currently not found, so we need to add
# $CMAKE_INSTALL_PREFIX/lib/python3.9/site-packages/lammps to LD_LIBRARY_PATH.
#
# export LD_LIBRARY_PATH=$CMAKE_INSTALL_PREFIX/lib64/lib:$CMAKE_INSTALL_PREFIX/lib64:$CMAKE_INSTALL_PREFIX/lib/python3.9/site-packages/lammps:$LD_LIBRARY_PATH
#
# where $CMAKE_INSTALL_PREFIX is the full path to the top-level folder of the virtual environment.
#
# To test the installation of the LAMMPS python module
# python3 -c "from lammps import lammps; lmp = lammps()"
#

from __future__ import print_function
import sys

import lammps
from lammps import lammps

def main():

# parse command line
argv = sys.argv
if len(argv) != 2:
print("Syntax: ./simple.py in.lj")
sys.exit()

infile = sys.argv[1]

args = "-k on g 1 -sf kk"
#args += " -nocite -sc none"
args=args.split()
lmp = lammps(cmdargs=args)

# run infile one line at a time to set up the simulation
lines = open(infile,'r').readlines()
for line in lines: lmp.command(line)

# this is wrapped as the run method, see methods_dispatch run()
# wrapped_context.run(timesteps, **kwargs) is called in methods/core.py
# do "run 0" to setup neighbor build and force computes
lmp.command("run 0")

# demo of how to extract simulation information from lmp (context)"
# see LMP_SRC/python/lammps/core.py, or under the installation path
# $CMAKE_INSTALL_PREFIX/lib/python3.9/site-packages/lammps/core.py

print("----------------------------------------------")
print("Simulation info from the LAMMPS python module:")
natoms = lmp.extract_global("natoms")
print(f"natoms = {natoms}")
nlocal = lmp.extract_setting('nlocal')
print(f"nlocal = {nlocal}")

boxlo,boxhi,xy,yz,xz,periodicity,_ = lmp.extract_box()
print(f"box lo = {boxlo}")
print(f"box hi = {boxhi}")
Lx = boxhi[0] - boxlo[0]
Ly = boxhi[1] - boxlo[1]
Lz = boxhi[2] - boxlo[2]
origin = boxlo
H = ((Lx, xy * Ly, xz * Lz), (0.0, Ly, yz * Lz), (0.0, 0.0, Lz))
print("box matrix: ", H)

# or
#boxlo = lmp.extract_global("boxlo")
#boxhi = lmp.extract_global("boxhi")

dim = lmp.extract_setting('dimension')
print("Dimensionality = ", dim)
pe = lmp.get_thermo("pe")
print(f"Current potential energy = {pe}")

dt = lmp.extract_global("dt")
print(f"Timestep dt = {dt}")

# Query if PKG_KOKKOS is enabled
pkg_kokkos_enabled = lmp.has_package('KOKKOS')
print(f"KOKKOS enabled = {pkg_kokkos_enabled}")

on_gpu = False
kokkos_backends = {}
if pkg_kokkos_enabled == True:
kokkos_backends = lmp.accelerator_config["KOKKOS"]
if 'cuda' in kokkos_backends["api"]:
on_gpu = True
if on_gpu:
print(' - KOKKOS with CUDA backend')
else:
print(kokkos_backends["api"])

print("----------------------------------------------")

# this is necessary to shut down the MPI communication when Kokkos environment is active
lmp.finalize()

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