diff --git a/src/create_atoms.cpp b/src/create_atoms.cpp index c247175ade..1974fe92ca 100644 --- a/src/create_atoms.cpp +++ b/src/create_atoms.cpp @@ -361,15 +361,17 @@ void CreateAtoms::add_lattice() // in lattice space, subbox is a tilted box // but bbox of subbox is aligned with lattice axes // so ilo:khi unit cells should completely tile bounding box - // decrement lo values if min < 0, since static_cast(-1.5) = -1 + // decrement lo, increment hi to avoid round-off issues in lattice->bbox(), + // which can lead to missing atoms in rare cases + // extra decrement of lo if min < 0, since static_cast(-1.5) = -1 int ilo,ihi,jlo,jhi,klo,khi; - ilo = static_cast (xmin); - jlo = static_cast (ymin); - klo = static_cast (zmin); - ihi = static_cast (xmax); - jhi = static_cast (ymax); - khi = static_cast (zmax); + ilo = static_cast (xmin) - 1; + jlo = static_cast (ymin) - 1; + klo = static_cast (zmin) - 1; + ihi = static_cast (xmax) + 1; + jhi = static_cast (ymax) + 1; + khi = static_cast (zmax) + 1; if (xmin < 0.0) ilo--; if (ymin < 0.0) jlo--; @@ -449,7 +451,7 @@ void CreateAtoms::add_lattice() if (!domain->regions[nregion]->match(x[0],x[1],x[2])) continue; // test if atom is in my subbox - + if (triclinic) { domain->x2lamda(x,lamda); coord = lamda;