Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in analysis function to calculate MSDs #2619

Merged
merged 136 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
826b2ad
added msd class
Mar 2, 2020
6540de2
added in msd types and dimension factors
hmacdope Mar 2, 2020
f50622c
fill out framework to calculate msd
hmacdope Mar 2, 2020
aa29d3b
fill out framework to calculate msd
hmacdope Mar 2, 2020
6e72bd4
fix merge conflict
hmacdope Mar 2, 2020
671e537
skeleton algorithm for naieve MSD algorithm
hmacdope Mar 3, 2020
b0e296b
add in fft algorithm skeleton
hmacdope Mar 3, 2020
67fc0d0
naieve algorithm complete
hmacdope Mar 4, 2020
3018a62
added in fft compute and tests
hmacdope Mar 11, 2020
44407e4
cleaned up tests and started working on docs
hmacdope Mar 11, 2020
4711fb6
ready to open WIP opull request
hmacdope Mar 13, 2020
f9f7dd9
worked on documentation and examples
hmacdope Mar 13, 2020
2358a11
more work on docs
hmacdope Mar 13, 2020
a8d400a
doc and example improvements
hmacdope Mar 14, 2020
0a960e4
improved numerical performance of FFT based algorithm
hmacdope Mar 14, 2020
cc11cc6
added in tidynamics tests
hmacdope Mar 15, 2020
e9b17fe
clean up deps
hmacdope Mar 15, 2020
09b5458
added tidynamics to test deps
hmacdope Mar 15, 2020
a06294b
test tidynymaics in test block and updated docs
hmacdope Mar 15, 2020
4cf63fd
try and fix install
hmacdope Mar 15, 2020
e5e3629
fix single failed build
hmacdope Mar 15, 2020
2c469f0
change travis and appveyor settings
hmacdope Mar 15, 2020
546f7f2
fix .appveyor
hmacdope Mar 15, 2020
e02dd09
Merge branch 'develop' into add_msd
hmacdope Mar 15, 2020
033273b
relax to decimal=3 tol for FFT step_traj test due to failing numpy=1.…
hmacdope Mar 15, 2020
dd5b25d
Merge branch 'add_msd' of github.com:hmacdope/mdanalysis into add_msd
hmacdope Mar 15, 2020
83be862
switch .indices for .ix for proper indexing of coordinate array
hmacdope Mar 15, 2020
d318a91
implement reccomended changes and improve docs
hmacdope Mar 16, 2020
10e3fc2
add small test to ensure selection is working
hmacdope Mar 16, 2020
089a2bd
add capability to pull out MSDs per particle
hmacdope Mar 16, 2020
d108453
fix typo in per particle tests
hmacdope Mar 16, 2020
8ebc233
add in test to show numerical error in constan tvelocity trajectory.
hmacdope May 15, 2020
e2d383d
replaced own fft code with tidynamics
hmacdope May 17, 2020
73bc1f7
add duecredit citation
hmacdope May 17, 2020
c71f5e6
add FCA citation
hmacdope May 17, 2020
ddbc4e3
update requires and fix docs build
hmacdope May 17, 2020
523f81f
update citation
hmacdope May 17, 2020
6eb76e2
Merge branch 'develop' into add_msd
hmacdope May 18, 2020
86d59bb
fix appveyor and travis yml, removing duplication
hmacdope May 18, 2020
a934882
fix typo in travis.yml
hmacdope May 18, 2020
7759da7
fix failing numpy=1.13 nets and update CHANGELOG
hmacdope May 18, 2020
851daa3
Update package/CHANGELOG
hmacdope May 18, 2020
d23ee0e
Update package/MDAnalysis/analysis/msd.py
hmacdope May 18, 2020
49fbd86
Merge branch 'develop' into add_msd
hmacdope May 18, 2020
9af111a
clean up imports and typos
hmacdope May 19, 2020
19625f0
Merge branch 'add_msd' of github.com:hmacdope/mdanalysis into add_msd
hmacdope May 20, 2020
0f637dd
framework moved to subclass AnalysisBase
hmacdope May 20, 2020
4c5f487
AnalysisBase compatible and passing tests
hmacdope May 20, 2020
78f7d4f
fix msd_by_particle and corresponding tests
hmacdope May 20, 2020
b458ae8
removed some inline comments that were useless
hmacdope May 20, 2020
09416cb
changed parse_msd_type to a clearer selection syntax
hmacdope May 20, 2020
60f0cca
remove fstring causing failed builds
hmacdope May 20, 2020
38da36e
fix typo in fstring removal
hmacdope May 20, 2020
0e22adf
fix another typo in fstring removal
hmacdope May 20, 2020
504e19c
clean up half changes to select kwarg
hmacdope May 20, 2020
e805403
clean up references
hmacdope May 20, 2020
3ba54a0
Merge remote-tracking branch 'upstream/develop' into add_msd
hmacdope May 20, 2020
6f70f06
fix docstring references
hmacdope May 21, 2020
4894bbd
improve docs and add image
hmacdope May 22, 2020
3a48b61
spelling in docs
hmacdope May 22, 2020
0d34487
remove inner loop over n_particles in simple MSD algorithm
hmacdope May 23, 2020
4ca2bf7
add seeding for np.random.randint
hmacdope May 23, 2020
8249a65
add pytest.mark.parametrize and move global vars to pytest.fixtures
hmacdope May 25, 2020
63b8fff
refactor constant velocity test using pytest.mark.parametrize
hmacdope May 25, 2020
0fc07f7
add tidynamics versioning
hmacdope May 25, 2020
0d69b65
move tidynamics to out of CONDA_MIN_DEPENDENCIES
hmacdope May 25, 2020
98d4b48
Update package/MDAnalysis/analysis/msd.py
hmacdope Jun 1, 2020
7d530eb
change docs markup
hmacdope Jun 1, 2020
2c760eb
spelling
hmacdope Jun 1, 2020
a7136c0
spelling
hmacdope Jun 1, 2020
ef6b6f4
caps
hmacdope Jun 1, 2020
f4aeaea
spelling
hmacdope Jun 1, 2020
121ac17
spelling
hmacdope Jun 1, 2020
09bedac
phrasing
hmacdope Jun 1, 2020
e070fb8
spelling
hmacdope Jun 1, 2020
d8c81cd
spelling
hmacdope Jun 1, 2020
1ac4086
spelling
hmacdope Jun 1, 2020
7a58d73
spelling
hmacdope Jun 1, 2020
c3ae32b
markup
hmacdope Jun 1, 2020
7764f9e
spelling
hmacdope Jun 1, 2020
9005ad5
change dimensions of base array
hmacdope Jun 1, 2020
e898226
keep dim of _position_array consistent
hmacdope Jun 1, 2020
b370a27
Merge branch 'develop' into add_msd
hmacdope Jun 1, 2020
3f5f5f3
pep8 lint
hmacdope Jun 1, 2020
e4e46ba
fix PEP8 compliance for line length
hmacdope Jun 2, 2020
d09f79c
update docs for PEP8 compliance
hmacdope Jun 3, 2020
cff23b0
add more references and tidy docs
hmacdope Jun 3, 2020
ba6f37a
removed repetitive structure in self.msd
hmacdope Jun 3, 2020
42720d8
clean up and PEP8 tests
hmacdope Jun 3, 2020
0f5a009
fix typo
hmacdope Jun 3, 2020
cc53e1b
refactor to only use the right dimension
hmacdope Jun 3, 2020
79f93a4
change docs for array sizing
hmacdope Jun 3, 2020
e9f4cf4
authroship note
hmacdope Jun 3, 2020
b909aad
move tidynamics to try except import
hmacdope Jun 3, 2020
bac625b
typo
hmacdope Jun 3, 2020
1aef299
lag time to lag-time
hmacdope Jun 3, 2020
2648d05
add start stop step tests
hmacdope Jun 3, 2020
a5a9716
Merge branch 'develop' into add_msd
hmacdope Jun 10, 2020
eccc5ea
fix start stop step tests
hmacdope Jun 10, 2020
f27b0da
fix test offsets
hmacdope Jun 10, 2020
33a8907
change docs
hmacdope Jun 10, 2020
fb7f458
clean up extra variables
hmacdope Jun 10, 2020
ac3a525
Merge branch 'add_msd' of github.com:hmacdope/mdanalysis into add_msd
hmacdope Jun 10, 2020
5e8c17f
fix docs
hmacdope Jun 10, 2020
41dde3f
fix import Error
hmacdope Jun 10, 2020
269ea05
Update package/MDAnalysis/analysis/msd.py
hmacdope Jun 10, 2020
ae5b93b
Merge branch 'add_msd' of https://github.com/hmacdope/mdanalysis into…
orbeckst Jun 11, 2020
2feb81e
corrected indentation and updated CHANGELOG
orbeckst Jun 11, 2020
141dca8
EinsteinMSD: also document run() method
orbeckst Jun 11, 2020
d007ac9
reorganized analysis docs toc for structure
orbeckst Jun 11, 2020
e1dbbbe
Update package/MDAnalysis/analysis/msd.py
hmacdope Jun 11, 2020
923e161
Update package/MDAnalysis/analysis/msd.py
hmacdope Jun 11, 2020
607e228
Update package/MDAnalysis/analysis/msd.py
hmacdope Jun 11, 2020
e983f83
fix
hmacdope Jun 11, 2020
7d4e54f
typo
hmacdope Jun 11, 2020
8498f1a
change import
hmacdope Jun 11, 2020
e39433e
change import error
hmacdope Jun 11, 2020
50b9f11
Update package/MDAnalysis/analysis/msd.py
hmacdope Jun 11, 2020
af5cedf
newline
hmacdope Jun 11, 2020
e76f164
Revert "newline"
hmacdope Jun 11, 2020
1d62c0c
change docs
hmacdope Jun 11, 2020
a55ad30
change docs
hmacdope Jun 11, 2020
491da98
change docs
hmacdope Jun 11, 2020
09fb909
Merge branch 'add_msd' of github.com:hmacdope/mdanalysis into add_msd
hmacdope Jun 11, 2020
4d9c2d5
confusion over revert
hmacdope Jun 11, 2020
0cf1882
change author notes etc
hmacdope Jun 11, 2020
f1c7bd2
small edits
hmacdope Jun 11, 2020
7321bb6
rip out docstrings for internal functions
hmacdope Jun 12, 2020
18eb09c
fix docstrings and line conts
hmacdope Jun 12, 2020
353ae3e
remove extra dtypes
hmacdope Jun 12, 2020
78911b8
more dtypes removed
hmacdope Jun 12, 2020
e8478ba
Merge branch 'develop' into add_msd
hmacdope Jun 12, 2020
6513f8b
remove select from kwargs
hmacdope Jun 12, 2020
38eeb15
Merge branch 'add_msd' of github.com:hmacdope/mdanalysis into add_msd
hmacdope Jun 12, 2020
fe02375
Merge remote-tracking branch 'upstream/develop' into add_msd
hmacdope Jun 14, 2020
16dca64
fix docs build error
hmacdope Jun 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions package/MDAnalysis/analysis/msd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
#
# MDAnalysis --- https://www.mdanalysis.org
# Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors
# (see the file AUTHORS for the full list of names)
#
# Released under the GNU Public Licence, v2 or any higher version
#
# Please cite your use of MDAnalysis in published work:
#
# R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler,
# D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein.
# MDAnalysis: A Python package for the rapid analysis of molecular dynamics
# simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th
# Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy.
# doi: 10.25080/majora-629e541a-00e
#
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein.
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations.
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#

"""
Mean Squared Displacement --- :mod:`MDAnalysis.analysis.msd`
==============================================================

This module implements the calculation of Mean Squared Displacmements (MSD).
MSDs can be used to characterise the speed at which particles move and has its roots
in the study of Brownian motion. For a thorough review see XXX et al. MSDs are computed from
the following expression

Where XX represents an ensemble average over

The computation of the MSD in this way can be computationally intensive due to it's N^2 scaling.
An algorithm to compute the MSD with Nlogn(N) scaling based on a Fast Fourier Transform is known and can be accessed by setting FFT=True.




Classes and Functions
---------------------

.. autoclass:: MeanSquaredDisplacement


"""

from __future__ import division, absolute_import
from six.moves import zip

import os
import errno
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
import warnings
import bz2
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
import functools
hmacdope marked this conversation as resolved.
Show resolved Hide resolved

import numpy as np
from scipy import fft,ifft
import logging
import MDAnalysis
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
hmacdope marked this conversation as resolved.
Show resolved Hide resolved



class MeanSquaredDisplacement(object):
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
r"""Class representing a density on a regular cartesian grid.

Parameters
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
----------∏
u :
An MDAnalysis Universe :class:`Universe`
selection :
An MDAnalysis selection string



Attributes
----------




Notes
-----
Notes


See Also
--------


Examples
--------
Typical use:



hmacdope marked this conversation as resolved.
Show resolved Hide resolved
"""

def __init__(self, u, selection, msd_type='xyz', fft=True):

#args
self.u = u
self.selection = selection
self.msd_type = msd_type
self.fft = fft

#local
self.dim_fac = 0
self._dim = None
self.atoms = None
self.n_frames = len(self.u.trajectory)
self._position_array = None

#result
self.timeseries = None
#prep
self._prepare()


def _prepare(self):
self.parse_msd_type()
self.select_reference_positions()

def parse_msd_type(self):
hmacdope marked this conversation as resolved.
Show resolved Hide resolved

if self.msd_type == 'xyz': # full 3d
self._dim = [0,1,2]
self.dim_fac = 3.0

elif self.msd_type == 'xy': # xy
self._dim = [0,1]
self.dim_fac = 2.0

elif self.msd_type == 'xz': # xz
self._dim = [0,2]
self.dim_fac = 2.0

elif self.msd_type == 'yz': # yz
self._dim = [1,2]
self.dim_fac = 2.0

elif self.msd_type == 'x': # x
self._dim = [0]
self.dim_fac = 1.0

elif self.msd_type == 'y': # y
self._dim = [1]
self.dim_fac = 1.0

elif self.msd_type == 'z': # z
self._dim = [2]
self.dim_fac = 1.0

else:
raise ValueError('invalid msd_type specified')
hmacdope marked this conversation as resolved.
Show resolved Hide resolved

def select_reference_positions(self):
self._position_array = self.u.trajectory.timeseries(self.u.select_atoms(self.selection),order='fac')
self.N_particles = self._position_array.shape[1]

def run(self):
if self.fft == True:
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
self.timeseries = self._run_fft()
else:
self.timeseries = self._run_simple()

def _run_simple(self): # naieve algorithm without FFT
# _position_array is shape time, nparticles, 3
msds_byparticle = np.zeros([self.n_frames, self.N_particles])
lagtimes = np.arange(1,self.n_frames)
msds_byparticle[0,:] = np.zeros(self.N_particles) # preset the zero lagtime so we dont have to iterate through
for n in range(self.N_particles):
for lag in lagtimes:
disp = self._position_array[:-lag,n,self._dim if lag else None] - self._position_array[lag:,n,self._dim]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lag will never be falsy because you've defined it between a range of 1 and N_frames

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to get rid of the outer loop, I think with something like the below? @tylerjereddy would know more

disp = self._position_array[:-lag, :, self._dim] - self._position_array[lag:, :, self._dim]
msds_by_particle[lag] = disp.sum(axis=-1) ** 2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks worth a try--I guess this is a little mind bending because of the 3D array data structure for _position_array. If it is already covered by unit tests that will make it easier to try to improve of course.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do subclass AnalysisBase, you may be able to get rid of the for lag in lagtimes loop as well (or more accurately merge it into the loop that run() always calls). Not sure how this will work with tidynamics.

def _single_frame(self):
  self.disp[:-self.frame_index] += self.ag.positions[self._dim]
  self.disp[self.frame_index:] -= self.ag.positions[self._dim]

def _conclude(self):
  self.msds_by_particle = self.disp**2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the outer loop over n_particles.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the work into the run loop I think is a bit suboptimal, as the data still needs to be accumulated for the tidynamics FFT based option. Happy to discuss.

sqdist = np.square(disp, dtype=np.float64).sum(axis=1, dtype=np.float64) #accumulation in anything other than f64 is innacurate
lilyminium marked this conversation as resolved.
Show resolved Hide resolved
msds_byparticle[lag,n] = np.mean(sqdist, dtype=np.float64)
msds = msds_byparticle.mean(axis=1, dtype=np.float64)
return msds

def _run_fft(self): #with FFT
# _position_array is shape time, nparticles, 3
msds_byparticle = []
reshape_positions = self._position_array[:,:,self._dim]
N=reshape_positions.shape[0]
D=np.square(reshape_positions).sum(axis=2, dtype=np.float64)
D=np.append(D,np.zeros(reshape_positions.shape[:2]), axis=0)
Q=2*D.sum(axis=0)
S1=np.zeros(reshape_positions.shape[:2])
for m in range(N):
Q=Q-D[m-1,:]-D[N-m,:]
S1[m,:]=Q/(N-m)

S2accumulate = []
for i in range(reshape_positions.shape[2]):
S2accumulate.append(self.autocorrFFT(reshape_positions[:,:,i]))
S2= np.sum(S2accumulate,axis=0,dtype=np.float64)

msds_byparticle.append(S1-2*S2)
msds = np.concatenate(msds_byparticle,axis=1).mean(axis=-1, dtype=np.float64)
return msds

@staticmethod
def autocorrFFT(x):
N=(x.shape[0])
F = fft(x, n=2*N, axis=0) #zero pad to get non-cyclic autocorrelation
PowerSpectralDensity = F * F.conjugate()
inverse = ifft(PowerSpectralDensity,axis=0)
autocorr = (inverse[:N]).real #autocorr convention B
n = np.arange(1, N+1)[::-1]
return autocorr/n[:, np.newaxis] #autocorr convention A


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. automodule:: MDAnalysis.analysis.msd
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Structure
analysis/helanal
analysis/rdf
analysis/dihedrals

analysis/msd

Volumetric analysis
===================
Expand Down
128 changes: 128 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_msd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
#
# MDAnalysis --- https://www.mdanalysis.org
# Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors
# (see the file AUTHORS for the full list of names)
#
# Released under the GNU Public Licence, v2 or any higher version
#
# Please cite your use of MDAnalysis in published work:
#
# R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler,
# D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein.
# MDAnalysis: A Python package for the rapid analysis of molecular dynamics
# simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th
# Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy.
# doi: 10.25080/majora-629e541a-00e
#
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein.
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations.
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
from __future__ import division, absolute_import, print_function
hmacdope marked this conversation as resolved.
Show resolved Hide resolved



import MDAnalysis as mda
from MDAnalysis.analysis.msd import MeanSquaredDisplacement as MSD

from numpy.testing import (assert_array_less,
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
assert_almost_equal, assert_equal)
import numpy as np

from scipy import fft,ifft

from MDAnalysisTests.datafiles import PSF, DCD, DCD

import pytest

SELECTION = 'backbone and name CA and resid 1-10'
NSTEP = 1000

@pytest.fixture(scope='module')
def u():
return mda.Universe(PSF, DCD)

@pytest.fixture(scope='module')
def msd(u):
m = MSD(u, SELECTION, msd_type='xyz', fft=False)
m.run()
return m

@pytest.fixture(scope='module')
def msd_fft(u):
m = MSD(u, SELECTION, msd_type='xyz', fft=True)
m.run()
return m

@pytest.fixture(scope='module')
def dimension_list():
dimensions = ['xyz', 'xy', 'xz', 'yz', 'x', 'y', 'z']
return dimensions

@pytest.fixture(scope='module')
def step_traj():
x = np.arange(NSTEP)
traj = np.vstack([x,x,x]).T
traj_reshape = traj.reshape([NSTEP,1,3])
u = mda.Universe.empty(1)
u.load_new(traj_reshape)
return u

def characteristic_poly(n,d): #polynomial that describes unit step trajectory MSD
x = np.arange(1,n+1)
y = d*((x-1)*(x-1))
return y

def test_fft_vs_simple_default(msd, msd_fft):
timeseries_simple = msd.timeseries
timeseries_fft = msd_fft.timeseries
assert_almost_equal(timeseries_simple, timeseries_fft, decimal=5)

def test_fft_vs_simple_all_dims(dimension_list, u):
for dim in dimension_list:
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
m_simple = MSD(u, SELECTION, msd_type=dim, fft=False)
m_simple.run()
timeseries_simple = m_simple.timeseries
m_fft = MSD(u,SELECTION, msd_type=dim, fft=True)
m_fft.run()
timeseries_fft = m_fft.timeseries
assert_almost_equal(timeseries_simple, timeseries_fft, decimal=5)

def test_simple_step_traj_3d(step_traj): # this should fit the polynomial 3(x-1)**2
m_simple = MSD(step_traj, 'all' , msd_type='xyz', fft=False)
m_simple.run()
poly3 = characteristic_poly(NSTEP,3)
assert_almost_equal(m_simple.timeseries, poly3)

def test_simple_step_traj_2d(step_traj): # this should fit the polynomial 2(x-1)**2
m_simple = MSD(step_traj, 'all' , msd_type='xy', fft=False)
m_simple.run()
poly2 = characteristic_poly(NSTEP,2)
assert_almost_equal(m_simple.timeseries, poly2)

def test_simple_step_traj_1d(step_traj): # this should fit the polynomial (x-1)**
m_simple = MSD(step_traj, 'all' , msd_type='x', fft=False)
m_simple.run()
poly1 = characteristic_poly(NSTEP,1)
assert_almost_equal(m_simple.timeseries, poly1)

def test_fft_step_traj_3d(step_traj): # this should fit the polynomial 3(x-1)**2
m_fft = MSD(step_traj, 'all' , msd_type='xyz', fft=True)
m_fft.run()
poly3 = characteristic_poly(NSTEP,3)
assert_almost_equal(m_fft.timeseries, poly3)

def test_fft_step_traj_2d(step_traj): # this should fit the polynomial 2(x-1)**2
m_fft = MSD(step_traj, 'all' , msd_type='xy', fft=True)
m_fft.run()
poly2 = characteristic_poly(NSTEP,2)
assert_almost_equal(m_fft.timeseries, poly2)

def test_fft_step_traj_1d(step_traj): # this should fit the polynomial (x-1)**2
m_fft = MSD(step_traj, 'all' , msd_type='x', fft=True)
m_fft.run()
poly1 = characteristic_poly(NSTEP,1)
assert_almost_equal(m_fft.timeseries, poly1)