Skip to content

Commit

Permalink
Merge pull request #689 from xchem/m2ms-1512-altlocs
Browse files Browse the repository at this point in the history
Enable aligned files sdf capture and download (issue 1512, altlocs)
  • Loading branch information
kaliif authored Nov 8, 2024
2 parents cae4416 + 3d08884 commit 77bdce1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
14 changes: 7 additions & 7 deletions viewer/download_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
'apo_desolv_file': ('aligned'), # SiteObservation: apo_desolv_file
'bound_file': ('aligned'), # SiteObservation: bound_file
'sdf_info': ('aligned'), # SiteObservation: ligand_mol_file (indirectly)
'ligand_mol': ('aligned'), # SiteObservation: ligand_mol
'ligand_sdf': ('aligned'), # SiteObservation: ligand_sdf
'ligand_smiles': ('aligned'), # SiteObservation: ligand_smiles
'ligand_pdb': ('aligned'), # SiteObservation: ligand_pdb
'smiles_info': (''), # SiteObservation: smiles_info (indirectly)
Expand Down Expand Up @@ -87,7 +87,7 @@ class ArchiveFile:
'diff_file': {},
'sigmaa_file': {},
'ligand_pdb': {},
'ligand_mol': {},
'ligand_sdf': {},
'ligand_smiles': {},
# additional ccp4 files, issue 1448
'event_file_crystallographic': {},
Expand Down Expand Up @@ -755,7 +755,7 @@ def _create_structures_dict(site_obvs, protein_params, other_params):
'artefacts_file',
'pdb_header_file',
'ligand_pdb',
'ligand_mol',
'ligand_sdf',
'ligand_smiles',
'diff_file',
]:
Expand Down Expand Up @@ -825,12 +825,12 @@ def _create_structures_dict(site_obvs, protein_params, other_params):
num_molecules_collected = 0
num_missing_sd_files = 0
for so in site_obvs:
if so.ligand_mol:
if so.ligand_sdf:
# There is an SD file (normal)
archive_path = str(
Path('aligned_files').joinpath(so.code).joinpath(f'{so.code}.sdf')
)
file_path = str(Path(settings.MEDIA_ROOT).joinpath(so.ligand_mol.name))
file_path = str(Path(settings.MEDIA_ROOT).joinpath(so.ligand_sdf.name))
# path is ignored when writing sdfs but mandatory field
zip_contents['molecules']['sdf_files'].update(
{
Expand All @@ -845,7 +845,7 @@ def _create_structures_dict(site_obvs, protein_params, other_params):
else:
# No file value (odd).
logger.warning(
"SiteObservation record's 'ligand_mol' isn't set (%s)", so
"SiteObservation record's 'ligand_sdf' isn't set (%s)", so
)
num_missing_sd_files += 1

Expand Down Expand Up @@ -899,7 +899,7 @@ def get_download_params(request):
'apo_solv_file': serializer.validated_data['all_aligned_structures'],
'apo_desolv_file': serializer.validated_data['all_aligned_structures'],
'ligand_pdb': serializer.validated_data['all_aligned_structures'],
'ligand_mol': serializer.validated_data['all_aligned_structures'],
'ligand_sdf': serializer.validated_data['all_aligned_structures'],
'ligand_smiles': serializer.validated_data['all_aligned_structures'],
'cif_info': serializer.validated_data['cif_info'],
'mtz_info': serializer.validated_data['mtz_info'],
Expand Down
28 changes: 28 additions & 0 deletions viewer/migrations/0084_auto_20241108_1119.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.25 on 2024-11-08 11:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('viewer', '0083_merge_20241105_1101'),
]

operations = [
migrations.AddField(
model_name='historicalsiteobservation',
name='ligand_sdf',
field=models.TextField(max_length=255, null=True),
),
migrations.AddField(
model_name='siteobservation',
name='ligand_sdf',
field=models.FileField(max_length=255, null=True, upload_to='target_loader_data/'),
),
migrations.AlterField(
model_name='compoundidentifier',
name='name',
field=models.TextField(),
),
]
3 changes: 3 additions & 0 deletions viewer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ class SiteObservation(Versionable, models.Model):
ligand_pdb = models.FileField(
upload_to="target_loader_data/", null=True, max_length=255
)
ligand_sdf = models.FileField(
upload_to="target_loader_data/", null=True, max_length=255
)
objects = models.Manager()
history = HistoricalRecords()
filter_manager = SiteObservationDataManager()
Expand Down
7 changes: 6 additions & 1 deletion viewer/target_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ def process_site_observation(
pdb_apo_solv: <file path>,
pdb_apo_desolv: <file path>,
ligand_mol: <file path>,
ligand_mol: <file path>,
ligand_pdb: <file path>,
ligand_smiles: <smiles>,
}
Expand Down Expand Up @@ -1387,6 +1388,7 @@ def process_site_observation(
ligand_pdb_t,
ligand_mol_t,
ligand_smiles_t,
ligand_sdf_t,
) = self.validate_files(
obj_identifier=experiment_id,
file_struct=data,
Expand All @@ -1404,6 +1406,7 @@ def process_site_observation(
"ligand_pdb",
"ligand_mol",
"ligand_smiles",
"ligand_sdf",
),
validate_files=validate_files,
)
Expand All @@ -1419,6 +1422,7 @@ def process_site_observation(
ligand_pdb = ligand_pdb_t[0]
ligand_mol = ligand_mol_t[0]
ligand_smiles = ligand_smiles_t[0]
ligand_sdf = ligand_sdf_t[0]

fields = {
# Code for this protein (e.g. Mpro_Nterm-x0029_A_501_0)
Expand All @@ -1445,7 +1449,8 @@ def process_site_observation(
"ligand_pdb": str(self._get_final_path(ligand_pdb)),
"ligand_mol": str(self._get_final_path(ligand_mol)),
"ligand_smiles": str(self._get_final_path(ligand_smiles)),
"pdb_header_file": "currently missing",
"ligand_sdf": str(self._get_final_path(ligand_sdf)),
"pdb_header_file": None,
}

return ProcessedObject(
Expand Down

0 comments on commit 77bdce1

Please sign in to comment.