def alignsg(sele): allsg = cmd.get_model("(("+sele+") and (name VSG))").atom allsf = cmd.get_model("(("+sele+") and (name S5,S6,S7,S8))").atom while allsg: closest = [9e9,None,None] for sga in allsg: for sfa in allsf: sg = Vec(sga.coord) sf = Vec(sfa.coord) if (sg-sf).length() < closest[0]: closest = [(sg-sf).length(),sga,sfa] sga,sfa = closest[1:] allsg.remove(sga) allsf.remove(sfa) if closest[0] > 10.0: break cmd.do("alter_state 1, (("+sele+") and (resi %s and name %s))"%(sga.resi,sga.name)+",x=%f"%sfa.coord[0]) cmd.do("alter_state 1, (("+sele+") and (resi %s and name %s))"%(sga.resi,sga.name)+",y=%f"%sfa.coord[1]) cmd.do("alter_state 1, (("+sele+") and (resi %s and name %s))"%(sga.resi,sga.name)+",z=%f"%sfa.coord[2])
def alignsg(sele): allsg = cmd.get_model("((" + sele + ") and (name VSG))").atom allsf = cmd.get_model("((" + sele + ") and (name S5,S6,S7,S8))").atom while allsg: closest = [9e9, None, None] for sga in allsg: for sfa in allsf: sg = Vec(sga.coord) sf = Vec(sfa.coord) if (sg - sf).length() < closest[0]: closest = [(sg - sf).length(), sga, sfa] sga, sfa = closest[1:] allsg.remove(sga) allsf.remove(sfa) if closest[0] > 10.0: break cmd.do("alter_state 1, ((" + sele + ") and (resi %s and name %s))" % (sga.resi, sga.name) + ",x=%f" % sfa.coord[0]) cmd.do("alter_state 1, ((" + sele + ") and (resi %s and name %s))" % (sga.resi, sga.name) + ",y=%f" % sfa.coord[1]) cmd.do("alter_state 1, ((" + sele + ") and (resi %s and name %s))" % (sga.resi, sga.name) + ",z=%f" % sfa.coord[2])
def set_rotamer(sel, chi1, chi2=0,chi3=0,chi4=0): at = cmd.get_model("byres ("+sel+")").atom[0] list = [chi1,chi2,chi3,chi4] for i in range(len(CHIS[at.resn])): print "Setting Chi"+str(i+1)+" to "+str(list[i]) editing.set_dihedral(sel + ' and name '+CHIS[at.resn][i][0], sel + ' and name '+CHIS[at.resn][i][1], sel + ' and name '+CHIS[at.resn][i][2], sel + ' and name '+CHIS[at.resn][i][3], str(list[i])) # Remove some objects that got created cmd.delete("pk1") cmd.delete("pk2") cmd.delete("pkmol")
def createAtomAlongBond(modelName, distance, resiA, atomNameA, resiB, atomNameB, atomNameC): model = cmd.get_model(modelName) p1 = getAtomCoords(model, str(resiA), atomNameA) p2 = getAtomCoords(model, str(resiB), atomNameB) if p1 is None: print "atom not found!", modelName, resiA, atomNameA elif p2 is None: print "atom not found!", modelName, resiB, atomNameB else: p3 = calculateNewPoint(p1, p2, distance) # the details of the new atom atomDetails = {} atomDetails['residueName'] = "HOH" atomDetails['residueNumber'] = "1" atomDetails['symbol'] = "O" atomDetails['name'] = atomNameC atomDetails['coords'] = p3 # make an atom with index n+1 and chain "X" newAtom = makeAtom(model.nAtom + 1, atomDetails, "X") model.add_atom(newAtom) model.update_index() cmd.load_model(model, "newpeptide")
def createRotamerPDBs(sel,ncutoff=10,pcutoff=0,prefix="ROTAMER"): # Get atoms from selection atoms = cmd.get_model("byres ("+sel+")") # Set up some variables.. residues = ['dummy'] # Keep track of residues already done # Loop through atoms in selection for at in atoms.atom: if at.resn in ('GLY','ALA') or "%s:%s:%s" % (at.chain,at.resn,at.resi) in residues: continue # Add to residue list (keep track of which ones we've done) residues.append("%s:%s:%s" % (at.chain,at.resn,at.resi)) # Check for a null chain id (some PDBs contain this) unit_select = "" if not at.chain == "": unit_select = "chain "+str(at.chain)+" and " # Define selections for residue residue_def = unit_select+'resi '+str(at.resi) # Get bin (phi,psi) definitions for this residue bin = doRotamers(residue_def, type='bins') # Store crystal angle crystal_angles = [0.0,0.0,0.0,0.0] for angle in range(3): try: crystal_angles[angle] = bin[3][angle] except IndexError: break # Retreive list of rotamers for this phi,psi bin + residue type match_rotamers = rotdat["%s:%s:%s" % (bin[0],str(bin[1]),str(bin[2]))] count = 0 for item in range(len(match_rotamers)): # Store probablity prob = match_rotamers[item][0] # Check cutoffs if float(prob) <= float(pcutoff): continue if float(count) >= float(ncutoff): break # Increment count count += 1 # Output to screen ... print "Residue %s%s, rotamer %i, prob %s" % (str(at.resn),str(at.resi),int(item),str(prob)) # Set to new rotamer set_rotamer(residue_def,match_rotamers[item][1],match_rotamers[item][2],match_rotamers[item][3],match_rotamers[item][4]) # Store in PDB file cmd.save("%s_%s%s_%i_%s.pdb" % (prefix,str(at.resn),str(at.resi),int(item),str(prob))) # Reset crystal angle set_rotamer(residue_def,crystal_angles[0],crystal_angles[1],crystal_angles[2],crystal_angles[3])
def doRotamers(sel,angles=[], type="color"): # Read in Rotamer library if not already done if len(rotdat) == 0: readRotLib() # Set up some variables.. residues = ['dummy'] # Keep track of residues already done probs = [] # probability of each residue conformation phi = 0 # phi,psi angles of current residue psi = 0 # Get atoms from selection atoms = cmd.get_model("byres ("+sel+")") # Loop through atoms in selection for at in atoms.atom: try: # Don't process Glycines or Alanines if not (at.resn == 'GLY' or at.resn == 'ALA'): if at.chain+":"+at.resn+":"+at.resi not in residues: residues.append(at.chain+":"+at.resn+":"+at.resi) # Check for a null chain id (some PDBs contain this) unit_select = "" if at.chain != "": unit_select = "chain "+str(at.chain)+" and " # Define selections for residue i-1, i and i+1 residue_def = unit_select+'resi '+str(at.resi) residue_def_prev = unit_select+'resi '+str(int(at.resi)-1) residue_def_next = unit_select+'resi '+str(int(at.resi)+1) # Compute phi/psi angle phi = cmd.get_dihedral(residue_def_prev+' and name C',residue_def+' and name N',residue_def+' and name CA',residue_def+' and name C') psi = cmd.get_dihedral(residue_def+' and name N',residue_def+' and name CA',residue_def+' and name C',residue_def_next+' and name N') if type == "set": print "Changing "+at.resn+str(at.resi)+" from "+str(phi)+","+str(psi)+" to "+str(angles[0])+","+str(angles[1]) cmd.set_dihedral(residue_def_prev+' and name C',residue_def+' and name N',residue_def+' and name CA',residue_def+' and name C',angles[0]) cmd.set_dihedral(residue_def+' and name N',residue_def+' and name CA',residue_def+' and name C',residue_def_next+' and name N', angles[1]) continue # Find correct 10x10 degree bin phi_digit = abs(int(phi)) - abs(int(phi/10)*10) psi_digit = abs(int(psi)) - abs(int(psi/10)*10) # Remember sign of phi,psi angles phi_sign = 1 if phi < 0: phi_sign = -1 psi_sign = 1 if psi < 0: psi_sign = -1 # Compute phi,psi bins phi_bin = int(math.floor(abs(phi/10))*10*phi_sign) if phi_digit >= 5: phi_bin = int(math.ceil(abs(phi/10))*10*phi_sign) psi_bin = int(math.floor(abs(psi/10))*10*psi_sign) if psi_digit >= 5: psi_bin = int(math.ceil(abs(psi/10))*10*psi_sign) print "Given "+at.resn+":"+at.resi+" PHI,PSI ("+str(phi)+","+str(psi)+") : bin ("+str(phi_bin)+","+str(psi_bin)+")" # Get current chi angle measurements chi = [] for i in range(len(CHIS[at.resn])): chi.append(cmd.get_dihedral(residue_def + ' and name '+CHIS[at.resn][i][0], residue_def + ' and name '+CHIS[at.resn][i][1], residue_def + ' and name '+CHIS[at.resn][i][2], residue_def + ' and name '+CHIS[at.resn][i][3])) print "CHIs: "+str(chi) if type == 'bins': return [at.resn, phi_bin,psi_bin] # Compute probabilities for given chi angles prob = 0 prob_box = 22 for item in range(len(rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)])): print "Rotamer from db: "+str(rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item]) if chi[0]: if chi[0] >= float(rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][1]) - (prob_box/2) and \ chi[0] <= float(rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][1]) + (prob_box/2): if len(chi) == 1: prob = rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][0] break if chi[1] >= float(rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][2]) - (prob_box/2) and \ float(chi[1] <= rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][2]) + (prob_box/2): if len(chi) == 2: prob = rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][0] break if chi[2] >= float(rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][3]) - (prob_box/2) and \ float(chi[2] <= rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][3]) + (prob_box/2): if len(chi) == 3: prob = rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][0] break if chi[3] >= float(rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][4]) - (prob_box/2) and \ float(chi[3] <= rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][4]) + (prob_box/2): prob = rotdat[at.resn+":"+str(phi_bin)+":"+str(psi_bin)][item][0] break print "PROB OF ROTAMER: "+str(prob) print "---------------------------" probs.append([residue_def, prob]) except: # probs.append([residue_def, -1]) print "Exception found" continue # Color according to rotamer probability rot_color(probs)
'cmd.get_names()' , 'cmd.delete("all")' , 'cmd.get_names()' , 'cmd.get_model("nonexistent")' , 'cmd.space("cmyk")', 'cmd.space("unknown")', 'cmd.space("rgb")', 'cmd.space()', ]) cmd.delete("all") cmd.load("dat/pept.pdb") mdl = cmd.get_model("pept") print mdl.__class__ print len(mdl.atom) mdl = cmd.get_model("none") print mdl.__class__ print len(mdl.atom) map( x, [ 'cmd.get_model("nonexistent")', 'cmd.create("test","none",quiet=0)', 'cmd.create("test2","nonexistent")', 'cmd.create("test3","?allowed",quiet=0)', 'cmd.fragment("arg")', 'cmd.fragment("nonexistent")', ])