Skip to content

Commit

Permalink
Moved ConverterBase out of coordinates/base.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmkenney committed Aug 21, 2023
1 parent 9032eb0 commit 8ebdbb8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 43 deletions.
3 changes: 2 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
??/??/?? IAlibay, hmacdope, pillose
??/??/?? IAlibay, hmacdope, pillose, ianmkenney

* 2.7.0

Expand All @@ -25,6 +25,7 @@ Enhancements
Changes
* Cython DEF statments have been replaced with compile time integer constants
as DEF is deprecated as of Cython>=3.0 (Issue #4237, PR #4246)
* ConverterBase class moved from coordinates/base.py to converters/base.py (Issue #3404)

Deprecations

Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/converters/ParmEd.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import itertools
import warnings

from ..coordinates import base
from . import base
from ..topology.tables import SYMB2Z
from ..core.universe import Universe
from ..exceptions import NoDataError
Expand Down
3 changes: 2 additions & 1 deletion package/MDAnalysis/converters/RDKit.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@

import numpy as np

from ..coordinates import base, memory
from . import base
from ..coordinates import memory
from ..coordinates.PDB import PDBWriter
from ..core.topologyattrs import _TOPOLOGY_ATTRS
from ..exceptions import NoDataError
Expand Down
62 changes: 62 additions & 0 deletions package/MDAnalysis/converters/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- 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
#

"""\
Converters
----------
Converters output information to other libraries.
.. autoclass:: ConverterBase
:members:
:inherited-members:
"""

from .. import _CONVERTERS
from ..coordinates.base import IOBase, SingleFrameReaderBase
from ..lib.util import asiterable


class _Convertermeta(type):
# Auto register upon class creation
def __init__(cls, name, bases, classdict):
type.__init__(type, name, bases, classdict)
try:
fmt = asiterable(classdict['lib'])
except KeyError:
pass
else:
for f in fmt:
f = f.upper()
_CONVERTERS[f] = cls


class ConverterBase(IOBase, metaclass=_Convertermeta):
"""Base class for converting to other libraries.
"""

def __repr__(self):
return "<{cls}>".format(cls=self.__class__.__name__)

def convert(self, obj):
raise NotImplementedError
40 changes: 0 additions & 40 deletions package/MDAnalysis/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@
:members:
:inherited-members:
Converters
----------
Converters output information to other libraries.
.. autoclass:: ConverterBase
:members:
:inherited-members:
Helper classes
--------------
Expand All @@ -134,7 +123,6 @@
_READERS, _READER_HINTS,
_SINGLEFRAME_WRITERS,
_MULTIFRAME_WRITERS,
_CONVERTERS
)
from .. import units
from ..auxiliary.base import AuxReader
Expand Down Expand Up @@ -1782,31 +1770,3 @@ def range_length(start, stop, step):
else:
# The range is empty.
return 0


class _Convertermeta(type):
# Auto register upon class creation
def __init__(cls, name, bases, classdict):
type.__init__(type, name, bases, classdict)
try:
fmt = asiterable(classdict['lib'])
except KeyError:
pass
else:
for f in fmt:
f = f.upper()
_CONVERTERS[f] = cls

class ConverterBase(IOBase, metaclass=_Convertermeta):
"""Base class for converting to other libraries.
See Also
--------
:mod:`MDAnalysis.converters`
"""

def __repr__(self):
return "<{cls}>".format(cls=self.__class__.__name__)

def convert(self, obj):
raise NotImplementedError

0 comments on commit 8ebdbb8

Please sign in to comment.