def test(xyz): a = rotate(xyz) ixyz = '%sx,%sy,%sz' % irotate(a) a2 = rotate(ixyz) print(xyz) print(ixyz) assert abs(a - a2).max() < 1e-10
def test(xyz): a = rotate(xyz) ixyz = '%sx,%sy,%sz' % irotate(a) a2 = rotate(ixyz) #print xyz #print ixyz #print np.around(a-a2, 5) assert abs(a-a2).max() < 1e-10
def test(xyz): a = rotate(xyz) ixyz = '%sx,%sy,%sz' % irotate(a) a2 = rotate(ixyz) print xyz print ixyz #print np.around(a-a2, 5) assert abs(a - a2).max() < 1e-10
def __init__(self, rotations): self.colormode = 'jmol' # The default colors self.nselected = 0 self.labels = None self.axes = rotate(rotations) self.configured = False self.frame = None # XXX self.colormode = 'jmol' self.colors = {} for i, rgb in enumerate(jmol_colors): self.colors[i] = ('#{0:02X}{1:02X}{2:02X}'.format(*(int(x * 255) for x in rgb))) # scaling factors for vectors self.force_vector_scale = self.config['force_vector_scale'] self.velocity_vector_scale = self.config['velocity_vector_scale'] # buttons self.b1 = 1 # left self.b3 = 3 # right if self.config['swap_mouse']: self.b1 = 3 self.b3 = 1
def __init__(self, rotations): self.colormode = 'jmol' # The default colors self.nselected = 0 self.labels = None self.axes = rotate(rotations) self.configured = False self.frame = None
def __init__(self, vbox, rotations): self.colormode = 'jmol' # The default colors self.nselected = 0 self.light_green_markings = 0 self.axes = rotate(rotations) # this is a hack, in order to be able to toggle menu actions off/on # without getting into an infinte loop self.menu_change = 0 self.atoms_to_rotate = None self.drawing_area = gtk.DrawingArea() self.drawing_area.set_size_request(450, 450) self.drawing_area.connect('button_press_event', self.press) self.drawing_area.connect('button_release_event', self.release) self.drawing_area.connect('motion-notify-event', self.move) # Signals used to handle backing pixmap: self.drawing_area.connect('expose_event', self.expose_event) self.drawing_area.connect('configure_event', self.configure_event) self.drawing_area.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK) vbox.pack_start(self.drawing_area) self.drawing_area.show() self.configured = False self.frame = None
def __init__(self, vbox, rotations): self.colormode = 'jmol' # The default colors self.nselected = 0 self.light_green_markings = 0 self.axes = rotate(rotations) # this is a hack, in order to be able to toggle menu actions off/on # without getting into an infinte loop self.menu_change = 0 self.atoms_to_rotate = None self.drawing_area = gtk.DrawingArea() self.drawing_area.set_size_request(450, 450) self.drawing_area.connect('button_press_event', self.press) self.drawing_area.connect('button_release_event', self.release) self.drawing_area.connect('motion-notify-event', self.move) # Signals used to handle backing pixmap: self.drawing_area.connect('expose_event', self.expose_event) self.drawing_area.connect('configure_event', self.configure_event) self.drawing_area.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK) vbox.pack_start(self.drawing_area) self.drawing_area.show() self.configured = False self.config = None self.frame = None
def __init__(self, rotations): self.colormode = 'jmol' # The default colors self.nselected = 0 self.labels = None self.axes = rotate(rotations) self.configured = False self.frame = None # XXX self.colormode = 'jmol' self.colors = {} for i, rgb in enumerate(jmol_colors): self.colors[i] = ('#{0:02X}{1:02X}{2:02X}'.format(*(int(x * 255) for x in rgb)))
def __init__(self, rotations): self.colormode = 'jmol' # The default colors self.nselected = 0 self.labels = None self.axes = rotate(rotations) self.configured = False self.frame = None # XXX self.colormode = 'jmol' self.colors = {} for i, rgb in enumerate(jmol_colors): self.colors[i] = ('#{0:02X}{1:02X}{2:02X}' .format(*(int(x * 255) for x in rgb)))
def calculate_plotting_offset(self, rotation, scale, maxwidth): # from ase.visualize.plot and ase.io.utils R = np.dot(self.atoms.get_positions(), rotate(rotation)) radii = covalent_radii[self.atoms.numbers] X1 = (R - radii[:, None]).min(0) X2 = (R + radii[:, None]).max(0) if show_unit_cell == 2: X1 = np.minimum(X1, cell_vertices.min(0)) X2 = np.maximum(X2, cell_vertices.max(0)) M = (X1 + X2) / 2 S = 1.05 * (X2 - X1) w = scale * S[0] if w > maxwidth: w = maxwidth scale = w / S[0] h = scale * S[1] offset = np.array([scale * M[0] - w / 2, scale * M[1] - h / 2, 0]) return offset
def __init__(self, vbox, rotations): self.colors = [None] * (len(jmol_colors) + 1) self.nselected = 0 self.rotation = rotate(rotations) self.drawing_area = gtk.DrawingArea() self.drawing_area.set_size_request(450, 450) self.drawing_area.connect('button_press_event', self.press) self.drawing_area.connect('button_release_event', self.release) self.drawing_area.connect('motion-notify-event', self.move) # Signals used to handle backing pixmap: self.drawing_area.connect('expose_event', self.expose_event) self.drawing_area.connect('configure_event', self.configure_event) self.drawing_area.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK) vbox.pack_start(self.drawing_area) self.drawing_area.show() self.configured = False self.frame = None
def set_view(self, menuitem): plane_rotation = menuitem.get_name() if plane_rotation == 'xyPlane': self.axes = rotate('0.0x,0.0y,0.0z') elif plane_rotation == 'yzPlane': self.axes = rotate('-90.0x,-90.0y,0.0z') elif plane_rotation == 'zxPlane': self.axes = rotate('90.0x,0.0y,90.0z') elif plane_rotation == 'yxPlane': self.axes = rotate('180.0x,0.0y,90.0z') elif plane_rotation == 'zyPlane': self.axes = rotate('0.0x,90.0y,0.0z') elif plane_rotation == 'xzPlane': self.axes = rotate('-90.0x,0.0y,0.0z') else: if plane_rotation == 'a1a2Plane': i, j = 0, 1 elif plane_rotation == 'a2a3Plane': i, j = 1, 2 elif plane_rotation == 'a3a1Plane': i, j = 2, 0 elif plane_rotation == 'a2a1Plane': i, j = 1, 0 elif plane_rotation == 'a3a2Plane': i, j = 2, 1 elif plane_rotation == 'a1a3Plane': i, j = 0, 2 x1 = self.images.A[self.frame, i] x2 = self.images.A[self.frame, j] norm = np.linalg.norm x1 = x1 / norm(x1) x2 = x2 - x1 * np.dot(x1, x2) x2 /= norm(x2) x3 = np.cross(x1, x2) self.axes = np.array([x1, x2, x3]).T self.set_coordinates()
def set_view(self, key): if key == 'Z': self.axes = rotate('0.0x,0.0y,0.0z') elif key == 'X': self.axes = rotate('-90.0x,-90.0y,0.0z') elif key == 'Y': self.axes = rotate('90.0x,0.0y,90.0z') elif key == 'Alt+Z': self.axes = rotate('180.0x,0.0y,90.0z') elif key == 'Alt+X': self.axes = rotate('0.0x,90.0y,0.0z') elif key == 'Alt+Y': self.axes = rotate('-90.0x,0.0y,0.0z') else: if key == '3': i, j = 0, 1 elif key == '1': i, j = 1, 2 elif key == '2': i, j = 2, 0 elif key == 'Alt+3': i, j = 1, 0 elif key == 'Alt+1': i, j = 2, 1 elif key == 'Alt+2': i, j = 0, 2 A = complete_cell(self.atoms.cell) x1 = A[i] x2 = A[j] norm = np.linalg.norm x1 = x1 / norm(x1) x2 = x2 - x1 * np.dot(x1, x2) x2 /= norm(x2) x3 = np.cross(x1, x2) self.axes = np.array([x1, x2, x3]).T self.set_frame()
def __init__(self, atoms, rotation='', show_unit_cell=2, radii=None, bbox=None, colors=None, scale=20, maxwidth=500, extra_offset=(0., 0.)): self.numbers = atoms.get_atomic_numbers() self.colors = colors if colors is None: self.colors = jmol_colors[self.numbers] if radii is None: radii = covalent_radii[self.numbers] elif isinstance(radii, float): radii = covalent_radii[self.numbers] * radii else: radii = np.array(radii) natoms = len(atoms) if isinstance(rotation, basestring): rotation = rotate(rotation) cell = atoms.get_cell() disp = atoms.get_celldisp().flatten() if show_unit_cell > 0: L, T, D = cell_to_lines(self, cell) cell_vertices = np.empty((2, 2, 2, 3)) for c1 in range(2): for c2 in range(2): for c3 in range(2): cell_vertices[c1, c2, c3] = np.dot([c1, c2, c3], cell) + disp cell_vertices.shape = (8, 3) cell_vertices = np.dot(cell_vertices, rotation) else: L = np.empty((0, 3)) T = None D = None cell_vertices = None nlines = len(L) positions = np.empty((natoms + nlines, 3)) R = atoms.get_positions() positions[:natoms] = R positions[natoms:] = L r2 = radii**2 for n in range(nlines): d = D[T[n]] if ((((R - L[n] - d)**2).sum(1) < r2) & (((R - L[n] + d)**2).sum(1) < r2)).any(): T[n] = -1 positions = np.dot(positions, rotation) R = positions[:natoms] if bbox is None: X1 = (R - radii[:, None]).min(0) X2 = (R + radii[:, None]).max(0) if show_unit_cell == 2: X1 = np.minimum(X1, cell_vertices.min(0)) X2 = np.maximum(X2, cell_vertices.max(0)) M = (X1 + X2) / 2 S = 1.05 * (X2 - X1) w = scale * S[0] if w > maxwidth: w = maxwidth scale = w / S[0] h = scale * S[1] offset = np.array([scale * M[0] - w / 2, scale * M[1] - h / 2, 0]) else: w = (bbox[2] - bbox[0]) * scale h = (bbox[3] - bbox[1]) * scale offset = np.array([bbox[0], bbox[1], 0]) * scale offset[0] = offset[0] - extra_offset[0] offset[1] = offset[1] - extra_offset[1] self.w = w + extra_offset[0] self.h = h + extra_offset[1] positions *= scale positions -= offset if nlines > 0: D = np.dot(D, rotation)[:, :2] * scale if cell_vertices is not None: cell_vertices *= scale cell_vertices -= offset cell = np.dot(cell, rotation) cell *= scale self.cell = cell self.positions = positions self.D = D self.T = T self.cell_vertices = cell_vertices self.natoms = natoms self.d = 2 * scale * radii # extension for partial occupancies self.frac_occ = False self.tags = None self.occs = None try: self.occs = atoms.info['occupancy'] self.tags = atoms.get_tags() self.frac_occ = True except KeyError: pass
def change(self, adjustment): if self.update: x, y, z = [float(a.value) for a in self.rotate] self.gui.axes = rotate('%fx,%fy,%fz' % (x, y, z)) self.gui.set_coordinates() return True
def __init__(self, atoms, rotation='', show_unit_cell=False, radii=None, bbox=None, colors=None, scale=20): self.numbers = atoms.get_atomic_numbers() self.colors = colors if colors is None: self.colors = jmol_colors[self.numbers] if radii is None: radii = covalent_radii[self.numbers] elif type(radii) is float: radii = covalent_radii[self.numbers] * radii else: radii = np.array(radii) natoms = len(atoms) if isinstance(rotation, str): rotation = rotate(rotation) A = atoms.get_cell() if show_unit_cell > 0: L, T, D = self.cell_to_lines(A) C = np.empty((2, 2, 2, 3)) for c1 in range(2): for c2 in range(2): for c3 in range(2): C[c1, c2, c3] = np.dot([c1, c2, c3], A) C.shape = (8, 3) C = np.dot(C, rotation) # Unit cell vertices else: L = np.empty((0, 3)) T = None D = None C = None nlines = len(L) X = np.empty((natoms + nlines, 3)) R = atoms.get_positions() X[:natoms] = R X[natoms:] = L r2 = radii**2 for n in range(nlines): d = D[T[n]] if ((((R - L[n] - d)**2).sum(1) < r2) & (((R - L[n] + d)**2).sum(1) < r2)).any(): T[n] = -1 X = np.dot(X, rotation) R = X[:natoms] if bbox is None: X1 = (R - radii[:, None]).min(0) X2 = (R + radii[:, None]).max(0) if show_unit_cell == 2: X1 = np.minimum(X1, C.min(0)) X2 = np.maximum(X2, C.max(0)) M = (X1 + X2) / 2 S = 1.05 * (X2 - X1) w = scale * S[0] if w > 500: w = 500 scale = w / S[0] h = scale * S[1] offset = np.array([scale * M[0] - w / 2, scale * M[1] - h / 2, 0]) else: w = (bbox[2] - bbox[0]) * scale h = (bbox[3] - bbox[1]) * scale offset = np.array([bbox[0], bbox[1], 0]) * scale self.w = w self.h = h X *= scale X -= offset if nlines > 0: D = np.dot(D, rotation)[:, :2] * scale if C is not None: C *= scale C -= offset A = np.dot(A, rotation) A *= scale self.A = A self.X = X self.D = D self.T = T self.C = C self.natoms = natoms self.d = 2 * scale * radii
def reset_view(self, menuitem): self.axes = rotate('0.0x,0.0y,0.0z') self.set_coordinates() self.focus(self)
def change(self): x, y, z = [float(a.value) for a in self.rotate] self.gui.axes = rotate('%fx,%fy,%fz' % (x, y, z)) self.gui.set_frame()
def generate_writer_variables(writer, atoms, rotation='', show_unit_cell=0, radii=None, bbox=None, colors=None, scale=20, maxwidth=500, extra_offset=(0., 0.)): writer.numbers = atoms.get_atomic_numbers() writer.colors = colors if colors is None: writer.colors = jmol_colors[writer.numbers] if radii is None: radii = covalent_radii[writer.numbers] elif isinstance(radii, float): radii = covalent_radii[writer.numbers] * radii else: radii = np.array(radii) natoms = len(atoms) if isinstance(rotation, basestring): rotation = rotate(rotation) cell = atoms.get_cell() disp = atoms.get_celldisp().flatten() if show_unit_cell > 0: L, T, D = cell_to_lines(writer, cell) cell_vertices = np.empty((2, 2, 2, 3)) for c1 in range(2): for c2 in range(2): for c3 in range(2): cell_vertices[c1, c2, c3] = np.dot([c1, c2, c3], cell) + disp cell_vertices.shape = (8, 3) cell_vertices = np.dot(cell_vertices, rotation) else: L = np.empty((0, 3)) T = None D = None cell_vertices = None nlines = len(L) positions = np.empty((natoms + nlines, 3)) R = atoms.get_positions() positions[:natoms] = R positions[natoms:] = L r2 = radii**2 for n in range(nlines): d = D[T[n]] if ((((R - L[n] - d)**2).sum(1) < r2) & (((R - L[n] + d)**2).sum(1) < r2)).any(): T[n] = -1 positions = np.dot(positions, rotation) R = positions[:natoms] if bbox is None: X1 = (R - radii[:, None]).min(0) X2 = (R + radii[:, None]).max(0) if show_unit_cell == 2: X1 = np.minimum(X1, cell_vertices.min(0)) X2 = np.maximum(X2, cell_vertices.max(0)) M = (X1 + X2) / 2 S = 1.05 * (X2 - X1) w = scale * S[0] if w > maxwidth: w = maxwidth scale = w / S[0] h = scale * S[1] offset = np.array([scale * M[0] - w / 2, scale * M[1] - h / 2, 0]) else: w = (bbox[2] - bbox[0]) * scale h = (bbox[3] - bbox[1]) * scale offset = np.array([bbox[0], bbox[1], 0]) * scale offset[0] = offset[0] - extra_offset[0] offset[1] = offset[1] - extra_offset[1] writer.w = w + extra_offset[0] writer.h = h + extra_offset[1] positions *= scale positions -= offset if nlines > 0: D = np.dot(D, rotation)[:, :2] * scale if cell_vertices is not None: cell_vertices *= scale cell_vertices -= offset cell = np.dot(cell, rotation) cell *= scale writer.cell = cell writer.positions = positions writer.D = D writer.T = T writer.cell_vertices = cell_vertices writer.natoms = natoms writer.d = 2 * scale * radii
def reset_view(self, menuitem): self.axes = rotate('0.0x,0.0y,0.0z') self.set_frame() self.focus(self)