1 """@namespace IMP.EMageFit.imp_general.io
2 Utility functions to handle IO.
5 from __future__
import print_function
17 log = logging.getLogger(
"io")
20 def get_vectors_from_points(points, vector_type="2d"):
21 if(vector_type ==
"2d"):
22 return [alg.Vector2D(p[0], p[1])
for p
in points]
23 elif(vector_type ==
"3d"):
24 return [alg.Vector3D(p[0], p[1], p[2])
for p
in points]
26 raise ValueError(
"vector type not recognized")
30 """ Simply creates IMP particles from a set of 2D points
31 model - is the model to store the particles
37 d.set_coordinates(alg.Vector3D(x[0], x[1], x[2]))
44 """ Simply creates IMP particles from a set of 2D points
45 model - is the model to store the particles
51 d.set_coordinates(alg.Vector3D(x[0], x[1], x[2]))
57 def get_particles_from_vector3ds(vs, model):
69 """ Writes a set of particles with coordinates to a file """
71 f_output = open(fn_output,
"w")
72 f_output.write(io.imp_info([IMP, em2d]))
74 f_output.write(get_common_title())
76 x, y, z = xyz.get_coordinates()
77 f_output.write(
"%8.3f %8.3f %8.3f\n" % (x, y, z))
82 """ Writes a hierarchy contained in h to the file fn """
84 g = display.HierarchyGeometry(h)
90 """ Writes a bunch o particles to the file fn
91 It is assumed that the particles can be decorated with XYZR
95 g = display.XYZRsGeometry(lsc)
101 """ Writes a bunch o particles to the file fn
102 It is assumed that the particles can be decorated with XYZR
104 ps = [a.get_particle()
for a
in xyzrs]
109 """ Writes a bunch o particles to the file fn
110 It is assumed that the particles can be decorated with XYZR
116 xyzr = core.XYZR.setup_particle(pa)
117 xyzr.set_radius(radius)
118 xyzr.set_coordinates(alg.Vector3D(p[0], p[1], p[2]))
125 Writes vectors as points in chimera
132 xyzr = core.XYZR.setup_particle(pa)
133 xyzr.set_radius(radius)
134 xyzr.set_coordinates(v)
140 """ writes a text files in the format required
141 for point alignment in multifit2
148 ap = mfit.AnchorsData(vs, edges)
149 mfit.write_txt(fn_output, ap)
152 def get_common_title():
153 return "# coordinates x | y | z\n"
159 Parseable output for a IMP Transformation3D
162 def __init__(self, T, delimiter="|"):
163 q = T.get_rotation().get_quaternion()
164 tr = T.get_translation()
165 self.rot_text = delimiter.join([str(i)
for i
in q])
166 self.tr_text = delimiter.join([str(i)
for i
in tr])
167 self.delimiter = delimiter
170 return self.delimiter.join([self.rot_text, self.tr_text])
173 class TextToTransformation3D:
175 def __init__(self, text, delimiter="|"):
176 vals = [float(x)
for x
in text.split(delimiter)]
178 raise ValueError(
"The text is not a transformation", vals)
179 R = alg.Rotation3D(vals[0], vals[1], vals[2], vals[3])
180 t = alg.Vector3D(vals[4], vals[5], vals[6])
181 self.t = alg.Transformation3D(R, t)
183 def get_transformation(self):
190 Transform a IMP reference frame into parseable output
193 def __init__(self, ref, delimiter="|"):
194 T = ref.get_transformation_to()
195 Transformation3DToText.__init__(self, T, delimiter)
198 class TextToReferenceFrame(TextToTransformation3D):
200 def __init__(self, text, delimiter="|"):
201 TextToTransformation3D.__init__(self, text, delimiter)
202 self.ref = alg.ReferenceFrame3D(self.get_transformation())
204 def get_reference_frame(self):
210 Read a file of alg.Transformation3D. The it is assumed that the
211 transformations are the only thing contained in a line
219 T = TextToTransformation3D(l).get_transformation()
227 Write a file with the Transformation3Ds contained in Ts
238 Read the reference frames contained in a solutions file from sampling
239 n is the maximum number of ref frames to read.
240 NOTE: Currently the function returns only the reference frames and
241 discards the score, the first element of a row
243 rows = csv_related.read_csv(fn, delimiter=
"/")
244 x = min(n, len(rows))
246 for i, row
in enumerate(rows[0:x]):
247 refs = [TextToReferenceFrame(t).get_reference_frame()
for t
in row[1:]]
248 all_refs.append(refs)
254 Read the PDB files, apply reference frames to them, and write a pdb
257 assembly = representation.create_assembly(model, fn_pdbs)
258 rbs = representation.create_rigid_bodies(assembly)
259 for t, rb
in zip(refs_texts, rbs):
260 r = TextToReferenceFrame(t).get_reference_frame()
261 rb.set_reference_frame(r)
262 atom.write_pdb(assembly, fn_output)
266 """ Prints information about the representation
267 Prints the number of components (hierarchies), its children,
268 and information about the chains and rigid bodies
270 print(
"##################################################################################")
272 print(
"##################################################################################")
275 print(
"#########################")
276 print(
"Hierarchies in the assembly:")
277 print(
"#########################")
278 for c
in assembly.get_children():
279 print(c.get_name() +
" Is valid? " + c.get_is_valid(
True)
280 +
" children " + str(c.get_number_of_children()))
281 print(
"Child info: " + c.show())
284 print(
"Number of chains in the hierarchy: %d" % len(hchains))
287 print(chain.get_name() +
" particles %d" % len(atom.get_leaves(chain)))
288 print(
"#########################")
289 print(
"Rigid bodies")
290 print(
"#########################")
291 for r
in components_rbs:
292 print(
"rigid body: Particles: %d coordinates: %s"
293 % (r.get_number_of_members(), r.get_coordinates()))
295 print(
"#########################")
297 print(
"#########################")
298 n = model.get_number_of_restraints()
300 print(model.get_restraint(i))
305 Returns text with the time and information about the modules employed
306 imp_modules is the set of modules whose infos are requested
310 if(imp_modules
is None):
311 versions = [IMP.get_module_version()]
316 versions = [p.get_module_version()
for p
in imp_modules]
317 text =
"# " + tt +
"\n"
321 text +=
"# " + x +
"\n"
Parseable output for a IMP Transformation3D.
def show_model_info
Prints information about the representation Prints the number of components (hierarchies), its children, and information about the chains and rigid bodies.
def write_particles_as_text
Writes a set of particles with coordinates to a file.
Restraints using electron microscopy 2D images (class averages).
Write geometry to a Python file for Chimera to read.
Various classes to hold sets of particles.
def write_hierarchy_to_chimera
Writes a hierarchy contained in h to the file fn.
def write_particles_to_chimera
Writes a bunch o particles to the file fn It is assumed that the particles can be decorated with XYZR...
Utility functions to handle representation.
def write_vectors_in_multifit2_format
writes a text files in the format required for point alignment in multifit2
Transform a IMP reference frame into parseable output.
def write_vectors_to_chimera
Writes vectors as points in chimera.
def imp_info
Returns text with the time and information about the modules employed imp_modules is the set of modul...
static XYZR setup_particle(kernel::Model *m, ParticleIndex pi)
def read_reference_frames
Read the reference frames contained in a solutions file from sampling n is the maximum number of ref ...
def write_xyzrs_to_chimera
Writes a bunch o particles to the file fn It is assumed that the particles can be decorated with XYZR...
Store a kernel::ParticleIndexes.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
def get_particles_from_points
Simply creates IMP particles from a set of 2D points model - is the model to store the particles...
def write_points_to_chimera
Writes a bunch o particles to the file fn It is assumed that the particles can be decorated with XYZR...
Fitting atomic structures into a cryo-electron microscopy density map.
Class to handle individual model particles.
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...
Store info for a chain of a protein.
def read_transforms
Read a file of alg.Transformation3D.
Output IMP model data in various file formats.
Functionality for loading, creating, manipulating and scoring atomic structures.
def write_transforms
Write a file with the Transformation3Ds contained in Ts.
def write_pdb_for_reference_frames
Read the PDB files, apply reference frames to them, and write a pdb.
Class for storing model, its restraints, constraints, and particles.