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

Better error messages when xtc fails

parent da541a0f
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,8 @@ The Frame class may contain multiple Residues which may each contain multiple At
Both Frame and Residue are iterable. Residue is indexable with either atom numbers or names.
"""
import os
import numpy as np
from simpletraj import trajectory
......@@ -15,6 +17,15 @@ from .parsers.cfg import CFG
np.seterr(all="raise")
try:
raise FileNotFoundError
except FileNotFoundError:
pass
except NameError:
class FileNotFoundError(OSError):
pass
class Atom:
"""
Hold data for a single atom
......@@ -112,9 +123,17 @@ class Frame:
self.numframes += 1
if xtc is not None:
self.xtc = trajectory.XtcTrajectory(xtc)
assert self.xtc.numatoms == self.natoms
self.numframes += self.xtc.numframes
try:
self.xtc = trajectory.XtcTrajectory(xtc)
except OSError as e:
if not os.path.isfile(xtc):
raise FileNotFoundError(xtc) from e
e.args = ("Error opening file '{0}'".format(xtc),)
raise
else:
if self.xtc.numatoms != self.natoms:
raise AssertionError("Number of atoms does not match between gro and xtc files.")
self.numframes += self.xtc.numframes
if itp is not None:
self._parse_itp(itp)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment