def driver(image_file, algorithm, binary_threshold, canny_low, canny_high, window_height, window_width, tracking, gap, repeat, transpose, debug, quiet): align = Alignment(image_file) params = { 'binary_threshold': binary_threshold, 'canny_thresh_low': canny_low, 'canny_thresh_high': canny_high, 'window_height': window_height, 'window_width' : window_width, 'gap': gap, 'transpose': transpose, 'debug': debug, 'quiet': quiet } if tracking: tracking(params, algorithm, repeat) elif algorithm: print(align.compute_center(algorithm, params));
def constrain_mutant_to_wt(mutant_pose, wt_pose, mut_focus_residues, wt_focus_residues, constrain=True, shell=6): aligner = Alignment(mutant_pose, wt_pose) # Get chain info (this is a roundabout way of getting this and # should probably be refactored at some point.) # Initially this just used the Rosetta chain, but (older?) versions # of PyRosetta do not seem to support that. tchain = mutant_pose.pdb_info().chain(mut_focus_residues[0]) mchain = wt_pose.pdb_info().chain(wt_focus_residues[0]) # Create a selection shell aligner.create_shell(shell, mut_focus_residues, mobile_focus_list=wt_focus_residues, tchain=tchain, mchain=mchain) aligner.match_align() if constrain: alignment_dict = {} assert (len(mut_focus_residues) == len(wt_focus_residues)) for i in range(0, len(mut_focus_residues)): alignment_dict[(wt_focus_residues[i], mut_focus_residues[i])] = ['N', 'C', 'CA'] csts = constraints_from_pose(aligner.mobile, aligner.target, alignment_dict) for cst in csts: aligner.target.add_constraint(cst) return aligner
import cv2 from align import Alignment X = Alignment() def read(path): img = cv2.imread(path) height = img.shape[0] width = img.shape[1] ratio = height / width return cv2.resize(img, (int(500 * ratio), 500)) def draw_rec(event, x, y, flags, param): global ix, iy, ex, ey, drawing, mode if event == cv2.EVENT_LBUTTONDOWN: ix, iy = x, y elif event == cv2.EVENT_LBUTTONUP: ex, ey = x, y def get_crop_size(image): cv2.namedWindow('draw_rectangle') cv2.setMouseCallback('draw_rectangle', draw_rec, image) print("Choose your area of interest!") while 1: cv2.imshow('draw_rectangle', image) k = cv2.waitKey(1) & 0xFF if k == ord('a'):
def tracking(params, algorithm='pin', repeat=1): #### ENABLE TAB COMPLETION readline.parse_and_bind('tab: complete') ################################################# pixel_size = 1.172 ## um / pixel slit_center_x = 1000 slit_center_y = 600 ################################################# ### MOTOR SETTINGS ################################################# mtr_samXE = PyEpics.Motor('1ide1:m34') mtr_samYE = PyEpics.Motor('1ide1:m35') mtr_samZE = PyEpics.Motor('1ide1:m36') mtr_samTh = PyEpics.Motor('1ide1:m86') mtr_samChi = PyEpics.Motor('1ide1:m87') mtr_samOme = PyEpics.Motor('1ide:m9') mtr_aeroXE = PyEpics.Motor('1ide1:m101') mtr_aeroZE = PyEpics.Motor('1ide1:m102') ################################################# pname = '/home/beams/S1IDUSER/mnt/s1c/mli_nov19/tomo' for i in range(repeat): ################################################# ### ALIGN ROTATION AXIS TO THE HS ################################################# ### MOVE STAGE TO 0 mtr_samOme.move(0, wait=True) ### TAKE AN IMAGE AT OME 0 PyEpics.caput('1idPG1:cam1:Acquire', 1) time.sleep(3) fname = PyEpics.caget('1idPG1:TIFF1:FileName_RBV', 'str') + "_%06d" % ( PyEpics.caget('1idPG1:TIFF1:FileNumber_RBV') - 1) + '.tif' pfname = os.path.join(pname, fname) print(pfname) align0 = Alignment(pfname) x0, y0 = align0.compute_center(algorithm, params) print(f"pin x,y position when omega is 0 : (x = {x0}, y = {y0}") if (x0 == -1) or (y0 == -1): print("Alignment failed at zero degress") break ### MOVE STAGE TO 180 mtr_samOme.move(180, wait=True) ### TAKE AN IMAGE AT OME 180 PyEpics.caput('1idPG1:cam1:Acquire', 1) time.sleep(3) fname = PyEpics.caget('1idPG1:TIFF1:FileName_RBV', 'str') + "_%06d" % ( PyEpics.caget('1idPG1:TIFF1:FileNumber_RBV') - 1) + '.tif' pfname = os.path.join(pname, fname) align180 = Alignment(pfname) x180, y180 = align180.compute_center(algorithm, params) if (x180 == -1) or (y180 == -1): print("Alignment failed at 180 degrees") break print(f"pin x,y position when omega is 180 : (X = {x180}, y = {180})") ### COMPUTE MOTIONS TO MAKE mid_x = (x180 + x0) / 2 half_delta_x = (x180 - x0) / 2 print(mid_x) print(half_delta_x) ### NEED TO CHECK / FIGURE OUT THE SIGNS ON THESE aeroXE_motion = ((mid_x - slit_center_x) * pixel_size) / 1000 samXE_motion = -(half_delta_x * pixel_size) / 1000 print('motions to execute') print(aeroXE_motion) print(samXE_motion) mtr_aeroXE.move(aeroXE_motion, relative=True, wait=True) mtr_samXE.move(samXE_motion, relative=True, wait=True)