From c49e339318f1b660ac8a4cb2d5e1f6cb01c97686 Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Mon, 20 Jan 2025 14:57:04 +0000 Subject: [PATCH 1/3] Added code to link cell to ensure all atoms are put in a single link cell if there are no pbcs --- src/tools/LinkCells.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tools/LinkCells.cpp b/src/tools/LinkCells.cpp index 603cfe7849..ab55875b2f 100644 --- a/src/tools/LinkCells.cpp +++ b/src/tools/LinkCells.cpp @@ -47,13 +47,15 @@ void LinkCells::buildCellLists( const std::vector& pos, const std::vecto plumed_assert( cutoffwasset && pos.size()==indices.size() ); // Must be able to check that pbcs are not nonsensical in some way?? -- GAT - - double determinant = pbc.getBox().determinant(); - - plumed_assert(determinant > epsilon) <<"Cell lists cannot be built when passing a box with null volume. Volume is "< epsilon) <<"Cell lists cannot be built when passing a box with null volume. Volume is "<& pos, const std::vecto lcell_starts.resize( ncellstot ); } // Clear nlcells - for(unsigned i=0; i Date: Mon, 20 Jan 2025 15:54:08 +0000 Subject: [PATCH 2/3] Second attempt to ensure all atoms are in single link cell if structure has nopbc --- src/tools/LinkCells.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tools/LinkCells.cpp b/src/tools/LinkCells.cpp index ab55875b2f..e1851e5d93 100644 --- a/src/tools/LinkCells.cpp +++ b/src/tools/LinkCells.cpp @@ -49,7 +49,7 @@ void LinkCells::buildCellLists( const std::vector& pos, const std::vecto // Must be able to check that pbcs are not nonsensical in some way?? -- GAT auto box = pbc.getBox(); if(box(0,0)==0.0 && box(0,1)==0.0 && box(0,2)==0.0 && box(1,0)==0.0 && box(1,1)==0.0 && box(1,2)==0.0 && box(2,0)==0.0 && box(2,1)==0 && box(2,2)==0) { - box(0,0) = box(1,1) = box(2,2) = 1e200; + box(0,0) = box(1,1) = box(2,2) = link_cutoff; } else { auto determinant = box.determinant(); plumed_assert(determinant > epsilon) <<"Cell lists cannot be built when passing a box with null volume. Volume is "<& pos, const std::vecto tot+=lcell_tots[i]; lcell_tots[i]=0; } - plumed_assert( tot==pos.size() ); + plumed_assert( tot==pos.size() ) <<"Total number of atoms found in link cells is "< LinkCells::findMyCell( const Vector& pos ) const { - Vector fpos=mypbc.realToScaled( pos ); std::array celn; + if( ncells[0]*ncells[1]*ncells[2] == 1 ) { + celn[0]=celn[1]=celn[2]=0; + return celn; + } + Vector fpos=mypbc.realToScaled( pos ); for(unsigned j=0; j<3; ++j) { celn[j] = std::floor( ( Tools::pbc(fpos[j]) + 0.5 ) * ncells[j] ); plumed_assert( celn[j]>=0 && celn[j] Date: Wed, 22 Jan 2025 09:37:57 +0000 Subject: [PATCH 3/3] Hopefully fixes issue with link cells when pbc are not set. --- src/tools/LinkCells.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/LinkCells.cpp b/src/tools/LinkCells.cpp index e1851e5d93..6cd19bc09f 100644 --- a/src/tools/LinkCells.cpp +++ b/src/tools/LinkCells.cpp @@ -49,7 +49,10 @@ void LinkCells::buildCellLists( const std::vector& pos, const std::vecto // Must be able to check that pbcs are not nonsensical in some way?? -- GAT auto box = pbc.getBox(); if(box(0,0)==0.0 && box(0,1)==0.0 && box(0,2)==0.0 && box(1,0)==0.0 && box(1,1)==0.0 && box(1,2)==0.0 && box(2,0)==0.0 && box(2,1)==0 && box(2,2)==0) { - box(0,0) = box(1,1) = box(2,2) = link_cutoff; + // If the box is not set then we can't use link cells. We thus set the link cell cutoff and box vectors equal to 23 (because it is the best number). + // Setting everything this way ensures that the link cells are a 1x1x1 box. Notice that if it is a one by one by one box then we are hard coded to return + // 0 in findCell + box(0,0) = box(1,1) = box(2,2) = link_cutoff = 23; } else { auto determinant = box.determinant(); plumed_assert(determinant > epsilon) <<"Cell lists cannot be built when passing a box with null volume. Volume is "<