mcpele  1.0.0
The Monte Carlo Python Energy Landscape Explorer
rsm_displacement.cpp
00001 #include <cmath>
00002 #include <stdexcept>
00003 
00004 #include "mcpele/histogram.h"
00005 #include "mcpele/rsm_displacement.h"
00006 
00007 namespace mcpele{
00008 
00009 
00010 GetDisplacementPerParticle::GetDisplacementPerParticle(pele::Array<double> initial_coordinates_,
00011         const size_t boxdimension_)
00012     : m_initial_coordinates(initial_coordinates_.copy()),
00013       m_boxdimension(boxdimension_),
00014       m_nr_particles(initial_coordinates_.size() / boxdimension_)
00015 {}
00016 
00017 double GetDisplacementPerParticle::compute_mean_particle_displacement(pele::Array<double> new_coords)
00018 {
00019     if (new_coords.size() != m_initial_coordinates.size()) {
00020         throw std::runtime_error("GetMeanRMSDisplacement::compute_mean_rsm_displacement: illegal new coords");
00021     }
00022     Moments mom;
00023     for (size_t particle = 0; particle < m_nr_particles; ++particle) {
00024         mom.update(get_particle_displ(particle, new_coords));
00025     }
00026     return mom.mean();
00027 }
00028 
00029 double GetDisplacementPerParticle::get_particle_displ(const size_t particle_idx, pele::Array<double> new_coords)
00030 {
00031     const size_t particle_start = particle_idx * m_boxdimension;
00032     double sumsq(0);
00033     for (size_t i = particle_start; i < particle_start + m_boxdimension; ++i) {
00034         const double deltai = m_initial_coordinates[i] - new_coords[i];
00035         sumsq += deltai*deltai;
00036     }
00037     return sqrt(sumsq);
00038 }
00039 
00040 
00041 } //namespace mcpele
 All Classes Namespaces Functions Variables Typedefs