1 """@namespace IMP.EMageFit.sampling
2 Utility functions to handle sampling.
12 log = logging.getLogger(
"sampling")
17 Functions required for sampling in a 2D/3D grid
25 Creates a grid of positions (Vector3Ds), centered at 0.
26 @param diameter The shape of the grid is a sphere with this diameter.
27 @param n_axis_points Number of points used along an axis for the grid.
28 The axis X Y and Z will contain n_axis_points, equispaced.
29 The other regions of space will contain only the points allowed by
30 the size of the sphere.
32 radius = diameter / 2.0
33 step = diameter / n_axis_points
34 points = [-radius + step * n
for n
in range(n_axis_points + 1)]
36 points = [x
for x
in points
if abs(x) > 1]
37 log.info(
"Points along the axis %s", points)
39 for x, y, z
in itertools.product(points, points, points):
40 d = (x ** 2. + y ** 2. + z ** 2.) ** .5
42 if d < (1.01 * radius):
43 positions.append(alg.Vector3D(x, y, z))
49 Creates a grid of positions (Vector3Ds), centered at 0.
50 The shape of the grid is a circle with diameter given by the parameter.
51 n_axis_points is the number of points along an axis: The axis X Y
52 will contain n_axis_points, equispaced. The other regions of space will
53 contain only the points allowed by the size of the circle.
56 raise ValueError(
"create_sampling_grid_2d: Negative diameter.")
58 raise ValueError(
"create_sampling_grid_2d: Less than one axis point.")
59 radius = diameter / 2.0
60 step = diameter / n_axis_points
61 points = [-radius + step * n
for n
in range(n_axis_points + 1)]
62 log.info(
"Points along the axis %s", points)
64 for x, y
in itertools.product(points, points):
65 d = (x ** 2. + y ** 2.) ** .5
67 if d < (1.01 * radius):
68 positions.append(alg.Vector3D(x, y, 0.0))
74 Rotations nearby a given one. They are got interpolating with
75 the rotations of the uniform coverage. The parameter f
76 (0 <= f <= 1) must be close to 0 to get orientations
77 that are close to the given orientation
78 - Values from 0.1 (tight cluster) to 0.4 (loose)
80 n - number of rotations requested
82 log.debug(
"Computing nearby rotations around %s", rotation)
83 unif = alg.get_uniform_cover_rotations_3d(n)
84 id_rot = alg.get_identity_rotation_3d()
87 r = alg.get_interpolated(rot, id_rot, f)
88 r = alg.compose(r, rotation)
95 def __init__(self, n_components, fixed, anchored):
97 Build a set of orientations and positions for sampling with DOMINO
98 @param n_components Number of components in the assembly
99 @param fixed List of True/False values. If fixed == True
100 for a component its position is not changed.
101 @param anchor A list of True/False values. If anchor = True,
102 the component is set at (0,0,0) without rotating it.
106 "SamplingSchema: Requesting less than 1 components.")
108 self.anchored = anchored
110 self.n_components = n_components
112 def get_sampling_transformations(self, i):
113 return self.transformations[i]
115 def read_from_database(self, fn_database, fields=["reference_frames"],
116 max_number=
False, orderby=
False):
118 Read orientations and positions from a database file.
119 self.anchored and self.fixed overwrite
120 the positions and orientations read from the database
122 if not os.path.exists(fn_database):
123 raise IOError(
"read_from_database: Database file not found. "
124 "Are you perhaps trying to run the DOMINO "
125 "optimization without having the database yet?")
128 db.connect(fn_database)
129 data = db.get_solutions(fields, max_number, orderby)
131 self.transformations = [[]
for T
in range(self.n_components)]
136 texts = d[0].split(
"/")
137 for i, t
in zip(range(self.n_components), texts):
138 T = io.TextToTransformation3D(t).get_transformation()
139 self.transformations[i].append(T)
142 for i
in range(self.n_components):
144 origin = alg.Transformation3D(alg.get_identity_rotation_3d(),
145 alg.Vector3D(0.0, 0.0, 0.))
146 self.transformations[i] = [origin]
149 for i
in range(self.n_components):
151 if len(self.transformations[i]) == 0:
152 raise ValueError(
"There are positions to keep fixed")
153 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.