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 text files in the format required
83 for point alignment in multifit2
90 ap = mfit.AnchorsData(vs, edges)
91 mfit.write_txt(fn_output, ap)
94 def get_common_title():
95 return "# coordinates x | y | z\n"
101 Parseable output for a IMP Transformation3D
104 def __init__(self, T, delimiter="|"):
105 q = T.get_rotation().get_quaternion()
106 tr = T.get_translation()
107 self.rot_text = delimiter.join([str(i)
for i
in q])
108 self.tr_text = delimiter.join([str(i)
for i
in tr])
109 self.delimiter = delimiter
112 return self.delimiter.join([self.rot_text, self.tr_text])
115 class TextToTransformation3D:
117 def __init__(self, text, delimiter="|"):
118 vals = [float(x)
for x
in text.split(delimiter)]
120 raise ValueError(
"The text is not a transformation", vals)
121 R = alg.Rotation3D(vals[0], vals[1], vals[2], vals[3])
122 t = alg.Vector3D(vals[4], vals[5], vals[6])
123 self.t = alg.Transformation3D(R, t)
125 def get_transformation(self):
132 Transform a IMP reference frame into parseable output
135 def __init__(self, ref, delimiter="|"):
136 T = ref.get_transformation_to()
137 Transformation3DToText.__init__(self, T, delimiter)
140 class TextToReferenceFrame(TextToTransformation3D):
142 def __init__(self, text, delimiter="|"):
143 TextToTransformation3D.__init__(self, text, delimiter)
144 self.ref = alg.ReferenceFrame3D(self.get_transformation())
146 def get_reference_frame(self):
152 Read a file of alg.Transformation3D. The it is assumed that the
153 transformations are the only thing contained in a line
161 T = TextToTransformation3D(l).get_transformation()
169 Write a file with the Transformation3Ds contained in Ts
180 Read the reference frames contained in a solutions file from sampling
181 n is the maximum number of ref frames to read.
182 NOTE: Currently the function returns only the reference frames and
183 discards the score, the first element of a row
185 rows = csv_related.read_csv(fn, delimiter=
"/")
186 x = min(n, len(rows))
188 for i, row
in enumerate(rows[0:x]):
189 refs = [TextToReferenceFrame(t).get_reference_frame()
for t
in row[1:]]
190 all_refs.append(refs)
196 Read the PDB files, apply reference frames to them, and write a pdb
199 assembly = representation.create_assembly(model, fn_pdbs)
200 rbs = representation.create_rigid_bodies(assembly)
201 for t, rb
in zip(refs_texts, rbs):
202 r = TextToReferenceFrame(t).get_reference_frame()
203 rb.set_reference_frame(r)
204 atom.write_pdb(assembly, fn_output)
208 Returns text with the time and information about the modules employed
209 imp_modules is the set of modules whose infos are requested
213 if(imp_modules
is None):
219 versions = [p.get_module_version()
for p
in imp_modules]
220 text =
"# " + tt +
"\n"
224 text +=
"# " + x +
"\n"
Parseable output for a IMP Transformation3D.
def write_particles_as_text
Writes a set of particles with coordinates to a file.
Restraints using electron microscopy 2D images (class averages).
Various classes to hold sets of particles.
static XYZR setup_particle(Model *m, ParticleIndex pi)
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.
Class for storing model, its restraints, constraints, and particles.
def imp_info
Returns text with the time and information about the modules employed imp_modules is the set of modul...
def read_reference_frames
Read the reference frames contained in a solutions file from sampling n is the maximum number of ref ...
def get_particles_from_points
Simply creates IMP particles from a set of 2D points model - is the model to store the particles...
Fitting atomic structures into a cryo-electron microscopy density map.
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...
Class to handle individual model particles.
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.
std::string get_module_version()