Skip to content

Commit

Permalink
Merge pull request #20 from MDIL-SNU/src_1.0.0
Browse files Browse the repository at this point in the history
Better algorithm for magnetism
  • Loading branch information
kstgood333 authored Jun 1, 2021
2 parents 4f10d16 + d7fd335 commit 1bd6745
Show file tree
Hide file tree
Showing 13 changed files with 607 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.6"
__version__ = "1.0.0"
11 changes: 7 additions & 4 deletions src/band.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###########################################
### Date: 2018-12-05 ###
### yybbyb@snu.ac.kr ###
### Date: 2020-11-05 ###
### mk01071@snu.ac.kr ###
###########################################
# This is for drawing band structure and estimating band gap.
import shutil, os, sys, subprocess, yaml
Expand All @@ -10,7 +10,7 @@
from module_hse import *
from input_conf import set_on_off
from _version import __version__
code_data = 'Version '+__version__+'. Modified at 2020-05-12'
code_data = 'Version '+__version__+'. Modified at 2020-11-05'

# Set input
dir = sys.argv[1]
Expand Down Expand Up @@ -133,8 +133,11 @@
else:
mag_on = check_magnet(dir+'/relax_'+pot_type,inp_yaml['magnetic_ordering']['minimum_moment'])
vasprun = make_incar_for_ncl(dir_band,mag_on,kpar,npar,vasp_std,vasp_gam,vasp_ncl)
wincar(dir_band+'/INCAR',dir_band+'/INCAR',[['NSW','0'],['LCHARG','.T.'],['ALGO','Normal']],[])
wincar(dir_band+'/INCAR',dir_band+'/INCAR',[['NSW','0'],['LCHARG','.T.']],[])

if os.path.isfile(dir+'/relax_'+pot_type+'/CHGCAR') and os.path.getsize(dir+'/relax_'+pot_type+'/CHGCAR') > 1000: #If electronic convergence in previous step had problem
shutil.copyfile(dir+'/relax_'+pot_type+'/CHGCAR',dir_band+'/CHGCAR')
wincar(dir_band+'/INCAR',dir_band+'/INCAR',[['ICHARG','1']],[])
# VASP calculation for CHGCAR
out = run_vasp(dir_band,nproc,vasprun,mpi)
if out == 1: # error in vasp calculation
Expand Down
44 changes: 38 additions & 6 deletions src/cutoff.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
####################################
# date : 2018-12-06 #
# date : 2020-11-05 #
# Author : feihoon@snu.ac.kr #
# Modifier : yybbyb@snu.ac.kr #
# Modifier : mk01071@snu.ac.kr #
####################################
import os, sys, subprocess, yaml
import os, sys, subprocess, yaml, shutil
from module_log import *
from module_vasprun import *
from module_converge import *
import math
from _version import __version__
code_data = 'Version '+__version__+'. Modified at 2020-05-12'
code_data = 'Version '+__version__+'. Modified at 2020-11-05'

# Set input
dir = sys.argv[1]
Expand Down Expand Up @@ -105,6 +106,8 @@
incar_for_hse(now_path+'/INCAR')
incar_from_yaml(now_path,inp_conv['incar'])
wincar(now_path+'/INCAR',now_path+'/INCAR',[['ENCUT',str(ENCUT)],['NSW','0'],['LWAVE','F'],['LCHARG','F']],[])
if pygrep('ALGO',dir+'/cutoff/EN'+str(ENCUT)+"/INCAR",0,0).split()[2].upper()[0] == "A" or (ENCUT-ENSTEP>=EN_recommend and os.path.isfile(dir+'/cutoff/EN'+str(ENCUT-ENSTEP)+"/INCAR") and pygrep('ALGO',dir+'/cutoff/EN'+str(ENCUT-ENSTEP)+"/INCAR",0,0).split()[2].upper()[0] == "A"):
wincar(now_path+'/INCAR',now_path+'/INCAR',[['NSW','0'],["ALGO","All"],['LCHARG','T'],['LWAVE','F']],[])
# Running vasp
out = run_vasp(now_path,nproc,vasprun,mpi)
if ENCUT < EN_recommend:
Expand Down Expand Up @@ -146,9 +149,32 @@
out = electronic_step_convergence_check(now_path)

if out == 2: # electronic step is not converged. (algo = normal)
make_amp2_log(dir+'/cutoff','The calculation stops but electronic step is not converged.')
print(0)
sys.exit()
# make_amp2_log(now_path,'We change ALGO normal to All.')
# wincar(now_path+'/INCAR',now_path+'/INCAR',[['ALGO','All'],['NSW','0'],['LCHARG','T'],['LWAVE','F'],['AMIX','#'],['BMIX','#'],['AMIX_MAG','#'],['BMIX_MAG','#']],[])
make_amp2_log(now_path,'We try ALGO All with a better guess on initial charge density.')
wincar(now_path+'/INCAR',now_path+'/INCAR',[['ALGO','All'],['NSW','0'],['LCHARG','T'],['LWAVE','F'],['AMIX','#'],['BMIX','#'],['AMIX_MAG','#'],['BMIX_MAG','#']],[])
if os.path.isfile(now_path+'/CHGCAR') and os.path.getsize(now_path+'/CHGCAR') > 1000:
wincar(now_path+'/INCAR',now_path+'/INCAR',[['ICHARG','1']],[])
out = run_vasp(now_path,nproc,vasprun,mpi)
if out == 1: # error in vasp calculation
print(0)
sys.exit()
else:
out = electronic_step_convergence_check_CHGCAR_conv(now_path)
count = 0
if out == 1:
count = 0; out_c = 1
while count < 3 and out_c != 0:
out = run_vasp(now_path,nproc,vasprun,mpi)
count = count+1
if out == 1: # error in vasp calculation
print(0)
sys.exit()
out_c = electronic_step_convergence_check_CHGCAR_conv(now_path)
if count==3 and out_c == 1:
make_amp2_log(target,'It is not converged.')
print(0)
sys.exit()
write_conv_result(now_path,enlog)

# electronic step is converged.
Expand All @@ -158,6 +184,12 @@
os.chdir('../')

make_amp2_log(dir+'/cutoff','cut off energy test is done')
#cp converged CHGCAR to INPUT0
if os.path.isfile(dir+'/cutoff/EN'+str(ENCUT-3*ENSTEP)+'/CHGCAR') and os.path.getsize(dir+'/cutoff/EN'+str(ENCUT-3*ENSTEP)+'/CHGCAR') > 1000:
shutil.copyfile(dir+'/cutoff/EN'+str(ENCUT-3*ENSTEP)+'/CHGCAR',dir+'/INPUT0/CHGCAR_conv')
if pygrep('ALGO',dir+'/cutoff/EN'+str(ENCUT-3*ENSTEP)+"/INCAR",0,0).split()[2].upper()[0] == "A":
wincar(dir+'/INPUT0/INCAR',dir+'/INPUT0/INCAR',["ALGO","All"],[])


with open(enlog,'a') as result:
result.write("\nConvergence criterion: E/atom < "+str(ENCONV)+" eV\n")
Expand Down
10 changes: 5 additions & 5 deletions src/dos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
####################################
# Modifier : yybbyb@snu.ac.kr #
# data : 2018-12-05 #
# Date : 2020-11-05 #
# mk01071@snu.ac.kr #
####################################
# This is for drawing density of states.
import shutil, os, sys, subprocess, yaml
Expand All @@ -9,7 +9,7 @@
from module_dos import *
from input_conf import set_on_off
from _version import __version__
code_data = 'Version '+__version__+'. Modified at 2020-05-12'
code_data = 'Version '+__version__+'. Modified at 2020-11-05'

# Set input
dir = sys.argv[1]
Expand Down Expand Up @@ -176,7 +176,7 @@
sys.exit()
make_amp2_log(dir_dos,'CHGCAR file is generated successfully.')

wincar(dir_dos+'/INCAR',dir_dos+'/INCAR',[['NEDOS','3001'],['ISMEAR','-5'],['SIGMA','0.1']],[])
wincar(dir_dos+'/INCAR',dir_dos+'/INCAR',[['NEDOS','3001'],['ISMEAR','-5'],['SIGMA','0.1'],["ALGO","Normal"]],[])

incar_from_yaml(dir_dos,inp_dos['incar'])

Expand All @@ -189,7 +189,7 @@
while 1:
make_multiple_kpts(dir+'/kptest/kpoint.log',dir_dos+'/KPOINTS',dir_dos+'/POSCAR',inp_dos['kp_multiplier'],sym,gam_option)

wincar(dir_dos+'/INCAR',dir_dos+'/INCAR',[['NSW','0'],['ISTART','1'],['ICHARG','11'],['LCHARG','.F.']],[])
wincar(dir_dos+'/INCAR',dir_dos+'/INCAR',[['NSW','0'],['ICHARG','11'],['LCHARG','.F.']],[])
if no_rlx == 1:
mag_on = 2
else:
Expand Down
5 changes: 3 additions & 2 deletions src/hse_gap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###########################################
### Date: 2018-12-05 ###
### Date: 2020-11-05 ###
### yybbyb@snu.ac.kr ###
### mk01071@snu.ac.kr ###
###########################################
# This is for estimating band gap with PBE@HSE scheme.
import shutil, os, sys, subprocess, yaml
Expand All @@ -12,7 +13,7 @@
from input_conf import set_on_off
from module_relax import *
from _version import __version__
code_data = 'Version '+__version__+'. Modified at 2020-05-12'
code_data = 'Version '+__version__+'. Modified at 2020-11-05'

# Set input
dir = sys.argv[1]
Expand Down
75 changes: 68 additions & 7 deletions src/kpoint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
####################################
# date : 2018-12-06 #
# Date: 2020-11-05 #
# Author : feihoon@snu.ac.kr #
# Modifier : yybbyb@snu.ac.kr #
# Modifier : mk01071@snu.ac.kr #
####################################
import os, sys, subprocess, yaml
from module_log import *
from module_vasprun import *
from module_converge import *
from _version import __version__
code_data = 'Version '+__version__+'. Modified at 2020-05-12'
code_data = 'Version '+__version__+'. Modified at 2020-11-05'

# Set input
dir = sys.argv[1]
Expand Down Expand Up @@ -98,6 +99,10 @@
incar_for_hse(now_path+'/INCAR')
incar_from_yaml(now_path,inp_conv['incar'])
wincar(now_path+'/INCAR',now_path+'/INCAR',[['NSW','0'],['LCHARG','F'],['LWAVE','F']],[])
#if algo is all in the last step, current step uses ALGO all
if os.path.isfile(dir+'/kptest/KP'+str(KPL-1)+"/INCAR") and pygrep('ALGO',dir+'/kptest/KP'+str(KPL-1)+"/INCAR",0,0).split()[2].upper()[0] == "A":
wincar(now_path+'/INCAR',now_path+'/INCAR',[['NSW','0'],["ALGO","All"],['LCHARG','T'],['LWAVE','F']],[])

out = run_vasp(now_path,nproc,vasprun,mpi)
if KPL == 1 or KPL == 2:
if out == 1: # error in vasp calculation
Expand All @@ -118,8 +123,38 @@
out = electronic_step_convergence_check(now_path)

if out == 2: # electronic step is not converged. (algo = normal)
make_amp2_log(dir+'/kptest','The calculation stops but electronic step is not converged, but pass because of too small kpoints.')
loopnum = 0
# make_amp2_log(dir+'/kptest','The calculation stops but electronic step is not converged, but pass because of too small kpoints.')
make_amp2_log(now_path,'We try ALGO All with a better guess on initial charge density.')
wincar(now_path+'/INCAR',now_path+'/INCAR',[['ALGO','All'],['NSW','0'],['LCHARG','T'],['LWAVE','F'],['AMIX','#'],['BMIX','#'],['AMIX_MAG','#'],['BMIX_MAG','#']],[])
if os.path.isfile(now_path+'/CHGCAR') and os.path.getsize(now_path+'/CHGCAR') > 1000:
wincar(now_path+'/INCAR',now_path+'/INCAR',[['ICHARG','1']],[])
out = run_vasp(now_path,nproc,vasprun,mpi)
if out == 1: # error in vasp calculation
make_amp2_log(dir+'/kptest','VASP error occurs, but pass because of too small kpoints.')
out = 3
loopnum = 0
else:
out = electronic_step_convergence_check_CHGCAR_conv(now_path)
count = 0
if out == 1:
count = 0; out_c = 1
while count < 3 and out_c != 0:
make_amp2_log(now_path,'The last CHGCAR is used as an initial guess.')
out = run_vasp(now_path,nproc,vasprun,mpi)
count = count+1
if out == 1: # error in vasp calculation
make_amp2_log(dir+'/kptest','VASP error occurs, but pass because of too small kpoints.')
out = 3
loopnum = 0
break
out_c = electronic_step_convergence_check_CHGCAR_conv(now_path)
if count==3 and out_c == 1:
make_amp2_log(dir+'/kptest','The calculation stops but electronic step is not converged, but pass because of too small kpoints.')
out = 3
loopnum = 0
continue
write_conv_result(now_path,kplog)

elif out < 2:
write_conv_result(now_path,kplog)

Expand All @@ -137,9 +172,33 @@
out = electronic_step_convergence_check(now_path)

if out == 2: # electronic step is not converged. (algo = normal)
make_amp2_log(dir+'/kptest','The calculation stops but electronic step is not converged.')
print(0)
sys.exit()
make_amp2_log(now_path,'We try ALGO All with a better guess on initial charge density.')
wincar(now_path+'/INCAR',now_path+'/INCAR',[['ALGO','All'],['NSW','0'],['LCHARG','T'],['LWAVE','F'],['AMIX','#'],['BMIX','#'],['AMIX_MAG','#'],['BMIX_MAG','#']],[])
if os.path.isfile(now_path+'/CHGCAR') and os.path.getsize(now_path+'/CHGCAR') > 1000:
wincar(now_path+'/INCAR',now_path+'/INCAR',[['ICHARG','1']],[])
out = run_vasp(now_path,nproc,vasprun,mpi)
if out == 1: # error in vasp calculation
print(0)
sys.exit()
else:
out = electronic_step_convergence_check_CHGCAR_conv(now_path)
count = 0
if out == 1:
count = 0; out_c = 1
while count < 3 and out_c != 0:
make_amp2_log(now_path,'The last CHGCAR is used as an initial guess.')
out = run_vasp(now_path,nproc,vasprun,mpi)
count = count+1
if out == 1: # error in vasp calculation
print(0)
sys.exit()
out_c = electronic_step_convergence_check_CHGCAR_conv(now_path)
if count==3 and out_c == 1:
make_amp2_log(target,'It is not converged.')
print(0)
sys.exit()
os.remove(now_path+'/CHGCAR')
os.remove(now_path+'/CHG')
# electronic step is converged.
write_conv_result(now_path,kplog)

Expand All @@ -159,6 +218,8 @@
result.write("Converged KPL: "+str(KPL-3)+'\n')
subprocess.call(['cp',dir+'/kptest/KP'+str(KPL-3)+'/KPOINTS',dir+'/kptest/KPOINTS_converged'])
subprocess.call(['cp',dir+'/kptest/KPOINTS_converged',dir+'/INPUT0/KPOINTS'])
if pygrep('ALGO',dir+'/kptest/KP'+str(KPL-3)+"/INCAR",0,0).split()[2].upper()[0] == "A":
wincar(dir+'/INPUT0/INCAR',dir+'/INPUT0/INCAR',[["ALGO","All"]],[])

make_conv_dat(dir+'/kptest','kpoint')
if not os.path.isfile(inp_yaml['program']['gnuplot']):
Expand Down
Loading

0 comments on commit 1bd6745

Please # to comment.