Skip to content

Commit

Permalink
Update examples and docs (cesmix-mit#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy authored Jun 25, 2024
1 parent b5e0d6d commit b465b83
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LAMMPS"
uuid = "ee2e13b9-eee9-4449-aafa-cfa6a2dbe14d"
authors = ["Valentin Churavy <v.churavy@gmail.com>"]
version = "0.4.0"
version = "0.4.1"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
37 changes: 23 additions & 14 deletions examples/lj_forces.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
using LAMMPS

lmp = LMP()
command(lmp, "units lj")
command(lmp, "atom_style atomic")
command(lmp, "atom_modify map array sort 0 0")
command(lmp, "box tilt large")

command(lmp, """
units lj
atom_style atomic
atom_modify map array sort 0 0
box tilt large
""")

# Setup box
x_hi = 10.0
y_hi = 10.0
z_hi = 10.0
command(lmp, "boundary p p p")
command(lmp, "region cell block 0 $x_hi 0 $y_hi 0 $z_hi units box")
command(lmp, "create_box 1 cell")
command(lmp, """
boundary p p p
region cell block 0 $x_hi 0 $y_hi 0 $z_hi units box
create_box 1 cell
""")

# Setup style
command(lmp, "pair_style lj/cut 2.5")
command(lmp, "pair_coeff * * 1 1") # TODO
command(lmp, """
pair_style lj/cut 2.5
pair_coeff * * 1 1
""")

# Setup atoms
natoms = 10
command(lmp, "create_atoms 1 random $natoms 1 NULL")
command(lmp, "mass 1 1.0")
command(lmp, """
create_atoms 1 random $natoms 1 NULL
mass 1 1.0
""")

# (x,y,z), natoms
positions = rand(3, 10) .* 5
LAMMPS.API.lammps_scatter_atoms(lmp, "x", 1, 3, positions)
scatter!(lmp, "x", positions)

# Compute pot_e
command(lmp, "compute pot_e all pe")

command(lmp, "run 0")

# extract output
forces = extract_atom(lmp, "f")
energies = extract_compute(lmp, "pot_e", LAMMPS.API.LMP_STYLE_GLOBAL, LAMMPS.API.LMP_TYPE_SCALAR)
forces = gather(lmp, "f")
energies = gather(lmp, "pot_e")
37 changes: 18 additions & 19 deletions examples/snap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,26 @@ using LAMMPS
const DATA = joinpath(dirname(pathof(LAMMPS)), "..", "examples", "example_GaN_data")

function run_snap(lmp, path, rcut, twojmax)
read_data_str = "read_data " * path

command(lmp, "log none")
command(lmp, "units metal")
command(lmp, "boundary p p p")
command(lmp, "atom_style atomic")
command(lmp, "atom_modify map array")
command(lmp, read_data_str)
command(lmp, "pair_style zero $rcut")
command(lmp, "pair_coeff * *")
command(lmp, "compute PE all pe")
command(lmp, "compute S all pressure thermo_temp")
command(lmp, "compute SNA all sna/atom $rcut 0.99363 $twojmax 0.5 0.5 1.0 0.5 rmin0 0.0 bzeroflag 0 quadraticflag 0 switchflag 1")
command(lmp, "compute SNAD all snad/atom $rcut 0.99363 $twojmax 0.5 0.5 1.0 0.5 rmin0 0.0 bzeroflag 0 quadraticflag 0 switchflag 1")
command(lmp, "compute SNAV all snav/atom $rcut 0.99363 $twojmax 0.5 0.5 1.0 0.5 rmin0 0.0 bzeroflag 0 quadraticflag 0 switchflag 1")
command(lmp, "thermo_style custom pe")
command(lmp, "run 0")
command(lmp, """
log none
units metal
boundary p p p
atom_style atomic
atom_modify map array
read_data $path
pair_style zero $rcut
pair_coeff * *
compute PE all pe
compute S all pressure thermo_temp
compute SNA all sna/atom $rcut 0.99363 $twojmax 0.5 0.5 1.0 0.5 rmin0 0.0 bzeroflag 0 quadraticflag 0 switchflag 1
compute SNAD all snad/atom $rcut 0.99363 $twojmax 0.5 0.5 1.0 0.5 rmin0 0.0 bzeroflag 0 quadraticflag 0 switchflag 1
compute SNAV all snav/atom $rcut 0.99363 $twojmax 0.5 0.5 1.0 0.5 rmin0 0.0 bzeroflag 0 quadraticflag 0 switchflag 1
thermo_style custom pe
run 0
""")

## Extract bispectrum
bs = extract_compute(lmp, "SNA", LAMMPS.API.LMP_STYLE_ATOM,
LAMMPS.API.LMP_TYPE_ARRAY)
bs = gather(lmp, "SNA", Float64)
return bs
end

Expand Down
25 changes: 22 additions & 3 deletions src/LAMMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,28 @@ After this processing the string is handed to LAMMPS for parsing and executing.
Arrays of Strings get concatenated into a single String inserting newline characters as needed.
!!! warning "Newline Characters"
Old versions of this package (0.4.0 or older) used to ignore newline characters,
such that `cmd` would allways be treated as a single command. In newer version this is no longer the case.
!!! compat "LAMMPS.jl 0.4.1"
Multiline string support `\"""` and support for array of strings was added.
Prior versions of LAMMPS.jl ignore newline characters.
# Examples
```
LMP(["-screen", "none"]) do lmp
command(lmp, \"""
atom_modify map yes
region cell block 0 2 0 2 0 2
create_box 1 cell
lattice sc 1
create_atoms 1 region cell
mass 1 1
group a id 1 2 3 5 8
group even id 2 4 6 8
group odd id 1 3 5 7
\""")
end
```
"""
function command(lmp::LMP, cmd::Union{String, Array{String}})
if cmd isa String
Expand Down

0 comments on commit b465b83

Please sign in to comment.