Skip to content

Commit

Permalink
Made implementation of link cells that should work even if you don't …
Browse files Browse the repository at this point in the history
…have PBC
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Jul 24, 2024
1 parent a24a72a commit e284c70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/tools/LinkCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace PLMD {
LinkCells::LinkCells( Communicator& cc ) :
comm(cc),
cutoffwasset(false),
nopbc(false),
link_cutoff(0.0),
ncells(3),
nstride(3)
Expand All @@ -45,10 +46,20 @@ double LinkCells::getCutoff() const {
void LinkCells::buildCellLists( const std::vector<Vector>& pos, const std::vector<unsigned>& indices, const Pbc& pbc ) {
plumed_assert( cutoffwasset && pos.size()==indices.size() );

// Must be able to check that pbcs are not nonsensical in some way?? -- GAT

// Setup the pbc object by copying it from action
mypbc.setBox( pbc.getBox() );
// Create an orthorhombic box around the atomic positions that encompasses every atomic position if there are no pbc
if( !pbc.isSet() ) {
Vector minp, maxp; minp = maxp = pos[0]; Tensor fake_box; fake_box.zero();
for(unsigned k=0; k<3; ++k) {
for(unsigned i=1; i<pos.size(); ++i) {
if( pos[i][k]>maxp[k] ) maxp[k] = pos[i][k];
if( pos[i][k]<minp[k] ) minp[k] = pos[i][k];
}
fake_box[k][k] = link_cutoff*( 1 + std::ceil( (maxp[k] - minp[k])/link_cutoff ) );
origin[k] = ( minp[k] + maxp[k] ) / 2;
}
mypbc.setBox( fake_box ); nopbc=true;
// Setup the pbc object by copying it from action if the Pbc were set
} else { mypbc.setBox( pbc.getBox() ); nopbc=false; }

// Setup the lists
if( pos.size()!=allcells.size() ) {
Expand Down Expand Up @@ -153,10 +164,12 @@ void LinkCells::retrieveAtomsInCells( const unsigned& ncells_required,
}

std::array<unsigned,3> LinkCells::findMyCell( const Vector& pos ) const {
Vector fpos=mypbc.realToScaled( pos );
Vector mypos = pos; if( nopbc ) mypos = pos - origin;
Vector fpos=mypbc.realToScaled( mypos );
std::array<unsigned,3> celn;
for(unsigned j=0; j<3; ++j) {
celn[j] = std::floor( ( Tools::pbc(fpos[j]) + 0.5 ) * ncells[j] );
if( nopbc ) celn[j] = std::floor( fpos[j] * ncells[j] );
else celn[j] = std::floor( ( Tools::pbc(fpos[j]) + 0.5 ) * ncells[j] );
plumed_assert( celn[j]>=0 && celn[j]<ncells[j] ); // Check that atom is in box
}
return celn;
Expand Down
4 changes: 4 additions & 0 deletions src/tools/LinkCells.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ class LinkCells {
Communicator & comm;
/// Check that the link cells were set up correctly
bool cutoffwasset;
/// Are there periodic boundary conditions setup
bool nopbc;
/// The cutoff to use for the sizes of the cells
double link_cutoff;
/// The pbc we are using for link cells
Pbc mypbc;
/// The location of the origin if we are not using periodic boundary conditions
Vector origin;
/// The number of cells in each direction
std::vector<unsigned> ncells;
/// The number of cells to stride through to get the link cells
Expand Down

1 comment on commit e284c70

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANGLES.tmp
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CAVITY.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CLUSTER_DIAMETER.tmp
Found broken examples in automatic/CLUSTER_DISTRIBUTION.tmp
Found broken examples in automatic/CLUSTER_PROPERTIES.tmp
Found broken examples in automatic/CONSTANT.tmp
Found broken examples in automatic/CONTACT_MATRIX.tmp
Found broken examples in automatic/CONTACT_MATRIX_PROPER.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DFSCLUSTERING.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HBOND_MATRIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/INCYLINDER.tmp
Found broken examples in automatic/INENVELOPE.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/METATENSOR.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/OUTPUT_CLUSTER.tmp
Found broken examples in automatic/PAMM.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in automatic/PYCVINTERFACE.tmp
Found broken examples in automatic/PYTHONFUNCTION.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_LINEAR_PROJ.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_MAHA_DIST.tmp
Found broken examples in automatic/SPRINT.tmp
Found broken examples in automatic/TETRAHEDRALPORE.tmp
Found broken examples in automatic/TORSIONS.tmp
Found broken examples in automatic/WHAM_WEIGHTS.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.