def configure_event(self, drawing_area, event): if self.configured: w = self.width h = self.height else: self.config = read_defaults() self.colormap = self.drawing_area.get_colormap() self.foreground_gc = self.drawing_area.window.new_gc( self.colormap.alloc_color(self.config['gui_foreground_color'])) self.background_gc = self.drawing_area.window.new_gc( self.colormap.alloc_color(self.config['gui_background_color'])) self.red = self.drawing_area.window.new_gc( self.colormap.alloc_color(62345, 0, 0), line_width=2) self.green = self.drawing_area.window.new_gc( self.colormap.alloc_color(0, 54456, 0), line_width=2) self.blue = self.drawing_area.window.new_gc( self.colormap.alloc_color(0, 0, 54456), line_width=2) self.selected_gc = self.drawing_area.window.new_gc( self.colormap.alloc_color(0, 16456, 0), line_width=3) x, y, self.width, self.height = drawing_area.get_allocation() self.pixmap = gtk.gdk.Pixmap(drawing_area.window, self.width, self.height) if self.configured: self.scale *= sqrt(1.0 * self.width * self.height / (w * h)) self.draw() self.configured = True
def __init__(self, images=None): self.covalent_radii = covalent_radii.copy() self.config = read_defaults() self.atom_scale = self.config['radii_scale'] if images is None: images = [Atoms()] self.initialize(images)
def __init__(self, images=None, rotations='', show_bonds=False, expr=None): if not isinstance(images, Images): images = Images(images) self.images = images self.observers = [] self.config = read_defaults() if show_bonds: self.config['show_bonds'] = True menu = self.get_menu_data() self.window = ui.ASEGUIWindow(close=self.exit, menu=menu, config=self.config, scroll=self.scroll, scroll_event=self.scroll_event, press=self.press, move=self.move, release=self.release, resize=self.resize) View.__init__(self, rotations) Status.__init__(self) self.subprocesses = [] # list of external processes self.movie_window = None self.vulnerable_windows = [] self.simulation = {} # Used by modules on Calculate menu. self.module_state = {} # Used by modules to store their state. self.arrowkey_mode = self.ARROWKEY_SCAN self.move_atoms_mask = None self.set_frame(len(self.images) - 1, focus=True) # Used to move the structure with the mouse self.prev_pos = None self.last_scroll_time = time() self.orig_scale = self.scale if len(self.images) > 1: self.movie() if expr is None: expr = self.config['gui_graphs_string'] if expr is not None and expr != '' and len(self.images) > 1: self.plot_graphs(expr=expr, ignore_if_nan=True)
def __init__(self, images=None, rotations='', show_unit_cell=True, show_bonds=False): # Try to change into directory of file you are viewing try: os.chdir(os.path.split(sys.argv[1])[0]) # This will fail sometimes (e.g. for starting a new session) except: pass if not images: images = Images() images.initialize([Atoms()]) self.images = images self.config = read_defaults() menu = self.get_menu_data(show_unit_cell, show_bonds) self.window = ui.ASEGUIWindow(close=self.exit, menu=menu, config=self.config, scroll=self.scroll, scroll_event=self.scroll_event, press=self.press, move=self.move, release=self.release, resize=self.resize) View.__init__(self, rotations) Status.__init__(self) self.graphs = [] # list of matplotlib processes self.graph_wref = [] # list of weakrefs to Graph objects self.movie_window = None self.vulnerable_windows = [] self.simulation = {} # Used by modules on Calculate menu. self.module_state = {} # Used by modules to store their state. self.arrowkey_mode = self.ARROWKEY_SCAN self.move_atoms_mask = None
def __init__(self, images=None, rotations='', show_unit_cell=True, show_bonds=False): # Try to change into directory of file you are viewing try: os.chdir(os.path.split(sys.argv[1])[0]) # This will fail sometimes (e.g. for starting a new session) except: pass if not images: images = Images() images.initialize([Atoms()]) self.images = images self.config = read_defaults() menu = self.get_menu_data(show_unit_cell, show_bonds) self.window = ui.ASEGUIWindow(self.exit, menu, self.config, self.scroll, self.scroll_event, self.press, self.move, self.release, self.resize) View.__init__(self, rotations) Status.__init__(self) self.graphs = [] # list of matplotlib processes self.graph_wref = [] # list of weakrefs to Graph objects self.movie_window = None self.vulnerable_windows = [] self.simulation = {} # Used by modules on Calculate menu. self.module_state = {} # Used by modules to store their state. self.moving = False self.move_atoms_mask = None
def initialize(self, images, filenames=None, init_magmom=False): self.natoms = len(images[0]) self.nimages = len(images) if filenames is None: filenames = [None] * self.nimages self.filenames = filenames if hasattr(images[0], 'get_shapes'): self.Q = np.empty((self.nimages, self.natoms, 4)) self.shapes = images[0].get_shapes() import os as os if os.path.exists('shapes'): shapesfile = open('shapes') lines = shapesfile.readlines() shapesfile.close() if '#{type:(shape_x,shape_y,shape_z), .....,}' in lines[0]: shape = eval(lines[1]) shapes = [] for an in images[0].get_atomic_numbers(): shapes.append(shape[an]) self.shapes = np.array(shapes) else: print 'shape file has wrong format' else: print 'no shapesfile found: default shapes were used!' else: self.shapes = None self.P = np.empty((self.nimages, self.natoms, 3)) self.V = np.empty((self.nimages, self.natoms, 3)) self.E = np.empty(self.nimages) self.K = np.empty(self.nimages) self.F = np.empty((self.nimages, self.natoms, 3)) self.M = np.empty((self.nimages, self.natoms)) self.T = np.empty((self.nimages, self.natoms), int) self.A = np.empty((self.nimages, 3, 3)) self.D = np.empty((self.nimages, 3)) self.Z = images[0].get_atomic_numbers() self.q = np.empty((self.nimages, self.natoms)) self.pbc = images[0].get_pbc() self.covalent_radii = covalent_radii config = read_defaults() if config['covalent_radii'] is not None: for data in config['covalent_radii']: self.covalent_radii[data[0]] = data[1] warning = False for i, atoms in enumerate(images): natomsi = len(atoms) if (natomsi != self.natoms or (atoms.get_atomic_numbers() != self.Z).any()): raise RuntimeError('Can not handle different images with ' + 'different numbers of atoms or different ' + 'kinds of atoms!') self.P[i] = atoms.get_positions() self.V[i] = atoms.get_velocities() if hasattr(self, 'Q'): self.Q[i] = atoms.get_quaternions() self.A[i] = atoms.get_cell() self.D[i] = atoms.get_celldisp().reshape((3, )) if (atoms.get_pbc() != self.pbc).any(): warning = True try: self.E[i] = atoms.get_potential_energy() except RuntimeError: self.E[i] = np.nan self.K[i] = atoms.get_kinetic_energy() try: self.F[i] = atoms.get_forces(apply_constraint=False) except RuntimeError: self.F[i] = np.nan try: if init_magmom: self.M[i] = atoms.get_initial_magnetic_moments() else: self.M[i] = atoms.get_magnetic_moments() except (RuntimeError, AttributeError): self.M[i] = atoms.get_initial_magnetic_moments() self.q[i] = atoms.get_initial_charges() # added support for tags try: self.T[i] = atoms.get_tags() except RuntimeError: self.T[i] = 0 if warning: print('WARNING: Not all images have the same bondary conditions!') self.selected = np.zeros(self.natoms, bool) self.selected_ordered = [] self.atoms_to_rotate_0 = np.zeros(self.natoms, bool) self.visible = np.ones(self.natoms, bool) self.nselected = 0 self.set_dynamic(constraints=images[0].constraints) self.repeat = np.ones(3, int) self.set_radii(config['radii_scale'])
def initialize(self, images, filenames=None, init_magmom=False): self.natoms = len(images[0]) self.nimages = len(images) if filenames is None: filenames = [None] * self.nimages self.filenames = filenames if hasattr(images[0], 'get_shapes'): self.Q = np.empty((self.nimages, self.natoms, 4)) self.shapes = images[0].get_shapes() import os as os if os.path.exists('shapes'): shapesfile = open('shapes') lines = shapesfile.readlines() shapesfile.close() if '#{type:(shape_x,shape_y,shape_z), .....,}' in lines[0]: shape = eval(lines[1]) shapes=[] for an in images[0].get_atomic_numbers(): shapes.append(shape[an]) self.shapes = np.array(shapes) else: print 'shape file has wrong format' else: print 'no shapesfile found: default shapes were used!' else: self.shapes = None self.P = np.empty((self.nimages, self.natoms, 3)) self.V = np.empty((self.nimages, self.natoms, 3)) self.E = np.empty(self.nimages) self.K = np.empty(self.nimages) self.F = np.empty((self.nimages, self.natoms, 3)) self.M = np.empty((self.nimages, self.natoms)) self.T = np.empty((self.nimages, self.natoms), int) self.A = np.empty((self.nimages, 3, 3)) self.D = np.empty((self.nimages, 3)) self.Z = images[0].get_atomic_numbers() self.q = np.empty((self.nimages, self.natoms)) self.pbc = images[0].get_pbc() self.covalent_radii = covalent_radii config = read_defaults() if config['covalent_radii'] is not None: for data in config['covalent_radii']: self.covalent_radii[data[0]] = data[1] warning = False for i, atoms in enumerate(images): natomsi = len(atoms) if (natomsi != self.natoms or (atoms.get_atomic_numbers() != self.Z).any()): raise RuntimeError('Can not handle different images with ' + 'different numbers of atoms or different ' + 'kinds of atoms!') self.P[i] = atoms.get_positions() self.V[i] = atoms.get_velocities() if hasattr(self, 'Q'): self.Q[i] = atoms.get_quaternions() self.A[i] = atoms.get_cell() self.D[i] = atoms.get_celldisp().reshape((3,)) if (atoms.get_pbc() != self.pbc).any(): warning = True try: self.E[i] = atoms.get_potential_energy() except RuntimeError: self.E[i] = np.nan self.K[i] = atoms.get_kinetic_energy() try: self.F[i] = atoms.get_forces(apply_constraint=False) except RuntimeError: self.F[i] = np.nan try: if init_magmom: self.M[i] = atoms.get_initial_magnetic_moments() else: self.M[i] = atoms.get_magnetic_moments() except (RuntimeError, AttributeError): self.M[i] = atoms.get_initial_magnetic_moments() self.q[i] = atoms.get_initial_charges() # added support for tags try: self.T[i] = atoms.get_tags() except RuntimeError: self.T[i] = 0 if warning: print('WARNING: Not all images have the same bondary conditions!') self.selected = np.zeros(self.natoms, bool) self.selected_ordered = [] self.atoms_to_rotate_0 = np.zeros(self.natoms, bool) self.visible = np.ones(self.natoms, bool) self.nselected = 0 self.set_dynamic(constraints = images[0].constraints) self.repeat = np.ones(3, int) self.set_radii(config['radii_scale'])
def initialize(self, images, filenames=None, init_magmom=False): self.natoms = len(images[0]) self.nimages = len(images) if hasattr(images[0], 'get_shapes'): self.shapes = images[0].get_shapes() self.Q = [] else: self.shapes = None if filenames is None: filenames = [None] * self.nimages self.filenames = filenames self.P = np.empty((self.nimages, self.natoms, 3)) self.V = np.empty((self.nimages, self.natoms, 3)) self.E = np.empty(self.nimages) self.K = np.empty(self.nimages) self.F = np.empty((self.nimages, self.natoms, 3)) self.M = np.empty((self.nimages, self.natoms)) self.T = np.empty((self.nimages, self.natoms), int) self.A = np.empty((self.nimages, 3, 3)) self.Z = images[0].get_atomic_numbers() self.pbc = images[0].get_pbc() self.covalent_radii = covalent_radii config = read_defaults() if config['covalent_radii'] is not None: for data in config['covalent_radii']: self.covalent_radii[data[0]] = data[1] warning = False for i, atoms in enumerate(images): natomsi = len(atoms) if (natomsi != self.natoms or (atoms.get_atomic_numbers() != self.Z).any()): raise RuntimeError('Can not handle different images with ' + 'different numbers of atoms or different ' + 'kinds of atoms!') self.P[i] = atoms.get_positions() self.V[i] = atoms.get_velocities() if hasattr(self, 'Q'): for q in atoms.get_quaternions(): self.Q.append(Quaternion(q)) self.A[i] = atoms.get_cell() if (atoms.get_pbc() != self.pbc).any(): warning = True try: self.E[i] = atoms.get_potential_energy() except RuntimeError: self.E[i] = np.nan self.K[i] = atoms.get_kinetic_energy() try: self.F[i] = atoms.get_forces(apply_constraint=False) except RuntimeError: self.F[i] = np.nan try: if init_magmom: self.M[i] = atoms.get_initial_magnetic_moments() else: self.M[i] = atoms.get_magnetic_moments() except (RuntimeError, AttributeError): self.M[i] = atoms.get_initial_magnetic_moments() # added support for tags try: self.T[i] = atoms.get_tags() except RuntimeError: self.T[i] = 0 if warning: print('WARNING: Not all images have the same bondary conditions!') self.selected = np.zeros(self.natoms, bool) self.selected_ordered = [] self.atoms_to_rotate_0 = np.zeros(self.natoms, bool) self.visible = np.ones(self.natoms, bool) self.nselected = 0 self.set_dynamic(constraints=images[0].constraints) self.repeat = np.ones(3, int) self.set_radii(config['radii_scale'])
def initialize(self, images, filenames=None, init_magmom=False): self.natoms = len(images[0]) self.nimages = len(images) if hasattr(images[0], 'get_shapes'): self.shapes = images[0].get_shapes() self.Q = [] else: self.shapes = None if filenames is None: filenames = [None] * self.nimages self.filenames = filenames self.P = np.empty((self.nimages, self.natoms, 3)) self.V = np.empty((self.nimages, self.natoms, 3)) self.E = np.empty(self.nimages) self.K = np.empty(self.nimages) self.F = np.empty((self.nimages, self.natoms, 3)) self.M = np.empty((self.nimages, self.natoms)) self.T = np.empty((self.nimages, self.natoms), int) self.A = np.empty((self.nimages, 3, 3)) self.Z = images[0].get_atomic_numbers() self.pbc = images[0].get_pbc() self.covalent_radii = covalent_radii config = read_defaults() if config['covalent_radii'] is not None: for data in config['covalent_radii']: self.covalent_radii[data[0]] = data[1] warning = False for i, atoms in enumerate(images): natomsi = len(atoms) if (natomsi != self.natoms or (atoms.get_atomic_numbers() != self.Z).any()): raise RuntimeError('Can not handle different images with ' + 'different numbers of atoms or different ' + 'kinds of atoms!') self.P[i] = atoms.get_positions() self.V[i] = atoms.get_velocities() if hasattr(self, 'Q'): for q in atoms.get_quaternions(): self.Q.append(Quaternion(q)) self.A[i] = atoms.get_cell() if (atoms.get_pbc() != self.pbc).any(): warning = True try: self.E[i] = atoms.get_potential_energy() except RuntimeError: self.E[i] = np.nan self.K[i] = atoms.get_kinetic_energy() try: self.F[i] = atoms.get_forces(apply_constraint=False) except RuntimeError: self.F[i] = np.nan try: if init_magmom: self.M[i] = atoms.get_initial_magnetic_moments() else: self.M[i] = atoms.get_magnetic_moments() except (RuntimeError, AttributeError): self.M[i] = atoms.get_initial_magnetic_moments() # added support for tags try: self.T[i] = atoms.get_tags() except RuntimeError: self.T[i] = 0 if warning: print('WARNING: Not all images have the same bondary conditions!') self.selected = np.zeros(self.natoms, bool) self.selected_ordered = [] self.atoms_to_rotate_0 = np.zeros(self.natoms, bool) self.visible = np.ones(self.natoms, bool) self.nselected = 0 self.set_dynamic(constraints = images[0].constraints) self.repeat = np.ones(3, int) self.set_radii(config['radii_scale'])
def __init__(self, images=None): self.covalent_radii = covalent_radii.copy() self.config = read_defaults() self.atom_scale = self.config['radii_scale'] if images is not None: self.initialize(images)