Skip to content

Commit

Permalink
Merge pull request #697 from xchem/m2ms-1575-vectors
Browse files Browse the repository at this point in the history
Removed reference to old observation attribute (issue 1575, vectors)
  • Loading branch information
kaliif authored Dec 5, 2024
2 parents e6730ed + 552f76b commit fc0c2cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
11 changes: 11 additions & 0 deletions viewer/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import logging
import uuid
from dataclasses import dataclass
Expand Down Expand Up @@ -575,6 +576,16 @@ def __repr__(self) -> str:
self.cmpd,
)

def get_ligand_mol_file(self):
contents = ''
if self.ligand_mol:
path = Path(settings.MEDIA_ROOT).joinpath(self.ligand_mol.name)
with contextlib.suppress(TypeError, FileNotFoundError):
with open(path, "r", encoding="utf-8") as f:
contents = f.read()

return contents


class CompoundIdentifierType(models.Model):
name = models.TextField(primary_key=True)
Expand Down
23 changes: 6 additions & 17 deletions viewer/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import contextlib
import logging
from pathlib import Path
from urllib.parse import urljoin
Expand Down Expand Up @@ -481,18 +480,15 @@ class VectorsSerializer(serializers.ModelSerializer):
vectors = serializers.SerializerMethodField()

def get_vectors(self, obj):
ligand_mol_file = obj.get_ligand_mol_file()
out_data = {}
if obj.ligand_mol_file:
if ligand_mol_file:
try:
out_data["3d"] = get_3d_vects_for_mol(
obj.ligand_mol_file, iso_labels=False
)
out_data["3d"] = get_3d_vects_for_mol(ligand_mol_file, iso_labels=False)
# temporary patch
except IndexError:
out_data["3d"] = get_3d_vects_for_mol(
obj.ligand_mol_file, iso_labels=True
)
out_data["indices"] = get_vect_indices_for_mol(obj.ligand_mol_file)
out_data["3d"] = get_3d_vects_for_mol(ligand_mol_file, iso_labels=True)
out_data["indices"] = get_vect_indices_for_mol(ligand_mol_file)
return out_data

class Meta:
Expand Down Expand Up @@ -955,14 +951,7 @@ class SiteObservationReadSerializer(serializers.ModelSerializer):
ligand_mol_file = serializers.SerializerMethodField()

def get_ligand_mol_file(self, obj):
contents = ''
if obj.ligand_mol:
path = Path(settings.MEDIA_ROOT).joinpath(obj.ligand_mol.name)
with contextlib.suppress(TypeError, FileNotFoundError):
with open(path, "r", encoding="utf-8") as f:
contents = f.read()

return contents
return obj.get_ligand_mol_file()

class Meta:
model = models.SiteObservation
Expand Down

0 comments on commit fc0c2cd

Please sign in to comment.