diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2020-09-22 13:28:48 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2020-09-22 13:28:48 +0530 |
commit | 5ad24bfceb8a22a4940c6d076ea3befc928ab1cd (patch) | |
tree | 81883ec4c205da9ebdec51481dbb0d59b40563b8 | |
parent | c00e771b4d4e1eecfe47408556424fb34ca33fc3 (diff) |
Increased Speed by 50%
-rw-r--r-- | app/dock-single.py | 31 | ||||
-rw-r--r-- | app/dock_docker.py | 36 | ||||
-rw-r--r-- | app/scripts/add-pictures.py | 6 | ||||
-rw-r--r-- | app/scripts/get-best.py | 45 | ||||
-rw-r--r-- | app/scripts/get_dock_score.py | 46 | ||||
-rwxr-xr-x | app/scripts/main.sh | 160 | ||||
-rw-r--r-- | app/scripts/makeReport.py | 458 | ||||
-rw-r--r-- | app/scripts/quick-ligand-protein.py | 121 |
8 files changed, 889 insertions, 14 deletions
diff --git a/app/dock-single.py b/app/dock-single.py index e9ef9b2..3526985 100644 --- a/app/dock-single.py +++ b/app/dock-single.py @@ -209,6 +209,23 @@ def email(zipArchive): s.quit() +def CopyContentOfFolder(sauce,destination): + src_files = os.listdir(sauce) + for file_name in src_files: + full_file_name = os.path.join(sauce, file_name) + if os.path.isfile(full_file_name): + copy(full_file_name, destination) + +def RemoveAllFilesMatching(directory,pattern): + print(directory+"/*"+pattern) + FileList = glob.glob(directory+"/*"+pattern) + for FilePath in FileList: + try: + print(FilePath) + os.remove(FilePath) + except: + print("Error in removing misc file") + inPDB = records[2] jobID = records[0] toaddr = records[1] @@ -218,16 +235,17 @@ date = records[6] #pdb_file_name = pdbpath.split('/')[-1] #pdbpath="./6lu7.pdb" -import os +import os,glob cd = os.getcwd() f = os.path.join(cd,"static/uploads") +scripts = os.path.join(cd,"scripts") reportDirectory = os.path.join(f,"reports") modelDirectory = os.path.join(f,"3DModels") #t = os.path.join(f,"receptor",target) #r = os.path.join(f,"ligands",ligand) #c = os.path.join(f,"configs",config) import tempfile -from shutil import make_archive, copyfile +from shutil import make_archive, copyfile,copy import time with tempfile.TemporaryDirectory() as directory: @@ -247,7 +265,11 @@ with tempfile.TemporaryDirectory() as directory: os.system('obabel -:"%s" --gen3d -opdbqt -O%s.pdbqt' % (records[3],records[4])) print("Ligand:",records[4]) print(str(records[4]+".pdbqt")) - os.system("docker run --rm -v ${PWD}:/results -w /results -u $(id -u ${USER}):$(id -g ${USER}) navanchauhan/curie-cli -r %s -l %s -c config.txt -dpi" % (pdbqt,str(records[4]+".pdbqt"))) + CopyContentOfFolder(scripts,directory) + os.system("./main.sh -r %s -l %s -c config.txt -dpi" % (pdbqt,str(records[4]+".pdbqt"))) + #os.system("docker run --rm -v ${PWD}:/results -w /results -u $(id -u ${USER}):$(id -g ${USER}) navanchauhan/curie-cli -r %s -l %s -c config.txt -dpi" % (pdbqt,str(records[4]+".pdbqt"))) + RemoveAllFilesMatching(directory,".py") + RemoveAllFilesMatching(directory,".sh") z = "Curie_Web_Result_"+str(jobID) zi = os.path.join(f,z) make_archive(zi, 'zip', directory) @@ -256,6 +278,7 @@ with tempfile.TemporaryDirectory() as directory: os.system("collada2gltf -i model.dae -o model.gltf") copyfile("model.gltf",os.path.join(modelDirectory,(str(jobID)+".gltf"))) arch = os.popen("uname -m").read() + print("Generating 3D Model") if "x86" in arch: os.system("docker run -it --rm -v $(pwd):/usr/app leon/usd-from-gltf:latest model.gltf model.usdz") elif "aarch64" in arch: @@ -264,8 +287,6 @@ with tempfile.TemporaryDirectory() as directory: copyfile("model.usdz",os.path.join(modelDirectory,(str(jobID)+".usdz"))) except: print("Could not generate USDZ file") - #copy(("Curie_Web_Result_"+str(jobID)),f) email(zi) - #print((str(zi) + ".zip")) mycursor.execute('UPDATE curieweb set done=1 where id="%s"' % (jobID)) mycon.commit()
\ No newline at end of file diff --git a/app/dock_docker.py b/app/dock_docker.py index 712e725..e2da478 100644 --- a/app/dock_docker.py +++ b/app/dock_docker.py @@ -68,6 +68,23 @@ def get3DModel(protein,ligand): cmd.save("model.dae") session.stop() +def CopyContentOfFolder(sauce,destination): + src_files = os.listdir(sauce) + for file_name in src_files: + full_file_name = os.path.join(sauce, file_name) + if os.path.isfile(full_file_name): + copy(full_file_name, destination) + +def RemoveAllFilesMatching(directory,pattern): + print(directory+"/*"+pattern) + FileList = glob.glob(directory+"/*"+pattern) + for FilePath in FileList: + try: + print(FilePath) + os.remove(FilePath) + except: + print("Error in removing misc file") + receptor_name = "protein.pdbqt" ligand_name = "ligand.pdbqt" description = "Curie Web Task" @@ -87,41 +104,43 @@ date = r[8] if r[9] is not None: description = r[9] -import os +import os,glob cd = os.getcwd() f = os.path.join(cd,"static/uploads") reportDirectory = os.path.join(f,"reports") +scripts = os.path.join(cd,"scripts") modelDirectory = os.path.join(f,"3DModels") #t = os.path.join(f,"receptor",target) #r = os.path.join(f,"ligands",ligand) #c = os.path.join(f,"configs",config) print(f) import tempfile -from shutil import make_archive, copyfile +from shutil import make_archive, copyfile,copy with tempfile.TemporaryDirectory() as directory: print('The created temporary directory is %s' % directory) os.chdir(directory) -# copy(t,os.getcwd()) -# copy(r,os.getcwd()) -# copy(c, os.getcwd()) with open(receptor_name,"wb") as file: file.write(targetB) with open(ligand_name,"wb") as file: file.write(ligandB) with open("config.txt","wb") as file: file.write(configB) - os.system("docker run --rm -v ${PWD}:/results -w /results -u $(id -u ${USER}):$(id -g ${USER}) navanchauhan/curie-cli -r %s -l %s -c config.txt -dpi" % (receptor_name,ligand_name)) - #copy("report.pdf",f) + # Legacy Docker Curie-Cli Run + #os.system("docker run --rm -v ${PWD}:/results -w /results -u $(id -u ${USER}):$(id -g ${USER}) navanchauhan/curie-cli -r %s -l %s -c config.txt -dpi" % (receptor_name,ligand_name)) + CopyContentOfFolder(scripts,directory) + os.system("./main.sh -r %s -l %s -c config.txt -dpi" % (receptor_name,ligand_name)) + RemoveAllFilesMatching(directory,".py") + RemoveAllFilesMatching(directory,".sh") z = "Curie_Web_Result_"+str(jobID) zi = os.path.join(f,z) make_archive(zi, 'zip', directory) - #copy(("Curie_Web_Result_"+str(jobID)),f) copyfile("report.pdf",os.path.join(reportDirectory,(str(jobID)+".pdf"))) get3DModel(receptor_name,ligand_name.replace(".pdbqt","_out.pdbqt")) os.system("collada2gltf -i model.dae -o model.gltf") copyfile("model.gltf",os.path.join(modelDirectory,(str(jobID)+".gltf"))) arch = os.popen("uname -m").read() + print("Generating 3D Model") if "x86" in arch: os.system("docker run -it --rm -v $(pwd):/usr/app leon/usd-from-gltf:latest model.gltf model.usdz") elif "aarch64" in arch: @@ -131,6 +150,5 @@ with tempfile.TemporaryDirectory() as directory: except: print("Could not generate USDZ file") email(zi) - #print((str(zi) + ".zip")) mycursor.execute('UPDATE curieweb set done=1 where id="%s"' % (jobID)) mycon.commit() diff --git a/app/scripts/add-pictures.py b/app/scripts/add-pictures.py new file mode 100644 index 0000000..95079f0 --- /dev/null +++ b/app/scripts/add-pictures.py @@ -0,0 +1,6 @@ +print("## Figures", end="\n\n") + +print("![Back View](output-back.png){width=100%}", end="\n\n") +print("![Front View](output-front.png){width=100%}", end="\n\n") +print("![Close Up View of the Back](closeup-back.png){width=100%}", end="\n\n") +print("![Close Up View of the Front](closeup-front.png){width=100%}", end="\n\n")
\ No newline at end of file diff --git a/app/scripts/get-best.py b/app/scripts/get-best.py new file mode 100644 index 0000000..b5f69a8 --- /dev/null +++ b/app/scripts/get-best.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 +import argparse +import pymol2 +import re + +################# +# Configuration # +################# + +version = "1.0" +desc_text = "PyMol Quick Visualtion " + version + +parser = argparse.ArgumentParser(description=desc_text) +parser.add_argument("-p","--protein",help="Path to protein file") +parser.add_argument("-l","--ligand",help="Path to ligand_out file") + +args = parser.parse_args() + +def li(s): + #log.info(s) + None + + +if args.protein == None: + print("Error: Please specify protein file") + exit(1) +if args.ligand == None: + print("Error: Please specify ligand file") + exit(1) + +print("Getting Best ligand from",args.protein,args.ligand) + +protein = args.protein +ligand = args.ligand + +session = pymol2.PyMOL() +session.start() +cmd = session.cmd +cmd.load(protein,'pro') +cmd.load(ligand,'lig') +cmd.split_states('lig') + +#fname = re.sub(r'^.*?/', '', protein.replace(".pdbqt","")) + "-" + re.sub(r'^.*?/', '', ligand.replace(".pdbqt","")) + ".pdb" + +cmd.save("best.pdb","pro lig_0001") diff --git a/app/scripts/get_dock_score.py b/app/scripts/get_dock_score.py new file mode 100644 index 0000000..c8b87d5 --- /dev/null +++ b/app/scripts/get_dock_score.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +import argparse + +parser = argparse.ArgumentParser(description="Get Docking Score") +parser.add_argument("-p","--protein",help="Path to protein file") +parser.add_argument("-l","--ligand",help="Path to ligand_out file") + +args = parser.parse_args() + +if args.protein == None: + print("Error: Please specify protein file") + exit(1) +if args.ligand == None: + print("Error: Please specify ligand file") + exit(1) + + +protein = args.protein +ligand = args.ligand + +from os.path import basename + +print("# " + str(basename(protein)).replace(".pdbqt","") + "-" + str(basename(ligand)).replace("_out.pdbqt",""), end="\n\n") + +from tabulate import tabulate + +file = open(ligand, "r") +lines = file.readlines() +results = [] +i = 1 +for line in lines: + ta = [] + if line.find('REMARK VINA') == 0 and line.split()[3] != "": + l = line.split() + ta.append(i) + ta.append(l[3]) + ta.append(l[4]) + ta.append(l[5]) + i += 1 + if ta != []: + results.append(ta) + +print("## Docking Scores",end="\n\n") +print(tabulate(results,headers=["No.","Affinity","rmsd l.b","rmsd u.b"])) +print("",end="\n\n") diff --git a/app/scripts/main.sh b/app/scripts/main.sh new file mode 100755 index 0000000..b1c789c --- /dev/null +++ b/app/scripts/main.sh @@ -0,0 +1,160 @@ +#!/bin/bash +echo "$(pwd)" +currentVersion="0.9" +protein="false" +ligand="false" +docking="false" +visualisations="false" +interactions="false" +proteinPath="" +ligandPath="" +pdfPath="" +smile="" +name="report" +config="" + +usage() +{ + cat <<EOF +Curie-CLI +Description: OwO. +Usage: curie [flags] or curie [-a] [arg] [-s] [arg] + -d Perform Docking using AutoDock Vina + -p Visualisations using PyMOL + -i Protein-Ligand Interactions using PLIP + -s SMILES Code for Ligand + -n Name for ligand if using the -s option + -r Specify Receptor file path (PDBQT Format Only!) + -l Specify Ligand file path (PDBQT Format Only!) + -c Specify AutoDock Vina Configuration File (TXT Format Only!) + -h Show the help + -v Get the tool version +Examples: + ./main.sh -v + ./main.sh -v +EOF +} + + +while getopts "r:l:s:n:c:vhdip" opt; do + case "$opt" in + \?) echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + h) usage + exit 0 + ;; + v) echo "Version $currentVersion" + exit 0 + ;; + u) + getConfiguredClient || exit 1 + checkInternet || exit 1 + update + exit 0 + ;; + d) + docking="true" + ;; + i) + interactions="true" + ;; + p) + visualisations="true" + ;; + s) + smile="$OPTARG" + ;; + n) + name="$OPTARG" + ;; + r) + proteinPath="$OPTARG" + ;; + l) + ligandPath="$OPTARG" + ;; + c) + config="$OPTARG" + ;; + a) + artist="true" + if [[ "$(echo "$@" | grep -Eo "\-s")" == "-s" ]];then song="true";fi # wont go through both options if arg spaced and not quoted this solves that issue (dont need this but once had bug on system where it was necessary) + if [[ "$(echo "$@" | grep -Eo "\-f")" == "-f" ]];then filePath=$(echo "$@" | grep -Eo "\-f [ a-z A-Z / 0-9 . \ ]*[ -]?" | sed s/-f//g | sed s/-//g | sed s/^" "//g);fi + ;; + #s) + # song="true" + # if [[ "$(echo "$@" | grep -Eo "\-a")" == "-a" ]];then artist="true";fi # wont go through both options if arg spaced and not quoted this solves that issue (dont need this but once had bug on system where it was necessary) + # if [[ "$(echo "$@" | grep -Eo "\-f")" == "-f" ]];then filePath=$(echo "$@" | grep -Eo "\-f [ a-z A-Z / 0-9 . \ ]*[ -]?" | sed s/-f//g | sed s/-//g | sed s/^" "//g);fi + # ;; + :) echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +if [[ $# == "0" ]]; then + usage ## if calling the tool with no flags and args chances are you want to return usage + exit 0 +elif [[ $# == "1" ]]; then + if [[ $1 == "update" ]]; then + getConfiguredClient || exit 1 + checkInternet || exit 1 + update || exit 1 + exit 0 + elif [[ $1 == "help" ]]; then + usage + exit 0 + fi +fi + +if [[ $docking == "true" ]]; then + if [[ $proteinPath != "" ]]; then + if [[ $smile != "" ]] || [[ $ligandPath != "" ]]; then + if [[ $config == "" ]]; then + echo "Configuration File Not Specified!" + exit 1 + else + dockingCheck="true" + fi + else + echo "WTF Only Protein!" + exit 1 + fi + fi +fi + +if [[ $smile != "" ]]; then + if [[ $name == "" ]]; then + name="ligand" + obabel -:"$smile" --gen3d -opdbqt -O$name.pdbqt + ligandPath="$name.pdbqt" + fi +fi + +if [[ $dockingCheck == "true" ]]; then + echo "" + vina --receptor $proteinPath --ligand $ligandPath --config $config +fi + + + +if [[ $interactions == "true" ]]; then + file=$(echo "$ligandPath" | cut -f 1 -d '.') + python3 ./get-best.py -p $proteinPath -l "$(echo $file)_out.pdbqt" + echo "Running PLIP" + plip -f best.pdb -qpxy + echo "Getting Dock Score" + python3 ./get_dock_score.py -l "$(echo $file)_out.pdbqt" -p $proteinPath > report.md + echo "Making partial report" + python3 ./makeReport.py --input . >> report.md + if [[ $visualisations == "true" ]]; then + echo "Creating Visualisations" + python3 ./quick-ligand-protein.py -p $proteinPath -l "$(echo $file)_out.pdbqt" + python3 ./add-pictures.py >> report.md + fi + echo "Generating PDF" + pandoc -V geometry:margin=1in report.md --pdf-engine=xelatex -o $name.pdf +fi + +#echo "$proteinPath and $ligandPath and $docking and $interactions and $visualisations" diff --git a/app/scripts/makeReport.py b/app/scripts/makeReport.py new file mode 100644 index 0000000..4f693ac --- /dev/null +++ b/app/scripts/makeReport.py @@ -0,0 +1,458 @@ +#!/usr/bin/python3 +import argparse + +parser = argparse.ArgumentParser(description="Make Report Helper Script") +parser.add_argument("-i", "--input", help="Path to report folder") + +args = parser.parse_args() + +if args.input == None: + print("Error: Please specify path") + exit(1) + +path = args.input +# path = '/Users/navanchauhan/Desktop/nCOV-19/scripts/pymol/test/' + +import untangle +from tabulate import tabulate + +# import sys +# report = path + "report.md" +# sys.stdout = open(report, 'w') + +from os import listdir +from os.path import isfile, join + +onlyfiles = [f for f in listdir(path) if isfile(join(path, f))] +image = "" +for x in onlyfiles: + if ".png" in x and "UNL" in x: + image = x +import os + +fname = os.path.join(path, "report.xml") + +doc = untangle.parse(fname) + +hi, hb, wb, sb, ps, pc, hab, mc = 0, 0, 0, 0, 0, 0, 0, 0 + +indexForUNL = 0 + +for x in doc.report.bindingsite: + if x.identifiers.longname.cdata == "UNL": + break + else: + indexForUNL += 1 + + +name = doc.report.pdbid.cdata +# print(("# " + (name.replace("_"," ")).replace("PROTEIN","")), end="\n\n") +fallback = 0 + +print("## Visualisation", end="\n\n") +print(f"![]({image})", end="\n\n") + +natural_ligands = [] +showNaturalLigands = True + +try: + for x in range(len(doc.report.bindingsite)): + if doc.report.bindingsite[x]["has_interactions"] == "True" and x != indexForUNL: + natural_ligands.append(x) +except: + fallback == 1 + +if natural_ligands == []: + showNaturalLigands == False + +for ligand in natural_ligands: + print("### Natural Ligand " + str(ligand+1), end="\n\n") + if doc.report.bindingsite[ligand].interactions.hydrophobic_interactions.cdata == "": + print("No Hydrophobic Interactions Found", end="\n\n") + else: + print("#### Hydrophobic Interactions", end="\n\n") + tableBody = [] + tableHeaders = ["No.", "Res.", "AA", "Dist", "Ligand Atom", "Proton Atom"] + i = 1 + for x in doc.report.bindingsite[ + ligand + ].interactions.hydrophobic_interactions.hydrophobic_interaction: + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist.cdata, + x.ligcarbonidx.cdata, + x.protcarbonidx.cdata, + ] + i += 1 + tableBody.append(l) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + if doc.report.bindingsite[ligand].interactions.hydrogen_bonds.cdata == "": + print("No Hydrogen Bonds Found", end="\n\n") + else: + print("## Hydrogen Bonds", end="\n\n") + tableBody = [] + tableHeaders = [ + "No.", + "Res.", + "AA", + "Dist H-A", + "Dist D-A", + "Don Angle", + "Protisdon?", + "Sidechain?", + "D. Atom", + "A. Atom", + ] + i = 1 + for x in doc.report.bindingsite[ + ligand + ].interactions.hydrogen_bonds.hydrogen_bond: + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist_h_a.cdata, + x.dist_d_a.cdata, + x.don_angle.cdata, + x.protisdon.cdata, + x.sidechain.cdata, + ] + l.append((x.donoridx.cdata + "[" + x.donortype.cdata + "]")) + l.append((x.acceptoridx.cdata + "[" + x.acceptortype.cdata + "]")) + i += 1 + tableBody.append(l) + # print(i, x.resnr.cdata, x.restype.cdata, x.dist_h_a.cdata, x.dist_d_a.cdata, x.don_angle.cdata, x.protisdon.cdata, x.sidechain.cdata, (x.donoridx.cdata + "[" + x.donortype.cdata + "]"), (x.acceptoridx.cdata + "[" + x.acceptortype.cdata + "]")) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + +print("## Docked Ligand Interactions", end="\n\n") + +try: + if ( + doc.report.bindingsite[indexForUNL].interactions.hydrophobic_interactions.cdata + == "" + ): + print("No Hydrophobic Interactions Found", end="\n\n") + else: + print("**Hydrophobic Interactions Found**", end="\n\n") + hi = 1 +except AttributeError: + fallback = 1 + +if fallback == 0: + if ( + doc.report.bindingsite[indexForUNL].interactions.hydrophobic_interactions.cdata + == "" + ): + print("No Hydrophobic Interactions Found", end="\n\n") + else: + print("**Hydrophobic Interactions Found**", end="\n\n") + hi = 1 + if doc.report.bindingsite[indexForUNL].interactions.hydrogen_bonds.cdata == "": + print("No Hydrogen Bonds Found", end="\n\n") + else: + print("**Hydrogen Bonds Found**", end="\n\n") + hb = 1 + if doc.report.bindingsite[indexForUNL].interactions.water_bridges.cdata == "": + print("No Water Bridges Found", end="\n\n") + else: + print("**Water Bridges Found**", end="\n\n") + wb = 1 + if doc.report.bindingsite[indexForUNL].interactions.salt_bridges.cdata == "": + print("No Salt Bridges Found", end="\n\n") + else: + print("**Salt Bridges Found**", end="\n\n") + sb = 1 + if doc.report.bindingsite[indexForUNL].interactions.pi_stacks.cdata == "": + print("No Pi Stacks Found", end="\n\n") + else: + print("**Pi Stacks Found**", end="\n\n") + ps = 1 + if ( + doc.report.bindingsite[indexForUNL].interactions.pi_cation_interactions.cdata + == "" + ): + print("No Pi Cation Interactions Found", end="\n\n") + else: + print("**Pi Cation Interactions Found**", end="\n\n") + pc = 1 + if doc.report.bindingsite[indexForUNL].interactions.halogen_bonds.cdata == "": + print("No Halogen Bonds Found", end="\n\n") + else: + print("** Halogen Bonds Found**", end="\n\n") + hab = 1 + if doc.report.bindingsite[indexForUNL].interactions.metal_complexes.cdata == "": + print("No Metal Complexes Found", end="\n\n") + else: + print("**Metal Complexes Found**", end="\n\n") + mc = 1 + +if fallback == 1: + if doc.report.bindingsite.interactions.hydrophobic_interactions.cdata == "": + print("No Hydrophobic Interactions Found", end="\n\n") + else: + print("**Hydrophobic Interactions Found**", end="\n\n") + hi = 1 + if doc.report.bindingsite.interactions.hydrogen_bonds.cdata == "": + print("No Hydrogen Bonds Found", end="\n\n") + else: + print("**Hydrogen Bonds Found**", end="\n\n") + hb = 1 + if doc.report.bindingsite.interactions.water_bridges.cdata == "": + print("No Water Bridges Found", end="\n\n") + else: + print("**Water Bridges Found**", end="\n\n") + wb = 1 + if doc.report.bindingsite.interactions.salt_bridges.cdata == "": + print("No Salt Bridges Found", end="\n\n") + else: + print("**Salt Bridges Found**", end="\n\n") + sb = 1 + if doc.report.bindingsite.interactions.pi_stacks.cdata == "": + print("No Pi Stacks Found", end="\n\n") + else: + print("**Pi Stacks Found**", end="\n\n") + ps = 1 + if doc.report.bindingsite.interactions.pi_cation_interactions.cdata == "": + print("No Pi Cation Interactions Found", end="\n\n") + else: + print("**Pi Cation Interactions Found**", end="\n\n") + pc = 1 + if doc.report.bindingsite.interactions.halogen_bonds.cdata == "": + print("No Halogen Bonds Found", end="\n\n") + else: + print("** Halogen Bonds Found**", end="\n\n") + hab = 1 + if doc.report.bindingsite.interactions.metal_complexes.cdata == "": + print("No Metal Complexes Found", end="\n\n") + else: + print("**Metal Complexes Found**", end="\n\n") + mc = 1 + +if fallback == 0: + if hi == 1: + print("## Hydrophobic Interactions", end="\n\n") + tableBody = [] + tableHeaders = ["No.", "Res.", "AA", "Dist", "Ligand Atom", "Proton Atom"] + i = 1 + for x in doc.report.bindingsite[ + indexForUNL + ].interactions.hydrophobic_interactions.hydrophobic_interaction: + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist.cdata, + x.ligcarbonidx.cdata, + x.protcarbonidx.cdata, + ] + i += 1 + tableBody.append(l) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + + if hb == 1: + print("## Hydrogen Bonds", end="\n\n") + tableBody = [] + tableHeaders = [ + "No.", + "Res.", + "AA", + "Dist H-A", + "Dist D-A", + "Don Angle", + "Protisdon?", + "Sidechain?", + "D. Atom", + "A. Atom", + ] + i = 1 + for x in doc.report.bindingsite[ + indexForUNL + ].interactions.hydrogen_bonds.hydrogen_bond: + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist_h_a.cdata, + x.dist_d_a.cdata, + x.don_angle.cdata, + x.protisdon.cdata, + x.sidechain.cdata, + ] + l.append((x.donoridx.cdata + "[" + x.donortype.cdata + "]")) + l.append((x.acceptoridx.cdata + "[" + x.acceptortype.cdata + "]")) + i += 1 + tableBody.append(l) + # print(i, x.resnr.cdata, x.restype.cdata, x.dist_h_a.cdata, x.dist_d_a.cdata, x.don_angle.cdata, x.protisdon.cdata, x.sidechain.cdata, (x.donoridx.cdata + "[" + x.donortype.cdata + "]"), (x.acceptoridx.cdata + "[" + x.acceptortype.cdata + "]")) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + + if sb == 1: + print("## Salt Bridges", end="\n\n") + tableBody = [] + tableHeaders = [ + "Index", + "Residue", + "AA", + "Distance", + "Protein positive?", + "Ligand Group", + "Ligand Atoms", + ] + i = 1 + for x in doc.report.bindingsite[ + indexForUNL + ].interactions.salt_bridges.salt_bridge: + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist.cdata, + x.protispos.cdata, + x.lig_group.cdata, + ] + atoms = [] + for y in x.lig_idx_list.idx: + atoms.append(y.cdata) + l.append(atoms) + i += 1 + tableBody.append(l) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + + if pc == 1: + print("## Pi Cation Interactions", end="\n\n") + tableBody = [] + tableHeaders = ["Index", "Residue", "AA", "Distance", "Prot charged?", "Atoms"] + i = 1 + for x in doc.report.bindingsite[ + indexForUNL + ].interactions.pi_cation_interactions.pi_cation_interaction: + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist.cdata, + x.offset.cdata, + x.protcharged.cdata, + ] + atoms = [] + for y in x.lig_idx_list.idx: + atoms.append(y.cdata) + l.append(atoms) + i += 1 + tableBody.append(l) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") +elif fallback == 1: + if hi == 1: + print("## Hydrophobic Interactions", end="\n\n") + tableBody = [] + tableHeaders = ["No.", "Res.", "AA", "Dist", "Ligand Atom", "Proton Atom"] + i = 1 + for ( + x + ) in ( + doc.report.bindingsite.interactions.hydrophobic_interactions.hydrophobic_interaction + ): + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist.cdata, + x.ligcarbonidx.cdata, + x.protcarbonidx.cdata, + ] + i += 1 + tableBody.append(l) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + + if hb == 1: + print("## Hydrogen Bonds", end="\n\n") + tableBody = [] + tableHeaders = [ + "No.", + "Res.", + "AA", + "Dist H-A", + "Dist D-A", + "Don Angle", + "Protisdon?", + "Sidechain?", + "D. Atom", + "A. Atom", + ] + i = 1 + for x in doc.report.bindingsite.interactions.hydrogen_bonds.hydrogen_bond: + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist_h_a.cdata, + x.dist_d_a.cdata, + x.don_angle.cdata, + x.protisdon.cdata, + x.sidechain.cdata, + ] + l.append((x.donoridx.cdata + "[" + x.donortype.cdata + "]")) + l.append((x.acceptoridx.cdata + "[" + x.acceptortype.cdata + "]")) + i += 1 + tableBody.append(l) + # print(i, x.resnr.cdata, x.restype.cdata, x.dist_h_a.cdata, x.dist_d_a.cdata, x.don_angle.cdata, x.protisdon.cdata, x.sidechain.cdata, (x.donoridx.cdata + "[" + x.donortype.cdata + "]"), (x.acceptoridx.cdata + "[" + x.acceptortype.cdata + "]")) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + + if sb == 1: + print("## Salt Bridges", end="\n\n") + tableBody = [] + tableHeaders = [ + "Index", + "Residue", + "AA", + "Distance", + "Protein positive?", + "Ligand Group", + "Ligand Atoms", + ] + i = 1 + for x in doc.report.bindingsite.interactions.salt_bridges.salt_bridge: + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist.cdata, + x.protispos.cdata, + x.lig_group.cdata, + ] + atoms = [] + for y in x.lig_idx_list.idx: + atoms.append(y.cdata) + l.append(atoms) + i += 1 + tableBody.append(l) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + + if pc == 1: + print("## Pi Cation Interactions", end="\n\n") + tableBody = [] + tableHeaders = ["Index", "Residue", "AA", "Distance", "Prot charged?", "Atoms"] + i = 1 + for ( + x + ) in ( + doc.report.bindingsite.interactions.pi_cation_interactions.pi_cation_interaction + ): + l = [ + i, + x.resnr.cdata, + x.restype.cdata, + x.dist.cdata, + x.offset.cdata, + x.protcharged.cdata, + ] + atoms = [] + for y in x.lig_idx_list.idx: + atoms.append(y.cdata) + l.append(atoms) + i += 1 + tableBody.append(l) + print(tabulate(tableBody, headers=tableHeaders), end="\n\n") + + diff --git a/app/scripts/quick-ligand-protein.py b/app/scripts/quick-ligand-protein.py new file mode 100644 index 0000000..6ea16c1 --- /dev/null +++ b/app/scripts/quick-ligand-protein.py @@ -0,0 +1,121 @@ +#!/usr/bin/python3 +import argparse + +# import logzero +# import logging +# from logzero import logger as log +import pymol2 +import time + +import os + +print(os.getcwd()) + +################# +# Configuration # +################# + +startTime = time.time() +version = "1.0" +desc_text = "PyMol Quick Visualtion " + version +ligandColor = "red" +# logzero.loglevel(logging.INFO) +height = 1000 +width = 800 +dpi = 300 +ray = 0 + + +m1 = "target" +m2 = "ligand" + +parser = argparse.ArgumentParser(description=desc_text) +parser.add_argument("-p", "--protein", help="Path to protein file") +parser.add_argument("-l", "--ligand", help="Path to ligand_out file") +parser.add_argument("-c", "--color", help="Color for ligand in visualisation") + +args = parser.parse_args() + +if args.protein == None: + print("Error: Please specify protein file") + exit(1) +if args.ligand == None: + print("Error: Please specify ligand file") + exit(1) +if args.color == None: + print("No color was speciifed, using default settings.") + +protein = args.protein +print("Protein: ", protein) +ligand = args.ligand + + +def loadMol(filename, name): + print("Loading " + filename + " as " + name) + cmd.load(filename, name) + + +def changeColor(name, colorName): + print("Changed " + name + "'s color to " + colorName) + cmd.color(colorName, name) + + +def orientEtZoom(): + cmd.orient() + cmd.zoom() + + +def showSurface(name): + cmd.show("surface", name) + + +def surfaceTransparency(amount): + print("Changed surface transparency to " + str(amount * 100) + "%") + cmd.set("transparency", amount) + + +def generatePNG(filename, height=height, width=width, dpi=dpi, ray=ray): + print("Generating " + filename + ".png") + cmd.png(filename, height, width, dpi=dpi, ray=ray) + + +def flipHorizontal(): + cmd.rotate("y", 180) + + +def zoomTo(name): + cmd.zoom(name) + + +def generatePictures(): + generatePNG("output-front") + flipHorizontal() + generatePNG("output-back") + zoomTo(m2) + generatePNG("closeup-back") + orientEtZoom() + flipHorizontal() + zoomTo(m2) + generatePNG("closeup-front") + + +print("Initialising PyMol") +session = pymol2.PyMOL() +print("Starting PyMol Session") +session.start() +cmd = session.cmd + +loadMol(protein, m1) +cmd.remove("resn hoh") # remove water +loadMol(ligand, m2) +changeColor(m1, "grey60") +changeColor(m2, ligandColor) +cmd.color("blue", "hetatm") # color heteroatoms +orientEtZoom() +showSurface(m1) +surfaceTransparency(0.6) + +generatePictures() + +endTime = time.time() +print("Finished Execution in " + str(round((endTime - startTime), 2)) + " seconds.") |