def test_log_targets(self): """Test python flags""" IMP.add_string_flag( "mystringflag", "mydefault", "Some string text") IMP.add_int_flag("myintflag", 3, "Some int text") IMP.add_bool_flag("myboolflag", "Some bool text") IMP.add_float_flag("myfloatflag", 10, "Some float text") extra = IMP.setup_from_argv(["python", "--mystringflag=hi", "--log_level=VERBOSE", "--myintflag=6", "--myfloatflag=-6.0", "--myboolflag", "zero", "one"], "test things", "arg0 arg1", 2) print(IMP.get_string_flag("mystringflag")) print(IMP.get_int_flag("myintflag")) print(IMP.get_float_flag("myfloatflag")) print(IMP.get_bool_flag("myboolflag")) print(IMP.get_log_level()) print(extra) self.assertEqual(IMP.get_string_flag("mystringflag"), "hi") self.assertEqual(IMP.get_int_flag("myintflag"), 6) self.assertEqual(IMP.get_float_flag("myfloatflag"), -6.0) self.assertEqual(IMP.get_bool_flag("myboolflag"), True) self.assertEqual(extra[0], "zero") self.assertEqual(extra[1], "one")
def test_log_targets(self): """Test python flags""" IMP.add_string_flag("mystringflag", "mydefault", "Some string text") IMP.add_int_flag("myintflag", 3, "Some int text") IMP.add_bool_flag("myboolflag", "Some bool text") IMP.add_float_flag("myfloatflag", 10, "Some float text") extra = IMP.setup_from_argv([ "python", "--mystringflag=hi", "--log_level=VERBOSE", "--myintflag=6", "--myfloatflag=-6.0", "--myboolflag", "zero", "one" ], "test things", "arg0 arg1", 2) print(IMP.get_string_flag("mystringflag")) print(IMP.get_int_flag("myintflag")) print(IMP.get_float_flag("myfloatflag")) print(IMP.get_bool_flag("myboolflag")) print(IMP.get_log_level()) print(extra) self.assertEqual(IMP.get_string_flag("mystringflag"), "hi") self.assertEqual(IMP.get_int_flag("myintflag"), 6) self.assertEqual(IMP.get_float_flag("myfloatflag"), -6.0) self.assertEqual(IMP.get_bool_flag("myboolflag"), True) self.assertEqual(extra[0], "zero") self.assertEqual(extra[1], "one")
def main(): IMP.add_string_flag("input_rmf", "", "The input RMF file.") IMP.add_string_flag("output_rmf", "", "The output RMF file in which to add cylinders.") IMP.add_string_flag( "ref_output", "", "reference output file from which info e.g. fg nup types can be extracted" ) IMP.add_float_flag("radius", 5, "The radius of the cylinder.") IMP.add_float_flag("site_radius", 2, "The radius of the sites.") IMP.add_bool_flag("recolor_fgs", "recolor fg nup chains") IMP.add_bool_flag("recolor_floats", "recolor floating (diffusing) molecules") IMP.add_int_flag( "smooth_n_frames", 1, "smooth by averaging over a window of specified frames (but retaining the same number of expected frames" ) IMP.add_int_flag("skip_n_frames", 1, "skip every n frames of output") IMP.setup_from_argv(sys.argv, "Prettify a movie") in_fname = IMP.get_string_flag("input_rmf") out_fname = IMP.get_string_flag("output_rmf") ref_output = IMP.get_string_flag("ref_output") radius = IMP.get_float_flag("radius") # Prepare out file with same static info as in file: in_fh = RMF.open_rmf_file_read_only(in_fname) out_fh = RMF.create_rmf_file(out_fname) print("creating file", out_fname) RMF.clone_file_info(in_fh, out_fh) RMF.clone_hierarchy(in_fh, out_fh) RMF.clone_static_frame(in_fh, out_fh) print("opened", in_fh.get_name()) cf = RMF.CylinderFactory(out_fh) rff = RMF.ReferenceFrameFactory(out_fh) tf = RMF.TypedFactory(out_fh) bf = RMF.BallFactory(out_fh) cdf = RMF.ColoredFactory(out_fh) ipf = RMF.IntermediateParticleFactory(out_fh) fg_types, kap_types, inert_types = _get_fg_and_floater_types(ref_output) # out_fh.set_current_frame(RMF.ALL_FRAMES) # Modify static information: if (IMP.get_bool_flag("recolor_floats")): _recolor(out_fh.get_root_node(), tf, cdf, kap_types, kap_color) _recolor(out_fh.get_root_node(), tf, cdf, inert_types, inert_color) _resize_sites(out_fh.get_root_node(), bf, IMP.get_float_flag("site_radius")) cylinders = [] for i, fg_type in enumerate(fg_types): color = IMP.display.get_display_color(i) rgb = [color.get_red(), color.get_green(), color.get_blue()] print("Checking fg type", fg_type) cylinders += _add_nodes(out_fh.get_root_node(), cf, cdf, tf, [fg_type], radius, rgb) # fg_color if (IMP.get_bool_flag("recolor_fgs")): # print "Recoloring",fg_type, rgb _recolor(out_fh.get_root_node(), tf, cdf, [fg_type], rgb) # fg_color # Clone and modify per-frame information: smooth_xyz_dict = {} smooth_n_frames = IMP.get_int_flag("smooth_n_frames") skip_n_frames = IMP.get_int_flag("skip_n_frames") print("Skip interval:", skip_n_frames, "frames") for f_id, f in enumerate(in_fh.get_frames()): is_write = f_id % skip_n_frames == 0 in_fh.set_current_frame(f) if not is_write: if (smooth_n_frames > 1): _smooth(in_fh.get_root_node(), tf, rff, smooth_xyz_dict, n=smooth_n_frames, is_write=False) print("skipping frame", f, f_id) continue print("cloning frame", f, f_id) out_fh.add_frame(in_fh.get_name(f), in_fh.get_type(f)) RMF.clone_loaded_frame(in_fh, out_fh) if (smooth_n_frames > 1): _smooth(out_fh.get_root_node(), tf, rff, smooth_xyz_dict, n=smooth_n_frames, is_write=True) for c in cylinders: _set_cylinder(c, cf, rff) if (IMP.get_bool_flag("recolor_fgs")): _recolor_cylinder(c, cf, cdf) DEBUG = False if DEBUG and f_id >= 5 * skip_n_frames: break
def main(): IMP.add_string_flag("input_rmf", "", "The input RMF file.") IMP.add_string_flag("output_rmf", "", "The output RMF file in which to add cylinders.") IMP.add_string_flag("ref_output", "", "reference output file from which info e.g. fg nup types can be extracted") IMP.add_float_flag("radius", 5, "The radius of the cylinder.") IMP.add_float_flag("site_radius", 2, "The radius of the sites.") IMP.add_bool_flag("recolor_fgs", "recolor fg nup chains") IMP.add_bool_flag("recolor_floats", "recolor floating (diffusing) molecules") IMP.add_int_flag("smooth_n_frames", 1, "smooth by averaging over a window of specified frames (but retaining the same number of expected frames") IMP.add_int_flag("skip_n_frames", 1, "skip every n frames of output") IMP.setup_from_argv(sys.argv, "Prettify a movie") in_fname= IMP.get_string_flag("input_rmf") out_fname= IMP.get_string_flag("output_rmf") ref_output = IMP.get_string_flag("ref_output") radius= IMP.get_float_flag("radius") # Prepare out file with same static info as in file: in_fh = RMF.open_rmf_file_read_only(in_fname) out_fh = RMF.create_rmf_file(out_fname) print("creating file", out_fname) RMF.clone_file_info(in_fh, out_fh) RMF.clone_hierarchy(in_fh, out_fh) RMF.clone_static_frame(in_fh, out_fh) print("opened", in_fh.get_name()) cf = RMF.CylinderFactory(out_fh) rff = RMF.ReferenceFrameFactory(out_fh) tf = RMF.TypedFactory(out_fh) bf = RMF.BallFactory(out_fh) cdf = RMF.ColoredFactory(out_fh) ipf = RMF.IntermediateParticleFactory(out_fh) fg_types, kap_types, inert_types = _get_fg_and_floater_types( ref_output ) # out_fh.set_current_frame(RMF.ALL_FRAMES) # Modify static information: if(IMP.get_bool_flag("recolor_floats")): _recolor(out_fh.get_root_node(), tf, cdf, kap_types, kap_color) _recolor(out_fh.get_root_node(), tf, cdf, inert_types, inert_color) _resize_sites(out_fh.get_root_node(), bf, IMP.get_float_flag("site_radius")) cylinders = [] for i, fg_type in enumerate(fg_types): color = IMP.display.get_display_color(i) rgb = [color.get_red(), color.get_green(), color.get_blue()] print("Checking fg type", fg_type) cylinders += _add_nodes(out_fh.get_root_node(), cf, cdf, tf, [fg_type], radius, rgb) # fg_color if(IMP.get_bool_flag("recolor_fgs")): # print "Recoloring",fg_type, rgb _recolor(out_fh.get_root_node(), tf, cdf, [fg_type], rgb) # fg_color # Clone and modify per-frame information: smooth_xyz_dict={} smooth_n_frames=IMP.get_int_flag("smooth_n_frames") skip_n_frames=IMP.get_int_flag("skip_n_frames") print("Skip interval:", skip_n_frames, "frames") for f_id, f in enumerate(in_fh.get_frames()): is_write= f_id % skip_n_frames == 0 in_fh.set_current_frame(f) if not is_write: if(smooth_n_frames>1): _smooth(in_fh.get_root_node(), tf, rff, smooth_xyz_dict, n=smooth_n_frames, is_write=False) print("skipping frame", f, f_id) continue print("cloning frame", f, f_id) out_fh.add_frame(in_fh.get_name(f), in_fh.get_type(f)) RMF.clone_loaded_frame(in_fh, out_fh) if(smooth_n_frames>1): _smooth(out_fh.get_root_node(), tf, rff, smooth_xyz_dict, n=smooth_n_frames, is_write=True) for c in cylinders: _set_cylinder(c, cf, rff) DEBUG=False if DEBUG and f_id >= 5*skip_n_frames: break
def main(): IMP.add_string_flag("input_rmf", "", "The input RMF file.") IMP.add_string_flag("output_pdb", "", "The output PDB file") IMP.add_string_flag("ref_output", "", "reference output file from which info e.g. fg nup types can be extracted") IMP.add_int_flag("skip_n_frames", 1, "skip every n frames of output; if 0, include only first frame") IMP.setup_from_argv(sys.argv, "Prettify a movie") in_fname= IMP.get_string_flag("input_rmf") out_fname= IMP.get_string_flag("output_pdb") ref_output = IMP.get_string_flag("ref_output") # Prepare out file with same static info as in file: in_fh = RMF.open_rmf_file_read_only(in_fname) rff = RMF.ReferenceFrameFactory(in_fh) tf = RMF.TypedFactory(in_fh) bf = RMF.BallFactory(in_fh) ipf = RMF.IntermediateParticleFactory(in_fh) fg_types, kap_types, inert_types = _get_fg_and_floater_types( ref_output ) type2chains={} for i, fg_type in enumerate(fg_types): print i, fg_type type2chains[fg_type] = _add_nodes(in_fh.get_root_node(), tf, [fg_type]) skip_n_frames=IMP.get_int_flag("skip_n_frames") if(skip_n_frames>0): print "Skip interval:", skip_n_frames, "frames" else: print "Showing only first frame" for f_id, f in enumerate(in_fh.get_frames()): is_write= (skip_n_frames==0) or (f_id%skip_n_frames == 0) in_fh.set_current_frame(f) if not is_write: print("skipping frame", f, f_id) continue fname= "%s_f%d.pdb" % (os.path.splitext(out_fname)[0],f_id) F= open(fname, 'w') # print("COMMENT writing frame", f, f_id) chain_id="A" atom_id=1 model_id=1 spoke_id=1 for fg_type, chains in type2chains.iteritems(): print >>F, "MODEL %d" % model_id for chain in chains: if chain_id=='I': # no more than 8 chains per model chain_id='A' print >>F, "ENDMDL" model_id=model_id+1 print >>F, "MODEL %d" % model_id for i,node in enumerate(chain): res_id=i+1 coord = rff.get(node).get_translation() print >>F, "ATOM %5d CA GLY %c%4d %8.2f%8.2f%8.2f 1.0 # %s" \ % (atom_id, chain_id, res_id, coord[0], coord[1], coord[2], fg_type + " spoke%d" % spoke_id) atom_id=atom_id+1 print >>F, "TER" chain_id=chr(ord(chain_id)+1) spoke_id = 1 + (spoke_id % 8) chain_id='A' print >>F, "ENDMDL" model_id=model_id+1 if skip_n_frames==0: break DEBUG=False if (DEBUG and f_id >= 5*skip_n_frames): break
def main(): IMP.add_string_flag("input_rmf", "", "The input RMF file.") IMP.add_string_flag("output_pdb", "", "The output PDB file") IMP.add_string_flag( "ref_output", "", "reference output file from which info e.g. fg nup types can be extracted" ) IMP.add_int_flag( "skip_n_frames", 1, "skip every n frames of output; if 0, include only first frame") IMP.add_int_flag("first_frame", 0, "start from speicifed frame") IMP.setup_from_argv(sys.argv, "Prettify a movie") in_fname = IMP.get_string_flag("input_rmf") out_fname = IMP.get_string_flag("output_pdb") ref_output = IMP.get_string_flag("ref_output") # Prepare out file with same static info as in file: in_fh = RMF.open_rmf_file_read_only(in_fname) rff = RMF.ReferenceFrameFactory(in_fh) tf = RMF.TypedFactory(in_fh) bf = RMF.BallFactory(in_fh) ipf = RMF.IntermediateParticleFactory(in_fh) fg_types, kap_types, inert_types = _get_fg_and_floater_types(ref_output) type2chains = {} print("fg_types", fg_types) for i, fg_type in enumerate(fg_types): type2chains[fg_type] = _add_nodes(in_fh.get_root_node(), tf, [fg_type]) print(type2chains[fg_type]) skip_n_frames = IMP.get_int_flag("skip_n_frames") first_frame = IMP.get_int_flag("first_frame") if (skip_n_frames > 0): print "Skip interval:", skip_n_frames, "frames" else: print "Showing only first frame" for f_id, f in enumerate(in_fh.get_frames()): is_write = (f_id >= first_frame) and ((skip_n_frames == 0) or (f_id % skip_n_frames == 0)) in_fh.set_current_frame(f) if not is_write: print("skipping frame", f, f_id) continue fname = "%s_f%05d.pdb" % (os.path.splitext(out_fname)[0], f_id) F = open(fname, 'w') print("COMMENT writing frame", f, f_id) chain_id = "A" atom_id = 1 model_id = 1 spoke_id = 1 for fg_type, chains in type2chains.iteritems(): print >> F, "MODEL %d" % model_id for chain in chains: print("Chain ", chain) if chain_id == 'I': # no more than 8 chains per model chain_id = 'A' print >> F, "ENDMDL" model_id = model_id + 1 print >> F, "MODEL %d" % model_id for i, node in enumerate(chain): res_id = i + 1 coord = rff.get(node).get_translation() print >>F, "ATOM %5d CA GLY %c%4d %8.2f%8.2f%8.2f 1.0 # %s" \ % (atom_id, chain_id, res_id, coord[0], coord[1], coord[2], fg_type + " spoke%d" % spoke_id) atom_id = atom_id + 1 print >> F, "TER" chain_id = chr(ord(chain_id) + 1) spoke_id = 1 + (spoke_id % 8) chain_id = 'A' print >> F, "ENDMDL" model_id = model_id + 1 if skip_n_frames == 0: break DEBUG = False if (DEBUG and f_id >= 5 * skip_n_frames): break