def createOutputStep(self): firstCoords = self.inputCoordinates[0].get() inputMics = firstCoords.getMicrographs() setOfCoordinates = self._createSetOfCoordinates(inputMics) setOfCoordinates.setBoxSize(firstCoords.getBoxSize()) # Read all consensus particles for micrograph in inputMics: fnTmp = self._getExtraPath('consensus_%06d.txt' % micrograph.getObjId()) if os.path.exists(fnTmp): coords = np.loadtxt(fnTmp) if coords.size == 2: # special case with only one coordinate in consensus coords = [coords] for coord in coords: aux = Coordinate() aux.setMicrograph(micrograph) aux.setX(coord[0]) aux.setY(coord[1]) setOfCoordinates.append(aux) #cleanPath(fnTmp) # Set output self._defineOutputs(outputCoordinates=setOfCoordinates) for coordinates in self.inputCoordinates: self._defineSourceRelation(coordinates, self.outputCoordinates)
def createOutputStep(self): firstCoords = self.inputCoordinates[0].get() inputMics = firstCoords.getMicrographs() setOfCoordinates = self._createSetOfCoordinates(inputMics) setOfCoordinates.setBoxSize(firstCoords.getBoxSize()) # Read all consensus particles for micrograph in inputMics: fnTmp = self._getExtraPath("consensus_%06d.txt" % micrograph.getObjId()) if os.path.exists(fnTmp): coords = np.loadtxt(fnTmp) if coords.size == 2: # special case with only one coordinate in consensus coords = [coords] for coord in coords: aux = Coordinate() aux.setMicrograph(micrograph) aux.setX(coord[0]) aux.setY(coord[1]) setOfCoordinates.append(aux) # cleanPath(fnTmp) # Set output self._defineOutputs(outputCoordinates=setOfCoordinates) for coordinates in self.inputCoordinates: self._defineSourceRelation(coordinates.get(), self.outputCoordinates)
def aaatest_particlesToStar(self): """ Write a SetOfParticles to Relion star input file. """ imgSet = SetOfParticles( filename=self.getOutputPath("particles.sqlite")) n = 10 fn = self.particles ctfs = [ CTFModel(defocusU=10000, defocusV=15000, defocusAngle=15), CTFModel(defocusU=20000, defocusV=25000, defocusAngle=25) ] acquisition = Acquisition(magnification=60000, voltage=300, sphericalAberration=2., amplitudeContrast=0.07) imgSet.setAcquisition(acquisition) coord = Coordinate() coord.setMicId(1) for i in range(n): p = Particle() p.setLocation(i + 1, fn) ctf = ctfs[i % 2] p.setCTF(ctf) p.setAcquisition(acquisition) p._xmipp_zScore = Float(i) coord.setX(i * 10) coord.setY(i * 10) p.setCoordinate(coord) imgSet.append(p) fnStar = self.getOutputPath('particles.star') fnStk = self.getOutputPath('particles.stk') print ">>> Writing to file: %s" % fnStar relion.writeSetOfParticles(imgSet, fnStar, fnStk) mdAll = md.MetaData(fnStar) self.assertTrue(mdAll.containsLabel(md.RLN_IMAGE_COORD_X)) self.assertTrue(mdAll.containsLabel(md.RLN_IMAGE_COORD_Y)) self.assertFalse(mdAll.containsLabel(md.RLN_SELECT_PARTICLES_ZSCORE))
def test_particlesWithPhaseShiftToStar(self): """ Write a SetOfParticles to Relion star input file. """ imgSet = SetOfParticles(filename=self.getOutputPath("particles_ph_sh.sqlite")) n = 10 fn = self.getFile('particles_binary') ctfs = [CTFModel(defocusU=10000, defocusV=15000, defocusAngle=15, phaseShift=90), CTFModel(defocusU=20000, defocusV=25000, defocusAngle=25, phaseShift=60) ] acquisition = Acquisition(magnification=60000, voltage=300, sphericalAberration=2., amplitudeContrast=0.07) imgSet.setAcquisition(acquisition) coord = Coordinate() coord.setMicId(1) for i in range(n): p = Particle() p.setLocation(i + 1, fn) ctf = ctfs[i % 2] p.setCTF(ctf) p.setAcquisition(acquisition) p._xmipp_zScore = Float(i) coord.setX(i * 10) coord.setY(i * 10) p.setCoordinate(coord) imgSet.append(p) fnStar = self.getOutputPath('particles_ph_sh.star') fnStk = self.getOutputPath('particles.stk') print (">>> Writing to file: %s" % fnStar) relion.writeSetOfParticles(imgSet, fnStar, fnStk) mdAll = md.MetaData(fnStar) self.assertTrue(mdAll.containsLabel(md.RLN_IMAGE_COORD_X)) self.assertTrue(mdAll.containsLabel(md.RLN_IMAGE_COORD_Y)) self.assertFalse(mdAll.containsLabel(md.RLN_SELECT_PARTICLES_ZSCORE)) self.assertTrue(mdAll.containsLabel(md.RLN_CTF_PHASESHIFT))
def create_subparticles(particle, symmetry_matrices, subparticle_vector_list, part_image_size, randomize, subparticles_total, align_subparticles): """ Obtain all subparticles from a given particle and set the properties of each such subparticle. """ # Euler angles that take particle to the orientation of the model matrix_particle = inv(particle.getTransform().getMatrix()) shifts, angles = geometryFromMatrix(matrix_particle) subparticles = [] subparticles_total += 1 symmetry_matrix_ids = range(1, len(symmetry_matrices) + 1) if randomize: # randomize the order of symmetry matrices, prevents preferred views random.shuffle(symmetry_matrix_ids) for subparticle_vector in subparticle_vector_list: matrix_from_subparticle_vector = subparticle_vector.get_matrix() for symmetry_matrix_id in symmetry_matrix_ids: # symmetry_matrix_id can be later written out to find out # which symmetry matrix created this subparticle symmetry_matrix = np.array(symmetry_matrices[symmetry_matrix_id - 1][0:3, 0:3]) subpart = particle.clone() m = np.matmul( matrix_particle[0:3, 0:3], (np.matmul(symmetry_matrix.transpose(), matrix_from_subparticle_vector.transpose()))) angles_org = -1.0 * np.ones(3) * euler_from_matrix(m, 'szyz') if align_subparticles: angles = -1.0 * np.ones(3) * euler_from_matrix(m, 'szyz') else: m2 = np.matmul(matrix_particle[0:3, 0:3], symmetry_matrix.transpose()) angles = -1.0 * np.ones(3) * euler_from_matrix(m2, 'szyz') # subparticle origin d = subparticle_vector.get_length() x = -m[0, 2] * d + shifts[0] y = -m[1, 2] * d + shifts[1] z = -m[2, 2] * d # save the subparticle coordinates (integer part) relative to the # user given image size and as a small shift in the origin (decimal part) x_d, x_i = math.modf(x) y_d, y_i = math.modf(y) alignment = em.Transform() alignmentOrg = em.Transform() M = matrixFromGeometry(np.array([-x_d, -y_d, 0]), angles, True) MOrg = matrixFromGeometry(np.array([-x_d, -y_d, 0]), angles_org, True) alignment.setMatrix(M) alignmentOrg.setMatrix(MOrg) subpart._transorg = alignmentOrg.clone() subpart.setTransform(alignment) coord = Coordinate() coord.setObjId(None) coord.setX(int(part_image_size / 2) - x_i) coord.setY(int(part_image_size / 2) - y_i) coord.setMicId(particle.getObjId()) if subpart.hasCTF(): ctf = subpart.getCTF() ctf.setDefocusU(subpart.getDefocusU() + z) ctf.setDefocusV(subpart.getDefocusV() + z) subpart.setCoordinate(coord) coord._subparticle = subpart.clone() subparticles.append(subpart) return subparticles