From 54a7a987609a12a5cd6e4c6fa8fb21432dabbabf Mon Sep 17 00:00:00 2001
From: Berk Onat <b.onat@warwick.ac.uk>
Date: Fri, 8 Dec 2017 14:43:11 +0000
Subject: [PATCH] Fixed trajectory checks in each attempt of heroistic read.

---
 .../nomadcore/md_data_access/MDDataAccess.py     | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/common/python/nomadcore/md_data_access/MDDataAccess.py b/common/python/nomadcore/md_data_access/MDDataAccess.py
index 36c76b8..905aab1 100644
--- a/common/python/nomadcore/md_data_access/MDDataAccess.py
+++ b/common/python/nomadcore/md_data_access/MDDataAccess.py
@@ -1206,6 +1206,7 @@ class MDDataAccess(object):
             file_format = self.trajformat
 
         usedefault=True
+        molfile_traj=None
         # Use the given order to check topology
         if self.interfaceorder:
             for interface in self.interfaceorder:
@@ -1220,8 +1221,9 @@ class MDDataAccess(object):
                         elif self.natoms is not None:
                             if self.natoms > 0:
                                 molfile_traj = pym.OpenMolfile(self.trajfile, file_format=filetrajformat, natoms=self.natoms, silent=False)
-                        if molfile_traj.trajectory is not None:
-                            trajhandler_check = molfile_traj
+                        if molfile_traj is not None:
+                            if molfile_traj.trajectory is not None:
+                                trajhandler_check = molfile_traj
                         if trajhandler_check:
                             trajhandler = None
                             trajhandler = self.pymolfile_iread(trajhandler_check)
@@ -1420,8 +1422,9 @@ class MDDataAccess(object):
                     elif self.natoms is not None:
                         if self.natoms > 0:
                             molfile_traj = pym.OpenMolfile(self.trajfile, file_format=filetrajformat, natoms=self.natoms, silent=False)
-                    if molfile_traj.trajectory is not None:
-                        trajhandler_check = molfile_traj
+                    if molfile_traj is not None:
+                        if molfile_traj.trajectory is not None:
+                            trajhandler_check = molfile_traj
                     if trajhandler_check:
                         trajhandler = None
                         trajhandler = self.pymolfile_iread(trajhandler_check)
@@ -1441,8 +1444,9 @@ class MDDataAccess(object):
                     if self.natoms is not None:
                         if self.natoms > 0:
                             molfile_traj = pym.OpenMolfile(self.trajfile, file_format=filetrajformat, natoms=self.natoms, silent=False)
-                    if molfile_traj.trajectory is not None:
-                        trajhandler_check = molfile_traj
+                    if molfile_traj is not None:
+                        if molfile_traj.trajectory is not None:
+                            trajhandler_check = molfile_traj
                     if trajhandler_check:
                         trajhandler = None
                         trajhandler = self.pymolfile_iread(trajhandler_check)
-- 
GitLab