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 ...@@ -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. Both Frame and Residue are iterable. Residue is indexable with either atom numbers or names.
""" """
import os
import numpy as np import numpy as np
from simpletraj import trajectory from simpletraj import trajectory
...@@ -15,6 +17,15 @@ from .parsers.cfg import CFG ...@@ -15,6 +17,15 @@ from .parsers.cfg import CFG
np.seterr(all="raise") np.seterr(all="raise")
try:
raise FileNotFoundError
except FileNotFoundError:
pass
except NameError:
class FileNotFoundError(OSError):
pass
class Atom: class Atom:
""" """
Hold data for a single atom Hold data for a single atom
...@@ -112,8 +123,16 @@ class Frame: ...@@ -112,8 +123,16 @@ class Frame:
self.numframes += 1 self.numframes += 1
if xtc is not None: if xtc is not None:
try:
self.xtc = trajectory.XtcTrajectory(xtc) self.xtc = trajectory.XtcTrajectory(xtc)
assert self.xtc.numatoms == self.natoms 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 self.numframes += self.xtc.numframes
if itp is not None: if itp is not None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment