Skip to content

Commit 6fa59fd

Browse files
committed
SyncVotingMixin --> sync_voting module
1 parent b70c562 commit 6fa59fd

7 files changed

Lines changed: 359 additions & 326 deletions

File tree

src/aspire/abinitio/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from .commonline_sdp import CommonlineSDP
99
from .commonline_lud import CommonlineLUD
1010
from .commonline_irls import CommonlineIRLS
11-
from .sync_voting import SyncVotingMixin
1211
from .commonline_sync import CLSyncVoting
1312
from .commonline_sync3n import CLSync3N
1413
from .commonline_c3_c4 import CLSymmetryC3C4

src/aspire/abinitio/commonline_c2.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import numpy as np
44
from scipy.linalg import eigh
55

6-
from aspire.abinitio import CLOrient3D, JSync, SyncVotingMixin
6+
from aspire.abinitio import CLOrient3D, JSync
7+
from aspire.abinitio.sync_voting import _syncmatrix_ij_vote_3n
78
from aspire.utils import J_conjugate, Rotation, all_pairs
89

910
from .commonline_utils import (
@@ -15,7 +16,7 @@
1516
logger = logging.getLogger(__name__)
1617

1718

18-
class CLSymmetryC2(CLOrient3D, SyncVotingMixin):
19+
class CLSymmetryC2(CLOrient3D):
1920
"""
2021
Define a class to estimate 3D orientations using common lines methods for molecules with C2 cyclic symmetry.
2122
@@ -241,7 +242,7 @@ def _estimate_relative_viewing_directions(self):
241242
self.build_clmatrix()
242243

243244
# Step 2: Calculate relative rotations associated with both mutual common lines.
244-
Rijs, Rijgs = self._estimate_all_Rijs_c2(self.clmatrix)
245+
Rijs, Rijgs = self._estimate_all_Rijs_c2()
245246

246247
# Step 3: Inner J-synchronization
247248
Rijs, Rijgs = self._local_J_sync_c2(Rijs, Rijgs)
@@ -338,23 +339,36 @@ def _estimate_inplane_rotations(self, vis, Rijs, Rijgs):
338339
# Secondary Methods for computing outer product #
339340
#################################################
340341

341-
def _estimate_all_Rijs_c2(self, clmatrix):
342+
def _estimate_all_Rijs_c2(self):
342343
"""
343344
Estimate the two sets of relative rotations, Rijs and Rijgs, between pairs
344345
of images using the voting method.
345346
346-
:param clmatrix: 2 x n_img x n_img array holding two sets of mutual common-lines
347-
between pairs of images.
348347
:return: Relative rotations, Rijs and Rijgs.
349348
"""
350349
k_list = np.arange(self.n_img)
351-
n_theta = self.n_theta
352350
pairs = all_pairs(self.n_img)
353351
Rijs = np.zeros((len(pairs), 3, 3), dtype=self.dtype)
354352
Rijgs = np.zeros((len(pairs), 3, 3), dtype=self.dtype)
355353
for idx, (i, j) in enumerate(pairs):
356-
Rijs[idx] = self._syncmatrix_ij_vote_3n(clmatrix[0], i, j, k_list, n_theta)
357-
Rijgs[idx] = self._syncmatrix_ij_vote_3n(clmatrix[1], i, j, k_list, n_theta)
354+
Rijs[idx] = _syncmatrix_ij_vote_3n(
355+
self.clmatrix[0],
356+
i,
357+
j,
358+
k_list,
359+
self.n_theta,
360+
self.hist_bin_width,
361+
self.full_width,
362+
)
363+
Rijgs[idx] = _syncmatrix_ij_vote_3n(
364+
self.clmatrix[1],
365+
i,
366+
j,
367+
k_list,
368+
self.n_theta,
369+
self.hist_bin_width,
370+
self.full_width,
371+
)
358372

359373
return Rijs, Rijgs
360374

src/aspire/abinitio/commonline_c3_c4.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import numpy as np
44
from numpy.linalg import norm, svd
55

6-
from aspire.abinitio import CLOrient3D, JSync, SyncVotingMixin
6+
from aspire.abinitio import CLOrient3D, JSync
7+
from aspire.abinitio.sync_voting import _syncmatrix_ij_vote_3n
78
from aspire.operators import PolarFT
89
from aspire.utils import J_conjugate, Rotation, all_pairs, anorm, trange
910

@@ -16,7 +17,7 @@
1617
logger = logging.getLogger(__name__)
1718

1819

19-
class CLSymmetryC3C4(CLOrient3D, SyncVotingMixin):
20+
class CLSymmetryC3C4(CLOrient3D):
2021
"""
2122
Define a class to estimate 3D orientations using common lines methods for molecules with
2223
C3 and C4 cyclic symmetry.
@@ -144,7 +145,7 @@ def _estimate_relative_viewing_directions(self):
144145
Riis = self._estimate_all_Riis_c3_c4(sclmatrix)
145146

146147
# Step 4: Calculate relative rotations
147-
Rijs = self._estimate_all_Rijs_c3_c4(self.clmatrix)
148+
Rijs = self._estimate_all_Rijs_c3_c4()
148149

149150
# Step 5: Inner J-synchronization
150151
vijs, viis = self._local_J_sync_c3_c4(Rijs, Riis)
@@ -317,17 +318,21 @@ def _estimate_all_Riis_c3_c4(self, sclmatrix):
317318

318319
return Riis
319320

320-
def _estimate_all_Rijs_c3_c4(self, clmatrix):
321+
def _estimate_all_Rijs_c3_c4(self):
321322
"""
322323
Estimate Rijs using the voting method.
323324
"""
324-
n_img = self.n_img
325-
n_theta = self.n_theta
326-
pairs = all_pairs(n_img)
325+
pairs = all_pairs(self.n_img)
327326
Rijs = np.zeros((len(pairs), 3, 3))
328327
for idx, (i, j) in enumerate(pairs):
329-
Rijs[idx] = self._syncmatrix_ij_vote_3n(
330-
clmatrix, i, j, np.arange(n_img), n_theta
328+
Rijs[idx] = _syncmatrix_ij_vote_3n(
329+
self.clmatrix,
330+
i,
331+
j,
332+
np.arange(self.n_img),
333+
self.n_theta,
334+
self.hist_bin_width,
335+
self.full_width,
331336
)
332337

333338
return Rijs

src/aspire/abinitio/commonline_sync.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import numpy as np
44

5-
from aspire.abinitio import CLOrient3D, SyncVotingMixin
5+
from aspire.abinitio import CLOrient3D
6+
from aspire.abinitio.sync_voting import _rotratio_eulerangle_vec, _vote_ij
67
from aspire.utils import nearest_rotations
78
from aspire.utils.matlab_compat import stable_eigsh
89

910
logger = logging.getLogger(__name__)
1011

1112

12-
class CLSyncVoting(CLOrient3D, SyncVotingMixin):
13+
class CLSyncVoting(CLOrient3D):
1314
"""
1415
Define a class to estimate 3D orientations using synchronization matrix and voting method.
1516
@@ -199,9 +200,11 @@ def _syncmatrix_ij_vote(self, clmatrix, i, j, k_list, n_theta):
199200
:return: The (i,j) rotation block of the synchronization matrix
200201
"""
201202

202-
_, good_k = self._vote_ij(clmatrix, n_theta, i, j, k_list)
203+
_, good_k = _vote_ij(
204+
clmatrix, n_theta, i, j, k_list, self.hist_bin_width, self.full_width
205+
)
203206

204-
rots = self._rotratio_eulerangle_vec(clmatrix, i, j, good_k, n_theta)
207+
rots = _rotratio_eulerangle_vec(clmatrix, i, j, good_k, n_theta)
205208

206209
if rots is not None:
207210
rot_mean = np.mean(rots, 0)

src/aspire/abinitio/commonline_sync3n.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
from numpy.linalg import norm
77
from scipy.optimize import curve_fit
88

9-
from aspire.abinitio import CLOrient3D, SyncVotingMixin
9+
from aspire.abinitio import CLOrient3D
10+
from aspire.abinitio.sync_voting import _syncmatrix_ij_vote_3n
1011
from aspire.utils import J_conjugate, all_pairs, nearest_rotations, random, tqdm, trange
1112
from aspire.utils.matlab_compat import stable_eigsh
1213

1314
logger = logging.getLogger(__name__)
1415

1516

16-
class CLSync3N(CLOrient3D, SyncVotingMixin):
17+
class CLSync3N(CLOrient3D):
1718
"""
1819
Define a class to estimate 3D orientations using common lines Sync3N methods (2017).
1920
@@ -955,7 +956,7 @@ def _estimate_all_Rijs_host(self, clmatrix):
955956
Rijs = np.zeros((len(self._pairs), 3, 3))
956957

957958
for idx, (i, j) in enumerate(tqdm(self._pairs, desc="Estimate Rijs")):
958-
Rijs[idx] = self._syncmatrix_ij_vote_3n(
959+
Rijs[idx] = _syncmatrix_ij_vote_3n(
959960
clmatrix, i, j, np.arange(n_img), n_theta
960961
)
961962

0 commit comments

Comments
 (0)