1 """@namespace IMP.pmi.topology.system_tools
2 Tools to help build structures
5 from __future__
import print_function
12 """ Yield successive length-sized chunks from a list.
14 for i
in range(0, len(input_list), length):
15 yield input_list[i:i + length]
17 def get_structure(mdl,pdb_fn,chain_id,res_range=[],offset=0,model_num=None,ca_only=False):
18 """read a structure from a PDB file and return a list of residues
19 @param mdl The IMP model
20 @param pdb_fn The file to read
21 @param chain_id Chain ID to read
22 @param res_range Add only a specific set of residues
23 @param offset Apply an offset to the residue indexes of the PDB file
24 @param model_num Read multi-model PDB and return that model
25 @param ca_only Read only CA atoms (by default, all non-waters are read)
34 if model_num>=len(mhs):
35 raise Exception(
"you requested model num "+str(model_num)+\
36 " but the PDB file only contains "+str(len(mhs))+
" models")
46 sel=
IMP.atom.Selection(mh,chain=chain_id,residue_indexes=range(res_range[0],res_range[1]+1),
49 for p
in sel.get_selected_particles():
55 """Generates a single bead"""
63 if ds_frag[0] == ds_frag[-1]:
64 rt=residues[0].get_residue_type()
66 h.set_name(
'%i_bead' % (ds_frag[0]))
67 prt.set_name(
'%i_bead' % (ds_frag[0]))
74 ptem.set_radius(radius)
77 h.set_name(
'%i-%i_bead' % (ds_frag[0], ds_frag[-1]))
78 prt.set_name(
'%i-%i_bead' % (ds_frag[0], ds_frag[-1]))
79 h.set_residue_indexes(range(ds_frag[0], ds_frag[-1] + 1))
81 radius = 0.8 * (3.0 / 4.0 / pi * volume) ** (1.0 / 3.0)
82 ptem.set_radius(radius)
86 if not tuple(input_coord)
is None:
87 ptem.set_coordinates(input_coord)
94 """Generates a string of beads with given length"""
97 out_hiers.append(
build_bead(model,chunk, input_coord=input_coord))
103 """Group residues along the backbone, adding beads as needed.
104 Currently this first groups into contiguous fragment regions ('folders')
105 with identical sets of resolutions. However this behavior may change.
106 The current resolutions used are 0 for atomic, and N for N residues
107 per ball (see @ref pmi_resolution).
109 @param root the hierarchy to which all the fragments and resolutions will be added
110 @param residues list of PMI Residues, labeled with resolution
111 @param rep_type Representation type (currently supports IMP.atom.BALLS)
112 @param ca_centers If true, when making residue beads, will place the bead at the CA position
114 allowed_reps=[IMP.atom.BALLS]
115 if rep_type
not in allowed_reps:
116 print(
"Only supported representation types are",allowed_types)
125 prev_rep = res.representations
126 prev_atomic = res.get_has_coordinates()
127 rep = res.representations
128 if rep==prev_rep
and res.get_has_coordinates()==prev_atomic:
129 cur_fragment.append(res)
131 fragments.append(cur_fragment)
134 prev_atomic=res.get_has_coordinates()
135 fragments.append(cur_fragment)
138 for frag_res
in fragments:
139 if len(frag_res[0].representations)==0:
141 res_nums=[r.get_index()
for r
in frag_res]
142 name =
"frag_%i-%i"%(res_nums[0],res_nums[-1])
143 if frag_res[0].get_has_coordinates():
144 this_rep=frag_res[0].representations
150 primary_rep_num=min(this_rep[
'balls'])
152 if 'balls' in this_rep:
154 if 0
in this_rep[
'balls']:
157 for residue
in frag_res:
158 f.add_child(residue.hier)
162 if 1
in this_rep[
'balls']:
164 for residue
in frag_res:
167 rp1.set_name(
"Residue_%i"%residue.get_index())
168 rt=residue.get_residue_type()
180 get_selected_particles()[0]
185 if primary_rep_num==1:
188 frep.add_representation(res1,IMP.atom.BALLS,1)
191 for resolution
in set(this_rep[
'balls']) - set([0,1]):
197 for residue
in frag_res:
198 c.add_child(residue.hier)
200 for ch
in sh.get_children():
202 if primary_rep_num==resolution:
205 frep.add_representation(resx,IMP.atom.BALLS,resolution)
212 this_resolutions=frag_res[0].representations[
'balls']
214 if len(this_resolutions) > 1 :
215 raise ValueError(
"build_along_backbone Error: residues with missing atomic coordinate should be associated with only one resolution")
216 if len(this_resolutions) == 0 :
217 print(
"build_along_backbone Error: no structure but trying to build resolution 0")
219 this_resolution=list(this_resolutions)[0]
229 def show_representation(node):
233 resolutions = repr.get_resolutions()
234 for r
in resolutions:
235 print(
'---- resolution %i ----' %r)
241 def recursive_show_representations(root):
double get_volume_from_residue_type(ResidueType rt)
Return an estimate for the volume of a given residue.
void show_molecular_hierarchy(Hierarchy h)
Print out the molecular hierarchy.
static Fragment setup_particle(Model *m, ParticleIndex pi)
double get_mass(const Selection &s)
Get the total mass of a hierarchy, in Daltons.
static XYZR setup_particle(Model *m, ParticleIndex pi)
double get_mass_from_number_of_residues(unsigned int num_aa)
Estimate the mass of a protein from the number of amino acids.
double get_ball_radius_from_volume_3d(double volume)
Return the radius of a sphere with a given volume.
static Residue setup_particle(Model *m, ParticleIndex pi, ResidueType t, int index, int insertion_code)
static Representation setup_particle(Model *m, ParticleIndex pi)
void read_pdb(TextInput input, int model, Hierarchy h)
A decorator for a representation.
double get_volume_from_mass(double m, ProteinDensityReference ref=ALBER)
Estimate the volume of a protein from its mass.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
A decorator for a particle representing an atom.
static Mass setup_particle(Model *m, ParticleIndex pi, Float mass)
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Gather all the molecular particles of a certain level in the hierarchy.
PDBSelector * get_default_pdb_selector()
A decorator for a particle with x,y,z coordinates.
A decorator for a residue.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
Hierarchies read_multimodel_pdb(TextInput input, Model *model, PDBSelector *selector=get_default_pdb_selector())
The general base class for IMP exceptions.
Hierarchy create_simplified_along_backbone(Chain input, const IntRanges &residue_segments, bool keep_detailed=false)
Class to handle individual model particles.
Select all CA ATOM records.
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
static Chain setup_particle(Model *m, ParticleIndex pi, std::string id)
An exception for an invalid value being passed to IMP.
Select hierarchy particles identified by the biological name.
A decorator for a particle with x,y,z coordinates and a radius.