Skip to content
Snippets Groups Projects
Commit ac71ab58 authored by Studer Gabriel's avatar Studer Gabriel
Browse files

Consider file suffix when loading structures in compare-structures action

If fault_tolerant is enabled, it might happily read a cif file as PDB file.
As a consequence, there are no residues in the returned entity.
parent de707c8d
Branches
Tags
No related merge requests found
...@@ -568,17 +568,26 @@ def _ReadStructureFile(path, c_alpha_only=False, fault_tolerant=False, ...@@ -568,17 +568,26 @@ def _ReadStructureFile(path, c_alpha_only=False, fault_tolerant=False,
entities = list() entities = list()
if not os.path.isfile(path): if not os.path.isfile(path):
raise IOError("%s is not a file" % path) raise IOError("%s is not a file" % path)
try:
# Determine file format from suffix.
ext = path.split(".")
if ext[-1] == "gz":
ext = ext[:-1]
if len(ext) <= 1:
raise RuntimeError(f"Could not determine format of file {path}.")
sformat = ext[-1].lower()
if sformat in ["pdb"]:
entity = LoadPDB( entity = LoadPDB(
path, path,
fault_tolerant=fault_tolerant, fault_tolerant=fault_tolerant,
calpha_only=c_alpha_only) calpha_only=c_alpha_only)
if not entity.IsValid(): if not entity.IsValid() or len(entity.residues) == 0:
raise IOError("Provided file does not contain valid entity.") raise IOError("Provided file does not contain valid entity.")
entity.SetName(os.path.basename(path)) entity.SetName(os.path.basename(path))
entity = _Select(entity) entity = _Select(entity)
entities.append(entity) entities.append(entity)
except Exception: elif sformat in ["cif", "mmcif"]:
try: try:
tmp_entity, cif_info = LoadMMCIF( tmp_entity, cif_info = LoadMMCIF(
path, path,
...@@ -623,6 +632,9 @@ def _ReadStructureFile(path, c_alpha_only=False, fault_tolerant=False, ...@@ -623,6 +632,9 @@ def _ReadStructureFile(path, c_alpha_only=False, fault_tolerant=False,
except Exception: except Exception:
raise raise
else:
raise RuntimeError(f"Unsupported file extension found for file {path}.")
return entities return entities
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment