def __init__(self, gui): self.gui = gui selected = self.selection() if not selected.any(): ui.error(_('No atoms selected!')) return win = ui.Window(_('Modify')) element = Element(callback=self.set_element) win.add(element) win.add( ui.Button(_('Change element'), partial(self.set_element, element))) self.tag = ui.SpinBox(0, -1000, 1000, 1, self.set_tag) win.add([_('Tag'), self.tag]) self.magmom = ui.SpinBox(0.0, -10, 10, 0.1, self.set_magmom) win.add([_('Moment'), self.magmom]) atoms = self.gui.atoms Z = atoms.numbers if Z.ptp() == 0: element.Z = Z[0] tags = atoms.get_tags()[selected] if tags.ptp() == 0: self.tag.value = tags[0] magmoms = get_magmoms(atoms)[selected] if magmoms.round(2).ptp() == 0.0: self.magmom.value = round(magmoms[0], 2)
def __init__(self, gui): self.win = ui.Window(_('Colors')) self.gui = gui self.win.add(ui.Label(_('Choose how the atoms are colored:'))) values = [ 'jmol', 'tag', 'force', 'velocity', 'initial charge', 'magmom' ] labels = [ _('By atomic number, default "jmol" colors'), _('By tag'), _('By force'), _('By velocity'), _('By initial charge'), _('By magnetic moment') ] self.radio = ui.RadioButtons(labels, values, self.toggle, vertical=True) self.radio.value = gui.colormode self.win.add(self.radio) self.activate() self.label = ui.Label() self.win.add(self.label)
def __init__(self, gui): self.gui = gui win = ui.Window(_('Settings')) # Constraints win.add(_('Constraints:')) win.add([ ui.Button(_('Constrain'), self.constrain_selected), '/', ui.Button(_('release'), self.release_selected), _(' selected atoms') ]) win.add(ui.Button(_('Constrain immobile atoms'), self.immobile)) win.add(ui.Button(_('Clear all constraints'), self.clear_constraints)) # Visibility win.add(_('Visibility:')) win.add([ ui.Button(_('Hide'), self.hide_selected), '/', ui.Button(_('show'), self.show_selected), _(' selected atoms') ]) win.add(ui.Button(_('View all atoms'), self.view_all)) # Miscellaneous win.add(_('Miscellaneous:')) self.scale = ui.SpinBox(self.gui.images.atom_scale, 0.2, 2.0, 0.1, self.scale_radii) win.add([_('Scale atomic radii:'), self.scale])
def reset(self, gui): """create a new color window""" self.win = ui.Window(_('Colors')) self.gui = gui self.win.add(ui.Label(_('Choose how the atoms are colored:'))) values = ['jmol', 'tag', 'force', 'velocity', 'initial charge', 'magmom', 'neighbors'] labels = [_('By atomic number, default "jmol" colors'), _('By tag'), _('By force'), _('By velocity'), _('By initial charge'), _('By magnetic moment'), _('By number of neighbors'), ] haveit = ['numbers', 'positions', 'forces', 'momenta', 'initial_charges', 'initial_magmoms'] for key in self.gui.atoms.arrays: if key not in haveit: values.append(key) labels.append('By user-defined "{}"'.format(key)) self.radio = ui.RadioButtons(labels, values, self.toggle, vertical=True) self.radio.value = gui.colormode self.win.add(self.radio) self.activate() self.label = ui.Label() self.win.add(self.label) if hasattr(self, 'mnmx'): self.win.add(self.cmaps) self.win.add(self.mnmx)
def __init__(self, gui): self.gui = gui self.gui.register_vulnerable(self) # Create grid control for cells # xx xy xz ||x|| pbc # yx yy yz ||y|| pbc # zx zy zz ||z|| pbc self.cell_grid = [] self.pbc = [] self.angles = [] atoms = self.gui.atoms cell = atoms.cell mags = cell.lengths() angles = cell.angles() pbc = atoms.pbc for i in [0, 1, 2]: # x_ y_ z_ row = [] for j in [0, 1, 2]: # _x _y _z row.append(ui.SpinBox(cell[i][j], -30, 30, 0.1, self.apply_vectors, rounding=7, width=9)) row.append(ui.SpinBox(mags[i], -30, 30, 0.1, self.apply_magnitudes, rounding=7, width=9)) self.cell_grid.append(row) self.pbc.append(ui.CheckButton('', bool(pbc[i]), self.apply_pbc)) self.angles.append(ui.SpinBox(angles[i], -360, 360, 15, self.apply_angles, rounding=7, width=9)) self.scale_atoms = ui.CheckButton('', False) self.vacuum = ui.SpinBox(5, 0, 15, 0.1, self.apply_vacuum) # TRANSLATORS: This is a title of a window. win = self.win = ui.Window(_('Cell Editor')) x, y, z = self.cell_grid win.add([_('A:'), x[0], x[1], x[2], _('||A||:'), x[3], _('periodic:'), self.pbc[0]]) win.add([_('B:'), y[0], y[1], y[2], _('||B||:'), y[3], _('periodic:'), self.pbc[1]]) win.add([_('C:'), z[0], z[1], z[2], _('||C||:'), z[3], _('periodic:'), self.pbc[2]]) win.add([_('∠BC:'), self.angles[0], _('∠AC:'), self.angles[1], _('∠AB:'), self.angles[2]]) win.add([_('Scale atoms with cell:'), self.scale_atoms]) win.add([ui.Button(_('Apply Vectors'), self.apply_vectors), ui.Button(_('Apply Magnitudes'), self.apply_magnitudes), ui.Button(_('Apply Angles'), self.apply_angles)]) win.add([_('Pressing 〈Enter〉 as you enter values will ' 'automatically apply correctly')]) # TRANSLATORS: verb win.add([ui.Button(_('Center'), self.apply_center), ui.Button(_('Wrap'), self.apply_wrap), _('Vacuum:'), self.vacuum, ui.Button(_('Apply Vacuum'), self.apply_vacuum)])
def __init__(self, gui): win = ui.Window(_('Constraints')) win.add([ui.Button(_('Fix'), self.selected), _('selected atoms')]) win.add( [ui.Button(_('Release'), self.unconstrain), _('selected atoms')]) win.add(ui.Button(_('Clear all constraints'), self.clear)) self.gui = gui
def __init__(self, gui): self.gui = gui self.win = win = ui.Window(_('Render current view in povray ... ')) win.add(ui.Label(_("Rendering %d atoms.") % len(self.gui.atoms))) guiwidth, guiheight = self.get_guisize() self.width_widget = ui.SpinBox(guiwidth, start=1, end=9999, step=1) self.height_widget = ui.SpinBox(guiheight, start=1, end=9999, step=1) win.add([ui.Label(_('Size')), self.width_widget, ui.Label('⨯'), self.height_widget]) self.linewidth_widget = ui.SpinBox(0.07, start=0.01, end=9.99, step=0.01) win.add([ui.Label(_('Line width')), self.linewidth_widget, ui.Label(_('Ångström'))]) self.constraints_widget = ui.CheckButton(_("Render constraints")) self.cell_widget = ui.CheckButton(_("Render unit cell"), value=True) win.add([self.cell_widget, self.constraints_widget]) formula = gui.atoms.get_chemical_formula(mode='hill') self.basename_widget = ui.Entry(width=30, value=formula, callback=self.update_outputname) win.add([ui.Label(_('Output basename: ')), self.basename_widget]) self.povray_executable = ui.Entry(width=30,value='povray') win.add([ui.Label(_('POVRAY executable')), self.povray_executable]) self.outputname_widget = ui.Label() win.add([ui.Label(_('Output filename: ')), self.outputname_widget]) self.update_outputname() self.texture_widget = ui.ComboBox(labels=self.texture_list, values=self.texture_list) win.add([ui.Label(_('Atomic texture set:')), self.texture_widget]) # complicated texture stuff self.camera_widget = ui.ComboBox(labels=self.cameras, values=self.cameras) self.camera_distance_widget = ui.SpinBox(50.0, -99.0, 99.0, 1.0) win.add([ui.Label(_('Camera type: ')), self.camera_widget]) win.add([ui.Label(_('Camera distance')), self.camera_distance_widget]) # render current frame/all frames self.frames_widget = ui.RadioButtons([_('Render current frame'), _('Render all frames')]) win.add(self.frames_widget) if len(gui.images) == 1: self.frames_widget.buttons[1].widget.configure(state='disabled') self.run_povray_widget = ui.CheckButton(_('Run povray'), True) self.keep_files_widget = ui.CheckButton(_('Keep povray files'), False) self.show_output_widget = ui.CheckButton(_('Show output window'), True) self.transparent = ui.CheckButton(_("Transparent background"), True) win.add(self.transparent) win.add([self.run_povray_widget, self.keep_files_widget, self.show_output_widget]) win.add(ui.Button(_('Render'), self.ok))
def pywindow(title, callback): code = callback() if code is None: ui.error( _('No Python code'), _('You have not (yet) specified a consistent set of parameters.')) else: win = ui.Window(title) win.add(ui.Text(code))
def __init__(self, gui): win = ui.Window(_('Constraints')) win.add([ui.Button(_('Constrain'), self.selected), _('selected atoms')]) win.add([ui.Button(_('Constrain'), self.immobile), _('immobile atoms')]) win.add([ui.Button(_('Unconstrain'), self.unconstrain), _('selected atoms')]) win.add(ui.Button(_('Clear constraints'), self.clear)) self.gui = gui
def __init__(self, gui): win = ui.Window('Graphs') self.expr = ui.Entry('', 50, self.plot) win.add([self.expr, ui.helpbutton(graph_help_text)]) win.add([ui.Button(_('Plot'), self.plot, 'xy'), ' x, y1, y2, ...'], 'w') win.add([ui.Button(_('Plot'), self.plot, 'y'), ' y1, y2, ...'], 'w') win.add([ui.Button(_('Save'), self.save)], 'w') self.gui = gui
def __init__(self, gui): self.gui = gui win = ui.Window(_('Rotate')) win.add(_('Rotation angles:')) self.rotate = [ui.SpinBox(42.0, -360, 360, 1, self.change) for i in '123'] win.add(self.rotate) win.add(ui.Button(_('Update'), self.update_angles)) win.add(_('Note:\nYou can rotate freely\n' 'with the mouse, by holding\n' 'down mouse button 2.')) self.update_angles()
def quick_info_window(self, key=None): from ase.gui.quickinfo import info info_win = ui.Window(_('Quick Info')) info_win.add(info(self)) # Update quickinfo window when we change frame def update(window): exists = window.exists if exists: # Only update if we exist window.things[0].text = info(self) return exists self.attach(update, info_win)
def __init__(self, gui): win = ui.Window(_('Repeat')) win.add(_('Repeat atoms:')) self.repeat = [ui.SpinBox(r, 1, 9, 1, self.change) for r in gui.images.repeat] win.add(self.repeat) win.add(ui.Button(_('Set unit cell'), self.set_unit_cell)) for sb, vec in zip(self.repeat, gui.atoms.cell): if not vec.any(): sb.active = False self.gui = gui
def __init__(self, gui): self.gui = gui win = self.win = ui.Window(_('Add atoms')) win.add(_('Specify chemical symbol, formula, or filename.')) def choose_file(): chooser = ui.ASEFileChooser(self.win.win) filename = chooser.go() if filename is None: # No file selected return self.combobox.value = filename # Load the file immediately, so we can warn now in case of error self.readfile(filename, format=chooser.format) if self.gui.images.selected.any(): default = current_selection_string else: default = 'H2' self._filename = None self._atoms_from_file = None from ase.collections import g2 labels = list(sorted(name for name in g2.names if len(g2[name]) > 1)) values = labels combobox = ui.ComboBox(labels, values) win.add([ _('Add:'), combobox, ui.Button(_('File ...'), callback=choose_file) ]) combobox.widget.bind('<Return>', lambda e: self.add()) combobox.value = default self.combobox = combobox spinners = [ ui.SpinBox(0.0, -1e3, 1e3, 0.1, rounding=2, width=3) for __ in range(3) ] win.add([_('Coordinates:')] + spinners) self.spinners = spinners win.add( _('Coordinates are relative to the center of the selection, ' 'if any, else absolute.')) self.picky = ui.CheckButton(_('Check positions'), True) win.add([ui.Button(_('Add'), self.add), self.picky]) self.focus()
def __init__(self, gui): self.gui = gui win = self.win = ui.Window(_('Add atoms')) win.add(_('Specify chemical symbol, formula, or filename.')) def set_molecule(value): self.entry.value = value self.focus() def choose_file(): chooser = ui.ASEFileChooser(self.win.win) filename = chooser.go() if filename is None: # No file selected return self.entry.value = filename # Load the file immediately, so we can warn now in case of error self.readfile(filename, format=chooser.format) self.entry = ui.Entry('', callback=self.add) win.add([ _('Add:'), self.entry, ui.Button(_('File ...'), callback=choose_file) ]) self._filename = None self._atoms_from_file = None from ase.collections import g2 labels = list(sorted(g2.names)) values = labels box = ui.ComboBox(labels, values, callback=set_molecule) win.add([_('Get molecule:'), box]) box.value = 'H2' spinners = [ ui.SpinBox(0.0, -1e3, 1e3, 0.1, rounding=2, width=3) for __ in range(3) ] win.add([_('Coordinates:')] + spinners) self.spinners = spinners win.add( _('Coordinates are relative to the center of the selection, ' 'if any, else absolute.')) self.picky = ui.CheckButton(_('Check positions'), True) win.add([ui.Button(_('Add'), self.add), self.picky]) self.focus()
def __init__(self, gui): # XXXXXXXXXXX still array based, not Atoms-based. Will crash win = ui.Window(_('Add atoms')) self.element = Element() win.add(self.element) self.absolute_position = ui.Entry('0,0,0') self.relative_position = ui.Entry('1.5,0,0') win.add([_('Absolute position:'), self.absolute_position, ui.Button(_('Add'), self.add_absolute)]) win.add([_('Relative to average position (of selection):'), self.relative_position, ui.Button(_('Add'), self.add_relative)]) self.gui = gui
def __init__(self, gui): self.element = Element('', self.apply) self.structure = ui.ComboBox(structures, structures, self.structure_changed) self.structure_warn = ui.Label('', 'red') self.orthogonal = ui.CheckButton('', True, self.make) self.lattice_a = ui.SpinBox(3.2, 0.0, 10.0, 0.001, self.make) self.retrieve = ui.Button(_('Get from database'), self.structure_changed) self.lattice_c = ui.SpinBox(None, 0.0, 10.0, 0.001, self.make) self.x = ui.SpinBox(1, 1, 30, 1, self.make) self.x_warn = ui.Label('', 'red') self.y = ui.SpinBox(1, 1, 30, 1, self.make) self.y_warn = ui.Label('', 'red') self.z = ui.SpinBox(1, 1, 30, 1, self.make) self.vacuum_check = ui.CheckButton('', False, self.vacuum_checked) self.vacuum = ui.SpinBox(5, 0, 40, 0.01, self.make) self.description = ui.Label('') win = self.win = ui.Window(_('Surface')) win.add(ui.Text(introtext)) win.add(self.element) win.add([_('Structure:'), self.structure, self.structure_warn]) win.add([_('Orthogonal cell:'), self.orthogonal]) win.add([_('Lattice constant:')]) win.add([_('\ta'), self.lattice_a, (u'Å'), self.retrieve]) win.add([_('\tc'), self.lattice_c, (u'Å')]) win.add([_('Size:')]) win.add([_('\tx: '), self.x, _(' unit cells'), self.x_warn]) win.add([_('\ty: '), self.y, _(' unit cells'), self.y_warn]) win.add([_('\tz: '), self.z, _(' unit cells')]) win.add([_('Vacuum: '), self.vacuum_check, self.vacuum, (u'Å')]) win.add(self.description) # TRANSLATORS: This is a title of a window. win.add([ pybutton(_('Creating a surface.'), self.make), ui.Button(_('Apply'), self.apply), ui.Button(_('OK'), self.ok) ]) self.element.grab_focus() self.gui = gui self.atoms = None self.lattice_c.active = False self.vacuum.active = False self.structure_changed()
def __init__(self, gui): self.win = win = ui.Window(_('Movie'), self.close) win.add(_('Image number:')) self.frame_number = ui.Scale(gui.frame + 1, 1, len(gui.images), callback=self.new_frame) win.add(self.frame_number) win.add([ ui.Button(_('First'), self.click, -1, True), ui.Button(_('Back'), self.click, -1), ui.Button(_('Forward'), self.click, 1), ui.Button(_('Last'), self.click, 1, True) ]) play = ui.Button(_('Play'), self.play) stop = ui.Button(_('Stop'), self.stop) # TRANSLATORS: This function plays an animation forwards and backwards # alternatingly, e.g. for displaying vibrational movement self.rock = ui.CheckButton(_('Rock')) win.add([play, stop, self.rock]) if len(gui.images) > 150: skipdefault = len(gui.images) // 150 tdefault = min(max(len(gui.images) / (skipdefault * 5.0), 1.0), 30) else: skipdefault = 0 tdefault = min(max(len(gui.images) / 5.0, 1.0), 30) self.time = ui.SpinBox(tdefault, 1.0, 99, 0.1) self.skip = ui.SpinBox(skipdefault, 0, 99, 1) win.add( [_(' Frame rate: '), self.time, _(' Skip frames: '), self.skip]) self.gui = gui self.direction = 1 self.timer = None gui.register_vulnerable(self)
def __init__(self, gui): self.gui = gui win = ui.Window(_('Settings')) # Constraints win.add(_('Constraints:')) win.add([ui.Button(_('Fix'), self.constrain_selected), '/', ui.Button(_('release'), self.release_selected), _(' selected atoms')]) win.add(ui.Button(_('Clear all constraints'), self.clear_constraints)) # Visibility win.add(_('Visibility:')) win.add([ui.Button(_('Hide'), self.hide_selected), '/', ui.Button(_('show'), self.show_selected), _(' selected atoms')]) win.add(ui.Button(_('View all atoms'), self.view_all)) # Miscellaneous win.add(_('Miscellaneous:')) self.scale = ui.SpinBox(self.gui.images.atom_scale, 0.2, 2.0, 0.1, self.scale_radii) win.add([_('Scale atomic radii:'), self.scale]) self.force_vector_scale = ui.SpinBox( self.gui.force_vector_scale, 0.0, 1e32, 0.1, rounding=2, callback=self.scale_force_vectors ) win.add([_('Scale force vectors:'), self.force_vector_scale]) self.velocity_vector_scale = ui.SpinBox( self.gui.velocity_vector_scale, 0.0, 1e32, 0.1, rounding=2, callback=self.scale_velocity_vectors ) win.add([_('Scale velocity vectors:'), self.velocity_vector_scale])
def __init__(self, gui): self.element = Element('C', self.make) self.bondlength = ui.SpinBox(1.42, 0.0, 10.0, 0.01, self.make) self.n = ui.SpinBox(5, 1, 100, 1, self.make) self.m = ui.SpinBox(5, 0, 100, 1, self.make) self.length = ui.SpinBox(1, 1, 100, 1, self.make) self.description = ui.Label('') win = self.win = ui.Window(_('Nanotube')) win.add(ui.Text(introtext)) win.add(self.element) win.add([_('Bond length: '), self.bondlength, _(u'Å')]) win.add(_('Select roll-up vector (n,m) and tube length:')) win.add(['n:', self.n, 'm:', self.m, _('Length:'), self.length]) win.add(self.description) win.add([ pybutton(_('Creating a nanoparticle.'), self.make), ui.Button(_('Apply'), self.apply), ui.Button(_('OK'), self.ok) ]) self.gui = gui self.atoms = None
def quick_info_window(self, key=None): from ase.gui.quickinfo import info ui.Window(_('Quick Info')).add(info(self))
def __init__(self, gui): self.atoms = None self.no_update = True self.old_structure = 'undefined' win = self.win = ui.Window(_('Nanoparticle')) win.add(ui.Text(introtext)) self.element = Element('', self.apply) lattice_button = ui.Button(_('Get structure'), self.set_structure_data) self.elementinfo = ui.Label(' ') win.add(self.element) win.add(self.elementinfo) win.add(lattice_button) # The structure and lattice constant labels = [] values = [] self.needs_4index = {} self.needs_2lat = {} self.factory = {} for abbrev, name, n4, c, factory in self.structure_data: labels.append(name) values.append(abbrev) self.needs_4index[abbrev] = n4 self.needs_2lat[abbrev] = c self.factory[abbrev] = factory self.structure = ui.ComboBox(labels, values, self.update_structure) win.add([_('Structure:'), self.structure]) self.fourindex = self.needs_4index[values[0]] self.a = ui.SpinBox(3.0, 0.0, 1000.0, 0.01, self.update) self.c = ui.SpinBox(3.0, 0.0, 1000.0, 0.01, self.update) win.add([_('Lattice constant: a ='), self.a, ' c =', self.c]) # Choose specification method self.method = ui.ComboBox( [_('Layer specification'), _('Wulff construction')], ['layers', 'wulff'], self.update_gui_method) win.add([_('Method: '), self.method]) self.layerlabel = ui.Label('Missing text') # Filled in later win.add(self.layerlabel) self.direction_table_rows = ui.Rows() win.add(self.direction_table_rows) self.default_direction_table() win.add(_('Add new direction:')) self.new_direction_and_size_rows = ui.Rows() win.add(self.new_direction_and_size_rows) self.update_new_direction_and_size_stuff() # Information win.add(_('Information about the created cluster:')) self.info = [ _('Number of atoms: '), ui.Label('-'), _(' Approx. diameter: '), ui.Label('-') ] win.add(self.info) # Finalize setup self.update_structure('fcc') self.update_gui_method() self.no_update = False self.auto = ui.CheckButton(_('Automatic Apply')) win.add(self.auto) win.add([ pybutton(_('Creating a nanoparticle.'), self.makeatoms), ui.helpbutton(helptext), ui.Button(_('Apply'), self.apply), ui.Button(_('OK'), self.ok) ]) self.gui = gui self.smaller_button = None self.largeer_button = None self.element.grab_focus()
def quick_info_window(self): from ase.gui.quickinfo import info ui.Window('Quick Info').add(info(self))