예제 #1
0
 def __init__(self, fh, diameter):
     self.atom_factory = RMF.AtomFactory(fh)
     self.bond_factory = RMF.BondFactory(fh)
     self.particle_factory = RMF.ParticleFactory(fh)
     self.ball_factory = RMF.BallFactory(fh)
     self.segment_factory = RMF.SegmentFactory(fh)
     self.cylinder_factory = RMF.CylinderFactory(fh)
     self.diameter = diameter * 1.5
예제 #2
0
def main():
    IMP.base.add_string_flag("input", "", "The RMF file to add cylinders to.")
    IMP.base.add_float_flag("radius", 5, "The radius of the cylinder.")
    IMP.base.add_float_flag("site_radius", 2, "The radius of the sites.")
    IMP.base.add_bool_flag("recolor_fgs", "recolor fg nup chains")
    IMP.base.add_bool_flag("recolor_floats",
                           "recolor floating (diffusing) molecules")
    IMP.base.setup_from_argv(sys.argv, "Prettify a movie")
    fh = RMF.open_rmf_file(IMP.base.get_string_flag("input"))
    radius = IMP.base.get_float_flag("radius")
    print "opened", fh.get_name()
    cf = RMF.CylinderFactory(fh)
    rff = RMF.ReferenceFrameFactory(fh)
    tf = RMF.TypedFactory(fh)
    bf = RMF.BallFactory(fh)
    cdf = RMF.ColoredFactory(fh)
    ipf = RMF.IntermediateParticleFactory(fh)
    fg_types = [
        IMP.npctransport.get_type_of_fg(i).get_string()
        for i in range(0, IMP.npctransport.get_number_of_types_of_fg())
    ]
    float_types = [
        IMP.npctransport.get_type_of_float(i).get_string()
        for i in range(0, IMP.npctransport.get_number_of_types_of_float())
    ]
    fh.set_current_frame(RMF.ALL_FRAMES)

    if (IMP.base.get_bool_flag("recolor_fgs")):
        _recolor(fh.get_root_node(), tf, cdf, fg_types, fg_color)
    if (IMP.base.get_bool_flag("recolor_floats")):
        _recolor(fh.get_root_node(), tf, cdf, float_types[0:1], kap_color)
        _recolor(fh.get_root_node(), tf, cdf, float_types[1:], crap_color)

    _resize_sites(fh.get_root_node(), bf,
                  IMP.base.get_float_flag("site_radius"))

    cylinders = _add_nodes(fh.get_root_node(), cf, cdf, tf, fg_types, radius,
                           fg_color)
    for i in range(0, fh.get_number_of_frames()):
        print "frame", i
        fh.set_current_frame(i)
        for c in cylinders:
            _set_cylinder(c, cf, rff)
예제 #3
0
## \example reference_frame_particle.py
# This simple example makes an RMF file with several rigid copies of the
# same thing
from __future__ import print_function
import RMF

file_name = RMF._get_temporary_file_path("reference_frame.rmfz")
print("file is", file_name)
fh = RMF.create_rmf_file(file_name)
fh.add_frame("first frame", RMF.FRAME)

rh = fh.get_root_node()

reference_frame_factory = RMF.ReferenceFrameFactory(fh)
ball_factory = RMF.BallFactory(fh)
particle_factory = RMF.ParticleFactory(fh)
color_factory = RMF.ColoredFactory(fh)
bond_factory = RMF.BondFactory(fh)

origin = rh.add_child("origin", RMF.REPRESENTATION)
pd = particle_factory.get(origin)
pd.set_radius(1)
pd.set_mass(2)
pd.set_coordinates(RMF.Vector3(0, 0, 0))

for i in range(0, 3):
    c = rh.add_child(str(i), RMF.REPRESENTATION)
    pd = particle_factory.get(c)
    pd.set_radius(1)
    pd.set_mass(2)
    coords = [0, 0, 0]
예제 #4
0
## \example geometry.py
# Show creation of geometry in an RMF

from __future__ import print_function
import RMF

tfn = RMF._get_temporary_file_path("aliases.rmf")
print("File is", tfn)

f = RMF.create_rmf_file(tfn)
f.add_frame("root", RMF.FRAME)

r = f.get_root_node()

bf = RMF.BallFactory(f)
cf = RMF.CylinderFactory(f)
sf = RMF.SegmentFactory(f)

b = bf.get(r.add_child("ball", RMF.GEOMETRY))
b.set_radius(1)
b.set_coordinates(RMF.Vector3(0, 0, 0))

c = cf.get(r.add_child("cylinder", RMF.GEOMETRY))
c.set_radius(.5)
c.set_coordinates_list([RMF.Vector3(0, 0, 0), RMF.Vector3(5, 5, 5)])
예제 #5
0
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
예제 #6
0
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
예제 #7
0
    if reference_frame_factory.get_is(node):
        reference_frame = RMF.CoordinateTransformer(
            reference_frame, reference_frame_factory.get(node))
        print("reference frame is now", reference_frame)
    elif segment_factory.get_is(node):
        segment = segment_factory.get(node)
        print("segment", node.get_name())
        # silliness
        coords = segment.get_coordinates()
        for i in range(0, len(coords[0])):
            print_coordinates(reference_frame,
                              [coords[0][i], coords[1][i], coords[2][i]])
    elif particle_factory.get_is(node):
        particle = particle_factory.get(node)
        print("particle", node.get_name(),
              print_coordinates(reference_frame, particle.get_coordinates()))
    elif ball_factory.get_is(node):
        particle = ball_factory.get(node)
        print("ball", node.get_name(),
              print_coordinates(reference_frame, particle.get_coordinates()))
    for c in node.get_children():
        visit(c, reference_frame, reference_frame_factory, particle_factory,
              segment_factory, ball_factory)


fh = RMF.open_rmf_file_read_only(RMF.get_example_path("reference_frames.rmf3"))

visit(fh.get_root_node(), RMF.CoordinateTransformer(),
      RMF.ReferenceFrameFactory(fh), RMF.ParticleFactory(fh),
      RMF.SegmentFactory(fh), RMF.BallFactory(fh))