Skip to content

Commit

Permalink
feat: map files now available for download in api/download_structures
Browse files Browse the repository at this point in the history
Also, assemblies.yaml is now expected instead of crystalforms.yaml
  • Loading branch information
kaliif committed Jan 30, 2024
1 parent f6bc83d commit f47e41c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
29 changes: 20 additions & 9 deletions viewer/download_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'bound_file': ('aligned'),
'cif_info': ('aligned'),
'mtz_info': ('aligned'),
# 'map_info': ('aligned'),
'map_info': ('aligned'),
'sigmaa_file': ('aligned'),
'diff_file': ('aligned'),
'event_file': ('aligned'),
Expand All @@ -56,8 +56,9 @@
'bound_file': {}, # x
'cif_info': {}, # from experiment
'mtz_info': {}, # from experiment
'map_info': {}, # from experiment
'event_file': {}, # x
'diff_file': {}, # renamed from diff_file and sigmaa_file
'diff_file': {},
'sigmaa_file': {},
},
'molecules': {
Expand Down Expand Up @@ -229,6 +230,7 @@ def _add_file_to_zip_aligned(ziparchive, code, filepath):
filepath = str(Path(settings.MEDIA_ROOT).joinpath(filepath))

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

for prot, prot_file in files.items():
if not _add_file_to_zip_aligned(ziparchive, prot.split(":")[0], prot_file):
error_file.write(f'{param},{prot},{prot_file}\n')
prot_errors += 1
# if it's a list of files (map_info) instead of single file
if not isinstance(prot_file, list):
prot_file = [prot_file]
for f in prot_file:
if not _add_file_to_zip_aligned(ziparchive, prot.split(":")[0], f):
error_file.write(f'{param},{prot},{f}\n')
prot_errors += 1

return prot_errors

Expand Down Expand Up @@ -606,10 +612,14 @@ def _create_structures_dict(target, site_obvs, protein_params, other_params):
# getting the param from experiment. more data are
# coming from there, that's why this is in try
# block
# getattr retrieves FieldFile object, hance the .name
zip_contents['proteins'][param][so.code] = getattr(
so.experiment, param
).name
model_attr = getattr(so.experiment, param)
# getattr retrieves FieldFile object, hence the .name
if isinstance(model_attr, list):
# except map_files, this returns a list of files
zip_contents['proteins'][param][so.code] = model_attr
else:
zip_contents['proteins'][param][so.code] = model_attr.name

except AttributeError:
# on the off chance that the data are in site_observation model
zip_contents['proteins'][param][so.code] = getattr(so, param).name
Expand Down Expand Up @@ -686,6 +696,7 @@ def get_download_params(request):
'bound_file',
'cif_info',
'mtz_info',
'map_info',
'event_file',
'sigmaa_file',
'diff_file',
Expand Down
1 change: 1 addition & 0 deletions viewer/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ class DownloadStructuresSerializer(serializers.Serializer):
diff_file = serializers.BooleanField(default=False)
event_file = serializers.BooleanField(default=False)
sigmaa_file = serializers.BooleanField(default=False)
map_info = serializers.BooleanField(default=False)
sdf_info = serializers.BooleanField(default=False)
single_sdf_file = serializers.BooleanField(default=False)
metadata_info = serializers.BooleanField(default=False)
Expand Down
7 changes: 1 addition & 6 deletions viewer/target_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@

# data that goes to tables are in the following files
# assemblies and xtalforms
# XTALFORMS_FILE = "assemblies.yaml"
XTALFORMS_FILE = "crystalforms.yaml"
XTALFORMS_FILE = "assemblies.yaml"

# target name, nothing else
CONFIG_FILE = "config*.yaml"
Expand Down Expand Up @@ -706,8 +705,6 @@ def process_experiment(
file_struct=panddas_files,
)

logger.debug("map_info_files: %s", map_info_files)

dtype = extract(key="type")

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

logger.debug("map_info_paths: %s", map_info_paths)

defaults = {
"status": status,
"version": version,
Expand Down

0 comments on commit f47e41c

Please sign in to comment.