def p6(c3a, c3b): ''' prep unit cell for P6 propogation ''' c3a_com = com(c3a) c3b_com = com(c3b) center = (c3b_com + c3a_com) / 2 center_tuple = center.tuple() xy_center = [center_tuple[0], center_tuple[1], 0.0] # print 'xy_center', xy_center # print 'np.linalg.norm(xy_center)', np.linalg.norm(xy_center) if np.linalg.norm(xy_center) > 0.00001: 'move to origin' trans(c3a, -Vec(xy_center)) trans(c3b, -Vec(xy_center)) else: 'close enough' c3a_com = com(c3a).tuple() c3b_com = com(c3b).tuple() c3_dist = (np.abs(c3a_com[0] - c3b_com[0])**2 + np.abs(c3a_com[1] - c3b_com[1])**2)**0.5 ### Angle between c3 centers must be 30 degrees ## 30, 60 degrees ## 0.523599, 1.5708 angle_to_c3a = np.arctan(c3a_com[1] / c3a_com[0]) # print np.degrees(angle_to_c3a), 'np.degrees(angle_to_c3a)' angle_correction = float(np.degrees(angle_to_c3a - 0.523599)) # print angle_correction,'angle_correction' rotz(c3a, -1 * angle_correction) rotz(c3b, -1 * angle_correction) ### one of c3 centers must be along y-axis c3a_com = com(c3a) c3b_com = com(c3b) # print 'c3_dist', c3_dist # disp_to_c3a = Vec(0.0, float(c3_dist), 0.0) - c3a_com # disp_to_c3b = Vec(0.0, float(c3_dist), 0.0) - c3b_com if c3a_com.tuple()[1] > c3b_com.tuple()[1]: # print 'A' displacement = (Vec(0.0, float(c3_dist), 0.0) - c3a_com).tuple() else: # print 'B' displacement = (Vec(0.0, float(c3_dist), 0.0) - c3b_com).tuple() displacement = Vec([displacement[0], displacement[1], 0.0]) trans(c3a, displacement) trans(c3b, displacement) # print 'c3_dist', c3_dist unit_cell = c3_dist * 1.73205080756887729352744634150587236694280525381038062805580 # print 'unit_cell', unit_cell CRYST1 = 'CRYST1{0}{0} 999.000 90.00 90.00 120.00 P 6 2'.format( str(unit_cell.round(3)).rjust(9)) print CRYST1
def show(self, points=[Vec(7, 12, 13), Vec(33, 34, 35)]): v = pymol.cmd.get_view() CGO = list() for x in self.frames: x.t = 100.0 * x.t assert self.celltype == "CUBIC" for p in points: for i, j, k in itertools.product(range(-1, 2), range(-1, 2), range(-1, 2)): CGO.extend(cgo_sphere(x * p + Vec(i, j, k) * 100.0)) pymol.cmd.load_cgo(CGO, self.name) cube(Vec(0, 0, 0), Vec(100, 100, 100)) pymol.cmd.set_view(v)
def op2xform(self, op): Xop, Yop, Zop = op.split(",") # print op X, Tx = self.op2vec(Xop) Y, Ty = self.op2vec(Yop) Z, Tz = self.op2vec(Zop) # print X # print Y # print Z # print Tx,Ty,Tz # print return Xform(Mat(X.x, X.y, X.z, Y.x, Y.y, Y.z, Z.x, Z.y, Z.z), Vec(Tx, Ty, Tz))
def hexgrid(n, w, maxang, sigma): global max_sinh, max_asinh dotthresh = cos(radians(maxang)) # if sigma != 0.0: # w = w / sigma X = w * Vec(1, 0, 0) Y = w * Vec(0.5, sqrt(3.0) / 2, 0) points = [] for i in range(-n, n + 1): for j in range(-n, n + 1): p = i * X + j * Y + Vec(0, 0, 1) old = max_sinh, max_asinh if sigma != 0.0: p.x = mysinh(p.x * sigma) / sigma p.y = mysinh(p.y * sigma) / sigma p2 = p p = p / p.length() if p.z >= dotthresh: points.append((p, p2)) else: # restore if not accepted max_sinh, max_asinh = old return points
def op2vec(self, op): op = op.replace(" ", "") v, t = Vec(), 0 for o in op.replace("-", "+-").strip("+").split("+"): if o == 'X': v += Ux elif o == '-X': v -= Ux elif o == 'Y': v += Uy elif o == '-Y': v -= Uy elif o == 'Z': v += Uz elif o == '-Z': v -= Uz elif o.count("/"): n, d = o.split("/") t += float(n) / float(d) else: raise ValueError return v, t
def hcp(i, j, k, r=1.0): return r * Vec(2.0 * i + (j % 2) + (k % 2), (j + (k % 2) / 3.0) * sqrt(3.0), k * sqrt(6.0) / 3.0 * 2.0)