def reload_system(self, ln: str, smis: oechem.OEMol, old_pdb: str, is_oe_already: bool = False): with self.logger("reload_system") as logger: logger.log("Loading {} with new smiles {}".format(old_pdb, ln)) with tempfile.TemporaryDirectory() as dirpath: ofs = oechem.oemolostream("{}/newlig.mol2".format(dirpath)) oechem.OEWriteMolecule(ofs, smis) ofs.close() cmd.reinitialize() cmd.load(old_pdb) cmd.remove("not polymer") cmd.load("{}/newlig.mol2".format(dirpath), "UNL") cmd.alter("UNL", "resn='UNL'") cmd.alter("UNL", "chain='A'") self.config.pdb_file_name = self.config.tempdir() + "reloaded.pdb" cmd.save(self.config.pdb_file_name) cmd.save(self.config.tempdir() + "apo.pdb") with open(self.config.pdb_file_name, 'r') as f: self.pdb = app.PDBFile(f) self.positions, self.topology = self.pdb.getPositions(), self.pdb.getTopology() if self.config.explicit and self.config.method == 'amber': self.system, self.topology, self.positions = self.__setup_system_ex_amber( pdbfile=self.config.pdb_file_name) elif self.config.explicit: self.system, self.topology, self.positions = self.__setup_system_ex_mm() else: self.system, self.topology, self.positions = self.__setup_system_im( pdbfile=self.config.pdb_file_name) return self.system
def ross_load(molecule): ''' for Jennifer Ross. ''' # if pic == 0: cmd.reinitialize() # cmd.depth_cue(1) # fails # cmd.set_depth_cue("off") # fails cmd.set("depth_cue","off") cmd.bg_color('white') fasta = molecule + '.fasta' pdb = molecule + '.pdb' print molecule print fasta print pdb cmd.load(fasta) if not os.path.exists(pdb): cmd.save(pdb) # cmd.show( string representation="", string selection="" ) cmd.show('spheres','all')
def test_msms_surface(): eps = 1e-3 cmd.reinitialize() cmd.fragment('ala', 'm1') # default psico.msms.msms_surface(name='surf1') extent = cmd.get_extent('surf1') assert extent[0] == approx([-2.705, -3.208, -2.413], rel=eps) assert extent[1] == approx([3.530, 2.907, 2.676], rel=eps) # global solvent_radius cmd.set('solvent_radius', 3.5) psico.msms.msms_surface(name='surf2') extent = cmd.get_extent('surf2') assert extent[0] == approx([-2.705, -3.169, -2.436], rel=eps) assert extent[1] == approx([3.530, 2.907, 2.676], rel=eps) # object-level solvent_radius cmd.set('solvent_radius', 2.8, 'm1') psico.msms.msms_surface(name='surf3') extent = cmd.get_extent('surf3') assert extent[0] == approx([-2.705, -3.161, -2.427], rel=eps) assert extent[1] == approx([3.530, 2.907, 2.676], rel=eps) # modified atom radii cmd.alter('m1', 'vdw = 3.0') psico.msms.msms_surface(name='surf4') extent = cmd.get_extent('surf4') assert extent[0] == approx([-4.605, -5.162, -4.418], rel=eps) assert extent[1] == approx([5.030, 4.861, 4.681], rel=eps)
def plot(self, outfile): ctrl_id, case_id, snp_df_sub = self.score_on_var() df = pd.merge(snp_df_sub, self.snps2aa, on='id') #pymol.finish_launching() cmd.reinitialize() cmd.fetch(self.pdb) cmd.alter(self.pdb, 'b = 0.5') cmd.show_as('cartoon', self.pdb) cmd.color('white', self.pdb) for i, row in df.iterrows(): resi = row['structure_position'] chain = row['chain'] pheno = row['es'] selec = 'snp%s' % i selec_atom = 'snp_atom%s' % i cmd.select(selec, 'name ca and resi %s and chain %s' % (resi, chain)) cmd.create(selec_atom, selec) cmd.set("sphere_scale", 0.8) cmd.show('sphere', selec_atom) cmd.alter(selec_atom, 'b=%s' % pheno) cmd.spectrum("b", "blue_white_red", selec_atom, maximum=1.0, minimum=0.0) cmd.bg_color("white") cmd.zoom() cmd.orient() cmd.save('%s.pse' % outfile) cmd.png('%s.png' % outfile, width=2400, height=2400, dpi=300, ray=1)
def test_polyala(): cmd.reinitialize() cmd.fab('EFG', 'm1') psico.editing.polyala() assert cmd.count_atoms('name CA') == 3 assert cmd.count_atoms('name CB') == 2 assert cmd.count_atoms('name CG+CD+CD1+CD2+2HG+3HG+1HD+2HD') == 0
def main(): """Main function. """ parser = argparse.ArgumentParser( description= "Take a selection of chains from a set of structures and save them as new structures." ) parser.add_argument('structure', nargs='+', help='Any format supported by Pymol.') parser.add_argument( '-c', '--chains', default='A', help= 'Chain string containing all the chains to be get, no space between chain IDs. Only single letter chain IDs are supported [default: %(default)s].' ) parser.add_argument( '--hetatm', action='store_true', default=False, help="Include hetatm in the output files [default: %(default)s].") parser.add_argument('-v', '--version', action='version', version='1.0', help="Show program's version number and exit.") args = parser.parse_args() chains = "".join(sorted(set(args.chains))) cmd.reinitialize() # Just to print Pymol usage as a module waring in here. for f in args.structure: try: cmd.load(f) except: sys.stderr.write( "WARNING: Can not load file {}. Ignoring it.\n".format(f)) continue if not has_chains(f, chains): sys.stderr.write( "WARNING: Structure {} does not have all requested chains: {}. Ignoring it.\n" .format(f, chains)) continue if args.hetatm: cmd.save("{}_{}.pdb".format(rootname(f), chains), "{} and chain {}".format(rootname(f), "+".join(chains))) else: cmd.save( "{}_{}.pdb".format(rootname(f), chains), "{} and not hetatm and chain {}".format( rootname(f), "+".join(chains))) cmd.delete(rootname(f))
def run(): global dialog cmd.reinitialize() cmd.do('set retain_order,1') ErrorGenerated = 0 # cmd.do('set pdb_retain_ids,1') # InfoArray = TabInfo() alpha = 0 if form.Alignalpha.isChecked(): alpha = 1 nonidentical = 0 if form.Nonchains.isChecked(): nonidentical = 1 try: files, UNK, cur_dir, pname = FileGeneration() except Exception as e: print("Error: please check input files.") ErrorGenerated = 1 f2 = open('ErrorLog.txt', 'w') f2.write(str(e)) f2.close() if ErrorGenerated == 0: files = natural_sort(files) CreateRMS(files, form.PDBCODE.text(), form.RMSCutoff.text(), UNK, alpha, nonidentical, cur_dir, pname)
def test_csp(): cmd.reinitialize() cmd.fab("A/1/ ARKA B/1/ GERD", "m1") cmd.fab("EE", "m2") cmd.fab("DD", "m3") assert psico.querying.csp("m1") == -2 assert psico.querying.csp("m2", "m3") == 4
def cheshift(pdb_path,cs_path): """Conects to CheShift to send and receive data""" pdb_filename = pdb_path.split('/')[-1] pdb_filenamenoext = re.sub(r'[^A-Za-z0-9-.]', '', pdb_filename.split('.')[0]) cs_filename = cs_path.split('/')[-1] # Send data to CheShift.com and captures the name of the new web page. br = mechanize.Browser() br.set_handle_refresh(False) br.set_proxies(proxy_values) try: br.open('http://www.cheshift.com/visual_test.html') br.select_form(nr=0) br.form.add_file(open(pdb_path), "chemical/x-pdb", pdb_filename, name = 'uploaded') br.form.add_file(open(cs_path), "text/plain", cs_filename, name='CS_file') br.form.set_value([ref_value.get()],name='radiogroup') br.form.set_all_readonly(False) response = br.submit().geturl() subfix = response.split('/')[-1].split('.')[0] except: Pmw.MessageDialog(title='Error',message_text=('Something went wrong while processing your request\n Please check your files and try again\n\nIf you could not find the problem please send and e-mail to [email protected]')) # Checks if the colored PDB file was created or if something went wrong test = 0 while True: try:# If the colored PDB was created, creates a local temporal PDB file # and loads that file into PyMOL. result = br.open('http://www.cheshift.com/jobs/%s/%s_b.pdb?r=%d' % (subfix, pdb_filenamenoext, test)).read() fd = tempfile.NamedTemporaryFile(bufsize=0,delete=False) fd.write(result) fd.close() pdb_tmp = fd.name pdblist = [] for line in open(pdb_tmp).readlines(): if 'ATOM' in line: pdblist.append(line) first = int(pdblist[0][22:26]) last = int(pdblist[-1][22:26]) cmd.reinitialize() rename = ('%s_b.pdb' % (pdb_filenamenoext)) cmd.load(pdb_tmp, rename) #CheShift does not provide results for the first or last residue cmd.remove('resi %s' % first) cmd.remove('resi %s' % last) colorize() break except: test += 1 try:# check for posible errors result = br.open('http://www.cheshift.com/jobs/%s/error.txt?r=%d' % (subfix, test)).read().split() # behind a proxy you need to add a "dummy" modifier to the requested file (?r=%d'). Otherwise you will just be checking the cached file and not the actual file. if int(result[0]) == 0: Pmw.MessageDialog(title = 'Error',message_text=('The residue at position %s is missing from your PDB file\n Please fix the problem and try again' % (result[1]))) elif int(result[0]) == 1: Pmw.MessageDialog(title = 'Error',message_text = ('The residue %s%s in your PDB file does not match\n with residue %s%s in your chemical shift file.\n\n Please check your files and try again' % (result[1], result[3], result[2], result[3]))) else: Pmw.MessageDialog(title = 'Error',message_text=('Something went wrong while processing your request\n Please check your files and try again\n\nIf you could not find the problem please write to us')) break except: pass time.sleep(5)
def q5(): ''' DESCRIPTION Question 5: How many axial stacks of helices does the ribozyme have? The following commands created the scene for "q5": delete all;fetch 3zp8, hammer, async=0;show cartoon, hammer;set_view (-0.5,0.18,-0.85,-0.17,-0.98,-0.11,-0.85,0.09,0.52,0.0,0.0,-167.2,-18.45,10.92,-12.11,126.37,208.02,-20.0);rock; To reuse of parts or all of the above commands, copy and paste the commands onto the command line or into a plain text file. These commands are sufficient for most editing tasks: To edit code, positon cursor on command line with left mouse button. Control-e moves the cursor to the end of the line, even when it is out of view. Control-a moves the cursor to the beginning of the line, even when it is out of view. Up arrow key recalls last line of commands for editing. These commands may not be available on all systems: Shift-control-a selects everything from the right of the cursor to the end of the line. Shift-control-e selects everything to the left of the cursor to the end of the line. Command-f moves the cursor to the end of the current word. Command-b moves the cursor to the begining of the current word. Control-f moves the cursor to the right by one character. Control-b moves the cursor to the left by one character. ''' cmd.reinitialize() cmd.fetch('3zp8', type='pdb', name= 'hammer', async='0') cmd.show_as('cartoon','hammer') cmd.rock() cmd.set_view('(-0.5,0.18,-0.85,-0.17,-0.98,-0.11,-0.85,0.09,0.52,0.0,0.0,-167.2,-18.45,10.92,-12.11,126.37,208.02,-20.0);') print('Enter "q5" to make the scene for question 5.') print('Enter "help q5" to see question 5 and the commands to make the scene.')
def chargerFichier(nomRepertoire, nomFichier): try: cmd.reinitialize() cmd.load(nomRepertoire + nomFichier + ".pdb") print("Chargement du ficher " + nomFichier + " effectue") except: print("Erreur de chargement du ficher " + nomFichier)
def show_chain_in_PDB(entry): PDB = entry[:4] chain = entry[-1:] cmd.reinitialize('everything') cmd.set("bg_rgb", "white") cmd.run("%s/B_strands_%s.py" % (PyMOL_script_dir, PDB)) cmd.show("cartoon", "all")
def test_add_missing_atoms(): cmd.reinitialize() cmd.load(DATA_PATH / '2x19-frag-mse.pdb') cmd.remove("not backbone") assert cmd.count_atoms("resi 132") == 4 psico.modelling.add_missing_atoms('resi 132+133', cycles=10) assert cmd.count_atoms("resi 132") == 8
def test_stub2ala(): cmd.reinitialize() cmd.fab('EFG', 'm1') cmd.remove('not (backbone or name CB)') psico.editing.stub2ala() my_values = [] cmd.iterate('guide', 'my_values.append(resn)', space=locals()) assert my_values == ['ALA', 'ALA', 'GLY']
def testGetSession(self): cmd.fragment('ala') x = cmd.count_atoms() s = cmd.get_session() cmd.reinitialize() cmd.set_session(s) self.assertEqual(['ala'], cmd.get_names()) self.assertEqual(x, cmd.count_atoms())
def test_get_seq(): cmd.reinitialize() cmd.load(DATA_PATH / '2x19-frag-mse.pdb') assert psico.modelling.get_seq("all") == "LSMMPD" cmd.remove("resi 134") assert psico.modelling.get_seq("all") == "LS/MPD" cmd.alter("resi 137", "resn = 'XXX'") assert psico.modelling.get_seq("all", unknown="#") == "LS/MP#"
def test_select_range(): cmd.reinitialize() cmd.fab("GASGAGS", "m1") cmd.select("s1", "resn ALA") psico.selecting.select_range() assert 4 == cmd.count_atoms("s1 & guide") psico.selecting.select_range("s2", "resn SER") assert 5 == cmd.count_atoms("s2 & guide")
def setUp(self) -> None: cmd.load(self.in_pdb1) self.all_atoms1 = pymol_utitlities.pymol_selection_to_atom_list("all") cmd.reinitialize() cmd.load(self.in_pdb2) self.all_atoms2 = pymol_utitlities.pymol_selection_to_atom_list("all") cmd.reinitialize()
def photo_pdb(pdb_file, out_file): pymol.finish_launching(['pymol', '-qc']) cmd.reinitialize() cmd.load(pdb_file) cmd.show_as('cartoon', 'all') cmd.util.cbc() cmd.png(filename=out_file, width=350, height=350, ray=0, dpi=300) cmd.quit()
def test_load_consurf(): cmd.reinitialize() cmd.load(DATA_PATH / "1ubq.cif.gz", "m1") cmd.color("white") psico.conservation.load_consurf( str(DATA_PATH / "consurf_summary-5NVGA.txt"), "m1") colors = psico.querying.iterate_to_list("m1", "color") assert len(set(colors)) > 10
def test_split(): cmd.reinitialize() cmd.fab('ACD', 'm1') psico.editing.split('byres', 'm1') assert cmd.count_atoms('entity01') == cmd.count_atoms('m1 & resn ALA') assert cmd.count_atoms('entity02') == cmd.count_atoms('m1 & resn CYS') assert cmd.count_atoms('entity03') == cmd.count_atoms('m1 & resn ASP') psico.editing.split('byres', 'm1', 'foo_') assert cmd.count_atoms('foo_01') == cmd.count_atoms('m1 & resn ALA')
def save_pocket(pdb, sdf, name): cmd.reinitialize() cmd.load(pdb) cmd.load(sdf, "LIG") cmd.select("POCK", "br. LIG around 4") stored.idx = 0 cmd.iterate("POCK and n. CA", expression="stored.idx+=1") cmd.save(name, "POCK") return stored.idx
def retrieve_pdb(): """Loads a PDB file provided by the user""" global pdb_path pdb_path = tkFileDialog.askopenfilename(title="Open PDB file", filetypes=[("PDB files", ".pdb"),("All files",".*")]) if len(pdb_path) == 0: del pdb_path else: cmd.reinitialize() cmd.load(pdb_path)
def test_iterate_state_to_list(): cmd.reinitialize() cmd.fragment("gly") r = psico.querying.iterate_state_to_list(-1, "not hydro", "(x,y,z)") assert len(r) == 4 assert r[0] == approx([-1.1945616, 0.201105937, -0.2060566]) assert r[1] == approx([0.23043768, 0.318106502, -0.5020566]) assert r[2] == approx([1.05943620, -0.38989559, 0.54194343]) assert r[3] == approx([0.54543632, -0.97489464, 1.49894345])
def test_set_phipsi(): cmd.reinitialize() cmd.fab('ACDEF', 'm1') psico.editing.set_phipsi('all', 160, 160) psico.editing.set_phipsi('resi 2+4', 120) psico.editing.set_phipsi('resi 3+4', psi=-140) assert cmd.get_phipsi('resi 2')['m1', 12] == approx((120., 160.)) assert cmd.get_phipsi('resi 3')['m1', 23] == approx((160., -140.)) assert cmd.get_phipsi('resi 4')['m1', 35] == approx((120., -140.))
def show_chain_in_PDB(entry): PDB = entry[:4] chain = entry[-1:] cmd.reinitialize('everything') cmd.do('@~/.pymolrc') cmd.set("bg_rgb", "white") cmd.run("%s/strands_%s.py" % (PyMOL_script_dir, PDB)) cmd.show("cartoon", "all") cmd.set("cartoon_transparency", .85, PDB) cmd.set("cartoon_transparency", 0.05, "%s_barrel" % PDB)
def test_mse2met(): cmd.reinitialize() cmd.load(FILENAME_WITH_MSE) assert cmd.count_atoms('resn MSE') == 16 assert cmd.count_atoms('name SE') == 2 psico.editing.mse2met() assert cmd.count_atoms('resn MSE') == 0 assert cmd.count_atoms('name SE') == 0 assert cmd.count_atoms('resn MET') == 16 assert cmd.count_atoms('name SD') == 2
def test_split_chains(): cmd.reinitialize() cmd.fab('ACD', 'm1', chain='A') cmd.fab('EFG', 'm2', chain='B') cmd.create('m3', 'm1 m2') psico.editing.split_chains('m3') assert cmd.get_chains('m3_A') == ['A'] assert cmd.get_chains('m3_B') == ['B'] psico.editing.split_chains('m3', 'foo_') assert cmd.get_chains('foo_0001') == ['A']
def test_remove_alt(): cmd.reinitialize() cmd.fab('AC', 'm1') cmd.alter('resn ALA', 'alt="A"') cmd.alter('resn CYS', 'alt="B"') cmd.create('m2', 'm1') psico.editing.remove_alt('m1') psico.editing.remove_alt('m2', keep='B') assert cmd.count_atoms('m1') == 10 assert cmd.count_atoms('m2') == 11
def test_split_molecules(): cmd.reinitialize() cmd.fab('ACD', 'm1') cmd.fab('EFG', 'm2') cmd.create('m3', 'm1 m2') psico.editing.split_molecules('m3') assert cmd.count_atoms('mol_01') == cmd.count_atoms('m1') assert cmd.count_atoms('mol_02') == cmd.count_atoms('m2') psico.editing.split_molecules('m3', 'foo_') assert cmd.count_atoms('foo_01') == cmd.count_atoms('m1')
def calcRMSD_pymol(uf, bf): """ Given two pdb files of the same protein, this function calculates the rmsd, asa for each and the molecular weight of each using Pymol """ # Call the function below before using any PyMOL modules. #time.sleep(random.random()) cmd.set("dot_solvent", 1) cmd.load(uf) cmd.load(bf) #cmd.h_add() #cmd.remove('het') _, un, _ = getFileParts(uf) _, bn, _ = getFileParts(bf) asa_u = cmd.get_area(un) asa_b = cmd.get_area(bn) umass = cmd.get_model(un).get_mass() bmass = cmd.get_model(bn).get_mass() #rms=cmd.super(un,bn,transform=1)[0] #time.sleep(random.random()) bv0 = [] cmd.iterate('all', 'bv0.append(b)', space=locals()) cmd.do('run colorbyrmsd.py; colorbyrmsd \'' + un + '\',\'' + bn + '\',guide = 0,doAlign=1, doPretty=1') while True: # synchronization bv1 = [] cmd.iterate('all', 'bv1.append(b)', space=locals()) if bv0 != bv1: time.sleep(0.1) break out_file = tempfile.NamedTemporaryFile(suffix='.pdb') out_file.close() tmp_pdb = out_file.name updb = tmp_pdb + 'u' bpdb = tmp_pdb + 'b' cmd.save(updb, un) cmd.save(bpdb, bn) (_, uR, _, _, _) = readPDB(updb) urmsd = getBvalues(uR) os.remove(updb) (_, bR, _, _, _) = readPDB(bpdb) brmsd = getBvalues(bR) os.remove(bpdb) rms = np.sqrt(np.mean( np.array([v for V in urmsd for v in V if v >= 0])**2)) #(_,urx,_,_,_)=readPDB(uf); ux=getBvalues(urx); # if np.abs(rms-rmsd)>0.1: # print "RMSD =",rms,rmsd # pdb.set_trace() cmd.reinitialize() pdb.set_trace() return rms, asa_u, asa_b, umass, bmass, urmsd, brmsd
def screenshotProteins(): # proteinsPath = ".\pdbs" # set style parameters # cmd.set("ray_opaque_background", 0) # cmd.remove("solvent") cmd.set("ambient", 0.3) cmd.set("antialias", 1) cmd.bg_color("white") # cmd.set("direct", 1.0) # cmd.set("ribbon_radius", 0.2) # cmd.set("cartoon_highlight_color", "grey50") # cmd.set("ray_trace_mode", 1) # cmd.set("stick_radius", 0.2) # cmd.set("mesh_radius", 0.02) # loop thru folders # for dir in os.walk(proteinsPath): # proteinPath = dir[0] # loop thru pdbs # for file in os.listdir(proteinPath): # if file.endswith('.pdb'): csvFileName = "docked-protein-homomers.csv" # to loop through csv file = open(csvFileName, "r") reader = csv.reader(file, delimiter=",") k = 1 for row in reader: for item in row: print(k, item) cmd.reinitialize() # load the pdb file cmd.fetch(item, path="./pdbs", type='pdb') #pdbPath= "./pdbs/" + item + ".cif" #cmd.load(pdbPath) color = pickAColor() cmd.color(color) cmd.show("cartoon") cmd.remove("solvent") # take a screenshot screenshotFileName = item + ".png" screenshotPath = os.path.join('screenshots', screenshotFileName) cmd.png(screenshotPath, 128, 128, ray=1) # clear cmd.delete("all") k = k + 1
def test_rmsf2b(): cmd.reinitialize() cmd.load(FILENAME_MULTISTATE) psico.editing.rmsf2b() my_values = [] cmd.iterate('resi 80 & guide', 'my_values.append(b)', space=locals()) assert my_values == approx([3.266], rel=1e-2) psico.editing.rmsf2b(linearscale=-1, var='q') my_values = [] cmd.iterate('resi 80 & guide', 'my_values.append(q)', space=locals()) assert my_values == approx([842.231], rel=1e-2)
def setUp(self): self.oldcwd = os.getcwd() cmd.reinitialize() cmd.viewport(640, 480) cwd = self.moddirs[type(self).__module__] os.chdir(cwd) cmd.feedback('push') cmd.feedback('disable', 'all', 'details actions') self.timings = []
def test_set_sequence(): cmd.reinitialize() cmd.fab('ACD', 'm1') psico.editing.set_sequence('EFG') myseq = [] cmd.iterate('guide', 'myseq.append(resn)', space=locals()) assert myseq == ['GLU', 'PHE', 'GLY'] psico.editing.set_sequence('HI', start=2) myseq = [] cmd.iterate('guide', 'myseq.append(resn)', space=locals()) assert myseq == ['GLU', 'HIS', 'ILE']
def testPSEBulkExportImport(self, pse_export_version, pse_binary_dump): with testing.mktemp('.pse') as filename: cmd.load(self.datafile("1oky-frag.pdb")) m1 = cmd.get_model() cmd.set("pse_export_version", pse_export_version) cmd.set("pse_binary_dump", pse_binary_dump) cmd.save(filename) cmd.reinitialize() cmd.load(filename) m2 = cmd.get_model() self.assertModelsAreSame(m1, m2)
def test_update_identifiers(): cmd.reinitialize() cmd.fab('ACD', 'm1') cmd.fab('ACD', 'm2') cmd.remove('m1 and not backbone') cmd.alter('m1', '(segi, chain) = ("Segi", "Chain")') psico.editing.update_identifiers('m2', 'm1', identifiers='segi chain') assert cmd.get_chains('m2') == ['Chain'] my_values = [] cmd.iterate('m2', 'my_values.append(segi)', space=locals()) assert set(my_values) == set(["Segi"])
def test_alphatoall(): cmd.reinitialize() cmd.fab('ACD', 'm1') cmd.alter('guide', 'color = resv') psico.editing.alphatoall('all', 'color') my_values = [] cmd.iterate('all', 'my_values.append(color)', space=locals()) assert set(my_values) == set([1, 2, 3]) cmd.alter('name N', 'color = resv + 3') psico.editing.alphatoall('all', 'color', operator='(name N) and') my_values = [] cmd.iterate('all', 'my_values.append(color)', space=locals()) assert set(my_values) == set([4, 5, 6])
def test_sst(): cmd.reinitialize() cmd.load(FILENAME_MULTISTATE) psico.editing.sst(raw='resn') my_values = [] cmd.iterate('guide', 'my_values.append((ss, resn))', space=locals()) assert my_values == [\ ('L', 'C'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'G'), ('H', 'G'), ('H', 'G'), ('L', 'C'), ('L', 'C'), ('H', 'I'), ('H', 'I'), ('H', 'I'), ('H', 'I'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('H', 'H'), ('L', 'C'), ('L', '3'), ('L', '3'), ('L', '3'), ('L', '3')]
def getImageLocation(self): cmd.reinitialize(); myFormats = [('Portable Network Graphics','*.png'),('JPEG / JFIF','*.jpg')] try: self.file = tkFileDialog.askopenfile(parent=dialog,mode='rb',filetypes=myFormats, title='Choose the contact map image file') except: quitProgram(self, "No Contact Map!") if self.file != None: data = self.file.read() print "Opening...", self.file.name print "Received %d bytes from this file." % len(data) getPDBLocation(self) else: quitProgram(self, "No Contact Map!")
def q6(): ''' DESCRIPTION Question 6: What is the average distance of the Na1044 ligand bonds? Give the residue numbers of the RNA nucleotides and the sodium to identify them. How many ligands are from RNA? The following commands created the scene for "q6": delete all;fetch 3zp8, hammer, async=0; rock;preset.ball_and_stick("all");distance ligand1, i. 1044, c. A and i. 22 and n. N7;distance ligand2, i. 1044, c. A and i. 21 and n. OP2;distance ligand3, i. 1044, i. 2121;distance ligand4, i. 1044, i. 2120;distance ligand5, i. 1044, i. 2122;distance ligand6, i. 1044, i. 2130;set_view (-0.87,0.18,-0.46,-0.39,-0.81,0.44,-0.29,0.56,0.78,-0.0,0.0,-20.47,-18.05,14.02,-18.89,17.47,23.47,-20.0); To reuse of parts or all of the above commands, copy and paste the commands onto the command line or into a plain text file. These commands are sufficient for most editing tasks: To edit code, positon cursor on command line with left mouse button. Control-e moves the cursor to the end of the line, even when it is out of view. Control-a moves the cursor to the beginning of the line, even when it is out of view. Up arrow key recalls last line of commands for editing. These commands may not be available on all systems: Shift-control-a selects everything from the right of the cursor to the end of the line. Shift-control-e selects everything to the left of the cursor to the end of the line. Command-f moves the cursor to the end of the current word. Command-b moves the cursor to the begining of the current word. Control-f moves the cursor to the right by one character. Control-b moves the cursor to the left by one character. ''' cmd.reinitialize() cmd.fetch('3zp8', type='pdb', name= 'hammer', async='0') cmd.rock() cmd.do('preset.ball_and_stick("all")') cmd.distance('Sodiumligand1',' resi 1044', 'chain A and i. 22 and n. N7') cmd.distance('Sodiumligand2', 'resi 1044', 'chain A and i. 21 and n. OP2') cmd.distance('Sodiumligand3', 'resi 1044', 'resi 2121') cmd.distance('Sodiumligand4', 'resi 1044', 'resi 2120') cmd.distance('Sodiumligand5', 'resi 1044', 'resi 2122') cmd.distance('Sodiumligand6', 'resi 1044', 'resi 2130') cmd.do('set label_size, -0.4') cmd.set_view('(-0.87,0.18,-0.46,-0.39,-0.81,0.44,-0.29,0.56,0.78,-0.0,0.0,-20.47,-18.05,14.02,-18.89,17.47,23.47,-20.0);') print('Enter "q6" to make the scene for question 6.') print('Enter "help q6" to see question 6 and the commands to make the scene.')
def q8(): ''' DESCRIPTION Question 8: Find the unusual base pair between A21 and G36. What is the length of the H-bonds between the bases (ignore the H atoms in the distance measurement)? List the distance with the residue name, residue number, and atom name. What additional H-bond occurs between a base in this base pair and a ribose ring of one of the two nucleotides in this base pair? The following commands created the scene for "q8": fetch 3zp8, hammer, async=0;hide everything;show ribbon;show sticks, resi 21 or resi 36;set_view (-0.9,-0.19,0.39,0.39,-0.74,0.55,0.19,0.65,0.74,0.0,0.0,-37.58,-21.66,15.71,-23.32,35.42,39.74,-20.0);rock; To reuse of parts or all of the above commands, copy and paste the commands onto the command line or into a plain text file. These commands are sufficient for most editing tasks: To edit code, positon cursor on command line with left mouse button. Control-e moves the cursor to the end of the line, even when it is out of view. Control-a moves the cursor to the beginning of the line, even when it is out of view. Up arrow key recalls last line of commands for editing. These commands may not be available on all systems: Shift-control-a selects everything from the right of the cursor to the end of the line. Shift-control-e selects everything to the left of the cursor to the end of the line. Command-f moves the cursor to the end of the current word. Command-b moves the cursor to the begining of the current word. Control-f moves the cursor to the right by one character. Control-b moves the cursor to the left by one character. ''' cmd.reinitialize() cmd.fetch('3zp8', type='pdb', name= 'hammer', async='0') cmd.show_as('ribbon', 'hammer') cmd.rock() cmd.hide('everything') cmd.show_as( 'ribbon','all') cmd.show_as('sticks', 'resi 21 or resi 36') cmd.set_view('(-0.9,-0.19,0.39,0.39,-0.74,0.55,0.19,0.65,0.74,0.0,0.0,-37.58,-21.66,15.71,-23.32,35.42,39.74,-20.0);') print('Enter "q8" to make the scene for question 8.') print('Enter "help q8" to see question 8 and the commands to make the scene.')
def q4(): ''' DESCRIPTION Question 4: What the dihedral angle about the disulfide bond between MRG81 of chain F and Cys258 of chain C? This is a cross link between the protein and the DNA. Is this a cis or trans conformation of the bonds about the S--S bond? Is this conformation energetically favorable or unfavorable? The following commands created the scene for "q4": delete all; fetch 3v6d, HIVrt, async=0;preset.ball_and_stick("(c. C and i. 258) or (c. F and i. 817 )");set_view (0.21,-0.91,0.34,-0.84,0.01,0.54,-0.5,-0.4,-0.77,0.0,-0.0,-38.82,-39.67,-55.1,10.96,36.31,41.34,-20.0); To reuse of parts or all of the above commands, copy and paste the commands onto the command line or into a plain text file. These commands are sufficient for most editing tasks: To edit code, positon cursor on command line with left mouse button. Control-e moves the cursor to the end of the line, even when it is out of view. Control-a moves the cursor to the beginning of the line, even when it is out of view. Up arrow key recalls last line of commands for editing. These commands may not be available on all systems: Shift-control-a selects everything from the right of the cursor to the end of the line. Shift-control-e selects everything to the left of the cursor to the end of the line. Command-f moves the cursor to the end of the current word. Command-b moves the cursor to the begining of the current word. Control-f moves the cursor to the right by one character. Control-b moves the cursor to the left by one character. ''' cmd.reinitialize() cmd.fetch('3v6d',type='pdb',name='HIVrt',async='0') cmd.do("preset.ball_and_stick(selection='(chain C and resi 258) or (chain F and resi 817 )')") cmd.set_view('(0.21,-0.91,0.34,-0.84,0.01,0.54,-0.5,-0.4,-0.77,0.0,-0.0,-38.82,-39.67,-55.1,10.96,36.31,41.34,-20.0);') cmd.rock() print('Enter "q4" to make the scene for question 4.') print('Enter "help q4" to see question 4 and the commands to make the scene.')
def q7(): ''' DESCRIPTION Question 7: Measure the longest dimension and the shortest dimension of the ribozyme. Enter "rock" to stop the rocking motion. What is the ratio of the longest dimension to the shortest dimension? Is it globular like a protein? The following commands created the scene for "q7": delete all;fetch 3zp8, hammer, async=0;show ribbon, hammer;set_view (0.62,0.14,0.78,0.13,-0.99,0.07,0.78,0.05,-0.63,-0.0,-0.0,-169.8,-16.43,9.44,-9.63,143.54,196.05,-20.0); rock; To reuse of parts or all of the above commands, copy and paste the commands onto the command line or into a plain text file. These commands are sufficient for most editing tasks: To edit code, positon cursor on command line with left mouse button. Control-e moves the cursor to the end of the line, even when it is out of view. Control-a moves the cursor to the beginning of the line, even when it is out of view. Up arrow key recalls last line of commands for editing. These commands may not be available on all systems: Shift-control-a selects everything from the right of the cursor to the end of the line. Shift-control-e selects everything to the left of the cursor to the end of the line. Command-f moves the cursor to the end of the current word. Command-b moves the cursor to the begining of the current word. Control-f moves the cursor to the right by one character. Control-b moves the cursor to the left by one character. ''' cmd.reinitialize() cmd.fetch('3zp8', type='pdb', name= 'hammer', async='0') cmd.show_as('ribbon', 'hammer') cmd.rock() cmd.set_view('(0.62,0.14,0.78,0.13,-0.99,0.07,0.78,0.05,-0.63,-0.0,-0.0,-169.8,-16.43,9.44,-9.63,143.54,196.05,-20.0);') print('Enter "q7" to make the scene for question 7.') print('Enter "help q7" to see question 7 and the commands to make the scene.')
def q3(): ''' DESCRIPTION Question 3: In which groove of the DNA is the protein making the most contacts? Is this unusual? The following commands created the scene for "q3": delete all; fetch 3v6d, HIVrt, async=0; show cartoon, c. A or c. B;hide lines, c. A or c. B;set_view (0.53,-0.06,-0.84,0.82,-0.21,0.53,-0.21,-0.98,-0.07,-0.0,-0.0,-192.99,-29.84,8.42,47.76,178.27,207.7,-20.0);rock; To reuse of parts or all of the above commands, copy and paste the commands onto the command line or into a plain text file. These commands are sufficient for most editing tasks: To edit code, positon cursor on command line with left mouse button. Control-e moves the cursor to the end of the line, even when it is out of view. Control-a moves the cursor to the beginning of the line, even when it is out of view. Up arrow key recalls last line of commands for editing. These commands may not be available on all systems: Shift-control-a selects everything from the right of the cursor to the end of the line. Shift-control-e selects everything to the left of the cursor to the end of the line. Command-f moves the cursor to the end of the current word. Command-b moves the cursor to the begining of the current word. Control-f moves the cursor to the right by one character. Control-b moves the cursor to the left by one character. ''' cmd.reinitialize() cmd.fetch('3v6d', type='pdb', name= 'HIVrt', async='0') cmd.show_as("cartoon","c. A or c. B") cmd.hide("lines","c. A or c. B") cmd.rock() cmd.set_view('(0.53,-0.06,-0.84,0.82,-0.21,0.53,-0.21,-0.98,-0.07,-0.0,-0.0,-192.99,-29.84,8.42,47.76,178.27,207.7,-20.0);') print('Enter "q3" to make the scene for question 3.') print('Enter "help q3" to see question 3 and the commands to make the scene.')
def q1(): ''' DESCRIPTION Question 1: Explain how AZT terminates extension of the DNA chain. The following commands created the scene for "q1": delete all; fetch 3v6d, HIVrt, async=0; rock;preset.ball_and_stick("c. P and i. 822");set_view (-0.99,-0.1,0.06,0.09,-0.39,0.92,-0.07,0.92,0.39,0.0,0.0,-29.2,-10.56,24.72,39.27,23.02,35.38,-20.0); To reuse of parts or all of the above commands, copy and paste the commands onto the command line or into a plain text file. These commands are sufficient for most editing tasks: To edit code, positon cursor on command line with left mouse button. Control-e moves the cursor to the end of the line, even when it is out of view. Control-a moves the cursor to the beginning of the line, even when it is out of view. Up arrow key recalls last line of commands for editing. These commands may not be available on all systems: Shift-control-a selects everything from the right of the cursor to the end of the line. Shift-control-e selects everything to the left of the cursor to the end of the line. Command-f moves the cursor to the end of the current word. Command-b moves the cursor to the begining of the current word. Control-f moves the cursor to the right by one character. Control-b moves the cursor to the left by one character. ''' cmd.reinitialize() cmd.fetch('3v6d', type='pdb', name='HIVrt',async='0') cmd.rock() preset.ball_and_stick('c. P and i. 822') cmd.set_view('(-0.99,-0.1,0.06,0.09,-0.39,0.92,-0.07,\ 0.92,0.39,0.0,0.0,-29.2,-10.56,24.72,39.27,\ 23.02,35.38,-20.0)') print('Enter "q1" to set scene for question 1.') print('Enter "help q1" for more information.')
def q2(): ''' DESCRIPTION Question 2: Look along the helical axis of the DNA. Is the DNA helix bent? The following commands created the scene for "q2": delete all; fetch 3v6d, HIVrt, async=0; rock;show cartoon, c. P or c. T;set_view (0.61,0.29,-0.73,0.78,-0.37,0.51,-0.12,-0.88,-0.45,-0.0,-0.0,-192.99,-29.84,8.42,47.76,178.27,207.7,-20.0); To reuse of parts or all of the above commands, copy and paste the commands onto the command line or into a plain text file. These commands are sufficient for most editing tasks: To edit code, positon cursor on command line with left mouse button. Control-e moves the cursor to the end of the line, even when it is out of view. Control-a moves the cursor to the beginning of the line, even when it is out of view. Up arrow key recalls last line of commands for editing. These commands may not be available on all systems: Shift-control-a selects everything from the right of the cursor to the end of the line. Shift-control-e selects everything to the left of the cursor to the end of the line. Command-f moves the cursor to the end of the current word. Command-b moves the cursor to the begining of the current word. Control-f moves the cursor to the right by one character. Control-b moves the cursor to the left by one character. ''' cmd.reinitialize() cmd.fetch('3v6d',type='pdb',name='HIVrt',async='0') cmd.rock() cmd.show_as("cartoon","chain P or chain T") cmd.set_view('(0.61,0.29,-0.73,0.78,-0.37,0.51,-0.12,-0.88,-0.45,-0.0, 0.0,-192.99,-29.84,8.42,47.76,178.27,207.7,-20.0);') print('Enter "q2" to make the scene for question 2.') print('Enter "help q2" to see question 2 and the commands to make the scene.')
def save_settings(filename='~/.pymolrc-settings.py', quiet=1): ''' DESCRIPTION Dumps all settings with non-default values to ~/.pymolrc-settings.py Feature Request: Save settings for later use - ID: 1009951 https://sourceforge.net/tracker/?func=detail&aid=1009951&group_id=4546&atid=354546 ''' from pymol.setting import get_name_list quiet = int(quiet) if not filename.endswith('.py'): print('Warning: filename should end with ".py"') # temporatily load default settings and remember them cmd.reinitialize('store_defaults') cmd.reinitialize('original_settings') original = [(name, cmd.get(name)) for name in get_name_list()] cmd.reinitialize('settings') # dump to file filename = cmd.exp_path(filename) f = open(filename, 'w') print('# AUTOGENERATED FILE', file=f) print('from pymol import cmd, invocation', file=f) print('if invocation.options.show_splash:', end=' ', file=f) # no newline print(' print "Loading settings from",', repr(filename), file=f) count = 0 for name, o_value in original: value = cmd.get(name) if value != o_value: print('cmd.set("%s", %s)' % (name, repr(value)), file=f) if not quiet: print('set %s, %s # default: %s' % (name, value, o_value)) count += 1 f.close() if not quiet: print('Dumped %d settings to %s' % (count, filename))
elif q_seq[pos] == '-' and t_seq[pos] != '-': crys_gaps += 1 #print 'crys gap' elif q_seq[pos] != '-' and t_seq[pos] == '-': aln_thr_gaps += 1 #print 'aln_thr gap' elif q_seq[pos] != '-' and t_seq[pos] != '-': aln_thr_seg_in.append(pos - aln_thr_gaps + 1) crys_seg_in.append(pos - crys_gaps + 1) #print "aln_thr ", pos - aln_thr_gaps + 1, "crys: ", pos - crys_gaps + 1 return aln_thr_seg_in, crys_seg_in for pdb in os.listdir(PDBS_PATH): if pdb.endswith(".pdb"): cmd.reinitialize() names_split = pdb.split('_') q_name_coh = names_split[0] q_name_doc = names_split[1] t_name_coh = names_split[3] t_name_doc = names_split[4] out_num = names_split[5].split('.')[0] aln_thr_seg_coh, crys_seg_coh = msa_segment('coh', q_name_coh, t_name_coh) aln_thr_seg_doc, crys_seg_doc = msa_segment('doc', q_name_doc, t_name_doc) aln_coh_length = fasta_length(read_aln('coh', q_name_coh)) crys_coh_length = fasta_length(read_aln('coh', t_name_coh)) aln_thr_seg_doc_added = [i+aln_coh_length for i in aln_thr_seg_doc] crys_seg_doc_added = [i+crys_coh_length for i in crys_seg_doc] aln_thr_seg_tot = aln_thr_seg_coh + aln_thr_seg_doc_added