def test_AnalysisFromFunction(): u = mda.Universe(PSF, DCD) step = 2 ana1 = base.AnalysisFromFunction( simple_function, mobile=u.atoms).run(step=step) ana2 = base.AnalysisFromFunction(simple_function, u.atoms).run(step=step) ana3 = base.AnalysisFromFunction( simple_function, u.trajectory, u.atoms).run(step=step) results = [] for ts in u.trajectory[::step]: results.append(simple_function(u.atoms)) results = np.asarray(results) for ana in (ana1, ana2, ana3): assert_equal(results, ana.results)
def test_AnalysisFromFunction_args_content(u): protein = u.select_atoms('protein') masses = protein.masses.reshape(-1, 1) another = mda.Universe(TPR, XTC).select_atoms("protein") ans = base.AnalysisFromFunction(mass_xyz, protein, another, masses) assert len(ans.args) == 3 result = np.sum(ans.run().results) assert_almost_equal(result, -317054.67757345125, decimal=6) assert (ans.args[0] is protein) and (ans.args[1] is another) assert ans._trajectory is protein.universe.trajectory
def test_AnalysisFromFunction(u, start, stop, step, nframes): ana1 = base.AnalysisFromFunction(simple_function, mobile=u.atoms) ana1.run(start=start, stop=stop, step=step) ana2 = base.AnalysisFromFunction(simple_function, u.atoms) ana2.run(start=start, stop=stop, step=step) ana3 = base.AnalysisFromFunction(simple_function, u.trajectory, u.atoms) ana3.run(start=start, stop=stop, step=step) results = [] for ts in u.trajectory[start:stop:step]: results.append(simple_function(u.atoms)) results = np.asarray(results) assert np.size(results, 0) == nframes for ana in (ana1, ana2, ana3): assert_equal(results, ana.results)
def test_AnalysisFromFunction_warning(u): func = base.AnalysisFromFunction(simple_function, mobile=u.atoms) msg = ("The structure of the `results` array will change in MDAnalysis " "version 2.0.") with pytest.warns(DeprecationWarning, match=msg): func.run()