Skip to content
Snippets Groups Projects
Commit 0f2ae012 authored by James Graham's avatar James Graham
Browse files

Fixed failing import if mdtraj not present

parent 7f1b1ae2
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,11 @@ import numpy as np
from simpletraj import trajectory
try:
from mdtraj.formats import XTCTrajectoryFile
except ImportError:
pass
from .util import backup_file
from .parsers.cfg import CFG
......@@ -162,6 +166,8 @@ class Frame:
raise FileNotFoundError(xtc) from e
e.args = ("Error opening file '{0}'".format(xtc),)
raise
except NameError as e:
raise ImportError("No module named 'mdtraj'") from e
else:
xyz, time, step, box = self.xtc.read(n_frames=1)
natoms = len(xyz[0])
......@@ -215,6 +221,8 @@ class Frame:
raise
def _next_frame_mdtraj(self, exclude=None):
if XTCTrajectoryFile is None:
raise ImportError("No module named 'mdtraj'")
try:
# self.xtc.seek(self.number)
i = 0
......@@ -292,6 +300,7 @@ class Frame:
def flush_xtc_buffer(self, filename):
if self._xtc_buffer is not None:
try:
xtc = XTCTrajectoryFile(filename, mode="w")
xyz, step, box = self._xtc_buffer()
......@@ -299,6 +308,8 @@ class Frame:
xtc.close()
self._xtc_buffer = None
except NameError as e:
raise ImportError("No module named 'mdtraj'") from e
def write_xtc(self, filename):
if self._xtc_buffer is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment