Beispiel #1
0
    def edit(self):
        """Modify atoms interactively through ag viewer. 

        Conflicts leading to undesirable behviour might arise
        when matplotlib has been pre-imported with certain
        incompatible backends and while trying to use the
        plot feature inside the interactive ag. To circumvent,
        please set matplotlib.use('gtk') before calling this
        method. 
        """
        from ase.gui.images import Images
        from ase.gui.gui import GUI
        images = Images([self])
        gui = GUI(images)
        gui.run()
        # use atoms returned from gui:
        # (1) delete all currently available atoms
        self.set_constraint()
        for z in range(len(self)):
            self.pop()
        edited_atoms = gui.images.get_atoms(0)
        # (2) extract atoms from edit session
        self.extend(edited_atoms)
        self.set_constraint(edited_atoms._get_constraints())
        self.set_cell(edited_atoms.get_cell())
        self.set_initial_magnetic_moments(edited_atoms.get_magnetic_moments())
        self.set_tags(edited_atoms.get_tags())
        return
Beispiel #2
0
def run(args):
    f1 = ase.io.read(args[0])
    f2 = ase.io.read(args[1])
    i1 = Images([f1])
    i2 = Images([f2])

    gui1 = GUI(i1, '', 1, False)
    gui1.run(None)
    gui2 = GUI(i2, '', 1, False)
    gui2.run(None)
Beispiel #3
0
    def run(opt, args):
        images = Images()

        if opt.aneb:
            opt.image_number = '-1'

        if len(args) > 0:
            from ase.io import string2index
            try:
                images.read(args, string2index(opt.image_number))
            except IOError as e:
                if len(e.args) == 1:
                    parser.error(e.args[0])
                else:
                    parser.error(e.args[1] + ': ' + e.filename)
        else:
            images.initialize([Atoms()])

        if opt.interpolate:
            images.interpolate(opt.interpolate)

        if opt.aneb:
            images.aneb()

        if opt.repeat != '1':
            r = opt.repeat.split(',')
            if len(r) == 1:
                r = 3 * r
            images.repeat_images([int(c) for c in r])

        if opt.radii_scale:
            images.set_radii(opt.radii_scale)

        if opt.output is not None:
            images.write(opt.output,
                         rotations=opt.rotations,
                         show_unit_cell=opt.show_unit_cell)
            opt.terminal = True

        if opt.terminal:
            if opt.graph is not None:
                data = images.graph(opt.graph)
                for line in data.T:
                    for x in line:
                        print(x, end=' ')
                    print()
        else:
            from ase.gui.gui import GUI
            import ase.gui.gtkexcepthook
            ase
            gui = GUI(images, opt.rotations, opt.show_unit_cell, opt.bonds)
            gui.run(opt.graph)
Beispiel #4
0
 def show_clusters(self):
     from ase.gui.gui import GUI
     from ase.gui.images import Images
     all_clusters = []
     self.tag_by_probability()
     for uid in range(len(self.gaussians)):
         cluster = self.atoms[self.cluster_id == uid]
         cluster.info = {"name": "Cluster ID: {}".format(uid)}
         all_clusters.append(cluster)
     images = Images()
     images.initialize(all_clusters)
     gui = GUI(images)
     gui.show_name = True
     gui.run()
Beispiel #5
0
    def run(args):
        from ase.gui.images import Images
        from ase.atoms import Atoms

        images = Images()

        if args.filenames:
            images.read(args.filenames, args.image_number)
        else:
            images.initialize([Atoms()])

        if args.interpolate:
            images.interpolate(args.interpolate)

        if args.repeat != '1':
            r = args.repeat.split(',')
            if len(r) == 1:
                r = 3 * r
            images.repeat_images([int(c) for c in r])

        if args.radii_scale:
            images.scale_radii(args.radii_scale)

        if args.output is not None:
            warnings.warn('You should be using "ase convert ..." instead!')
            images.write(args.output, rotations=args.rotations)
            args.terminal = True

        if args.terminal:
            if args.graph is not None:
                data = images.graph(args.graph)
                for line in data.T:
                    for x in line:
                        print(x, end=' ')
                    print()
        else:
            import os
            from ase.gui.gui import GUI

            backend = os.environ.get('MPLBACKEND', '')
            if backend == 'module://ipykernel.pylab.backend_inline':
                # Jupyter should not steal our windows
                del os.environ['MPLBACKEND']

            gui = GUI(images, args.rotations, args.bonds, args.graph)
            gui.run()
Beispiel #6
0
    def run(opt, args):
        images = Images()

        if opt.aneb:
            opt.image_number = '-1'

        if len(args) > 0:
            from ase.io import string2index
            images.read(args, string2index(opt.image_number))
        else:
            images.initialize([Atoms()])

        if opt.interpolate:
            images.interpolate(opt.interpolate)

        if opt.aneb:
            images.aneb()

        if opt.repeat != '1':
            r = opt.repeat.split(',')
            if len(r) == 1:
                r = 3 * r
            images.repeat_images([int(c) for c in r])

        if opt.radii_scale:
            images.set_radii(opt.radii_scale)

        if opt.output is not None:
            images.write(opt.output, rotations=opt.rotations,
                         show_unit_cell=opt.show_unit_cell)
            opt.terminal = True

        if opt.terminal:
            if opt.graph is not None:
                data = images.graph(opt.graph)
                for line in data.T:
                    for x in line:
                        print(x, end=' ')
                    print()
        else:
            from ase.gui.gui import GUI
            import ase.gui.gtkexcepthook
            ase
            gui = GUI(images, opt.rotations, opt.show_unit_cell, opt.bonds)
            gui.run(opt.graph)
Beispiel #7
0
Datei: ag.py Projekt: lqcata/ase
    def run(opt, args):
        images = Images()

        if opt.aneb:
            opt.image_number = '-1'

        if len(args) > 0:
            from ase.io import string2index
            images.read(args, string2index(opt.image_number))
        else:
            images.initialize([Atoms()])

        if opt.interpolate:
            images.interpolate(opt.interpolate)

        if opt.aneb:
            images.aneb()

        if opt.repeat != '1':
            r = opt.repeat.split(',')
            if len(r) == 1:
                r = 3 * r
            images.repeat_images([int(c) for c in r])

        if opt.output is not None:
            images.write(opt.output,
                         rotations=opt.rotations,
                         show_unit_cell=opt.show_unit_cell)
            opt.terminal = True

        if opt.terminal:
            if opt.graph is not None:
                data = images.graph(opt.graph)
                for line in data.T:
                    for x in line:
                        print x,
                    print
        else:
            from ase.gui.gui import GUI
            import ase.gui.gtkexcepthook
            gui = GUI(images, opt.rotations, opt.show_unit_cell, opt.bonds)
            gui.run(opt.graph)
Beispiel #8
0
    def run(args):
        from ase.gui.images import Images
        from ase.atoms import Atoms

        images = Images()

        if args.filenames:
            from ase.io import string2index
            images.read(args.filenames, string2index(args.image_number))
        else:
            images.initialize([Atoms()])

        if args.interpolate:
            images.interpolate(args.interpolate)

        if args.repeat != '1':
            r = args.repeat.split(',')
            if len(r) == 1:
                r = 3 * r
            images.repeat_images([int(c) for c in r])

        if args.radii_scale:
            images.set_radii(args.radii_scale)

        if args.output is not None:
            images.write(args.output,
                         rotations=args.rotations,
                         show_unit_cell=args.show_unit_cell)
            args.terminal = True

        if args.terminal:
            if args.graph is not None:
                data = images.graph(args.graph)
                for line in data.T:
                    for x in line:
                        print(x, end=' ')
                    print()
        else:
            from ase.gui.gui import GUI
            gui = GUI(images, args.rotations, args.show_unit_cell, args.bonds)
            gui.run(args.graph)
Beispiel #9
0
    def run(args):
        from ase.gui.images import Images
        from ase.atoms import Atoms

        images = Images()

        if args.filenames:
            from ase.io import string2index
            images.read(args.filenames, string2index(args.image_number))
        else:
            images.initialize([Atoms()])

        if args.interpolate:
            images.interpolate(args.interpolate)

        if args.repeat != '1':
            r = args.repeat.split(',')
            if len(r) == 1:
                r = 3 * r
            images.repeat_images([int(c) for c in r])

        if args.radii_scale:
            images.set_radii(args.radii_scale)

        if args.output is not None:
            images.write(args.output, rotations=args.rotations,
                         show_unit_cell=args.show_unit_cell)
            args.terminal = True

        if args.terminal:
            if args.graph is not None:
                data = images.graph(args.graph)
                for line in data.T:
                    for x in line:
                        print(x, end=' ')
                    print()
        else:
            from ase.gui.gui import GUI
            gui = GUI(images, args.rotations, args.show_unit_cell, args.bonds)
            gui.run(args.graph)
def show_configs():
    db = dataset.connect(DB_NAME)
    vac_tbl = db[VAC]
    sol_tbl = db[SOL]

    # Find unique runIDs
    ids = sol_tbl.distinct('runID')

    images = []
    for runRes in ids:
        positions = []
        symbols = []
        charges = []
        runID = runRes['runID']
        for item in sol_tbl.find(runID=runID):
            symbols.append(item['symbol'])
            pos = [item['X'], item['Y'], item['Z']]
            positions.append(pos)
            charges.append(None)

        # Extract vacancy positions
        for item in vac_tbl.find(runID=runID):
            e = item['energy']
            charges.append(e)
            pos = [item['X'], item['Y'], item['Z']]
            positions.append(pos)
            symbols.append('X')

        max_charge = max([c for c in charges if c is not None])
        charges = [c - max_charge if c is not None else 0.0 for c in charges]
        images.append(
            Atoms(symbols=symbols, positions=positions, charges=charges))

    from ase.gui.images import Images
    from ase.gui.gui import GUI
    images = Images(images)
    images.covalent_radii[0] = covalent_radii[12]
    gui = GUI(images)
    gui.run()
Beispiel #11
0
    def run(args):
        from ase.gui.images import Images
        from ase.atoms import Atoms

        images = Images()

        if args.filenames:
            images.read(args.filenames, args.image_number)
        else:
            images.initialize([Atoms()])

        if args.interpolate:
            images.interpolate(args.interpolate)

        if args.repeat != '1':
            r = args.repeat.split(',')
            if len(r) == 1:
                r = 3 * r
            images.repeat_images([int(c) for c in r])

        if args.radii_scale:
            images.scale_radii(args.radii_scale)

        if args.output is not None:
            warnings.warn('You should be using "ase convert ..." instead!')
            images.write(args.output, rotations=args.rotations)
            args.terminal = True

        if args.terminal:
            if args.graph is not None:
                data = images.graph(args.graph)
                for line in data.T:
                    for x in line:
                        print(x, end=' ')
                    print()
        else:
            from ase.gui.gui import GUI
            gui = GUI(images, args.rotations, args.bonds, args.graph)
            gui.run()
Beispiel #12
0
    for n in alltests:
        if n.startswith(name):
            name = n
            break
    else:
        1 / 0
    print(name)
    test = globals()[name]
    gui = GUI()

    def f():
        test(gui)
        if not args.pause:
            gui.exit()

    gui.run(test=f)


def window():
    def hello(event=None):
        print('hello', event)

    menu = [('Hi', [ui.MenuItem('_Hello', hello, 'Ctrl+H')]),
            ('Hell_o', [ui.MenuItem('ABC', hello, choices='ABC')])]
    win = ui.MainWindow('Test', menu=menu)

    win.add(ui.Label('Hello'))
    win.add(ui.Button('Hello', hello))

    r = ui.Rows([ui.Label(x * 7) for x in 'abcd'])
    win.add(r)
Beispiel #13
0
            images.write(opt.output, rotations=opt.rotations,
                         show_unit_cell=opt.show_unit_cell)
            opt.terminal = True

        if opt.terminal:
            if opt.graph is not None:
                data = images.graph(opt.graph)
                for line in data.T:
                    for x in line:
                        print x,
                    print
        else:
            from ase.gui.gui import GUI
            import ase.gui.gtkexcepthook
            gui = GUI(images, opt.rotations, opt.show_unit_cell, opt.bonds)
            gui.run(opt.graph)

    import traceback

    try:
        run(opt, args)
    except KeyboardInterrupt:
        pass
    except Exception:
        traceback.print_exc()
        print(_("""
An exception occurred!  Please report the issue to
[email protected] - thanks!  Please also report this if
it was a user error, so that a better error message can be provided
next time."""))
Beispiel #14
0
    gui.open(filename='h2o.json')
    save_dialog(gui, 'h2o.cif@-1')


p = argparse.ArgumentParser()
p.add_argument('tests', nargs='*')
p.add_argument('-p', '--pause', action='store_true')

if __name__ == '__main__':
    args = p.parse_args()
else:
    # We are running inside the test framework: ignore sys.args
    args = p.parse_args([])

for name in args.tests or alltests:
    for n in alltests:
        if n.startswith(name):
            name = n
            break
    else:
        1 / 0
    print(name)
    test = globals()[name]
    gui = GUI()

    def f():
        test(gui)
        if not args.pause:
            gui.exit()
    gui.run(test=f)
Beispiel #15
0
            images.write(opt.output, rotations=opt.rotations,
                         show_unit_cell=opt.show_unit_cell)
            opt.terminal = True

        if opt.terminal:
            if opt.graph is not None:
                data = images.graph(opt.graph)
                for line in data.T:
                    for x in line:
                        print x,
                    print
        else:
            from ase.gui.gui import GUI
            import ase.gui.gtkexcepthook
            gui = GUI(images, opt.rotations, opt.show_unit_cell, opt.bonds)
            gui.run(opt.graph)

    import traceback

    try:
        run(opt, args)
    except KeyboardInterrupt:
        pass
    except Exception:
        traceback.print_exc()
        print(_("""
An exception occurred!  Please report the issue to
[email protected] - thanks!  Please also report this if
it was a user error, so that a better error message can be provided
next time."""))