def listenShowJ(self): self.serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.serversocket.bind(('', self.showjPort)) #become a server socket self.serversocket.listen(1) while True: try: (clientsocket, address) = self.serversocket.accept() msg = clientsocket.recv( 1024) #should be a single message, so no loop tokens = shlex.split(msg) cmd = tokens[0] if cmd == 'rotate': rot = float(tokens[1]) tilt = float(tokens[2]) psi = float(tokens[3]) matrix = xmipp.Euler_angles2matrix(rot, tilt, psi) elif cmd == 'rotate_matrix': matrixString = tokens[1] matrix = ast.literal_eval(matrixString) matrix = [matrix[0][:3], matrix[1][:3], matrix[2][:3]] self.client.send('rotate') self.client.send(matrix) clientsocket.close() except EOFError: print('Lost connection to client')
def listenShowJ(self): """This function with a very confusing name send messages to the chimera server""" while True: try: (clientsocket, address) = self.serversocket.accept() msg = clientsocket.recv( 1024) #should be a single message, so no loop tokens = shlex.split(msg) cmd = tokens[0] if cmd == 'rotate': rot = float(tokens[1]) tilt = float(tokens[2]) psi = float(tokens[3]) matrix = xmipp.Euler_angles2matrix(rot, tilt, psi) elif cmd == 'rotate_matrix': matrixString = tokens[1] matrix = ast.literal_eval(matrixString) matrix = [matrix[0][:3], matrix[1][:3], matrix[2][:3]] self.client.send('rotate') self.client.send(matrix) clientsocket.close() except EOFError: print('Lost connection to client')
def _getTransformation(self, md, objId): rot = md.getValue(xmipp.MDL_ANGLE_ROT, objId) or 0. tilt = md.getValue(xmipp.MDL_ANGLE_TILT, objId) or 0. psi = md.getValue(xmipp.MDL_ANGLE_PSI, objId) or 0. tMatrix = xmipp.Euler_angles2matrix(rot, tilt, psi) x = md.getValue(xmipp.MDL_SHIFT_X, objId) or 0. y = md.getValue(xmipp.MDL_SHIFT_Y, objId) or 0. z = md.getValue(xmipp.MDL_SHIFT_Z, objId) or 0. matrix = [ tMatrix[0][0], tMatrix[0][1], tMatrix[0][2], x, tMatrix[1][0], tMatrix[1][1], tMatrix[1][2], y, tMatrix[2][0], tMatrix[2][1], tMatrix[2][2], z ] return matrix
def _showProjMatchLibAndImages(self, paramName=None): from numpy import array, dot #map stack position with ref number imgAndClasses = [] mdIn = xmipp.MetaData() mdOut = xmipp.MetaData() mdTmp = xmipp.MetaData() for ref3d in self._refsList: for it in self._iterations: convert_refno_to_stack_position = {} file_name = self.protocol._getFileName( 'projectLibrarySampling', iter=it, ref=ref3d) file_nameReferences = 'projectionDirections@' + file_name if exists(file_name): #last reference name mdReferences = xmipp.MetaData(file_nameReferences) mdReferencesSize = mdReferences.size() for id in mdReferences: convert_refno_to_stack_position[mdReferences.getValue( xmipp.MDL_NEIGHBOR, id)] = id file_nameImages = "ctfGroup[0-9][0-9][0-9][0-9][0-9][0-9]@" + self.protocol._getFileName( 'docfileInputAnglesIters', iter=it) mdTmp.read(file_nameImages) #query with ref3D mdIn.importObjects(mdTmp, xmipp.MDValueEQ(xmipp.MDL_REF3D, ref3d)) mdOut.clear() for i in mdIn: id1 = mdOut.addObject() mdOut.setValue(xmipp.MDL_IMAGE, mdIn.getValue(xmipp.MDL_IMAGE, i), id1) psi = -1. * mdIn.getValue(xmipp.MDL_ANGLE_PSI, i) flip = mdIn.getValue(xmipp.MDL_FLIP, i) if (flip): psi = -psi eulerMatrix = xmipp.Euler_angles2matrix(0., 0., psi) x = mdIn.getValue(xmipp.MDL_SHIFT_X, i) y = mdIn.getValue(xmipp.MDL_SHIFT_Y, i) shift = array([x, y, 0]) shiftOut = dot(eulerMatrix, shift) [x, y, z] = shiftOut if flip: x = -x mdOut.setValue(xmipp.MDL_ANGLE_PSI, psi, id1) mdOut.setValue(xmipp.MDL_SHIFT_X, x, id1) mdOut.setValue(xmipp.MDL_SHIFT_Y, y, id1) mdOut.setValue(xmipp.MDL_FLIP, flip, id1) ref2D = mdIn.getValue(xmipp.MDL_REF, i) file_references = self.protocol._getFileName( 'projectLibraryStk', iter=it, ref=ref3d) file_reference = xmipp.FileName() file_reference.compose( convert_refno_to_stack_position[ref2D], file_references) id2 = mdOut.addObject() mdOut.setValue(xmipp.MDL_IMAGE, file_reference, id2) mdOut.setValue(xmipp.MDL_ANGLE_PSI, 0., id2) if mdOut.size() == 0: print "Empty metadata" else: file_nameReferences = self.protocol._getFileName( 'projectLibrarySampling', iter=it, ref=ref3d) sfn = createUniqueFileName(file_nameReferences) file_nameReferences = 'projectionDirections@' + sfn mdOut.write(file_nameReferences) imgAndClasses.append( self.createDataView(file_nameReferences)) else: print "File %s does not exist" % file_name return imgAndClasses