# ----------------------------------------------------------------------------- # Open PDB file, make multiscale model, and export 3d scene. # # Allowed export formats are POV-Ray, RenderMan, X3D, VRML, and OBJ. # OBJ format requires installing the separate ExportOBJ Chimera plug-in # from the Chimera experimental features web page. # def export_pdb_as_multiscale(pdb_path, resolution, export_format, export_path): # Open PDB from chimera import openModels as om mlist = om.open(pdb_path) # Create multiscale model from MultiScale import multiscale_model_dialog d = multiscale_model_dialog(create = True) d.surface_resolution.set('%g' % resolution) # For copies of molecule: d.multimer_none, d.multimer_unitcell d.multimer_type.set(d.multimer_biounit) d.make_multimers(mlist) # Export scene. if export_format == 'OBJ': import ExportOBJ ExportOBJ.write_surfaces_as_wavefront_obj(export_path) else: from chimera import exports exports.doExportCommand(export_format, export_path) # Close files from chimera import closeSession closeSession() # ----------------------------------------------------------------------------- # Export multiscale surface models for all PDB files in a directory. # def export_pdbs(dir, resolution, export_format, export_suffix): from os import listdir filenames = [n for n in listdir(dir) if n.endswith('.pdb')] from os.path import join for f in filenames: pdb_path = join(dir, f) export_path = join(dir, f.rstrip('.pdb') + export_suffix) export_pdb_as_multiscale(pdb_path, resolution, export_format, export_path) # ----------------------------------------------------------------------------- # Formats: 'VRML', 'OBJ', 'POV-Ray', 'RenderMan', 'X3D' # export_pdbs(dir = '/tmp/pdbfiles', # location of PDB files resolution = 3, export_format = 'VRML', export_suffix = '.vrml')