def open(self, button=None, filename=None): from ase.io.formats import all_formats, get_ioformat labels = [_('Automatic')] values = [''] def key(item): return item[1][0] for format, (description, code) in sorted(list(all_formats.items()), key=key): io = get_ioformat(format) if io.read and description != '?': labels.append(_(description)) values.append(format) format = [None] def callback(value): format[0] = value chooser = ui.LoadFileDialog(self.window.win, _('Open ...')) ui.Label(_('Choose parser:')).pack(chooser.top) formats = ui.ComboBox(labels, values, callback) formats.pack(chooser.top) filename = filename or chooser.go() if filename: self.images.read([filename], slice(None), format[0]) self.set_colors() self.set_coordinates(self.images.nimages - 1, focus=True)
def save_dialog(gui): dialog = gtk.FileChooserDialog(_('Save ...'), None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_SAVE, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) dialog.set_current_name('') dialog.set_current_folder(os.getcwd()) text = _('Append name with "@n" in order to write image number "n" ' 'instead of the current image.\n' 'Append "@start:stop" or "@start:stop:step" if you want to write ' 'a range of images.\n' 'You can leave out "start" and "stop" so that "name@:" will ' 'give you all images.\n' 'Negative numbers count from the last image ' '("name@-1": last image, "name@-2:": last two).') dialog.set_extra_widget(gtk.Label(text)) response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() dialog.destroy() else: dialog.destroy() return filename, index = parse_filename(filename) if index is None: index = slice(gui.frame, gui.frame + 1) if isinstance(index, str): index = string2index(index) format = filetype(filename, read=False) io = get_ioformat(format) extra = {} remove_hidden = False if format in ['png', 'eps', 'pov']: bbox = np.empty(4) size = np.array([gui.width, gui.height]) / gui.scale bbox[0:2] = np.dot(gui.center, gui.axes[:, :2]) - size / 2 bbox[2:] = bbox[:2] + size extra['rotation'] = gui.axes extra['show_unit_cell'] = gui.ui.get_widget( '/MenuBar/ViewMenu/ShowUnitCell').get_active() extra['bbox'] = bbox extra['colors'] = gui.get_colors(rgb=True)[gui.images.visible] remove_hidden = True images = [gui.images.get_atoms(i, remove_hidden=remove_hidden) for i in range(*index.indices(gui.images.nimages))] if len(images) > 1 and io.single: # We want to write multiple images, but the file format does not # support it. The solution is to write multiple files, inserting # a number in the file name before the suffix. j = filename.rfind('.') filename = filename[:j] + '{0:05d}' + filename[j:] for i, atoms in enumerate(images): write(filename.format(i), atoms, **extra) else: write(filename, images, **extra)
def open(self, button=None, filename=None): from ase.io.formats import all_formats, get_ioformat labels = [_('Automatic')] values = [''] def key(item): return item[1][0] for format, (description, code) in sorted(all_formats.items(), key=key): io = get_ioformat(format) if io.read and description != '?': labels.append(_(description)) values.append(format) format = [None] def callback(value): format[0] = value chooser = ui.LoadFileDialog(self.window.win, _('Open ...')) ui.Label(_('Choose parser:')).pack(chooser.top) formats = ui.ComboBox(labels, values, callback) formats.pack(chooser.top) filename = filename or chooser.go() if filename: self.images.read([filename], slice(None), format[0]) self.set_frame(len(self.images) - 1, focus=True)
def save_dialog(gui, filename=None): dialog = ui.SaveFileDialog(gui.window.win, _('Save ...')) ui.Text(text).pack(dialog.top) filename = filename or dialog.go() if not filename: return filename, index = parse_filename(filename) if index is None: index = slice(gui.frame, gui.frame + 1) elif isinstance(index, basestring): index = string2index(index) elif isinstance(index, slice): pass else: if index < 0: index += len(gui.images) index = slice(index, index + 1) format = filetype(filename, read=False) io = get_ioformat(format) extra = {} remove_hidden = False if format in ['png', 'eps', 'pov']: bbox = np.empty(4) size = gui.window.size / gui.scale bbox[0:2] = np.dot(gui.center, gui.axes[:, :2]) - size / 2 bbox[2:] = bbox[:2] + size extra['rotation'] = gui.axes extra['show_unit_cell'] = gui.window['toggle-show-unit-cell'] extra['bbox'] = bbox colors = gui.get_colors(rgb=True) extra['colors'] = [ rgb for rgb, visible in zip(colors, gui.images.visible) if visible ] remove_hidden = True images = [ gui.images.get_atoms(i, remove_hidden=remove_hidden) for i in range(*index.indices(len(gui.images))) ] if len(images) > 1 and io.single: # We want to write multiple images, but the file format does not # support it. The solution is to write multiple files, inserting # a number in the file name before the suffix. j = filename.rfind('.') filename = filename[:j] + '{0:05d}' + filename[j:] for i, atoms in enumerate(images): write(filename.format(i), atoms, **extra) else: try: write(filename, images, **extra) except Exception as err: from ase.gui.ui import showerror showerror(_('Error'), err) raise
def save_dialog(gui, filename=None): dialog = ui.SaveFileDialog(gui.window.win, _('Save ...')) ui.Text(text).pack(dialog.top) filename = filename or dialog.go() if not filename: return filename, index = parse_filename(filename) if index is None: index = slice(gui.frame, gui.frame + 1) elif isinstance(index, basestring): index = string2index(index) elif isinstance(index, slice): pass else: if index < 0: index += len(gui.images) index = slice(index, index + 1) format = filetype(filename, read=False) io = get_ioformat(format) extra = {} remove_hidden = False if format in ['png', 'eps', 'pov']: bbox = np.empty(4) size = gui.window.size / gui.scale bbox[0:2] = np.dot(gui.center, gui.axes[:, :2]) - size / 2 bbox[2:] = bbox[:2] + size extra['rotation'] = gui.axes extra['show_unit_cell'] = gui.window['toggle-show-unit-cell'] extra['bbox'] = bbox colors = gui.get_colors(rgb=True) extra['colors'] = [rgb for rgb, visible in zip(colors, gui.images.visible) if visible] remove_hidden = True images = [gui.images.get_atoms(i, remove_hidden=remove_hidden) for i in range(*index.indices(len(gui.images)))] if len(images) > 1 and io.single: # We want to write multiple images, but the file format does not # support it. The solution is to write multiple files, inserting # a number in the file name before the suffix. j = filename.rfind('.') filename = filename[:j] + '{0:05d}' + filename[j:] for i, atoms in enumerate(images): write(filename.format(i), atoms, **extra) else: write(filename, images, **extra)
def open(self, button=None): from ase.io.formats import all_formats, get_ioformat formats = [(_('Automatic'), None)] def key(item): return item[1][0] for format, (description, code) in sorted(all_formats.items(), key=key): io = get_ioformat(format) if io.read and description != '?': formats.append((_(description), format)) chooser = gtk.FileChooserDialog( _('Open ...'), None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_filename(_("<<filename>>")) # Add a file type filter name_to_format = {} types = gtk.combo_box_new_text() for name, format in formats: types.append_text(name) name_to_format[name] = format types.set_active(0) img_vbox = gtk.VBox() pack(img_vbox, [gtk.Label(_('File type:')), types]) img_vbox.show() chooser.set_extra_widget(img_vbox) ok = chooser.run() == gtk.RESPONSE_OK if ok: filenames = [chooser.get_filename()] filetype = types.get_active_text() chooser.destroy() if not ok: return self.reset_tools_modes() self.images.read(filenames, slice(None), name_to_format[filetype]) self.set_colors() self.set_coordinates(self.images.nimages - 1, focus=True)
def __init__(self, win, formatcallback=lambda event: None): from ase.io.formats import all_formats, get_ioformat LoadFileDialog.__init__(self, win, _('Open ...')) labels = [_('Automatic')] values = [''] def key(item): return item[1][0] for format, (description, code) in sorted(all_formats.items(), key=key): io = get_ioformat(format) if io.read and description != '?': labels.append(_(description)) values.append(format) self.format = None def callback(value): self.format = value Label(_('Choose parser:')).pack(self.top) formats = ComboBox(labels, values, callback) formats.pack(self.top)
continue if not matplotlib and format in ['eps', 'png']: continue if not etree and format == 'exciting': continue if not Scientific and format == 'etsf': continue atoms = get_atoms() images = [atoms, atoms] io = get_ioformat(format) print('{0:20}{1}{2}{3}{4}'.format(format, ' R'[bool(io.read)], ' W'[bool(io.write)], '+1'[io.single], 'SF'[io.acceptsfd])) fname1 = '{}/io-test.1.{}'.format(testdir, format) fname2 = '{}/io-test.2.{}'.format(testdir, format) if io.write: write(fname1, atoms, format=format) if not io.single: write(fname2, images, format=format) if io.read: for a in [read(fname1, format=format), read(fname1)]: check(a, atoms, format)
def test(format): if format in ['abinit', 'castep-cell', 'dftb', 'eon', 'gaussian']: # Someone should do something ... return if format in ['v-sim', 'mustem']: # Standalone test used as not compatible with 1D periodicity return if format in ['mustem']: # Standalone test used as specific arguments are required return if format in ['dmol-arc', 'dmol-car', 'dmol-incoor']: # We have a standalone dmol test return if format in ['gif', 'mp4']: # Complex dependencies; see animate.py test return if format in ['postgresql', 'trj', 'vti', 'vtu']: # Let's not worry about these. return if not matplotlib and format in ['eps', 'png']: return if not etree and format == 'exciting': return if not Scientific and format == 'etsf': return if not netCDF4 and format == 'netcdftrajectory': return atoms = get_atoms() if format == 'dlp4': atoms.pbc = (1, 1, 0) images = [atoms, atoms] io = get_ioformat(format) print('{0:20}{1}{2}{3}{4}'.format(format, ' R'[bool(io.read)], ' W'[bool(io.write)], '+1'[io.single], 'SF'[io.acceptsfd])) fname1 = '{}/io-test.1.{}'.format(testdir, format) fname2 = '{}/io-test.2.{}'.format(testdir, format) if io.write: write(fname1, atoms, format=format) if not io.single: write(fname2, images, format=format) if io.read: for a in [read(fname1, format=format), read(fname1)]: check(a, atoms, format) if not io.single: if format in ['json', 'db']: aa = read(fname2 + '@id=1') + read(fname2 + '@id=2') else: aa = [read(fname2), read(fname2, 0)] aa += read(fname2, ':') for a in iread(fname2, format=format): aa.append(a) assert len(aa) == 6, aa for a in aa: check(a, atoms, format)
def save_dialog(gui): dialog = gtk.FileChooserDialog(_('Save ...'), None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_SAVE, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) dialog.set_current_name('') dialog.set_current_folder(os.getcwd()) text = _('Append name with "@n" in order to write image number "n" ' 'instead of the current image.\n' 'Append "@start:stop" or "@start:stop:step" if you want to write ' 'a range of images.\n' 'You can leave out "start" and "stop" so that "name@:" will ' 'give you all images.\n' 'Negative numbers count from the last image ' '("name@-1": last image, "name@-2:": last two).') dialog.set_extra_widget(gtk.Label(text)) response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() dialog.destroy() else: dialog.destroy() return filename, index = parse_filename(filename) if index is None: index = slice(gui.frame, gui.frame + 1) if isinstance(index, str): index = string2index(index) format = filetype(filename, read=False) io = get_ioformat(format) extra = {} remove_hidden = False if format in ['png', 'eps', 'pov']: bbox = np.empty(4) size = np.array([gui.width, gui.height]) / gui.scale bbox[0:2] = np.dot(gui.center, gui.axes[:, :2]) - size / 2 bbox[2:] = bbox[:2] + size extra['rotation'] = gui.axes extra['show_unit_cell'] = gui.ui.get_widget( '/MenuBar/ViewMenu/ShowUnitCell').get_active() extra['bbox'] = bbox extra['colors'] = gui.get_colors(rgb=True)[gui.images.visible] remove_hidden = True images = [ gui.images.get_atoms(i, remove_hidden=remove_hidden) for i in range(*index.indices(gui.images.nimages)) ] if len(images) > 1 and io.single: # We want to write multiple images, but the file format does not # support it. The solution is to write multiple files, inserting # a number in the file name before the suffix. j = filename.rfind('.') filename = filename[:j] + '{0:05d}' + filename[j:] for i, atoms in enumerate(images): write(filename.format(i), atoms, **extra) else: write(filename, images, **extra)
continue if format in ['postgresql', 'trj', 'vti', 'vtu']: # Let's not worry about these. continue if not matplotlib and format in ['eps', 'png']: continue if not etree and format == 'exciting': continue if not Scientific and format == 'etsf': continue io = get_ioformat(format) print('{0:20}{1}{2}{3}{4}'.format(format, ' R'[bool(io.read)], ' W'[bool(io.write)], '+1'[io.single], 'SF'[io.acceptsfd])) fname1 = 'io-test.1.' + format fname2 = 'io-test.2.' + format if io.write: write(fname1, atoms, format=format) if not io.single: write(fname2, images, format=format) if io.read: for a in [read(fname1, format=format), read(fname1)]: check(a, format) if not io.single: