|
70 | 70 |
|
71 | 71 |
|
72 | 72 | def findseq(needle, haystack, selName=None, het=0, firstOnly=0): |
73 | | - # set the name of the selection to return. |
74 | | - if selName == None: |
75 | | - rSelName = "foundSeq" + str(random.randint(0, 32000)) |
76 | | - selName = rSelName |
77 | | - elif selName == "sele": |
78 | | - rSelName = "sele" |
79 | | - else: |
80 | | - rSelName = selName |
81 | | - |
82 | | - # input checking |
83 | | - if not checkParams(needle, haystack, selName, het, firstOnly): |
84 | | - print("There was an error with a parameter. Please see") |
85 | | - print("the above error message for how to fix it.") |
86 | | - return None |
87 | | - |
88 | 73 | one_letter = { |
89 | 74 | '00C': 'C', '01W': 'X', '0A0': 'D', '0A1': 'Y', '0A2': 'K', |
90 | 75 | '0A8': 'C', '0AA': 'V', '0AB': 'V', '0AC': 'G', '0AD': 'G', |
@@ -335,43 +320,58 @@ def findseq(needle, haystack, selName=None, het=0, firstOnly=0): |
335 | 320 | 'YG ': 'G', 'YOF': 'Y', 'YRR': 'N', 'YYG': 'G', 'Z ': 'C', |
336 | 321 | 'ZAD': 'A', 'ZAL': 'A', 'ZBC': 'C', 'ZCY': 'C', 'ZDU': 'U', |
337 | 322 | 'ZFB': 'X', 'ZGU': 'G', 'ZHP': 'N', 'ZTH': 'T', 'ZZJ': 'A'} |
338 | | - |
339 | | - # remove hetero atoms (waters/ligands/etc) from consideration? |
340 | | - if het: |
341 | | - cmd.select("__h", "br. " + haystack) |
| 323 | + # set the name of the selection to return. |
| 324 | + if selName == None: |
| 325 | + rSelName = "foundSeq" + str(random.randint(0, 32000)) |
| 326 | + selName = rSelName |
| 327 | + elif selName == "sele": |
| 328 | + rSelName = "sele" |
342 | 329 | else: |
343 | | - cmd.select("__h", "br. " + haystack + " and not het") |
| 330 | + rSelName = selName |
| 331 | + # make an empty selection to which we add residues |
| 332 | + cmd.select(rSelName, 'None') |
| 333 | + for obj in cmd.get_object_list(haystack): |
| 334 | + # input checking |
| 335 | + if not checkParams(needle, haystack, selName, het, firstOnly): |
| 336 | + print("There was an error with a parameter. Please see") |
| 337 | + print("the above error message for how to fix it.") |
| 338 | + return None |
344 | 339 |
|
345 | | - # get the AAs in the haystack |
346 | | - aaDict = {'aaList': []} |
347 | | - cmd.iterate("(name ca) and __h", "aaList.append((resi,resn,chain))", space=aaDict) |
348 | 340 |
|
349 | | - IDs = [x[0] for x in aaDict['aaList']] |
350 | | - AAs = ''.join([one_letter[x[1]] for x in aaDict['aaList']]) |
351 | | - chains = [x[2] for x in aaDict['aaList']] |
| 341 | + # remove hetero atoms (waters/ligands/etc) from consideration? |
| 342 | + if het: |
| 343 | + cmd.select("__h", f"br. {obj} and {haystack}") |
| 344 | + else: |
| 345 | + cmd.select("__h", f"br. {obj} and {haystack} and not het") |
352 | 346 |
|
353 | | - reNeedle = re.compile(needle.upper()) |
354 | | - it = reNeedle.finditer(AAs) |
| 347 | + # get the AAs in the haystack |
| 348 | + aaDict = {'aaList': []} |
| 349 | + cmd.iterate("(name ca) and __h", "aaList.append((resi,resn,chain))", space=aaDict) |
355 | 350 |
|
356 | | - # make an empty selection to which we add residues |
357 | | - cmd.select(rSelName, 'None') |
| 351 | + IDs = [x[0] for x in aaDict['aaList']] |
| 352 | + AAs = ''.join([one_letter[x[1]] for x in aaDict['aaList']]) |
| 353 | + chains = [x[2] for x in aaDict['aaList']] |
358 | 354 |
|
359 | | - for i in it: |
360 | | - (start, stop) = i.span() |
361 | | - # we found some residues, which chains are they from? |
362 | | - i_chains = chains[start:stop] |
363 | | - # are all residues from one chain? |
364 | | - if len(set(i_chains)) != 1: |
365 | | - # now they are not, this match is not really a match, skip it |
366 | | - continue |
367 | | - chain = i_chains[0] |
368 | | - # Only apply chains to selection algebra if there are defined chains. |
369 | | - if chain: |
370 | | - cmd.select(rSelName, rSelName + " or (__h and i. " + '+'.join(IDs[ii] for ii in range(start, stop)) + " and c. " + chain + " )") |
371 | | - else: |
372 | | - cmd.select(rSelName, rSelName + " or (__h and i. " + '+'.join(IDs[ii] for ii in range(start, stop)) + ")") |
373 | | - if int(firstOnly): |
374 | | - break |
| 355 | + reNeedle = re.compile(needle.upper()) |
| 356 | + it = reNeedle.finditer(AAs) |
| 357 | + |
| 358 | + |
| 359 | + for i in it: |
| 360 | + (start, stop) = i.span() |
| 361 | + # we found some residues, which chains are they from? |
| 362 | + i_chains = chains[start:stop] |
| 363 | + # are all residues from one chain? |
| 364 | + if len(set(i_chains)) != 1: |
| 365 | + # now they are not, this match is not really a match, skip it |
| 366 | + continue |
| 367 | + chain = i_chains[0] |
| 368 | + # Only apply chains to selection algebra if there are defined chains. |
| 369 | + if chain: |
| 370 | + cmd.select(rSelName, rSelName + " or (__h and i. " + '+'.join(IDs[ii] for ii in range(start, stop)) + " and c. " + chain + " )") |
| 371 | + else: |
| 372 | + cmd.select(rSelName, rSelName + " or (__h and i. " + '+'.join(IDs[ii] for ii in range(start, stop)) + ")") |
| 373 | + if int(firstOnly): |
| 374 | + break |
375 | 375 | cmd.delete("__h") |
376 | 376 | return rSelName |
377 | 377 | cmd.extend("findseq", findseq) |
|
0 commit comments