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
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
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
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
def get_particle_infos_for_pdb_writing(self, name, atomistic=False): # index_residue_pair_list={} # the resindexes dictionary keep track of residues that have been already # added to avoid duplication # highest resolution have highest priority resindexes_dict = {} # this dictionary dill contain the sequence of tuples needed to # write the pdb particle_infos_for_pdb = [] geometric_center = [0, 0, 0] atom_count = 0 atom_index = 0 for n, p in enumerate(impatom.get_leaves(self.dictionary_pdbs[name])): # this loop gets the protein name from the # particle leave by descending into the hierarchy (protname, is_a_bead) = IMP.pmi.tools.get_prot_name_from_particle( p, self.dictchain[name]) if protname not in resindexes_dict: resindexes_dict[protname] = [] if impatom.Atom.get_is_setup(p) and atomistic: atom_index += 1 residue = impatom.Residue(impatom.Atom(p).get_parent()) rt = residue.get_residue_type() resind = residue.get_index() atomtype = impatom.Atom(p).get_atom_type() xyz = list(IMP.core.XYZ(p).get_coordinates()) geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append( (xyz, atom_index, atomtype, rt, self.dictchain[name][protname], resind)) resindexes_dict[protname].append(resind) elif impatom.Residue.get_is_setup(p): residue = impatom.Residue(p) resind = residue.get_index() # skip if the residue was already added by atomistic resolution # 0 if resind in resindexes_dict[protname]: continue else: resindexes_dict[protname].append(resind) atom_index += 1 rt = residue.get_residue_type() xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append( (xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) # if protname not in index_residue_pair_list: # index_residue_pair_list[protname]=[(atom_index,resind)] # else: # index_residue_pair_list[protname].append((atom_index,resind)) elif impatom.Fragment.get_is_setup(p) and not is_a_bead: resindexes = IMP.pmi.tools.get_residue_indexes(p) resind = resindexes[len(resindexes) / 2] if resind in resindexes_dict[protname]: continue else: resindexes_dict[protname].append(resind) atom_index += 1 rt = impatom.ResidueType('BEA') xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append( (xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) else: if is_a_bead: atom_index += 1 rt = impatom.ResidueType('BEA') resindexes = IMP.pmi.tools.get_residue_indexes(p) resind = resindexes[len(resindexes) / 2] xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append( (xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) # if protname not in index_residue_pair_list: # index_residue_pair_list[protname]=[(atom_index,resind)] # else: # index_residue_pair_list[protname].append((atom_index,resind)) geometric_center = (geometric_center[0] / atom_count, geometric_center[1] / atom_count, geometric_center[2] / atom_count) return (particle_infos_for_pdb, geometric_center) '''