IndexError: pop from empty list
本帖最后由 houcl 于 2022-2-21 09:30 编辑C:\Users\houcl\Downloads>py -2 RING-Viz.py examples/3jqz_edges.txt -pdbFile examples/3jqz.pdb
Exception in thread Thread-1:Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner self.run()
File "C:\Python27\lib\threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs)
File "C:\Python27\lib\site-packages\pymol\__init__.py", line 439, in launch invocation.parse_args(args)
File "C:\Python27\lib\site-packages\pymol\invocation.py", line 427, in parse_args
options.deferred.append("_do_spawn %s"%av.pop())
IndexError: pop from empty list 鬼才晓得,人估计是够呛 空列表不能pop,建议发代码,不然我们也不知道为啥会报这个错误 大马强 发表于 2022-2-21 09:42
空列表不能pop,建议发代码,不然我们也不知道为啥会报这个错误
#!/usr/bin/env python
import sys
import pymol
from pymol.cgo import *
import argparse
def argParser():
# Parser implementation
parser = argparse.ArgumentParser( prog='RING-Viz.py',
description="RING-Viz: Visualize Residue Interaction Networks with Pymol",
epilog="Example 1: python RING-Viz.py examples/3jqz.edges\nExample 2: python RING-Viz.py examples/3jqz.edges -pdbFile examples/3jqz.pdb_modified\n\n",
formatter_class=argparse.RawDescriptionHelpFormatter)
#formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('ringFile', help='The RIN file (edges) generated by RING-2.0')
parser.add_argument('-pdbFile','--pdbFile', help='By default it is automatically fetched')
parser.add_argument('-pdbId','--pdbIdentifier', help='By default it is inferred from the ringFile')
parser.add_argument('-dMin','--distCutOffMin', default=None, type=float, help='Minimum distance threshold')
parser.add_argument('-dMax','--distCutOffMax', default=None, type=float, help='Maximum distance threshold')
parser.add_argument('-deg','--degreeMin', default=None, type=int, help='Minimum node degree')
parser.add_argument('-rMC','--removeMC_MC',action='store_true',default=False,
help='Remove main-chain/main-chain interactions')
parser.add_argument('-ori','--orientation',nargs='*',default=False,
help='Define a list of orientations to visualize')
parser.add_argument('-lw','--lineWidth',default=2.0, type=float,
help='Define interaction line width in pixels')
parser.add_argument('-int','--interaction',nargs='*',default=False,
help='Define a list of interactions to visualize')
parser.add_argument('-n','--nodes',nargs='*',default=False,
help='Consider all contacts involving at least one of the nodes in the list, <chain><position>')
parser.add_argument('-ns','--nodesStrict',action='store_true',default=False,
help='Consider all contacts involving only nodes in the --nodes list (strictly)')
# Initialize the parser object
args=parser.parse_args()
return args
############################################################
# Color map
intTypeMap = {
"IONIC":{"color":"blue","rgb":(0.0,0.0,1.0)},
"SSBOND":{"color":"yellow","rgb":(1.0,1.0,0.0)},
"PIPISTACK":{"color":"orange","rgb":(1.0,0.5,0.0)},
"PICATION":{"color":"red","rgb":(1.0,0.0,0.0)},
"HBOND":{"color":"cyan","rgb":(0.0,1.0,1.0)},
"VDW":{"color":"gray50","rgb":(0.5,0.5,0.5)},
"IAC":{"color":"white","rgb":(1.0,1.0,1.0)}
}
# Get all coordinates
def getCoordinates(pdbName):
model = pymol.cmd.get_model(pdbName, 1)
coords = {}
for at in model.atom:
insetionCode = "_"
resi = at.resi
try:
int(at.resi)
except:
insetionCode = at.resi[-1]
resi = at.resi
atom_id = at.chain + ":" + resi + ":" + insetionCode + ":" + at.resn + ":" + at.name
coords = , at.coord, at.coord]
del model
return coords
def parseEdges(fileName, coords, distCutOffMin = None, distCutOffMax = None, rmMainChain = False, degreeMin = None, nodeList = [], ppOrientList = [], intList = [], nodeListStrict = False):
'''
{
interaction_type : [
(
(chain, position, atom, coordinates),
(chain, position, atom, coordinates)
),
]
}
'''
interactions = {}
degree = {}
missing = []
with open(fileName) as f:
for line in f:
if line:
if line!="#" and not line.startswith("NodeId"):
# Parse one RING edges line
nodeId1,interaction,nodeId2,distance,angle,energy,atom1,atom2,donor,positive,cation,orientation = line.split("\t")
chain1,pos1,i1,res1 = nodeId1.split(":")
chain2,pos2,i2,res2 = nodeId2.split(":")
pos1 = int(pos1)
pos2 = int(pos2)
intType,intSubType = interaction.split(":")
sub1,sub2 = intSubType.split("_")
if orientation:
orientation = orientation.split()
distance = float(distance)
start = True
# Filters
if distCutOffMin:
if (distance <= distCutOffMin):
start = False
if distCutOffMax:
if (distance > distCutOffMax):
start = False
if rmMainChain:
if sub1 == "MC" and sub2 == "MC":
start = False
if ppOrientList:
if orientation not in ppOrientList:
start = False
if intList:
if intType not in intList:
start = False
if start:
coord1 = None
if (atom1.find(","))!=-1:
coord1 =
atom1 = None
else:
coord1 = coords.get(nodeId1 + ":" + atom1)
coord2 = None
if (atom2.find(","))!=-1:
coord2 =
atom2 = None
else:
coord2 = coords.get(nodeId2 + ":" + atom2)
# Assign interaction elements
if coord1 and coord2:
# Pymol selection of the interacting atoms
selection1 = (chain1,pos1,atom1,coord1)
selection2 = (chain2,pos2,atom2,coord2)
# Collect atom pairs
if intType not in interactions:
interactions = []
interactions.append((selection1,selection2))
else:
missingCoords = []
if not coord1:
missingCoords.append((nodeId1,atom1))
if not coord2:
missingCoords.append((nodeId2,atom2))
missing.append((intType,nodeId1,nodeId2,distance,missingCoords))
if degreeMin:
# Calculate node degree
if (chain1,pos1) not in degree:
degree[(chain1,pos1)] = 0
degree[(chain1,pos1)] += 1
if (chain2,pos2) not in degree:
degree[(chain2,pos2)] = 0
degree[(chain2,pos2)] += 1
validNodes = None
# Filter by node degree
if degreeMin:
validNodesDegree = set( >= degreeMin])
validNodes = validNodesDegree
print("No. nodes after filtering by degree >= ",degreeMin,":",len(validNodesDegree))
# Filter by user provided nodes
if nodeList:
validNodesUser = set([(node.strip(),int(node.strip())) for node in nodeList])
if degreeMin:
validNodes.intersection_update(validNodesUser)
else:
validNodes = validNodesUser
print("No. nodes after filtering by the user provided list:",len(validNodes))
# Remove edges
if nodeList or degreeMin:
for intType in interactions:
for i in range(len(interactions)-1,-1,-1):
selection1,selection2 = interactions
if ((selection1,selection1) not in validNodes and (selection2,selection2) not in validNodes) or (nodeListStrict and ((selection1,selection1) not in validNodes or (selection2,selection2) not in validNodes)):
del interactions
if missing:
print ("\nTotal missing connections:",len(missing),"\nFirst 10 missing:\n", "\n".join())
print ("\nInteractions parsed:",[(intType,len(interactions)) for intType in interactions])
return interactions
def drawConnections(interactions,intTypeMap,linewidth):
for interaction in interactions:
if interactions:
# Select involved residues
selName = interaction + "_nodes"
pymol.cmd.select(selName, " or ".join(frozenset(["{}/{}/".format(s,s) for ele in interactions for s in ele])))
pymol.cmd.show( "sticks", interaction + "_nodes")
#pymol.cmd.show( "lines", interaction + "_nodes")
#pymol.cmd.color( intTypeMap["color"], interaction + "_nodes")
objName = interaction + "_edges"
cr,cg,cb = intTypeMap["rgb"]
obj = [ BEGIN, LINES, COLOR, cr, cg, cb ]
for s,t in interactions:
s_coords = s
t_coords = t
obj.append( VERTEX )
obj.append(s_coords )
obj.append(s_coords )
obj.append(s_coords)
obj.append( VERTEX )
obj.append(t_coords)
obj.append(t_coords)
obj.append(t_coords)
obj.append(END)
pymol.cmd.load_cgo( obj, objName )
pymol.cmd.set("cgo_line_width", float(linewidth), objName )
print interaction,"contacts calculated"
#######################################################################
# Main
args = argParser()
if not args.pdbFile:
if not args.pdbIdentifier:
pdbName = args.ringFile.replace("..","").split(".").replace("pdb","").replace("_edges","").replace("\\","/").split("/")[-1]
else:
pdbName = args.pdbIdentifier
pymol.finish_launching()
try:
print("Trying to download:", pdbName)
pymol.cmd.fetch(pdbName, pdbName)
except:
print("Fail to download:",pdbName)
else:
pdbName = args.pdbFile.replace("..","").split(".").replace("pdb","").replace("_edges","").replace("\\","/").split("/")[-1]
pymol.finish_launching()
pymol.cmd.load(args.pdbFile, pdbName)
print("pdbName:", pdbName)
# Remove ambiguous atoms by occupancy values
try:
pymol.cmd.remove(pdbName + " and q<0.5")
except:
print("Fail to remove alternative atoms (by occupancy)")
# Remove water molecules
pymol.cmd.remove("resn hoh")
pymol.cmd.hide( "lines", "all")
pymol.cmd.show( "cartoon", "all")
pymol.cmd.show( "sticks", "hetatm")
#pymol.cmd.spectrum(selection="all")
pymol.util.cbc(selection="all")
pymol.util.cnc(selection="all")
# Parse interaction file
interactions = parseEdges( args.ringFile,
getCoordinates(pdbName),
distCutOffMin = args.distCutOffMin,
distCutOffMax = args.distCutOffMax,
rmMainChain = args.removeMC_MC,
degreeMin = args.degreeMin,
nodeList = args.nodes,
nodeListStrict = args.nodesStrict,
ppOrientList = args.orientation,
intList = args.interaction )
# Draw connections
drawConnections(interactions,intTypeMap,args.lineWidth)
pymol.cmd.orient(pdbName)
页:
[1]