Esempio n. 1
0
def get_nucleic_acid_backbone(hierarchy, backbone='minimal'):
    """
        Returns the atoms in the backbone of the nucleic acid contained
        in the hierarchy.
        backbone 'minimal' returns the atoms: ["P", "O5'", "C5'", "C4'", "C3'", "O3'"]
        backbone 'trace' returns the atoms C4'
    """
    #    log.debug("get_nucleic_acid_backbone")
    backbone_atoms = []
    if backbone == 'minimal':
        backbone_atoms = ["P", "O5'", "C5'", "C4'", "C3'", "O3'"]
    elif backbone == 'trace':
        backbone_atoms = ["C4'"]
    else:
        raise ValueError("Wrong value for the type of backbone")
    backbone_atom_types = [atom.AtomType(t) for t in backbone_atoms]
    h_chains = atom.get_by_type(hierarchy, atom.CHAIN_TYPE)
    backbone = []
    if len(h_chains) > 1:
        raise ValueError("The hierarchy mas more than one chain")
    h_residues = atom.get_by_type(hierarchy, atom.RESIDUE_TYPE)
    for hr in h_residues:
        res = atom.Residue(hr)
        if not (res.get_is_dna() or res.get_is_rna()):
            raise ValueError("Residue is not part of a nucleic acid")
        h_atoms = atom.get_by_type(hr, atom.ATOM_TYPE)
        for at in h_atoms:
            if atom.Atom(at).get_atom_type() in backbone_atom_types:
                backbone.append(at)
    return backbone
Esempio n. 2
0
def get_nucleic_acid_backbone(hierarchy, backbone='minimal'):
    """
        Returns the atoms in the backbone of the nucleic acid contained
        in the hierarchy.
        backbone 'minimal' returns the atoms: ["P", "O5'", "C5'", "C4'", "C3'", "O3'"]
        backbone 'trace' returns the atoms C4'
    """
#    log.debug("get_nucleic_acid_backbone")
    backbone_atoms = []
    if backbone == 'minimal':
        backbone_atoms = ["P", "O5'", "C5'", "C4'", "C3'", "O3'"]
    elif backbone == 'trace':
        backbone_atoms = ["C4'"]
    else:
        raise ValueError("Wrong value for the type of backbone")
    backbone_atom_types = [atom.AtomType(t) for t in backbone_atoms]
    h_chains = atom.get_by_type(hierarchy, atom.CHAIN_TYPE)
    backbone = []
    if len(h_chains) > 1:
        raise ValueError("The hierarchy mas more than one chain")
    h_residues = atom.get_by_type(hierarchy, atom.RESIDUE_TYPE)
    for hr in h_residues:
        res = atom.Residue(hr)
        if not (res.get_is_dna() or res.get_is_rna()):
            raise ValueError("Residue is not part of a nucleic acid")
        h_atoms = atom.get_by_type(hr, atom.ATOM_TYPE)
        for at in h_atoms:
            if atom.Atom(at).get_atom_type() in backbone_atom_types:
                backbone.append(at)
    return backbone
Esempio n. 3
0
    def test__rigid_bodies_drms(self):
        """ Test drms measure taking into account rigid bodies"""
        m = IMP.Model()
        sel = atom.CAlphaPDBSelector()
        prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel)
        prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel)

        hchains1 = atom.get_by_type(prot1, atom.CHAIN_TYPE)
        hchains2 = atom.get_by_type(prot2, atom.CHAIN_TYPE)
        xyzs1 = core.XYZs(atom.get_leaves(prot1))
        xyzs2 = core.XYZs(atom.get_leaves(prot2))
        x = 0
        ranges = []
        for h in hchains1:
            ls1 = (atom.get_leaves(h))
            y = x + len(ls1)
            ranges.append((x, y))
            x = y
        drms = atom.get_drms(xyzs1, xyzs2)
        rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges)
        self.assertAlmostEqual(rb_drms, 0)
        self.assertAlmostEqual(drms, rb_drms, delta=1e-3, msg="rb_drms != drms")
        # Same thing after transformation of each of the chains
        for h in hchains2:
            R = alg.get_random_rotation_3d()
            v = alg.get_random_vector_in(alg.get_unit_bounding_box_3d())
            T = alg.Transformation3D(R, v)
            ls = atom.get_leaves(h)
            for l in ls:
                core.transform(l.get_as_xyz(), T)
        drms = atom.get_drms(xyzs1, xyzs2)
        rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges)
        self.assertAlmostEqual(drms, rb_drms, delta=0.3, msg="rb_drms != drms")
Esempio n. 4
0
def get_native_model_info(fn_pdb1):
    """
        Fills the information for the native structure
    """
    model_info = ModelInfo()
    sel = atom.ATOMPDBSelector()
    m1 = IMP.Model()
    hierarchy1 =  atom.read_pdb(fn_pdb1, m1, sel)
    sel = atom.CAlphaPDBSelector()
    malphas1 = IMP.Model()
    alphas1 =  atom.read_pdb(fn_pdb1, malphas1, sel)
    axyzs1 = [core.XYZ(l) for l in atom.get_leaves(alphas1)]
    model_info.rmsd_calpha = 0.0
    model_info.drms_alpha = 0.0
    model_info.rmsd = 0.0
    model_info.nat_over = 100.
    xyzs1 = [core.XYZ(l) for l in atom.get_leaves(hierarchy1)]
    model_info.radius_g = atom.get_radius_of_gyration(xyzs1)
    h_chains1 = atom.get_by_type(hierarchy1, atom.CHAIN_TYPE)
    for hc1 in h_chains1:
        ch1 = atom.Chain(hc1)
        chain_info = ChainInfo()
        chain_info.chain_id = ch1.get_id()
        chain_info.placement_distance = 0.0
        chain_info.placement_angle = 0.0
        chain_info.rmsd =  0.0
        native_overlap_threshold = 10
        chain_info.nat_over = 0.0
        chain_info.model_id = -1
        model_info.chains_infos.append(chain_info)
    model_info.model_id = -1
    return model_info
Esempio n. 5
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.
    """
    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)
        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 CA %s", ranges, len(calphas1))

    xyzs = [core.XYZ(l) for l in backbone]
    native_chains = atom.get_by_type(native_assembly, atom.CHAIN_TYPE)
    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")
    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(native_assembly, "drms_filtering_calphas.pdb")
        raise ValueError("There is a problem with the drms")
    return drms
Esempio n. 6
0
def get_all_chains(hierarchies):
    """ Gets all the chains in a set of hierarchies
        @param hierarchies A set of IMP.atom.Hierarchy objects
    """
    chains = []
    for h in hierarchies:
        chains_in_h = atom.get_by_type(h, atom.CHAIN_TYPE)
        for ch in chains_in_h:
            chains.append(ch.get_as_chain())
    return chains
Esempio n. 7
0
def get_all_chains(hierarchies):
    """ Gets all the chains in a set of hierarchies
        @param hierarchies A set of IMP.atom.Hierarchy objects
    """
    chains=[]
    for h in hierarchies:
        chains_in_h = atom.get_by_type(h, atom.CHAIN_TYPE)
        for ch in chains_in_h:
            chains.append(ch.get_as_chain())
    return chains
Esempio n. 8
0
    def test__rigid_bodies_drms(self):
        """ Test drms measure taking into account rigid bodies"""
        m = IMP.kernel.Model()
        sel = atom.CAlphaPDBSelector()
        prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel)
        prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel)

        hchains1 = atom.get_by_type(prot1, atom.CHAIN_TYPE)
        hchains2 = atom.get_by_type(prot2, atom.CHAIN_TYPE)
        xyzs1 = core.XYZs(atom.get_leaves(prot1))
        xyzs2 = core.XYZs(atom.get_leaves(prot2))
        x = 0
        ranges = []
        for h in hchains1:
            ls1 = (atom.get_leaves(h))
            y = x + len(ls1)
            ranges.append((x, y))
            x = y
        drms = atom.get_drms(xyzs1, xyzs2)
        rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges)
        self.assertAlmostEqual(rb_drms, 0)
        self.assertAlmostEqual(
            drms,
            rb_drms,
            delta=1e-3,
            msg="rb_drms != drms")
        # Same thing after transformation of each of the chains
        for h in hchains2:
            R = alg.get_random_rotation_3d()
            v = alg.get_random_vector_in(alg.get_unit_bounding_box_3d())
            T = alg.Transformation3D(R, v)
            ls = atom.get_leaves(h)
            for l in ls:
                core.transform(l.get_as_xyz(), T)
        drms = atom.get_drms(xyzs1, xyzs2)
        rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges)
        self.assertAlmostEqual(drms, rb_drms, delta=0.3, msg="rb_drms != drms")
Esempio n. 9
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.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.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
Esempio n. 10
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
Esempio n. 11
0
def get_backbone(hierarchy):
    """
        Get the backbone atoms for a hierarchy. It can be a protein or a
        nucleic acid
    """
    h_residues = atom.get_by_type(hierarchy, atom.RESIDUE_TYPE)
    if len(h_residues) == 0:
        raise ValueError("No residues!")
    atoms = []
    res = atom.Residue(h_residues[0])
    if res.get_is_dna() or res.get_is_rna():
        atoms = get_nucleic_acid_backbone(hierarchy, 'trace')
    else:
        atoms = get_calphas(hierarchy)
    return atoms
Esempio n. 12
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
Esempio n. 13
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
Esempio n. 14
0
def get_backbone(hierarchy):
    """
        Get the backbone atoms for a hierarchy. It can be a protein or a
        nucleic acid
    """
    h_residues = atom.get_by_type(hierarchy, atom.RESIDUE_TYPE)
    if len(h_residues) == 0:
        raise ValueError("No residues!")
    atoms = []
    res = atom.Residue(h_residues[0])
    if res.get_is_dna() or res.get_is_rna():
        atoms = get_nucleic_acid_backbone(hierarchy, 'trace')
    else:
        atoms = get_calphas(hierarchy)
    return atoms
Esempio n. 15
0
def create_simplified_dna(dna_hierarchy, n_res):
    """ Gets a hierarchy containing a molecule of DNA and simplifies it,
        generating a coarse representation of spheres. The function returns
        a hierarchy with the spheres.
        n_res - Number of residues to use per sphere.
    """
    chain = dna_hierarchy.get_as_chain()
    if (not chain.get_is_valid(True)):
        raise TypeError(
            "create_simplified_dna: the hierarchy provided is not a "
            "chain.")

    model = dna_hierarchy.get_model()
    ph = IMP.kernel.Particle(model)
    simplified_h = atom.Hierarchy.setup_particle(ph)
    atom.Chain.setup_particle(ph, "0")

    residues = atom.get_by_type(dna_hierarchy, atom.RESIDUE_TYPE)
    l = len(residues)
    # print "the DNA has ",l,"residues"
    for i in range(0, l, n_res):
        xyzrs = []
        equivalent_mass = 0.0
        residues_numbers = []
        for r in residues[i:i + n_res]:
            rr = atom.Residue(r)
            residues_numbers.append(rr.get_index())
            # print "residue",rr.get_name(),rr.get_index()
            residue_xyzrs = [
                core.XYZ(a.get_particle()) for a in rr.get_children()
            ]
            xyzrs += residue_xyzrs
            #            print "residue",r,"mass",get_residue_mass(r)
            equivalent_mass += get_residue_mass(r)

        s = core.get_enclosing_sphere(xyzrs)
        p = IMP.kernel.Particle(model)
        xyzr = core.XYZR.setup_particle(p)
        xyzr.set_radius(s.get_radius())
        xyzr.set_coordinates(s.get_center())
        fragment = atom.Fragment.setup_particle(p)
        fragment.set_residue_indexes(residues_numbers)
        atom.Mass.setup_particle(p, equivalent_mass)
        simplified_h.add_child(fragment)
    simplified_h.set_name("DNA")
    #    print "simplified_h is valid:",simplified_h.get_is_valid(True)
    return simplified_h
Esempio n. 16
0
def create_simplified_dna(dna_hierarchy, n_res):
    """ Gets a hierarchy containing a molecule of DNA and simplifies it,
        generating a coarse representation of spheres. The function returns
        a hierarchy with the spheres.
        n_res - Number of residues to use per sphere.
    """
    chain = dna_hierarchy.get_as_chain()
    if(not chain.get_is_valid(True)):
        raise TypeError("create_simplified_dna: the hierarchy provided is not a "
                        "chain.")

    model = dna_hierarchy.get_model()
    ph = IMP.Particle(model)
    simplified_h = atom.Hierarchy.setup_particle(ph)
    atom.Chain.setup_particle(ph, "0")

    residues = atom.get_by_type(dna_hierarchy, atom.RESIDUE_TYPE)
    l = len(residues)
    # print "the DNA has ",l,"residues"
    for i in range(0, l, n_res):
        xyzrs = []
        equivalent_mass = 0.0
        residues_numbers = []
        for r in residues[i: i + n_res]:
            rr = atom.Residue(r)
            residues_numbers.append(rr.get_index())
            # print "residue",rr.get_name(),rr.get_index()
            residue_xyzrs = [core.XYZ(a.get_particle())
                             for a in rr.get_children()]
            xyzrs += residue_xyzrs
#            print "residue",r,"mass",get_residue_mass(r)
            equivalent_mass += get_residue_mass(r)

        s = core.get_enclosing_sphere(xyzrs)
        p = IMP.Particle(model)
        xyzr = core.XYZR.setup_particle(p)
        xyzr.set_radius(s.get_radius())
        xyzr.set_coordinates(s.get_center())
        fragment = atom.Fragment.setup_particle(p)
        fragment.set_residue_indexes(residues_numbers)
        atom.Mass.setup_particle(p, equivalent_mass)
        simplified_h.add_child(fragment)
    simplified_h.set_name("DNA")
#    print "simplified_h is valid:",simplified_h.get_is_valid(True)
    return simplified_h
Esempio n. 17
0
def get_coarse_selection(coarse_h, residues_numbers):
    """ The function returns the particles (fragments) in the coarse hierarchy
        that were created by summarizing the residues_numbers.

        Coarse hierarchy - Hierarchy formed by a bunch of
        fragments. Each fragment must have the residue numbers that it contains
        residue_numbers - list with the number of the residues that need to
        be recovered.
        The function returns the set of particles that are atom.Fragments
    """
    particles = []
    fragments =  atom.get_by_type(coarse_h, atom.FRAGMENT_TYPE)
    for f in fragments:
        ff = atom.Fragment(f)
        residues_in_f = ff.get_residue_indexes()
        for number in residues_in_f:
            if number in residues_numbers:
                particles.append( ff.get_particle() )
                break
    return particles
Esempio n. 18
0
def get_coarse_selection(coarse_h, residues_numbers):
    """ The function returns the particles (fragments) in the coarse hierarchy
        that were created by summarizing the residues_numbers.

        Coarse hierarchy - Hierarchy formed by a bunch of
        fragments. Each fragment must have the residue numbers that it contains
        residue_numbers - list with the number of the residues that need to
        be recovered.
        The function returns the set of particles that are atom.Fragments
    """
    particles = []
    fragments = atom.get_by_type(coarse_h, atom.FRAGMENT_TYPE)
    for f in fragments:
        ff = atom.Fragment(f)
        residues_in_f = ff.get_residue_indexes()
        for number in residues_in_f:
            if number in residues_numbers:
                particles.append(ff.get_particle())
                break
    return particles
Esempio n. 19
0
def get_calphas(chain_hierarchy):
    h_residues = atom.get_by_type(chain_hierarchy, atom.RESIDUE_TYPE)
    cas = [atom.get_atom(atom.Residue(r), atom.AtomType("CA"))
                                                        for r in h_residues]
    return cas
Esempio n. 20
0
def get_calphas(chain_hierarchy):
    h_residues = atom.get_by_type(chain_hierarchy, atom.RESIDUE_TYPE)
    cas = [
        atom.get_atom(atom.Residue(r), atom.AtomType("CA")) for r in h_residues
    ]
    return cas
Esempio n. 21
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
Esempio n. 22
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
Esempio n. 23
0
        m.show_all_statistics()
        #for i in range(0,m.get_number_of_restraints()):
        #    r=m.get_restraint(i)
        #    print "restraint",r.get_name(),"value",r.evaluate(False)
    def do_show(self, stream):
        print >> stream, ps


# Get model from PDB file
IMP.base.set_log_level(IMP.base.TERSE)
m = IMP.Model()
prot =  atom.read_pdb(em2d.get_example_path("1z5s.pdb"),m,atom.ATOMPDBSelector())
atom.add_radii(prot)

# get the chains
chains = atom.get_by_type(prot,atom.CHAIN_TYPE)
print "there are",len(chains),"chains in 1z5s.pdb"

# set the chains as rigid bodies
native_chain_centers = []
rigid_bodies= []
for c in chains:
    atoms=core.get_leaves(c)
    rbd=core.RigidBody.setup_particle(c,atoms)
    rigid_bodies.append(rbd)
    print "chain has",rbd.get_number_of_members(), \
                          "atoms","coordinates: ",rbd.get_coordinates()
    native_chain_centers.append(rbd.get_coordinates())

bb=alg.BoundingBox3D(alg.Vector3D(-25, -40,-60),
                         alg.Vector3D( 25,  40, 60))