Skip to content

Commit

Permalink
Remove py2 things from aux, vis, transform, and others (#2762)
Browse files Browse the repository at this point in the history
* Remove py2 things from aux

* rm py2 for selections, tests, transformations

* Remove py2 from visualization

* Remove misc py2 things

* errsmg typo
  • Loading branch information
IAlibay authored Jun 16, 2020
1 parent 0d951a2 commit e9e47c3
Show file tree
Hide file tree
Showing 68 changed files with 85 additions and 255 deletions.
2 changes: 0 additions & 2 deletions benchmarks/benchmarks/GRO.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division, absolute_import, print_function

import numpy as np
from MDAnalysis.coordinates.GRO import GROReader
from MDAnalysis.topology.GROParser import GROParser
Expand Down
2 changes: 0 additions & 2 deletions benchmarks/benchmarks/ag_methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division, absolute_import, print_function

import MDAnalysis
import numpy as np

Expand Down
2 changes: 0 additions & 2 deletions benchmarks/benchmarks/analysis/distances.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division, absolute_import, print_function

import MDAnalysis
import numpy as np

Expand Down
2 changes: 0 additions & 2 deletions benchmarks/benchmarks/analysis/leaflet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division, absolute_import, print_function

import MDAnalysis

# use a lipid bilayer system for leaflet testing
Expand Down
2 changes: 0 additions & 2 deletions benchmarks/benchmarks/analysis/psa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division, absolute_import, print_function

import MDAnalysis
import numpy as np

Expand Down
2 changes: 0 additions & 2 deletions benchmarks/benchmarks/analysis/rdf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division, absolute_import, print_function

import MDAnalysis

try:
Expand Down
2 changes: 0 additions & 2 deletions benchmarks/benchmarks/analysis/rms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division, absolute_import, print_function

import MDAnalysis

try:
Expand Down
2 changes: 0 additions & 2 deletions benchmarks/benchmarks/selections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division, absolute_import, print_function

import MDAnalysis

try:
Expand Down
1 change: 0 additions & 1 deletion benchmarks/benchmarks/traj_reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division, absolute_import, print_function

try:
from MDAnalysis.coordinates.DCD import DCDReader
Expand Down
2 changes: 0 additions & 2 deletions maintainer/adapt_sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#
# Adjust path in sitemap.xml

from __future__ import print_function

from xml.etree import ElementTree
import argparse

Expand Down
1 change: 0 additions & 1 deletion package/MDAnalysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
doi:10.1016/j.jmb.2009.09.009
"""
from __future__ import absolute_import

__all__ = ['Universe', 'as_Universe', 'Writer', 'fetch_mmtf',
'AtomGroup', 'ResidueGroup', 'SegmentGroup']
Expand Down
14 changes: 3 additions & 11 deletions package/MDAnalysis/auxiliary/XVG.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
.. autofunction:: uncomment
"""
from __future__ import absolute_import

from six import raise_from

import numbers
import os
import numpy as np
Expand Down Expand Up @@ -150,13 +146,9 @@ def _select_data(self, key):
try:
return self._data[key]
except IndexError:
raise_from(
ValueError(
'{} not a valid index for data with {} '
'columns'.format(key, len(self._data))
),
None
)
errmsg = (f'{key} not a valid index for data with '
f'{len(self._data)} columns')
raise ValueError(errmsg) from None
else:
return np.array([self._select_data(i) for i in key])

Expand Down
2 changes: 0 additions & 2 deletions package/MDAnalysis/auxiliary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,6 @@
"""

from __future__ import absolute_import

# registry of auxiliary readers
_AUXREADERS = {}

Expand Down
6 changes: 1 addition & 5 deletions package/MDAnalysis/auxiliary/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
"""

from __future__ import division, absolute_import
import six
from six.moves import range

import os
import numbers
import math
Expand Down Expand Up @@ -235,7 +231,7 @@ def _empty_data(self):
return np.full_like(self.data, np.nan)


class AuxReader(six.with_metaclass(_AuxReaderMeta)):
class AuxReader(metaclass=_AuxReaderMeta):
""" Base class for auxiliary readers.
Allows iteration over a set of data from a trajectory, additional
Expand Down
20 changes: 6 additions & 14 deletions package/MDAnalysis/auxiliary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@
.. autofunction:: get_auxreader_for
.. autofunction:: auxreader
"""
from __future__ import absolute_import

from six import raise_from, string_types

from . import _AUXREADERS
from ..lib import util


def get_auxreader_for(auxdata=None, format=None):
"""Return the appropriate auxiliary reader class for *auxdata*/*format*.
Expand Down Expand Up @@ -65,7 +62,7 @@ def get_auxreader_for(auxdata=None, format=None):
raise ValueError('Must provide either auxdata or format')

if format is None:
if isinstance(auxdata, string_types):
if isinstance(auxdata, str):
## assume it's a filename?
format = util.guess_format(auxdata)
else:
Expand All @@ -75,19 +72,14 @@ def get_auxreader_for(auxdata=None, format=None):
try:
return _AUXREADERS[format]
except KeyError:
raise_from(
ValueError(
"Unknown auxiliary data format for auxdata: "
"{0}".format(auxdata)),
None
)
errmsg = f"Unknown auxiliary data format for auxdata: {auxdata}"
raise ValueError(errmsg) from None
else:
try:
return _AUXREADERS[format]
except KeyError:
raise_from(
ValueError("Unknown auxiliary data format {0}".format(format)),
None)
errmsg = f"Unknown auxiliary data format {format}"
raise ValueError(errmsg) from None

def auxreader(auxdata, format=None, **kwargs):
""" Return an auxiliary reader instance for *auxdata*.
Expand Down
1 change: 0 additions & 1 deletion package/MDAnalysis/due.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"""

from __future__ import absolute_import
__version__ = '0.0.5'


Expand Down
10 changes: 3 additions & 7 deletions package/MDAnalysis/selections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
.. autofunction:: get_writer
"""
from __future__ import absolute_import
from six import raise_from

import os.path

from .. import _SELECTION_WRITERS
Expand Down Expand Up @@ -86,7 +83,6 @@ def get_writer(filename, defaultformat):
try:
return _SELECTION_WRITERS[format]
except KeyError:
raise_from(NotImplementedError(
"Writing as {0!r} is not implemented;"
" only {1!r} will work.".format(format, _SELECTION_WRITERS.keys())),
None)
errmsg = (f"Writing as {format} is not implemented; only "
f"{ _SELECTION_WRITERS.keys()} will work.")
raise NotImplementedError(errmsg) from None
8 changes: 2 additions & 6 deletions package/MDAnalysis/selections/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@
.. autofunction:: join
"""
from __future__ import absolute_import

import six
from six.moves import range

import os.path

from ..lib import util
from . import _SELECTION_WRITERS


def join(seq, string="", func=None):
"""Create a list from sequence.
Expand Down Expand Up @@ -75,7 +71,7 @@ def __init__(cls, name, bases, classdict):
_SELECTION_WRITERS[f] = cls


class SelectionWriterBase(six.with_metaclass(_Selectionmeta)):
class SelectionWriterBase(metaclass=_Selectionmeta):
"""Export a selection in MDAnalysis to a format usable in an external package.
The :class:`SelectionWriterBase` writes a selection string to a file
Expand Down
3 changes: 1 addition & 2 deletions package/MDAnalysis/selections/charmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
.. _CHARMM: http://www.charmm.org
.. _CHARMM selection: http://www.charmm.org/documentation/c34b1/select.html
"""
from __future__ import absolute_import

from . import base


class SelectionWriter(base.SelectionWriterBase):
format = ["CHARMM", "str"]
ext = "str"
Expand Down
3 changes: 1 addition & 2 deletions package/MDAnalysis/selections/gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
.. autoclass:: SelectionWriter
:inherited-members:
"""
from __future__ import absolute_import

from . import base


class SelectionWriter(base.SelectionWriterBase):
format = ["Gromacs", "ndx"]
ext = "ndx"
Expand Down
3 changes: 1 addition & 2 deletions package/MDAnalysis/selections/jmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
.. _Jmol: http://wiki.jmol.org/index.php/Main_Page
.. _Jmol selection: http://chemapps.stolaf.edu/jmol/docs/#define
"""
from __future__ import absolute_import

from . import base


class SelectionWriter(base.SelectionWriterBase):
format = ["Jmol", "spt"]
ext = "spt"
Expand Down
3 changes: 1 addition & 2 deletions package/MDAnalysis/selections/pymol.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
.. autoclass:: SelectionWriter
:inherited-members:
"""
from __future__ import absolute_import

from . import base


class SelectionWriter(base.SelectionWriterBase):
format = ["PyMol", "pml"]
ext = "pml"
Expand Down
3 changes: 1 addition & 2 deletions package/MDAnalysis/selections/vmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@
:inherited-members:
"""
from __future__ import absolute_import

from . import base


class SelectionWriter(base.SelectionWriterBase):
format = "VMD"
ext = "vmd"
Expand Down
4 changes: 1 addition & 3 deletions package/MDAnalysis/tests/datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
:mod:`MDAnalysisTests` package which must be downloaded from
http://pypi.python.org/pypi/MDAnalysisTests and installed.
"""
from __future__ import print_function, absolute_import
from six import raise_from

try:
from MDAnalysisTests.datafiles import *
Expand All @@ -51,4 +49,4 @@
print()
print("and download and install the `MDAnalysisTests-x.y.z.tar.gz'")
print("that matches your MDAnalysis release.")
raise_from(ImportError("MDAnalysisTests package not installed."), None)
raise ImportError("MDAnalysisTests package not installed.") from None
2 changes: 0 additions & 2 deletions package/MDAnalysis/transformations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def wrapped(ts):
"""

from __future__ import absolute_import

from .translate import translate, center_in_box
from .rotate import rotateby
from .positionaveraging import PositionAverager
Expand Down
21 changes: 10 additions & 11 deletions package/MDAnalysis/transformations/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
.. autofunction:: fit_rot_trans
"""
from __future__ import absolute_import
from six import raise_from

import numpy as np
from functools import partial

Expand Down Expand Up @@ -91,14 +88,14 @@ def fit_translation(ag, reference, plane=None, weights=None):
try:
plane = axes[plane]
except (TypeError, KeyError):
raise_from(ValueError('{} is not a valid plane'.format(plane)), None)
raise ValueError(f'{plane} is not a valid plane') from None
try:
if ag.atoms.n_residues != reference.atoms.n_residues:
raise ValueError("{} and {} have mismatched number of residues".format(ag,reference))
errmsg = f"{ag} and {reference} have mismatched number of residues"
raise ValueError(errmsg)
except AttributeError:
raise_from(
AttributeError("{} or {} is not valid Universe/AtomGroup".format(ag,reference)),
None)
errmsg = f"{ag} or {reference} is not valid Universe/AtomGroup"
raise AttributeError(errmsg) from None
ref, mobile = align.get_matching_atoms(reference.atoms, ag.atoms)
weights = align.get_weights(ref.atoms, weights=weights)
ref_com = ref.center(weights)
Expand Down Expand Up @@ -168,12 +165,14 @@ def fit_rot_trans(ag, reference, plane=None, weights=None):
try:
plane = axes[plane]
except (TypeError, KeyError):
raise_from(ValueError('{} is not a valid plane'.format(plane)), None)
raise ValueError(f'{plane} is not a valid plane') from None
try:
if ag.atoms.n_residues != reference.atoms.n_residues:
raise ValueError("{} and {} have mismatched number of residues".format(ag,reference))
errmsg = f"{ag} and {reference} have mismatched number of residues"
raise ValueError(errmsg)
except AttributeError:
raise_from(AttributeError("{} or {} is not valid Universe/AtomGroup".format(ag,reference)), None)
errmsg = f"{ag} or {reference} is not valid Universe/AtomGroup"
raise AttributeError(errmsg) from None
ref, mobile = align.get_matching_atoms(reference.atoms, ag.atoms)
weights = align.get_weights(ref.atoms, weights=weights)
ref_com = ref.center(weights)
Expand Down
3 changes: 0 additions & 3 deletions package/MDAnalysis/transformations/positionaveraging.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@
.. autoclass:: PositionAverager
"""
from __future__ import absolute_import

import numpy as np
import warnings



class PositionAverager(object):
"""
Expand Down
Loading

0 comments on commit e9e47c3

Please sign in to comment.