-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakeSAM.py
executable file
·76 lines (62 loc) · 2.49 KB
/
MakeSAM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
#
# This script does not make physically realistic SAMs
# it is intended only for creating visualizations
# or starting points for calculations
#
import sys,os,argparse
from ase.io import read,write
from ase.build import fcc111,add_adsorbate
# Parse command line arguments
desc='Build a pysically unrealistic SAM from an XYZ file containing a molecule'
parser = argparse.ArgumentParser(description=desc,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('infile', type=str, nargs=1, default=[],
help='XYZ file to parse.')
parser.add_argument('-H', '--height', type=int, default=1.5,
help='Height in Angstroms to place molecules above surface.')
parser.add_argument('-t', '--tilt', type=int, default=0,
help='Tilt angle.')
parser.add_argument('-A', '--tiltaxis', type=str, default='x',
help='Tilt axis.')
parser.add_argument('-e','--electrode', type=str, default='Au',
help='Type of electrode.')
parser.add_argument('-s','--size', type=str, default='10,10,2',
help='Size of the substrate in the form x,y,z number of atoms.')
parser.add_argument('-T','--topcontact', action='store_true', default=False,
help='Add a top contact.')
opts=parser.parse_args()
# Needed for zmatrix parser class
opts.build = False
opts.project = True
from parse.xyz import Parser
if not opts.infile:
print("I need an input file.")
sys.exit()
position='hcp'
try:
opts.size = tuple(map(int, opts.size.strip().split(',')))
except:
print("Error parsing size as three comma-separated integers")
sys.exit()
slab=fcc111(opts.electrode, opts.size)
# Needed to prevent multilayer formation
slab.info['adsorbate_info']['top layer atom index'] = len(slab.positions)-1
xyz = Parser(opts,opts.infile[0])
xyz.parseZmatrix()
if opts.tilt > 0:
xyz.zmat.rotateAboutAxis(opts.tiltaxis,opts.tilt)
mol = xyz.getZmat()
print(mol)
for i in range(1,opts.size[0]-1,2):
add_adsorbate(slab,mol,opts.height,position,offset=[0,i],mol_index=0)
firstmol = len(slab.positions)
for n in range(2,opts.size[0]-1,2):
add_adsorbate(slab,mol,opts.height,position,offset=[n,i],mol_index=0)
if opts.topcontact:
top = fcc111(opts.electrode, opts.size)
del(slab.info['adsorbate_info']['top layer atom index'])
#slab.info['adsorbate_info']['top layer atom index'] = firstmol
add_adsorbate(slab,top,opts.height,position,offset=[0,0],mol_index=0)
write(opts.infile[0][:-4]+'_SAM.png',slab,rotation='80x,180z')
write(opts.infile[0][:-4]+'_SAM.xyz',slab)