diff --git a/src/library.cpp b/src/library.cpp index 2e2f7a3d0d..1a67624f21 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -673,7 +673,8 @@ void lammps_extract_box(void *handle, double *boxlo, double *boxhi, This function sets the simulation box dimensions (upper and lower bounds and tilt factors) from the provided data and then re-initializes the box -information and all derived settings. +information and all derived settings. It may only be called before atoms +are created. \endverbatim * @@ -692,12 +693,16 @@ void lammps_reset_box(void *handle, double *boxlo, double *boxhi, BEGIN_CAPTURE { - // error if box does not exist - if ((lmp->domain->box_exist == 0) - && (lmp->comm->me == 0)) { - lmp->error->warning(FLERR,"Calling lammps_reset_box without a box"); + if (lmp->atom->natoms > 0) + lmp->error->all(FLERR,"Calling lammps_reset_box not supported when atoms exist"); + + // warn and do nothing if no box exists + if (lmp->domain->box_exist == 0) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,"Ignoring call to lammps_reset_box without a box"); return; } + domain->boxlo[0] = boxlo[0]; domain->boxlo[1] = boxlo[1]; domain->boxlo[2] = boxlo[2]; diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 07e920bda7..cd405bfb93 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -161,6 +161,8 @@ TEST_F(LibraryProperties, box) boxhi[1] = 7.3; xy = 0.1; if (!verbose) ::testing::internal::CaptureStdout(); + // lammps_reset_box() may only be called without atoms + lammps_command(lmp, "delete_atoms group all bond yes"); lammps_reset_box(lmp, boxlo, boxhi, xy, yz, xz); if (!verbose) ::testing::internal::GetCapturedStdout(); lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag);