Skip to content
Snippets Groups Projects
Unverified Commit a79b7251 authored by Xavier Robin's avatar Xavier Robin
Browse files

fix: identify biounit with string id

parent f90a1db8
Branches
Tags
No related merge requests found
...@@ -139,11 +139,11 @@ def _ParseArgs(): ...@@ -139,11 +139,11 @@ def _ParseArgs():
dest="model_biounit", dest="model_biounit",
required=False, required=False,
default=None, default=None,
type=int, type=str,
help=("Only has an effect if model is in mmcif format. By default, " help=("Only has an effect if model is in mmcif format. By default, "
"the asymmetric unit (AU) is used for scoring. If there are " "the asymmetric unit (AU) is used for scoring. If there are "
"biounits defined in the mmcif file, you can specify the " "biounits defined in the mmcif file, you can specify the "
"(0-based) index of the one which should be used.")) "ID (as a string) of the one which should be used."))
parser.add_argument( parser.add_argument(
"-rb", "-rb",
...@@ -151,11 +151,11 @@ def _ParseArgs(): ...@@ -151,11 +151,11 @@ def _ParseArgs():
dest="reference_biounit", dest="reference_biounit",
required=False, required=False,
default=None, default=None,
type=int, type=str,
help=("Only has an effect if reference is in mmcif format. By default, " help=("Only has an effect if reference is in mmcif format. By default, "
"the asymmetric unit (AU) is used for scoring. If there are " "the asymmetric unit (AU) is used for scoring. If there are "
"biounits defined in the mmcif file, you can specify the " "biounits defined in the mmcif file, you can specify the "
"(0-based) index of the one which should be used.")) "ID (as a string) of the one which should be used."))
parser.add_argument( parser.add_argument(
"-ft", "-ft",
...@@ -317,7 +317,7 @@ def _GetStructureFormat(structure_path, sformat=None): ...@@ -317,7 +317,7 @@ def _GetStructureFormat(structure_path, sformat=None):
f"file {structure_path}.") f"file {structure_path}.")
def _LoadStructure(structure_path, sformat, fault_tolerant, bu_idx): def _LoadStructure(structure_path, sformat, fault_tolerant, bu_id):
"""Read OST entity either from mmCIF or PDB. """Read OST entity either from mmCIF or PDB.
The returned structure has structure_path attached as structure name The returned structure has structure_path attached as structure name
...@@ -329,24 +329,20 @@ def _LoadStructure(structure_path, sformat, fault_tolerant, bu_idx): ...@@ -329,24 +329,20 @@ def _LoadStructure(structure_path, sformat, fault_tolerant, bu_idx):
ost.PushVerbosityLevel(ost.LogLevel.Error) ost.PushVerbosityLevel(ost.LogLevel.Error)
# Load the structure # Load the structure
if sformat == "mmcif": if sformat == "mmcif":
if bu_idx is not None: if bu_id is not None:
cif_entity, cif_seqres, cif_info = \ cif_entity, cif_seqres, cif_info = \
io.LoadMMCIF(structure_path, info=True, seqres=True, io.LoadMMCIF(structure_path, info=True, seqres=True,
fault_tolerant=fault_tolerant) fault_tolerant=fault_tolerant)
if len(cif_info.biounits) == 0: for biounit in cif_info.biounits:
raise RuntimeError(f"No biounit found - requested index" if biounit.id == bu_id:
f" {bu_idx}.") entity = ost.mol.alg.CreateBU(cif_entity, biounit)
elif bu_idx < 0: if not entity.IsValid():
raise RuntimeError(f"Invalid biounit - requested index {bu_idx}, " raise IOError(
f"must be a positive integer or 0.") "Provided file does not contain valid entity.")
elif bu_idx >= len(cif_info.biounits): break
raise RuntimeError(f"Invalid biounit - requested index {bu_idx}, " else:
f"must be < {len(cif_info.biounits)}.") raise RuntimeError(f"No biounit found with ID '{bu_id}'.")
biounit = cif_info.biounits[bu_idx]
entity = ost.mol.alg.CreateBU(cif_entity, biounit)
if not entity.IsValid():
raise IOError(
"Provided file does not contain valid entity.")
else: else:
entity = io.LoadMMCIF(structure_path, entity = io.LoadMMCIF(structure_path,
fault_tolerant = fault_tolerant) fault_tolerant = fault_tolerant)
...@@ -594,13 +590,13 @@ def _Main(): ...@@ -594,13 +590,13 @@ def _Main():
sformat=args.reference_format) sformat=args.reference_format)
reference = _LoadStructure(args.reference, reference = _LoadStructure(args.reference,
sformat=reference_format, sformat=reference_format,
bu_idx=args.reference_biounit, bu_id=args.reference_biounit,
fault_tolerant = args.fault_tolerant) fault_tolerant = args.fault_tolerant)
model_format = _GetStructureFormat(args.model, model_format = _GetStructureFormat(args.model,
sformat=args.model_format) sformat=args.model_format)
model = _LoadStructure(args.model, model = _LoadStructure(args.model,
sformat=model_format, sformat=model_format,
bu_idx=args.model_biounit, bu_id=args.model_biounit,
fault_tolerant = args.fault_tolerant) fault_tolerant = args.fault_tolerant)
# Load ligands # Load ligands
......
...@@ -141,11 +141,11 @@ def _ParseArgs(): ...@@ -141,11 +141,11 @@ def _ParseArgs():
dest="model_biounit", dest="model_biounit",
required=False, required=False,
default=None, default=None,
type=int, type=str,
help=("Only has an effect if model is in mmcif format. By default, " help=("Only has an effect if model is in mmcif format. By default, "
"the asymmetric unit (AU) is used for scoring. If there are " "the asymmetric unit (AU) is used for scoring. If there are "
"biounits defined in the mmcif file, you can specify the " "biounits defined in the mmcif file, you can specify the "
"(0-based) index of the one which should be used.")) "ID (as a string) of the one which should be used."))
parser.add_argument( parser.add_argument(
"-rb", "-rb",
...@@ -153,11 +153,11 @@ def _ParseArgs(): ...@@ -153,11 +153,11 @@ def _ParseArgs():
dest="reference_biounit", dest="reference_biounit",
required=False, required=False,
default=None, default=None,
type=int, type=str,
help=("Only has an effect if reference is in mmcif format. By default, " help=("Only has an effect if reference is in mmcif format. By default, "
"the asymmetric unit (AU) is used for scoring. If there are " "the asymmetric unit (AU) is used for scoring. If there are "
"biounits defined in the mmcif file, you can specify the " "biounits defined in the mmcif file, you can specify the "
"(0-based) index of the one which should be used.")) "ID (as a string) of the one which should be used."))
parser.add_argument( parser.add_argument(
"-rna", "-rna",
...@@ -563,7 +563,7 @@ def _GetStructureFormat(structure_path, sformat=None): ...@@ -563,7 +563,7 @@ def _GetStructureFormat(structure_path, sformat=None):
raise Exception(f"Unknown/unsupported file format found for " raise Exception(f"Unknown/unsupported file format found for "
f"file {structure_path}.") f"file {structure_path}.")
def _LoadStructure(structure_path, sformat, fault_tolerant, bu_idx): def _LoadStructure(structure_path, sformat, fault_tolerant, bu_id):
"""Read OST entity either from mmCIF or PDB. """Read OST entity either from mmCIF or PDB.
The returned structure has structure_path attached as structure name The returned structure has structure_path attached as structure name
...@@ -575,24 +575,19 @@ def _LoadStructure(structure_path, sformat, fault_tolerant, bu_idx): ...@@ -575,24 +575,19 @@ def _LoadStructure(structure_path, sformat, fault_tolerant, bu_idx):
ost.PushVerbosityLevel(ost.LogLevel.Error) ost.PushVerbosityLevel(ost.LogLevel.Error)
# Load the structure # Load the structure
if sformat == "mmcif": if sformat == "mmcif":
if bu_idx is not None: if bu_id is not None:
cif_entity, cif_seqres, cif_info = \ cif_entity, cif_seqres, cif_info = \
io.LoadMMCIF(structure_path, info=True, seqres=True, io.LoadMMCIF(structure_path, info=True, seqres=True,
fault_tolerant=fault_tolerant) fault_tolerant=fault_tolerant)
if len(cif_info.biounits) == 0: for biounit in cif_info.biounits:
raise RuntimeError(f"No biounit found - requested index" if biounit.id == bu_id:
f" {bu_idx}.") entity = ost.mol.alg.CreateBU(cif_entity, biounit)
elif bu_idx < 0: if not entity.IsValid():
raise RuntimeError(f"Invalid biounit - requested index {bu_idx}, " raise IOError(
f"must be a positive integer or 0.") "Provided file does not contain valid entity.")
elif bu_idx >= len(cif_info.biounits): break
raise RuntimeError(f"Invalid biounit - requested index {bu_idx}, " else:
f"must be < {len(cif_info.biounits)}.") raise RuntimeError(f"No biounit found with ID '{bu_id}'.")
biounit = cif_info.biounits[bu_idx]
entity = ost.mol.alg.CreateBU(cif_entity, biounit)
if not entity.IsValid():
raise IOError(
"Provided file does not contain valid entity.")
else: else:
entity = io.LoadMMCIF(structure_path, entity = io.LoadMMCIF(structure_path,
fault_tolerant = fault_tolerant) fault_tolerant = fault_tolerant)
...@@ -870,13 +865,13 @@ def _Main(): ...@@ -870,13 +865,13 @@ def _Main():
sformat=args.reference_format) sformat=args.reference_format)
reference = _LoadStructure(args.reference, reference = _LoadStructure(args.reference,
sformat=reference_format, sformat=reference_format,
bu_idx=args.reference_biounit, bu_id=args.reference_biounit,
fault_tolerant = args.fault_tolerant) fault_tolerant = args.fault_tolerant)
model_format = _GetStructureFormat(args.model, model_format = _GetStructureFormat(args.model,
sformat=args.model_format) sformat=args.model_format)
model = _LoadStructure(args.model, model = _LoadStructure(args.model,
sformat=model_format, sformat=model_format,
bu_idx=args.model_biounit, bu_id=args.model_biounit,
fault_tolerant = args.fault_tolerant) fault_tolerant = args.fault_tolerant)
out = _Process(model, reference, args, model_format, reference_format) out = _Process(model, reference, args, model_format, reference_format)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment