1
1
from pymatgen .analysis .adsorption import AdsorbateSiteFinder
2
2
from pymatgen .core .structure import Molecule , Structure
3
+ from pymatgen .core .surface import Slab
3
4
from pymatgen .io .vasp .inputs import Poscar
4
5
6
+
7
+ def slab_from_structure (miller : list [int ], structure : Structure ) -> Slab :
8
+ '''
9
+ Returns a pymatgen.core.surface.Slab from a pymatgen structure
10
+ '''
11
+ import numpy as np
12
+
13
+ #if miller is None, raise error
14
+ if miller is None :
15
+ raise ValueError ('miller index is required' )
16
+
17
+ return Slab (lattice = structure .lattice ,
18
+ species = structure .species_and_occu ,
19
+ coords = structure .frac_coords ,
20
+ miller_index = miller ,
21
+ oriented_unit_cell = structure ,
22
+ shift = 0 ,
23
+ scale_factor = np .eye (3 , dtype = int ),
24
+ site_properties = structure .site_properties )
25
+
5
26
def structure_from_file (filename : str ) -> Structure :
6
27
'''
7
28
Creates a pymatgen structure from a file
@@ -24,23 +45,23 @@ def get_chemical_formula(structure: Structure) -> str:
24
45
'''
25
46
return structure .composition .reduced_formula
26
47
27
- def add_adsorbate_single (structure : Structure , adsorbate : Molecule , coverage : list [int ] = [1 , 1 , 1 ], distance : float = 1.0 ) -> list [Structure ]:
48
+ def add_adsorbate_single (structure : Structure , adsorbate : Molecule , coverage : list [int ] = [1 , 1 , 1 ], distance : float = 1.0 , positions = ( 'ontop' , 'bridge' , 'hollow' ) ) -> list [Structure ]:
28
49
'''
29
50
Finds all adsorption sites on a structure and adsorbs the adsorbate at each site. Returns a list of adsorbed structures.
30
51
'''
31
52
32
53
asf = AdsorbateSiteFinder (structure )
33
- ads_structs = asf .generate_adsorption_structures (adsorbate , repeat = coverage , find_args = {"distance" : distance }) # edit later
54
+ ads_structs = asf .generate_adsorption_structures (adsorbate , repeat = coverage , find_args = {"distance" : distance , "positions" : positions }) # edit later
34
55
35
56
return ads_structs
36
57
37
- def add_adsorbate_on_both_surfaces (structure : Structure , adsorbate : Molecule , coverage : list [int ] = [1 , 1 , 1 ], distance : float = 1.0 ) -> list [Structure ]:
58
+ def add_adsorbate_on_both_surfaces (structure : Structure , adsorbate : Molecule , miller_plane : list [ int ], coverage : list [int ] = [1 , 1 , 1 ], distance : float = 1.0 , positions = ( 'ontop' , 'bridge' , 'hollow' ) ) -> list [Structure ]:
38
59
'''
39
60
Finds all adsorption sites on a structure and adsorbs the adsorbate at each site. Returns a list of adsorbed structures.
40
61
'''
41
-
42
- asf = AdsorbateSiteFinder (structure )
43
- ads_structs = asf .adsorb_both_surfaces (adsorbate , repeat = coverage , find_args = {"distance" : distance }) # edit later
62
+ slab = slab_from_structure ( miller = miller_plane , structure = structure )
63
+ asf = AdsorbateSiteFinder (slab )
64
+ ads_structs = asf .adsorb_both_surfaces (adsorbate , repeat = coverage , find_args = {"distance" : distance , "positions" : positions }) # edit later
44
65
45
66
return ads_structs
46
67
@@ -59,10 +80,14 @@ def create_adsorbed_structure(args):
59
80
structure = structure_from_file (args .input )
60
81
adsorbate = adsorbate_from_file (args .adsorbate )
61
82
83
+ #if positions = 'all', then set positions to be positions=('ontop', 'bridge', 'hollow')
84
+ if args .positions == 'all' :
85
+ args .positions = ('ontop' , 'bridge' , 'hollow' )
86
+
62
87
if args .both :
63
- ads_structs = add_adsorbate_on_both_surfaces (structure , adsorbate , coverage = args .coverage , distance = args .distance )
88
+ ads_structs = add_adsorbate_on_both_surfaces (structure , adsorbate , miller_plane = args . plane , coverage = args .coverage , distance = args .distance , positions = args . positions )
64
89
else :
65
- ads_structs = add_adsorbate_single (structure , adsorbate , coverage = args .coverage , distance = args .distance )
90
+ ads_structs = add_adsorbate_single (structure , adsorbate , coverage = args .coverage , distance = args .distance , positions = args . positions )
66
91
67
92
poscars = [ Poscar (ads_struct , sort_structure = True ) for ads_struct in ads_structs ]
68
93
0 commit comments