def show_ref_ns(frame): beadid = REF_BEAD position = frame.bead_coords[beadid] * 10 normal = frame.normals[beadid] x, y, z = position cmd.load_cgo([COLOR, 0.80, 0.22, 0.22, SPHERE, x, y, z, 3.0], "NS_ref") neighbors = neighbor_search(frame.box, frame.bead_coords, cutoff=NS_RADIUS) cmd.load_cgo([COLOR, 0.8, 1.0, 0.8, SPHERE, x, y, z, NS_RADIUS * 10.0], "NS_cutoff") cmd.set("cgo_transparency", 0.6, "NS_cutoff") cgo_neighbors = [] for nid in neighbors[beadid]: x, y, z = frame.bead_coords[nid] * 10 cgo_neighbors.extend([COLOR, 0.18, 0.53, 0.18, SPHERE, x, y, z, 2.1]) cmd.load_cgo(cgo_neighbors, "NS_neighbors") cgo_pca = [] cgo_pca = draw_vector(position, normal, cgo_obj=cgo_pca, color=(0.33, 0.67, 0.33), alpha=1.0, factor=1.5, length=20) cmd.load_cgo(cgo_pca, "NS_normal") print("Fatslim reference bead drawn")
def show_apl(frame): from fatslimlib.core_geometry import get_zoi, is_inside_polygon, clip_zoi from scipy.spatial import Voronoi beadid = REF_BEAD ref_position = frame.bead_coords[beadid] x, y, z = ref_position * 10 membrane = frame.get_membranes()[0] cmd.load_cgo([COLOR, 0.8, 0.2, 1.0, SPHERE, x, y, z, 2.5], "APL_ref") cmd.load_cgo([COLOR, 0.8, 0.2, 1.0, SPHERE, 0, 0, 0, 2.5], "APL_ref_2D") cmd.load_cgo([COLOR, 0.8, 1.0, 0.8, SPHERE, x, y, z, APL_DEFAULT_CUTOFF * 10.0], "APL_cutoff") cmd.set("cgo_transparency", 0.6, "APL_cutoff") if beadid in membrane.leaflet1.beadids: same_leaflet = membrane.leaflet1 else: same_leaflet = membrane.leaflet2 ref_leaflet_beadid = list(same_leaflet.beadids).index(beadid) ref_normal = same_leaflet.normals[ref_leaflet_beadid] cgo_ref_normal = draw_vector(ref_position * 10, ref_normal, cgo_obj=[], color=(1.0, 1.0, 0.22), alpha=1.0) cmd.load_cgo(cgo_ref_normal, "APL_ref_normal") lipid_neighbors = neighbor_search( frame.box, np.array([ref_position]), neighbor_coords=same_leaflet.coords, cutoff=APL_DEFAULT_CUTOFF ) lipid_coords_2d = put_atoms_on_plane(ref_position, ref_normal, lipid_neighbors[0], same_leaflet.coords, frame.box) cgo_2d_plane_axes = [] cgo_plane_axes = [] for axis in complete_basis(ref_normal): cgo_plane_axes = draw_vector( ref_position * 10, axis, cgo_obj=cgo_plane_axes, color=(0.22, 1.0, 0.5), alpha=1.0, factor=0.5 ) for i in range(2): axis = np.zeros(3) axis[i] = 1.0 cgo_2d_plane_axes = draw_vector( [0.0, 0.0, 0.0], axis, cgo_obj=cgo_2d_plane_axes, color=(0.22, 1.0, 0.5), alpha=1.0, factor=0.5 ) cmd.load_cgo(cgo_2d_plane_axes, "APL_2d_plane") cmd.load_cgo(cgo_plane_axes, "APL_plane") cgo_lipid_neighbors = [] cgo_lipid_neighbors_2d = [] cgo_lipid_projection_lines = [] cgo_lipid_neighbors_proj = [] for i, nid in enumerate(lipid_neighbors[0]): cur_coords = same_leaflet.coords[nid] x, y, z = cur_coords * 10 cgo_lipid_neighbors.extend([COLOR, 0.18, 0.53, 0.18, SPHERE, x, y, z, 2.1]) x2d, y2d = lipid_coords_2d[i] * 10 cgo_lipid_neighbors_2d.extend([COLOR, 0.4, 0.6, 1.0, SPHERE, x2d, y2d, 0.0, 1.9]) dx_vector = frame.box.dx(ref_position, cur_coords) proj = cur_coords - np.dot(dx_vector, ref_normal) * ref_normal proj *= 10 cgo_lipid_projection_lines.extend( [ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, x, y, z, # 1 VERTEX, proj[XX], proj[YY], proj[ZZ], # 2 END, ] ) cgo_lipid_neighbors_proj.extend([COLOR, 0.4, 0.6, 1.0, SPHERE, proj[XX], proj[YY], proj[ZZ], 1.9]) cmd.load_cgo(cgo_lipid_neighbors, "APL_lipid_neighbors") cmd.load_cgo(cgo_lipid_neighbors_2d, "APL_2D_lipid_neighbors") cmd.load_cgo(cgo_lipid_neighbors_proj, "APL_proj_lipid_neighbors") cmd.load_cgo(cgo_lipid_projection_lines, "APL_lipid_projection_lines") zoi = get_zoi(np.zeros(2), lipid_coords_2d) * 10 if len(zoi) == 0: print("APL: Error no ZOI!") else: print("APL: ZOI polygon has %i vertices" % len(zoi)) cgo_zoi = [] for i in range(len(zoi)): start = zoi[i] end = zoi[(i + 1) % len(zoi)] cgo_zoi.extend( [ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, start[XX], start[YY], 0, # 1 VERTEX, end[XX], end[YY], 0, # 2 END, ] ) cmd.load_cgo(cgo_zoi, "APL_ZOI") voro_pts = lipid_coords_2d.tolist() voro_pts.append([0.0, 0.0]) voro_pts = np.array(voro_pts) voro_diagram = Voronoi(voro_pts) vor_vertices = voro_diagram.vertices * 10 cgo_voro = [] for region in voro_diagram.regions: if len(region) == 0 or -1 in region: continue for i in range(len(region)): start = vor_vertices[region[i]] end = vor_vertices[region[(i + 1) % len(region)]] cgo_voro.extend( [ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, start[XX], start[YY], 0, # 1 VERTEX, end[XX], end[YY], 0, # 2 END, ] ) cmd.load_cgo(cgo_voro, "APL_VORO") if len(frame.interacting_group_coords) != 0: print("APL: %i interacting coords to take into account. " % len(frame.interacting_group_coords)) interacting_neighbors = neighbor_search( frame.box, np.array([ref_position]), neighbor_coords=frame.interacting_group_coords, cutoff=APL_DEFAULT_CUTOFF, ) interacting_coords_2d = put_atoms_on_plane( ref_position, ref_normal, interacting_neighbors[0], frame.interacting_group_coords, frame.box ) cgo_interacting_neighbors = [] cgo_interacting_neighbors_2d = [] cgo_interacting_projection_lines = [] cgo_interacting_neighbors_proj = [] cgo_interacting_xcm_used = [] total_weight = 0 xcm_interacting = np.zeros(2) zoi /= 10 for i, nid in enumerate(interacting_neighbors[0]): cur_coords = frame.interacting_group_coords[nid] x, y, z = cur_coords * 10 cgo_interacting_neighbors.extend([COLOR, 1.0, 1.0, 0.18, SPHERE, x, y, z, 1.0]) x2d, y2d = interacting_coords_2d[i] * 10 cgo_interacting_neighbors_2d.extend([COLOR, 1.0, 0.7, 0.2, SPHERE, x2d, y2d, 0.0, 0.9]) dx_vector = frame.box.dx(ref_position, cur_coords) interacting_weight = np.abs(dprod(dx_vector, ref_normal)) / APL_DEFAULT_CUTOFF proj = cur_coords - np.dot(dx_vector, ref_normal) * ref_normal proj *= 10 cgo_interacting_projection_lines.extend( [ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, x, y, z, # 1 VERTEX, proj[XX], proj[YY], proj[ZZ], # 2 END, ] ) cgo_interacting_neighbors_proj.extend([COLOR, 0.4, 0.6, 1.0, SPHERE, proj[XX], proj[YY], proj[ZZ], 1.9]) if is_inside_polygon(zoi, interacting_coords_2d[i]): total_weight += interacting_weight xcm_interacting[XX] += interacting_weight * interacting_coords_2d[i][XX] xcm_interacting[YY] += interacting_weight * interacting_coords_2d[i][YY] cgo_interacting_xcm_used.extend( [ COLOR, 1.0, 0.5, 0.2, SPHERE, interacting_coords_2d[i][XX] * 10, interacting_coords_2d[i][YY] * 10, 0, 1.0, ] ) if total_weight > 0: xcm_interacting[XX] /= total_weight xcm_interacting[YY] /= total_weight clipped_zoi = clip_zoi(zoi, np.zeros(2), xcm_interacting) * 10 cmd.load_cgo( [COLOR, 1.0, 0.5, 0.2, SPHERE, xcm_interacting[XX] * 10, xcm_interacting[YY] * 10, np.zeros(2), 2.5], "APL_intera_XCM_2D", ) cgo_clipped_zoi = [] for j, start in enumerate(clipped_zoi): end = clipped_zoi[(j + 1) % len(clipped_zoi)] cgo_clipped_zoi.extend( [ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, start[XX], start[YY], 0, # 1 VERTEX, end[XX], end[YY], 0, # 2 END, ] ) cmd.load_cgo(cgo_clipped_zoi, "APL_CLIPPED_ZOI") cmd.load_cgo(cgo_interacting_neighbors, "APL_interacting_neighbors") cmd.load_cgo(cgo_interacting_neighbors_2d, "APL_2D_interacting_neighbors") cmd.load_cgo(cgo_interacting_neighbors_proj, "APL_proj_interacting_neighbors") cmd.load_cgo(cgo_interacting_projection_lines, "APL_interacting_projection_lines") cmd.load_cgo(cgo_interacting_xcm_used, "APL_interacting_xcm_used") print("FATSLiM APL OK")
def show_thickness(frame): beadid = REF_BEAD ref_position = frame.bead_coords[beadid] x, y, z = ref_position * 10 membrane = frame.get_membranes()[0] cmd.load_cgo([COLOR, 1.0, 0.2, 1.0, SPHERE, x, y, z, 2.5], "THICKNESS_ref") cmd.load_cgo([COLOR, 0.8, 1.0, 0.8, SPHERE, x, y, z, THICKNESS_DEFAULT_CUTOFF * 10.0], "THICKNESS_cutoff") cmd.set("cgo_transparency", 0.6, "THICKNESS_cutoff") if beadid in membrane.leaflet1.beadids: other_leaflet = membrane.leaflet2 same_leaflet = membrane.leaflet1 else: other_leaflet = membrane.leaflet1 same_leaflet = membrane.leaflet2 ref_leaflet_beadid = list(same_leaflet.beadids).index(beadid) ref_normal = same_leaflet.normals[ref_leaflet_beadid] cgo_ref_normal = draw_vector(ref_position * 10, ref_normal, cgo_obj=[], color=(1.0, 1.0, 0.22), alpha=1.0) cmd.load_cgo(cgo_ref_normal, "THICKNESS_ref_normal") # Step 1: get XCM same_neighbors = neighbor_search( frame.box, np.array([ref_position]), neighbor_coords=same_leaflet.coords, cutoff=NS_RADIUS ) total_weight = 0.0 ref_xcm = np.zeros(3) cgo_neighbors = [] cgo_useful = [] for nid in same_neighbors[0]: dprod_normal = dprod(same_leaflet.normals[nid], ref_normal) if dprod_normal < THICKNESS_MIN_COS_NORMAL: continue dx = frame.box.dx(ref_position, same_leaflet.coords[nid]) x, y, z = same_leaflet.coords[nid] * 10 cgo_neighbors.extend([COLOR, 0.18, 0.53, 0.18, SPHERE, x, y, z, 2.1]) dx_norm = norm(dx) if dx_norm < EPSILON: continue weight = 1 - dx_norm / NS_RADIUS weight = 1 total_weight += weight dx *= weight ref_xcm += dx cgo_useful.extend([COLOR, 0.90, 0.80, 0.18, SPHERE, x, y, z, 2.5]) if total_weight > EPSILON: ref_xcm /= total_weight ref_xcm += ref_position x, y, z = ref_xcm * 10.0 cmd.load_cgo([COLOR, 0.0, 0.3, 1.0, SPHERE, x, y, z, 3.5], "THICKNESS_REF_XCM") cmd.load_cgo(cgo_neighbors, "THICKNESS_REF_neighbors") cmd.load_cgo(cgo_useful, "THICKNESS_REF_used") neighbors = neighbor_search( frame.box, np.array([ref_position]), neighbor_coords=other_leaflet.coords, cutoff=THICKNESS_DEFAULT_CUTOFF ) cgo_directions = [] cgo_normals = [] cgo_neighbors = [] cgo_useful = [] normals = other_leaflet.normals proj_lines = [] avg_dx = np.zeros(3) total_weight = 0 for nid in neighbors[0]: other_coord = other_leaflet.coords[nid] other_normal = other_leaflet.normals[nid] dprod_normal = dprod(other_normal, ref_normal) x, y, z = other_coord * 10 cgo_neighbors.extend([COLOR, 0.18, 0.53, 0.18, SPHERE, x, y, z, 2.1]) cgo_normals = draw_vector( other_coord * 10, other_normal, cgo_obj=cgo_normals, color=(1.0, 1.0, 0.22), alpha=1.0 ) # Make sure that both beads belong to different leaflet if dprod_normal > -COS_45: continue # Get the distance (through the bilayer) between the ref bead and its twin dx = frame.box.dx_leaflet(ref_xcm, other_coord, ref_normal) dx_norm = norm(dx) # we check dx because the image which is on the right side of the bilayer may not be a good twin (too far) if dx_norm > THICKNESS_DEFAULT_CUTOFF: continue dprod_dx = np.abs(dprod(dx, ref_normal)) cos_trial = dprod_dx / dx_norm if cos_trial < THICKNESS_MIN_COS_DX: continue weight = (np.abs(dprod_normal) - THICKNESS_MIN_COS_NORMAL) / (1.0 - THICKNESS_MIN_COS_NORMAL) # weight = 1 if weight > 0: dx *= weight total_weight += weight avg_dx += dx cgo_useful.extend([COLOR, 0.90, 0.80, 0.18, SPHERE, x, y, z, 2.5]) dx = frame.box.dx_leaflet(ref_position, other_leaflet.coords[nid], ref_normal) coords = ref_position + dx cgo_normals = draw_vector(coords * 10, normals[nid], cgo_obj=cgo_normals, color=(1.0, 1.0, 0.22), alpha=1.0) if total_weight > EPSILON: avg_dx /= total_weight other_xcm = ref_xcm + avg_dx x, y, z = other_xcm * 10 cmd.load_cgo([COLOR, 0.0, 1.0, 0.2, SPHERE, x, y, z, 3.5], "THICKNESS_OTHER_XCM") cmd.load_cgo(cgo_neighbors, "THICKNESS_neighbors") cmd.load_cgo(cgo_useful, "THICKNESS_used") cmd.load_cgo(cgo_normals, "THICKNESS_normals") x, y, z = ref_xcm * 10 dx, dy, dz = 100 * ref_normal ref_line = [ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, x - dx, y - dy, z - dz, # 1 VERTEX, x + dx, y + dy, z + dz, # 2 END, ] ref_line = draw_vector(ref_xcm * 10, ref_normal, cgo_obj=ref_line, color=(1.0, 1.0, 0.22), alpha=1.0) cmd.load_cgo(ref_line, "THICKNESS_normal_xcm") print("Fatslim thickness OK")
def show_apl(frame): from fatslimlib.core_geometry import get_zoi, is_inside_polygon, clip_zoi from scipy.spatial import Voronoi beadid = REF_BEAD ref_position = frame.bead_coords[beadid] x, y, z = ref_position * 10 membrane = frame.get_membranes()[0] cmd.load_cgo([COLOR, 0.8, 0.2, 1.0, SPHERE, x, y, z, 2.5], "APL_ref") cmd.load_cgo([COLOR, 0.8, 0.2, 1.0, SPHERE, 0, 0, 0, 2.5], "APL_ref_2D") cmd.load_cgo([COLOR, 0.8, 1.0, 0.8, SPHERE, x, y, z, APL_DEFAULT_CUTOFF * 10.0], "APL_cutoff") cmd.set("cgo_transparency", 0.6, "APL_cutoff") if beadid in membrane.leaflet1.beadids: same_leaflet = membrane.leaflet1 else: same_leaflet = membrane.leaflet2 ref_leaflet_beadid = list(same_leaflet.beadids).index(beadid) ref_normal = same_leaflet.normals[ref_leaflet_beadid] cgo_ref_normal = draw_vector(ref_position * 10, ref_normal, cgo_obj=[], color=(1.0, 1.0, 0.22), alpha=1.0) cmd.load_cgo(cgo_ref_normal, "APL_ref_normal") lipid_neighbors = neighbor_search(frame.box, np.array([ref_position, ]), neighbor_coords=same_leaflet.coords, cutoff=APL_DEFAULT_CUTOFF ) lipid_coords_2d = put_atoms_on_plane(ref_position, ref_normal, lipid_neighbors[0], same_leaflet.coords, frame.box) cgo_2d_plane_axes = [] cgo_plane_axes = [] for axis in complete_basis(ref_normal): cgo_plane_axes = draw_vector(ref_position * 10, axis, cgo_obj=cgo_plane_axes, color=(0.22, 1.0, 0.5), alpha=1.0, factor=0.5) for i in range(2): axis = np.zeros(3) axis[i] = 1.0 cgo_2d_plane_axes = draw_vector([0.0, 0.0, 0.0], axis, cgo_obj=cgo_2d_plane_axes, color=(0.22, 1.0, 0.5), alpha=1.0, factor=0.5) cmd.load_cgo(cgo_2d_plane_axes, "APL_2d_plane") cmd.load_cgo(cgo_plane_axes, "APL_plane") cgo_lipid_neighbors = [] cgo_lipid_neighbors_2d = [] cgo_lipid_projection_lines = [] cgo_lipid_neighbors_proj = [] for i, nid in enumerate(lipid_neighbors[0]): cur_coords = same_leaflet.coords[nid] x, y, z = cur_coords * 10 cgo_lipid_neighbors.extend([COLOR, 0.18, 0.53, 0.18, SPHERE, x, y, z, 2.1]) x2d, y2d = lipid_coords_2d[i] * 10 cgo_lipid_neighbors_2d.extend([COLOR, 0.4, 0.6, 1.0, SPHERE, x2d, y2d, 0.0, 1.9]) dx_vector = frame.box.dx(ref_position, cur_coords) proj = cur_coords - np.dot(dx_vector, ref_normal) * ref_normal proj *= 10 cgo_lipid_projection_lines.extend([ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, x, y, z, # 1 VERTEX, proj[XX], proj[YY], proj[ZZ], # 2 END ]) cgo_lipid_neighbors_proj.extend([COLOR, 0.4, 0.6, 1.0, SPHERE, proj[XX], proj[YY], proj[ZZ], 1.9]) cmd.load_cgo(cgo_lipid_neighbors, "APL_lipid_neighbors") cmd.load_cgo(cgo_lipid_neighbors_2d, "APL_2D_lipid_neighbors") cmd.load_cgo(cgo_lipid_neighbors_proj, "APL_proj_lipid_neighbors") cmd.load_cgo(cgo_lipid_projection_lines, "APL_lipid_projection_lines") zoi = get_zoi(np.zeros(2), lipid_coords_2d) * 10 if len(zoi) == 0: print("APL: Error no ZOI!") else: print("APL: ZOI polygon has %i vertices" % len(zoi)) cgo_zoi = [] for i in range(len(zoi)): start = zoi[i] end = zoi[(i + 1) % len(zoi)] cgo_zoi.extend([ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, start[XX], start[YY], 0, # 1 VERTEX, end[XX], end[YY], 0, # 2 END ]) cmd.load_cgo(cgo_zoi, "APL_ZOI") voro_pts = lipid_coords_2d.tolist() voro_pts.append([0.0, 0.0]) voro_pts = np.array(voro_pts) voro_diagram = Voronoi(voro_pts) vor_vertices = voro_diagram.vertices * 10 cgo_voro = [] for region in voro_diagram.regions: if len(region) == 0 or -1 in region: continue for i in range(len(region)): start = vor_vertices[region[i]] end = vor_vertices[region[(i + 1) % len(region)]] cgo_voro.extend([ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, start[XX], start[YY], 0, # 1 VERTEX, end[XX], end[YY], 0, # 2 END ]) cmd.load_cgo(cgo_voro, "APL_VORO") if len(frame.interacting_group_coords) != 0: print("APL: %i interacting coords to take into account. " % len(frame.interacting_group_coords)) interacting_neighbors = neighbor_search(frame.box, np.array([ref_position, ]), neighbor_coords=frame.interacting_group_coords, cutoff=APL_DEFAULT_CUTOFF ) interacting_coords_2d = put_atoms_on_plane(ref_position, ref_normal, interacting_neighbors[0], frame.interacting_group_coords, frame.box) cgo_interacting_neighbors = [] cgo_interacting_neighbors_2d = [] cgo_interacting_projection_lines = [] cgo_interacting_neighbors_proj = [] cgo_interacting_xcm_used = [] total_weight = 0 xcm_interacting = np.zeros(2) zoi /= 10 for i, nid in enumerate(interacting_neighbors[0]): cur_coords = frame.interacting_group_coords[nid] x, y, z = cur_coords * 10 cgo_interacting_neighbors.extend([COLOR, 1.0, 1.0, 0.18, SPHERE, x, y, z, 1.0]) x2d, y2d = interacting_coords_2d[i] * 10 cgo_interacting_neighbors_2d.extend([COLOR, 1.0, 0.7, 0.2, SPHERE, x2d, y2d, 0.0, 0.9]) dx_vector = frame.box.dx(ref_position, cur_coords) interacting_weight = np.abs(dprod(dx_vector, ref_normal)) / APL_DEFAULT_CUTOFF proj = cur_coords - np.dot(dx_vector, ref_normal) * ref_normal proj *= 10 cgo_interacting_projection_lines.extend([ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, x, y, z, # 1 VERTEX, proj[XX], proj[YY], proj[ZZ], # 2 END ]) cgo_interacting_neighbors_proj.extend( [COLOR, 0.4, 0.6, 1.0, SPHERE, proj[XX], proj[YY], proj[ZZ], 1.9]) if is_inside_polygon(zoi, interacting_coords_2d[i]): total_weight += interacting_weight xcm_interacting[XX] += interacting_weight * interacting_coords_2d[i][XX] xcm_interacting[YY] += interacting_weight * interacting_coords_2d[i][YY] cgo_interacting_xcm_used.extend( [COLOR, 1.0, 0.5, 0.2, SPHERE, interacting_coords_2d[i][XX] * 10, interacting_coords_2d[i][YY] * 10, 0, 1.0]) if total_weight > 0: xcm_interacting[XX] /= total_weight xcm_interacting[YY] /= total_weight clipped_zoi = clip_zoi(zoi, np.zeros(2), xcm_interacting) * 10 cmd.load_cgo([COLOR, 1.0, 0.5, 0.2, SPHERE, xcm_interacting[XX] * 10, xcm_interacting[YY] * 10, np.zeros(2), 2.5], "APL_intera_XCM_2D") cgo_clipped_zoi = [] for j, start in enumerate(clipped_zoi): end = clipped_zoi[(j + 1) % len(clipped_zoi)] cgo_clipped_zoi.extend([ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, start[XX], start[YY], 0, # 1 VERTEX, end[XX], end[YY], 0, # 2 END ]) cmd.load_cgo(cgo_clipped_zoi, "APL_CLIPPED_ZOI") cmd.load_cgo(cgo_interacting_neighbors, "APL_interacting_neighbors") cmd.load_cgo(cgo_interacting_neighbors_2d, "APL_2D_interacting_neighbors") cmd.load_cgo(cgo_interacting_neighbors_proj, "APL_proj_interacting_neighbors") cmd.load_cgo(cgo_interacting_projection_lines, "APL_interacting_projection_lines") cmd.load_cgo(cgo_interacting_xcm_used, "APL_interacting_xcm_used") print("FATSLiM APL OK")
def show_thickness(frame): beadid = REF_BEAD ref_position = frame.bead_coords[beadid] x, y, z = ref_position * 10 membrane = frame.get_membranes()[0] cmd.load_cgo([COLOR, 1.0, 0.2, 1.0, SPHERE, x, y, z, 2.5], "THICKNESS_ref") cmd.load_cgo([COLOR, 0.8, 1.0, 0.8, SPHERE, x, y, z, THICKNESS_DEFAULT_CUTOFF * 10.0], "THICKNESS_cutoff") cmd.set("cgo_transparency", 0.6, "THICKNESS_cutoff") if beadid in membrane.leaflet1.beadids: other_leaflet = membrane.leaflet2 same_leaflet = membrane.leaflet1 else: other_leaflet = membrane.leaflet1 same_leaflet = membrane.leaflet2 ref_leaflet_beadid = list(same_leaflet.beadids).index(beadid) ref_normal = same_leaflet.normals[ref_leaflet_beadid] cgo_ref_normal = draw_vector(ref_position * 10, ref_normal, cgo_obj=[], color=(1.0, 1.0, 0.22), alpha=1.0) cmd.load_cgo(cgo_ref_normal, "THICKNESS_ref_normal") # Step 1: get XCM same_neighbors = neighbor_search(frame.box, np.array([ref_position, ]), neighbor_coords=same_leaflet.coords, cutoff=NS_RADIUS ) total_weight = 0.0 ref_xcm = np.zeros(3) cgo_neighbors = [] cgo_useful = [] for nid in same_neighbors[0]: dprod_normal = dprod(same_leaflet.normals[nid], ref_normal) if dprod_normal < THICKNESS_MIN_COS_NORMAL: continue dx = frame.box.dx(ref_position, same_leaflet.coords[nid]) x, y, z = same_leaflet.coords[nid] * 10 cgo_neighbors.extend([COLOR, 0.18, 0.53, 0.18, SPHERE, x, y, z, 2.1]) dx_norm = norm(dx) if dx_norm < EPSILON: continue weight = 1 - dx_norm / NS_RADIUS weight = 1 total_weight += weight dx *= weight ref_xcm += dx cgo_useful.extend([COLOR, 0.90, 0.80, 0.18, SPHERE, x, y, z, 2.5]) if total_weight > EPSILON: ref_xcm /= total_weight ref_xcm += ref_position x, y, z = ref_xcm * 10.0 cmd.load_cgo([COLOR, 0.0, 0.3, 1.0, SPHERE, x, y, z, 3.5], "THICKNESS_REF_XCM") cmd.load_cgo(cgo_neighbors, "THICKNESS_REF_neighbors") cmd.load_cgo(cgo_useful, "THICKNESS_REF_used") neighbors = neighbor_search(frame.box, np.array([ref_position, ]), neighbor_coords=other_leaflet.coords, cutoff=THICKNESS_DEFAULT_CUTOFF) cgo_directions = [] cgo_normals = [] cgo_neighbors = [] cgo_useful = [] normals = other_leaflet.normals proj_lines = [] avg_dx = np.zeros(3) total_weight = 0 for nid in neighbors[0]: other_coord = other_leaflet.coords[nid] other_normal = other_leaflet.normals[nid] dprod_normal = dprod(other_normal, ref_normal) x, y, z = other_coord * 10 cgo_neighbors.extend([COLOR, 0.18, 0.53, 0.18, SPHERE, x, y, z, 2.1]) cgo_normals = draw_vector(other_coord * 10, other_normal, cgo_obj=cgo_normals, color=(1.0, 1.0, 0.22), alpha=1.0) # Make sure that both beads belong to different leaflet if dprod_normal > -COS_45: continue # Get the distance (through the bilayer) between the ref bead and its twin dx = frame.box.dx_leaflet(ref_xcm, other_coord, ref_normal) dx_norm = norm(dx) # we check dx because the image which is on the right side of the bilayer may not be a good twin (too far) if dx_norm > THICKNESS_DEFAULT_CUTOFF: continue dprod_dx = np.abs(dprod(dx, ref_normal)) cos_trial = dprod_dx / dx_norm if cos_trial < THICKNESS_MIN_COS_DX: continue weight = (np.abs(dprod_normal) - THICKNESS_MIN_COS_NORMAL) / \ (1.0 - THICKNESS_MIN_COS_NORMAL) # weight = 1 if weight > 0: dx *= weight total_weight += weight avg_dx += dx cgo_useful.extend([COLOR, 0.90, 0.80, 0.18, SPHERE, x, y, z, 2.5]) dx = frame.box.dx_leaflet(ref_position, other_leaflet.coords[nid], ref_normal) coords = ref_position + dx cgo_normals = draw_vector(coords * 10, normals[nid], cgo_obj=cgo_normals, color=(1.0, 1.0, 0.22), alpha=1.0) if total_weight > EPSILON: avg_dx /= total_weight other_xcm = ref_xcm + avg_dx x, y, z = other_xcm * 10 cmd.load_cgo([COLOR, 0.0, 1.0, 0.2, SPHERE, x, y, z, 3.5], "THICKNESS_OTHER_XCM") cmd.load_cgo(cgo_neighbors, "THICKNESS_neighbors") cmd.load_cgo(cgo_useful, "THICKNESS_used") cmd.load_cgo(cgo_normals, "THICKNESS_normals") x, y, z = ref_xcm * 10 dx, dy, dz = 100 * ref_normal ref_line = [ LINEWIDTH, 1.0, BEGIN, LINES, COLOR, 0.5, 0.5, 0.5, VERTEX, x - dx, y - dy, z - dz, # 1 VERTEX, x + dx, y + dy, z + dz, # 2 END ] ref_line = draw_vector(ref_xcm * 10, ref_normal, cgo_obj=ref_line, color=(1.0, 1.0, 0.22), alpha=1.0) cmd.load_cgo(ref_line, "THICKNESS_normal_xcm") print("Fatslim thickness OK")