Merge branch 'develop' into group-bitmap-accessor

This commit is contained in:
Axel Kohlmeyer
2024-09-06 17:10:27 -04:00
87 changed files with 5113 additions and 3509 deletions

View File

@ -49,6 +49,7 @@ protected:
if (verbose) std::cout << output;
EXPECT_THAT(output, StartsWith("LAMMPS ("));
}
void TearDown() override
{
::testing::internal::CaptureStdout();
@ -470,9 +471,9 @@ TEST_F(LibraryProperties, global)
EXPECT_EQ(lammps_extract_global_datatype(lmp, "xlattice"), LAMMPS_DOUBLE);
EXPECT_EQ(lammps_extract_global_datatype(lmp, "ylattice"), LAMMPS_DOUBLE);
EXPECT_EQ(lammps_extract_global_datatype(lmp, "zlattice"), LAMMPS_DOUBLE);
auto *xlattice = (double *)lammps_extract_global(lmp, "xlattice");
auto *ylattice = (double *)lammps_extract_global(lmp, "ylattice");
auto *zlattice = (double *)lammps_extract_global(lmp, "zlattice");
auto *xlattice = (double *)lammps_extract_global(lmp, "xlattice");
auto *ylattice = (double *)lammps_extract_global(lmp, "ylattice");
auto *zlattice = (double *)lammps_extract_global(lmp, "zlattice");
EXPECT_NE(xlattice, nullptr);
EXPECT_NE(ylattice, nullptr);
EXPECT_NE(zlattice, nullptr);
@ -484,9 +485,9 @@ TEST_F(LibraryProperties, global)
lammps_command(lmp, "units real");
lammps_command(lmp, "lattice fcc 2.0");
if (!verbose) ::testing::internal::GetCapturedStdout();
xlattice = (double *)lammps_extract_global(lmp, "xlattice");
ylattice = (double *)lammps_extract_global(lmp, "ylattice");
zlattice = (double *)lammps_extract_global(lmp, "zlattice");
xlattice = (double *)lammps_extract_global(lmp, "xlattice");
ylattice = (double *)lammps_extract_global(lmp, "ylattice");
zlattice = (double *)lammps_extract_global(lmp, "zlattice");
EXPECT_NE(xlattice, nullptr);
EXPECT_NE(ylattice, nullptr);
EXPECT_NE(zlattice, nullptr);
@ -694,11 +695,10 @@ TEST_F(LibraryProperties, has_error)
class AtomProperties : public ::testing::Test {
protected:
void *lmp;
int ntypes, nlocal, nall;
AtomProperties() = default;
;
AtomProperties() = default;
~AtomProperties() override = default;
;
void SetUp() override
{
@ -713,11 +713,30 @@ protected:
if (verbose) std::cout << output;
EXPECT_THAT(output, StartsWith("LAMMPS ("));
::testing::internal::CaptureStdout();
lammps_command(lmp, "fix props all property/atom i_one i2_two 2 d_three d2_four 2");
lammps_command(lmp, "fix rmass all property/atom mol q rmass ghost yes");
lammps_command(lmp, "region box block 0 2 0 2 0 2");
lammps_command(lmp, "create_box 1 box");
lammps_command(lmp, "mass 1 3.0");
lammps_command(lmp, "create_atoms 1 single 1.0 1.0 1.5");
lammps_command(lmp, "create_atoms 1 single 0.2 0.1 0.1");
lammps_command(lmp, "set group all mass 2.0");
lammps_command(lmp, "set atom 1 charge -1");
lammps_command(lmp, "set atom 2 charge 1");
lammps_command(lmp, "set atom 1 mol 2");
lammps_command(lmp, "set atom 2 mol 1");
lammps_command(lmp, "set atom 1 i_one -3");
lammps_command(lmp, "set atom 2 i_one 3");
lammps_command(lmp, "set atom 1 d_three -1.3");
lammps_command(lmp, "set atom 2 d_three 3.5");
lammps_command(lmp, "set atom 1 i_two[1] -3");
lammps_command(lmp, "set atom 2 i_two[2] 3");
lammps_command(lmp, "set atom * d_four[1] -1.3");
lammps_command(lmp, "set atom * d_four[2] 3.5");
ntypes = lammps_extract_setting(lmp, "ntypes");
nlocal = lammps_extract_setting(lmp, "nlocal");
nall = lammps_extract_setting(lmp, "nall");
output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output;
}
@ -740,14 +759,42 @@ TEST_F(AtomProperties, invalid)
TEST_F(AtomProperties, mass)
{
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "mass"), LAMMPS_DOUBLE);
EXPECT_EQ(lammps_extract_atom_size(lmp, "mass", 0), ntypes + 1);
auto *mass = (double *)lammps_extract_atom(lmp, "mass");
ASSERT_NE(mass, nullptr);
ASSERT_DOUBLE_EQ(mass[1], 3.0);
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "rmass"), LAMMPS_DOUBLE);
EXPECT_EQ(lammps_extract_atom_size(lmp, "rmass", 0), nall);
mass = (double *)lammps_extract_atom(lmp, "rmass");
ASSERT_NE(mass, nullptr);
ASSERT_DOUBLE_EQ(mass[0], 2.0);
ASSERT_DOUBLE_EQ(mass[1], 2.0);
}
TEST_F(AtomProperties, charge)
{
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "q"), LAMMPS_DOUBLE);
EXPECT_EQ(lammps_extract_atom_size(lmp, "rmass", 0), nall);
auto *charge = (double *)lammps_extract_atom(lmp, "q");
ASSERT_NE(charge, nullptr);
ASSERT_DOUBLE_EQ(charge[0], -1.0);
ASSERT_DOUBLE_EQ(charge[1], 1.0);
}
TEST_F(AtomProperties, molecule)
{
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "molecule"), LAMMPS_TAGINT);
EXPECT_EQ(lammps_extract_atom_size(lmp, "molecule", 0), nall);
auto *molecule = (tagint *)lammps_extract_atom(lmp, "molecule");
ASSERT_NE(molecule, nullptr);
ASSERT_EQ(molecule[0], 2);
ASSERT_EQ(molecule[1], 1);
}
TEST_F(AtomProperties, id)
{
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "id"), LAMMPS_TAGINT);
EXPECT_EQ(lammps_extract_atom_size(lmp, "id", 0), nall);
auto *id = (tagint *)lammps_extract_atom(lmp, "id");
ASSERT_NE(id, nullptr);
ASSERT_EQ(id[0], 1);
@ -757,6 +804,7 @@ TEST_F(AtomProperties, id)
TEST_F(AtomProperties, type)
{
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "type"), LAMMPS_INT);
EXPECT_EQ(lammps_extract_atom_size(lmp, "type", 0), nall);
int *type = (int *)lammps_extract_atom(lmp, "type");
ASSERT_NE(type, nullptr);
ASSERT_EQ(type[0], 1);
@ -766,6 +814,8 @@ TEST_F(AtomProperties, type)
TEST_F(AtomProperties, position)
{
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "x"), LAMMPS_DOUBLE_2D);
EXPECT_EQ(lammps_extract_atom_size(lmp, "x", LMP_SIZE_ROWS), nall);
EXPECT_EQ(lammps_extract_atom_size(lmp, "x", LMP_SIZE_COLS), 3);
auto **x = (double **)lammps_extract_atom(lmp, "x");
ASSERT_NE(x, nullptr);
EXPECT_DOUBLE_EQ(x[0][0], 1.0);
@ -776,6 +826,41 @@ TEST_F(AtomProperties, position)
EXPECT_DOUBLE_EQ(x[1][2], 0.1);
}
TEST_F(AtomProperties, custom)
{
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "i_one"), LAMMPS_INT);
EXPECT_EQ(lammps_extract_atom_size(lmp, "i_one", 0), nlocal);
auto *one = (int *)lammps_extract_atom(lmp, "i_one");
ASSERT_NE(one, nullptr);
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "i2_two"), LAMMPS_INT_2D);
EXPECT_EQ(lammps_extract_atom_size(lmp, "i2_two", LMP_SIZE_ROWS), nlocal);
EXPECT_EQ(lammps_extract_atom_size(lmp, "i2_two", LMP_SIZE_COLS), 2);
auto **two = (int **)lammps_extract_atom(lmp, "i2_two");
ASSERT_NE(two, nullptr);
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "d_three"), LAMMPS_DOUBLE);
EXPECT_EQ(lammps_extract_atom_size(lmp, "d_three", 0), nlocal);
auto *three = (double *)lammps_extract_atom(lmp, "d_three");
ASSERT_NE(three, nullptr);
EXPECT_EQ(lammps_extract_atom_datatype(lmp, "d2_four"), LAMMPS_DOUBLE_2D);
EXPECT_EQ(lammps_extract_atom_size(lmp, "d2_four", LMP_SIZE_ROWS), nlocal);
EXPECT_EQ(lammps_extract_atom_size(lmp, "d2_four", LMP_SIZE_COLS), 2);
auto **four = (double **)lammps_extract_atom(lmp, "d2_four");
ASSERT_NE(four, nullptr);
EXPECT_EQ(one[0], -3);
EXPECT_EQ(one[1], 3);
EXPECT_EQ(two[0][0], -3);
EXPECT_EQ(two[0][1], 0);
EXPECT_EQ(two[1][0], 0);
EXPECT_EQ(two[1][1], 3);
EXPECT_DOUBLE_EQ(three[0], -1.3);
EXPECT_DOUBLE_EQ(three[1], 3.5);
EXPECT_DOUBLE_EQ(four[0][0], -1.3);
EXPECT_DOUBLE_EQ(four[0][1], 3.5);
EXPECT_DOUBLE_EQ(four[1][0], -1.3);
EXPECT_DOUBLE_EQ(four[1][1], 3.5);
}
TEST(SystemSettings, kokkos)
{
if (!lammps_config_has_package("KOKKOS")) GTEST_SKIP();

View File

@ -88,10 +88,9 @@ for header in headers:
style = m[1]
if upper.match(style):
continue
if style in ['reax/c', 'reax/c/omp', 'reax/c/kk',
'reax/c/kk/device', 'reax/c/kk/host',
'reax/c/species', 'reax/c/bonds',
'reax/c/species/kk', 'reax/c/bonds/kk', 'meam/c']:
if style in ['lj/sdk', 'lj/sdk/coul/long', 'lj/sdk/coul/msm', 'sdk', 'lj/sdk/gpu',
'lj/sdk/coul/long/gpu', 'lj/sdk/omp', 'lj/sdk/coul/long/omp', 'sdk/omp',
'lj/sdk/coul/msm/omp', 'lj/sdk/kk', 'lj/sdk/coul/long/kk', 'sdk/kk']:
continue
# detect, process, and flag suffix styles:
@ -176,11 +175,12 @@ def check_tests(name,styles,yaml,search,skip=()):
counter = 0
counter += check_tests('pair',pair,'*-pair-*.yaml',
'.*pair_style:\\s*((\\S+).*)?',skip=('meam','lj/sf'))
'.*pair_style:\\s*((\\S+).*)?',
skip=('lj/sf','lj/sdk', 'lj/sdk/coul/long', 'lj/sdk/coul/msm'))
counter += check_tests('bond',bond,'bond-*.yaml',
'.*bond_style:\\s*((\\S+).*)?')
counter += check_tests('angle',angle,'angle-*.yaml',
'.*angle_style:\\s*((\\S+).*)?')
'.*angle_style:\\s*((\\S+).*)?', skip=('sdk'))
counter += check_tests('dihedral',dihedral,'dihedral-*.yaml',
'.*dihedral_style:\\s*((\\S+).*)?')
counter += check_tests('improper',improper,'improper-*.yaml',

View File

@ -4,9 +4,9 @@ MODULE keepstuff
TYPE(LAMMPS), SAVE :: lmp
INTEGER, SAVE :: mycomm
CHARACTER(LEN=40), DIMENSION(3), PARAMETER :: demo_input = &
[ CHARACTER(LEN=40) :: &
'region box block 0 $x 0 2 0 2', &
'create_box 1 box', &
[ CHARACTER(LEN=40) :: &
'region box block 0 $x 0 2 0 2', &
'create_box 1 box', &
'create_atoms 1 single 1.0 1.0 ${zpos}' ]
CHARACTER(LEN=40), DIMENSION(3), PARAMETER :: big_input = &
[ CHARACTER(LEN=40) :: &
@ -14,15 +14,26 @@ MODULE keepstuff
'create_box 1 box', &
'create_atoms 1 single 1.0 1.0 ${zpos}' ]
CHARACTER(LEN=40), DIMENSION(2), PARAMETER :: cont_input = &
[ CHARACTER(LEN=40) :: &
'create_atoms 1 single &', &
[ CHARACTER(LEN=40) :: &
'create_atoms 1 single &', &
' 0.2 0.1 0.1' ]
CHARACTER(LEN=60), DIMENSION(18), PARAMETER :: prop_input = &
[ CHARACTER(LEN=60) :: 'fix 1 all nve', 'mass 1 3.0', &
'fix 2 all property/atom mol q rmass ghost yes', &
'fix 3 all property/atom i_one i2_two 2 d_three d2_four 2', &
'set group all mass 2.0', 'set atom 1 charge -1', &
'set atom 2 charge 1', 'set atom 1 mol 2', 'set atom 2 mol 1', &
'set atom 1 i_one -3', 'set atom 2 i_one 3', &
'set atom 1 d_three -1.3', 'set atom 2 d_three 3.5', &
'set atom 1 i_two[1] -3', 'set atom 2 i_two[2] 3', &
'set atom * d_four[1] -1.3', 'set atom * d_four[2] 3.5', &
'run 0 post no' ]
CHARACTER(LEN=40), DIMENSION(1), PARAMETER :: more_input = &
[ CHARACTER(LEN=40) :: 'create_atoms 1 single 0.5 0.5 0.5' ]
CHARACTER(LEN=40), DIMENSION(3), PARAMETER :: pair_input = &
[ CHARACTER(LEN=40) :: &
'pair_style lj/cut 2.5', &
'pair_coeff 1 1 1.0 1.0', &
[ CHARACTER(LEN=40) :: &
'pair_style lj/cut 2.5', &
'pair_coeff 1 1 1.0 1.0', &
'mass 1 2.0' ]
INTERFACE
@ -63,4 +74,3 @@ CONTAINS
END FUNCTION f2c_string
END MODULE keepstuff

View File

@ -24,12 +24,13 @@ END SUBROUTINE f_lammps_close
SUBROUTINE f_lammps_setup_extract_atom() BIND(C)
USE LIBLAMMPS
USE keepstuff, ONLY : lmp, big_input, cont_input, pair_input
USE keepstuff, ONLY : lmp, big_input, cont_input, pair_input, prop_input
IMPLICIT NONE
CALL lmp%commands_list(big_input)
CALL lmp%commands_list(cont_input)
CALL lmp%commands_list(pair_input)
CALL lmp%commands_list(prop_input)
END SUBROUTINE f_lammps_setup_extract_atom
FUNCTION f_lammps_extract_atom_mass() BIND(C)
@ -44,6 +45,19 @@ FUNCTION f_lammps_extract_atom_mass() BIND(C)
f_lammps_extract_atom_mass = mass(1)
END FUNCTION f_lammps_extract_atom_mass
FUNCTION f_lammps_extract_atom_mass_size() BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int) :: f_lammps_extract_atom_mass_size, ntypes
REAL(c_double), DIMENSION(:), POINTER :: mass => NULL()
ntypes = lmp%extract_setting('ntypes')
mass = lmp%extract_atom('mass')
f_lammps_extract_atom_mass_size = SIZE(mass)
END FUNCTION f_lammps_extract_atom_mass_size
FUNCTION f_lammps_extract_atom_tag_int(i) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
@ -83,6 +97,18 @@ FUNCTION f_lammps_extract_atom_type(i) BIND(C)
f_lammps_extract_atom_type = atype(i)
END FUNCTION f_lammps_extract_atom_type
FUNCTION f_lammps_extract_atom_type_size() BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int) :: f_lammps_extract_atom_type_size
INTEGER(c_int), DIMENSION(:), POINTER :: atype => NULL()
atype = lmp%extract_atom('type')
f_lammps_extract_atom_type_size = size(atype)
END FUNCTION f_lammps_extract_atom_type_size
FUNCTION f_lammps_extract_atom_mask(i) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_int
USE LIBLAMMPS
@ -109,6 +135,19 @@ SUBROUTINE f_lammps_extract_atom_x(i, x) BIND(C)
x = xptr(:,i)
END SUBROUTINE f_lammps_extract_atom_x
FUNCTION f_lammps_extract_atom_x_size(i) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int), INTENT(IN), VALUE :: i
INTEGER(c_int) :: f_lammps_extract_atom_x_size
REAL(c_double), DIMENSION(:,:), POINTER :: xptr => NULL()
xptr = lmp%extract_atom('x')
f_lammps_extract_atom_x_size = SIZE(xptr, i)
END FUNCTION f_lammps_extract_atom_x_size
SUBROUTINE f_lammps_extract_atom_v(i, v) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
@ -121,3 +160,16 @@ SUBROUTINE f_lammps_extract_atom_v(i, v) BIND(C)
vptr = lmp%extract_atom('v')
v = vptr(:,i)
END SUBROUTINE f_lammps_extract_atom_v
FUNCTION f_lammps_extract_atom_v_size(i) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int
USE LIBLAMMPS
USE keepstuff, ONLY : lmp
IMPLICIT NONE
INTEGER(c_int), INTENT(IN), VALUE :: i
INTEGER(c_int) :: f_lammps_extract_atom_v_size
REAL(c_double), DIMENSION(:,:), POINTER :: xptr => NULL()
xptr = lmp%extract_atom('v')
f_lammps_extract_atom_v_size = SIZE(xptr, i)
END FUNCTION f_lammps_extract_atom_v_size

View File

@ -1,6 +1,7 @@
// unit tests for extracting Atom class data from a LAMMPS instance through the
// Fortran wrapper
#include "atom.h"
#include "lammps.h"
#include "library.h"
#include <cstdint>
@ -16,12 +17,16 @@ void *f_lammps_with_args();
void f_lammps_close();
void f_lammps_setup_extract_atom();
double f_lammps_extract_atom_mass();
int f_lammps_extract_atom_mass_size();
int f_lammps_extract_atom_tag_int(int);
int64_t f_lammps_extract_atom_tag_int64(int64_t);
int f_lammps_extract_atom_type(int);
int f_lammps_extract_atom_type_size();
int f_lammps_extract_atom_mask(int);
void f_lammps_extract_atom_x(int, double *);
int f_lammps_extract_atom_x_size(int);
void f_lammps_extract_atom_v(int, double *);
int f_lammps_extract_atom_v_size(int);
}
class LAMMPS_extract_atom : public ::testing::Test {
@ -50,7 +55,9 @@ protected:
TEST_F(LAMMPS_extract_atom, mass)
{
f_lammps_setup_extract_atom();
EXPECT_DOUBLE_EQ(f_lammps_extract_atom_mass(), 2.0);
int ntypes = lmp->atom->ntypes;
EXPECT_DOUBLE_EQ(f_lammps_extract_atom_mass(), 3.0);
EXPECT_EQ(f_lammps_extract_atom_mass_size(), ntypes + 1);
};
TEST_F(LAMMPS_extract_atom, tag)
@ -68,8 +75,10 @@ TEST_F(LAMMPS_extract_atom, tag)
TEST_F(LAMMPS_extract_atom, type)
{
f_lammps_setup_extract_atom();
int nall = lmp->atom->nlocal + lmp->atom->nghost;
EXPECT_EQ(f_lammps_extract_atom_type(1), 1);
EXPECT_EQ(f_lammps_extract_atom_type(2), 1);
EXPECT_EQ(f_lammps_extract_atom_type_size(), nall);
};
TEST_F(LAMMPS_extract_atom, mask)
@ -86,6 +95,7 @@ TEST_F(LAMMPS_extract_atom, mask)
TEST_F(LAMMPS_extract_atom, x)
{
f_lammps_setup_extract_atom();
int nall = lmp->atom->nlocal + lmp->atom->nghost;
double x1[3];
double x2[3];
f_lammps_extract_atom_x(1, x1);
@ -96,11 +106,15 @@ TEST_F(LAMMPS_extract_atom, x)
EXPECT_DOUBLE_EQ(x2[0], 0.2);
EXPECT_DOUBLE_EQ(x2[1], 0.1);
EXPECT_DOUBLE_EQ(x2[2], 0.1);
// in Fortran row and column are swapped
EXPECT_EQ(f_lammps_extract_atom_x_size(1), 3);
EXPECT_EQ(f_lammps_extract_atom_x_size(2), nall);
}
TEST_F(LAMMPS_extract_atom, v)
{
f_lammps_setup_extract_atom();
int nall = lmp->atom->nlocal + lmp->atom->nghost;
double v1[3];
double v2[3];
f_lammps_extract_atom_v(1, v1);
@ -117,4 +131,13 @@ TEST_F(LAMMPS_extract_atom, v)
EXPECT_DOUBLE_EQ(v1[0], 1.0);
EXPECT_DOUBLE_EQ(v1[1], 2.0);
EXPECT_DOUBLE_EQ(v1[2], 3.0);
// in Fortran row and column are swapped!
EXPECT_EQ(f_lammps_extract_atom_v_size(1), 3);
EXPECT_EQ(f_lammps_extract_atom_v_size(2), lmp->atom->nlocal);
lammps_command(lmp, "comm_modify vel yes");
lammps_command(lmp, "run 0 post no");
EXPECT_EQ(f_lammps_extract_atom_v_size(1), 3);
EXPECT_EQ(f_lammps_extract_atom_v_size(2), nall);
}
// TODO: write tests for custom properties

View File

@ -155,67 +155,104 @@ class PythonNumpy(unittest.TestCase):
self.assertEqual(values[1,0], 1.5)
self.assertEqual(values[1,3], 1.5)
def testExtractAtomDeprecated(self):
self.lmp.command("units lj")
self.lmp.command("atom_style atomic")
self.lmp.command("atom_modify map array")
self.lmp.command("region box block 0 2 0 2 0 2")
self.lmp.command("create_box 1 box")
x = [
1.0, 1.0, 1.0,
1.0, 1.0, 1.5
]
types = [1, 1]
self.assertEqual(self.lmp.create_atoms(2, id=None, type=types, x=x), 2)
nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT)
self.assertEqual(nlocal, 2)
ident = self.lmp.numpy.extract_atom_iarray("id", nlocal, dim=1)
self.assertEqual(len(ident), 2)
ntypes = self.lmp.extract_global("ntypes", LAMMPS_INT)
self.assertEqual(ntypes, 1)
x = self.lmp.numpy.extract_atom_darray("x", nlocal, dim=3)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
self.assertEqual(len(x), 2)
self.assertTrue((x[0] == (1.0, 1.0, 1.0)).all())
self.assertTrue((x[1] == (1.0, 1.0, 1.5)).all())
self.assertEqual(len(v), 2)
def testExtractAtom(self):
self.lmp.command("units lj")
self.lmp.command("atom_style atomic")
self.lmp.command("atom_modify map array")
self.lmp.command("region box block 0 2 0 2 0 2")
self.lmp.command("create_box 1 box")
self.lmp.command("create_box 2 box")
x = [
1.0, 1.0, 1.0,
1.0, 1.0, 1.5
]
x = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.5, 1.5, 1.0, 1.0 ]
types = [1, 2, 1]
ids = [1, 2, 3]
self.assertEqual(self.lmp.create_atoms(3, id=ids, type=types, x=x), 3)
self.lmp.command("mass * 2.0")
self.lmp.command("pair_style zero 1.1")
self.lmp.command("pair_coeff * *")
self.lmp.command("fix props all property/atom i_one i2_two 2 d_three d2_four 2");
self.lmp.command("fix rmass all property/atom mol q rmass ghost yes");
self.lmp.command("fix 1 all nve")
self.lmp.command("run 0 post no")
ntypes = self.lmp.extract_setting("ntypes");
nlocal = self.lmp.extract_setting("nlocal");
nall = self.lmp.extract_setting("nall");
self.assertEqual(nlocal, 3)
self.assertEqual(ntypes, 2)
self.assertEqual(nall, 63)
types = [1, 1]
self.lmp.command("set atom 1 charge -1");
self.lmp.command("set atom 2 charge 1");
self.lmp.command("set atom 3 charge 0");
self.lmp.command("set atom * mol 2");
self.lmp.command("set atom 2 mol 1");
self.lmp.command("set atom 1 i_one -3");
self.lmp.command("set atom 2 i_one 3");
self.lmp.command("set atom 2 d_three -1.3");
self.lmp.command("set atom 3 d_three 3.5");
self.lmp.command("set atom 1 i_two[1] -3");
self.lmp.command("set atom 2 i_two[2] 3");
self.lmp.command("set atom * d_four[1] -1.3");
self.lmp.command("set atom * d_four[2] 3.5");
self.lmp.command("run 0 post no")
self.assertEqual(self.lmp.create_atoms(2, id=None, type=types, x=x), 2)
nlocal = self.lmp.extract_global("nlocal")
self.assertEqual(nlocal, 2)
mass = self.lmp.numpy.extract_atom("mass")
self.assertEqual(len(mass), ntypes + 1)
self.assertTrue((mass == (0.0, 2.0, 2.0)).all())
rmass = self.lmp.numpy.extract_atom("rmass")
self.assertEqual(len(rmass), nall)
self.assertTrue((rmass[0:3] == (0.0, 0.0, 0.0)).all())
charge = self.lmp.numpy.extract_atom("q")
self.assertEqual(len(charge), nall)
self.assertTrue((charge[0:3] == (-1.0, 1.0, 0.0)).all())
molecule = self.lmp.numpy.extract_atom("molecule")
self.assertEqual(len(molecule), nall)
self.assertTrue((molecule[0:3] == (2, 1, 2)).all())
ident = self.lmp.numpy.extract_atom("id")
self.assertEqual(len(ident), 2)
self.assertEqual(len(ident), nall)
self.assertTrue((ident[0:3] == (1, 2, 3)).all())
ntypes = self.lmp.extract_global("ntypes")
self.assertEqual(ntypes, 1)
atype = self.lmp.numpy.extract_atom("type")
self.assertEqual(len(atype), nall)
self.assertTrue((atype[0:3] == (1, 2, 1)).all())
x = self.lmp.numpy.extract_atom("x")
v = self.lmp.numpy.extract_atom("v")
self.assertEqual(len(x), 2)
self.assertEqual(len(x), nall)
self.assertEqual(len(x[0]), 3)
self.assertTrue((x[0] == (1.0, 1.0, 1.0)).all())
self.assertTrue((x[1] == (1.0, 1.0, 1.5)).all())
self.assertEqual(len(v), 2)
self.assertTrue((x[2] == (1.5, 1.0, 1.0)).all())
self.assertEqual(len(v), nlocal)
self.assertEqual(len(v[0]), 3)
self.lmp.command("comm_modify vel yes");
self.lmp.command("run 0 post no")
v = self.lmp.numpy.extract_atom("v")
self.assertEqual(len(v), nall)
one = self.lmp.numpy.extract_atom("i_one")
two = self.lmp.numpy.extract_atom("i2_two")
three = self.lmp.numpy.extract_atom("d_three")
four = self.lmp.numpy.extract_atom("d2_four")
self.assertEqual(len(one), nlocal)
self.assertTrue((one == (-3, 3, 0)).all())
self.assertEqual(len(two), nlocal)
self.assertEqual(len(two[0]), 2)
self.assertTrue((two[0] == (-3, 0)).all())
self.assertTrue((two[1] == (0, 3)).all())
self.assertTrue((two[2] == (0, 0)).all())
self.assertEqual(len(three), nlocal)
self.assertTrue((three == (0.0, -1.3, 3.5)).all())
self.assertEqual(len(four), nlocal)
self.assertEqual(len(four[0]), 2)
self.assertTrue((four[0] == (-1.3, 3.5)).all())
self.assertTrue((four[1] == (-1.3, 3.5)).all())
self.assertTrue((four[2] == (-1.3, 3.5)).all())
@unittest.skipIf(not has_full,"Gather bonds test")
def testGatherBond_newton_on(self):