Skip to content
Snippets Groups Projects
Commit 6e657c15 authored by Niklaus Johner's avatar Niklaus Johner
Browse files

Added python module trajectory_analysis.py with a function

to smooth a vector or list of floats
parent 0c7d1e73
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ set(OST_MOL_ALG_PYMOD_MODULES ...@@ -10,6 +10,7 @@ set(OST_MOL_ALG_PYMOD_MODULES
"__init__.py" "__init__.py"
views.py views.py
superpose.py superpose.py
trajectory_analysis.py
) )
if (ENABLE_IMG) if (ENABLE_IMG)
......
from _ost_mol_alg import * from _ost_mol_alg import *
from ost.mol.alg.superpose import * from ost.mol.alg.superpose import *
import ost.mol.alg.trajectory_analysis
"""
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment