diff --git a/modules/mol/alg/pymod/CMakeLists.txt b/modules/mol/alg/pymod/CMakeLists.txt index 004c475efdf99c095aa693c133f7a2af51e84248..0bfc29b0ac698170f91e2189c5359a408464acc8 100644 --- a/modules/mol/alg/pymod/CMakeLists.txt +++ b/modules/mol/alg/pymod/CMakeLists.txt @@ -10,6 +10,7 @@ set(OST_MOL_ALG_PYMOD_MODULES "__init__.py" views.py superpose.py + trajectory_analysis.py ) if (ENABLE_IMG) diff --git a/modules/mol/alg/pymod/__init__.py b/modules/mol/alg/pymod/__init__.py index 98fe346c5a07b1e28571832929b535ab0588adb3..11c4c0198ffcaa328223a0e826bbb43d56130996 100644 --- a/modules/mol/alg/pymod/__init__.py +++ b/modules/mol/alg/pymod/__init__.py @@ -1,3 +1,3 @@ from _ost_mol_alg import * from ost.mol.alg.superpose import * - +import ost.mol.alg.trajectory_analysis diff --git a/modules/mol/alg/pymod/trajectory_analysis.py b/modules/mol/alg/pymod/trajectory_analysis.py new file mode 100644 index 0000000000000000000000000000000000000000..5e8c452b74c43fbf15247a4da70dd8c613d6a846 --- /dev/null +++ b/modules/mol/alg/pymod/trajectory_analysis.py @@ -0,0 +1,48 @@ +""" +Some functions for analyzing trajectories + +Author: Niklaus Johner +""" + +from ost import * +import os + +def smooth(vec,n): +#Function to smooth a vector or a list of floats +#for each element it takes the average over itself and the +#n elements on each side, so over (2n+1) elements + try: + vec2=vec.copy() + except: + vec2=vec[:] + for i in range(n): + v=0.0 + count=1.0 + v+=vec[i] + for j in range(n): + count+=1 + v+=vec[i+j+1] + for j in range(i): + count+=1 + v+=vec[i-(j+1)] + vec2[i]=v/float(count) + for i in range(1,n+1): + v=0.0 + count=1.0 + v+=vec[-i] + for j in range(n): + count+=1 + v+=vec[-(i+j+1)] + for j in range(i-1): + count+=1 + v+=vec[-i+j+1] + vec2[-i]=v/float(count) + for i in range(n,len(vec2)-n): + v=vec[i] + for j in range(n): + v+=vec[i+j+1] + v+=vec[i-j-1] + vec2[i]=v/float(2.*n+1.) + return vec2 + +