Skip to content

Commit f47e41c

Browse files
committed
feat: map files now available for download in api/download_structures
Also, assemblies.yaml is now expected instead of crystalforms.yaml
1 parent f6bc83d commit f47e41c

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

viewer/download_structures.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'bound_file': ('aligned'),
3636
'cif_info': ('aligned'),
3737
'mtz_info': ('aligned'),
38-
# 'map_info': ('aligned'),
38+
'map_info': ('aligned'),
3939
'sigmaa_file': ('aligned'),
4040
'diff_file': ('aligned'),
4141
'event_file': ('aligned'),
@@ -56,8 +56,9 @@
5656
'bound_file': {}, # x
5757
'cif_info': {}, # from experiment
5858
'mtz_info': {}, # from experiment
59+
'map_info': {}, # from experiment
5960
'event_file': {}, # x
60-
'diff_file': {}, # renamed from diff_file and sigmaa_file
61+
'diff_file': {},
6162
'sigmaa_file': {},
6263
},
6364
'molecules': {
@@ -229,6 +230,7 @@ def _add_file_to_zip_aligned(ziparchive, code, filepath):
229230
filepath = str(Path(settings.MEDIA_ROOT).joinpath(filepath))
230231

231232
if Path(filepath).is_file():
233+
# strip off the leading parts of path
232234
archive_path = str(Path(*Path(filepath).parts[7:]))
233235
if _is_mol_or_sdf(filepath):
234236
# It's a MOL or SD file.
@@ -285,9 +287,13 @@ def _protein_files_zip(zip_contents, ziparchive, error_file):
285287
continue
286288

287289
for prot, prot_file in files.items():
288-
if not _add_file_to_zip_aligned(ziparchive, prot.split(":")[0], prot_file):
289-
error_file.write(f'{param},{prot},{prot_file}\n')
290-
prot_errors += 1
290+
# if it's a list of files (map_info) instead of single file
291+
if not isinstance(prot_file, list):
292+
prot_file = [prot_file]
293+
for f in prot_file:
294+
if not _add_file_to_zip_aligned(ziparchive, prot.split(":")[0], f):
295+
error_file.write(f'{param},{prot},{f}\n')
296+
prot_errors += 1
291297

292298
return prot_errors
293299

@@ -606,10 +612,14 @@ def _create_structures_dict(target, site_obvs, protein_params, other_params):
606612
# getting the param from experiment. more data are
607613
# coming from there, that's why this is in try
608614
# block
609-
# getattr retrieves FieldFile object, hance the .name
610-
zip_contents['proteins'][param][so.code] = getattr(
611-
so.experiment, param
612-
).name
615+
model_attr = getattr(so.experiment, param)
616+
# getattr retrieves FieldFile object, hence the .name
617+
if isinstance(model_attr, list):
618+
# except map_files, this returns a list of files
619+
zip_contents['proteins'][param][so.code] = model_attr
620+
else:
621+
zip_contents['proteins'][param][so.code] = model_attr.name
622+
613623
except AttributeError:
614624
# on the off chance that the data are in site_observation model
615625
zip_contents['proteins'][param][so.code] = getattr(so, param).name
@@ -686,6 +696,7 @@ def get_download_params(request):
686696
'bound_file',
687697
'cif_info',
688698
'mtz_info',
699+
'map_info',
689700
'event_file',
690701
'sigmaa_file',
691702
'diff_file',

viewer/serializers.py

+1
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ class DownloadStructuresSerializer(serializers.Serializer):
832832
diff_file = serializers.BooleanField(default=False)
833833
event_file = serializers.BooleanField(default=False)
834834
sigmaa_file = serializers.BooleanField(default=False)
835+
map_info = serializers.BooleanField(default=False)
835836
sdf_info = serializers.BooleanField(default=False)
836837
single_sdf_file = serializers.BooleanField(default=False)
837838
metadata_info = serializers.BooleanField(default=False)

viewer/target_loader.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646

4747
# data that goes to tables are in the following files
4848
# assemblies and xtalforms
49-
# XTALFORMS_FILE = "assemblies.yaml"
50-
XTALFORMS_FILE = "crystalforms.yaml"
49+
XTALFORMS_FILE = "assemblies.yaml"
5150

5251
# target name, nothing else
5352
CONFIG_FILE = "config*.yaml"
@@ -706,8 +705,6 @@ def process_experiment(
706705
file_struct=panddas_files,
707706
)
708707

709-
logger.debug("map_info_files: %s", map_info_files)
710-
711708
dtype = extract(key="type")
712709

713710
if dtype == "manual":
@@ -750,8 +747,6 @@ def process_experiment(
750747
if map_info_files:
751748
map_info_paths = [str(self._get_final_path(k)) for k in map_info_files]
752749

753-
logger.debug("map_info_paths: %s", map_info_paths)
754-
755750
defaults = {
756751
"status": status,
757752
"version": version,

0 commit comments

Comments
 (0)