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

Joseph Montoya montoyjh at alumni.stanford.edu
Sat Dec 31 07:17:53 CET 2016


In Python, you can’t specify a non-keyword argument after a keyword argument, which means once you specify a keyword in the argument list of a function (in this case, “height” in “height=0.85” on the final line), you have to use keywords for the following arguments.  I believe

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

on line 25 should fix this problem.

> On Dec 30, 2016, at 9:34 PM, 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 <http://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/20161230/953a5e00/attachment.html>


More information about the ase-users mailing list