diff --git a/package/CHANGELOG b/package/CHANGELOG index a282fab6ed0..b03db1587eb 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -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) diff --git a/package/MDAnalysis/topology/TOPParser.py b/package/MDAnalysis/topology/TOPParser.py index b16ea022eac..53fde99a02a 100644 --- a/package/MDAnalysis/topology/TOPParser.py +++ b/package/MDAnalysis/topology/TOPParser.py @@ -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 @@ -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 diff --git a/package/MDAnalysis/topology/_elements.py b/package/MDAnalysis/topology/_elements.py deleted file mode 100644 index 35a55c3e225..00000000000 --- a/package/MDAnalysis/topology/_elements.py +++ /dev/null @@ -1,144 +0,0 @@ -# -*- 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 -# - -# atomic number to element dict -NUMBER_TO_ELEMENT = { - 1: 'H', - 2: 'He', - 3: 'Li', - 4: 'Be', - 5: 'B', - 6: 'C', - 7: 'N', - 8: 'O', - 9: 'F', - 10: 'Ne', - 11: 'Na', - 12: 'Mg', - 13: 'Al', - 14: 'Si', - 15: 'P', - 16: 'S', - 17: 'Cl', - 18: 'Ar', - 19: 'K', - 20: 'Ca', - 21: 'Sc', - 22: 'Ti', - 23: 'V', - 24: 'Cr', - 25: 'Mn', - 26: 'Fe', - 27: 'Co', - 28: 'Ni', - 29: 'Cu', - 30: 'Zn', - 31: 'Ga', - 32: 'Ge', - 33: 'As', - 34: 'Se', - 35: 'Br', - 36: 'Kr', - 37: 'Rb', - 38: 'Sr', - 39: 'Y', - 40: 'Zr', - 41: 'Nb', - 42: 'Mo', - 43: 'Tc', - 44: 'Ru', - 45: 'Rh', - 46: 'Pd', - 47: 'Ag', - 48: 'Cd', - 49: 'In', - 50: 'Sn', - 51: 'Sb', - 52: 'Te', - 53: 'I', - 54: 'Xe', - 55: 'Cs', - 56: 'Ba', - 57: 'La', - 58: 'Ce', - 59: 'Pr', - 60: 'Nd', - 61: 'Pm', - 62: 'Sm', - 63: 'Eu', - 64: 'Gd', - 65: 'Tb', - 66: 'Dy', - 67: 'Ho', - 68: 'Er', - 69: 'Tm', - 70: 'Yb', - 71: 'Lu', - 72: 'Hf', - 73: 'Ta', - 74: 'W', - 75: 'Re', - 76: 'Os', - 77: 'Ir', - 78: 'Pt', - 79: 'Au', - 80: 'Hg', - 81: 'Tl', - 82: 'Pb', - 83: 'Bi', - 84: 'Po', - 85: 'At', - 86: 'Rn', - 87: 'Fr', - 88: 'Ra', - 89: 'Ac', - 90: 'Th', - 91: 'Pa', - 92: 'U', - 93: 'Np', - 94: 'Pu', - 95: 'Am', - 96: 'Cm', - 97: 'Bk', - 98: 'Cf', - 99: 'Es', - 100: 'Fm', - 101: 'Md', - 102: 'No', - 103: 'Lr', - 104: 'Rf', - 105: 'Db', - 106: 'Sg', - 107: 'Bh', - 108: 'Hs', - 109: 'Mt', - 110: 'Ds', - 111: 'Rg', - 112: 'Cn', - 113: 'Uut', - 114: 'Fl', - 115: 'Uup', - 116: 'Lv', - 117: 'Uus', - 118: 'Uuo', -} diff --git a/package/MDAnalysis/topology/tables.py b/package/MDAnalysis/topology/tables.py index 51419217892..97efb74c45c 100644 --- a/package/MDAnalysis/topology/tables.py +++ b/package/MDAnalysis/topology/tables.py @@ -46,7 +46,6 @@ .. autodata:: TABLE_VDWRADII """ from __future__ import absolute_import -from ._elements import NUMBER_TO_ELEMENT def kv2dict(s, convertor=str): diff --git a/testsuite/MDAnalysisTests/topology/test_top.py b/testsuite/MDAnalysisTests/topology/test_top.py index 8b015c00b3c..1ab1247e151 100644 --- a/testsuite/MDAnalysisTests/topology/test_top.py +++ b/testsuite/MDAnalysisTests/topology/test_top.py @@ -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 @@ -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 = [ @@ -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)) @@ -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): @@ -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):