clustering  0.12
Clustering suite for molecular dynamics trajectories.
 All Classes Namespaces Files Functions Variables Typedefs
Namespaces | Classes | Typedefs | Functions | Variables
Clustering::Density Namespace Reference

namespace for density-based clustering functions More...

Namespaces

 MPI
 MPI implementations of compute intensive functions.
 
 OpenCL
 OpenCL implementations of compute intensive functions.
 

Classes

struct  BoxGrid
 

Typedefs

using FreeEnergy = std::pair< std::size_t, float >
 matches frame id to free energy
 
using Neighbor = Clustering::Tools::Neighbor
 matches neighbor's frame id to distance
 
using Neighborhood = Clustering::Tools::Neighborhood
 map frame id to neighbors
 
using Box = std::array< int, 2 >
 encodes 2D box for box-assisted search algorithm
 

Functions

BoxGrid compute_box_grid (const float *coords, const std::size_t n_rows, const std::size_t n_cols, const float radius)
 
constexpr Box neighbor_box (const Box center, const int i_neighbor)
 
bool is_valid_box (const Box box, const BoxGrid &grid)
 
std::vector< std::size_t > calculate_populations (const float *coords, const std::size_t n_rows, const std::size_t n_cols, const float radius)
 calculate population of n-dimensional hypersphere per frame for one fixed radius.
 
std::map< float, std::vector
< std::size_t > > 
calculate_populations (const float *coords, const std::size_t n_rows, const std::size_t n_cols, std::vector< float > radii)
 
std::vector< float > calculate_free_energies (const std::vector< std::size_t > &pops)
 
std::vector< FreeEnergysorted_free_energies (const std::vector< float > &fe)
 
std::tuple< Neighborhood,
Neighborhood
nearest_neighbors (const float *coords, const std::size_t n_rows, const std::size_t n_cols, const std::vector< float > &free_energy)
 
std::set< std::size_t > high_density_neighborhood (const float *coords, const std::size_t n_cols, const std::vector< FreeEnergy > &sorted_fe, const std::size_t i_frame, const std::size_t limit, const float max_dist)
 
double compute_sigma2 (const Neighborhood &nh)
 
std::vector< std::size_t > assign_low_density_frames (const std::vector< std::size_t > &initial_clustering, const Neighborhood &nh_high_dens, const std::vector< float > &free_energy)
 
void main (boost::program_options::variables_map args)
 
std::vector< std::size_t > initial_density_clustering (const std::vector< float > &free_energy, const Neighborhood &nh, const float free_energy_threshold, const float *coords, const std::size_t n_rows, const std::size_t n_cols, const std::vector< std::size_t > initial_clusters)
 

Variables

constexpr int BOX_DIFF [9][2]
 
const int N_NEIGHBOR_BOXES = 9
 number of neigbor boxes in 2D grid (including center box).
 

Detailed Description

namespace for density-based clustering functions


Class Documentation

struct Clustering::Density::BoxGrid

the full grid constructed for boxed-assisted nearest neighbor search with fixed distance criterion.

Definition at line 75 of file density_clustering.hpp.

Class Members
vector< Box > assigned_box matching frame id to the frame's assigned box
map< Box, vector< int > > boxes the boxes with a list of assigned frame ids
vector< int > n_boxes total number of boxes

Function Documentation

std::vector< std::size_t > Clustering::Density::assign_low_density_frames ( const std::vector< std::size_t > &  initial_clustering,
const Neighborhood nh_high_dens,
const std::vector< float > &  free_energy 
)

given an initial clustering computed from free energy cutoff screenings, assign all yet unclustered frames (those in 'state 0') to their geometrically next cluster. do this by starting at the lowest free energy of unassigned frames, then assigning the next lowest, etc. thus, all initial clusters will be filled with growing free energy, effectively producing microstates separated close to the free energy barriers.

Definition at line 326 of file density_clustering.cpp.

std::vector< float > Clustering::Density::calculate_free_energies ( const std::vector< std::size_t > &  pops)

re-use populations to calculate local free energy estimate via $ G = -k_B T \ln(P)$.

Definition at line 194 of file density_clustering.cpp.

std::map< float, std::vector< std::size_t > > Clustering::Density::calculate_populations ( const float *  coords,
const std::size_t  n_rows,
const std::size_t  n_cols,
const std::vector< float >  radii 
)

calculate populations of n-dimensional hypersphere per frame for different radii in one go. computationally much more efficient than running single-radius version for every radius.

Definition at line 124 of file density_clustering.cpp.

BoxGrid Clustering::Density::compute_box_grid ( const float *  coords,
const std::size_t  n_rows,
const std::size_t  n_cols,
const float  radius 
)

uses fixed radius to separate coordinate space in equally sized boxes for box-assisted nearest neighbor search.

Definition at line 39 of file density_clustering.cpp.

double Clustering::Density::compute_sigma2 ( const Neighborhood nh)

compute sigma2 as deviation of squared nearest-neighbor distances. sigma2 is given by E[x^2] > Var(x) = E[x^2] - E[x]^2, with x being the distances between nearest neighbors).

Definition at line 315 of file density_clustering.cpp.

std::set< std::size_t > Clustering::Density::high_density_neighborhood ( const float *  coords,
const std::size_t  n_cols,
const std::vector< FreeEnergy > &  sorted_fe,
const std::size_t  i_frame,
const std::size_t  limit,
const float  max_dist 
)

compute local neighborhood of a given frame. neighbor candidates are all frames below a given limit, effectively limiting the frames to the ones below a free energy cutoff.

Definition at line 274 of file density_clustering.cpp.

std::vector< std::size_t > Clustering::Density::initial_density_clustering ( const std::vector< float > &  free_energy,
const Neighborhood &  nh,
const float  free_energy_threshold,
const float *  coords,
const std::size_t  n_rows,
const std::size_t  n_cols,
const std::vector< std::size_t >  initial_clusters 
)

returns state trajectory for clusters given by a free energy threshold. frames with a local free energy estimate higher than the given threshold will not be clustered and remain in 'state 0'.

Definition at line 37 of file density_clustering_common.cpp.

bool Clustering::Density::is_valid_box ( const Box  box,
const BoxGrid &  grid 
)

returns true, if the box is a valid box in the grid. return false, if the box is outside of the grid.

Definition at line 95 of file density_clustering.cpp.

void Clustering::Density::main ( boost::program_options::variables_map  args)

user interface and controlling function for density-based geometric clustering.

parsed parameters:

  • file : input file with coordinates
  • free-energy-input: previously computed free energies (input)
  • free-energy: computed free energies (output)
  • population: computed populations (output)
  • output: clustered trajectory
  • radii: list of radii for free energy / population computations (input)
  • radius: radius for clustering (input)
  • nearest-neighbors-input: previously computed nearest neighbor list (input)
  • nearest-neighbors: nearest neighbor list (output)
  • threshold-screening: option for automated free energy threshold screening (input)
  • threshold: threshold for single run with limited free energy (input)
  • only-initial: if true, do not fill microstates up to barriers, but keep initial clusters below free energy cutoff (bool flag)

Definition at line 344 of file density_clustering.cpp.

std::tuple< Neighborhood, Neighborhood > Clustering::Density::nearest_neighbors ( const float *  coords,
const std::size_t  n_rows,
const std::size_t  n_cols,
const std::vector< float > &  free_energy 
)

for every frame: compute the nearest neighbor (first tuple field) and the nearest neighbor with lower free energy, i.e. higher density (second tuple field).

Definition at line 220 of file density_clustering.cpp.

constexpr Box Clustering::Density::neighbor_box ( const Box  center,
const int  i_neighbor 
)

returns neighbor box given by neighbor index (in 3D: 27 different neighbors, including center itself) and the given center box.

Definition at line 89 of file density_clustering.cpp.

std::vector< FreeEnergy > Clustering::Density::sorted_free_energies ( const std::vector< float > &  fe)

returns the given free energies sorted lowest to highest. original indices are retained.

Definition at line 207 of file density_clustering.cpp.

Variable Documentation

constexpr int Clustering::Density::BOX_DIFF[9][2]
Initial value:
= {{-1, 1}, { 0, 1}, { 1, 1}
, {-1, 0}, { 0, 0}, { 1, 0}
, {-1,-1}, { 0,-1}, { 1,-1}}

encodes box differences in 2D, i.e. if you are at the center box, the 9 different tuples hold the steppings to the 9 spacial neighbors (including the center box itself).

Definition at line 54 of file density_clustering.hpp.