Until now, when performing computer simulations while changing parameters little by little, I had to manually operate one file each time, but as the number of required data increases (about 200), it becomes difficult. So I wrote a simple script to automate it to some extent.
I was doing it manually -Create a directory for each parameter value -Create an input file and a job command file in the directory -Edit the parameters of the input file with an editor ・ Job submission I will operate the command with python so that it can be executed.
This time, the first-principles calculation package is used to calculate the interaction energy obtained from the interatomic distance of graphite.
import os
import re
from time import sleep
```osis used for terminal command operations,
reis used for regular expressions, and
sleep`` is used for spacing job submissions.
Create 200 pieces of data with interatomic distances from 3.01 Å
to 5.00 Å
.
begin = 3.01
end = 5.00
step = 0.01
Create the input file and the file that is the source of the job file in the data
directory in advance, and read those files.
#Assign the path to a variable
input_path = 'data/input_seed'
job_path = 'data/qsub_seed'
#Open the file and read it as text
with open(input_path) as f:
input_file = f.read()
with open(job_path) as f:
job_file = f.read()
Since the parameter is not an integer and the range
function cannot be used, we are defining a new drange
function.
#drange function definition
def drange(begin, end, step):
n = begin
while n < end:
yield n
n += step
for r in drange(begin,end,step):
#Å=>Convert to bohr
ang = ('{:.8f}'.format(r*2/0.529177))
#Create directory, specify file path
os.system('mkdir %s' % r)
input_name = ('%s/nfinp' % r)
job_name = ('%s/run.sh' % r)
#Replace distance with regular expression
distance = str(ang)
input_mod = re.sub('distance',distance,input_file)
#Create a file in the directory
with open(input_name, mode='w') as f:
f.write(input_mod)
with open(job_name, mode='w') as f:
f.write(job_file)
#Enter the directory and submit a job
current_dir = os.getcwd()
os.chdir(current_dir + ('/%s' % r))
os.system('qsub run.sh')
os.chdir(current_dir)
sleep(1)
The contents of the original input file look like this. The interatomic distance ( distance
) is used as a variable, and ** replaced with a regular expression **. I honestly don't understand the other parts lol
data/input_seed
0 0 0 0 0 0 : graphite
6.00 20.00 1 4 4 : GMAX, GMAXP, NTYP, NATM, NATM2
1 0 : num_space_group, type of bravis lattice
4.655149797 4.655149797 distance 90.0 90.0 60.0 : a,b,c,alpha,beta,gamma
24 24 2 1 1 1 : knx,kny,knz, k-point shift
0 0 : NCORD, NINV
0.000000000000 0.000000000000 0.250000000000 1 1 1
0.333333333333 0.333333333333 0.250000000000 1 1 1
0.000000000000 0.000000000000 -0.250000000000 1 1 1
-0.333333333333 -0.333333333333 -0.250000000000 1 1 1
6 0.1500 1.00794 3 1 0.d0 : TYPE 1IATOMN,ALFA,AMION,ILOC,IVAN
0 0 0 0 0 : ICOND 0-MD, 1-CONT.MD, 2-WAVE FN,, 3-WAVE FN CONT., iconstpw
0 1 : IPRE, IPRI
200 1000 0 57200.00 0 : NMD1, NMD2, iter_last, CPUMAX,ifstop
6 1 : Simple=1,Broyd2=3,Blugel=6, 1:charge, 2:potential mix.
0 30 0.5 : starting mixing, kbxmix,alpha
0.60 0.50 0.60 0.70 1.00 : DTIM1, DTIM2, DTIM3, DTIM4, dtim_last
100.00 2 1 0.10D-08 1.d-06 : DTIO ,IMDALG, IEXPL, EDELTA
-0.0010 1.00D+03 0 : WIDTH,FORCCR,ISTRESS
rev-vdw-df2 1 : XCTYPE, nspin
1.00 3 : destm, n_stm
101 : NBZTYP 0-SF, 1-BK, 2-SC, 3-BCC, 4-FCC, 5-DIA, 6-HEX
0 0 0 : NKX, NKY, NKZ
0 0 0 : NKX2,NKY2,NKZ2
12 : NEG
1 : NEXTST(MB)
0 : 0; random numbers, 1; matrix diagon
2 0 0 0(MB) : imsd, i_2lm, i_sd2another, wksz for phase
0 : evaluation of eko difference.0 = no ,1 = yes
0 : npdosao
0 0.0 : SM_N, dopping
It would be nice if we could output the necessary part of the output file as a database and even draw a graph.
Recommended Posts