def xfer_write_debug(dev, reg_addr, val): cmd = [STLINK_DEBUG_COMMAND, STLINK_DEBUG_APIV2_WRITEDEBUGREG] args = [ord(q) for q in struct.pack("<II", reg_addr, val)] cmd.extend(args) res = xfer_normal_input(dev, cmd, 2) logging.debug("WRITE DEBUG %#x ==> %d (%#08x) (res=%s)", reg_addr, val, val, res) #assert res == # Sometimes this fails: """
def xfer_write32(dev, reg_addr, data): cmd = [STLINK_DEBUG_COMMAND, STLINK_DEBUG_WRITEMEM32] dlen = len(data) * 4 args = [ord(q) for q in struct.pack("<IH", reg_addr, dlen)] cmd.extend(args) xfer_normal_input(dev, cmd, 0) out_data = struct.pack("<%dI" % len(data), *data) xfer_send_only_raw(dev, out_data) logging.debug("WRITEMEM32 %#x/%d ==> %s", reg_addr, dlen, [hex(i) for i in data])
def trace_on(dev, buff=4096, hz=2000000): cmd = [STLINK_DEBUG_COMMAND, STLINK_DEBUG_APIV2_START_TRACE_RX] args = [ord(q) for q in struct.pack("<HI", buff, hz)] cmd.extend(args) # f240001080841e000000000000000000 # This is what windows stlink sends: f2 40 00 10 80 84 1e 00 00 00 00 00 00 00 00 00 # 16 bit trace size = 0x1000 # 32bit hz res = xfer_normal_input(dev, cmd, 2) logging.debug("START TRACE (buffer= %d, hz= %d)", buff, hz)
def xfer_read_debug(dev, reg_addr): cmd = [STLINK_DEBUG_COMMAND, STLINK_DEBUG_APIV2_READDEBUGREG] args = [ord(q) for q in struct.pack("<I", reg_addr)] cmd.extend(args) res = xfer_normal_input(dev, cmd, 8) status, unknown, val = struct.unpack_from("<HHI", lame_py(bytearray(res))) logging.debug("READ DEBUG: %#x ==> %d (%#08x) status=%#x, unknown=%#x", reg_addr, val, val, status, unknown) #assert status == 0x80, "failed to read debug reg?!" # yuck, sometimes status is 0x15 or 0x25 and it shows garbage. not sure what it means though? # do I need to send the sync shit? return val
def xfer_read32(dev, reg_addr, count): """ count is in bytes! """ cmd = [STLINK_DEBUG_COMMAND, STLINK_DEBUG_READMEM32] args = [ord(q) for q in struct.pack("<IH", reg_addr, count)] cmd.extend(args) res = xfer_normal_input(dev, cmd, count) u32s = struct.unpack("<%dI" % (count/4), res) logging.debug("READMEM32 %#x/%d returned: %s", reg_addr, count, [hex(i) for i in u32s]) return u32s
def xfer_read32(dev, reg_addr, count): """ count is in bytes! """ cmd = [STLINK_DEBUG_COMMAND, STLINK_DEBUG_READMEM32] args = [ord(q) for q in struct.pack("<IH", reg_addr, count)] cmd.extend(args) res = xfer_normal_input(dev, cmd, count) u32s = struct.unpack("<%dI" % (count / 4), res) logging.debug("READMEM32 %#x/%d returned: %s", reg_addr, count, [hex(i) for i in u32s]) return u32s
def say(self, phrase): self._logger.debug("Saying '%s' with '%s'", phrase, self.SLUG) with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f: fname = f.name cmd = ['pico2wave', '--wave', fname] if self.language not in self.languages: raise ValueError("Language '%s' not supported by '%s'", self.language, self.SLUG) cmd.extend(['-l', self.language]) cmd.append(phrase) self._logger.debug('Executing %s', ' '.join([pipes.quote(arg) for arg in cmd])) with tempfile.TemporaryFile() as f: subprocess.call(cmd, stdout=f, stderr=f) f.seek(0) output = f.read() if output: self._logger.debug("Output was: '%s'", output) self.play(fname) os.remove(fname)
def say(self, phrase): self._logger.debug("Saying '%s' with '%s'", phrase, self.SLUG) cmd = ['flite'] if self.voice: cmd.extend(['-voice', self.voice]) cmd.extend(['-t', phrase]) with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f: fname = f.name cmd.append(fname) with tempfile.SpooledTemporaryFile() as out_f: self._logger.debug('Executing %s', ' '.join([pipes.quote(arg) for arg in cmd])) subprocess.call(cmd, stdout=out_f, stderr=out_f) out_f.seek(0) output = out_f.read().strip() if output: self._logger.debug("Output was: '%s'", output) self.play(fname) os.remove(fname)
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]) # Uncommenting this is nice because it loads rotamer library upon startup # however, it slows the PyMOL loading process a lot # instead I've put this call into the menuing code.. # readRotLib() cmd.extend('set_phipsi',set_phipsi) cmd.extend('set_rotamer',set_rotamer) cmd.extend('colorRotamers',colorRotamers) cmd.extend('createRotamerPDBs',createRotamerPDBs)
# Provide some useful information stored.allRMSDval = [] stored.allRMSDval = stored.alnAnb + stored.alnBnb print "\nColorByRMSD completed successfully." print "The MINIMUM RMSD value is: "+str(min(stored.allRMSDval)) print "The MAXIMUM RMSD value is: "+str(max(stored.allRMSDval)) if doPretty!=None: # Showcase what we did cmd.orient() cmd.hide("all") cmd.show_as("cartoon", objSel1 + " or " + objSel2) # Select the residues not used for alignment; they still have their B-factors as "-10" cmd.select("notUsedForAln", "b < 0") # White-wash the residues not used for alignment cmd.color("white", "notUsedForAln") # Color the residues used for alignment according to their B-factors (RMSD values) cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln") # Delete the selection of atoms not used for alignment # If you would like to keep this selection intact, # just comment "cmd.delete" line and # uncomment the "cmd.disable" line below. cmd.delete("notUsedForAln") # cmd.disable("notUsedForAln") print "\nObjects are now colored by C-alpha RMS deviation." print "All residues with RMSD values greater than the maximum are colored white..." cmd.extend("colorByRMSD", colorByRMSD)
FileSupport.createLogsFolder() FileSupport.createTmpFolder() # Add the properties # # Default and user defined properties are in a dictionary: # this way it is easy for the user to overrride default properties. props = {} setProps(props, args.className) if args.jProp is not None: addUserProps(props, args.jProp) if len(props) > 0: stingOfPros = formatProps(props) # Sort to enhance readability stingOfPros.sort() cmd.extend(formatProps(props)) if verbose: print "java properties:" for p in stingOfPros: print "\t", p[2:] else: if (verbose): print "No java properties defined" #add the classpath theClasspath = CommonDefs.buildClasspath() if (args.language == 'j' or args.language == 'java'): theClasspath = CommonDefs.addScalaJarsToClassPath(theClasspath) cmd.append("-cp") cmd.append(theClasspath) if verbose:
if len(ntd)==2: ntdList += [((ntd[0][0])+'-'+(ntd[0][1]), ntd_color)] ntdList += [((ntd[1][0])+'-'+(ntd[1][1]), ntd_color)] #print len(ntdList) return ntdList def color_structure(pdb_file): ''' this function colors each nucleotide in pymol >>>print (data[1][0]) 2886_2897 2QBG must match the name of pdb file which is open data[i][1] = color data[i][0] = range of nucleotide data[i][2] = chain ''' url = 'https://raw.githubusercontent.com/hmaryam/pymol/master/%s_coloring_info.csv' % pdb_file response = urllib2.urlopen(url) reader = csv.reader(response, delimiter=",") data = nt_ranges(reader) for i in range(0,len(data)): if (data[i][2]) != '': cmd.color(data[i][1], "%s and resi %s in chain %s" % ( pdb_file, data[i][0], data[i][2])) elif(data[i][2]) == '': cmd.color(data[i][1], "%s and resi %s " % ( pdb_file, data[i][0])) cmd.extend('color', color_structure)
def get_sane_pairing(pairing): l = {} for position in pairing: try: position_n = int(position[0]) except ValueError: position_n = position[0] try: position_l = longer_names[position[1]] except KeyError: print 'Warning: {} not found'.format(position[1]) continue l[position_n] = position_l return l cmd.extend('get_sane_pairing',get_sane_pairing) holder = [] def printer(resi,resn,name): holder.append((resn ,resi)) def get_resi_in_selection(objsel="(all)"): print objsel myspace = {'myfunc':printer} cmd.iterate('{}'.format(objsel),'myfunc(resi,resn,name)',space=myspace) for res_pair in list(OrderedDict.fromkeys(holder)): print "{},{}".format(res_pair[1],res_pair[0]), print "\t", cmd.extend('get_resi_in_selection',get_resi_in_selection)
def color_structure(pdb_file): ''' this function colors each nucleotide in pymol >>>print (data[1][0]) 2886_2897 2QBG must match the name of pdb file which is open data[i][1] = color data[i][0] = range of nucleotide data[i][2] = chain ''' pdb_file = pdb_file.upper() url = 'https://raw.githubusercontent.com/BGSU-RNA/3D-structure-coloring/master/csv_files/%s.csv' % pdb_file response = urllib2.urlopen(url) reader = csv.reader(response, delimiter=",") data = nt_ranges(reader) for i in range(0, len(data)): if (data[i][2]) != '': cmd.color( data[i][1], "%s and resi %s in chain %s" % (pdb_file, data[i][0], data[i][2])) elif (data[i][2]) == '': cmd.color(data[i][1], "%s and resi %s " % (pdb_file, data[i][0])) cmd.extend('color_structure', color_structure)
def metaphorics(): cmd.extend("readcex", readcex) cmd.extend("colorbyB", colorbyB)
def metaphorics(): cmd.extend("readcex",readcex) cmd.extend("colorbyB",colorbyB)
# cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln+ResNotInBothPDB") cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not (notUsedForAln or ResNotInBothPDB)") ### Delete the selection of atoms not used for alignment ### If you would like to keep this selection intact, ### just comment "cmd.delete" line and ### uncomment the "cmd.disable" line abowe. cmd.disable("notUsedForAln") cmd.delete("notUsedForAln") cmd.disable("ResNotInBothPDB") cmd.delete("ResNotInBothPDB") print "\nObjects are now colored by C-alpha displacement deviation." print "Blue is minimum and red is maximum..." print "White is those residues used in the alignment algorithm. Can be turned off in top of algorithm." print "Black is residues that does not exist in both files..." cmd.extend("ColorByDisplacementCA", ColorByDisplacementCA) def displacementUpdateBAll(objA, alnAri, objB, alnBri): print "This will take a while to go through the for loops. Give me around 3-5 minutes..." ### If residue is unassigned in one of the pdb files, we reset its value for x in range(len(alnAri)): s1 = objA + " and resi " + alnAri[x][0] + " and name " + str(alnAri[x][1]) cmd.alter( s1, "b = " + str(-0.01)) for x in range(len(alnBri)): s2 = objB + " and resi " + alnBri[x][0] + " and name " + alnBri[x][1] cmd.alter( s2, "b = " + str(-0.01)) cmd.sort(objA); cmd.sort(objB) for x in range(len(alnAri)): s1 = objA + " and resi " + alnAri[x][0] + " and name " + alnAri[x][1] s2 = objB + " and resi " + alnAri[x][0] + " and name " + alnAri[x][1] ### Names starting with __ (underscores) are normally hidden by PyMOL
def _run_make(self, args): cmd = ["make", "TSR_PYTHON=" + sys.executable] cmd.extend(args) out = subprocess.check_output(cmd) return out
def doRun(directory, MardynExe): # first run if baseRemote and directory == "reference": localRemote = baseRemote else: localRemote = remote os.chdir(directory) call(['chmod', '+x', MardynExe]) cmd = [] doRemote = localRemote and (directory == 'new' or not baseIsLocal) if doRemote: rsyncremote = localRemote if localRemote.endswith('-mic0') or localRemote.endswith('-mic1'): rsyncremote = localRemote[:-5] command = "mkdir -p " + remoteprefix mkdircmd = [] mkdircmd.extend(['ssh', rsyncremote, command]) p = Popen(mkdircmd, stdout=PIPE, stderr=PIPE) out, err = p.communicate() if p.returncode: print("error on mkdir -p:") print(out, err) exit(1) remotedirectory = remoteprefix + "/" + directory command = "rsync --delete-before -r ../" + directory + " " + rsyncremote + ":" + remoteprefix print(command) p = Popen(split(command)) p.wait() if p.returncode: print("error on rsync") exit(1) command = "cd " + remotedirectory + " && pwd && " cmd.extend(['ssh', localRemote, command]) if allMPI: cmd.extend(split(MPI_START)) if directory == 'new' or not baseisnormal: cmd.extend(['-n', str(mpi)]) else: cmd.extend(['-n', '1']) else: if PAR and (directory == 'new' or not baseisnormal): cmd.extend(split(MPI_START)) cmd.extend(['-n', str(mpi)]) if legacyCellProcessor and directory == "new": cmd.extend([ './' + MardynExe, "--legacy-cell-processor", "--final-checkpoint=0", "input/" + xmlBase, "--steps", numIterations ]) else: cmd.extend([ './' + MardynExe, "--final-checkpoint=0", "input/" + xmlBase, "--steps", numIterations ]) # cmd.extend(['/work_fast/tchipevn/SDE/sde-external-7.41.0-2016-03-03-lin/sde64', '-knl', '--', './' + MardynExe, "--final-checkpoint=0", xmlBase, numIterations]); print(cmd) print("================") t = time.time() while True: # repeatedly try this if srun was not working p = Popen(cmd, stdout=PIPE, stderr=PIPE) out, err = p.communicate() if p.returncode == 1 and ("Job violates accounting/QOS policy" in err or "Socket timed out on send/recv" in err): print( "srun submit limit reached or socket timed out error, trying again in 60s" ) time.sleep(60) continue break t = time.time() - t print("elapsed time:", t) if p.returncode: print("error while executing program:") print(out, err) exit(1) print(out, err) if doRemote: # sync back command = "rsync " + rsyncremote + ":" + remotedirectory + "/* ./" print(command) p = Popen(split(command)) p.wait() if "RDF" in comparePlugins: p = Popen(['ls', '-r'] + glob("val.comparison*.rdf"), stdout=PIPE, stderr=PIPE) out, err = p.communicate() p = Popen(split("cp " + split(out)[0] + " val.comparison.rdf")) # Copy newest rdf file to val.comparison.rdf p.wait() for comparisonFilename in comparisonFilenames: # possible switch/if statements if other comparison plugins require different output. p = Popen( split("sed -i.bak '/^#/d; s/[[:blank:]]*$//; /^$/d' " + comparisonFilename)) # deletes lines starting with #. # These are the lines containing timestamps, and have to be removed for proper comparison. p.wait() os.chdir('..')
# 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 getAtomCoords(model, resi, atomName): for a in model.atom: if a.resi == resi and a.name == atomName: return a.coord return None def calculateNewPoint(p1, p2, distance): v1 = cpv.normalize(cpv.sub(p1, p2)) return cpv.add(p1, cpv.scale(v1, distance)) def makeAtom(index, atomDetails, chain): atom = chempy.Atom() atom.index = index atom.name = atomDetails['name'] atom.symbol = atomDetails['symbol'] atom.resn = atomDetails['residueName'] atom.chain = chain atom.resi = atomDetails['residueNumber'] atom.resi_number = int(atomDetails['residueNumber']) atom.coord = atomDetails['coords'] atom.hetatm = False return atom cmd.extend("createAtomAlongBond", createAtomAlongBond)