Skip to content

Commit

Permalink
Merge pull request plumed#1053 from plumed/optimize-emst
Browse files Browse the repository at this point in the history
Optimized EMST setup
  • Loading branch information
GiovanniBussi authored Apr 8, 2024
2 parents 91d87b5 + 028767e commit 0c40a4e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tools/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ std::vector<AtomNumber> Tree::getTree(std::vector<AtomNumber> atoms)
// clear root_ vector
root_.clear();

std::vector<Vector> positions;

// remove atoms not in PDB file
std::vector<AtomNumber> addtotree, addtoroot;
std::vector<AtomNumber> newatoms;
newatoms.reserve(atoms.size());
positions.reserve(atoms.size());
tree.reserve(atoms.size());
root_.reserve(atoms.size());
if(!moldat_->checkForAtom(atoms[0])) plumed_merror("The first atom in the list should be present in the PDB file");
// store first atom
newatoms.push_back(atoms[0]);
positions.push_back(moldat_->getPosition(atoms[0]));
for(unsigned i=1; i<atoms.size(); ++i) {
if(!moldat_->checkForAtom(atoms[i])) {
// store this atom for later
Expand All @@ -64,6 +70,7 @@ std::vector<AtomNumber> Tree::getTree(std::vector<AtomNumber> atoms)
addtoroot.push_back(atoms[i-1]);
} else {
newatoms.push_back(atoms[i]);
positions.push_back(moldat_->getPosition(atoms[i]));
}
}
// reassign atoms
Expand All @@ -88,7 +95,7 @@ std::vector<AtomNumber> Tree::getTree(std::vector<AtomNumber> atoms)
double minroot = std::numeric_limits<double>::max();
int iroot = -1;
for(unsigned j=0; j<atoms.size(); ++j) {
double dist = delta(moldat_->getPosition(atoms[selected_vertex]), moldat_->getPosition(atoms[j])).modulo2();
double dist = delta(positions[selected_vertex], positions[j]).modulo2();
if(dist < mindist[j]) mindist[j] = dist;
if(dist < minroot && intree[j] && dist>0.0) {
minroot = dist;
Expand Down

0 comments on commit 0c40a4e

Please sign in to comment.