Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Revilush committed Jan 12, 2024
1 parent a698381 commit 9534f87
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 48 deletions.
23 changes: 23 additions & 0 deletions main/graphutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from rdkit.Chem import Draw
from rdkit.Chem.rdchem import RWMol
from rdkit.Chem.rdchem import GetPeriodicTable
from rdkit.Chem.Draw import MolsToGridImage
from rdkit.Chem.rdFMCS import FindMCS
from rdkit.Chem.Draw import MolToImage
import io

import functools

def convertMolecule(molecule):
Expand Down Expand Up @@ -152,6 +157,24 @@ def nth_smallest_submolecule(n, submolecules, highlights):

return Chem.MolToSmiles(submol), submol_image, annotated_molecule_image

def two_molecules(ms):
ms = ["CCC1CC2C1CN2", "C1CC2C1CC2CF"]
ms = list(map(Chem.MolFromSmiles, ms))

i = Chem.Draw.MolsToGridImage(ms, subImgSize=(1050,1050))
imgByteArr = io.BytesIO()
i.save(imgByteArr, format=i.format)


r = Chem.rdFMCS.FindMCS(ms)
# (i, r)
molCmn = MolToImage(r.queryMol, size=(1020,1020))
imgByteArr2 = io.BytesIO()
molCmn.save(imgByteArr2, format=molCmn.format)

return imgByteArr.getvalue(), imgByteArr2.getvalue()


if __name__ == "__main__":
m = Chem.MolFromSmiles("CC(C)C[C@H](NC(=O)CNC(=O)[C@H](C)NC(=O)[C@H](CC(=O)O)NC(=O)[C@H](CC(=O)O)NC(=O)[C@H](C)NC(=O)[C@@H]1CCCN1C(=O)[C@H](CCCCN)NC(=O)CNC(=O)[C@@H]1CCCN1C(=O)[C@@H]1CCCN1C(=O)[C@@H]1CCCN1C(=O)[C@H](CCC(=O)O)NC(=O)CN)C(=O)N[C@H](C(=O)O)C(C)C")
submol = nth_smallest_submolecule(2, *iterate_submolecules(m))
Expand Down
66 changes: 29 additions & 37 deletions projectApp/templates/projectApp/home.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% extends 'shared/base.html' %}
{% block content %}

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body {
background-color: #d5ebd8;
}
Expand Down Expand Up @@ -44,36 +44,28 @@
background-color: #2980b9;
color: #fff;
}
</style>
<title>Attractive Page with Buttons</title>
</head>
<body>

<div class="container">
<h1 class="text-center">Comparing Subgraphs of Complex Structures</h1>
<br><br>
<h2 class="text-center">How many structures do you want to compare?</h2>
<br>

<div class="row justify-content-center mt-3">
<div class="col-md-6 text-center">

<a href="{% url 'oneMolecule' %}" class="btn btn-custom btn-lg btn-block" value="1">
One structure
</a>
</div>
<div class="col-md-6 text-center">
<a href="{% url 'twoMolecules' %}" class="btn btn-custom btn-lg btn-block" value="2">
Two structures
</a>
</style>
<title>Attractive Page with Buttons</title>
</head>
<body>
<div class="container">
<h1 class="text-center">Comparing Subgraphs of Complex Structures</h1>
<h2 class="text-center">How many structures do you want to compare?</h2>
<div class="row justify-content-center mt-3">
<div class="col-md-6 text-center">
<a href="{% url 'oneMolecule' %}"
class="btn btn-custom btn-lg btn-block"
value="1">One structure</a>
</div>
<div class="col-md-6 text-center">
<a href="{% url 'collectInputTwo' %}"
class="btn btn-custom btn-lg btn-block"
value="2">Two structures</a>
</div>
</div>
</div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

</body>

{% endblock %}
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
{% endblock %}
30 changes: 30 additions & 0 deletions projectApp/templates/projectApp/processedTwo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends 'shared/base.html' %}
{% block content %}
<style>
img {
display: block;
margin-left: auto;
margin-right: auto;
float: left;
}
</style>
<div class="container mt-5">
<h1 class="text-center mb-4">Most Significant Subunit of a Complex Structure</h1>
<h2>Common molecule structure is: {{ molecular_data }}</h2>
</div>
<div class ="container">
<div class="row">
<div class="col">
<img src="data:image/png;base64,{{ mols }}" width="90%">
</div>
<div class="col">
<img src="data:image/png;base64,{{ common_mol }}" width="90%">
</div>
</div>
</div>
<div class="col-md-6 text-center">
<a href="{% url 'twoMolecule' %}"
class="btn btn-custom btn-lg btn-block"
value="Return">Return</a>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
{% block content %}
<div class="container mt-5">
<h1 class="text-center mb-4">Compare Subgraphs of Two Complex Structures</h1>
<form action="{% url 'collectInputTwo' %}" method="post">
<form action="{% url 'twoMolecule' %}" method="post">
{% csrf_token %}

<div class="form-group">
<label for="firstMoleculeInput">Enter your first molecule</label>
<textarea class="form-control" id="firstMoleculeInput" rows="3"></textarea>
<textarea class="form-control" name="firstMoleculeInput" rows="3"></textarea>
</div>

<div class="form-group">
<label for="secondMoleculeInput">Enter your second molecule</label>
<textarea class="form-control" id="secondMoleculeInput" rows="3"></textarea>
<textarea class="form-control" name="secondMoleculeInput" rows="3"></textarea>
</div>

<button class="btn btn-success btn-lg btn-block" type="submit">Compare Now!</button>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion projectApp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
urlpatterns = [
path("", views.home, name="home"),
path("oneMolecule/", views.oneMolecule, name="oneMolecule"),
path("views.twoMolecules/", views.twoMolecules, name="twoMolecules"),
path("twoMolecule/", views.twoMolecule, name="twoMolecule"),
path("collectDataTwo/", views.collectInputTwo, name="collectInputTwo"),
path("processDataOne/", views.processDataOne, name="processDataOne")
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
23 changes: 19 additions & 4 deletions projectApp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,36 @@
from main.graphutils import convertMolecule
from main.graphutils import iterate_submolecules
from main.graphutils import draw_submolecules
from main.graphutils import two_molecules
import base64


def start(request):
return render(request, "projectApp/home.html")

def home(request):
return render(request, "projectApp/home.html")
return render(request, "projectApp/home.html")

def oneMolecule(request):
return render(request, "projectApp/oneMolecule.html")

def twoMolecules(request):
return render(request, "projectApp/twoMolecules.html")
def twoMolecule(request):
mol1 = request.POST.get("firstMoleculeInput")
mol2 = request.POST.get("secondMoleculeInput")
# print(mol1, mol2)
ms = []
ms.append(mol1)
ms.append(mol2)

all_mols = two_molecules(ms)
# print(all_mols)
return render(request, "projectApp/processedTwo.html", {
"mols": base64.b64encode(all_mols[0]).decode(),
"common_mol": base64.b64encode(all_mols[1]).decode(),
})

def collectInputTwo(request):
return render(request, 'projectApp/twoMolecules.html')
return render(request, 'projectApp/twoMolecule.html')

def displayImages(request, mol):
smallest = nth_smallest_submolecule(1, *iterate_submolecules(mol))
Expand Down

0 comments on commit 9534f87

Please sign in to comment.