-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added _getCovalentBondContentOp() and _updateCovalentBondContentOp()
- Loading branch information
Ezra Peisach
committed
Jan 23, 2024
1 parent
c88f3db
commit 9f0d3a2
Showing
6 changed files
with
334 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
__author__ = "Ezra Peisach" | ||
__email__ = "[email protected]" | ||
__license__ = "Apache 2.0" | ||
__version__ = "0.36" | ||
__version__ = "0.37" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] + ' <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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
# |
Oops, something went wrong.