Exemplo n.º 1
0
def create_simplified_assembly(assembly, components_rbs, n_res):
    """ Simplifies an assembly, by creating a hierarchy with one ball per
        n_res residues. Each of the chains in the new hierarchy are added to
        the rigid bodies for each of the components.
        There must be correspondence between the children of the assembly
        (components) and the rigid bodies. I check for the ids.
    """
    molecule = assembly.get_as_molecule()
    if (not molecule.get_is_valid(True)):
        raise TypeError("The argument is not a valid  hierarchy")

    model = assembly.get_model()
    n_children = molecule.get_number_of_children()

    sh = IMP.kernel.Particle(model)
    simplified_hierarchy = atom.Molecule.setup_particle(sh)

    for i in range(n_children):  # for all members of the assembly
        component = molecule.get_child(i)
        name = component.get_name()
        rb = components_rbs[i]
        if (rb.get_name() != get_rb_name(name)):
            raise ValueError("Rigid body and component do not match")

        hchains = atom.get_by_type(component, atom.CHAIN_TYPE)
        ch = IMP.kernel.Particle(model)
        coarse_component_h = atom.Molecule.setup_particle(ch)
        # simplify all the chains in the member
        for h in hchains:
            chain = atom.Chain(h.get_particle())
            coarse_h = None
            if (name == "DNA"):
                # print "simplifying DNA"
                coarse_h_particle = create_simplified_dna(h, n_res)
                coarse_h = atom.Hierarchy(coarse_h_particle)
            else:
                coarse_h = atom.create_simplified_along_backbone(chain, n_res)

            # does not work for DNA
            chain_rb = atom.create_rigid_body(coarse_h)
            # chain_rb = atom.setup_as_rigid_body(coarse_h) # works with DNA
            chain_rb.set_name("sub_rb" + name)
            rb.add_member(chain_rb)

            # are required to have excluded volume
            coarse_component_h.add_child(atom.Chain(coarse_h))
        coarse_component_h.set_name(name)
        simplified_hierarchy.add_child(coarse_component_h)
    return simplified_hierarchy
Exemplo n.º 2
0
def create_assembly_from_pdb(model, fn_pdb, names=False):
    """
        Builds the assembly setting the chains in the PDB file as components
    """
    temp = read_component(model, fn_pdb)
    hchains = atom.get_by_type(temp, atom.CHAIN_TYPE)
    ids = [atom.Chain(h).get_id() for h in hchains]
    log.debug("Creating assembly from pdb %s,names: %s. Chains %s", fn_pdb,
              names, ids)
    atom.add_radii(temp)
    if (names):
        for i, h in enumerate(hchains):
            h.set_name(names[i])
    assembly = IMP.atom.Molecule.setup_particle(temp)
    return assembly
Exemplo n.º 3
0
def rename_chains(assembly):
    """ Rename all the chains of an assembly so there are no conflicts with
        the ids. The names are added sequentially.
    """
    m = assembly.get_as_molecule()
    if (not m.get_is_valid(True)):
        raise TypeError("The argument is not a valid  hierarchy")
    all_chains_as_hierarchies = get_all_chains(m.get_children())
    letters = string.ascii_uppercase
    n_chains = len(all_chains_as_hierarchies)
    if (len(letters) < n_chains):
        raise ValueError("There are more chains than letter ids")
    ids = letters[0:n_chains]
    for h, c_id in zip(all_chains_as_hierarchies, ids):
        chain = atom.Chain(h.get_particle())
        chain.set_id(c_id)
        chain.set_name("chain %s" % c_id)
Exemplo n.º 4
0
def show_model_info(model, assembly, components_rbs):
    """ Prints information about the representation
        Prints the number of components (hierarchies), its children,
        and information about the chains and rigid bodies
    """
    print(
        "##################################################################################"
    )
    print("Model Info")
    print(
        "##################################################################################"
    )

    print(model.show())
    print("#########################")
    print("Hierarchies in the assembly:")
    print("#########################")
    for c in assembly.get_children():
        print(c.get_name() + " Is valid? " + c.get_is_valid(True) +
              " children " + str(c.get_number_of_children()))
        print("Child info: " + c.show())

        hchains = IMP.atom.get_by_type(c, IMP.atom.CHAIN_TYPE)
        print("Number of chains in the hierarchy: %d" % len(hchains))
        for h in hchains:
            chain = atom.Chain(h.get_particle())
            print(chain.get_name() +
                  " particles %d" % len(atom.get_leaves(chain)))
    print("#########################")
    print("Rigid bodies")
    print("#########################")
    for r in components_rbs:
        print("rigid body: Particles: %d coordinates: %s" %
              (r.get_number_of_members(), r.get_coordinates()))

    print("#########################")
    print("Restraints")
    print("#########################")
    n = model.get_number_of_restraints()
    for i in range(n):
        print(model.get_restraint(i))
Exemplo n.º 5
0
Arquivo: io.py Projeto: sirusb/imp
def show_model_info(model, assembly, components_rbs):
    """ Prints information about the representation
        Prints the number of components (hierarchies), its children,
        and information about the chains and rigid bodies
    """
    print "##################################################################################"
    print "Model Info"
    print "##################################################################################"

    print model.show()
    print "#########################"
    print "Hierarchies in the assembly:"
    print "#########################"
    for c in assembly.get_children():
        print c.get_name(), "Is valid?", c.get_is_valid(
            True), "children", c.get_number_of_children()
        print "Child info: ", c.show()

        hchains = IMP.atom.get_by_type(c, IMP.atom.CHAIN_TYPE)
        print "Number of chains in the hierarchy:", len(hchains)
        for h in hchains:
            chain = atom.Chain(h.get_particle())
            print chain.get_name(), "particles", len(atom.get_leaves(chain))
    print "#########################"
    print "Rigid bodies"
    print "#########################"
    for r in components_rbs:
        print "rigid body: Particles:", r.get_number_of_members(),
        print "coordinates:", r.get_coordinates()

    print "#########################"
    print "Restraints"
    print "#########################"
    n = model.get_number_of_restraints()
    for i in range(n):
        print model.get_restraint(i)
Exemplo n.º 6
0
def get_drms_for_backbone(assembly, native_assembly):
    """
        Measure the DRMS ob the backbone between two assemblies.
        @param assembly The DRMS is computed for this assembly
        @param native_assembly The assembly that acts as a reference

       Notes:
          1) The components of the assembly can be proteins or nucleic acids
          2) If a protein, the c-alphas are used for calculating the drms
          3) If a nucleic acid, the backbone of C4' atoms is used
          4) The chains are treated as rigid bodies to speed the calculation.

        WARNING: if the function fails with a segmentation fault, one of the
        possible problems is that IMP reads some HETATM as calphas. Check that
        the chain does not have heteroatoms.
    """
    log.debug("Measuring DRMS of the backbone")
    begin_range = 0
    ranges = []
    backbone = []
    h_chains = atom.get_by_type(assembly, atom.CHAIN_TYPE)
    for h in h_chains:
        atoms = representation.get_backbone(h)
        """"
        for a in atoms:
            print "atom ===> ",
            at = atom.Atom(a)
            hr = at.get_parent()
            res = atom.Residue(hr)
            ch = atom.Chain(h)
            ch.show()
            print " - ",
            res.show()
            print " - ",
            at.show()
            print ""
        """
        backbone.extend(atoms)
        end_range = begin_range + len(atoms)
        ranges.append((begin_range, end_range))
        begin_range = end_range
    log.debug("Ranges %s number of atoms %s", ranges, len(backbone))
    xyzs = [core.XYZ(l) for l in backbone]
    native_chains = atom.get_by_type(native_assembly, atom.CHAIN_TYPE)
    names = [atom.Chain(ch).get_id() for ch in native_chains]
    native_backbone = []
    for h in native_chains:
        native_backbone.extend(representation.get_backbone(h))
    native_xyzs = [core.XYZ(l) for l in native_backbone]
    if len(xyzs) != len(native_xyzs):
        raise ValueError(
            "Cannot compute DRMS for sets of atoms of different size")
    log.debug("Getting rigid bodies rmsd")
    drms = atom.get_rigid_bodies_drms(xyzs, native_xyzs, ranges)
    if drms < 0 or math.isnan(drms):  # or drms > 100:
        log.debug(
            "len(xyzs) = %s. len(native_xyzs) = %s",
            len(xyzs),
            len(native_xyzs))
        log.debug("drms = %s", drms)
        atom.write_pdb(assembly, "drms_model_calphas.pdb")
        atom.write_pdb(native_assembly, "drms_native_calphas.pdb")
        raise ValueError("There is a problem with the drms. I wrote the pdbs "
                         "for you: drms_model_calphas.pdb drms_native_calphas.pdb")
    return drms