def mayavi(structure, N=10): """ import this module and run mayavi to see the divide and conquer boxes. Enjoy and play around. """ from enthought.mayavi.mlab import points3d from pylada.crystal.cppwrappers import periodic_dnc mesh, boxes = periodic_dnc(structure, nperbox=30, overlap=0.25, return_mesh = True) x, y, z, s = [], [], [], [] for i, box in enumerate(boxes): if i == N: continue x.extend([(atom.pos[0] + trans[0]) for atom, trans, inbox in box if inbox]) y.extend([(atom.pos[1] + trans[1]) for atom, trans, inbox in box if inbox]) z.extend([(atom.pos[2] + trans[2]) for atom, trans, inbox in box if inbox]) s.extend([0.5 for atom, trans, inbox in box if inbox]) points3d(x,y,z,s, scale_factor=0.1, colormap="copper") x, y, z, s = [], [], [], [] for i, box in enumerate(boxes): if i < N: continue x.extend([(atom.pos[0] + trans[0]) for atom, trans, inbox in box if inbox]) y.extend([(atom.pos[1] + trans[1]) for atom, trans, inbox in box if inbox]) z.extend([(atom.pos[2] + trans[2]) for atom, trans, inbox in box if inbox]) s.extend([float(i+1) + (0. if inbox else 0.4) for atom, trans, inbox in box if inbox]) break points3d(x,y,z,s, scale_factor=0.004, colormap="autumn") x, y, z, s = [], [], [], [] for i, box in enumerate(boxes): if i < N: continue x.extend([(atom.pos[0] + trans[0]) for atom, trans, inbox in box if not inbox]) y.extend([(atom.pos[1] + trans[1]) for atom, trans, inbox in box if not inbox]) z.extend([(atom.pos[2] + trans[2]) for atom, trans, inbox in box if not inbox]) s.extend([float(i+2) + (0. if inbox else 0.4) for atom, trans, inbox in box if not inbox]) break points3d(x,y,z,s, scale_factor=0.01, opacity=0.3)
def check(structure): from numpy import multiply, cast, any from numpy.linalg import inv from pylada.crystal.cppwrappers import periodic_dnc from pylada.math import gruber mesh, boxes = periodic_dnc(structure, nperbox=30, overlap=0.125, return_mesh = True) invcell = gruber(structure.cell) invcell[:, 0] /= float(mesh[0]) invcell[:, 1] /= float(mesh[1]) invcell[:, 2] /= float(mesh[2]) invcell = inv(invcell) for box in boxes: assert any(u[2] for u in box) for atom, trans, inbox in box: if inbox: break index = indices(invcell, trans+atom.pos, mesh) for atom, trans, inbox in box: pi = indices(invcell, trans+atom.pos, mesh) if inbox: assert all(abs(pi - index) < 1e-8), (pi, index) else: assert any( abs(u-v) == 1 \ or (w>1 and abs(u-v) == w-1) \ or w == 1 for u, v, w in zip(pi, index, mesh) )