示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    def set_structure_data(self, *args):
        'Called when the user presses [Get structure].'
        if not self.element.check():
            return
        z = self.element.Z
        ref = ase.data.reference_states[z]
        if ref is None:
            structure = None
        else:
            structure = ref['symmetry']

        if ref is None or structure not in [s[0]
                                            for s in self.structure_data]:
            ui.error(_('Unsupported or unknown structure'),
                     _('Element = {0}, structure = {1}')
                     .format(self.element.symbol, structure))
            return

        self.structure.value = structure

        a = ref['a']
        self.a.value = a
        self.fourindex = self.needs_4index[structure]
        if self.fourindex:
            try:
                c = ref['c']
            except KeyError:
                c = ref['c/a'] * a
            self.c.value = c
示例#4
0
def txt2pos(txt):
    try:
        x, y, z = (float(x) for x in txt.split(','))
    except ValueError as ex:
        ui.error(_('Bad position'), ex)
    else:
        return x, y, z
示例#5
0
    def set_structure_data(self, *args):
        'Called when the user presses [Get structure].'
        z = self.element.Z
        if z is None:
            return
        ref = ase.data.reference_states[z]
        if ref is None:
            structure = None
        else:
            structure = ref['symmetry']

        if ref is None or structure not in [s[0] for s in self.structure_data]:
            ui.error(
                _('Unsupported or unknown structure'),
                _('Element = {0}, structure = {1}').format(
                    self.element.symbol, structure))
            return

        self.structure.value = structure

        a = ref['a']
        self.a.value = a
        self.fourindex = self.needs_4index[structure]
        if self.fourindex:
            try:
                c = ref['c']
            except KeyError:
                c = ref['c/a'] * a
            self.c.value = c
示例#6
0
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))
示例#7
0
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))
示例#8
0
 def add_relative(self):
     rpos = txt2pos(self.relative_position.value)
     pos = self.gui.atoms.positions
     if self.gui.images.selected.any():
         pos = pos[self.gui.images.selected[:len(pos)]]
     if len(pos) == 0:
         ui.error('No atoms present')
     else:
         center = pos.mean(0)
         self.add(center + rpos)
示例#9
0
 def apply(self):
     self.makeatoms()
     if self.atoms is not None:
         self.gui.new_atoms(self.atoms)
         return True
     else:
         ui.error(_('No valid atoms.'),
                  _('You have not (yet) specified a consistent set of '
                    'parameters.'))
         return False
示例#10
0
 def apply(self, callbackarg=None):
     self.makeatoms()
     if self.atoms is not None:
         self.gui.new_atoms(self.atoms)
         return True
     else:
         ui.error(
             _('No valid atoms.'),
             _('You have not (yet) specified a consistent set of '
               'parameters.'))
         return False
示例#11
0
 def apply(self):
     self.make()
     if self.atoms is not None:
         self.gui.new_atoms(self.atoms)
         return True
     else:
         ui.error(
             _('No valid atoms.'),
             _('You have not (yet) specified a consistent '
               'set of parameters.'))
         return False
示例#12
0
文件: gui.py 项目: ssrokyz/ase-3.20.1
    def paste_atoms_from_clipboard(self, event=None):
        try:
            atoms = self.clipboard.get_atoms()
        except Exception as err:
            ui.error(
                'Cannot paste atoms',
                'Pasting currently works only with the ASE JSON format.\n\n'
                f'Original error:\n\n{err}')
            return

        if self.atoms == Atoms():
            self.atoms.cell = atoms.cell
            self.atoms.pbc = atoms.pbc
        self.paste_atoms_onto_existing(atoms)
示例#13
0
    def plot(self, type=None, expr=None, ignore_if_nan=False):
        if expr is None:
            expr = self.expr.value
        else:
            self.expr.value = expr

        try:
            data = self.gui.images.graph(expr)
        except Exception as ex:
            ui.error(ex)
            return

        if ignore_if_nan and len(data) == 2 and np.isnan(data[1]).all():
            return
        pickledata = (data, self.gui.frame, expr, type)
        self.gui.pipe('graph', pickledata)
示例#14
0
    def plot(self, type=None, expr=None):
        if expr is None:
            expr = self.expr.value
        else:
            self.expr.value = expr

        try:
            data = self.gui.images.graph(expr)
        except (SyntaxError, NameError) as ex:
            ui.error(ex)
            return

        process = subprocess.Popen([sys.executable, '-m', 'ase.gui.graphs'],
                                   stdin=subprocess.PIPE)
        pickle.dump((data, self.gui.frame, expr, type), process.stdin,
                    protocol=0)
        process.stdin.close()
        self.gui.graphs.append(process)
示例#15
0
文件: graphs.py 项目: yfyh2013/ase
    def plot(self, type=None, expr=None):
        if expr is None:
            expr = self.expr.value
        else:
            self.expr.value = expr

        try:
            data = self.gui.images.graph(expr)
        except (SyntaxError, NameError) as ex:
            ui.error(ex)
            return

        process = subprocess.Popen([sys.executable, '-m', 'ase.gui.graphs'],
                                   stdin=subprocess.PIPE)
        pickledata = (data, self.gui.frame, expr, type)
        pickle.dump(pickledata, process.stdin, protocol=0)
        process.stdin.close()
        self.gui.graphs.append(process)
示例#16
0
 def row_add(self, widget=None):
     'Add a row to the list of directions.'
     if self.fourindex:
         n = 4
     else:
         n = 3
     idx = tuple(a.value for a in self.new_direction[1:1 + 2 * n:2])
     if not any(idx):
         ui.error(_('At least one index must be non-zero'), '')
         return
     if n == 4 and sum(idx) != 0:
         ui.error(_('Invalid hexagonal indices',
                    'The sum of the first three numbers must be zero'))
         return
     new = [idx, 5, 1.0]
     if self.method.value == 'wulff':
         new[1] = self.new_direction[-2].value
     else:
         new[2] = self.new_direction[-2].value
     self.direction_table.append(new)
     self.add_direction(*new)
     self.update()
示例#17
0
 def row_add(self, widget=None):
     'Add a row to the list of directions.'
     if self.fourindex:
         n = 4
     else:
         n = 3
     idx = tuple(a.value for a in self.new_direction[1:1 + 2 * n:2])
     if not any(idx):
         ui.error(_('At least one index must be non-zero'), '')
         return
     if n == 4 and sum(idx) != 0:
         ui.error(
             _('Invalid hexagonal indices',
               'The sum of the first three numbers must be zero'))
         return
     new = [idx, 5, 1.0]
     if self.method.value == 'wulff':
         new[1] = self.new_direction[-2].value
     else:
         new[2] = self.new_direction[-2].value
     self.direction_table.append(new)
     self.add_direction(*new)
     self.update()
示例#18
0
 def bad_plot(self, err, msg=''):
     ui.error(_('Plotting failed'), '\n'.join([str(err), msg]).strip())