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

Update examples and docs #47

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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 <[email protected]>"]
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
vchuravy marked this conversation as resolved.
Show resolved Hide resolved
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")
33 changes: 18 additions & 15 deletions examples/snap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ const DATA = joinpath(dirname(pathof(LAMMPS)), "..", "examples", "example_GaN_da
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
ead_data_st
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
vchuravy marked this conversation as resolved.
Show resolved Hide resolved
thermo_style custom pe
run 0
""")

## Extract bispectrum
bs = extract_compute(lmp, "SNA", LAMMPS.API.LMP_STYLE_ATOM,
vchuravy marked this conversation as resolved.
Show resolved Hide resolved
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
Loading