diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 20cfd37b61ce883451e2ed30ed85b7ca52dad2b1..b33aa47ca38bf22015ddd9fc7533908ceea000b6 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -1089,7 +1089,7 @@ class Compound(AutoFillableModel): """ String representation """ - return "Compound #{}".format(self.id) + return "iPPI-DB Compound #{}".format(self.id) def get_absolute_url(self): """ @@ -1165,6 +1165,30 @@ class Compound(AutoFillableModel): urls.append(self.drugbank_url) return urls + def get_bioschemas(self, request): + json_data = { + "@type": "MolecularEntity", + "@context": "http://schema.org" + } + json_data['name'] = str(self) + if self.pk is not None: + json_data['url'] = request.build_absolute_uri(self.get_absolute_url()) + if self.inchi is not None: + json_data['inChI'] = self.inchi + if self.iupac_name != "": + json_data['iupacName'] = self.iupac_name + if self.molecular_weight is not None: + json_data['molecularWeight'] = self.molecular_weight + if self.inchikey is not None: + json_data['inChIKey'] = self.inchikey + if self.chembl_id is not None: + json_data['image'] = f"https://www.ebi.ac.uk/chembl/api/data/image/{ self.chembl_id }.svg" + if self.canonical_smile is not None: + json_data['smiles'] = self.canonical_smile + if len(self.sameas_urls)>0: + json_data['sameAs'] = self.sameas_urls + return json_data + def clean(self): """ Perform additional checks: diff --git a/ippisite/ippidb/templates/compound_card.html b/ippisite/ippidb/templates/compound_card.html index 19ee66094b276e7ebef22974fb79a3d78639475b..94436c01b566cbd3cffbe07e068d99e265677d11 100644 --- a/ippisite/ippidb/templates/compound_card.html +++ b/ippisite/ippidb/templates/compound_card.html @@ -557,42 +557,7 @@ </div> </div> -<script id='JSON_LD' type="application/ld+json"> - - { -"url": "{{ request.build_absolute_uri }}", -{% if compound.inchi %} -"inChI": "{{ compound.inchi }}", -{% endif %} -{% if compound.iupac_name %} -"name": "{{ compound.iupac_name }}", -{% endif %} -{% if compound.iupac_name %} -"iupacName": "{{ compound.iupac_name }}", -{% endif %} -{% if compound.molecular_weight %} -"molecularWeight": {{ compound.molecular_weight }}, -{% endif %} -"identifier": "{{ compound.id }}", -{% if compound.inchikey %} -"inChIKey": "{{ compound.inchikey }}", -{% endif %} -"@type": "MolecularEntity", -{% if compound.chembl_id %} -"image": "https://www.ebi.ac.uk/chembl/api/data/image/{{ compound.chembl_id }}.svg", -{% endif %} -{% if compound.canonical_smile %} -"smiles": [ - "{{ compound.canonical_smile|escapejs }}" -], -{% endif %} -{% if compound.sameas_urls %} -"sameAs": {{ compound.sameas_urls|safe }}, -{% endif %} -"@context": "http://schema.org" -} - -</script> +{{ bioschemas_data|json_script:compound }} <script> var showTab = function (hash) { window.location.hash = hash; diff --git a/ippisite/ippidb/views/compound_query.py b/ippisite/ippidb/views/compound_query.py index 9d78f4871e3acc768bed434ee9aeeb1ce28b1abd..cb894a7268f5d9de13a8e272baf714a765e0af45 100644 --- a/ippisite/ippidb/views/compound_query.py +++ b/ippisite/ippidb/views/compound_query.py @@ -771,6 +771,7 @@ class CompoundDetailView(DetailView): pca_biplot = {"data": [], "correlation_circle": ""} context["pca_biplot_data"] = pca_biplot["data"] context["pca_biplot_cc"] = pca_biplot["correlation_circle"] + context["bioschemas_data"] = self.object.get_bioschemas(self.request) return context