Merge pull request #3089 from akohlmey/collected-small-changes

Collected small changes and fixes
This commit is contained in:
Axel Kohlmeyer
2022-01-19 11:44:33 -05:00
committed by GitHub
15 changed files with 254 additions and 311 deletions

View File

@ -122,6 +122,9 @@ class lammps(object):
for f in os.listdir(winpath)]):
lib_ext = ".dll"
modpath = winpath
elif any([f.startswith('liblammps') and f.endswith('.so')
for f in os.listdir(modpath)]):
lib_ext = ".so"
else:
import platform
if platform.system() == "Darwin":

View File

@ -67,33 +67,7 @@ MSM::MSM(LAMMPS *lmp)
factors[0] = 2;
MPI_Comm_rank(world,&me);
phi1d = dphi1d = nullptr;
nmax = 0;
part2grid = nullptr;
g_direct = nullptr;
g_direct_top = nullptr;
v0_direct = v1_direct = v2_direct = nullptr;
v3_direct = v4_direct = v5_direct = nullptr;
v0_direct_top = v1_direct_top = v2_direct_top = nullptr;
v3_direct_top = v4_direct_top = v5_direct_top = nullptr;
ngrid = nullptr;
alpha = betax = betay = betaz = nullptr;
nx_msm = ny_msm = nz_msm = nullptr;
nxlo_in = nylo_in = nzlo_in = nullptr;
nxhi_in = nyhi_in = nzhi_in = nullptr;
nxlo_out = nylo_out = nzlo_out = nullptr;
nxhi_out = nyhi_out = nzhi_out = nullptr;
delxinv = delyinv = delzinv = nullptr;
qgrid = nullptr;
egrid = nullptr;
v0grid = v1grid = v2grid = v3grid = v4grid = v5grid = nullptr;
peratom_allocate_flag = 0;
scalar_pressure_flag = 1;
@ -116,7 +90,7 @@ void MSM::settings(int narg, char **arg)
MSM::~MSM()
{
delete [] factors;
delete[] factors;
deallocate();
if (peratom_allocate_flag) deallocate_peratom();
deallocate_levels();
@ -311,6 +285,11 @@ double MSM::estimate_total_error()
void MSM::setup()
{
// change_box may trigger MSM::setup() before MSM::init() was called
// error out and request full initialization.
if (!delxinv) error->all(FLERR, "MSM must be fully initialized for this operation");
double *prd;
double a = cutoff;
@ -626,15 +605,19 @@ void MSM::allocate()
gcall->setup(ngcall_buf1,ngcall_buf2);
npergrid = 1;
memory->destroy(gcall_buf1);
memory->destroy(gcall_buf2);
memory->create(gcall_buf1,npergrid*ngcall_buf1,"msm:gcall_buf1");
memory->create(gcall_buf2,npergrid*ngcall_buf2,"msm:gcall_buf2");
// allocate memory for each grid level
for (int n=0; n<levels; n++) {
memory->destroy3d_offset(qgrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]);
memory->create3d_offset(qgrid[n],nzlo_out[n],nzhi_out[n],
nylo_out[n],nyhi_out[n],nxlo_out[n],nxhi_out[n],"msm:qgrid");
memory->destroy3d_offset(egrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]);
memory->create3d_offset(egrid[n],nzlo_out[n],nzhi_out[n],
nylo_out[n],nyhi_out[n],nxlo_out[n],nxhi_out[n],"msm:egrid");
@ -654,6 +637,8 @@ void MSM::allocate()
gc[n]->setup(ngc_buf1[n],ngc_buf2[n]);
npergrid = 1;
memory->destroy(gc_buf1[n]);
memory->destroy(gc_buf2[n]);
memory->create(gc_buf1[n],npergrid*ngc_buf1[n],"msm:gc_buf1");
memory->create(gc_buf2[n],npergrid*ngc_buf2[n],"msm:gc_buf2");
} else {
@ -835,11 +820,15 @@ void MSM::deallocate_levels()
{
if (world_levels) {
for (int n=0; n < levels; ++n) {
if (qgrid[n])
if (qgrid[n]) {
memory->destroy3d_offset(qgrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]);
qgrid[n] = nullptr;
}
if (egrid[n])
if (egrid[n]) {
memory->destroy3d_offset(egrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]);
egrid[n] = nullptr;
}
if (gc) {
if (gc[n]) {
@ -857,57 +846,57 @@ void MSM::deallocate_levels()
}
}
delete [] ngrid;
delete[] ngrid;
ngrid = nullptr;
memory->destroy(procneigh_levels);
delete [] world_levels;
delete [] active_flag;
delete[] world_levels;
delete[] active_flag;
delete [] gc;
delete [] gc_buf1;
delete [] gc_buf2;
delete [] ngc_buf1;
delete [] ngc_buf2;
delete[] gc;
delete[] gc_buf1;
delete[] gc_buf2;
delete[] ngc_buf1;
delete[] ngc_buf2;
delete [] alpha;
delete [] betax;
delete [] betay;
delete [] betaz;
delete[] alpha;
delete[] betax;
delete[] betay;
delete[] betaz;
delete [] nx_msm;
delete [] ny_msm;
delete [] nz_msm;
delete[] nx_msm;
delete[] ny_msm;
delete[] nz_msm;
delete [] nxlo_in;
delete [] nylo_in;
delete [] nzlo_in;
delete[] nxlo_in;
delete[] nylo_in;
delete[] nzlo_in;
delete [] nxhi_in;
delete [] nyhi_in;
delete [] nzhi_in;
delete[] nxhi_in;
delete[] nyhi_in;
delete[] nzhi_in;
delete [] nxlo_out;
delete [] nylo_out;
delete [] nzlo_out;
delete[] nxlo_out;
delete[] nylo_out;
delete[] nzlo_out;
delete [] nxhi_out;
delete [] nyhi_out;
delete [] nzhi_out;
delete[] nxhi_out;
delete[] nyhi_out;
delete[] nzhi_out;
delete [] delxinv;
delete [] delyinv;
delete [] delzinv;
delete[] delxinv;
delete[] delyinv;
delete[] delzinv;
delete [] qgrid;
delete [] egrid;
delete[] qgrid;
delete[] egrid;
delete [] v0grid;
delete [] v1grid;
delete [] v2grid;
delete [] v3grid;
delete [] v4grid;
delete [] v5grid;
delete[] v0grid;
delete[] v1grid;
delete[] v2grid;
delete[] v3grid;
delete[] v4grid;
delete[] v5grid;
world_levels = nullptr;
active_flag = nullptr;
@ -1060,8 +1049,7 @@ void MSM::set_grid_global()
}
if (flag && gridflag && me == 0)
error->warning(FLERR,
"Number of MSM mesh points changed to be a multiple of 2");
error->warning(FLERR, "Number of MSM mesh points changed to be a multiple of 2");
// adjust Coulombic cutoff to give desired error (if requested)
@ -1087,8 +1075,7 @@ void MSM::set_grid_global()
*p_cutoff = cutoff;
if (me == 0)
error->warning(FLERR,"Adjusting Coulombic cutoff for "
"MSM, new cutoff = {:.8}", cutoff);
error->warning(FLERR,"Adjusting Coulombic cutoff for MSM, new cutoff = {:.8}", cutoff);
}
if (triclinic == 0) {

View File

@ -197,11 +197,9 @@ void PPPM::init()
error->all(FLERR,"Must redefine kspace_style after changing to triclinic box");
if (domain->triclinic && differentiation_flag == 1)
error->all(FLERR,"Cannot (yet) use PPPM with triclinic box "
"and kspace_modify diff ad");
error->all(FLERR,"Cannot (yet) use PPPM with triclinic box and kspace_modify diff ad");
if (domain->triclinic && slabflag)
error->all(FLERR,"Cannot (yet) use PPPM with triclinic box and "
"slab correction");
error->all(FLERR,"Cannot (yet) use PPPM with triclinic box and slab correction");
if (domain->dimension == 2)
error->all(FLERR,"Cannot use PPPM with 2d simulation");

View File

@ -499,10 +499,13 @@ void PairEAMCD::read_h_coeff(char *filename)
// Seek to end of file, read last part into a buffer and
// then skip over lines in buffer until reaching the end.
platform::fseek(fptr, platform::END_OF_FILE);
platform::fseek(fptr, platform::ftell(fptr) - MAXLINE);
if ( (platform::fseek(fptr, platform::END_OF_FILE) < 0)
|| (platform::fseek(fptr, platform::ftell(fptr) - MAXLINE) < 0))
error->one(FLERR,"Failure to seek to end-of-file for reading h(x) coeffs: {}",
utils::getsyserror());
char *buf = new char[MAXLINE+1];
fread(buf, 1, MAXLINE, fptr);
utils::sfread(FLERR, buf, 1, MAXLINE, fptr, filename, error);
buf[MAXLINE] = '\0'; // must 0-terminate buffer for string processing
Tokenizer lines(buf, "\n");
delete[] buf;

View File

@ -439,7 +439,7 @@ clean:
clean-all:
rm -rf Obj_*
rm style_*.h packages_*.h lmpgitversion.h lmpinstalledpkgs.h
rm -f style_*.h packages_*.h lmpgitversion.h lmpinstalledpkgs.h
clean-%:
@if [ $@ = "clean-serial" ]; \

View File

@ -246,8 +246,10 @@ FixReaxFFSpecies::~FixReaxFFSpecies()
if (posflag && multipos_opened) fclose(pos);
}
modify->delete_compute(fmt::format("SPECATOM_{}",id));
modify->delete_fix(fmt::format("SPECBOND_{}",id));
try {
modify->delete_compute(fmt::format("SPECATOM_{}",id));
modify->delete_fix(fmt::format("SPECBOND_{}",id));
} catch (std::exception &) {}
}
/* ---------------------------------------------------------------------- */

View File

@ -19,6 +19,7 @@
namespace LAMMPS_NS {
class Dump : protected Pointers {
friend class Output;
public:
char *id; // user-defined name of Dump
char *style; // style of Dump

View File

@ -1200,11 +1200,11 @@ int DumpImage::modify_param(int narg, char **arg)
utils::bounds(FLERR,arg[1],1,atom->ntypes,nlo,nhi,error);
// get list of colors
// assign colors in round-robin fashion to types
auto colors = Tokenizer(arg[2],"/").as_vector();
const int ncolors = colors.size();
// assign colors in round-robin fashion to types
int m = 0;
for (int i = nlo; i <= nhi; i++) {
colortype[i] = image->color2rgb(colors[m%ncolors].c_str());
@ -1249,32 +1249,19 @@ int DumpImage::modify_param(int narg, char **arg)
int nlo,nhi;
utils::bounds(FLERR,arg[1],1,atom->nbondtypes,nlo,nhi,error);
// ptrs = list of ncount colornames separated by '/'
// process list of ncount colornames separated by '/'
// assign colors in round-robin fashion to bond types
int ncount = 1;
char *nextptr;
char *ptr = arg[2];
while ((nextptr = strchr(ptr,'/'))) {
ptr = nextptr + 1;
ncount++;
}
char **ptrs = new char*[ncount+1];
ncount = 0;
ptrs[ncount++] = strtok(arg[2],"/");
while ((ptrs[ncount++] = strtok(nullptr,"/")));
ncount--;
// assign each of ncount colors in round-robin fashion to types
auto colors = Tokenizer(arg[2],"/").as_vector();
const int ncolors = colors.size();
int m = 0;
for (int i = nlo; i <= nhi; i++) {
bcolortype[i] = image->color2rgb(ptrs[m%ncount]);
bcolortype[i] = image->color2rgb(colors[m%ncolors].c_str());
if (bcolortype[i] == nullptr)
error->all(FLERR,"Invalid color in dump_modify command");
m++;
}
delete [] ptrs;
return 3;
}

View File

@ -522,7 +522,7 @@ void FixMove::initial_integrate(int /*vflag*/)
}
}
// for wiggle: X = X0 + A sin(w*dt)
// for wiggle: X = X0 + A sin(w*dt)
} else if (mstyle == WIGGLE) {
double arg = omega_rotate * delta;
@ -578,19 +578,19 @@ void FixMove::initial_integrate(int /*vflag*/)
}
}
// for rotate by right-hand rule around omega:
// P = point = vector = point of rotation
// R = vector = axis of rotation
// w = omega of rotation (from period)
// X0 = xoriginal = initial coord of atom
// R0 = runit = unit vector for R
// D = X0 - P = vector from P to X0
// C = (D dot R0) R0 = projection of atom coord onto R line
// A = D - C = vector from R line to X0
// B = R0 cross A = vector perp to A in plane of rotation
// A,B define plane of circular rotation around R line
// X = P + C + A cos(w*dt) + B sin(w*dt)
// V = w R0 cross (A cos(w*dt) + B sin(w*dt))
// for rotate by right-hand rule around omega:
// P = point = vector = point of rotation
// R = vector = axis of rotation
// w = omega of rotation (from period)
// X0 = xoriginal = initial coord of atom
// R0 = runit = unit vector for R
// D = X0 - P = vector from P to X0
// C = (D dot R0) R0 = projection of atom coord onto R line
// A = D - C = vector from R line to X0
// B = R0 cross A = vector perp to A in plane of rotation
// A,B define plane of circular rotation around R line
// X = P + C + A cos(w*dt) + B sin(w*dt)
// V = w R0 cross (A cos(w*dt) + B sin(w*dt))
} else if (mstyle == ROTATE) {
double arg = omega_rotate * delta;
@ -707,10 +707,10 @@ void FixMove::initial_integrate(int /*vflag*/)
}
}
// for variable: compute x,v from variables
// NOTE: also allow for changes to extra attributes?
// omega, angmom, theta, quat
// only necessary if prescribed motion involves rotation
// for variable: compute x,v from variables
// NOTE: also allow for changes to extra attributes?
// omega, angmom, theta, quat
// only necessary if prescribed motion involves rotation
} else if (mstyle == VARIABLE) {
@ -778,21 +778,16 @@ void FixMove::initial_integrate(int /*vflag*/)
} else if (vxvarstr) {
if (vxvarstyle == EQUAL) v[i][0] = vx;
else v[i][0] = velocity[i][0];
if (rmass) {
x[i][0] += dtv * v[i][0];
} else {
x[i][0] += dtv * v[i][0];
}
x[i][0] += dtv * v[i][0];
} else {
if (rmass) {
dtfm = dtf / rmass[i];
v[i][0] += dtfm * f[i][0];
x[i][0] += dtv * v[i][0];
} else {
dtfm = dtf / mass[type[i]];
v[i][0] += dtfm * f[i][0];
x[i][0] += dtv * v[i][0];
}
x[i][0] += dtv * v[i][0];
}
if (yvarstr && vyvarstr) {
@ -806,21 +801,16 @@ void FixMove::initial_integrate(int /*vflag*/)
} else if (vyvarstr) {
if (vyvarstyle == EQUAL) v[i][1] = vy;
else v[i][1] = velocity[i][1];
if (rmass) {
x[i][1] += dtv * v[i][1];
} else {
x[i][1] += dtv * v[i][1];
}
x[i][1] += dtv * v[i][1];
} else {
if (rmass) {
dtfm = dtf / rmass[i];
v[i][1] += dtfm * f[i][1];
x[i][1] += dtv * v[i][1];
} else {
dtfm = dtf / mass[type[i]];
v[i][1] += dtfm * f[i][1];
x[i][1] += dtv * v[i][1];
}
x[i][1] += dtv * v[i][1];
}
if (zvarstr && vzvarstr) {
@ -834,21 +824,16 @@ void FixMove::initial_integrate(int /*vflag*/)
} else if (vzvarstr) {
if (vzvarstyle == EQUAL) v[i][2] = vz;
else v[i][2] = velocity[i][2];
if (rmass) {
x[i][2] += dtv * v[i][2];
} else {
x[i][2] += dtv * v[i][2];
}
x[i][2] += dtv * v[i][2];
} else {
if (rmass) {
dtfm = dtf / rmass[i];
v[i][2] += dtfm * f[i][2];
x[i][2] += dtv * v[i][2];
} else {
dtfm = dtf / mass[type[i]];
v[i][2] += dtfm * f[i][2];
x[i][2] += dtv * v[i][2];
}
x[i][2] += dtv * v[i][2];
}
domain->remap_near(x[i],xold);

View File

@ -57,8 +57,7 @@ Molecule::Molecule(LAMMPS *lmp, int narg, char **arg, int &index) :
id = utils::strdup(arg[0]);
if (!utils::is_id(id))
error->all(FLERR,"Molecule template ID must have only "
"alphanumeric or underscore characters");
error->all(FLERR,"Molecule template ID must have only alphanumeric or underscore characters");
// parse args until reach unknown arg (next file)
@ -130,8 +129,7 @@ Molecule::Molecule(LAMMPS *lmp, int narg, char **arg, int &index) :
if (me == 0) {
fp = fopen(arg[ifile],"r");
if (fp == nullptr)
error->one(FLERR,"Cannot open molecule file {}: {}",
arg[ifile], utils::getsyserror());
error->one(FLERR,"Cannot open molecule file {}: {}",arg[ifile], utils::getsyserror());
}
read(0);
if (me == 0) fclose(fp);
@ -496,8 +494,7 @@ void Molecule::read(int flag)
if (nmatch != nwant)
error->one(FLERR,"Invalid header line format in molecule file");
} catch (TokenizerException &e) {
error->one(FLERR, "Invalid header in molecule file\n"
"{}", e.what());
error->one(FLERR,"Invalid header in molecule file: {}", e.what());
}
}
@ -618,11 +615,9 @@ void Molecule::read(int flag)
// Error: Either a too long/short section or a typo in the keyword
if (utils::strmatch(keyword,"^[A-Za-z ]+$"))
error->one(FLERR,"Unknown section '{}' in molecule "
"file\n",keyword);
error->one(FLERR,"Unknown section '{}' in molecule file\n",keyword);
else error->one(FLERR,"Unexpected line in molecule file "
"while looking for the next "
"section:\n{}",line);
"while looking for the next section:\n{}",line);
}
keyword = parse_keyword(1,line);
}
@ -648,8 +643,7 @@ void Molecule::read(int flag)
if (bondflag && specialflag == 0) {
if (domain->box_exist == 0)
error->all(FLERR,"Cannot auto-generate special bonds before "
"simulation box is defined");
error->all(FLERR,"Cannot auto-generate special bonds before simulation box is defined");
if (flag) {
special_generate();
@ -691,8 +685,7 @@ void Molecule::coords(char *line)
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 4)
error->all(FLERR,"Invalid line in Coords section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Coords section of molecule file: {}",line);
int iatom = values.next_int() - 1;
if (iatom < 0 || iatom >= natoms)
@ -707,19 +700,16 @@ void Molecule::coords(char *line)
x[iatom][2] *= sizescale;
}
} catch (TokenizerException &e) {
error->all(FLERR,"Invalid line in Coords section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Coords section of molecule file: {}\n{}",e.what(),line);
}
for (int i = 0; i < natoms; i++)
if (count[i] == 0) error->all(FLERR,"Atom {} missing in Coords "
"section of molecule file",i+1);
if (count[i] == 0) error->all(FLERR,"Atom {} missing in Coords section of molecule file",i+1);
if (domain->dimension == 2) {
for (int i = 0; i < natoms; i++)
if (x[i][2] != 0.0)
error->all(FLERR,"Z coord in molecule file for atom {} "
"must be 0.0 for 2d-simulation.",i+1);
error->all(FLERR,"Z coord in molecule file for atom {} must be 0.0 for 2d-simulation",i+1);
}
}
@ -737,8 +727,7 @@ void Molecule::types(char *line)
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 2)
error->all(FLERR,"Invalid line in Types section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Types section of molecule file: {}",line);
int iatom = values.next_int() - 1;
if (iatom < 0 || iatom >= natoms)
@ -748,17 +737,14 @@ void Molecule::types(char *line)
type[iatom] += toffset;
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Types section of "
"molecule file: {}\n{}", e.what(),line);
error->all(FLERR,"Invalid line in Types section of molecule file: {}\n{}",e.what(),line);
}
for (int i = 0; i < natoms; i++) {
if (count[i] == 0) error->all(FLERR,"Atom {} missing in Types "
"section of molecule file",i+1);
if (count[i] == 0) error->all(FLERR,"Atom {} missing in Types section of molecule file",i+1);
if ((type[i] <= 0) || (domain->box_exist && (type[i] > atom->ntypes)))
error->all(FLERR,"Invalid atom type {} for atom {} "
"in molecule file",type[i],i+1);
error->all(FLERR,"Invalid atom type {} for atom {} in molecule file",type[i],i+1);
ntypes = MAX(ntypes,type[i]);
}
@ -777,8 +763,7 @@ void Molecule::molecules(char *line)
readline(line);
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 2)
error->all(FLERR,"Invalid line in Molecules section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Molecules section of molecule file: {}",line);
int iatom = values.next_int() - 1;
if (iatom < 0 || iatom >= natoms)
@ -788,19 +773,17 @@ void Molecule::molecules(char *line)
// molecule[iatom] += moffset; // placeholder for possible molecule offset
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Molecules section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Molecules section of molecule file: {}\n{}",e.what(),line);
}
for (int i = 0; i < natoms; i++)
if (count[i] == 0) error->all(FLERR,"Atom {} missing in Molecules "
"section of molecule file",i+1);
for (int i = 0; i < natoms; i++)
for (int i = 0; i < natoms; i++) {
if (count[i] == 0)
error->all(FLERR,"Atom {} missing in Molecules section of molecule file",i+1);
}
for (int i = 0; i < natoms; i++) {
if (molecule[i] < 0)
error->all(FLERR,"Invalid molecule ID {} for atom {} "
"in molecule file",molecule[i],i+1);
error->all(FLERR,"Invalid molecule ID {} for atom {} in molecule file",molecule[i],i+1);
}
for (int i = 0; i < natoms; i++)
nmolecules = MAX(nmolecules,molecule[i]);
}
@ -818,23 +801,21 @@ void Molecule::fragments(char *line)
ValueTokenizer values(utils::trim_comment(line));
if ((int)values.count() > natoms+1)
error->all(FLERR,"Too many atoms per fragment in Fragments "
"section of molecule file");
error->all(FLERR,"Too many atoms per fragment in Fragments section of molecule file");
fragmentnames[i] = values.next_string();
while (values.has_next()) {
int iatom = values.next_int()-1;
if (iatom < 0 || iatom >= natoms)
error->all(FLERR,"Invalid atom ID {} for fragment {} in "
"Fragments section of molecule file",
iatom+1, fragmentnames[i]);
error->all(FLERR,"Invalid atom ID {} for fragment {} in Fragments section of "
"molecule file", iatom+1, fragmentnames[i]);
fragmentmask[i][iatom] = 1;
}
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid atom ID in Fragments section of "
"molecule file: {}\n{}", e.what(),line);
error->all(FLERR,"Invalid atom ID in Fragments section of "
"molecule file: {}\n{}", e.what(),line);
}
}
@ -851,8 +832,7 @@ void Molecule::charges(char *line)
ValueTokenizer values(utils::trim_comment(line));
if ((int)values.count() != 2)
error->all(FLERR,"Invalid line in Charges section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Charges section of molecule file: {}",line);
int iatom = values.next_int() - 1;
if (iatom < 0 || iatom >= natoms)
@ -862,13 +842,13 @@ void Molecule::charges(char *line)
q[iatom] = values.next_double();
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Charges section of "
"molecule file: {}.\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Charges section of molecule file: {}\n{}",e.what(),line);
}
for (int i = 0; i < natoms; i++)
if (count[i] == 0) error->all(FLERR,"Atom {} missing in Charges "
"section of molecule file",i+1);
for (int i = 0; i < natoms; i++) {
if (count[i] == 0)
error->all(FLERR,"Atom {} missing in Charges section of molecule file",i+1);
}
}
/* ----------------------------------------------------------------------
@ -885,8 +865,7 @@ void Molecule::diameters(char *line)
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 2)
error->all(FLERR,"Invalid line in Diameters section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Diameters section of molecule file: {}",line);
int iatom = values.next_int() - 1;
if (iatom < 0 || iatom >= natoms)
error->all(FLERR,"Invalid atom index in Diameters section of molecule file");
@ -897,16 +876,14 @@ void Molecule::diameters(char *line)
maxradius = MAX(maxradius,radius[iatom]);
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Diameters section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Diameters section of molecule file: {}\n{}",e.what(),line);
}
for (int i = 0; i < natoms; i++) {
if (count[i] == 0) error->all(FLERR,"Atom {} missing in Diameters "
"section of molecule file",i+1);
if (count[i] == 0)
error->all(FLERR,"Atom {} missing in Diameters section of molecule file",i+1);
if (radius[i] < 0.0)
error->all(FLERR,"Invalid atom diameter {} for atom {} "
"in molecule file", radius[i], i+1);
error->all(FLERR,"Invalid atom diameter {} for atom {} in molecule file", radius[i], i+1);
}
}
@ -923,8 +900,7 @@ void Molecule::masses(char *line)
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 2)
error->all(FLERR,"Invalid line in Masses section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Masses section of molecule file: {}",line);
int iatom = values.next_int() - 1;
if (iatom < 0 || iatom >= natoms)
@ -934,8 +910,7 @@ void Molecule::masses(char *line)
rmass[iatom] *= sizescale*sizescale*sizescale;
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Masses section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Masses section of molecule file: {}\n{}",e.what(),line);
}
for (int i = 0; i < natoms; i++) {
@ -972,15 +947,13 @@ void Molecule::bonds(int flag, char *line)
try {
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 4)
error->all(FLERR,"Invalid line in Bonds section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Bonds section of molecule file: {}",line);
values.next_int();
itype = values.next_int();
atom1 = values.next_tagint();
atom2 = values.next_tagint();
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Bonds section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Bonds section of molecule file: {}\n{}",e.what(),line);
}
itype += boffset;
@ -1042,16 +1015,14 @@ void Molecule::angles(int flag, char *line)
try {
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 5)
error->all(FLERR,"Invalid line in Angles section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Angles section of molecule file: {}",line);
values.next_int();
itype = values.next_int();
atom1 = values.next_tagint();
atom2 = values.next_tagint();
atom3 = values.next_tagint();
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Angles section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Angles section of molecule file: {}\n{}",e.what(),line);
}
itype += aoffset;
@ -1128,8 +1099,7 @@ void Molecule::dihedrals(int flag, char *line)
try {
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 6)
error->all(FLERR,"Invalid line in Dihedrals section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Dihedrals section of molecule file: {}",line);
values.next_int();
itype = values.next_int();
@ -1138,8 +1108,7 @@ void Molecule::dihedrals(int flag, char *line)
atom3 = values.next_tagint();
atom4 = values.next_tagint();
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Dihedrals section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Dihedrals section of molecule file: {}\n{}",e.what(),line);
}
itype += doffset;
@ -1150,8 +1119,7 @@ void Molecule::dihedrals(int flag, char *line)
(atom4 <= 0) || (atom4 > natoms) ||
(atom1 == atom2) || (atom1 == atom3) || (atom1 == atom4) ||
(atom2 == atom3) || (atom2 == atom4) || (atom3 == atom4))
error->all(FLERR,
"Invalid atom ID in dihedrals section of molecule file");
error->all(FLERR,"Invalid atom ID in dihedrals section of molecule file");
if ((itype <= 0) || (domain->box_exist && (itype > atom->ndihedraltypes)))
error->all(FLERR,"Invalid dihedral type in Dihedrals section of molecule file");
@ -1230,8 +1198,7 @@ void Molecule::impropers(int flag, char *line)
try {
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 6)
error->all(FLERR,"Invalid line in Impropers section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Impropers section of molecule file: {}",line);
values.next_int();
itype = values.next_int();
atom1 = values.next_tagint();
@ -1239,8 +1206,7 @@ void Molecule::impropers(int flag, char *line)
atom3 = values.next_tagint();
atom4 = values.next_tagint();
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Impropers section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Impropers section of molecule file: {}\n{}",e.what(),line);
}
itype += ioffset;
@ -1251,8 +1217,7 @@ void Molecule::impropers(int flag, char *line)
(atom4 <= 0) || (atom4 > natoms) ||
(atom1 == atom2) || (atom1 == atom3) || (atom1 == atom4) ||
(atom2 == atom3) || (atom2 == atom4) || (atom3 == atom4))
error->all(FLERR,
"Invalid atom ID in impropers section of molecule file");
error->all(FLERR,"Invalid atom ID in impropers section of molecule file");
if ((itype <= 0) || (domain->box_exist && (itype > atom->nimpropertypes)))
error->all(FLERR,"Invalid improper type in Impropers section of molecule file");
@ -1325,15 +1290,14 @@ void Molecule::nspecial_read(int flag, char *line)
try {
ValueTokenizer values(utils::trim_comment(line));
if (values.count() != 4)
error->all(FLERR,"Invalid line in Special Bond Counts section of "
"molecule file: {}",line);
error->all(FLERR,"Invalid line in Special Bond Counts section of molecule file: {}",line);
values.next_int();
c1 = values.next_tagint();
c2 = values.next_tagint();
c3 = values.next_tagint();
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Special Bond Counts section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Special Bond Counts section of "
"molecule file: {}\n{}",e.what(),line);
}
if (flag) {
@ -1358,8 +1322,7 @@ void Molecule::special_read(char *line)
int nwords = values.count();
if (nwords != nspecial[i][2]+1)
error->all(FLERR,"Molecule file special list "
"does not match special count");
error->all(FLERR,"Molecule file special list does not match special count");
values.next_int(); // ignore
@ -1367,13 +1330,12 @@ void Molecule::special_read(char *line)
special[i][m-1] = values.next_tagint();
if (special[i][m-1] <= 0 || special[i][m-1] > natoms ||
special[i][m-1] == i+1)
error->all(FLERR,"Invalid atom index in Special Bonds "
"section of molecule file");
error->all(FLERR,"Invalid atom index in Special Bonds section of molecule file");
}
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid line in Special Bonds section of "
"molecule file: {}\n{}",e.what(),line);
error->all(FLERR,"Invalid line in Special Bonds section of "
"molecule file: {}\n{}",e.what(),line);
}
}
@ -1502,8 +1464,7 @@ void Molecule::shakeflag_read(char *line)
shake_flag[i] = values.next_int();
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid Shake Flags section in molecule file\n"
"{}", e.what());
error->all(FLERR,"Invalid Shake Flags section in molecule file: {}", e.what());
}
for (int i = 0; i < natoms; i++)
@ -1572,8 +1533,7 @@ void Molecule::shakeatom_read(char *line)
}
} catch (TokenizerException &e) {
error->all(FLERR,"Invalid shake atom in molecule file\n"
"{}", e.what());
error->all(FLERR,"Invalid shake atom in molecule file: {}", e.what());
}
for (int i = 0; i < natoms; i++) {
@ -1642,8 +1602,7 @@ void Molecule::shaketype_read(char *line)
error->all(FLERR,"Invalid shake type data in molecule file");
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid shake type data in molecule file\n",
"{}", e.what());
error->all(FLERR,"Invalid shake type data in molecule file: {}",e.what());
}
for (int i = 0; i < natoms; i++) {
@ -1695,8 +1654,7 @@ void Molecule::body(int flag, int pflag, char *line)
} else nword += ncount;
}
} catch (TokenizerException &e) {
error->all(FLERR, "Invalid body params in molecule file\n",
"{}", e.what());
error->all(FLERR,"Invalid body params in molecule file: {}", e.what());
}
}
@ -1735,8 +1693,7 @@ void Molecule::check_attributes(int flag)
if (onemol->rmassflag && !atom->rmass_flag) mismatch = 1;
if (mismatch && me == 0)
error->warning(FLERR,
"Molecule attributes do not match system attributes");
error->warning(FLERR,"Molecule attributes do not match system attributes");
// for all atom styles, check nbondtype,etc
@ -1770,8 +1727,7 @@ void Molecule::check_attributes(int flag)
// warn if molecule topology defined but no special settings
if (onemol->bondflag && !onemol->specialflag)
if (me == 0) error->warning(FLERR,"Molecule has bond topology "
"but no special bond settings");
if (me == 0) error->warning(FLERR,"Molecule has bond topology but no special bond settings");
}
}
@ -1878,47 +1834,31 @@ void Molecule::allocate()
memory->create(special,natoms,maxspecial,"molecule:special");
if (bondflag) {
memory->create(bond_type,natoms,bond_per_atom,
"molecule:bond_type");
memory->create(bond_atom,natoms,bond_per_atom,
"molecule:bond_atom");
memory->create(bond_type,natoms,bond_per_atom,"molecule:bond_type");
memory->create(bond_atom,natoms,bond_per_atom,"molecule:bond_atom");
}
if (angleflag) {
memory->create(angle_type,natoms,angle_per_atom,
"molecule:angle_type");
memory->create(angle_atom1,natoms,angle_per_atom,
"molecule:angle_atom1");
memory->create(angle_atom2,natoms,angle_per_atom,
"molecule:angle_atom2");
memory->create(angle_atom3,natoms,angle_per_atom,
"molecule:angle_atom3");
memory->create(angle_type,natoms,angle_per_atom,"molecule:angle_type");
memory->create(angle_atom1,natoms,angle_per_atom,"molecule:angle_atom1");
memory->create(angle_atom2,natoms,angle_per_atom,"molecule:angle_atom2");
memory->create(angle_atom3,natoms,angle_per_atom,"molecule:angle_atom3");
}
if (dihedralflag) {
memory->create(dihedral_type,natoms,dihedral_per_atom,
"molecule:dihedral_type");
memory->create(dihedral_atom1,natoms,dihedral_per_atom,
"molecule:dihedral_atom1");
memory->create(dihedral_atom2,natoms,dihedral_per_atom,
"molecule:dihedral_atom2");
memory->create(dihedral_atom3,natoms,dihedral_per_atom,
"molecule:dihedral_atom3");
memory->create(dihedral_atom4,natoms,dihedral_per_atom,
"molecule:dihedral_atom4");
memory->create(dihedral_type,natoms,dihedral_per_atom,"molecule:dihedral_type");
memory->create(dihedral_atom1,natoms,dihedral_per_atom,"molecule:dihedral_atom1");
memory->create(dihedral_atom2,natoms,dihedral_per_atom,"molecule:dihedral_atom2");
memory->create(dihedral_atom3,natoms,dihedral_per_atom,"molecule:dihedral_atom3");
memory->create(dihedral_atom4,natoms,dihedral_per_atom,"molecule:dihedral_atom4");
}
if (improperflag) {
memory->create(improper_type,natoms,improper_per_atom,
"molecule:improper_type");
memory->create(improper_atom1,natoms,improper_per_atom,
"molecule:improper_atom1");
memory->create(improper_atom2,natoms,improper_per_atom,
"molecule:improper_atom2");
memory->create(improper_atom3,natoms,improper_per_atom,
"molecule:improper_atom3");
memory->create(improper_atom4,natoms,improper_per_atom,
"molecule:improper_atom4");
memory->create(improper_type,natoms,improper_per_atom,"molecule:improper_type");
memory->create(improper_atom1,natoms,improper_per_atom,"molecule:improper_atom1");
memory->create(improper_atom2,natoms,improper_per_atom,"molecule:improper_atom2");
memory->create(improper_atom3,natoms,improper_per_atom,"molecule:improper_atom3");
memory->create(improper_atom4,natoms,improper_per_atom,"molecule:improper_atom4");
}
if (shakeflag) {
@ -2058,7 +1998,7 @@ void Molecule::skip_lines(int n, char *line, const std::string &section)
readline(line);
if (utils::strmatch(utils::trim(utils::trim_comment(line)),"^[A-Za-z ]+$"))
error->one(FLERR,"Unexpected line in molecule file while "
"skipping {} section:\n{}",section,line);
"skipping {} section:\n{}",section,line);
}
}

View File

@ -41,6 +41,8 @@ using namespace LAMMPS_NS;
#define DELTA 1
#define EPSDT 1.0e-6
enum {SETUP, WRITE, RESET_DT};
/* ----------------------------------------------------------------------
initialize all output
------------------------------------------------------------------------- */
@ -232,7 +234,7 @@ void Output::setup(int memflag)
// only do this if dump written or dump has not been written yet
if (writeflag || last_dump[idump] < 0)
calculate_next_dump(0,idump,ntimestep);
calculate_next_dump(SETUP,idump,ntimestep);
// if dump not written now, use addstep_compute_all()
// since don't know what computes the dump will invoke
@ -361,7 +363,7 @@ void Output::setup(int memflag)
dump[idump]->write();
last_dump[idump] = ntimestep;
calculate_next_dump(1,idump,ntimestep);
calculate_next_dump(WRITE,idump,ntimestep);
if (mode_dump[idump] == 0 &&
(dump[idump]->clearstep || var_dump[idump]))
@ -468,12 +470,12 @@ void Output::setup(int memflag)
for timestep mode, set next_dump
for simulation time mode, set next_time_dump and next_dump
which flag depends on caller
0 = from setup() at start of run
1 = from write() during run each time a dump file is written
2 = from reset_dt() called from fix dt/reset when it changes timestep size
SETUP = from setup() at start of run
WRITE = from write() during run each time a dump file is written
RESET_DT = from reset_dt() called from fix dt/reset when it changes timestep size
------------------------------------------------------------------------- */
void Output::calculate_next_dump(int which, int idump, bigint ntimestep)
void Output::calculate_next_dump(int which, int idump, bigint ntimestep)
{
// dump mode is by timestep
// just set next_dump
@ -482,13 +484,13 @@ void Output::setup(int memflag)
if (every_dump[idump]) {
// which = 0: nextdump = next multiple of every_dump
// which = 1: increment nextdump by every_dump
// which = SETUP: nextdump = next multiple of every_dump
// which = WRITE: increment nextdump by every_dump
if (which == 0)
if (which == SETUP)
next_dump[idump] =
(ntimestep/every_dump[idump])*every_dump[idump] + every_dump[idump];
else if (which == 1)
else if (which == WRITE)
next_dump[idump] += every_dump[idump];
} else {
@ -510,17 +512,28 @@ void Output::setup(int memflag)
if (every_time_dump[idump] > 0.0) {
// which = 0: nexttime = next multiple of every_time_dump
// which = 1: increment nexttime by every_time_dump
// which = 2: no change to previous nexttime (only timestep has changed)
// which = SETUP: nexttime = next multiple of every_time_dump
// which = WRITE: increment nexttime by every_time_dump
// which = RESET_DT: no change to previous nexttime (only timestep has changed)
if (which == 0)
switch (which) {
case SETUP:
nexttime = static_cast<bigint> (tcurrent/every_time_dump[idump]) *
every_time_dump[idump] + every_time_dump[idump];
else if (which == 1)
break;
case WRITE:
nexttime = next_time_dump[idump] + every_time_dump[idump];
else if (which == 2)
break;
case RESET_DT:
nexttime = next_time_dump[idump];
break;
default:
nexttime = 0;
error->all(FLERR,"Unexpected argument to calculate_next_dump");
}
nextdump = ntimestep +
static_cast<bigint> ((nexttime - tcurrent - EPSDT*update->dt) /
@ -541,10 +554,10 @@ void Output::setup(int memflag)
} else {
// do not re-evaulate variable for which = 2, leave nexttime as-is
// do not re-evaulate variable for which = RESET_DT, leave nexttime as-is
// unless next_time_dump < 0.0, which means variable never yet evaluated
if (which < 2 || next_time_dump[idump] < 0.0) {
if (which < RESET_DT || next_time_dump[idump] < 0.0) {
nexttime = input->variable->compute_equal(ivar_dump[idump]);
} else
nexttime = next_time_dump[idump];
@ -619,9 +632,8 @@ int Output::check_time_dumps(bigint ntimestep)
{
next_dump_any = MAXBIGINT;
for (int idump = 0; idump < ndump; idump++)
if (last_dump[idump] >= 0)
error->all(FLERR,
"Cannot reset timestep with active dump - must undump first");
if ((last_dump[idump] >= 0) && !update->whichflag && !dump[idump]->multifile)
error->all(FLERR, "Cannot reset timestep with active dump - must undump first");
if (restart_flag_single) {
if (restart_every_single) {
@ -704,7 +716,7 @@ void Output::reset_dt()
// since timestep change affects next step
if (next_dump[idump] != ntimestep)
calculate_next_dump(2,idump,update->ntimestep);
calculate_next_dump(RESET_DT,idump,update->ntimestep);
if (dump[idump]->clearstep || var_dump[idump])
next_time_dump_any = MIN(next_time_dump_any,next_dump[idump]);

View File

@ -524,7 +524,7 @@ void PairHybridScaled::write_restart(FILE *fp)
int n = scalevars.size();
fwrite(&n, sizeof(int), 1, fp);
for (auto var : scalevars) {
for (auto &var : scalevars) {
n = var.size() + 1;
fwrite(&n, sizeof(int), 1, fp);
fwrite(var.c_str(), sizeof(char), n, fp);

View File

@ -1,5 +1,5 @@
BootStrap: docker
From: fedora:34
From: fedora:35
%post
dnf -y update
@ -94,7 +94,7 @@ EOF
CUSTOM_PROMPT_ENV=/.singularity.d/env/99-zz_custom_prompt.sh
cat >$CUSTOM_PROMPT_ENV <<EOF
#!/bin/bash
PS1="[fedora34:\u@\h] \W> "
PS1="[fedora35:\u@\h] \W> "
EOF
chmod 755 $CUSTOM_PROMPT_ENV

View File

@ -176,6 +176,33 @@ TEST_F(MoleculeFileTest, minimal)
ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*"));
}
TEST_F(MoleculeFileTest, notype)
{
BEGIN_CAPTURE_OUTPUT();
command("atom_style atomic");
command("region box block 0 1 0 1 0 1");
command("create_box 1 box");
run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n");
auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*"));
TEST_FAILURE(".*ERROR: Create_atoms molecule must have atom types.*",
command("create_atoms 0 single 0.0 0.0 0.0 mol notype 542465"););
}
TEST_F(MoleculeFileTest, extramass)
{
BEGIN_CAPTURE_OUTPUT();
command("atom_style atomic");
command("region box block 0 1 0 1 0 1");
command("create_box 1 box");
run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"
" Types\n\n 1 1\n Masses\n\n 1 1.0\n");
command("create_atoms 0 single 0.0 0.0 0.0 mol extramass 73546");
auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*WARNING: Molecule attributes do not match "
"system attributes.*"));
}
TEST_F(MoleculeFileTest, twomols)
{
BEGIN_CAPTURE_OUTPUT();

View File

@ -356,18 +356,16 @@ create_atoms 1 single &
def test_extract_box_triclinic(self):
self.lmp.command("boundary p p p")
self.lmp.command("region box block 0 2 0 2 0 2")
self.lmp.command("region box prism 0 2 0 2 0 2 0.1 0.2 0.3")
self.lmp.command("create_box 1 box")
self.lmp.command("change_box all triclinic")
self.lmp.command("change_box all xy final 0.1 yz final 0.2 xz final 0.3")
boxlo, boxhi, xy, yz, xz, periodicity, box_change = self.lmp.extract_box()
self.assertEqual(boxlo, [0.0, 0.0, 0.0])
self.assertEqual(boxhi, [2.0, 2.0, 2.0])
self.assertEqual(xy, 0.1)
self.assertEqual(yz, 0.2)
self.assertEqual(xz, 0.3)
self.assertEqual(xz, 0.2)
self.assertEqual(yz, 0.3)
self.assertEqual(periodicity, [1, 1, 1])
self.assertEqual(box_change, 0)