1 """@namespace IMP.EMageFit.imp_general.representation
2 Utility functions to handle representation.
15 log = logging.getLogger(
"representation")
20 Functions to deal with the representation of assemblies and managing
29 Builds the assembly setting the chains in the PDB file as components
32 hchains = atom.get_by_type(temp, atom.CHAIN_TYPE)
33 ids = [
atom.Chain(h).get_id()
for h
in hchains]
34 log.debug(
"Creating assembly from pdb %s,names: %s. Chains %s",
38 for i, h
in enumerate(hchains):
45 """ Read all the PDBs given in the list of names fn_pdbs and adds the
46 hierarchies to the model
49 for i, fn_pdb
in enumerate(fn_pdbs):
54 assembly.add_child(prot)
59 """ Read a PDB molecule, add atoms, and set a name
62 log.debug(
"reading component %s from %s", name, fn_pdb)
64 log.debug(
"reading component from %s", fn_pdb)
66 hierarchy = atom.read_pdb(fn_pdb, model,
69 hierarchy.set_name(name)
70 atom.add_radii(hierarchy)
75 """ set the children of a molecule type hierarchy as rigid bodies
76 In this case, all the children are the components of the complex.
77 I use the function create_rigid_body(), that creates a lot of
80 I have changed the function and now build the rigid body directly from
81 the leaves of each of the components. With this I guarantee that the
82 number of rigid members is going to be the same if the components have
83 the same number of atoms.
85 molecule = assembly.get_as_molecule()
86 if(
not molecule.get_is_valid(
True)):
87 raise TypeError(
"create_rigid_bodies(): The argument is not a valid "
90 for c
in molecule.get_children():
92 core.RigidBody.setup_particle(p, atom.get_leaves(c))
101 """ Rename all the chains of an assembly so there are no conflicts with
102 the ids. The names are added sequentially.
104 m = assembly.get_as_molecule()
105 if(
not m.get_is_valid(
True)):
106 raise TypeError(
"The argument is not a valid hierarchy")
108 letters = string.ascii_uppercase
109 n_chains = len(all_chains_as_hierarchies)
110 if(len(letters) < n_chains):
111 raise ValueError(
"There are more chains than letter ids")
112 ids = letters[0:n_chains]
113 for h, c_id
in zip(all_chains_as_hierarchies, ids):
116 chain.set_name(
"chain %s" % c_id)
120 """ Gets a hierarchy containing a molecule of DNA and simplifies it,
121 generating a coarse representation of spheres. The function returns
122 a hierarchy with the spheres.
123 n_res - Number of residues to use per sphere.
125 chain = dna_hierarchy.get_as_chain()
126 if(
not chain.get_is_valid(
True)):
127 raise TypeError(
"create_simplified_dna: the hierarchy provided is not a "
130 model = dna_hierarchy.get_model()
132 simplified_h = atom.Hierarchy.setup_particle(ph)
133 atom.Chain.setup_particle(ph,
"0")
135 residues = atom.get_by_type(dna_hierarchy, atom.RESIDUE_TYPE)
138 for i
in range(0, l, n_res):
140 equivalent_mass = 0.0
141 residues_numbers = []
142 for r
in residues[i: i + n_res]:
144 residues_numbers.append(rr.get_index())
146 residue_xyzrs = [
core.XYZ(a.get_particle())
147 for a
in rr.get_children()]
148 xyzrs += residue_xyzrs
150 equivalent_mass += get_residue_mass(r)
152 s = core.get_enclosing_sphere(xyzrs)
154 xyzr = core.XYZR.setup_particle(p)
155 xyzr.set_radius(s.get_radius())
156 xyzr.set_coordinates(s.get_center())
157 fragment = atom.Fragment.setup_particle(p)
158 fragment.set_residue_indexes(residues_numbers)
159 atom.Mass.setup_particle(p, equivalent_mass)
160 simplified_h.add_child(fragment)
161 simplified_h.set_name(
"DNA")
166 def get_residue_mass(residue):
167 r = residue.get_as_residue()
168 if(r.get_is_valid(
True) ==
False):
169 raise TypeError(
"The argument is not a residue")
171 for l
in atom.get_leaves(r):
173 mass += ms.get_residue_mass()
178 """ Simplifies an assembly, by creating a hierarchy with one ball per
179 n_res residues. Each of the chains in the new hierarchy are added to
180 the rigid bodies for each of the components.
181 There must be correspondence between the children of the assembly
182 (components) and the rigid bodies. I check for the ids.
184 molecule = assembly.get_as_molecule()
185 if(
not molecule.get_is_valid(
True)):
186 raise TypeError(
"The argument is not a valid hierarchy")
188 model = assembly.get_model()
189 n_children = molecule.get_number_of_children()
192 simplified_hierarchy = atom.Molecule.setup_particle(sh)
194 for i
in range(n_children):
195 component = molecule.get_child(i)
196 name = component.get_name()
197 rb = components_rbs[i]
199 raise ValueError(
"Rigid body and component do not match")
201 hchains = atom.get_by_type(component, atom.CHAIN_TYPE)
203 coarse_component_h = atom.Molecule.setup_particle(ch)
213 coarse_h = atom.create_simplified_along_backbone(chain, n_res)
216 chain_rb = atom.create_rigid_body(coarse_h)
218 chain_rb.set_name(
"sub_rb" + name)
219 rb.add_member(chain_rb)
222 coarse_component_h.add_child(
atom.Chain(coarse_h))
223 coarse_component_h.set_name(name)
224 simplified_hierarchy.add_child(coarse_component_h)
225 return simplified_hierarchy
229 """ Select a component of the assembly using the name """
230 for c
in assembly.get_children():
231 if (c.get_name() == name):
234 "The requested component %s is not in the assembly" %
239 """ Select a rigid body from the rigid_bodies using the name """
240 for rb
in rigid_bodies:
241 if (rb.get_name() == name):
243 raise ValueError(
"This rigid body is not in the set: %s" % name)
247 """ Name to use for the rigid body of a hierarch"""
252 """ Build the rigid body for all the particles in the selection S """
253 ps = S.get_selected_particles()
256 rbS = core.RigidBody.setup_particle(p_rbS, xyzrs)
260 def get_selection_as_hierarchy(model, S):
262 h = core.Hierarchy.setup_particle(ph)
263 for p
in S.get_selected_particles():
264 x = core.Hierarchy.setup_particle(p)
270 """ Gets a selection of particles and decorates them as Atoms.
271 Then all of them are put into a big residue. I have this to use
272 with the multifit.create_coarse_molecule_from_molecule() function
275 h = atom.Residue.setup_particle(ph)
276 for p
in S.get_selected_particles():
282 """ The function returns the particles (fragments) in the coarse hierarchy
283 that were created by summarizing the residues_numbers.
285 Coarse hierarchy - Hierarchy formed by a bunch of
286 fragments. Each fragment must have the residue numbers that it contains
287 residue_numbers - list with the number of the residues that need to
289 The function returns the set of particles that are atom.Fragments
292 fragments = atom.get_by_type(coarse_h, atom.FRAGMENT_TYPE)
295 residues_in_f = ff.get_residue_indexes()
296 for number
in residues_in_f:
297 if number
in residues_numbers:
298 particles.append(ff.get_particle())
305 Rotates the reference frame of a rigid body around the centroid
307 c = rb.get_coordinates()
308 ref = rb.get_reference_frame()
309 R = ref.get_transformation_to().get_rotation()
310 R2 = alg.compose(rot, R)
311 T = alg.Transformation3D(R2, c)
312 ref = alg.ReferenceFrame3D(T)
313 rb.set_reference_frame(ref)
318 Aplies a transformation around the centroid of a rigid body.
319 First does the rotation around the centroid and
320 then applies the transformation.
321 @param rb A IMP.core.RigidBody object
322 @param T a IMP.algebra.Transformation3D object
325 rb.set_coordinates(rb.get_coordinates() + T.get_translation())
330 Get the particle for a residue in a hierarchy.
331 @param h The hierarchy
332 @param chain_id If chain_id == False, just search for the residue
333 @param res Number of residue in the chain
340 return s.get_selected_particles()[0]
345 Get the coordinates of a residue (the coordinates of the first particle)
347 @param chain_id See help for get_residue_particle()
348 @param res See help for get_residue_particle()
351 return core.XYZ(p).get_coordinates()
355 hierarchy2, chain_id2, residue2):
357 Distance between two residues. See the help for get_residue_particle()
367 d = alg.get_distance(coords1, coords2)
372 """ Gets all the chains in a set of hierarchies
373 @param hierarchies A set of IMP.atom.Hierarchy objects
376 for h
in hierarchies:
377 chains_in_h = atom.get_by_type(h, atom.CHAIN_TYPE)
378 for ch
in chains_in_h:
379 chains.append(ch.get_as_chain())
383 def set_reference_frames(rigid_bodies, reference_frames):
384 for ref, rb
in zip(reference_frames, rigid_bodies):
385 rb.set_reference_frame(ref)
390 Returns the atoms in the backbone of the nucleic acid contained
392 backbone 'minimal' returns the atoms: ["P", "O5'", "C5'", "C4'", "C3'", "O3'"]
393 backbone 'trace' returns the atoms C4'
397 if backbone ==
'minimal':
398 backbone_atoms = [
"P",
"O5'",
"C5'",
"C4'",
"C3'",
"O3'"]
399 elif backbone ==
'trace':
400 backbone_atoms = [
"C4'"]
402 raise ValueError(
"Wrong value for the type of backbone")
403 backbone_atom_types = [
atom.AtomType(t)
for t
in backbone_atoms]
404 h_chains = atom.get_by_type(hierarchy, atom.CHAIN_TYPE)
406 if len(h_chains) > 1:
407 raise ValueError(
"The hierarchy mas more than one chain")
408 h_residues = atom.get_by_type(hierarchy, atom.RESIDUE_TYPE)
409 for hr
in h_residues:
411 if not (res.get_is_dna()
or res.get_is_rna()):
412 raise ValueError(
"Residue is not part of a nucleic acid")
413 h_atoms = atom.get_by_type(hr, atom.ATOM_TYPE)
415 if atom.Atom(at).get_atom_type()
in backbone_atom_types:
420 def get_calphas(chain_hierarchy):
421 h_residues = atom.get_by_type(chain_hierarchy, atom.RESIDUE_TYPE)
429 Get the backbone atoms for a hierarchy. It can be a protein or a
432 h_residues = atom.get_by_type(hierarchy, atom.RESIDUE_TYPE)
433 if len(h_residues) == 0:
434 raise ValueError(
"No residues!")
437 if res.get_is_dna()
or res.get_is_rna():
440 atoms = get_calphas(hierarchy)
446 Gets all the members of a set of rigid bodies, removing the subrigid
447 bodies. Returns all the plain atom or bead members
451 for rb
in rigid_bodies:
452 members += get_simple_members(rb)
456 def get_simple_members(rb):
458 members = [m
for m
in rb.get_members()
459 if not core.RigidBody.get_is_setup(m.get_particle())]
Select non water and non hydrogen atoms.
def get_selection_as_atom_hierarchy
Gets a selection of particles and decorates them as Atoms.
A decorator to associate a particle with a part of a protein/DNA/RNA.
def get_nucleic_acid_backbone
Returns the atoms in the backbone of the nucleic acid contained in the hierarchy. ...
Various classes to hold sets of particles.
def create_simplified_assembly
Simplifies an assembly, by creating a hierarchy with one ball per n_res residues. ...
def get_residue_particle
Get the particle for a residue in a hierarchy.
def create_rigid_bodies
set the children of a molecule type hierarchy as rigid bodies In this case, all the children are the ...
def get_selection_rigid_body
Build the rigid body for all the particles in the selection S.
def get_component
Select a component of the assembly using the name.
def get_backbone
Get the backbone atoms for a hierarchy.
def apply_rotation_around_centroid
Rotates the reference frame of a rigid body around the centroid.
def get_all_members
Gets all the members of a set of rigid bodies, removing the subrigid bodies.
def get_all_chains
Gets all the chains in a set of hierarchies.
def get_rb_name
Name to use for the rigid body of a hierarch.
static Molecule setup_particle(Model *m, ParticleIndex pi)
def apply_transformation_around_centroid
Aplies a transformation around the centroid of a rigid body.
def create_assembly_from_pdb
Builds the assembly setting the chains in the PDB file as components.
The standard decorator for manipulating molecular structures.
A decorator for a particle representing an atom.
def create_assembly
Read all the PDBs given in the list of names fn_pdbs and adds the hierarchies to the model...
def get_coarse_selection
The function returns the particles (fragments) in the coarse hierarchy that were created by summarizi...
A decorator for a particle with x,y,z coordinates.
def get_residues_distance
Distance between two residues.
def rename_chains
Rename all the chains of an assembly so there are no conflicts with the ids.
A decorator for a residue.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
def get_rigid_body
Select a rigid body from the rigid_bodies using the name.
def get_residue_coordinates
Get the coordinates of a residue (the coordinates of the first particle)
Class to handle individual model particles.
Store info for a chain of a protein.
A decorator for a rigid body.
def create_simplified_dna
Gets a hierarchy containing a molecule of DNA and simplifies it, generating a coarse representation o...
Output IMP model data in various file formats.
Functionality for loading, creating, manipulating and scoring atomic structures.
def read_component
Read a PDB molecule, add atoms, and set a name.
Select hierarchy particles identified by the biological name.
A decorator for a particle with x,y,z coordinates and a radius.