5 import IMP.em2d.imp_general.io
as io
11 log = logging.getLogger(
"sampling")
16 Functions required for sampling in a 2D/3D grid
22 def create_sampling_grid_3d(diameter, n_axis_points):
24 Creates a grid of positions (Vector3Ds), centered at 0.
25 @param diameter The shape of the grid is a sphere with this diameter.
26 @param n_axis_points Number of points used alogn an axis for the grid.
27 The axis X Y and Z will contain n_axis_points, equispaced.
28 The other regions of space will contain only the points allowed by
29 the size of the spere.
31 radius = diameter / 2.0
32 step = diameter / n_axis_points
33 points = [-radius + step * n
for n
in range(n_axis_points + 1)]
35 points = filter(
lambda x: abs(x) > 1, points)
36 log.info(
"Points along the axis %s", points)
38 for x, y, z
in itertools.product(points, points, points):
39 d = (x ** 2. + y ** 2. + z ** 2.) ** .5
41 if(d < (1.01 * radius)):
42 positions.append(alg.Vector3D(x, y, z))
46 def create_sampling_grid_2d(diameter, n_axis_points):
48 Creates a grid of positions (Vector3Ds), centered at 0.
49 The shape of the grid is a circle with diameter given by the parameter.
50 n_axis_points is the number of points along an axis: The axis X Y
51 will contain n_axis_points, equispaced. The other regions of space will
52 contain only the points allowed by the size of the circle.
55 raise ValueError(
"create_sampling_grid_2d: Negative diameter.")
56 if(n_axis_points < 1):
57 raise ValueError(
"create_sampling_grid_2d: Less than one axis point.")
58 radius = diameter / 2.0
59 step = diameter / n_axis_points
60 points = [-radius + step * n
for n
in range(n_axis_points + 1)]
61 log.info(
"Points along the axis %s", points)
63 for x, y
in itertools.product(points, points):
64 d = (x ** 2. + y ** 2.) ** .5
66 if(d < (1.01 * radius)):
67 positions.append(alg.Vector3D(x, y, 0.0))
71 def get_orientations_nearby(rotation, n, f):
73 Rotations nearby a given one. They are got intepolating with
74 the rotations of the uniform coverage. The parameter f
75 (0 <= f <= 1) must be close to 0 to get orientations
76 that are close to the given orientation
77 - Values from 0.1 (tight cluster) to 0.4 (loose)
79 n - number of rotations requested
81 log.debug(
"Computing nearby rotations around %s", rotation)
82 unif = alg.get_uniform_cover_rotations_3d(n)
83 id_rot = alg.get_identity_rotation_3d()
86 r = alg.get_interpolated(rot, id_rot, f)
87 r = alg.compose(r, rotation)
94 def __init__(self, n_components, fixed, anchored):
96 Build a set of orientations and positions for sampling with DOMINO
97 @param n_components Number of components in the assembly
98 @param fixed List of True/False values. If fixed == True
99 for a component its position is not changed.
100 @param anchor A list of True/False values. If anchor = True,
101 the component is set at (0,0,0) without rotating it.
103 if(n_components < 1):
105 "SamplingSchema: Requesting less than 1 components.")
107 self.anchored = anchored
109 self.n_components = n_components
111 def get_sampling_transformations(self, i):
112 return self.transformations[i]
114 def read_from_database(self, fn_database, fields=["reference_frames"],
115 max_number=
False, orderby=
False):
117 Read orientations and positions from a database file.
118 self.anchored and self.fixed overwrite
119 the positions and orientations read from the database
121 if not os.path.exists(fn_database):
122 raise IOError(
"read_from_database: Database file not found. "
123 "Are you perhaps trying to run the DOMINO optimization without "
124 "having the database yet?")
126 db = solutions_io.ResultsDB()
127 db.connect(fn_database)
128 data = db.get_solutions(fields, max_number, orderby)
130 self.transformations = [[]
for T
in range(self.n_components)]
135 texts = d[0].split(
"/")
136 for i, t
in zip(range(self.n_components), texts):
137 T = io.TextToTransformation3D(t).get_transformation()
138 self.transformations[i].append(T)
141 for i
in range(self.n_components):
143 origin = alg.Transformation3D(alg.get_identity_rotation_3d(),
144 alg.Vector3D(0.0, 0.0, 0.))
145 self.transformations[i] = [origin]
148 for i
in range(self.n_components):
150 if len(self.transformations[i]) == 0:
151 raise ValueError(
"There are positions to keep fixed")
152 self.transformations[i] = [self.transformations[i][0]]
Utility functions to manage SQL databases with sqlite3.
Utility functions to store and retrieve solution information.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...