1 """@namespace IMP.EMageFit.sampling
2 Utility functions to handle sampling.
13 log = logging.getLogger(
"sampling")
18 Functions required for sampling in a 2D/3D grid
26 Creates a grid of positions (Vector3Ds), centered at 0.
27 @param diameter The shape of the grid is a sphere with this diameter.
28 @param n_axis_points Number of points used alogn an axis for the grid.
29 The axis X Y and Z will contain n_axis_points, equispaced.
30 The other regions of space will contain only the points allowed by
31 the size of the spere.
33 radius = diameter / 2.0
34 step = diameter / n_axis_points
35 points = [-radius + step * n
for n
in range(n_axis_points + 1)]
37 points = [x
for x
in points
if abs(x) > 1]
38 log.info(
"Points along the axis %s", points)
40 for x, y, z
in itertools.product(points, points, points):
41 d = (x ** 2. + y ** 2. + z ** 2.) ** .5
43 if(d < (1.01 * radius)):
44 positions.append(alg.Vector3D(x, y, z))
50 Creates a grid of positions (Vector3Ds), centered at 0.
51 The shape of the grid is a circle with diameter given by the parameter.
52 n_axis_points is the number of points along an axis: The axis X Y
53 will contain n_axis_points, equispaced. The other regions of space will
54 contain only the points allowed by the size of the circle.
57 raise ValueError(
"create_sampling_grid_2d: Negative diameter.")
58 if(n_axis_points < 1):
59 raise ValueError(
"create_sampling_grid_2d: Less than one axis point.")
60 radius = diameter / 2.0
61 step = diameter / n_axis_points
62 points = [-radius + step * n
for n
in range(n_axis_points + 1)]
63 log.info(
"Points along the axis %s", points)
65 for x, y
in itertools.product(points, points):
66 d = (x ** 2. + y ** 2.) ** .5
68 if(d < (1.01 * radius)):
69 positions.append(alg.Vector3D(x, y, 0.0))
75 Rotations nearby a given one. They are got intepolating with
76 the rotations of the uniform coverage. The parameter f
77 (0 <= f <= 1) must be close to 0 to get orientations
78 that are close to the given orientation
79 - Values from 0.1 (tight cluster) to 0.4 (loose)
81 n - number of rotations requested
83 log.debug(
"Computing nearby rotations around %s", rotation)
84 unif = alg.get_uniform_cover_rotations_3d(n)
85 id_rot = alg.get_identity_rotation_3d()
88 r = alg.get_interpolated(rot, id_rot, f)
89 r = alg.compose(r, rotation)
96 def __init__(self, n_components, fixed, anchored):
98 Build a set of orientations and positions for sampling with DOMINO
99 @param n_components Number of components in the assembly
100 @param fixed List of True/False values. If fixed == True
101 for a component its position is not changed.
102 @param anchor A list of True/False values. If anchor = True,
103 the component is set at (0,0,0) without rotating it.
105 if(n_components < 1):
107 "SamplingSchema: Requesting less than 1 components.")
109 self.anchored = anchored
111 self.n_components = n_components
113 def get_sampling_transformations(self, i):
114 return self.transformations[i]
116 def read_from_database(self, fn_database, fields=["reference_frames"],
117 max_number=
False, orderby=
False):
119 Read orientations and positions from a database file.
120 self.anchored and self.fixed overwrite
121 the positions and orientations read from the database
123 if not os.path.exists(fn_database):
124 raise IOError(
"read_from_database: Database file not found. "
125 "Are you perhaps trying to run the DOMINO optimization without "
126 "having the database yet?")
129 db.connect(fn_database)
130 data = db.get_solutions(fields, max_number, orderby)
132 self.transformations = [[]
for T
in range(self.n_components)]
137 texts = d[0].split(
"/")
138 for i, t
in zip(range(self.n_components), texts):
139 T = io.TextToTransformation3D(t).get_transformation()
140 self.transformations[i].append(T)
143 for i
in range(self.n_components):
145 origin = alg.Transformation3D(alg.get_identity_rotation_3d(),
146 alg.Vector3D(0.0, 0.0, 0.))
147 self.transformations[i] = [origin]
150 for i
in range(self.n_components):
152 if len(self.transformations[i]) == 0:
153 raise ValueError(
"There are positions to keep fixed")
154 self.transformations[i] = [self.transformations[i][0]]
Utility functions to handle IO.
def get_orientations_nearby
Rotations nearby a given one.
Utility functions to store and retrieve solution information.
Class for managing the results of the experiments.
def create_sampling_grid_3d
Creates a grid of positions (Vector3Ds), centered at 0.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
def create_sampling_grid_2d
Creates a grid of positions (Vector3Ds), centered at 0.