Skip to content

Commit 0b839d7

Browse files
committed
Check SMI from poseFIle too
1 parent 6e9b6b9 commit 0b839d7

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

autodock/protocols/protocol_encoder_dock_scoring.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828

2929
from pyworkflow.protocol import params
3030

31-
from pwchem.utils import performBatchThreading, findThreadFiles, concatFiles, splitFile, makeSubsets
32-
from pwchem import Plugin as pwchemPlugin
31+
from pwchem.utils import findThreadFiles, concatFiles, splitFile, makeSubsets, insistentRun
3332
from pwchem.constants import RDKIT_DIC
34-
from pwchem.objects import SmallMoleculesLibrary
3533

3634
from autodock import Plugin as autodockPlugin
3735
from autodock.protocols import ProtChemAutodockGPU
@@ -69,7 +67,7 @@ def _defineParams(self, form):
6967
help='Whether to use a SMI library SmallMoleculesLibrary object as input')
7068

7169
group.addParam('inputLibrary', params.PointerParam, pointerClass="SmallMoleculesLibrary",
72-
label='Input library: ', condition='useLibrary',
70+
label='Input library: ', condition='useLibrary', allowsNull=True,
7371
help="Input Small molecules library to predict")
7472
group.addParam('batchSize', params.IntParam, label='Batch size (MB): ', default=100, condition='useLibrary',
7573
expertLevel=params.LEVEL_ADVANCED, help='Batch size for running conplex in batches')
@@ -178,7 +176,7 @@ def trainingStep(self):
178176
args += f'-ef {autodockPlugin.getChemPropFile()} '
179177

180178
modelsPath = os.path.abspath(autodockPlugin.getPluginHome('models'))
181-
pwchemPlugin.runCondaCommand(self, args, GCR_DIC, f'python {scriptName}', cwd=self._getPath())
179+
insistentRun(self, f'python {scriptName}', args, envDic=GCR_DIC, cwd=self._getPath())
182180

183181
shutil.copytree(os.path.abspath(self._getPath(sysName)), os.path.join(modelsPath, sysName), dirs_exist_ok=True)
184182
self.mergeAllSMIFiles(True, gpuIdx)
@@ -195,7 +193,8 @@ def predictionStep(self, i, gpuIdx, inMols=None, inSMIFile=None):
195193
smisFile = self.buildSMIsFile(inMols, writeScores=False, gpuIdx=gpuIdx, it=i)
196194
elif inSMIFile:
197195
smisFile = self.getInputSMIFile(writeScores=False, gpuIdx=gpuIdx, it=i)
198-
os.link(inSMIFile, smisFile)
196+
if not os.path.exists(smisFile):
197+
os.link(inSMIFile, smisFile)
199198

200199
modelsPath = os.path.abspath(autodockPlugin.getPluginHome('models'))
201200
shutil.copytree(os.path.join(modelsPath, sysName), os.path.abspath(self._getPath(sysName)), dirs_exist_ok=True)
@@ -205,7 +204,7 @@ def predictionStep(self, i, gpuIdx, inMols=None, inSMIFile=None):
205204
if self.getEnumText('encoder') == CHEMPROP:
206205
args += f'-ef {autodockPlugin.getChemPropFile()} '
207206

208-
pwchemPlugin.runCondaCommand(self, args, GCR_DIC, f'python {scriptName}', cwd=self._getPath())
207+
insistentRun(self, f'python {scriptName}', args, envDic=GCR_DIC, cwd=self._getPath())
209208

210209
def createOutputStep(self):
211210
for gpuIdx in self.getInputGpuIdxs():
@@ -219,7 +218,8 @@ def createOutputStep(self):
219218
with open(oLibFile, 'w') as f:
220219
for smiName, score in smiScoreDic.items():
221220
if not self.applyFilter.get() or score < self.outThres.get():
222-
f.write(f'{mapDic[smiName]}\t{score}\n')
221+
prevLine = "\t".join(mapDic[smiName].split())
222+
f.write(f'{prevLine}\t{score}\n')
223223

224224
prevHeaders = inLib.getHeaders()
225225
outputLib = inLib.clone()
@@ -326,11 +326,15 @@ def buildSMIsFile(self, dMols, writeScores=True, gpuIdx=0, it=0):
326326
if molFile.endswith('.smi'):
327327
self.writeSMIs(dMols, writeScores, it, origin='file', gpuIdx=gpuIdx)
328328
else:
329-
getFileFunc = 'getPoseFile' if writeScores else 'getFileName'
330-
molFile = getattr(dMols[0], getFileFunc)()
329+
getFileFuncs = ['getPoseFile', 'getFileName']
330+
fileFuncIdx = 0 if writeScores else 1
331+
molFile = getattr(dMols[0], getFileFuncs[fileFuncIdx])()
332+
molFile2 = getattr(dMols[0], getFileFuncs[abs(fileFuncIdx-1)])()
331333

332334
if self.checkHasSMI(molFile):
333335
smiFile, mapFile = self.writeSMIs(dMols, writeScores, it, origin='Meeko', gpuIdx=gpuIdx)
336+
elif self.checkHasSMI(molFile2):
337+
smiFile, mapFile = self.writeSMIs(dMols, not writeScores, it, origin='Meeko', gpuIdx=gpuIdx)
334338
else:
335339
inMolsFile = self.writeInputMolsFile(dMols, writeScores, it, gpuIdx=gpuIdx)
336340
mapFile = self.getMapSMIFile(writeScores, it, gpuIdx=gpuIdx)

0 commit comments

Comments
 (0)