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
33 if model_num>=len(mhs):
34 raise Exception(
"you requested model num "+str(model_num)+\
35 " but the PDB file only contains "+str(len(mhs))+
" models")
45 sel=
IMP.atom.Selection(mh,chain=chain_id,residue_indexes=range(res_range[0],res_range[1]+1),
48 for p
in sel.get_selected_particles():
54 """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)
95 Generates a string of beads with given length
99 outhiers.append(
build_bead(model,chunk, input_coord=input_coord))
105 """Group residues along the backbone, adding beads as needed.
106 Currently this first groups into contiguous fragment regions ('folders')
107 with identical sets of resolutions. However this behavior may
108 The current resolutions used are 0 for atomic, and N for N residues
109 per ball (see @ref pmi_resolution).
111 @param root the hierarchy to which all the fragments and resolutions will be added
112 @param residues list of PMI Residues, labeled with resolution
113 @param rep_type Representation type (currently supports IMP.atom.BALLS)
114 @param ca_centers If true, when making residue beads, will place the bead at the CA position
116 allowed_reps=[IMP.atom.BALLS]
117 if rep_type
not in allowed_reps:
118 print(
"Only supported representation types are",allowed_types)
127 prev_rep = res.representations
128 prev_atomic = res.get_has_coordinates()
129 rep = res.representations
130 if rep==prev_rep
and res.get_has_coordinates()==prev_atomic:
131 cur_fragment.append(res)
133 fragments.append(cur_fragment)
136 prev_atomic=res.get_has_coordinates()
137 fragments.append(cur_fragment)
141 for frag_res
in fragments:
142 if len(frag_res[0].representations)==0:
144 res_nums=[r.get_index()
for r
in frag_res]
145 name =
"frag_%i-%i"%(res_nums[0],res_nums[-1])
146 if frag_res[0].get_has_coordinates():
147 this_rep=frag_res[0].representations
153 primary_rep_num=min(this_rep[
'balls'])
155 if 'balls' in this_rep:
157 if 0
in this_rep[
'balls']:
160 for residue
in frag_res:
161 f.add_child(residue.hier)
165 if 1
in this_rep[
'balls']:
167 for residue
in frag_res:
170 rp1.set_name(
"Residue_%i"%residue.get_index())
171 rt=residue.get_residue_type()
183 get_selected_particles()[0]
188 if primary_rep_num==1:
191 frep.add_representation(res1,IMP.atom.BALLS,1)
194 for resolution
in set(this_rep[
'balls']) - set([0,1]):
200 for residue
in frag_res:
201 c.add_child(residue.hier)
203 for ch
in sh.get_children():
205 if primary_rep_num==resolution:
208 frep.add_representation(resx,IMP.atom.BALLS,resolution)
215 this_resolutions=frag_res[0].representations[
'balls']
217 if len(this_resolutions) > 1 :
218 print(
"build_along_backbone Error: residues with missing atomic coordinate should be associated with only one resolution")
220 this_resolution=this_resolutions.pop()
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):
static Residue setup_particle(kernel::Model *m, ParticleIndex pi, ResidueType t, int index, int insertion_code)
double get_volume_from_residue_type(ResidueType rt)
Return an estimate for the volume of a given residue.
Hierarchies read_multimodel_pdb(base::TextInput input, kernel::Model *model, PDBSelector *selector=get_default_pdb_selector())
void show_molecular_hierarchy(Hierarchy h)
Print out the molecular hierarchy.
Ints get_index(const kernel::ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
double get_mass(const Selection &s)
Get the total mass of a hierarchy, in Daltons.
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 bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
static XYZR setup_particle(kernel::Model *m, ParticleIndex pi)
A decorator for a representation.
double get_volume_from_mass(double m, ProteinDensityReference ref=ALBER)
Estimate the volume of a protein from its mass.
A decorator for a particle representing an atom.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
PDBSelector * get_default_pdb_selector()
A decorator for a particle with x,y,z coordinates.
static Chain setup_particle(kernel::Model *m, ParticleIndex pi, std::string id)
Class to handle individual model particles.
static Mass setup_particle(kernel::Model *m, ParticleIndex pi, Float mass)
A decorator for a residue.
static Representation setup_particle(kernel::Model *m, ParticleIndex pi)
Hierarchy create_simplified_along_backbone(Chain input, const IntRanges &residue_segments, bool keep_detailed=false)
static Fragment setup_particle(kernel::Model *m, ParticleIndex pi)
Select all CA ATOM records.
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
void read_pdb(base::TextInput input, int model, Hierarchy h)
Select hierarchy particles identified by the biological name.
An exception for an invalid value being passed to IMP.
A decorator for a particle with x,y,z coordinates and a radius.