Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ MDAnalysis.log
authors.py
# Ignore the .DS_Store file in the osx file system
*.DS_Store
# ignore files from tests
.hypothesis/
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Chronological list of authors
- Rocco Meli
- Lily Wang
- Matthijs Tadema
- Joao Miguel Correia Teixeira

External code
-------------
Expand Down
6 changes: 5 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
mm/dd/yy richardjgowers, kain88-de, lilyminium, p-j-smith, bdice

mm/dd/yy richardjgowers, kain88-de, lilyminium, p-j-smith, bdice, joaomcteixeira

* 0.21.0

Expand All @@ -25,6 +26,9 @@ Fixes
* PDBQTParser now gives icode TopologyAttrs (Issue #2361)

Enhancements
* Uniforms exception handling between Python 2.7 and Python 3: raised exceptions
do not contain previous exceptions traceback. Uses six package to handle
py27 and py3 compatibility (PR #2357)
* Expanded selection wildcards to the start and middle of strings (Issue #2370)
* Added type checking and conversion to Connection TopologyAttrs (Issue #2373)
* New analysis.hydrogenbonds.HydrogenBondAnalysis class for the analysis of
Expand Down
12 changes: 8 additions & 4 deletions package/MDAnalysis/analysis/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
import logging

from six.moves import range, zip, zip_longest
from six import string_types
from six import raise_from, string_types

import numpy as np

Expand Down Expand Up @@ -507,8 +507,12 @@ def alignto(mobile, reference, select="all", weights=None,
# treat subselection as AtomGroup
mobile_atoms = subselection.atoms
except AttributeError:
raise TypeError("subselection must be a selection string, an"
" AtomGroup or Universe or None")
raise_from(
TypeError(
"subselection must be a selection string, an"
" AtomGroup or Universe or None"
),
None)

# _fit_to DOES subtract center of mass, will provide proper min_rmsd
mobile_atoms, new_rmsd = _fit_to(mobile_coordinates, ref_coordinates,
Expand Down Expand Up @@ -1167,7 +1171,7 @@ def get_atoms_byres(g, match_mask=np.logical_not(mismatch_mask)):
"Try to improve your selections for mobile and reference.").format(
ag1.n_atoms, ag2.n_atoms)
logger.error(errmsg)
raise SelectionError(errmsg)
raise_from(SelectionError(errmsg), None)

if np.any(mass_mismatches):
# Test 2 failed.
Expand Down
18 changes: 12 additions & 6 deletions package/MDAnalysis/analysis/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@

from __future__ import print_function, division, absolute_import
from six.moves import range, zip
from six import string_types
from six import raise_from, string_types

import numpy as np
import sys
Expand Down Expand Up @@ -373,11 +373,14 @@ def _check_set_unit(self, u):
units.conversion_factor[unit_type][value]
self.units[unit_type] = value
except KeyError:
raise ValueError('Unit ' + str(value) + ' of type ' + str(unit_type) + ' is not recognized.')
raise_from(
ValueError('Unit ' + str(value) + ' of type ' + str(unit_type) + ' is not recognized.'),
None,
)
except AttributeError:
errmsg = '"unit" must be a dictionary with keys "length" and "density.'
logger.fatal(errmsg)
raise ValueError(errmsg)
raise_from(ValueError(errmsg), None)
# need at least length and density (can be None)
if 'length' not in self.units:
raise ValueError('"unit" must contain a unit for "length".')
Expand Down Expand Up @@ -486,7 +489,10 @@ def convert_density(self, unit='Angstrom'):
self.grid *= units.get_conversion_factor('density',
self.units['density'], unit)
except KeyError:
raise ValueError("The name of the unit ({0!r} supplied) must be one of:\n{1!r}".format(unit, units.conversion_factor['density'].keys()))
raise_from(
ValueError("The name of the unit ({0!r} supplied) must be one of:\n{1!r}".format(unit, units.conversion_factor['density'].keys())),
None,
)
self.units['density'] = unit

def __repr__(self):
Expand Down Expand Up @@ -527,13 +533,13 @@ def _set_user_grid(gridcenter, xdim, ydim, zdim, smin, smax):
try:
gridcenter = np.asarray(gridcenter, dtype=np.float32)
except ValueError:
raise ValueError("Non-number values assigned to gridcenter")
raise_from(ValueError("Non-number values assigned to gridcenter"), None)
if gridcenter.shape != (3,):
raise ValueError("gridcenter must be a 3D coordinate")
try:
xyzdim = np.array([xdim, ydim, zdim], dtype=np.float32)
except ValueError:
raise ValueError("xdim, ydim, and zdim must be numbers")
raise_from(ValueError("xdim, ydim, and zdim must be numbers"), None)

# Set min/max by shifting by half the edge length of each dimension
umin = gridcenter - xyzdim/2
Expand Down
5 changes: 3 additions & 2 deletions package/MDAnalysis/analysis/hbonds/hbond_autocorrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
"""
from __future__ import division, absolute_import
from six.moves import zip
from six import raise_from

import numpy as np
import scipy.optimize
Expand Down Expand Up @@ -300,8 +301,8 @@ def __init__(self, universe,
# check that slicing is possible
try:
self.u.trajectory[0]
except:
raise ValueError("Trajectory must support slicing")
except Exception:
raise_from(ValueError("Trajectory must support slicing"), None)

self.h = hydrogens
self.a = acceptors
Expand Down
4 changes: 2 additions & 2 deletions package/MDAnalysis/analysis/hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ def create_vmd_surface(self, filename="hole.vmd", **kwargs):
except subprocess.CalledProcessError as err:
os.unlink(tmp_sos)
logger.fatal("sph_process failed ({0})".format(err.returncode))
raise OSError(err.returncode, "sph_process failed")
six.raise_from(OSError(err.returncode, "sph_process failed"), None)
except:
os.unlink(tmp_sos)
raise
Expand All @@ -1045,7 +1045,7 @@ def create_vmd_surface(self, filename="hole.vmd", **kwargs):
stderr=FNULL)
except subprocess.CalledProcessError as err:
logger.fatal("sos_triangle failed ({0})".format(err.returncode))
raise OSError(err.returncode, "sos_triangle failed")
six.raise_from(OSError(err.returncode, "sos_triangle failed"), None)
finally:
os.unlink(tmp_sos)

Expand Down
12 changes: 10 additions & 2 deletions package/MDAnalysis/analysis/nuclinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@

import numpy as np
from math import pi, sin, cos, atan2, sqrt, pow
from six import raise_from

from MDAnalysis.lib import mdamath

Expand Down Expand Up @@ -711,8 +712,15 @@ def hydroxyl(universe, seg, i):
try:
hydr = h.dihedral.value() % 360
except ValueError:
raise ValueError("Resid {0} does not contain atoms C1', C2', O2', H2' but atoms {1}"
.format(i, str(list(h.atoms))))
raise_from(
ValueError(
(
"Resid {0} does not contain atoms C1', C2', O2', H2' "
"but atoms {1}"
).format(i, str(list(h.atoms)))
),
None)

return hydr


Expand Down
3 changes: 2 additions & 1 deletion package/MDAnalysis/analysis/polymer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"""
from __future__ import division, absolute_import
from six.moves import range
from six import raise_from

import numpy as np
import scipy.optimize
Expand Down Expand Up @@ -248,7 +249,7 @@ def _perform_fit(self):
try:
self.results
except AttributeError:
raise NoDataError("Use the run method first")
raise_from(NoDataError("Use the run method first"), None)
self.x = np.arange(len(self.results)) * self.lb

self.lp = fit_exponential_decay(self.x, self.results)
Expand Down
25 changes: 17 additions & 8 deletions package/MDAnalysis/analysis/psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@

import six
from six.moves import range, cPickle, zip
from six import string_types
from six import raise_from, string_types

import os
import warnings
Expand Down Expand Up @@ -266,9 +266,14 @@ def get_path_metric_func(name):
try:
return path_metrics[name]
except KeyError as key:
raise KeyError('Path metric "{}" not found. Valid selections: {}'
''.format(key, " ".join('"{}"'.format(n)
for n in path_metrics.keys())))
raise_from(
KeyError(
'Path metric "{}" not found. Valid selections: {}'.format(
key,
" ".join('"{}"'.format(n) for n in path_metrics.keys())
)
),
None)


def sqnorm(v, axis=None):
Expand Down Expand Up @@ -1865,7 +1870,7 @@ def plot_annotated_heatmap(self, filename=None, linkage='ward', \
try:
import seaborn.apionly as sns
except ImportError:
raise ImportError(
raise_from(ImportError(
"""ERROR --- The seaborn package cannot be found!

The seaborn API could not be imported. Please install it first.
Expand All @@ -1880,7 +1885,9 @@ def plot_annotated_heatmap(self, filename=None, linkage='ward', \

and install in the usual manner.
"""
)
),
None,
)

if self.D is None:
raise ValueError(
Expand Down Expand Up @@ -1974,7 +1981,7 @@ def plot_nearest_neighbors(self, filename=None, idx=0, \
try:
import seaborn.apionly as sns
except ImportError:
raise ImportError(
raise_from(ImportError(
"""ERROR --- The seaborn package cannot be found!

The seaborn API could not be imported. Please install it first.
Expand All @@ -1989,7 +1996,9 @@ def plot_nearest_neighbors(self, filename=None, idx=0, \

and install in the usual manner.
"""
)
),
None,
)

colors = sns.xkcd_palette(["cherry", "windows blue"])

Expand Down
18 changes: 13 additions & 5 deletions package/MDAnalysis/analysis/rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
from __future__ import division, absolute_import

from six.moves import zip
from six import string_types
from six import raise_from, string_types

import numpy as np

Expand Down Expand Up @@ -287,16 +287,24 @@ def process_selection(select):
try:
select = {'mobile': select[0], 'reference': select[1]}
except IndexError:
raise IndexError("select must contain two selection strings "
"(reference, mobile)")
raise_from(IndexError(
"select must contain two selection strings "
"(reference, mobile)"),
None,
)
elif type(select) is dict:
# compatability hack to use new nomenclature
try:
select['mobile']
select['reference']
except KeyError:
raise KeyError("select dictionary must contain entries for keys "
"'mobile' and 'reference'.")
raise_from(
KeyError(
"select dictionary must contain entries for keys "
"'mobile' and 'reference'."
),
None,
)
else:
raise TypeError("'select' must be either a string, 2-tuple, or dict")
select['mobile'] = asiterable(select['mobile'])
Expand Down
10 changes: 8 additions & 2 deletions package/MDAnalysis/auxiliary/XVG.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from __future__ import absolute_import

from six.moves import range
from six import raise_from

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

Expand Down
14 changes: 10 additions & 4 deletions package/MDAnalysis/auxiliary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"""
from __future__ import absolute_import

from six import string_types
from six import raise_from, string_types

from . import _AUXREADERS
from ..lib import util
Expand Down Expand Up @@ -75,13 +75,19 @@ def get_auxreader_for(auxdata=None, format=None):
try:
return _AUXREADERS[format]
except KeyError:
raise ValueError("Unknown auxiliary data format for auxdata: "
"{0}".format(auxdata))
raise_from(
ValueError(
"Unknown auxiliary data format for auxdata: "
"{0}".format(auxdata)),
None
)
else:
try:
return _AUXREADERS[format]
except KeyError:
raise ValueError("Unknown auxiliary data format {0}".format(format))
raise_from(
ValueError("Unknown auxiliary data format {0}".format(format)),
None)

def auxreader(auxdata, format=None, **kwargs):
""" Return an auxiliary reader instance for *auxdata*.
Expand Down
11 changes: 8 additions & 3 deletions package/MDAnalysis/coordinates/CRD.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from __future__ import absolute_import

from six.moves import zip, range
from six import raise_from

import itertools
import numpy as np
Expand Down Expand Up @@ -80,9 +81,13 @@ def _read_first_frame(self):
coords_list.append(np.array(line[45:100].split()[0:3], dtype=float))
else:
coords_list.append(np.array(line[20:50].split()[0:3], dtype=float))
except:
raise ValueError("Check CRD format at line {0}: {1}"
"".format(linenum, line.rstrip()))
except Exception:
raise_from(
ValueError(
"Check CRD format at line {0}: {1}"
"".format(linenum, line.rstrip())),
None
)

self.n_atoms = len(coords_list)

Expand Down
Loading