From 818da844e44951930fdb2dd710df4ed041445e88 Mon Sep 17 00:00:00 2001 From: Berk Onat <b.onat@warwick.ac.uk> Date: Wed, 24 Jan 2018 17:02:13 +0000 Subject: [PATCH] Fixed several bugs related to topology info in MDDataAccess --- .../nomadcore/md_data_access/MDDataAccess.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/common/python/nomadcore/md_data_access/MDDataAccess.py b/common/python/nomadcore/md_data_access/MDDataAccess.py index 9e9d0e3..09fddf2 100644 --- a/common/python/nomadcore/md_data_access/MDDataAccess.py +++ b/common/python/nomadcore/md_data_access/MDDataAccess.py @@ -1062,7 +1062,7 @@ class MDDataAccess(object): if self.topohandler is None: if self.topofile: - self.check_topology_format_support("traj") + self.check_topology_format_support() if self.trajhandler is None: self.check_trajectory_format_support("traj") @@ -1288,9 +1288,8 @@ class MDDataAccess(object): filetrajformat = re.sub('[.]', '', chkformat) trajhandler_check = None if self.topohandler is not None: - numatoms = self.get_natoms_from_topo(topocode="pymolfile") - if(isinstance(self.topohandler, pym.OpenMolfile) - or isinstance(self.topohandler, pym.OpenMolfile.topology)): + numatoms = self.get_natoms_from_topo(topocode=self.topocode) + if isinstance(self.topohandler, pym.OpenMolfile): molfile_traj = pym.OpenMolfile(chkfile, file_format=filetrajformat, topology=self.topohandler, silent=False) elif numatoms is not None: if numatoms > 0: @@ -1409,7 +1408,7 @@ class MDDataAccess(object): self.natoms = numatoms usedefault=False break - except (AttributeError, IOError, OSError, ValueError, TypeError): + except (AttributeError, IOError, OSError, ValueError, TypeError, KeyError): try: universe = mda_u.Universe(self.topohandler, self.trajfile, format=mdanalysis_format) trajhandler = None @@ -1447,8 +1446,8 @@ class MDDataAccess(object): self.natoms = numatoms usedefault=False break - #except (AttributeError, IOError, OSError, ValueError, TypeError): - except IOError: + except (IOError, ValueError, TypeError, KeyError): + #except IOError: pass # if topology handler is not a MDAnalysis Universe # or is not initialized, we can try accessing only @@ -2799,11 +2798,21 @@ class MDDataAccess(object): if __name__ == "__main__": topo_file = sys.argv[1] - traj_file = sys.argv[2] + topo_format = sys.argv[2] + traj_file = sys.argv[3] + traj_format = sys.argv[4] MDdata = MDDataAccess() MDdata.trajfile = traj_file MDdata.topofile = topo_file - #MDdata.interfaceorder = ["mdanalysis", "pymolfile", "mdtraj", "ase"] + if 'None' in topo_format: + pass + else: + MDdata.topoformat = topo_format + if 'None' in traj_format: + pass + else: + MDdata.trajformat = traj_format + MDdata.interfaceorder = ["mdanalysis", "pymolfile", "mdtraj", "ase"] #MDdata.interfaceorder = ["pymolfile", "mdanalysis", "mdtraj", "ase"] MDdata.interfacematch = False traj_iterator = MDdata.load() -- GitLab