1 from __future__
import print_function
6 import pyRMSD.RMSDCalculator
10 def parse_custom_ranges(ranges_file):
13 with open(ranges_file)
as fh:
16 return d[
'density_custom_ranges']
19 def get_particles_from_superposed(
20 cluster_conform_i, cluster_conform_0, align, ps, trans,
22 def _to_vector3ds(numpy_array):
28 calculator_name =
"QCP_SERIAL_CALCULATOR"
30 calculator_name =
"NOSUP_SERIAL_CALCULATOR"
32 conforms = numpy.array([cluster_conform_0, cluster_conform_i])
34 if symm_groups
is None:
35 calculator = pyRMSD.RMSDCalculator.RMSDCalculator(
39 s1 = parse_symm_groups_for_pyrmsd(symm_groups)
40 calculator = pyRMSD.RMSDCalculator.RMSDCalculator(
42 fittingCoordsets=conforms,
43 calcSymmetryGroups=s1,
46 rmsd, superposed_fit = calculator.pairwise(
47 0, 1, get_superposed_coordinates=
True)
54 _to_vector3ds(superposed_fit[0]), _to_vector3ds(cluster_conform_0))
56 for particle_index
in range(len(superposed_fit[1])):
61 return rmsd, ps, trans
65 """Compute mean density maps from structures.
66 Keeps a dictionary of density maps,
67 keys are in the custom ranges. When you call add_subunits_density, it adds
68 particle coordinates to the existing density maps.
71 def __init__(self, custom_ranges=None, resolution=20.0, voxel=5.0,
74 @param list of particles decorated with mass, radius, and XYZ
75 @param resolution The MRC resolution of the output map
77 @param voxel The voxel size for the output map (lower is slower)
80 self.MRCresolution = resolution
82 self.count_models = 0.0
84 self.bead_names = bead_names
85 self.custom_ranges = custom_ranges
89 self.particle_indices_in_custom_ranges = {}
91 for density_name
in self.custom_ranges:
92 self.particle_indices_in_custom_ranges[density_name] = []
95 for index, beadname
in enumerate(self.bead_names):
96 for density_name
in self.custom_ranges:
98 for domain
in self.custom_ranges[density_name]:
99 if self._is_contained(beadname, domain):
100 self.particle_indices_in_custom_ranges[
101 density_name].append(index)
104 def normalize_density(self):
107 def _create_density_from_particles(self, ps, name,
108 kernel_type=
'GAUSSIAN'):
109 '''Internal function for adding to densities.
110 pass XYZR particles with mass and create a density from them.
111 kernel type options are GAUSSIAN, BINARIZED_SPHERE, and SPHERE.'''
114 dmap.set_was_used(
True)
116 if name
not in self.densities:
117 self.densities[name] = dmap
123 dmap3.set_was_used(
True)
125 dmap3.add(self.densities[name])
126 self.densities[name] = dmap3
128 def _is_contained(self, bead_name, domain):
129 """ domain can be the name of a single protein or a tuple
130 (start_residue,end_residue,protein_name)
131 bead is a string of type moleculeName_startResidue_endResidue
134 (bead_protein, bead_res_start,
135 bead_res_end, bead_copy) = bead_name.split(
"_")
138 if isinstance(domain, tuple):
139 domain_protein = domain[2]
141 domain_protein = domain
143 if "." in domain_protein:
144 spl = domain_protein.split(
".")
145 domain_protein = spl[0]
146 domain_copy = int(spl[1])
148 domain_copy = bead_copy = -1
150 if bead_protein != domain_protein
or int(bead_copy) != domain_copy:
154 if isinstance(domain, tuple):
155 bead_residues = set(range(int(bead_res_start),
156 int(bead_res_end)+1))
157 domain_residues = set(range(int(domain[0]),
159 return not domain_residues.isdisjoint(bead_residues)
164 """Add a frame to the densities.
165 @param ps List of particles decorated with XYZR and Mass.
167 self.count_models += 1.0
169 particles_custom_ranges = {}
170 for density_name
in self.custom_ranges:
171 particles_custom_ranges[density_name] = []
174 for density_name
in self.custom_ranges:
176 in self.particle_indices_in_custom_ranges[density_name]:
177 particles_custom_ranges[density_name].append(
181 for density_name
in self.custom_ranges:
182 self._create_density_from_particles(
183 particles_custom_ranges[density_name], density_name)
185 def get_density_keys(self):
186 return list(self.densities.keys())
189 """Get the current density for some component name"""
190 if name
not in self.densities:
193 return self.densities[name]
195 def write_mrc(self, path=".", file_prefix=""):
196 for density_name
in self.densities:
197 mrc = os.path.join(path, file_prefix +
"_" + density_name +
".mrc")
198 self.densities[density_name].
multiply(1. / self.count_models)
200 self.densities[density_name], mrc,
202 if len(self.densities) == 1:
205 return os.path.join(path, file_prefix +
"_*.mrc")
def get_density
Get the current density for some component name.
Compute mean density maps from structures.
Class for sampling a density map from particles.
DensityMap * multiply(const DensityMap *m1, const DensityMap *m2)
Return a density map for which voxel i contains the result of m1[i]*m2[i].
DensityMap * create_density_map(const IMP::algebra::GridD< 3, S, V, E > &arg)
Create a density map from an arbitrary IMP::algebra::GridD.
def add_subunits_density
Add a frame to the densities.
Basic utilities for handling cryo-electron microscopy 3D density maps.
A decorator for a particle with x,y,z coordinates.
algebra::BoundingBoxD< 3 > get_bounding_box(const DensityMap *m)
Transformation3D get_transformation_aligning_first_to_second(Vector3Ds a, Vector3Ds b)