-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify_uincar.py
42 lines (34 loc) · 1.29 KB
/
modify_uincar.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
#!/usr/bin/env python
# -*-coding: utf-8 -*-
#modifyu_incar.py
#Mohammad Saleheen
#CREATED: 02-03-2020
# add the u parameters for adsorbate atoms (0) to a surface INCAR
# based on number of adsorbates in the poscar file
import numpy as np
import linecache
import itertools
atoms = [item for item in linecache.getline('POSCAR', 6).split()]
atom_type = len(atoms)
def check_atom_types(atom_type, line):
tag, metal, oxygen = line.split()
if atom_type == 2:
return '{} {} {}\n'.format(tag, metal, oxygen)
elif atom_type == 3:
return '{} {} {} 0\n'.format(tag, metal, oxygen)
elif atom_type == 4:
return '{} {} {} 0 0\n'.format(tag, metal, oxygen)
else:
print('There must be something wrong! Check POSCAR!')
exit()
fw = open('new_incar', 'w')
with open('INCAR', 'r') as f:
for line in f:
if 'LDAUJ' in line:
fw.write(check_atom_types(atom_type, line))
elif 'LDAUL' in line:
fw.write(check_atom_types(atom_type, line))
elif 'LDAUU' in line:
fw.write(check_atom_types(atom_type, line))
else:
fw.write(line)