예제 #1
0
파일: save.py 프로젝트: rosswhitfield/ase
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)
예제 #2
0
def read_nomad_json(fd, index):
    # wth, we should not be passing index like this!
    from ase.io.formats import string2index
    if isinstance(index, str):
        index = string2index(index)

    d = _read_nomad_json(fd)
    images = list(d.iterimages())
    return images[index]
예제 #3
0
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
예제 #4
0
    def __call__(self, fd, index=None, **kwargs):
        if isinstance(index, basestring):
            index = string2index(index)

        if index is None or index == ':':
            index = slice(None, None, None)

        if not isinstance(index, (slice, basestring)):
            index = slice(index, (index + 1) or None)

        for chunk in self._getslice(fd, index):
            yield chunk.build(**kwargs)
예제 #5
0
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)
예제 #6
0
파일: db.py 프로젝트: btodac/ase
def read_db(filename, index, **kwargs):
    db = ase.db.connect(filename, serial=True, **kwargs)

    if isinstance(index, basestring):
        try:
            index = string2index(index)
        except ValueError:
            pass

    if isinstance(index, int):
        index = slice(index, index + 1 or None)

    if isinstance(index, basestring):
        # index is a database query string:
        for row in db.select(index):
            yield row.toatoms()
    else:
        start, stop, step = index.indices(db.count())
        if start == stop:
            return
        assert step == 1
        for row in db.select(offset=start, limit=stop - start):
            yield row.toatoms()
예제 #7
0
파일: db.py 프로젝트: rchiechi/QuantumParse
def read_db(filename, index, **kwargs):
    db = ase.db.connect(filename, serial=True, **kwargs)

    if isinstance(index, basestring):
        try:
            index = string2index(index)
        except ValueError:
            pass

    if isinstance(index, int):
        index = slice(index, index + 1 or None)

    if isinstance(index, basestring):
        # index is a database query string:
        for row in db.select(index):
            yield row.toatoms()
    else:
        start, stop, step = index.indices(db.count())
        if start == stop:
            return
        assert step == 1
        for row in db.select(offset=start, limit=stop - start):
            yield row.toatoms()
예제 #8
0
파일: save.py 프로젝트: uu1477/MyAse
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)