forked from enviPath/enviPy
wip
This commit is contained in:
@ -1,3 +1,19 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
from .models import (
|
||||||
|
PESCompound,
|
||||||
|
PESStructure
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PESCompoundAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class PESStructureAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(PESCompound, PESCompoundAdmin)
|
||||||
|
admin.site.register(PESStructure, PESStructureAdmin)
|
||||||
|
|||||||
@ -4,6 +4,7 @@ from epdb.template_registry import register_template
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# PES Create
|
||||||
register_template(
|
register_template(
|
||||||
"epdb.actions.collections.compound",
|
"epdb.actions.collections.compound",
|
||||||
"actions/collections/new_pes.html",
|
"actions/collections/new_pes.html",
|
||||||
@ -13,3 +14,18 @@ register_template(
|
|||||||
"modals/collections/new_pes_modal.html",
|
"modals/collections/new_pes_modal.html",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# PES Viz
|
||||||
|
register_template(
|
||||||
|
"epdb.objects.compound.viz",
|
||||||
|
"objects/compound_viz.html",
|
||||||
|
)
|
||||||
|
|
||||||
|
register_template(
|
||||||
|
"epdb.objects.compound_structure.viz",
|
||||||
|
"objects/compound_structure_viz.html",
|
||||||
|
)
|
||||||
|
|
||||||
|
register_template(
|
||||||
|
"epdb.objects.node.viz",
|
||||||
|
"objects/node_viz.html",
|
||||||
|
)
|
||||||
35
bayer/migrations/0004_pescompound_pesstructure.py
Normal file
35
bayer/migrations/0004_pescompound_pesstructure.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# Generated by Django 6.0.3 on 2026-04-15 20:03
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bayer', '0003_package_data_pool'),
|
||||||
|
('epdb', '0023_alter_compoundstructure_options_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='PESCompound',
|
||||||
|
fields=[
|
||||||
|
('compound_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='epdb.compound')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
bases=('epdb.compound',),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='PESStructure',
|
||||||
|
fields=[
|
||||||
|
('compoundstructure_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='epdb.compoundstructure')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
bases=('epdb.compoundstructure',),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
bayer/migrations/0005_pesstructure_pes_link.py
Normal file
19
bayer/migrations/0005_pesstructure_pes_link.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 6.0.3 on 2026-04-16 08:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bayer', '0004_pescompound_pesstructure'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='pesstructure',
|
||||||
|
name='pes_link',
|
||||||
|
field=models.URLField(default=None, verbose_name='PES Link'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -1,11 +1,15 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
import urllib.parse
|
||||||
|
import nh3
|
||||||
from django.conf import settings as s
|
from django.conf import settings as s
|
||||||
from django.db import models
|
from django.db import models, transaction
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from epdb.models import (
|
from epdb.models import (
|
||||||
EnviPathModel,
|
EnviPathModel,
|
||||||
|
Compound,
|
||||||
|
CompoundStructure,
|
||||||
ParallelRule,
|
ParallelRule,
|
||||||
SequentialRule,
|
SequentialRule,
|
||||||
SimpleAmbitRule,
|
SimpleAmbitRule,
|
||||||
@ -95,4 +99,70 @@ class Package(EnviPathModel):
|
|||||||
return rules
|
return rules
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "epdb_package"
|
db_table = "epdb_package"
|
||||||
|
|
||||||
|
|
||||||
|
class PESCompound(Compound):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@transaction.atomic
|
||||||
|
def create(
|
||||||
|
package: "Package", pes_data: dict, name: str = None, description: str = None, *args, **kwargs
|
||||||
|
) -> "Compound":
|
||||||
|
|
||||||
|
pes_url = pes_data["pes_url"]
|
||||||
|
|
||||||
|
# Check if we find a direct match for a given pes_link
|
||||||
|
if PESStructure.objects.filter(pes_link=pes_url, compound__package=package).exists():
|
||||||
|
return PESStructure.objects.get(pes_link=pes_url, compound__package=package).compound
|
||||||
|
|
||||||
|
# Generate Compound
|
||||||
|
c = PESCompound()
|
||||||
|
c.package = package
|
||||||
|
|
||||||
|
if name is not None:
|
||||||
|
# Clean for potential XSS
|
||||||
|
name = nh3.clean(name, tags=s.ALLOWED_HTML_TAGS).strip()
|
||||||
|
|
||||||
|
if name is None or name == "":
|
||||||
|
name = f"Compound {Compound.objects.filter(package=package).count() + 1}"
|
||||||
|
|
||||||
|
c.name = name
|
||||||
|
|
||||||
|
# We have a default here only set the value if it carries some payload
|
||||||
|
if description is not None and description.strip() != "":
|
||||||
|
c.description = nh3.clean(description, tags=s.ALLOWED_HTML_TAGS).strip()
|
||||||
|
|
||||||
|
c.save()
|
||||||
|
|
||||||
|
is_standardized = standardized_smiles == smiles
|
||||||
|
|
||||||
|
if not is_standardized:
|
||||||
|
_ = CompoundStructure.create(
|
||||||
|
c,
|
||||||
|
standardized_smiles,
|
||||||
|
name="Normalized structure of {}".format(name),
|
||||||
|
description="{} (in its normalized form)".format(description),
|
||||||
|
normalized_structure=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
cs = CompoundStructure.create(
|
||||||
|
c, smiles, name=name, description=description, normalized_structure=is_standardized
|
||||||
|
)
|
||||||
|
|
||||||
|
c.default_structure = cs
|
||||||
|
c.save()
|
||||||
|
|
||||||
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
class PESStructure(CompoundStructure):
|
||||||
|
pes_link = models.URLField(blank=False, null=False, verbose_name="PES Link")
|
||||||
|
|
||||||
|
def d3_json(self):
|
||||||
|
return {
|
||||||
|
"is_pes": True,
|
||||||
|
"pes_link": self.pes_link,
|
||||||
|
# Will overwrite image from Node
|
||||||
|
"image": f"{reverse("depict_pes")}?pesLink={urllib.parse.quote(self.pes_link)}"
|
||||||
|
}
|
||||||
|
|||||||
@ -90,7 +90,7 @@
|
|||||||
<form
|
<form
|
||||||
id="new-pes-modal-form"
|
id="new-pes-modal-form"
|
||||||
accept-charset="UTF-8"
|
accept-charset="UTF-8"
|
||||||
action="{% url 'package compound list' meta.current_package.uuid %}"
|
action="{% url 'create pes' meta.current_package.uuid %}"
|
||||||
method="post"
|
method="post"
|
||||||
>
|
>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
@ -129,9 +129,10 @@
|
|||||||
name="pes-link"
|
name="pes-link"
|
||||||
type="text"
|
type="text"
|
||||||
class="input input-bordered w-full"
|
class="input input-bordered w-full"
|
||||||
placeholder="Link to PES"
|
placeholder="Link to PES e.g. https://pesregapp-test.cropkey-np.ag/entities/PES-000126"
|
||||||
x-model="pesLink"
|
x-model="pesLink"
|
||||||
@input="updatePesViz()"
|
@input="updatePesViz()"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
12
bayer/templates/objects/compound_structure_viz.html
Normal file
12
bayer/templates/objects/compound_structure_viz.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{% if compound_structure.pes_link %}
|
||||||
|
<!-- Image Representation -->
|
||||||
|
<div class="collapse-arrow bg-base-200 collapse">
|
||||||
|
<input type="checkbox" checked />
|
||||||
|
<div class="collapse-title text-xl font-medium">PES Image Representation</div>
|
||||||
|
<div class="collapse-content">
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<img src='{% url 'depict_pes' %}?pesLink={{ compound_structure.pes_link|urlencode }}'/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
12
bayer/templates/objects/compound_viz.html
Normal file
12
bayer/templates/objects/compound_viz.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{% if compound.default_structure.pes_link %}
|
||||||
|
<!-- Image Representation -->
|
||||||
|
<div class="collapse-arrow bg-base-200 collapse">
|
||||||
|
<input type="checkbox" checked />
|
||||||
|
<div class="collapse-title text-xl font-medium">PES Image Representation</div>
|
||||||
|
<div class="collapse-content">
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<img src='{% url 'depict_pes' %}?pesLink={{ compound.default_structure.pes_link|urlencode }}'/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
12
bayer/templates/objects/node_viz.html
Normal file
12
bayer/templates/objects/node_viz.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{% if node.default_node_label.pes_link %}
|
||||||
|
<!-- Image Representation -->
|
||||||
|
<div class="collapse-arrow bg-base-200 collapse">
|
||||||
|
<input type="checkbox" checked />
|
||||||
|
<div class="collapse-title text-xl font-medium">PES Image Representation</div>
|
||||||
|
<div class="collapse-content">
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<img src='{% url 'depict_pes' %}?pesLink={{ node.default_node_label.pes_link|urlencode }}'/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
@ -2,7 +2,13 @@ from django.urls import re_path
|
|||||||
|
|
||||||
from . import views as v
|
from . import views as v
|
||||||
|
|
||||||
|
UUID = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
re_path(r"^depict_pes$", v.visualize_pes, name="depict_pes"),
|
re_path(r"^depict_pes$", v.visualize_pes, name="depict_pes"),
|
||||||
|
re_path(
|
||||||
|
rf"^package/(?P<package_uuid>{UUID})/compound$",
|
||||||
|
v.create_pes,
|
||||||
|
name="create pes",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,13 +1,41 @@
|
|||||||
|
import base64
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from django.conf import settings as s
|
from django.conf import settings as s
|
||||||
|
from django.core.exceptions import BadRequest
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from pydantic import BaseModel
|
from django.shortcuts import redirect
|
||||||
|
|
||||||
from utilities.chem import FormatConverter
|
from bayer.models import PESCompound
|
||||||
|
from epdb.logic import PackageManager
|
||||||
|
from epdb.views import _anonymous_or_real
|
||||||
|
from utilities.decorators import package_permission_required
|
||||||
|
|
||||||
|
|
||||||
class PES(BaseModel):
|
@package_permission_required()
|
||||||
pass
|
def create_pes(request, package_uuid):
|
||||||
|
current_user = _anonymous_or_real(request)
|
||||||
|
current_package = PackageManager.get_package_by_id(current_user, package_uuid)
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
compound_name = request.POST.get('compound-name')
|
||||||
|
compound_description = request.POST.get('compound-description')
|
||||||
|
pes_link = request.POST.get('pes-link')
|
||||||
|
|
||||||
|
if pes_link:
|
||||||
|
try:
|
||||||
|
pes_data = fetch_pes(request, pes_link)
|
||||||
|
except ValueError as e:
|
||||||
|
return BadRequest(f"Could not fetch PES data for {pes_link}")
|
||||||
|
|
||||||
|
pes = PESCompound.create(current_package, pes_data, compound_name, compound_description)
|
||||||
|
|
||||||
|
return redirect(pes.url)
|
||||||
|
else:
|
||||||
|
return BadRequest("Please provide a PES link.")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_pes(request, pes_url) -> dict:
|
def fetch_pes(request, pes_url) -> dict:
|
||||||
@ -19,28 +47,35 @@ def fetch_pes(request, pes_url) -> dict:
|
|||||||
from epauth.views import get_access_token_from_request
|
from epauth.views import get_access_token_from_request
|
||||||
token = get_access_token_from_request(request)
|
token = get_access_token_from_request(request)
|
||||||
|
|
||||||
if token:
|
if token or True:
|
||||||
for k, v in s.PES_API_MAPPING.items():
|
for k, v in s.PES_API_MAPPING.items():
|
||||||
if pes_url.startsWith(k):
|
if pes_url.startswith(k):
|
||||||
pes_id = pes_url.split('/')[-1]
|
pes_id = pes_url.split('/')[-1]
|
||||||
headers = {"Authorization": f"Bearer {token['access_token']}"}
|
|
||||||
params = {"pes_reg_entity_corporate_id": pes_id}
|
|
||||||
|
|
||||||
res = requests.get(v, headers=headers, params=params, proxies=proxies)
|
if pes_id == 'dummy' or True:
|
||||||
|
import json
|
||||||
try:
|
res_data = json.load(open(s.BASE_DIR / "fixtures/pes.json"))
|
||||||
res.raise_for_status()
|
|
||||||
pes_data = res.json()
|
|
||||||
|
|
||||||
if len(pes_data) == 0:
|
|
||||||
raise ValueError(f"PES with id {pes_id} not found")
|
|
||||||
|
|
||||||
res_data = pes_data[0]
|
|
||||||
res_data["pes_url"] = pes_url
|
res_data["pes_url"] = pes_url
|
||||||
return res_data
|
return res_data
|
||||||
|
else:
|
||||||
|
headers = {"Authorization": f"Bearer {token['access_token']}"}
|
||||||
|
params = {"pes_reg_entity_corporate_id": pes_id}
|
||||||
|
|
||||||
except requests.exceptions.HTTPError as e:
|
res = requests.get(v, headers=headers, params=params, proxies=proxies)
|
||||||
raise ValueError(f"Error fetching PES with id {pes_id}: {e}")
|
|
||||||
|
try:
|
||||||
|
res.raise_for_status()
|
||||||
|
pes_data = res.json()
|
||||||
|
|
||||||
|
if len(pes_data) == 0:
|
||||||
|
raise ValueError(f"PES with id {pes_id} not found")
|
||||||
|
|
||||||
|
res_data = pes_data[0]
|
||||||
|
res_data["pes_url"] = pes_url
|
||||||
|
return res_data
|
||||||
|
|
||||||
|
except requests.exceptions.HTTPError as e:
|
||||||
|
raise ValueError(f"Error fetching PES with id {pes_id}: {e}")
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unknown URL {pes_url}")
|
raise ValueError(f"Unknown URL {pes_url}")
|
||||||
else:
|
else:
|
||||||
@ -52,8 +87,10 @@ def visualize_pes(request):
|
|||||||
|
|
||||||
if pes_link:
|
if pes_link:
|
||||||
pes_data = fetch_pes(request, pes_link)
|
pes_data = fetch_pes(request, pes_link)
|
||||||
print(pes_data)
|
|
||||||
|
|
||||||
return HttpResponse(
|
representations = pes_data.get('representations')
|
||||||
FormatConverter.to_png("c1ccccc1"), content_type="image/png"
|
|
||||||
)
|
for rep in representations:
|
||||||
|
if rep.get('type') == 'color':
|
||||||
|
image_data = base64.b64decode(rep.get('base64').replace("data:image/png;base64,", ""))
|
||||||
|
return HttpResponse(image_data, content_type="image/png")
|
||||||
|
|||||||
@ -1,17 +1,22 @@
|
|||||||
|
import hashlib
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
|
import jwt
|
||||||
|
import requests
|
||||||
|
|
||||||
import nh3
|
import nh3
|
||||||
from django.conf import settings as s
|
from django.conf import settings as s
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.http import HttpResponse, JsonResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from ninja import Field, Form, Query, Router, Schema
|
from ninja import Field, Form, Query, Router, Schema
|
||||||
|
from ninja.errors import HttpError
|
||||||
|
from ninja.security import HttpBearer
|
||||||
from ninja.security import SessionAuth
|
from ninja.security import SessionAuth
|
||||||
|
|
||||||
from utilities.chem import FormatConverter
|
from utilities.chem import FormatConverter
|
||||||
from utilities.misc import PackageExporter
|
from utilities.misc import PackageExporter
|
||||||
|
|
||||||
from .logic import (
|
from .logic import (
|
||||||
EPDBURLParser,
|
EPDBURLParser,
|
||||||
GroupManager,
|
GroupManager,
|
||||||
@ -59,7 +64,46 @@ def _anonymous_or_real(request):
|
|||||||
return get_user_model().objects.get(username="anonymous")
|
return get_user_model().objects.get(username="anonymous")
|
||||||
|
|
||||||
|
|
||||||
router = Router(auth=SessionAuth(csrf=False))
|
def validate_token(token: str) -> dict:
|
||||||
|
TENANT_ID = s.MS_ENTRA_TENANT_ID
|
||||||
|
CLIENT_ID = s.MS_ENTRA_CLIENT_ID
|
||||||
|
|
||||||
|
# Fetch Microsoft's public keys
|
||||||
|
jwks_uri = f"https://login.microsoftonline.com/{TENANT_ID}/discovery/v2.0/keys"
|
||||||
|
jwks = requests.get(jwks_uri).json()
|
||||||
|
|
||||||
|
header = jwt.get_unverified_header(token)
|
||||||
|
|
||||||
|
public_key = jwt.algorithms.RSAAlgorithm.from_jwk(
|
||||||
|
next(k for k in jwks["keys"] if k["kid"] == header["kid"])
|
||||||
|
)
|
||||||
|
|
||||||
|
claims = jwt.decode(
|
||||||
|
token,
|
||||||
|
public_key,
|
||||||
|
algorithms=["RS256"],
|
||||||
|
audience=[CLIENT_ID, f"api://{CLIENT_ID}"],
|
||||||
|
issuer=f"https://sts.windows.net/{TENANT_ID}/",
|
||||||
|
)
|
||||||
|
return claims
|
||||||
|
|
||||||
|
|
||||||
|
class MSBearerTokenAuth(HttpBearer):
|
||||||
|
|
||||||
|
def authenticate(self, request, token):
|
||||||
|
if token is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
claims = validate_token(token)
|
||||||
|
|
||||||
|
if not User.objects.filter(uuid=claims['oid']).exists():
|
||||||
|
return None
|
||||||
|
|
||||||
|
request.user = User.objects.get(uuid=claims['oid'])
|
||||||
|
return request.user
|
||||||
|
|
||||||
|
|
||||||
|
router = Router(auth=MSBearerTokenAuth())
|
||||||
|
|
||||||
|
|
||||||
class Error(Schema):
|
class Error(Schema):
|
||||||
@ -153,59 +197,6 @@ class SimpleModel(SimpleObject):
|
|||||||
identifier: str = "relative-reasoning"
|
identifier: str = "relative-reasoning"
|
||||||
|
|
||||||
|
|
||||||
################
|
|
||||||
# Login/Logout #
|
|
||||||
################
|
|
||||||
@router.post("/", response={200: SimpleUser, 403: Error}, auth=None)
|
|
||||||
def login(request, loginusername: Form[str], loginpassword: Form[str]):
|
|
||||||
from django.contrib.auth import authenticate, login
|
|
||||||
|
|
||||||
if request.headers.get("Authorization"):
|
|
||||||
import jwt
|
|
||||||
import requests
|
|
||||||
|
|
||||||
TENANT_ID = s.MS_ENTRA_TENANT_ID
|
|
||||||
CLIENT_ID = s.MS_ENTRA_CLIENT_ID
|
|
||||||
|
|
||||||
def validate_token(token: str) -> dict:
|
|
||||||
# Fetch Microsoft's public keys
|
|
||||||
jwks_uri = f"https://login.microsoftonline.com/{TENANT_ID}/discovery/v2.0/keys"
|
|
||||||
jwks = requests.get(jwks_uri).json()
|
|
||||||
|
|
||||||
header = jwt.get_unverified_header(token)
|
|
||||||
|
|
||||||
public_key = jwt.algorithms.RSAAlgorithm.from_jwk(
|
|
||||||
next(k for k in jwks["keys"] if k["kid"] == header["kid"])
|
|
||||||
)
|
|
||||||
|
|
||||||
claims = jwt.decode(
|
|
||||||
token,
|
|
||||||
public_key,
|
|
||||||
algorithms=["RS256"],
|
|
||||||
audience=[CLIENT_ID, f"api://{CLIENT_ID}"],
|
|
||||||
issuer=f"https://sts.windows.net/{TENANT_ID}/",
|
|
||||||
)
|
|
||||||
return claims
|
|
||||||
|
|
||||||
token = request.headers.get("Authorization").split(" ")[1]
|
|
||||||
|
|
||||||
claims = validate_token(token)
|
|
||||||
|
|
||||||
if not User.objects.filter(uuid=claims['oid']).exists():
|
|
||||||
user = None
|
|
||||||
else:
|
|
||||||
user = User.objects.get(uuid=claims['oid'])
|
|
||||||
|
|
||||||
else:
|
|
||||||
email = User.objects.get(username=loginusername).email
|
|
||||||
user = authenticate(username=email, password=loginpassword)
|
|
||||||
|
|
||||||
if user:
|
|
||||||
login(request, user)
|
|
||||||
return user
|
|
||||||
else:
|
|
||||||
return 403, {"message": "Invalid username and/or password"}
|
|
||||||
|
|
||||||
|
|
||||||
########
|
########
|
||||||
# User #
|
# User #
|
||||||
|
|||||||
@ -627,6 +627,25 @@ class PackageManager(object):
|
|||||||
else:
|
else:
|
||||||
pack.reviewed = False
|
pack.reviewed = False
|
||||||
|
|
||||||
|
# EDIT START
|
||||||
|
if data.get("classification"):
|
||||||
|
if data["classification"] == "INTERNAL":
|
||||||
|
pack.classification = Package.Classification.RESTRICTED
|
||||||
|
elif data["classification"] == "RESTRICTED":
|
||||||
|
pack.classification = Package.Classification.RESTRICTED
|
||||||
|
elif data["classification"] == "SECRET":
|
||||||
|
pack.classification = Package.Classification.SECRET
|
||||||
|
|
||||||
|
if not "datapool" in data:
|
||||||
|
raise ValueError("Missing datapool in package")
|
||||||
|
|
||||||
|
g = Group.objects.get(uuid=data["datapool"].split('/')[-1])
|
||||||
|
pack.data_pool = g
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Invalid classification {data['classification']}")
|
||||||
|
|
||||||
|
# EDIT END
|
||||||
|
|
||||||
pack.description = data["description"]
|
pack.description = data["description"]
|
||||||
pack.save()
|
pack.save()
|
||||||
|
|
||||||
@ -712,7 +731,13 @@ class PackageManager(object):
|
|||||||
default_structure = None
|
default_structure = None
|
||||||
|
|
||||||
for structure in compound["structures"]:
|
for structure in compound["structures"]:
|
||||||
struc = CompoundStructure()
|
if structure.get("pesLink"):
|
||||||
|
from bayer.models import PESStructure
|
||||||
|
struc = PESStructure()
|
||||||
|
struc.pes_link = structure["pesLink"]
|
||||||
|
else:
|
||||||
|
struc = CompoundStructure()
|
||||||
|
|
||||||
# struc.object_url = Command.get_id(structure, keep_ids)
|
# struc.object_url = Command.get_id(structure, keep_ids)
|
||||||
struc.compound = comp
|
struc.compound = comp
|
||||||
struc.uuid = UUID(structure["id"].split("/")[-1]) if keep_ids else uuid4()
|
struc.uuid = UUID(structure["id"].split("/")[-1]) if keep_ids else uuid4()
|
||||||
@ -720,6 +745,10 @@ class PackageManager(object):
|
|||||||
struc.description = structure["description"]
|
struc.description = structure["description"]
|
||||||
struc.aliases = structure.get("aliases", [])
|
struc.aliases = structure.get("aliases", [])
|
||||||
struc.smiles = structure["smiles"]
|
struc.smiles = structure["smiles"]
|
||||||
|
|
||||||
|
if structure.get("molfile"):
|
||||||
|
struc.molfile = structure["molfile"]
|
||||||
|
|
||||||
struc.save()
|
struc.save()
|
||||||
|
|
||||||
for scen in structure["scenarios"]:
|
for scen in structure["scenarios"]:
|
||||||
|
|||||||
@ -1113,6 +1113,7 @@ class CompoundStructure(
|
|||||||
canonical_smiles = models.TextField(blank=False, null=False, verbose_name="Canonical SMILES")
|
canonical_smiles = models.TextField(blank=False, null=False, verbose_name="Canonical SMILES")
|
||||||
inchikey = models.TextField(max_length=27, blank=False, null=False, verbose_name="InChIKey")
|
inchikey = models.TextField(max_length=27, blank=False, null=False, verbose_name="InChIKey")
|
||||||
normalized_structure = models.BooleanField(null=False, blank=False, default=False)
|
normalized_structure = models.BooleanField(null=False, blank=False, default=False)
|
||||||
|
molfile = models.TextField(blank=True, null=True, verbose_name="Molfile")
|
||||||
|
|
||||||
external_identifiers = GenericRelation("ExternalIdentifier")
|
external_identifiers = GenericRelation("ExternalIdentifier")
|
||||||
|
|
||||||
@ -1209,6 +1210,9 @@ class CompoundStructure(
|
|||||||
|
|
||||||
return dict(hls)
|
return dict(hls)
|
||||||
|
|
||||||
|
def d3_json(self):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class EnzymeLink(EnviPathModel, KEGGIdentifierMixin):
|
class EnzymeLink(EnviPathModel, KEGGIdentifierMixin):
|
||||||
rule = models.ForeignKey("Rule", on_delete=models.CASCADE, db_index=True)
|
rule = models.ForeignKey("Rule", on_delete=models.CASCADE, db_index=True)
|
||||||
@ -2215,7 +2219,9 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin, AdditionalInformationMixin)
|
|||||||
if isinstance(ai.get(), PropertyPrediction):
|
if isinstance(ai.get(), PropertyPrediction):
|
||||||
predicted_properties[ai.get().__class__.__name__].append(ai.data)
|
predicted_properties[ai.get().__class__.__name__].append(ai.data)
|
||||||
|
|
||||||
return {
|
extra_structure_data = self.default_node_label.d3_json()
|
||||||
|
|
||||||
|
res = {
|
||||||
"depth": self.depth,
|
"depth": self.depth,
|
||||||
"stereo_removed": self.stereo_removed,
|
"stereo_removed": self.stereo_removed,
|
||||||
"url": self.url,
|
"url": self.url,
|
||||||
@ -2224,6 +2230,7 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin, AdditionalInformationMixin)
|
|||||||
"image_svg": IndigoUtils.mol_to_svg(
|
"image_svg": IndigoUtils.mol_to_svg(
|
||||||
self.default_node_label.smiles, width=40, height=40
|
self.default_node_label.smiles, width=40, height=40
|
||||||
),
|
),
|
||||||
|
|
||||||
"name": self.get_name(),
|
"name": self.get_name(),
|
||||||
"smiles": self.default_node_label.smiles,
|
"smiles": self.default_node_label.smiles,
|
||||||
"scenarios": [{"name": s.get_name(), "url": s.url} for s in self.scenarios.all()],
|
"scenarios": [{"name": s.get_name(), "url": s.url} for s in self.scenarios.all()],
|
||||||
@ -2238,6 +2245,9 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin, AdditionalInformationMixin)
|
|||||||
"timeseries": self.get_timeseries_data(),
|
"timeseries": self.get_timeseries_data(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.update(**extra_structure_data)
|
||||||
|
return res
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def create(
|
def create(
|
||||||
|
|||||||
@ -637,44 +637,54 @@ function draw(pathway, elem) {
|
|||||||
node.filter(d => !d.pseudo).each(function (d, i) {
|
node.filter(d => !d.pseudo).each(function (d, i) {
|
||||||
const g = d3.select(this);
|
const g = d3.select(this);
|
||||||
|
|
||||||
// Parse the SVG string
|
if (d.is_pes) {
|
||||||
const parser = new DOMParser();
|
g.append("svg:image")
|
||||||
const svgDoc = parser.parseFromString(d.image_svg, "image/svg+xml");
|
.attr("xlink:href", d.image)
|
||||||
const svgElem = svgDoc.documentElement;
|
.attr("width", 40)
|
||||||
|
.attr("height", 40)
|
||||||
|
.attr("x", -20)
|
||||||
|
.attr("y", -20);
|
||||||
|
} else {
|
||||||
|
// Parse the SVG string
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const svgDoc = parser.parseFromString(d.image_svg, "image/svg+xml");
|
||||||
|
const svgElem = svgDoc.documentElement;
|
||||||
|
|
||||||
// Create a unique prefix per node
|
// Create a unique prefix per node
|
||||||
const prefix = `node-${i}-`;
|
const prefix = `node-${i}-`;
|
||||||
|
|
||||||
// Rename all IDs and fix <use> references
|
// Rename all IDs and fix <use> references
|
||||||
svgElem.querySelectorAll('[id]').forEach(el => {
|
svgElem.querySelectorAll("[id]").forEach(el => {
|
||||||
const oldId = el.id;
|
const oldId = el.id;
|
||||||
const newId = prefix + oldId;
|
const newId = prefix + oldId;
|
||||||
el.id = newId;
|
el.id = newId;
|
||||||
|
|
||||||
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
||||||
// Update <use> elements that reference this old ID
|
// Update <use> elements that reference this old ID
|
||||||
const uses = Array.from(svgElem.querySelectorAll('use')).filter(
|
const uses = Array.from(svgElem.querySelectorAll("use")).filter(
|
||||||
u => u.getAttributeNS(XLINK_NS, 'href') === `#${oldId}`
|
u => u.getAttributeNS(XLINK_NS, "href") === `#${oldId}`
|
||||||
);
|
);
|
||||||
|
|
||||||
uses.forEach(u => {
|
uses.forEach(u => {
|
||||||
u.setAttributeNS(XLINK_NS, 'href', `#${newId}`);
|
u.setAttributeNS(XLINK_NS, "href", `#${newId}`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
g.node().appendChild(svgElem);
|
g.node().appendChild(svgElem);
|
||||||
|
|
||||||
const vb = svgElem.viewBox.baseVal;
|
const vb = svgElem.viewBox.baseVal;
|
||||||
const svgWidth = vb.width || 40;
|
const svgWidth = vb.width || 40;
|
||||||
const svgHeight = vb.height || 40;
|
const svgHeight = vb.height || 40;
|
||||||
|
|
||||||
const scale = (nodeRadius * 2) / Math.max(svgWidth, svgHeight);
|
const scale = (nodeRadius * 2) / Math.max(svgWidth, svgHeight);
|
||||||
|
|
||||||
|
g.select("svg")
|
||||||
|
.attr("width", svgWidth * scale)
|
||||||
|
.attr("height", svgHeight * scale)
|
||||||
|
.attr("x", -svgWidth * scale / 2)
|
||||||
|
.attr("y", -svgHeight * scale / 2);
|
||||||
|
}
|
||||||
|
|
||||||
g.select("svg")
|
|
||||||
.attr("width", svgWidth * scale)
|
|
||||||
.attr("height", svgHeight * scale)
|
|
||||||
.attr("x", -svgWidth * scale / 2)
|
|
||||||
.attr("y", -svgHeight * scale / 2);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// add element to nodes array
|
// add element to nodes array
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{% extends "framework_modern.html" %}
|
{% extends "framework_modern.html" %}
|
||||||
|
{% load envipytags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
@ -82,6 +83,12 @@
|
|||||||
<div class="collapse-content">{{ compound.description }}</div>
|
<div class="collapse-content">{{ compound.description }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% epdb_slot_templates "epdb.objects.compound.viz" as viz_templates %}
|
||||||
|
|
||||||
|
{% for tpl in viz_templates %}
|
||||||
|
{% include tpl %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<!-- Image Representation -->
|
<!-- Image Representation -->
|
||||||
<div class="collapse-arrow bg-base-200 collapse">
|
<div class="collapse-arrow bg-base-200 collapse">
|
||||||
<input type="checkbox" checked />
|
<input type="checkbox" checked />
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{% extends "framework_modern.html" %}
|
{% extends "framework_modern.html" %}
|
||||||
|
{% load envipytags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
@ -50,6 +51,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% epdb_slot_templates "epdb.objects.compound_structure.viz" as viz_templates %}
|
||||||
|
|
||||||
|
{% for tpl in viz_templates %}
|
||||||
|
{% include tpl %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<!-- Image Representation -->
|
<!-- Image Representation -->
|
||||||
<div class="collapse-arrow bg-base-200 collapse">
|
<div class="collapse-arrow bg-base-200 collapse">
|
||||||
<input type="checkbox" checked />
|
<input type="checkbox" checked />
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{% extends "framework_modern.html" %}
|
{% extends "framework_modern.html" %}
|
||||||
|
{% load envipytags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
@ -54,6 +55,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% epdb_slot_templates "epdb.objects.node.viz" as viz_templates %}
|
||||||
|
|
||||||
|
{% for tpl in viz_templates %}
|
||||||
|
{% include tpl %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<!-- Image Representation -->
|
<!-- Image Representation -->
|
||||||
<div class="collapse-arrow bg-base-200 collapse">
|
<div class="collapse-arrow bg-base-200 collapse">
|
||||||
<input type="checkbox" checked />
|
<input type="checkbox" checked />
|
||||||
|
|||||||
Reference in New Issue
Block a user