Unverified Commit 79202805 authored by Timothy Palpant's avatar Timothy Palpant Committed by GitHub
Browse files

Fix import of netcdf_file for compatibility with scipy 1.14 (#4602)



* Fix import of netcdf_file for scipy 1.14

* Fix indentation

---------
Co-authored-by: default avatarTimothy Palpant <tim@atommapper.com>
parent ab7ad049
......@@ -1440,14 +1440,9 @@ class AmberNetcdfRestart(object):
"""
def __init__(self, filename, asNumpy=False):
try:
from scipy.io import NetCDFFile
from scipy.io import netcdf_file
except ImportError:
# scipy < 1.8.0
try:
from scipy.io.netcdf import NetCDFFile
except ImportError:
raise ImportError('scipy is necessary to parse NetCDF '
'restarts')
raise ImportError('scipy is necessary to parse NetCDF restarts')
self.filename = filename
self.velocities = self.boxVectors = self.time = None
......@@ -1457,10 +1452,10 @@ class AmberNetcdfRestart(object):
# to valid memory while the file handle is open. Since the context
# manager GCs the ncfile handle, the memory for the original variables
# is no longer valid. So copy those arrays while the handle is still
# open. This is unnecessary in scipy v.0.12 and lower because NetCDFFile
# open. This is unnecessary in scipy v.0.12 and lower because netcdf_file
# accidentally leaks the file handle, but that was 'fixed' in 0.13. This
# fix taken from MDTraj
ncfile = NetCDFFile(filename, 'r')
ncfile = netcdf_file(filename, 'r')
try:
self.natom = ncfile.dimensions['atom']
self.coordinates = np.array(ncfile.variables['coordinates'][:])
......
......@@ -5,15 +5,10 @@ from openmm import *
from openmm.unit import *
import openmm.app.element as elem
try:
from scipy.io import NetCDFFile
from scipy.io import netcdf_file
SCIPY_IMPORT_FAILED = False
except ImportError:
try:
# scipy < 1.8.0
from scipy.io import netcdf
SCIPY_IMPORT_FAILED = False
except:
SCIPY_IMPORT_FAILED = True
SCIPY_IMPORT_FAILED = True
def compareByElement(array1, array2, cmp):
for x, y in zip(array1, array2):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment