Skip to content

Commit

Permalink
support gather[bonds|angles|dihedrals|impropers]
Browse files Browse the repository at this point in the history
  • Loading branch information
Joroks committed Jul 15, 2024
1 parent ae5ada0 commit 2491043
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 4 deletions.
77 changes: 75 additions & 2 deletions src/LAMMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import MPI
include("api.jl")

export LMP, command, get_natoms, extract_atom, extract_compute, extract_global,
extract_setting, gather, scatter!, group_to_atom_ids, get_category_ids,
extract_variable,
extract_setting, gather, gather_bonds, gather_angles, gather_dihedrals, gather_impropers,
scatter!, group_to_atom_ids, get_category_ids, extract_variable,

# _LMP_DATATYPE
LAMMPS_NONE,
Expand Down Expand Up @@ -740,6 +740,79 @@ function _get_T(lmp::LMP, name::String)

end

"""
gather_bonds(lmp::LMP)
Gather the list of all bonds into a 3 x nbonds Matrix:
```
row1 -> bond type
row2 -> atom 1
row3 -> atom 2
```
"""
function gather_bonds(lmp::LMP)
ndata = extract_global(lmp, "nbonds", LAMMPS_INT64)[]
data = Matrix{Int32}(undef, 3, ndata)
API.lammps_gather_bonds(lmp, data)
return data
end

"""
gather_angles(lmp::LMP)
Gather the list of all angles into a 4 x nangles Matrix:
```
row1 -> angle type
row2 -> atom 1
row3 -> atom 2
row4 -> atom 3
```
"""
function gather_angles(lmp::LMP)
ndata = extract_global(lmp, "nangles", LAMMPS_INT64)[]
data = Matrix{Int32}(undef, 4, ndata)
API.lammps_gather_angles(lmp, data)
return data
end

"""
gather_dihedrals(lmp::LMP)
Gather the list of all dihedrals into a 5 x ndihedrals Matrix:
```
row1 -> dihedral type
row2 -> atom 1
row3 -> atom 2
row4 -> atom 3
row5 -> atom 4
```
"""
function gather_dihedrals(lmp::LMP)
ndata = extract_global(lmp, "ndihedrals", LAMMPS_INT64)[]
data = Matrix{Int32}(undef, 5, ndata)
API.lammps_gather_dihedrals(lmp, data)
return data
end

"""
gather_impropers(lmp::LMP)
Gather the list of all impropers into a 5 x nimpropers Matrix:
```
row1 -> improper type
row2 -> atom 1
row3 -> atom 2
row4 -> atom 3
row5 -> atom 4
```
"""
function gather_impropers(lmp::LMP)
ndata = extract_global(lmp, "nimpropers", LAMMPS_INT64)[]
data = Matrix{Int32}(undef, 5, ndata)
API.lammps_gather_impropers(lmp, data)
return data
end

"""
group_to_atom_ids(lmp::LMP, group::String)
Expand Down
37 changes: 35 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,41 @@ end

@test gather(lmp, "x", Float64, subset) == gather(lmp, "c_pos", Float64, subset) == gather(lmp, "f_pos", Float64, subset) == data_subset

# verify that no errors were missed
@test LAMMPS.API.lammps_has_error(lmp) == 0
# verify that no errors were missed
@test LAMMPS.API.lammps_has_error(lmp) == 0
end
end

@testset "Gather bonds/angles/dihedrals/impropers" begin
LMP(["-screen", "none"]) do lmp
file = joinpath(@__DIR__, "test_files/bonds_angles_dihedrals_impropers.data")

command(lmp, """
atom_style molecular
read_data $file
""")

@test gather_bonds(lmp) == transpose([
1 1 2
1 2 3
1 3 4
1 4 1
])
@test gather_angles(lmp) == transpose([
1 1 2 3
1 2 3 4
])
@test gather_angles(lmp) == transpose([
1 1 2 3
1 2 3 4
])
@test gather_dihedrals(lmp) == transpose([
1 1 2 3 4
])
@test gather_impropers(lmp) == transpose([
1 4 3 2 1
])
@test LAMMPS.API.lammps_has_error(lmp) == 0
end
end

Expand Down
48 changes: 48 additions & 0 deletions test/test_files/bonds_angles_dihedrals_impropers.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#

4 atoms
4 bonds
2 angles
1 dihedrals
1 impropers

1 atom types
1 bond types
1 angle types
1 dihedral types
1 improper types

-1 1 xlo xhi
-1 1 ylo yhi
-1 1 zlo zhi

Masses

1 1

Atoms # molecular

1 1 1 0 0 0
2 1 1 0 0 0
3 1 1 0 0 0
4 1 1 0 0 0

Bonds

1 1 1 2
2 1 2 3
3 1 3 4
4 1 4 1

Angles

1 1 1 2 3
2 1 2 3 4

Dihedrals

1 1 1 2 3 4

Impropers

1 1 4 3 2 1

0 comments on commit 2491043

Please sign in to comment.