Skip to content

Commit

Permalink
V0.21 Refactor and add ligand and target neighbor data. Keep all near…
Browse files Browse the repository at this point in the history
…est residue level interacitons.
  • Loading branch information
jdwestbrook committed Feb 25, 2021
1 parent cc96d22 commit f03b2cc
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 31 deletions.
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
}
25 changes: 11 additions & 14 deletions rcsb/utils/dictionary/DictMethodEntityInstanceHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, **kwargs):
self.__dApi = rP.getResource("Dictionary API instance (pdbx_core)") if rP else None
self.__ccP = rP.getResource("ChemCompProvider instance") if rP else None
self.__rlsP = rP.getResource("RcsbLigandScoreProvider instance") if rP else None
self.__tiP = rP.getResource("TargetInteractionProvider instance") if rP else None
self.__niP = rP.getResource("NeighborInteractionProvider instance") if rP else None
#
logger.debug("Dictionary entity-instance level method helper init")

Expand Down Expand Up @@ -1704,12 +1704,10 @@ def buildInstanceValidationScores(self, dataContainer, catName, **kwargs):
rankD = {}
scoreD = {}
# -- Get existing interactions or calculate on the fly
if False and self.__tiP.hasEntry(entryId):
pass
# intD = self.__tiP.getInteractions(entryId)
# ligandAtomCountD = self.__tiP.getAtomCounts(entryId)
if self.__niP.hasEntry(entryId):
ligandAtomCountD = self.__niP.getAtomCounts(entryId)
intIsBoundD = self.__niP.getLigandNeighborBoundState(entryId)
else:
# intD, ligandAtomCountD = self.__commonU.getNonpolymerInstanceNeighbors(dataContainer)
ligandAtomCountD = self.__commonU.getLigandAtomCountD(dataContainer)
intIsBoundD = self.__commonU.getLigandNeighborBoundState(dataContainer)

Expand Down Expand Up @@ -1877,10 +1875,9 @@ def buildInstanceTargetNeighbors(self, dataContainer, catName, **kwargs):
asymIdD = self.__commonU.getInstanceEntityMap(dataContainer)
asymAuthIdD = self.__commonU.getAsymAuthIdMap(dataContainer)
# -- Get existing interactions or calculate on the fly
# TODO
if False and self.__tiP.hasEntry(entryId):
# intD = self.__tiP.getInteractions(entryId)
pass
if self.__niP.hasEntry(entryId):
ligandIndexD = self.__niP.getLigandNeighborIndex(entryId)
nearestNeighborL = self.__niP.getNearestNeighborList(entryId)
else:
ligandIndexD = self.__commonU.getLigandNeighborIndex(dataContainer)
nearestNeighborL = self.__commonU.getNearestNeighborList(dataContainer)
Expand Down Expand Up @@ -1954,10 +1951,10 @@ def buildInstanceLigandNeighbors(self, dataContainer, catName, **kwargs):
asymIdD = self.__commonU.getInstanceEntityMap(dataContainer)
asymAuthIdD = self.__commonU.getAsymAuthIdMap(dataContainer)
# -- Get existing interactions or calculate on the fly
# TODO
if False and self.__tiP.hasEntry(entryId):
# intD = self.__tiP.getInteractions(entryId)
pass
#
if self.__niP.hasEntry(entryId):
targetIndexD = self.__niP.getTargetNeighborIndex(entryId)
nearestNeighborL = self.__niP.getNearestNeighborList(entryId)
else:
targetIndexD = self.__commonU.getTargetNeighborIndex(dataContainer)
nearestNeighborL = self.__commonU.getNearestNeighborList(dataContainer)
Expand Down
22 changes: 11 additions & 11 deletions rcsb/utils/dictionary/DictMethodResourceProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from rcsb.utils.dictionary.DictionaryApiProviderWrapper import DictionaryApiProviderWrapper
from rcsb.utils.dictionary.DictMethodCommonUtils import DictMethodCommonUtils
from rcsb.utils.dictionary.TargetInteractionProvider import TargetInteractionProvider
from rcsb.utils.dictionary.NeighborInteractionProvider import NeighborInteractionProvider
from rcsb.utils.chemref.AtcProvider import AtcProvider
from rcsb.utils.chemref.ChemCompModelProvider import ChemCompModelProvider
from rcsb.utils.chemref.ChemCompProvider import ChemCompProvider
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(self, cfgOb, **kwargs):
self.__pcP = None
self.__phP = None
self.__rlsP = None
self.__tiP = None
self.__niP = None
#
#
# self.__wsPattern = re.compile(r"\s+", flags=re.UNICODE | re.MULTILINE)
Expand All @@ -125,7 +125,7 @@ def __init__(self, cfgOb, **kwargs):
"PubChemProvider instance": self.__fetchPubChemProvider,
"PharosProvider instance": self.__fetchPharosProvider,
"RcsbLigandScoreProvider instance": self.__fetchRcsbLigandScoreProvider,
"TargetInteractionProvider instance": self.__fetchTargetInteractionProvider,
"NeighborInteractionProvider instance": self.__fetchNeighborInteractionProvider,
}
logger.debug("Dictionary resource provider init completed")
#
Expand Down Expand Up @@ -396,19 +396,19 @@ def __fetchRcsbLigandScoreProvider(self, cfgOb, configName, cachePath, useCache=
self.__rlsP = RcsbLigandScoreProvider(cachePath=cachePath, useCache=useCache)
return self.__rlsP

def __fetchTargetInteractionProvider(self, cfgOb, configName, cachePath, useCache=True, **kwargs):
def __fetchNeighborInteractionProvider(self, cfgOb, configName, cachePath, useCache=True, **kwargs):
logger.debug("configName %s cachePath %s kwargs %r", configName, cachePath, kwargs)
if not self.__tiP:
if not self.__niP:
# --
try:
minCount = 10
tiP = TargetInteractionProvider(cfgOb, configName, cachePath=cachePath, useCache=useCache)
ok = tiP.fromStash()
ok = tiP.reload()
ok = tiP.testCache(minCount=minCount)
niP = NeighborInteractionProvider(cfgOb, configName, cachePath=cachePath, useCache=useCache)
ok = niP.fromStash()
ok = niP.reload()
ok = niP.testCache(minCount=minCount)
if ok:
self.__tiP = tiP
self.__niP = niP
except Exception as e:
logger.warning("Failing with %s", str(e))
#
return self.__tiP
return self.__niP
38 changes: 34 additions & 4 deletions rcsb/utils/dictionary/NeighborInteractionProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,37 @@ def getTargetNeighborIndex(self, entryId):
pass
return {}

def getNearestNeighborList(self, entryId):
"""Return the list of neares neighbors for the entry.
Args:
entryId (str): entry identifier
Returns:
list: [LigandTargetInstance(), ...]
"""
try:
return self.__neighborD["entries"][entryId.upper()]["nearestNeighbors"]
except Exception:
pass
return []

def getLigandNeighborBoundState(self, entryId):
"""Return the dicitonary of ligand instances with isBound boolean status.
Args:
entryId (str): entry identifier
Returns:
(dict): {ligandAsymId: True if isBound, ... }
"""
try:
return self.__neighborD["entries"][entryId.upper()]["ligandIsBoundD"]
except Exception:
pass
return {}

def getAtomCounts(self, entryId):
"""Return the non-polymer instance occupancy weighted atome counts for the input entry.
Expand Down Expand Up @@ -222,8 +253,7 @@ def __reload(self, fmt="pickle", useCache=True):
#
if useCache and self.__mU.exists(targetFilePath):
neighborD = self.__mU.doImport(targetFilePath, fmt=fmt)
# TODO
if True or fmt != "pickle":
if fmt != "pickle":
for _, nD in neighborD["entries"].items():
nD["nearestNeighbors"] = [LigandTargetInstance(*neighbor) for neighbor in nD["nearestNeighbors"]]
except Exception as e:
Expand Down Expand Up @@ -305,7 +335,7 @@ def __toStash(self, url, stashRemoteDirPath, userName=None, password=None, remot
"""
ok = False
try:
stU = StashUtil(os.path.join(self.__dirPath, "stash"), "nonpolymer-target-interactions")
stU = StashUtil(os.path.join(self.__dirPath, "stash"), "ligand-target-neighbors")
ok = stU.makeBundle(self.__dirPath, [self.__stashDir])
if ok:
ok = stU.storeBundle(url, stashRemoteDirPath, remoteStashPrefix=remoteStashPrefix, userName=userName, password=password)
Expand Down Expand Up @@ -349,7 +379,7 @@ def __fromStash(self, url, stashRemoteDirPath, userName=None, password=None, rem
"""
ok = False
try:
stU = StashUtil(os.path.join(self.__dirPath, "stash"), "nonpolymer-target-interactions")
stU = StashUtil(os.path.join(self.__dirPath, "stash"), "ligand-target-neighbors")
ok = stU.fetchBundle(self.__dirPath, url, stashRemoteDirPath, remoteStashPrefix=remoteStashPrefix, userName=userName, password=password)
except Exception as e:
logger.error("Failing with url %r stashDirPath %r: %s", url, stashRemoteDirPath, str(e))
Expand Down
4 changes: 2 additions & 2 deletions rcsb/utils/tests-dictionary/testDictMethodRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def __runContentType(self, contentType, mockLength, mergeContent):
self.assertGreaterEqual(len(locatorObjList), mockLength)
for container in containerList:
cName = container.getName()
# if cName not in ["6TTM"]:
# continue
if cName not in ["6TTM"]:
continue
logger.debug("Processing container %s", cName)
dmh.apply(container)
savePath = os.path.join(HERE, "test-output", cName + "-with-method.cif")
Expand Down

0 comments on commit f03b2cc

Please sign in to comment.