Skip to content

Commit

Permalink
Refactor universe identity check between groups, optional scipy.spars…
Browse files Browse the repository at this point in the history
…e import
  • Loading branch information
Jan Domanski authored and kain88-de committed Feb 29, 2016
1 parent 25655f1 commit 4d5c798
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/contacts.py
Expand Up @@ -911,7 +911,7 @@ def __init__(self, grA, grB, refA, refB, radius=4.5, lambda_constant=1.8, beta=5
results: list
Fraction of native contacts for each frame
"""
assert(grA.universe == grB.universe)
if not grA.universe == grB.universe: raise ValueError("grA and grB should come from the same Universe")
self.u = grA.universe
self.grA, self.grB = grA, grB

Expand Down
8 changes: 7 additions & 1 deletion package/MDAnalysis/analysis/distances.py
Expand Up @@ -31,7 +31,6 @@
__all__ = ['distance_array', 'self_distance_array', 'contact_matrix', 'dist']

import numpy as np
from scipy import sparse

from MDAnalysis.lib.distances import distance_array, self_distance_array
from MDAnalysis.lib.c_distances import contact_matrix_no_pbc, contact_matrix_pbc
Expand All @@ -55,6 +54,13 @@ def contact_matrix(coord, cutoff=15.0, returntype="numpy", box=None):
.. versionchanged:: 0.11.0
Keyword *suppress_progmet* and *progress_meter_freq* were removed.
'''
try:
from scipy import sparse
except ImportError:
print("scipy.sparse cannot be imported")
return


if returntype == "numpy":
adj = (distance_array(coord, coord, box=box) < cutoff)
return adj
Expand Down

0 comments on commit 4d5c798

Please sign in to comment.