Skip to content

Commit

Permalink
added _getCovalentBondContentOp() and _updateCovalentBondContentOp()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezra Peisach committed Jan 23, 2024
1 parent c88f3db commit 9f0d3a2
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 9 deletions.
2 changes: 1 addition & 1 deletion wwpdb/apps/ann_tasks_v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
__author__ = "Ezra Peisach"
__email__ = "[email protected]"
__license__ = "Apache 2.0"
__version__ = "0.36"
__version__ = "0.37"
13 changes: 7 additions & 6 deletions wwpdb/apps/ann_tasks_v2/utils/GetCloseContact.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Update:
##
"""
Manage utility to correct TLS problems
Manage utility to correct close contact problems
"""
__docformat__ = "restructuredtext en"
Expand Down Expand Up @@ -45,7 +45,7 @@ def run(self, entryId, inpFile):
retD["found"] = "no"
try:
inpPath = os.path.join(self.__sessionPath, inpFile)
logPath = os.path.join(self.__sessionPath, entryId + "-close-contact.log")
logPath = os.path.join(self.__sessionPath, entryId + "-get-close-contact.log")
retPath = os.path.join(self.__sessionPath, entryId + "-close-contact.json")
for filePath in (logPath, retPath):
if os.access(filePath, os.R_OK):
Expand Down Expand Up @@ -85,10 +85,11 @@ def __processCloseContactContent(self, jsonObj):
<table class="table table-borderedless width80">
<tr>
<th><input id="close_contact_select_all" class="btn btn-primary my-task-form-submit" value="Select All" type="button"
onClick="select_close_contact('close_contact_select_all', '');" /></th>
onClick="select_close_contact_covalent_bond('update-close-contact-form', 'close_contact_', 'close_contact_select_all', '');" /></th>
%s
<th><input id="close_contact_submit" class="btn btn-primary my-task-form-submit" value="Submit" type="submit" /></th>
<th><input id="close_contact_exit" class="btn btn-primary my-task-form-submit" value="Exit" type="button" onClick="exit_close_contact_page();" /></th>
<th><input id="close_contact_exit" class="btn btn-primary my-task-form-submit" value="Exit" type="button"
onClick="exit_close_contact_covalent_bond_page();" /></th>
</tr>
</table>
<br/>
Expand Down Expand Up @@ -149,8 +150,8 @@ def __processCloseContactContent(self, jsonObj):
select_green_button = ""
if (green_count > 0) and (green_count < len(jsonObj["close_contact"])):
select_green_button = (
'<th><input id="close_contact_select_all_green" class="btn btn-primary my-task-form-submit" value="Select All green" '
+ "type=\"button\" onClick=\"select_close_contact('close_contact_select_all_green', 'green');\" /></th>"
'<th><input id="close_contact_select_all_green" class="btn btn-primary my-task-form-submit" value="Select All green" type="button" '
+ "onClick=\"select_close_contact_covalent_bond('update-close-contact-form', 'close_contact_', 'close_contact_select_all_green', 'green');\" /></th>"
)
#
return htmlTemplate % (str(count), select_green_button, tablerow)
Expand Down
166 changes: 166 additions & 0 deletions wwpdb/apps/ann_tasks_v2/utils/GetCovalentBond.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
##
# File: GetCovalentBond.py
# Date: 28-Sep-2020 Zukang Feng
#
# Update:
##
"""
Manage utility to correct covalent bond problems
"""
__docformat__ = "restructuredtext en"
__author__ = "Zukang Feng"
__email__ = "[email protected]"
__license__ = "Creative Commons Attribution 3.0 Unported"
__version__ = "V0.07"

import json
import os
import sys
import traceback

from wwpdb.utils.dp.RcsbDpUtility import RcsbDpUtility


class GetCovalentBond(object):
"""
GetCovalentBond class encapsulates correcting covalent bond problems.
"""

def __init__(self, reqObj=None, verbose=False, log=sys.stderr):
self.__reqObj = reqObj
self.__verbose = verbose
self.__lfh = log
#
self.__setup()

def __setup(self):
self.__siteId = self.__reqObj.getValue("WWPDB_SITE_ID")
self.__sObj = self.__reqObj.getSessionObj()
self.__sessionPath = self.__sObj.getPath()

def run(self, entryId, inpFile):
"""Run the calculation"""
retD = {}
retD["found"] = "no"
try:
inpPath = os.path.join(self.__sessionPath, inpFile)
logPath = os.path.join(self.__sessionPath, entryId + "-get-covalent-bond.log")
retPath = os.path.join(self.__sessionPath, entryId + "-covalent-bond.json")
for filePath in (logPath, retPath):
if os.access(filePath, os.R_OK):
os.remove(filePath)
#
#
dp = RcsbDpUtility(tmpPath=self.__sessionPath, siteId=self.__siteId, verbose=self.__verbose, log=self.__lfh)
#
dp.imp(inpPath)
dp.op("annot-get-covalent-bond")
dp.expLog(dstPath=logPath, appendMode=False)
dp.exp(retPath)
#
if os.access(retPath, os.R_OK):
with open(retPath) as ifh:
jsonObj = json.load(ifh)
htmlcontent = self.__processCloseContactContent(jsonObj)
if htmlcontent:
retD["htmlcontent"] = htmlcontent
retD["found"] = "yes"
#
#
#
dp.cleanup()
except: # noqa: E722 pylint: disable=bare-except
traceback.print_exc(file=self.__lfh)
#
return retD

def __processCloseContactContent(self, jsonObj):
""" """
if (not jsonObj) or ("covalent_bond" not in jsonObj) or (not jsonObj["covalent_bond"]):
return ""
#
htmlTemplate = """
<input type="hidden" name="total_covalent_bond_num" value="%s" />
<table class="table table-borderedless width80">
<tr>
<th><input id="covalent_bond_select_all" class="btn btn-primary my-task-form-submit" value="Select All" type="button"
onClick="select_close_contact_covalent_bond('update-covalent-bond-form', 'covalent_bond_', 'covalent_bond_select_all', '');" /></th>
<th><input id="covalent_bond_submit" class="btn btn-primary my-task-form-submit" value="Submit" type="submit" /></th>
<th><input id="covalent_bond_exit" class="btn btn-primary my-task-form-submit" value="Exit" type="button"
onClick="exit_close_contact_covalent_bond_page();" /></th>
</tr>
</table>
<br/>
<table class="table table-bordered table-striped width100">
<tr>
<th colspan="5">Atom1</th>
<th colspan="5">Atom2</th>
<th rowspan="2">Distance</th>
</tr>
<tr>
<th>Chain ID</th>
<th>Residue</th>
<th>Number</th>
<th>Atom</th>
<th>Symmetry</th>
<th>Chain ID</th>
<th>Residue</th>
<th>Number</th>
<th>Atom</th>
<th>Symmetry</th>
</tr>
%s
</table>
"""
#
tablerow = ""
count = 0
for tupL in jsonObj["covalent_bond"]:
tablerow += "<tr>"
#
atom = tupL[4]
if tupL[5]:
atom += "(" + tupL[5] + ")"
#
tablerow += "<td>" + tupL[0] + "</td>" + "<td>" + tupL[1] + "</td>" + "<td>" + tupL[2] + tupL[3] + "</td>" + "<td>" + atom + "</td>" + "<td>" + tupL[6] + "</td>"
atom = tupL[11]
if tupL[12]:
atom += "(" + tupL[12] + ")"
#
tablerow += "<td>" + tupL[7] + "</td>" + "<td>" + tupL[8] + "</td>" + "<td>" + tupL[9] + tupL[10] + "</td>" + "<td>" + atom + "</td>" + "<td>" + tupL[13] + "</td>"
#
tupL[6] = tupL[6].replace("_", "-");
tupL[13] = tupL[13].replace("_", "-");
bond_id = "covalent_bond_" + str(count)
#
tablerow += "<td>" + tupL[14] + '&nbsp; &nbsp; &nbsp; &nbsp; <input type="checkbox" id="' + bond_id + '" name="' + bond_id + '" value="' + "_".join(tupL) + '"/></td>'
#
tablerow += "</tr>\n"
count += 1
#
return htmlTemplate % (str(count), tablerow)


def main():
from wwpdb.utils.config.ConfigInfo import ConfigInfo
from wwpdb.utils.session.WebRequest import InputRequest

#
siteId = os.getenv("WWPDB_SITE_ID")
cI = ConfigInfo(siteId)
#
myReqObj = InputRequest({}, verbose=True, log=sys.stderr)
myReqObj.setValue("TopSessionPath", cI.get("SITE_WEB_APPS_TOP_SESSIONS_PATH"))
myReqObj.setValue("TopPath", cI.get("SITE_WEB_APPS_TOP_PATH"))
myReqObj.setValue("WWPDB_SITE_ID", siteId)
myReqObj.setValue("sessionid", "d581f7aa63cc8feba7d96fb9fd103866fca45a7d")
#
calc = GetCovalentBond(reqObj=myReqObj, verbose=True, log=sys.stderr)
retD = calc.run("D_1000001900", "D_1000001900_model_P1.cif")
for k, v in retD.items():
print(k + "=" + v)


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions wwpdb/apps/ann_tasks_v2/utils/UpdateCloseContact.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Update:
##
"""
Manage utility to correct TLS problems
Manage utility to correct close contact problems
"""
__docformat__ = "restructuredtext en"
Expand Down Expand Up @@ -59,7 +59,7 @@ def run(self, entryId, inpFile, closeContactList):
"""Run the calculation"""
try:
inpPath = os.path.join(self.__sessionPath, inpFile)
logPath = os.path.join(self.__sessionPath, entryId + "-close-contact.log")
logPath = os.path.join(self.__sessionPath, entryId + "-update-close-contact.log")
dataPath = os.path.join(self.__sessionPath, entryId + "-close-contact.txt")
for filePath in (logPath, dataPath):
if os.access(filePath, os.R_OK):
Expand Down
95 changes: 95 additions & 0 deletions wwpdb/apps/ann_tasks_v2/utils/UpdateCovalentBond.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
##
# File: UpdateCovalentBond.py
# Date: 22-Jan-2024 Zukang Feng
#
# Update:
##
"""
Manage utility to correct covalent bond problems
"""
__docformat__ = "restructuredtext en"
__author__ = "Zukang Feng"
__email__ = "[email protected]"
__license__ = "Creative Commons Attribution 3.0 Unported"
__version__ = "V0.07"

import sys
import os.path
import os
import traceback

from wwpdb.utils.dp.RcsbDpUtility import RcsbDpUtility
from wwpdb.apps.ann_tasks_v2.utils.SessionWebDownloadUtils import SessionWebDownloadUtils


class UpdateCovalentBond(SessionWebDownloadUtils):
"""
UpdateCovalentBond class encapsulates correcting covalent bond problems.
"""

def __init__(self, reqObj=None, verbose=False, log=sys.stderr):
super(UpdateCovalentBond, self).__init__(reqObj=reqObj, verbose=verbose, log=log)
self.__verbose = verbose
self.__lfh = log
self.__reqObj = reqObj
#
self.__setup()

def __setup(self):
self.__siteId = self.__reqObj.getValue("WWPDB_SITE_ID")
self.__sObj = self.__reqObj.getSessionObj()
self.__sessionPath = self.__sObj.getPath()

def __checkStatus(self, logFilePath):
status = "error"
if os.access(logFilePath, os.R_OK):
ifh = open(logFilePath, "r")
for line in ifh:
if str(line).startswith("Finished!"):
status = "ok"
break
#
#
#
return status

def run(self, entryId, inpFile, closeContactList):
"""Run the calculation"""
try:
inpPath = os.path.join(self.__sessionPath, inpFile)
logPath = os.path.join(self.__sessionPath, entryId + "-update-covalent-bond.log")
dataPath = os.path.join(self.__sessionPath, entryId + "-covalent-bond.txt")
for filePath in (logPath, dataPath):
if os.access(filePath, os.R_OK):
os.remove(filePath)
#
#
ofh = open(dataPath, "w")
for closeContact in closeContactList:
ofh.write("%s\n" % closeContact)
#
ofh.close()
#
status = False
dp = RcsbDpUtility(tmpPath=self.__sessionPath, siteId=self.__siteId, verbose=self.__verbose, log=self.__lfh)
#
dp.imp(inpPath)
dp.addInput(name="datafile", value=dataPath)
dp.op("annot-remove-covalent-bond")
dp.expLog(dstPath=logPath, appendMode=False)
if os.access(logPath, os.R_OK):
self.addDownloadPath(logPath)
if self.__checkStatus(logPath) == "ok":
dp.exp(inpPath)
self.addDownloadPath(inpPath)
status = True
#
#
dp.cleanup()
return status
except: # noqa: E722 pylint: disable=bare-except
traceback.print_exc(file=self.__lfh)
return False
#
Loading

0 comments on commit 9f0d3a2

Please sign in to comment.