I have a very simple python script that runs Tanimoto similarity index between a molecule sample and a molecule database:
from openbabel import pybel
def get_similar(targetmol):
results = []
# calculate fingerprints of the sample
targetfp = targetmol.calcfp()
for mol in pybel.readfile("smi", "/path/to/db.smi"):
# calculate fingerprints of the db
fp = mol.calcfp()
# calculate the Tanimoto index via the "|" operator
tan = fp | targetfp
if tan[0] >= 0.8:
results.append(tan)
return results
targetmol = next(pybel.readfile("smi", "/path/to/sample.smi"))
print(get_similar(targetmol))
My goal here is to add this function to a website that I am developing with Django.
Ideally, users will submit their own molecule and receive a list of the most similar ones present in my database on a new page, as an on-click function.
What I need to do here is to let the script use the users's molecule as a sample but, most importantly, I do not know how to deploy this function in the Django framework.
Since I know that this is not a code shop, I simply would love to receive a clear explanation on how to register my function, how to call it as an on-click function and what I have to change in order to let the script use the users's molecule instead of sample.smi.
For reference, I took inspiration from this repo https://github.com/michal-stuglik/django-blastplus but due to my scarce-to-zero knowledge of python and Django, I get lost.
Thank you for the time spent in reading and eventually answering me.
System
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
Django==3.1.13
django-admin==2.0.1
openbabel-wheel==3.1.1.7