def open_file(self, requestevent, replyevent): from chimera import openModels, UserError, replyobj try: listdesc = requestevent.AEGetParamDesc(AEc.keyDirectObject, AEc.typeAEList) for i in xrange(listdesc.AECountItems()): aliasdesc = listdesc.AEGetNthDesc(i + 1, AEc.typeAlias)[1] alias = File.Alias(rawdata=aliasdesc.data) fsref = alias.FSResolveAlias(None)[0] pathname = fsref.as_pathname() #print "GOT OPEN FOR %s" % pathname openModels.open(pathname) except UserError, what: replyobj.error("%s" % what)
def make_2btv_multiscale_model(): # Open 2btv by fetching it from the RCSB from chimera import openModels m = openModels.open('2btv', 'PDBID')[0] # Color atoms by element from chimera import actions map(actions.colorAtomByElement, m.atoms) # 2btv does not have biological oligomer (BIOMT) matrices. # So get 120 matrices for a crystal unit cell with 2 virus particles # and use only first 60 to get just one particle. import PDBmatrices slist = PDBmatrices.pdb_smtry_matrices(m.pdbHeaders) mlist = PDBmatrices.pdb_mtrix_matrices(m.pdbHeaders) matrices = PDBmatrices.matrix_products(slist, mlist) matrices = matrices[:60] # Make copies of molecule. from MultiScale import molecule_copies mcopies = molecule_copies(m, matrices) # Define groups and colors. from MultiScale import make_chain_groups, make_group p_trimers = make_chain_groups('P trimer', ('P', 'C', 'D'), mcopies, color=(.5, .6, .9, 1)) # RGBA, A=opacity q_trimers = make_chain_groups('Q trimer', ('Q', 'E', 'F'), mcopies, color=(.7, .7, .8, 1)) r_trimers = make_chain_groups('R trimer', ('R', 'G', 'H'), mcopies, color=(.9, .8, .7, 1)) s_trimers = make_chain_groups('S trimer', ('S', 'I', 'J'), mcopies, color=(.7, .5, .6, 1)) # T trimers are made up of a monomer from each of 3 transformed molecules. t_triples = ((1, 20, 23), (2, 22, 27), (3, 26, 60), (4, 44, 59), (5, 16, 43), (6, 18, 40), (7, 17, 42), (8, 41, 55), (9, 49, 54), (10, 36, 48), (11, 25, 38), (12, 37, 47), (13, 35, 46), (14, 29, 34), (15, 21, 28), (19, 24, 39), (30, 33, 56), (31, 50, 53), (32, 52, 57), (45, 51, 58)) t_mcopies = map( lambda (i, j, k): (mcopies[i - 1], mcopies[j - 1], mcopies[k - 1]), t_triples) t_trimers = make_chain_groups('T trimer', ('T', ), t_mcopies, color=(.5, .9, .6, 1)) all_trimers = p_trimers + q_trimers + r_trimers + s_trimers + t_trimers outer_layer = make_group('Outer layer', all_trimers) dimers = make_chain_groups('VP3 dimer', ('A', 'B'), mcopies, chain_colors=((.7, .5, .9, 1), (.5, .8, .8, 1))) inner_layer = make_group('Inner layer', dimers) capsid = make_group('Bluetongue capsid', (outer_layer, inner_layer)) import MultiScale d = MultiScale.show_multiscale_model_dialog() d.add_models([capsid])
def main(): print sys.argv if len(sys.argv) != 3: # if no input print "ERROR: Wrong number of inputs" print "syntax: chimera --nogui --script \"chimera_move_pdb.py pdbinput output_prefix\"" print len(sys.argv) return input_pdb = sys.argv[1] output_prefix = sys.argv[2] print "pdb input = " + input_pdb print "output prefix = "+ output_prefix model = openModels.open(input_pdb) #prep(model) start = 0.0 #list = [start] for i in range(10): start = start + 0.03 #list.append(start) runCommand("move x 0.03 ") print output_prefix+"."+str(start)+".pdb" runCommand("write 0 "+output_prefix+"."+str(start)+".pdb")
def main(): print sys.argv if len(sys.argv) != 3: # if no input print "ERROR: Wrong number of inputs" print "syntax: chimera --nogui --script \"chimera_dockprep.py pdbinput output_prefix\"" print len(sys.argv) return #models = openModels.list(modelTypes=[chimera.Molecule]) input_pdb = sys.argv[1] output_prefix = sys.argv[2] print "pdb input = " + input_pdb print "output prefix = " + output_prefix #runCommand("open " + input_pdb) #models = chimera.openModels.list(modelTypes=[chimera.Molecule]) #model = models model = openModels.open(input_pdb) #runCommand("del @H,H?,H??,H???") # remove all hydrogens writeMol2(model, output_prefix + "before_dockprep.mol2") prep(model) runCommand("write 0 " + output_prefix + ".pdb") writeMol2(model, output_prefix + ".mol2") runCommand("del HC") # remove all non-polar hydrogens runCommand("write 0 " + output_prefix + "_polarH.pdb") runCommand("del @H,H?,H??,H???") # remove all hydrogens runCommand("write 0 " + output_prefix + "_noH.pdb")
def cal_SASA(input_pdb, output_prefix): print "pdb inputs = " + input_pdb print "output prefix = " + output_prefix model = openModels.open(input_pdb) runCommand("surf :all") out = open(output_prefix + "sasa.txt", "w") x = '---------------------------------------------------------------------------------\n' print "list " + str(list(model)) for m in openModels.list(modelTypes=[Molecule]): msas = 0 for r in m.residues: try: sas = r.areaSAS except AttributeError: continue msas = msas + sas out.write('%s,%f\n' % (r, sas)) out.write(x) out.write('%s,%f\n' % (m, msas)) out.write('\n') out.close() runCommand("del") print msas return msas
def generate_images(cubs, pdbs): if 'CHIMERA' not in os.environ: sys.exit("To render movies, you must run the script with " "pychimera: pychimera wfnmovie.py [...]") from chimera import runCommand as rc, openModels print('Generating .png images for {} cub/pdb files'.format(len(cubs))) for i, (cub, pdb) in tqdm(enumerate(zip(cubs, pdbs))): cubmodel = openModels.open(cub)[0] pdbmodel = openModels.open(pdb)[0] rc('vol #0 level 0.70') rc('scolor #0 gradient #0 cmap rainbow') rc('transp 50 #0') rc('turn y 180') rc('turn x -60') rc('focus') rc('copy file {}.png width 1280 height 720'.format(cub.split('.')[0])) openModels.close([cubmodel, pdbmodel])
def make_2btv_multiscale_model(): # Open 2btv by fetching it from the RCSB from chimera import openModels m = openModels.open('2btv', 'PDBID')[0] # Color atoms by element from chimera import actions map(actions.colorAtomByElement, m.atoms) # 2btv does not have biological oligomer (BIOMT) matrices. # So get 120 matrices for a crystal unit cell with 2 virus particles # and use only first 60 to get just one particle. import PDBmatrices slist = PDBmatrices.pdb_smtry_matrices(m.pdbHeaders) mlist = PDBmatrices.pdb_mtrix_matrices(m.pdbHeaders) matrices = PDBmatrices.matrix_products(slist, mlist) matrices = matrices[:60] # Make copies of molecule. from MultiScale import molecule_copies mcopies = molecule_copies(m, matrices) # Define groups and colors. from MultiScale import make_chain_groups, make_group p_trimers = make_chain_groups('P trimer', ('P','C','D'), mcopies, color = (.5, .6, .9, 1)) # RGBA, A=opacity q_trimers = make_chain_groups('Q trimer', ('Q','E','F'), mcopies, color = (.7, .7, .8, 1)) r_trimers = make_chain_groups('R trimer', ('R','G','H'), mcopies, color = (.9, .8, .7, 1)) s_trimers = make_chain_groups('S trimer', ('S','I','J'), mcopies, color = (.7, .5, .6, 1)) # T trimers are made up of a monomer from each of 3 transformed molecules. t_triples = ((1,20,23),(2,22,27),(3,26,60),(4,44,59),(5,16,43), (6,18,40),(7,17,42),(8,41,55),(9,49,54),(10,36,48), (11,25,38),(12,37,47),(13,35,46),(14,29,34),(15,21,28), (19,24,39),(30,33,56),(31,50,53),(32,52,57),(45,51,58)) t_mcopies = map(lambda (i,j,k): (mcopies[i-1],mcopies[j-1],mcopies[k-1]), t_triples) t_trimers = make_chain_groups('T trimer', ('T',), t_mcopies, color = (.5, .9, .6, 1)) all_trimers = p_trimers + q_trimers + r_trimers + s_trimers + t_trimers outer_layer = make_group('Outer layer', all_trimers) dimers = make_chain_groups('VP3 dimer', ('A','B'), mcopies, chain_colors = ((.7, .5, .9, 1), (.5, .8, .8, 1))) inner_layer = make_group('Inner layer', dimers) capsid = make_group('Bluetongue capsid', (outer_layer, inner_layer)) import MultiScale d = MultiScale.show_multiscale_model_dialog() d.add_models([capsid])
def main(): print sys.argv if len(sys.argv) != 3: # if no input print "ERROR: Wrong number of inputs" print "syntax: chimera --nogui --script \"chimera_open_save.py pdbinput output_prefix\"" print len(sys.argv) return #models = openModels.list(modelTypes=[chimera.Molecule]) input_file = sys.argv[1] output_prefix = sys.argv[2] print "input = " + input_file model = openModels.open(input_file) writeMol2(model, output_prefix + "_chimera.mol2")
def open_map(parms, mapFileName, structure): from chimera import openModels mapCURR = openModels.open(mapFileName)[0] if parms.mapType == 'sigma': #normalize map to mean of 0 and stdev of 1 scaledDen = make_normalized_map(mapCURR) elif parms.mapType == 'volume': scaledDen = mapCURR else: print 'ERROR: Unrecognized map type!' sys.exit() #extend map to 5.0 A beyond pdb coordinates return bounding_xray_map_symmetry(structure.atoms, 5.0, scaledDen)
def fetch_emdb_map(id, open_fit_pdbs = False, open_models = True): site = 'ftp.ebi.ac.uk' url_pattern = 'ftp://%s/pub/databases/emdb/structures/EMD-%s/map/%s' xml_url_pattern = 'ftp://%s/pub/databases/emdb/structures/EMD-%s/header/%s' from chimera.replyobj import status, info status('Fetching %s from %s...\n' % (id,site), blankAfter = False) # Fetch map. map_name = 'emd_%s.map' % id map_gz_name = map_name + '.gz' map_url = url_pattern % (site, id, map_gz_name) name = 'EMDB %s' % id minimum_map_size = 8192 # bytes from chimera import fetch map_path, headers = fetch.fetch_file(map_url, name, minimum_map_size, 'EMDB', map_name, uncompress = True) # Display map. status('Opening map %s...\n' % map_name, blankAfter = False) from VolumeViewer import open_volume_file models = open_volume_file(map_path, 'ccp4', map_name, 'surface', open_models = open_models) if open_fit_pdbs: # Find fit pdb ids. status('EMDB %s: looking for fits PDBs\n' % id) pdb_ids = fit_pdb_ids_from_web_service(id) msg = ('EMDB %s has %d fit PDB models: %s\n' % (id, len(pdb_ids), ','.join(pdb_ids))) status(msg) info(msg) if pdb_ids: mlist = [] from chimera import _openPDBIDModel, openModels for pdb_id in pdb_ids: status('Opening %s\n' % pdb_id) if open_models: m = openModels.open(pdb_id, 'PDBID') else: m = _openPDBIDModel(pdb_id) mlist.extend(m) models.extend(mlist) return models
def main(): print sys.argv if len(sys.argv) != 3 and len(sys.argv) != 4: # if no input print "ERROR: Wrong number of inputs" print "syntax: chimera --nogui --script \"chimera_dockprep.py pdbinput output_prefix keepH\"" print len(sys.argv) return #models = openModels.list(modelTypes=[chimera.Molecule]) input_pdb = sys.argv[1] output_prefix = sys.argv[2] if len(sys.argv) == 4: if (sys.argv[3] == 'yes'): keepH = True elif (sys.argv[3] == 'no'): keepH = False else: print("keepH must be yes or no, setting it to no.") keepH = False else: keepH = False print "pdb input = " + input_pdb print "output prefix = " + output_prefix #runCommand("open " + input_pdb) #models = chimera.openModels.list(modelTypes=[chimera.Molecule]) #model = models model = openModels.open(input_pdb) if not (keepH): runCommand("del @H,H?,H??,H???") # remove all hydrogens writeMol2(model, output_prefix+"before_dockprep.mol2") prep(model) runCommand("write 0 "+output_prefix+".pdb") writeMol2(model, output_prefix+".mol2") runCommand("del HC") # remove all non-polar hydrogens runCommand("write 0 "+output_prefix+"_polarH.pdb") runCommand("del @H,H?,H??,H???") # remove all hydrogens runCommand("write 0 "+output_prefix+"_noH.pdb")
def make_multiscale_models(pdbs): if len(pdbs) == 0: return from chimera import openModels from matrix import chimera_xform import MultiScale mm = MultiScale.multiscale_manager() for pdb_path, tflist in pdbs: pdb = openModels.open(pdb_path)[0] # Multiscale keeps the original pdb unmoved. # Make it align with surfaces. pdb.openState.localXform(chimera_xform(tflist[0])) mgroup = mm.molecule_multimer(pdb, tflist) multiscale_single_color([mgroup], random_color(pdb.name)) MultiScale.show_multiscale_model_dialog()
def main(): print sys.argv if not (len(sys.argv) == 4 or len(sys.argv) == 3): # if no input print "ERROR: Wrong number of inputs" print "syntax: chimera --nogui --script \"chimera_addh.py pdbinput output_prefix [keepH] \"" print len(sys.argv) return #models = openModels.list(modelTypes=[chimera.Molecule]) input_pdb = sys.argv[1] output_prefix = sys.argv[2] if (len(sys.argv) == 4): hflag = sys.argv[3] else: hflag = "no" print "pdb input = " + input_pdb print "output prefix = " + output_prefix print "hflag = " + hflag #runCommand("open " + input_pdb) #models = chimera.openModels.list(modelTypes=[chimera.Molecule]) #model = models model = openModels.open(input_pdb) if hflag != "keepH": print( "hydrogens will be removed. if you want to kept the hydrogens pass keepH as 3 argument." ) runCommand("del @H,H?,H??,H???") # remove all hydrogens writeMol2(model, output_prefix + "before_dockprep.mol2") #prep(model) runCommand("addh") runCommand("write 0 " + output_prefix + ".pdb") writeMol2(model, output_prefix + ".mol2") runCommand("del HC") # remove all non-polar hydrogens runCommand("write 0 " + output_prefix + "_polarH.pdb") runCommand("del @H,H?,H??,H???") # remove all hydrogens runCommand("write 0 " + output_prefix + "_noH.pdb")
from Bio.PDB.Polypeptide import PPBuilder import L_fasta2pir from L_aln_tools import muscle_aln # from dna_tools_simple import change_dna_seq_in_pdb os.environ['LD_LIBRARY_PATH']='/Library/modeller-9.14/lib/mac10v4' from modeller import * # Load standard Modeller classes from modeller.automodel import * # Load the automodel class ##### #Extract chains with Chimera nucl_xen=openModels.open('1kx5.pdb',type='PDB') # nucl_yeast=openModels.open('1id3.pdb',type='PDB') # h2a_xen=Seq(str(nucl[0].sequence('C'))) # h2a_yeast=Seq(str(nuclZ[0].sequence('C'))) rc('select :.A :.B :.C :.D :.E :.F :.G :.H') rc('write selected format pdb #0 xen_nucl.pdb') # rc('write selected format pdb #1 h2a_yeast_xray.pdb') #generate alignments #Biopython extracts seqs from pdb p = PDBParser(PERMISSIVE=1) s = p.get_structure('1kx5', '1kx5.pdb') ppb=PPBuilder() seqs_xen=dict() for i in ['A','B','C','D','E','F','G','H']: seqs_xen[i]=ppb.build_peptides(s[0][i])[0].get_sequence()
from StringIO import StringIO from Bio.PDB.PDBParser import PDBParser from Bio.PDB.Polypeptide import PPBuilder import L_fasta2pir from L_aln_tools import muscle_aln # from dna_tools_simple import change_dna_seq_in_pdb os.environ['LD_LIBRARY_PATH'] = '/Library/modeller-9.14/lib/mac10v4' from modeller import * # Load standard Modeller classes from modeller.automodel import * # Load the automodel class ##### #Extract chains with Chimera nucl_xen = openModels.open('1kx5.pdb', type='PDB') # nucl_yeast=openModels.open('1id3.pdb',type='PDB') # h2a_xen=Seq(str(nucl[0].sequence('C'))) # h2a_yeast=Seq(str(nuclZ[0].sequence('C'))) rc('select :.A :.B :.C :.D :.E :.F :.G :.H') rc('write selected format pdb #0 xen_nucl.pdb') # rc('write selected format pdb #1 h2a_yeast_xray.pdb') #generate alignments #Biopython extracts seqs from pdb p = PDBParser(PERMISSIVE=1) s = p.get_structure('1kx5', '1kx5.pdb') ppb = PPBuilder() seqs_xen = dict() for i in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']: seqs_xen[i] = ppb.build_peptides(s[0][i])[0].get_sequence()
def open_last_session(): 'Open the top file in the session file history list' paths = recent_opened_files(session_files=True) if paths: from chimera import openModels openModels.open(paths[0], type="Python")