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

Port topology module #1420

Merged
merged 4 commits into from
Jun 24, 2017
Merged
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
8 changes: 7 additions & 1 deletion testsuite/MDAnalysisTests/topology/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
from __future__ import absolute_import

from unittest import TestCase

from numpy.testing import (
assert_,
)
Expand All @@ -28,11 +31,14 @@
from MDAnalysis.core.topology import Topology


class ParserBase(object):
class ParserBase(TestCase):
"""Base class for testing Topology parsers.

All Parsers must subclass this class!
"""

__test__ = False

expected_attrs = []
guessed_attrs = []

Expand Down
5 changes: 5 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_crd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#
from __future__ import absolute_import

from unittest import TestCase

import MDAnalysis as mda

from MDAnalysisTests.topology.base import ParserBase
Expand All @@ -30,6 +32,9 @@


class TestCRDParser(ParserBase):

__test__ = True

parser = mda.topology.CRDParser.CRDParser
filename = CRD
expected_attrs = ['ids', 'names', 'tempfactors',
Expand Down
29 changes: 28 additions & 1 deletion testsuite/MDAnalysisTests/topology/test_dlpoly.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@


class DLPUniverse(ParserBase):

__test__ = False

def test_creates_universe(self):
u = mda.Universe(self.filename, topology_format=self.format)
assert_(isinstance(u, mda.Universe))

class DLPBase2(DLPUniverse):

__test__ = False

expected_attrs = ['ids', 'names']
guessed_attrs = ['types', 'masses']
expected_n_atoms = 216
Expand All @@ -56,18 +62,27 @@ def test_names(self):


class TestDLPHistoryParser(DLPBase2):

__test__ = True

parser = mda.topology.DLPolyParser.HistoryParser
filename = DLP_HISTORY
format='HISTORY'


class TestDLPConfigParser(DLPBase2):

__test__ = True

parser = mda.topology.DLPolyParser.ConfigParser
filename = DLP_CONFIG
format='CONFIG'


class DLPBase(DLPUniverse):

__test__ = False

expected_attrs = ['ids', 'names']
guessed_attrs = ['types', 'masses']
expected_n_atoms = 3
Expand All @@ -80,24 +95,36 @@ def test_dlp_names(self):


class TestDLPConfigMinimal(DLPBase):

__test__ = True

parser = mda.topology.DLPolyParser.ConfigParser
filename = DLP_CONFIG_minimal
format='CONFIG'


class TestDLPConfigOrder(DLPBase):

__test__ = True

parser = mda.topology.DLPolyParser.ConfigParser
filename = DLP_CONFIG_order
format='CONFIG'


class TestDLPHistoryMinimal(DLPBase):

__test__ = True

parser = mda.topology.DLPolyParser.HistoryParser
filename = DLP_HISTORY_minimal
format='HISTORY'


class TestDLPHistoryOrder(DLPBase):

__test__ = True

parser = mda.topology.DLPolyParser.HistoryParser
filename = DLP_HISTORY_order
format='HISTORY'
3 changes: 3 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@


class TestDMSParser(ParserBase):

__test__ = True

parser = mda.topology.DMSParser.DMSParser
filename = DMS
expected_attrs = ['ids', 'names', 'bonds', 'charges',
Expand Down
12 changes: 12 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_gms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@


class GMSBase(ParserBase):

__test__ = False

parser = mda.topology.GMSParser.GMSParser
expected_attrs = ['names', 'atomiccharges']
guessed_attrs = ['masses', 'types']
Expand All @@ -44,6 +47,9 @@ class GMSBase(ParserBase):


class TestGMSASYMOPT(GMSBase):

__test__ = True

filename = GMS_ASYMOPT
expected_n_atoms = 6

Expand All @@ -57,6 +63,9 @@ def test_types(self):


class TestGMSSYMOPT(GMSBase):

__test__ = True

filename = GMS_SYMOPT
expected_n_atoms = 4

Expand All @@ -69,4 +78,7 @@ def test_types(self):
[6, 6, 1, 1])

class TestGMSASYMSURF(TestGMSASYMOPT):

__test__ = True

filename = GMS_ASYMSURF
3 changes: 3 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_gro.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@


class TestGROParser(ParserBase):

__test__ = True

parser = mda.topology.GROParser.GROParser
filename = GRO
expected_attrs = ['ids', 'names', 'resids', 'resnames', 'masses']
Expand Down
37 changes: 13 additions & 24 deletions testsuite/MDAnalysisTests/topology/test_guessers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,61 +36,50 @@
from MDAnalysisTests.core.test_fragments import make_starshape

class TestGuessMasses(object):
@staticmethod
def test_guess_masses():
def test_guess_masses(self):
out = guessers.guess_masses(['C', 'C', 'H'])

assert_(isinstance(out, np.ndarray))
assert_array_equal(out,
np.array([12.011, 12.011, 1.008]))

@staticmethod
def test_guess_masses_warn():
def test_guess_masses_warn(self):
assert_warns(UserWarning, guessers.guess_masses, ['X'])

@staticmethod
def test_guess_masses_miss():
def test_guess_masses_miss(self):
out = guessers.guess_masses(['X', 'Z'])
assert_array_equal(out, np.array([0.0, 0.0]))

@staticmethod
def test_get_atom_mass():
def test_get_atom_mass(self):
assert_(guessers.get_atom_mass('H') == 1.008)

@staticmethod
def test_get_atom_mass_miss():
def test_get_atom_mass_miss(self):
assert_(guessers.get_atom_mass('XYZ') == 0.0)

@staticmethod
def test_guess_atom_mass():
def test_guess_atom_mass(self):
assert_(guessers.guess_atom_mass('1H') == 1.008)


class TestGuessTypes(object):
# guess_types
# guess_atom_type
# guess_atom_element
@staticmethod
def test_guess_types():
def test_guess_types(self):
out = guessers.guess_types(['MG2+', 'C12'])

assert_(isinstance(out, np.ndarray))
assert_array_equal(out, np.array(['MG', 'C'], dtype=object))

@staticmethod
def test_guess_atom_element():

def test_guess_atom_element(self):
assert_(guessers.guess_atom_element('MG2+') == 'MG')

@staticmethod
def test_guess_atom_element_empty():

def test_guess_atom_element_empty(self):
assert_(guessers.guess_atom_element('') == '')

@staticmethod
def test_guess_atom_element_singledigit():
def test_guess_atom_element_singledigit(self):
assert_(guessers.guess_atom_element('1') == '1')

@staticmethod
def test_guess_atom_element_1H():
def test_guess_atom_element_1H(self):
assert_(guessers.guess_atom_element('1H') == 'H')
assert_(guessers.guess_atom_element('2H') == 'H')

Expand Down
3 changes: 3 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_hoomdxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@


class TestHoomdXMLParser(ParserBase):

__test__ = True

parser = mda.topology.HoomdXMLParser.HoomdXMLParser
filename = HoomdXMLdata
expected_attrs = ['types', 'masses', 'charges', 'radii',
Expand Down
21 changes: 21 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_lammpsdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@


class LammpsBase(ParserBase):

__test__ = False

parser = mda.topology.LAMMPSParser.DATAParser
expected_n_segments = 1
expected_attrs = ['types', 'resids', 'masses', 'charges']
Expand Down Expand Up @@ -100,6 +103,9 @@ class TestLammpsData(LammpsBase):
The reading of coords and velocities is done separately in
test_coordinates
"""

__test__ = True

filename = LAMMPSdata
expected_n_atoms = 18364
expected_n_atom_types = 10
Expand All @@ -114,6 +120,9 @@ class TestLammpsData(LammpsBase):


class TestLAMMPSCNT(LammpsBase):

__test__ = True

filename = LAMMPScnt
expected_n_atoms = 604
expected_n_atom_types = 1
Expand All @@ -129,10 +138,16 @@ class TestLAMMPSCNT(LammpsBase):


class TestLAMMPSCNT2(TestLAMMPSCNT):

__test__ = True

filename = LAMMPScnt2


class TestLAMMPSHYD(LammpsBase):

__test__ = True

filename = LAMMPShyd
expected_n_atoms = 2
expected_n_atom_types = 1
Expand All @@ -145,10 +160,16 @@ class TestLAMMPSHYD(LammpsBase):


class TestLAMMPSHYD2(TestLAMMPSHYD):

__test__ = True

filename = LAMMPShyd2


class TestLAMMPSDeletedAtoms(LammpsBase):

__test__ = True

filename = LAMMPSdata_deletedatoms

expected_n_atoms = 10
Expand Down
14 changes: 10 additions & 4 deletions testsuite/MDAnalysisTests/topology/test_mmtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
from MDAnalysisTests.topology.base import ParserBase
from MDAnalysisTests.datafiles import MMTF, MMTF_gz

from unittest import TestCase


class TestMMTFParser(ParserBase):
__test__ = False

parser = mda.topology.MMTFParser.MMTFParser
filename = MMTF
expected_attrs = ['ids', 'names', 'types', 'altLocs',
Expand All @@ -27,13 +31,15 @@ class TestMMTFParser(ParserBase):


class TestMMTFParser_gz(TestMMTFParser):
__test__ = True

filename = MMTF_gz
expected_n_atoms = 1140
expected_n_residues = 36
expected_n_segments = 4


class TestMMTFUniverse(object):
class TestMMTFUniverse(TestCase):
def setUp(self):
self.u = mda.Universe(MMTF)

Expand Down Expand Up @@ -87,7 +93,7 @@ def setUp(self):
self.u = mda.Universe(top)


class TestMMTFgzUniverse(object):
class TestMMTFgzUniverse(TestCase):
def setUp(self):
self.u = mda.Universe(MMTF_gz)

Expand Down Expand Up @@ -119,9 +125,9 @@ def setUp(self, mock_fetch):
top = mmtf.parse(MMTF)
mock_fetch.return_value = top
self.u = mda.fetch_mmtf('173D') # string is irrelevant


class TestSelectModels(object):

class TestSelectModels(TestCase):
# tests for 'model' keyword in select_atoms
def setUp(self):
self.u = mda.Universe(MMTF_gz)
Expand Down
Loading