Esempio n. 1
0
def test_get_angles():
    from ase.build import graphene_nanoribbon
    import numpy as np

    g = graphene_nanoribbon(3, 2, type="zigzag", vacuum=5)

    test_set = [[0, 1, x] for x in range(2, len(g))]

    manual_results = [
        g.get_angle(a1, a2, a3, mic=True) for a1, a2, a3 in test_set
    ]

    set_results = g.get_angles(test_set, mic=True)

    assert (np.allclose(manual_results, set_results))
Esempio n. 2
0
    # We will do the "toothless" spin-polarised Si instead.
    calc = calculate('Fe',
                     bulk('Fe', orthorhombic=True),
                     KPointsGrid=[[4, 4, 4]],
                     KPointsUseSymmetries=True,
                     ExtraStates=4,
                     Spacing='0.15 * Angstrom',
                     SmearingFunction='fermi_dirac',
                     Smearing='0.1 * eV',
                     PseudoPotentialSet='sg15',
                     ExperimentalFeatures=True,
                     SpinComponents='spin_polarized')
    eF = calc.get_fermi_level()
    assert abs(eF - 5.33) < 1e-1
    # XXXX octopus does not get magnetic state?
    print('eF', eF)

if 0:
    # Experimental feature: mixed periodicity.  Let us not do this for now...
    graphene = graphene_nanoribbon(2, 2, sheet=True)
    graphene.positions = graphene.positions[:, [0, 2, 1]]
    graphene.pbc = [1, 1, 0]  # from 1, 0, 1
    calc = calculate('graphene',
                     graphene,
                     KPointsGrid=[[2, 1, 2]],
                     KPointsUseSymmetries=True,
                     ExperimentalFeatures=True,
                     ExtraStates=4,
                     SmearingFunction='fermi_dirac',
                     Smearing='0.1 * eV')
Esempio n. 3
0
# creates: a1.png, a2.png, a3.png, cnt1.png, cnt2.png, gnr1.png, gnr2.png
from ase.io import write
from ase.build import bulk
from ase.build import nanotube, graphene_nanoribbon

for i, a in enumerate(
    [bulk('Cu', 'fcc', a=3.6),
     bulk('Cu', 'fcc', a=3.6, orthorhombic=True),
     bulk('Cu', 'fcc', a=3.6, cubic=True)]):
    write('a%d.pov' % (i + 1), a,
          show_unit_cell=2, display=False, run_povray=True)

cnt1 = nanotube(6, 0, length=4, vacuum=2.5)
cnt1.rotate('x', 'z', rotate_cell=True)
cnt2 = nanotube(3, 3, length=6, bond=1.4, symbol='Si', vacuum=2.5)
cnt2.rotate('x', 'z', rotate_cell=True)

for i, a in enumerate([cnt1, cnt2]):
    write('cnt%d.pov' % (i + 1), a,
          show_unit_cell=2, display=False, run_povray=True)

gnr1 = graphene_nanoribbon(3, 4, type='armchair', saturated=True, vacuum=2.5)
gnr2 = graphene_nanoribbon(2, 6, type='zigzag', saturated=True,
                           C_H=1.1, C_C=1.4, vacuum=3.0,
                           magnetic=True, initial_mag=1.12)

for i, a in enumerate([gnr1, gnr2]):
    write('gnr%d.pov' % (i + 1), a,
          rotation='90x',
          show_unit_cell=2, display=False, run_povray=True)
Esempio n. 4
0
###
### Writes electron localization function into file elf_ribbon.cube
###

from ase import Atoms
from ase.build import graphene_nanoribbon, add_adsorbate
from ase.io import write
from gpaw import GPAW
from gpaw.occupations import FermiDirac
from gpaw.eigensolvers.rmmdiis import RMMDIIS
from gpaw.mpi import size, rank

from gpaw.elf import ELF

# Graphene nanoribbon
ribbon = graphene_nanoribbon(5, 6, type='armchair', saturated=True, vacuum=3.5)

# Gold adsorbate
pos = (ribbon[35].position + ribbon[60].position) / 2.0
pos[1] += 2.2
adsorbate = Atoms('Au', (pos, ))
ribbon += adsorbate
ribbon.center(axis=1, vacuum=3.5)

txt = 'output_p_{}.txt'.format(size)
ribbon.calc = GPAW(
    h=0.22,
    xc='PBE',
    txt=txt,
    occupations=FermiDirac(0.2),
    eigensolver=RMMDIIS(),
Esempio n. 5
0
from ase.build import graphene_nanoribbon
import numpy as np

g = graphene_nanoribbon(3, 2, type="zigzag", vacuum=5)

test_set = [[0, 1, x] for x in range(2, len(g))]

manual_results = [g.get_angle(a1, a2, a3, mic=True) for a1, a2, a3 in test_set]

set_results = g.get_angles(test_set, mic=True)

assert (np.allclose(manual_results, set_results))
Esempio n. 6
0
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 17 16:51:00 2016

@author: cl-iop
"""
from ase.build import graphene_nanoribbon, nanotube
from ase.visualize import view
from pyramids.io.output import writeSiesta

from ase.io.cube import read_cube_data
from ase.io import write

#graphene_nanoribbon() vacuum=0.71
atom = graphene_nanoribbon(6,1,type='armchair',saturated=True,vacuum=5)
writeSiesta('structure.fdf',atom)
view(atom)

rot = '90x,0y,00z'
kwargs = {
    'rotation'      : rot, # text string with rotation (default='' )
    'radii'         : 1.0, # float, or a list with one float per atom
    'colors'        : None,# List: one (r, g, b) tuple per atom
    'show_unit_cell': 2,   # 0, 1, or 2 to not show, show, and show all of cell
    }
kwargs.update({
    'run_povray'   : True, # Run povray or just write .pov + .ini files
    'display'      : True,# Display while rendering
    'pause'        : True, # Pause when done rendering (only if display)
    'transparent'  : True,# Transparent background
    'canvas_width' : None, # Width of canvas in pixels
Esempio n. 7
0
for i, a in enumerate(
    [bulk('Cu', 'fcc', a=3.6),
     bulk('Cu', 'fcc', a=3.6, orthorhombic=True),
     bulk('Cu', 'fcc', a=3.6, cubic=True)]):
    write('a%d.pov' % (i + 1), a,
          show_unit_cell=2, display=False, run_povray=True)

cnt1 = nanotube(6, 0, length=4, vacuum=2.5)
cnt1.rotate('x', 'z', rotate_cell=True)
cnt2 = nanotube(3, 3, length=6, bond=1.4, symbol='Si', vacuum=2.5)
cnt2.rotate('x', 'z', rotate_cell=True)

for i, a in enumerate([cnt1, cnt2]):
    write('cnt%d.pov' % (i + 1), a,
          show_unit_cell=2, display=False, run_povray=True)

ind = [2, 0, 1]
gnr1 = graphene_nanoribbon(3, 4, type='armchair', saturated=True, vacuum=2.5)
gnr1.set_cell(np.diag(gnr1.cell)[ind])
gnr1.positions = gnr1.positions[:, ind]
gnr2 = graphene_nanoribbon(2, 6, type='zigzag', saturated=True,
                           C_H=1.1, C_C=1.4, vacuum=3.0,
                           magnetic=True, initial_mag=1.12)
gnr2.set_cell(np.diag(gnr2.cell)[ind])
gnr2.positions = gnr2.positions[:, ind]

for i, a in enumerate([gnr1, gnr2]):
    write('gnr%d.pov' % (i + 1), a,
          show_unit_cell=2, display=False, run_povray=True)
Esempio n. 8
0
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 17 16:51:00 2016

@author: cl-iop
"""
from ase.build import graphene_nanoribbon, nanotube
from ase.visualize import view
from pyramids.io.output import writeSiesta

from ase.io.cube import read_cube_data
from ase.io import write

#graphene_nanoribbon() vacuum=0.71
atom = graphene_nanoribbon(6, 1, type='armchair', saturated=True, vacuum=5)
writeSiesta('structure.fdf', atom)
view(atom)

rot = '90x,0y,00z'
kwargs = {
    'rotation': rot,  # text string with rotation (default='' )
    'radii': 1.0,  # float, or a list with one float per atom
    'colors': None,  # List: one (r, g, b) tuple per atom
    'show_unit_cell': 2,  # 0, 1, or 2 to not show, show, and show all of cell
}
kwargs.update({
    'run_povray':
    True,  # Run povray or just write .pov + .ini files
    'display':
    True,  # Display while rendering
    'pause':
Esempio n. 9
0
    def makeatoms(self, *args):
        self.update_element()
        self.update_gui()
        if self.legal_element is None or (self.struct.get_active() == 2 and
                                          self.legal_element2 is None):
            self.atoms = None
            self.pybut.python = None
            self.status.set_markup(
                _("Please specify a consistent set of atoms. "))
        else:
            n = int(self.n.value)
            m = int(self.m.value)
            CC = self.bondlength.value
            vacuum = self.vacuum.value
            orient = self.orient_text[self.orient.get_active()]
            elem = self.legal_element
            if self.struct.get_active() == 0:
                # Extended sheet
                self.atoms = graphene_nanoribbon(
                    n,
                    m,
                    type=orient,
                    C_C=CC,
                    vacc=vacuum,
                    sheet=True,
                    main_element=elem)
            elif self.struct.get_active() == 1:
                # Unsaturated nanoribbon
                self.atoms = graphene_nanoribbon(
                    n, m, type=orient, C_C=CC, vacc=vacuum, main_element=elem)
            elif self.struct.get_active() == 2:
                # Saturated nanoribbon
                elem2 = self.legal_element2
                self.atoms = graphene_nanoribbon(
                    n,
                    m,
                    type=orient,
                    C_C=CC,
                    C_H=self.bondlength2.value,
                    vacuum=vacuum,
                    saturated=True,
                    main_element=elem,
                    saturate_element=elem2)
            else:
                raise RuntimeError("Unknown structure in SetupGraphene!")

        # Now, rotate into the xy plane (ase.gui's default view plane)
        pos = self.atoms.get_positions()
        cell = self.atoms.get_cell()
        pbc = self.atoms.get_pbc()
        cell[1, 1], cell[2, 2] = cell[2, 2], cell[1, 1]
        x = pos[:, 1].copy()
        z = pos[:, 2].copy()
        pos[:, 1] = z
        pos[:, 2] = x
        self.atoms.set_cell(cell)
        self.atoms.set_positions(pos)
        self.atoms.set_pbc([pbc[0], pbc[2], pbc[1]])
        label = label_template % {
            'natoms': len(self.atoms),
            'symbols': formula(self.atoms.get_atomic_numbers()),
            'volume': np.inf
        }
        self.status.set_markup(label)
Esempio n. 10
0
    def makeatoms(self, *args):
        self.update_element()
        self.update_gui()
        if self.legal_element is None or (self.struct.get_active() == 2 and
                                          self.legal_element2 is None):
            self.atoms = None
            self.pybut.python = None
            self.status.set_markup(
                _("Please specify a consistent set of atoms. "))
        else:
            n = int(self.n.value)
            m = int(self.m.value)
            CC = self.bondlength.value
            vacuum = self.vacuum.value
            orient = self.orient_text[self.orient.get_active()]
            elem = self.legal_element
            if self.struct.get_active() == 0:
                # Extended sheet
                self.atoms = graphene_nanoribbon(
                    n,
                    m,
                    type=orient,
                    C_C=CC,
                    vacc=vacuum,
                    sheet=True,
                    main_element=elem)
            elif self.struct.get_active() == 1:
                # Unsaturated nanoribbon
                self.atoms = graphene_nanoribbon(
                    n, m, type=orient, C_C=CC, vacc=vacuum, main_element=elem)
            elif self.struct.get_active() == 2:
                # Saturated nanoribbon
                elem2 = self.legal_element2
                self.atoms = graphene_nanoribbon(
                    n,
                    m,
                    type=orient,
                    C_C=CC,
                    C_H=self.bondlength2.value,
                    vacuum=vacuum,
                    saturated=True,
                    main_element=elem,
                    saturate_element=elem2)
            else:
                raise RuntimeError("Unknown structure in SetupGraphene!")

        # Now, rotate into the xy plane (ase.gui's default view plane)
        pos = self.atoms.get_positions()
        cell = self.atoms.get_cell()
        pbc = self.atoms.get_pbc()
        cell[1, 1], cell[2, 2] = cell[2, 2], cell[1, 1]
        x = pos[:, 1].copy()
        z = pos[:, 2].copy()
        pos[:, 1] = z
        pos[:, 2] = x
        self.atoms.set_cell(cell)
        self.atoms.set_positions(pos)
        self.atoms.set_pbc([pbc[0], pbc[2], pbc[1]])
        label = label_template % {
            'natoms': len(self.atoms),
            'symbols': formula(self.atoms.get_atomic_numbers()),
            'volume': np.inf
        }
        self.status.set_markup(label)
def make_system(name, h, a, n, m):
    print('running...')
    """Function that takes in the height, h, the spacing of the adsorbate, a,
    the number of positive pole down molecules, n, and the number of negative
    pole down molecules, m."""
    """name specifies the type of base layer: graphene or mos2"""
    d = 0.92791085  #this value is from the relaxed HF molecule in a vacuum
    mol = Atoms('HF', positions=[(0, 0, 0), (0, 0, d)])
    """mol is the dipole molecule. d indicates the bond length"""
    if name == 'graphene':
        num = a * (n + m) / 4.26
        """number of unit cells. 4.26 represents the cell length in angstroms"""
        global gnr
        gnr = graphene_nanoribbon(1,
                                  int(math.ceil(num)),
                                  type='armchair',
                                  vacuum=17.5,
                                  saturated=False,
                                  sheet=True)
        """creates a graphene sheet with 10 A of vacuum on the top and bottom"""
        size = gnr.get_cell()
        cellwidth = size[0][0]
        cellheight = size[1][1]
        celllength = size[2][2]
        spacing = celllength / (n + m)
        """gets the cell dimensions"""
        mol.rotate(270, (1, 0, 0))
        for i in range(n):
            add_adsorbate(gnr,
                          mol,
                          height=(-i) * spacing,
                          position=(cellwidth / 2, cellheight / 2 + h + d),
                          mol_index=1)
        """adds n HF molecules at a separation h from the graphene"""
        mol.rotate(180, (1, 0, 0))
        for j in range(m):
            add_adsorbate(gnr,
                          mol,
                          height=-(j + n) * spacing,
                          position=(cellwidth / 2, cellheight / 2 + h),
                          mol_index=1)
            """adds m HF molecules in the opposite orientation"""
        write('graph' + str(n) + 'up' + str(m) + 'down_center.cif', gnr)
        write('graph' + str(n) + 'up' + str(m) + 'down_center.pwi', gnr)

    elif name == 'BN':
        num = a * (n + m) / 3
        global BN
        BN = Atoms('BN',
                   positions=[(0, 1.405056151, 12.5),
                              (1.2561747111, 0.7252528076, 12.5)])
        dim = [(2.5123494221, 0, 0), (-1.256174711, 2.1757584227, 0),
               (0, 0, 25)]
        BN.set_cell(dim)
        BN = BN.repeat((int(math.ceil(num)), 2, 1))
        dimensions = BN.get_cell()
        BN.set_cell([dimensions[0][0], (dimensions[1][1]), dimensions[2][2]])
        cellwidth = dimensions[0][0]
        spacing = cellwidth / (n + m)
        for i in range(n):

            add_adsorbate(BN,
                          mol,
                          height=h,
                          position=(i * spacing, dimensions[1][1] / 2),
                          mol_index=0)
        mol.rotate(180, (1, 0, 0))
        for j in range(m):
            add_adsorbate(BN,
                          mol,
                          height=h + d,
                          position=((j + n) * spacing, dimensions[1][1] / 2),
                          mol_index=0)
        BN = sort(BN)
        write('BN.cif', BN)
        write(str(n) + 'up' + str(m) + 'down.pwi', BN)
    elif name == 'mos2':
        """#this code runs for the MoS2 system
        num=a*(n+m)/3.17
        global mos2
        mos2=mx2(formula='MoS2', kind='2H', a=3.18, thickness=1, size=(int(math.ceil(num)),1, 1),
             vacuum=10)
        #mx2 makes an MoS2 system
        dim=mos2.get_cell()
        cellwidth=dim[0][0]
        cellheight=dim[1][1]
        celllength=dim[2][2]
        spacing=cellwidth/(n+m)
        #mos2.set_cell([(dim[0][0],0,0),(0,dim[1][1],0),(0,0,dim[2][2])],scale_Atoms=True)
        #truncates the unit cell to be cubic
        for i in range(n):
            add_adsorbate(mos2, mol, height=cellwidth+h,position=((-i)*spacing,cellheight/2
                                                                  ),mol_index=1)
            adds adsorbates to the MoS2
        mol.rotate(180,(1,0,0))
        for j in range(m):
            add_adsorbate(mos2, mol, height=cellwidth+h-d,position=(-(j+n)*spacing,
                                            cellheight/2),mol_index=1)
        write('mos2.cif',mos2)
        #write('mos2.pwi',mos2)"""
    print('complete')
Esempio n. 12
0
from __future__ import print_function

from ase.build import graphene_nanoribbon
"""
type armchair, zigzag
ase.build.graphene_nanoribbon(n, m, type='zigzag',
       saturated=False, C_H=1.09, C_C=1.42,
       vacuum=None, magnetic=None, initial_mag=1.12,
       sheet=False, main_element='C', saturate_element='H')
"""

atoms = graphene_nanoribbon(8, 8, sheet=True, type='armchair')
atoms.set_pbc([True, True, True])
atoms.write('orig.xyz')
atoms.write('orig.xsf')

# setup the cell
cell = atoms.get_cell()
print('original:')
print(cell)
zz = cell[2, 2]
cell[1, 1] = zz
cell[2, 2] = 10.0
atoms.set_cell(cell)

# setup coords
pos = atoms.positions
print(pos)
zz = pos[:, 2]
print(zz)
pos[:, 1] = zz
Esempio n. 13
0
frac_OH = args.OH
frac_COC = args.COC
frac_ket = args.ketone
frac_ketH = args.ketone_H

fraction = {'OH': frac_OH,'COC': frac_COC, 'ket': frac_ket, 'ket+H': frac_ketH}

# ### 1. Build graphene sheet

if verbose:
	print('Creating graphene geometry ...')
	print('Setting up graphene')

if cell_type == 'ortho':
	gr = graphene_nanoribbon(nx,ny,type=border_type,saturated=False,C_C=bond_CC,vacuum=vacuum,magnetic=False,sheet=True,main_element='C')
	xyz = np.array(gr.get_positions())
	xyz = xyz[:,[0,2,1]]
	gr = Atoms(gr.symbols,positions=xyz,cell=[[gr.cell[0,0],0.,0.],[0.,gr.cell[2,2],0.],[0.,0.,gr.cell[1,1]]],pbc=[True,True,False])
else:
	a = bond_CC * (3 ** .5)
	c = vacuum
	gr_uc = Atoms('C2',
				  scaled_positions=[[0, 0, 1/2],[2/3,1/3,1/2]],
				  cell=[[a,0,0], [- a * .5,a * 3 ** .5 / 2,0], [0,0,c]],
				  pbc=[1, 1, 0])
	
	if flake:
		gr_uc.translate([-bond_CC * (3 ** .5)*0.5,0,0]) # this is done so the edge is nicely terminated
		gr_uc.wrap()
	
Esempio n. 14
0
from ase.optimize import QuasiNewton
from ase.build import graphene_nanoribbon
from gpaw import GPAW

GNR = graphene_nanoribbon(12,1,type='zigzag', vacc=6)
GNR.set_pbc((0,0,1))
kpts = (1,1,10)
calc = GPAW(kpts=kpts,spinpol=True)
GNR.set_calculator(calc)
dyn = QuasiNewton(GNR, trajectory='ZGNR12.traj')
dyn.run(fmax=0.05)
Esempio n. 15
0
from ase.build import graphene_nanoribbon
from ase.visualize import view
from ase import units
from ase.md.verlet import VelocityVerlet
from ase.calculators.emt import EMT
from ase.md.langevin import Langevin
from ase.md import MDLogger
from ase.md.npt import NPT
import numpy as np

gnrb = graphene_nanoribbon(20, 20, type="armchair", saturated=True, vacuum=3.5)
view(gnrb)
gnrb.set_calculator(EMT())
dyn = VelocityVerlet(gnrb, dt=5.0 * units.fs)
# dyn = Langevin(gnrb, 5 * units.fs, units.kB * 123, 0.002)
stress = 2
# dyn = NPT(gnrb, 5*units.fs, 300*units.kB, stress, 25*units.fs, 75*units.fs)
dyn.attach(MDLogger(dyn,
                    gnrb,
                    'md2.log',
                    header=True,
                    stress=False,
                    peratom=True,
                    mode="w"),
           interval=1)
dyn.run(100)
# view(gnrb)