mcpele  1.0.0
The Monte Carlo Python Energy Landscape Explorer
check_spherical_container.cpp
00001 #include "mcpele/check_spherical_container.h"
00002 
00003 using std::runtime_error;
00004 using pele::Array;
00005 
00006 namespace mcpele{
00007 
00008 CheckSphericalContainer::CheckSphericalContainer(const double radius, const size_t ndim)
00009     : m_radius2(radius * radius),
00010       m_ndim(ndim)
00011 {}
00012 
00013 bool CheckSphericalContainer::conf_test(Array<double> &trial_coords, MC * mc)
00014 {
00015   const size_t N = trial_coords.size();
00016   for (size_t i = 0; i < N; i += m_ndim) {
00017       double r2 = 0;
00018       for (size_t j = i; j < i + m_ndim; ++j) {
00019           r2 += trial_coords[j] * trial_coords[j];
00020       }
00021       if (r2 > m_radius2) {
00022           //printf("fail spherical container %d %f %f %f %f\n", i, sqrt(r2), x[i], x[i+1], x[i+2]);
00023           //an atom is outside the spherical container
00024           return false;
00025       }
00026   }
00027   //printf("check spherical OK ");
00028   return true;
00029 }
00030 
00031 } // namespace mcpele
 All Classes Namespaces Functions Variables Typedefs