Skip to content

Commit

Permalink
Merge pull request #2700 from IAlibay/remove-numtoelem
Browse files Browse the repository at this point in the history
- Fixes #2699
- Changes made in this Pull Request:
    - Removes MDAnalysis.topology._elements.py (Remove `NUMBER_TO_ELEMENTS`)
    - Switches `NUMBER_TO_ELEMENTS` to `Z2SYMB` in TOPParser
    - Adds a more thorough elements test and starts cleaning up tests in anticipation of #2651
  • Loading branch information
orbeckst authored May 28, 2020
2 parents 186cebf + 4019011 commit 57e7bd4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 150 deletions.
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Enhancements
the capability to allow intermittent behaviour (PR #2256)

Changes
* Removes duplicate `NUMBER_TO_ELEMENTS` table from topology._elements,
`Z2SYMB` from topology.tables should now be used instead (Issue #2699)
* Deprecated :class:`ProgressMeter` and replaced it with :class:`ProgressBar` using
the tqdm package (Issue #928, PR #2617). Also fixes issue #2504.
* Removed `details` from `ClusteringMethod`s (Issue #2575, PR #2620)
Expand Down
4 changes: 2 additions & 2 deletions package/MDAnalysis/topology/TOPParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import itertools

from . import guessers
from .tables import NUMBER_TO_ELEMENT
from .tables import Z2SYMB
from ..lib.util import openany, FORTRANReader
from .base import TopologyReaderBase
from ..core.topology import Topology
Expand Down Expand Up @@ -433,7 +433,7 @@ def parse_elements(self, num_per_record, numlines):

vals = self.parsesection_mapper(
numlines,
lambda x: NUMBER_TO_ELEMENT[int(x)] if int(x) > 0 else "DUMMY")
lambda x: Z2SYMB[int(x)] if int(x) > 0 else "DUMMY")
attr = Elements(np.array(vals, dtype=object))
return attr

Expand Down
144 changes: 0 additions & 144 deletions package/MDAnalysis/topology/_elements.py

This file was deleted.

1 change: 0 additions & 1 deletion package/MDAnalysis/topology/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
.. autodata:: TABLE_VDWRADII
"""
from __future__ import absolute_import
from ._elements import NUMBER_TO_ELEMENT


def kv2dict(s, convertor=str):
Expand Down
29 changes: 26 additions & 3 deletions testsuite/MDAnalysisTests/topology/test_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from __future__ import absolute_import
import MDAnalysis as mda
import pytest

import numpy as np
from numpy.testing import assert_equal
from MDAnalysisTests.topology.base import ParserBase
from MDAnalysisTests.datafiles import (
PRM, # ache.prmtop
Expand All @@ -41,6 +42,8 @@
ATOMIC_NUMBER_MSG = ("ATOMIC_NUMBER record not found, guessing atom elements "
"based on their atom types")
COORDINATE_READER_MSG = ("No coordinate reader found")


class TOPBase(ParserBase):
parser = mda.topology.TOPParser.TOPParser
expected_attrs = [
Expand Down Expand Up @@ -129,7 +132,7 @@ def test_improper_atoms_bonded(self, top):
forward = ((imp[0], imp[2]), (imp[1], imp[2]), (imp[2], imp[3]))
backward = ((imp[0], imp[1]), (imp[1], imp[2]), (imp[1], imp[3]))
for a, b in zip(forward, backward):
assert ((b in vals) or (b[::-1] in vals) or
assert ((b in vals) or (b[::-1] in vals) or
(a in vals) or (a[::-1] in vals))


Expand Down Expand Up @@ -233,6 +236,27 @@ class TestPRM12Parser(TOPBase):
(338, 337, 335, 354), (351, 337, 335, 354))
atom_zero_improper_values = ()
atom_i_improper_values = ((335, 337, 338, 351),)
elems_ranges = [[0, 36], [351, 403]]
expected_elems = [np.array(["H", "O", "C", "H", "H", "C", "H", "O", "C",
"H", "N", "C", "H", "N", "C", "C", "O", "N",
"H", "C", "N", "H", "H", "N", "C", "C", "H",
"C", "H", "H", "O", "P", "O", "O", "O", "C"],
dtype=object),
np.array(["C", "C", "H", "C", "H", "H", "O", "P", "O",
"O", "O", "C", "H", "H", "C", "H", "O", "C",
"H", "N", "C", "H", "N", "C", "C", "O", "N",
"H", "C", "N", "H", "H", "N", "C", "C", "H",
"C", "H", "H", "O", "H", "Na", "Na", "Na",
"Na", "Na", "Na", "Na", "Na", "O", "H", "H"],
dtype=object)]

def test_elements(self, top):
"""Loops over ranges of the topology elements list and compared
against a provided list of expected values.
"""
for erange, evals in zip(self.elems_ranges, self.expected_elems):
assert_equal(top.elements.values[erange[0]:erange[1]], evals,
"unexpected element match")


class TestParm7Parser(TOPBase):
Expand Down Expand Up @@ -344,7 +368,6 @@ def test_warning(self, filename):
assert len(record) == 2
assert str(record[0].message.args[0]) == ATOMIC_NUMBER_MSG
assert COORDINATE_READER_MSG in str(record[1].message.args[0])



class TestPRMNCRST(TOPBase):
Expand Down

0 comments on commit 57e7bd4

Please sign in to comment.