Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 13 additions & 2 deletions testsuite/MDAnalysisTests/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import numpy as np
import pytest
from six.moves import zip, range
from six.moves import cPickle as pickle
from unittest import TestCase
from numpy.testing import (assert_equal, assert_almost_equal,
assert_array_almost_equal, assert_allclose)
Expand Down Expand Up @@ -100,8 +101,8 @@ def test_coordinates(self):
err_msg="wrong coordinates for A10:CA")

def test_distances(self):
NTERM = self.universe.atoms.N[0]
CTERM = self.universe.atoms.C[-1]
NTERM = self.universe.select_atoms("name N")[0]
CTERM = self.universe.select_atoms("name C")[-1]
d = mda.lib.mdamath.norm(NTERM.position - CTERM.position)
assert_almost_equal(d,
self.ref_distances['endtoend'],
Expand Down Expand Up @@ -424,6 +425,16 @@ def test_add_another_transformations_raises_ValueError(self, transformed):
with pytest.raises(ValueError):
transformed.add_transformations(translate([2,2,2]))

@pytest.mark.parametrize("protocol", range(1, pickle.HIGHEST_PROTOCOL+1))
def test_pickle(self, reader, protocol):
try:
s = pickle.dumps(reader, protocol=protocol)
except TypeError as err:
pytest.fail("Reader cannot be pickled with protocol={}\n{}".format(
protocol, err))
assert len(s) > 1000


class MultiframeReaderTest(BaseReaderTest):
def test_last_frame(self, ref, reader):
ts = reader[-1]
Expand Down
20 changes: 15 additions & 5 deletions testsuite/MDAnalysisTests/coordinates/test_chainreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#
from __future__ import division, absolute_import
from six.moves import zip
from six.moves import cPickle as pickle

import numpy as np
import os
Expand Down Expand Up @@ -119,8 +120,8 @@ def test_write_dcd(self, universe, tmpdir):
ts_new._pos,
self.prec,
err_msg="Coordinates disagree at frame {0:d}".format(
ts_orig.frame))
ts_orig.frame))

def test_transform_iteration(self, universe, transformed):
vector = np.float32([10,10,10])
# # Are the transformations applied and
Expand All @@ -135,15 +136,15 @@ def test_transform_iteration(self, universe, transformed):
frame = ts.frame
ref = universe.trajectory[frame].positions + vector
assert_almost_equal(ts.positions, ref, decimal = 6)

def test_transform_slice(self, universe, transformed):
vector = np.float32([10,10,10])
# what happens when we slice the trajectory?
for ts in transformed.trajectory[5:17:3]:
frame = ts.frame
ref = universe.trajectory[frame].positions + vector
assert_almost_equal(ts.positions, ref, decimal = 6)

def test_transform_switch(self, universe, transformed):
vector = np.float32([10,10,10])
# grab a frame:
Expand All @@ -154,13 +155,22 @@ def test_transform_switch(self, universe, transformed):
assert_almost_equal(transformed.trajectory[10].positions, newref, decimal = 6)
# what happens when we comeback to the previous frame?
assert_almost_equal(transformed.trajectory[2].positions, ref, decimal = 6)

def test_transfrom_rewind(self, universe, transformed):
vector = np.float32([10,10,10])
ref = universe.trajectory[0].positions + vector
transformed.trajectory.rewind()
assert_almost_equal(transformed.trajectory.ts.positions, ref, decimal = 6)

@pytest.mark.parametrize("protocol", range(1, pickle.HIGHEST_PROTOCOL+1))
def test_pickle(self, universe, protocol):
try:
s = pickle.dumps(universe.trajectory, protocol=protocol)
except TypeError as err:
pytest.fail("ChainReader cannot be pickled with protocol={}\n{}".format(
protocol, err))
assert len(s) > 1000

class TestChainReaderCommonDt(object):
common_dt = 100.0
prec = 3
Expand Down
53 changes: 52 additions & 1 deletion testsuite/MDAnalysisTests/coordinates/test_crd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,61 @@
assert_equal,
)

import numpy as np

import MDAnalysis as mda
from MDAnalysis.coordinates.CRD import CRDReader, CRDWriter
from MDAnalysis.coordinates.base import Timestep

from MDAnalysisTests.datafiles import CRD
from MDAnalysisTests.datafiles import PSF, CRD, COORDINATES_ADK
from MDAnalysisTests import make_Universe
from MDAnalysisTests.coordinates.base import (
BaseReference, BaseReaderTest, BaseWriterTest,
)


class CRDReference(BaseReference):
def __init__(self):
super(CRDReference, self).__init__()
self.trajectory = CRD
self.topology = PSF
self.reader = CRDReader
self.writer = CRDWriter
self.ext = 'crd'
self.n_frames = 1
self.totaltime = 0
self.n_atoms = 3341
self.container_format = True
self.dimensions = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
self.volume = 0.0

self.first_frame = Timestep(self.n_atoms)
self.first_frame.positions = np.loadtxt(COORDINATES_ADK, delimiter=',',
dtype=np.float32)
self.first_frame.frame = 0
self.first_frame.aux.lowf = self.aux_lowf_data[0]
self.first_frame.aux.highf = self.aux_highf_data[0]

self.last_frame = self.first_frame.copy()


class TestCRDReader(BaseReaderTest):
@staticmethod
@pytest.fixture(scope='class')
def ref():
return CRDReference()

def test_time(self, ref, reader):
u = mda.Universe(ref.topology, ref.trajectory)
assert_equal(u.trajectory.time, 0.0,
"wrong time of the frame")

def test_full_slice(self, ref, reader):
u = mda.Universe(ref.topology, ref.trajectory)
trj_iter = u.trajectory[:]
frames = [ts.frame for ts in trj_iter]
assert_equal(frames, np.arange(u.trajectory.n_frames))



class TestCRDWriter(object):
Expand Down
Binary file not shown.
10 changes: 5 additions & 5 deletions testsuite/MDAnalysisTests/data/coordinates/test_topology.pdb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
MODEL
CRYST1 80.000 80.000 80.000 60.00 60.00 90.00
ATOM 1 CA MET 1 00.000 00.000 00.000 1.00 84.71
ATOM 2 CA ARG 2 01.000 01.000 01.000 1.00 68.59
ATOM 3 CA ILE 3 02.000 02.000 02.000 1.00 48.30
ATOM 4 CA LYS 4 03.000 03.000 03.000 1.00 49.38
ATOM 5 CA LEU 5 04.000 04.000 04.000 1.00 42.10
ATOM 1 CA MET 1 0.000 0.000 0.000 1.00 84.71
ATOM 2 CA ARG 2 1.000 1.000 1.000 1.00 68.59
ATOM 3 CA ILE 3 2.000 2.000 2.000 1.00 48.30
ATOM 4 CA LYS 4 3.000 3.000 3.000 1.00 49.38
ATOM 5 CA LEU 5 4.000 4.000 4.000 1.00 42.10
END
6 changes: 5 additions & 1 deletion testsuite/MDAnalysisTests/datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from __future__ import absolute_import

__all__ = [
"COORDINATES_ADK", # numpy/csv file with 3341 coordinates from CRD
# np.savetxt("data/adk_positions.csv.gz", u.atoms.positions, delimiter=",")
"PSF", "DCD", "CRD", # CHARMM (AdK example, DIMS trajectory from JMB 2009 paper)
"DCD2", # CHARMM (AdK example, DIMS trajectory from PLOS Comput Biol paper)
"PSF_notop", "PSF_BAD", # Same as PSF but no bonds etc, malformed version of previous
Expand Down Expand Up @@ -67,7 +69,6 @@
"PDB_chainidrepeat", # Issue #1107
"PDB", "GRO", "XTC", "TRR", "TPR", "GRO_velocity", # Gromacs (AdK)
"GRO_incomplete_vels",
"COORDINATES_GRO_BZ2",
"GRO_large", #atom number truncation at > 100,000 particles, Issue 550
"GRO_residwrap", # resids wrapping because of 5 digit field (Issue #728)
"GRO_residwrap_0base", # corner case of #728 with resid=0 for first atom
Expand Down Expand Up @@ -136,6 +137,7 @@
"COORDINATES_XYZ_BZ2",
"COORDINATES_GRO",
"COORDINATES_GRO_INCOMPLETE_VELOCITY",
"COORDINATES_GRO_BZ2",
"Martini_membrane_gro", # for testing the leaflet finder
"COORDINATES_XTC",
"COORDINATES_TRR",
Expand Down Expand Up @@ -185,6 +187,8 @@
COORDINATES_DCD = resource_filename(__name__, 'data/coordinates/test.dcd')
COORDINATES_TOPOLOGY = resource_filename(__name__, 'data/coordinates/test_topology.pdb')

COORDINATES_ADK = resource_filename(__name__, 'data/adk_positions.csv.gz')

PSF = resource_filename(__name__, 'data/adk.psf')
PSF_notop = resource_filename(__name__, 'data/adk_notop.psf')
PSF_BAD = resource_filename(__name__, 'data/adk_notop_BAD.psf')
Expand Down