[ase-users] SyntaxError: non-keyword arg after keyword arg

Tristan Maxson tgmaxson at gmail.com
Sat Dec 31 07:20:58 CET 2016


A syntax error is almost always a user error in python, due to weird quirks
of the language.  I think this line with is the offending line.

add_adsorbate(slab, H2mol, height=0.85, fcc_1)

It looks like you specify the height by name,  then supply an unnamed fcc_1
afterwards. In python this is not allowed. Since you named your height
keyword, you must also name a keyword for fcc_1

I am traveling and don't know exactly what the parameter is off the top of
my head but I think it should be site or something similar?

add_adsorbate(slab, H2mol, height=0.85, site=fcc_1)

Thank you,
Tristan Maxson

On Dec 31, 2016 12:42 AM, "Punit Kumar via ase-users" <
ase-users at listserv.fysik.dtu.dk> wrote:

> Hi, all
> I am trying to calculate initial and final state for dissociative
> adsorption of hydrogen molecule on Ni surface. For that the code I have
> written is
>
> from __future__ import print_function
> from ase import Atoms
> from ase.build import fcc111, add_adsorbate
> from ase.calculators.emt import EMT
> from ase.constraints import FixAtoms
> from ase.optimize import QuasiNewton
> from ase.io import write
> from math import sin, pi
>
> # Find the initial and final states for the reaction.
>
> # Set up a (2 x 2 x 3) three layer slab of Ni:
> slab = fcc111('Ni',size=(2, 2, 3))
> a = slab.get_distance(0,1)
> slab.center(vacuum=6, axis=2)
> slab.set_pbc((True, True, True))
>
> # Initial state.
> d = 0.74 # H2 bond length
> H2mol = Atoms('H2', positions=[(0, 0, 0), (0, 0, d)])
> H2mol.set_pbc((True, True, True))
>
> # adsorption of H-atom on Ni fcc site
> fcc_1 = [a/2., a*sin(pi/3.)/3.]
> add_adsorbate(slab, H2mol, height=0.85, fcc_1)
>
> # Use the EMT calculator for the forces and energies:
> slab.set_calculator(EMT())
>
> # fix the bottom two layer
> constraint = FixAtoms(mask=[i.tag > 1 for i in slab])
> slab.set_constraint(constraint)
>
> # Relax the structure
> dyn = QuasiNewton(slab, trajectory='H2.traj')
> dyn.run(fmax=0.01)
>
>
> fd = open('adsorption.txt', 'w')
> print('initial state:', slab.get_potential_energy())
>
>
> # Now the final state.
> # Move the second H atom to a neighboring hollow site:
> slab[-1].position[0] = slab[-2].position[0] + 0.25 * slab.cell[0,0]
> slab[-1].position[1] = slab[-2].position[1]
>
> # Relax the structure
> dyn = QuasiNewton(slab, trajectory='2H.traj')
> dyn.run(fmax=0.01)
>
> fd = open('dissociation.txt', 'w')
> print('final state:  ', slab.get_potential_energy())
>
> but when I run this code it gives me syntax error as
>
> File "H2_dissociation_Ni.py", line 25
>     add_adsorbate(slab, H2mol, height=0.85, fcc_1)
> SyntaxError: non-keyword arg after keyword arg
>
> Can someone help me where I am doing it wrong.
>
> Thank You
> Punit
>
> _______________________________________________
> ase-users mailing list
> ase-users at listserv.fysik.dtu.dk
> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20161231/21af7231/attachment.html>


More information about the ase-users mailing list