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 readcex(file,*args): # Author: Scott Dixon import os.path standardResidues = ("ALA", "ARG", "ASP", "ASN", "ASX", "CYS", "GLY", "GLU", "GLN", "HIS", "ILE", "LEU", "LYS", "MET", "PHE", "PRO", "SER", "THR", "TYR", "TRP", "VAL", "HID", "HIE") def childprop(tag, tree,_self=cmd): try: p = CEX.selectChildren(tree,tag)[0].value if p[0] == '"': p = p[1:-1] list = map(string.strip,string.split(p,";")) return list except IndexError: return None f = open(file,"r") cs = CEX.CEXstream(f) modelname = os.path.splitext(os.path.basename(file))[0] #get the base filename if len(args) > 0: modelname = args[0] while 1: tree = CEX.readTree(cs) if not tree: break if tree.name == "$MOL": smiles = tree.value confs = CEX.selectChildren(tree,"XYZ") try: name = CEX.selectProperty(tree,"/NAM").value except AttributeError: name = "" anames = childprop("ANAM", tree) atypes = childprop("ATYPE", tree) resnos = childprop("RESNO", tree) resnames = childprop("RESNA", tree) chains = childprop("CHAIN", tree) occups = childprop("OCCUP", tree) bvals = childprop("BVAL", tree) pcharges = childprop("PCHARGE", tree) rads = childprop("RAD", tree) ligsites = childprop("SCORE", tree) clusters = childprop("CLUSTER", tree) parser = CEXpyParser() try: parser.parse(smiles) except CEX.CEXsmilesError, data: print data break parser.model.molecule.title = name for at in parser.model.atom: i = at.index if anames: at.name = anames[i] if resnames: at.resn = resnames[i] if at.resn in standardResidues: at.hetatm = 0 if resnos: at.resi = resnos[i] at.resi_number = int(resnos[i]) if chains: at.chain = chains[i] if bvals: at.b = bvals[i] if occups: at.q = occups[i] if rads: at.vdw = rads[i] if atypes: at.text_type = atypes[i] if pcharges: chg = pcharges[i] if chg == "": chg = 0.0 at.partial_charge = float(chg) if clusters: at.resi = clusters[i] at.resi_number = int(clusters[i]) if ligsites: at.b = ligsites[i] for conf in confs: if conf.value[0] == '"': conf.value = conf.value[1:-1] xyz = map(lambda x:string.split(x,","),string.split(conf.value,";")) for at in parser.model.atom: i = at.index at.coord = [ float(xyz[i][0]), float(xyz[i][1]), float(xyz[i][2]) ] cmd.load_model(parser.model,modelname,discrete=1,finish=0) else: pass
def readcex(file, *args): # Author: Scott Dixon import os.path standardResidues = ("ALA", "ARG", "ASP", "ASN", "ASX", "CYS", "GLY", "GLU", "GLN", "HIS", "ILE", "LEU", "LYS", "MET", "PHE", "PRO", "SER", "THR", "TYR", "TRP", "VAL", "HID", "HIE") def childprop(tag, tree, _self=cmd): try: p = CEX.selectChildren(tree, tag)[0].value if p[0] == '"': p = p[1:-1] list = map(string.strip, string.split(p, ";")) return list except IndexError: return None f = open(file, "r") cs = CEX.CEXstream(f) modelname = os.path.splitext( os.path.basename(file))[0] #get the base filename if len(args) > 0: modelname = args[0] while 1: tree = CEX.readTree(cs) if not tree: break if tree.name == "$MOL": smiles = tree.value confs = CEX.selectChildren(tree, "XYZ") try: name = CEX.selectProperty(tree, "/NAM").value except AttributeError: name = "" anames = childprop("ANAM", tree) atypes = childprop("ATYPE", tree) resnos = childprop("RESNO", tree) resnames = childprop("RESNA", tree) chains = childprop("CHAIN", tree) occups = childprop("OCCUP", tree) bvals = childprop("BVAL", tree) pcharges = childprop("PCHARGE", tree) rads = childprop("RAD", tree) ligsites = childprop("SCORE", tree) clusters = childprop("CLUSTER", tree) parser = CEXpyParser() try: parser.parse(smiles) except CEX.CEXsmilesError, data: print data break parser.model.molecule.title = name for at in parser.model.atom: i = at.index if anames: at.name = anames[i] if resnames: at.resn = resnames[i] if at.resn in standardResidues: at.hetatm = 0 if resnos: at.resi = resnos[i] at.resi_number = int(resnos[i]) if chains: at.chain = chains[i] if bvals: at.b = bvals[i] if occups: at.q = occups[i] if rads: at.vdw = rads[i] if atypes: at.text_type = atypes[i] if pcharges: chg = pcharges[i] if chg == "": chg = 0.0 at.partial_charge = float(chg) if clusters: at.resi = clusters[i] at.resi_number = int(clusters[i]) if ligsites: at.b = ligsites[i] for conf in confs: if conf.value[0] == '"': conf.value = conf.value[1:-1] xyz = map(lambda x: string.split(x, ","), string.split(conf.value, ";")) for at in parser.model.atom: i = at.index at.coord = [ float(xyz[i][0]), float(xyz[i][1]), float(xyz[i][2]) ] cmd.load_model(parser.model, modelname, discrete=1, finish=0) else: pass