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

Move parmed to optional dependency #2477

Merged
merged 9 commits into from
Feb 26, 2020
Merged
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ matrix:
# SETUP_CMD="${PYTEST_FLAGS} --cov=MDAnalysis"

- env: NAME='minimal'
PIP_DEPENDENCIES=""
CONDA_DEPENDENCIES=${CONDA_MIN_DEPENDENCIES}
INSTALL_HOLE="false"
CODECOV="true" SETUP_CMD="${PYTEST_FLAGS} --cov=MDAnalysis"
Expand Down
7 changes: 4 additions & 3 deletions package/MDAnalysis/coordinates/ParmEd.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ def convert(self, obj):
"""
try:
import parmed as pmd
except ModuleNotFoundError:
raise ValueError('Parmed is required for ParmEdConverter but '
'is not installed.')
except ImportError:
raise ImportError('ParmEd is required for ParmEdConverter but '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we import coordinates.ParmEd anywhere, i.e., is it guaranteed that this does not break the installation for anyone not having ParmEd?

'is not installed. Try installing it with \n'
'pip install parmed')
try:
# make sure to use atoms (Issue 46)
ag_or_ts = obj.atoms
Expand Down
6 changes: 3 additions & 3 deletions package/MDAnalysis/core/_get_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_reader_for(filename, format=None):
:class:`~MDAnalysis.coordinates.memory.MemoryReader` is returned.
- If `filename` is an MMTF object,
:class:`~MDAnalysis.coordinates.MMTF.MMTFReader` is returned.
- If `filename` is a ParmEd Structure,
- If `filename` is a ParmEd Structure,
:class:`~MDAnalysis.coordinates.ParmEd.ParmEdReader` is returned.
- If `filename` is an iterable of filenames,
:class:`~MDAnalysis.coordinates.chain.ChainReader` is returned.
Expand Down Expand Up @@ -176,7 +176,7 @@ def get_writer_for(filename, format=None, multiframe=None):
None)
else:
format = util.check_compressed_format(root, ext)

if format == '':
raise ValueError((
'File format could not be guessed from {}, '
Expand Down Expand Up @@ -275,7 +275,7 @@ def get_converter_for(format):
TypeError
If no appropriate parser could be found.


.. versionadded:: 0.21.0
"""
try:
Expand Down
3 changes: 1 addition & 2 deletions package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ def dynamic_author_list():
'scipy>=1.0.0',
'matplotlib>=1.5.1',
'mock',
'parmed',
]
if not os.name == 'nt':
install_requires.append('gsd>=1.4.0')
Expand Down Expand Up @@ -593,7 +592,7 @@ def dynamic_author_list():
ext_modules=exts,
requires=['numpy (>=1.13.3)', 'biopython (>= 1.71)', 'mmtf (>=1.0.0)',
'networkx (>=1.0)', 'GridDataFormats (>=0.3.2)', 'joblib',
'scipy (>=1.0.0)', 'matplotlib (>=1.5.1)', 'parmed'],
'scipy (>=1.0.0)', 'matplotlib (>=1.5.1)'],
# all standard requirements are available through PyPi and
# typically can be installed without difficulties through setuptools
setup_requires=[
Expand Down
5 changes: 3 additions & 2 deletions testsuite/MDAnalysisTests/coordinates/test_parmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from __future__ import absolute_import

import pytest
import parmed as pmd
import MDAnalysis as mda

from numpy.testing import (assert_equal,
Expand All @@ -45,6 +44,9 @@
PRM_UreyBradley,
)

pmd = pytest.importorskip('parmed')


class TestParmEdReaderGRO:
ref_filename = GRO

Expand All @@ -67,7 +69,6 @@ def test_coordinates(self):


class BaseTestParmEdReader(_SingleFrameReader):

def setUp(self):
self.universe = mda.Universe(pmd.load_file(self.ref_filename))
self.ref = mda.Universe(self.ref_filename)
Expand Down
8 changes: 6 additions & 2 deletions testsuite/MDAnalysisTests/topology/test_parmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from __future__ import absolute_import

import pytest
import parmed as pmd
import MDAnalysis as mda

from MDAnalysisTests.topology.base import ParserBase
Expand All @@ -32,6 +31,8 @@
PRM
)

pmd = pytest.importorskip('parmed')

class BaseTestParmedParser(ParserBase):
parser = mda.topology.ParmEdParser.ParmEdParser
expected_attrs = ['ids', 'names', 'types', 'masses',
Expand Down Expand Up @@ -62,6 +63,10 @@ def filename(self):
def universe(self, filename):
return mda.Universe(filename)

def test_creates_universe(self, filename):
u = mda.Universe(filename)
assert isinstance(u, mda.Universe)

def test_bonds_total_counts(self, top, filename):
unique = set([(a.atom1.idx, a.atom2.idx)
for a in filename.bonds])
Expand Down Expand Up @@ -236,4 +241,3 @@ def test_dihedral_types(self, universe):
)):
assert dih.type[i].type.phi_k == phi_k
assert dih.type[i].type.per == per