diff --git a/modules/geom/pymod/export_vecmat3_op.cc b/modules/geom/pymod/export_vecmat3_op.cc index b858001faac7bdaf6485c4433e6acb6b0da69cbd..5c06a2499ed7e2af0a5e73fe9ad5dd589b289a46 100644 --- a/modules/geom/pymod/export_vecmat3_op.cc +++ b/modules/geom/pymod/export_vecmat3_op.cc @@ -68,6 +68,7 @@ void export_VecMat3_op() def("Distance2WithPBC",Vec3Distance2WithPBC); def("DistanceWithPBC",Vec3DistanceWithPBC); def("MinDistance",MinDistance); + def("MinDistanceIndices",MinDistanceIndices); def("MinDistanceWithPBC",MinDistanceWithPBC); def("WrapVec3",WrapVec3); def("WrapVec3List",WrapVec3List); diff --git a/modules/geom/src/vecmat3_op.cc b/modules/geom/src/vecmat3_op.cc index 8a1debee816113fc87d196379b6e0230a241238d..2653a081fc83a0bef9bb062d1f451d1a5996672c 100644 --- a/modules/geom/src/vecmat3_op.cc +++ b/modules/geom/src/vecmat3_op.cc @@ -228,6 +228,29 @@ Real MinDistanceWithPBC(const Vec3List& l1, const Vec3List& l2, Vec3& basis_vec) return std::sqrt(min); } +std::vector<unsigned int> MinDistanceIndices(const Vec3List& l1, const Vec3List& l2) +{ + // returns the indices index1, index2 corresponding to the points in + // the Vec3List l1 and l2 having the minimal distance. + if (l1.size()==0 || l2.size()==0){throw GeomException("cannot calculate minimal distance: empty Vec3List");} + Real min=Length2(*l1.begin()-*l2.begin()); + Real d; + std::vector<unsigned int> il; + il.push_back(0); + il.push_back(0); + for (unsigned int i=0;i!=l1.size();i++){ + for (unsigned int j=0;j!=l2.size();j++){ + d=Length2(l1[i]-l2[j]); + if (d<min){ + min=d; + il[0]=i; + il[1]=j; + } + } + } + return il; +} + Vec3 WrapVec3(const Vec3& v1,const Vec3& box_center,const Vec3& basis_vec){ Vec3 v; Real r; diff --git a/modules/geom/src/vecmat3_op.hh b/modules/geom/src/vecmat3_op.hh index e13c2f07657c1c1489436b21f80b6e16b7e2a139..b4a18d3cb965e4d30cec4820cca9abb38c592472 100644 --- a/modules/geom/src/vecmat3_op.hh +++ b/modules/geom/src/vecmat3_op.hh @@ -215,7 +215,10 @@ Real DLLEXPORT_OST_GEOM MinDistance(const Vec3List& l1, const Vec3List& l2); //! returns the minimal distance between the points in two Vec3List // with periodic boundaries in x,y,z given in basis_vec Real DLLEXPORT_OST_GEOM MinDistanceWithPBC(const Vec3List& l1, const Vec3List& l2, Vec3& basis_vec); - +//! returns the indices index1, index2 corresponding to the points in +//! the Vec3List l1 and l2 having the minimal distance. +std::vector<unsigned int> DLLEXPORT_OST_GEOM MinDistanceIndices(const Vec3List& l1, const Vec3List& l2); + //!wraps a vector in a box with periodic boundaries Vec3 DLLEXPORT_OST_GEOM WrapVec3(const Vec3& v1,const Vec3& box_center,const Vec3& basis_vec); //!wraps all the verctors in a Vec3List in a box with periodic boundaries