Skip to content

Commit

Permalink
Merge pull request #6 from AnguseZhang/master
Browse files Browse the repository at this point in the history
Update Readme and provide test case with methane.
  • Loading branch information
amcadmus committed Jun 24, 2019
2 parents 92b33ea + 7c4c298 commit f1fc65b
Show file tree
Hide file tree
Showing 27 changed files with 7,023 additions and 115 deletions.
465 changes: 400 additions & 65 deletions README.md

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions data/example/INCAR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
PREC=A
ENCUT=400.000000
ISYM=0
ALGO=fast
EDIFF=1E-6
LREAL=F
NPAR=1
KPAR=1

ISTART=0
ICHARG=2
ISIF=2
ISMEAR=1
SIGMA=0.200000
IBRION=0
MAXMIX=50
NBLOCK=1
KBLOCK=100

SMASS=0
POTIM=2
TEBEG=50
TEEND=50

NSW=10

LWAVE=F
LCHARG=F
PSTRESS=0

KSPACING=2
KGAMMA=F
23 changes: 23 additions & 0 deletions data/example/INCAR.rlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PREC=A
ENCUT=400.000000
# ISYM=0
ALGO=fast
EDIFF=1.000000e-06
LREAL=T
NPAR=1
KPAR=1

NELMIN=4
ISIF=2
ISMEAR=0
SIGMA=0.05
IBRION=2

NSW=1000

LWAVE=F
LCHARG=F
PSTRESS=0

KSPACING=2
KGAMMA=F
19 changes: 19 additions & 0 deletions data/example/POSCAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
POSCAR file written by OVITO
1.0000000000000000
10.0000000000000000 0.0000000000000000 0.0000000000000000
0.0000000000000000 10.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000 10.0000000000000000
H C
4 1
Direct
0.5381543385532134 0.4068608007477559 0.3605730142093164
0.3945396557300829 0.4803205689390709 0.4384688400135213
0.5520924283424902 0.5654502852627673 0.4427087377775140
0.5281853047372259 0.4164147551778533 0.5391826568442692
0.5032505926369848 0.4672551598725561 0.4452323411553799

0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
3,880 changes: 3,880 additions & 0 deletions data/example/POTCAR

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions data/example/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"cell_type": "diamond",
"super_cell": [1, 1, 1],
"elements": ["H","C"],
"from_poscar": true,
"from_poscar_path": "example/POSCAR",
"potcars": ["example/POTCAR"
],
"relax_incar": "example/INCAR.rlx",
"md_incar" : "example/INCAR.md",
"scale": [1.00],
"skip_relax": false,
"pert_numb": 30,
"md_nstep" : 10,
"pert_box": 0.03,
"pert_atom": 0.01,
"deepgen_templ": "../generator/template/",
"coll_ndata": 5000,
"_comment": "that's all"
}
95 changes: 48 additions & 47 deletions data/gen.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,18 @@ def place_element (jdata) :
def make_vasp_relax (jdata) :
out_dir = jdata['out_dir']
potcars = jdata['potcars']
encut = jdata['encut']
kspacing = jdata['kspacing_relax']
kgamma = jdata['kgamma']
ismear = 1
if 'ismear' in jdata :
ismear = jdata['ismear']
sigma = 0.2
if 'sigma' in jdata :
sigma = jdata['sigma']
#encut = jdata['encut']
#kspacing = jdata['kspacing_relax']
#kgamma = jdata['kgamma']
#ismear = 1
#if 'ismear' in jdata :
# ismear = jdata['ismear']
#sigma = 0.2
#if 'sigma' in jdata :
# sigma = jdata['sigma']
cwd = os.getcwd()
vasp_dir = os.path.join(cwd, 'vasp.in')

#vasp_dir = os.path.join(cwd, 'vasp.in')

work_dir = os.path.join(out_dir, global_dirname_02)
assert (os.path.isdir(work_dir))
Expand All @@ -287,7 +288,7 @@ def make_vasp_relax (jdata) :
os.remove(os.path.join(work_dir, 'INCAR' ))
if os.path.isfile(os.path.join(work_dir, 'POTCAR')) :
os.remove(os.path.join(work_dir, 'POTCAR'))
shutil.copy2(os.path.join(vasp_dir, 'INCAR.rlx' ),
shutil.copy2( jdata['relax_incar'],
os.path.join(work_dir, 'INCAR'))
out_potcar = os.path.join(work_dir, 'POTCAR')
with open(out_potcar, 'w') as outfile:
Expand All @@ -296,15 +297,15 @@ def make_vasp_relax (jdata) :
outfile.write(infile.read())

os.chdir(work_dir)
replace('INCAR', 'ENCUT=.*', 'ENCUT=%f' % encut)
replace('INCAR', 'ISIF=.*', 'ISIF=3')
replace('INCAR', 'KSPACING=.*', 'KSPACING=%f' % kspacing)
if kgamma :
replace('INCAR', 'KGAMMA=.*', 'KGAMMA=T')
else :
replace('INCAR', 'KGAMMA=.*', 'KGAMMA=F')
replace('INCAR', 'ISMEAR=.*', 'ISMEAR=%d' % ismear)
replace('INCAR', 'SIGMA=.*', 'SIGMA=%f' % sigma)
#replace('INCAR', 'ENCUT=.*', 'ENCUT=%f' % encut)
#replace('INCAR', 'ISIF=.*', 'ISIF=3')
#replace('INCAR', 'KSPACING=.*', 'KSPACING=%f' % kspacing)
#if kgamma :
# replace('INCAR', 'KGAMMA=.*', 'KGAMMA=T')
#else :
# replace('INCAR', 'KGAMMA=.*', 'KGAMMA=F')
#replace('INCAR', 'ISMEAR=.*', 'ISMEAR=%d' % ismear)
#replace('INCAR', 'SIGMA=.*', 'SIGMA=%f' % sigma)

sys_list = glob.glob('sys-*')
for ss in sys_list:
Expand Down Expand Up @@ -401,23 +402,23 @@ def pert_scaled(jdata) :
def make_vasp_md(jdata) :
out_dir = jdata['out_dir']
potcars = jdata['potcars']
scale = jdata['scale']
encut = jdata['encut']
kspacing = jdata['kspacing_md']
kgamma = jdata['kgamma']
pert_numb = jdata['pert_numb']
md_temp = jdata['md_temp']
scale = jdata['scale']
pert_numb = jdata['pert_numb']
md_nstep = jdata['md_nstep']
ismear = 1
if 'ismear' in jdata :
ismear = jdata['ismear']
sigma = 0.2
if 'sigma' in jdata :
sigma = jdata['sigma']
#encut = jdata['encut']
#kspacing = jdata['kspacing_md']
#kgamma = jdata['kgamma']
#md_temp = jdata['md_temp']
#ismear = 1
#f 'ismear' in jdata :
# ismear = jdata['ismear']
#sigma = 0.2
#if 'sigma' in jdata :
# sigma = jdata['sigma']

cwd = os.getcwd()
vasp_dir = os.path.join(cwd, 'vasp.in')
vasp_dir = os.path.join(cwd, vasp_dir)
#vasp_dir = os.path.join(cwd, 'vasp.in')
#vasp_dir = os.path.join(cwd, vasp_dir)
path_ps = os.path.join(out_dir, global_dirname_03)
path_ps = os.path.abspath(path_ps)
assert(os.path.isdir(path_ps))
Expand All @@ -428,26 +429,26 @@ def make_vasp_md(jdata) :
path_md = os.path.join(out_dir, global_dirname_04)
path_md = os.path.abspath(path_md)
create_path(path_md)
shutil.copy2(os.path.join(vasp_dir, 'INCAR.md'),
shutil.copy2(jdata['md_incar'],
os.path.join(path_md, 'INCAR'))
out_potcar = os.path.join(path_md, 'POTCAR')
with open(out_potcar, 'w') as outfile:
for fname in potcars:
with open(fname) as infile:
outfile.write(infile.read())
os.chdir(path_md)
replace('INCAR', 'ENCUT=.*', 'ENCUT=%f' % encut)
replace('INCAR', 'ISIF=.*', 'ISIF=2')
replace('INCAR', 'KSPACING=.*', 'KSPACING=%f' % kspacing)
if kgamma :
replace('INCAR', 'KGAMMA=.*', 'KGAMMA=T')
else :
replace('INCAR', 'KGAMMA=.*', 'KGAMMA=F')
replace('INCAR', 'NSW=.*', 'NSW=%d' % md_nstep)
replace('INCAR', 'TEBEG=.*', 'TEBEG=%d' % md_temp)
replace('INCAR', 'TEEND=.*', 'TEEND=%d' % md_temp)
replace('INCAR', 'ISMEAR=.*', 'ISMEAR=%d' % ismear)
replace('INCAR', 'SIGMA=.*', 'SIGMA=%f' % sigma)
#replace('INCAR', 'ENCUT=.*', 'ENCUT=%f' % encut)
#replace('INCAR', 'ISIF=.*', 'ISIF=2')
#replace('INCAR', 'KSPACING=.*', 'KSPACING=%f' % kspacing)
#if kgamma :
# replace('INCAR', 'KGAMMA=.*', 'KGAMMA=T')
#else :
# replace('INCAR', 'KGAMMA=.*', 'KGAMMA=F')
#replace('INCAR', 'NSW=.*', 'NSW=%d' % md_nstep)
#replace('INCAR', 'TEBEG=.*', 'TEBEG=%d' % md_temp)
#replace('INCAR', 'TEEND=.*', 'TEEND=%d' % md_temp)
#replace('INCAR', 'ISMEAR=.*', 'ISMEAR=%d' % ismear)
#replace('INCAR', 'SIGMA=.*', 'SIGMA=%f' % sigma)
os.chdir(cwd)

for ii in sys_ps :
Expand Down
81 changes: 81 additions & 0 deletions data/lib/BatchJob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python3

import os
import sys
from enum import Enum
from subprocess import Popen, PIPE

class JobStatus (Enum) :
unsubmitted = 1
waiting = 2
running = 3
terminated = 4
finished = 5
unknow = 100

class BatchJob (object):
"""
Abstract class of a batch job
It submit a job (leave the id in file tag_jobid)
It check the status of the job (return JobStatus)
NOTICE: I assume that when a job finishes, a tag file named tag_finished should be touched by the user.
TYPICAL USAGE:
job = DERIVED_BatchJob (dir, script)
job.submit ()
stat = job.check_status ()
"""
def __init__ (self,
job_dir = "", # dir of the job
job_script = "", # name of the job script
job_finish_tag = "tag_finished", # name of the tag for finished job
job_id_file = "tag_jobid") : # job id if making an existing job
self.job_dir = job_dir
self.job_script = job_script
self.job_id_file = job_dir + "/" + job_id_file
self.job_finish_tag = job_dir + "/" + job_finish_tag
self.cwd = os.getcwd()
self.submit_cmd = str(self.submit_command())
def get_job_id (self) :
if True == os.path.exists (self.job_id_file) :
fp = open (self.job_id_file, 'r')
job_id = fp.read ()
return str(job_id)
else :
return ""
def submit_command (self) :
"""
submission is
$ [command] [script]
"""
raise RuntimeError ("submit_command not implemented")
def check_status (self):
raise RuntimeError ("check_status not implemented")
def submit (self) :
if self.get_job_id () != "" :
stat = self.check_status()
if stat != JobStatus.terminated :
if stat == JobStatus.unknow :
raise RuntimeError ("unknown job status, terminate!")
print ("# job %s, dir %s already submitted (waiting, running or finished), would not submit again" %
(self.get_job_id(), self.job_dir))
return self.get_job_id()
else :
print ("# find terminated job " + self.get_job_id() + ", submit again")
if (False == os.path.isdir (self.job_dir) ) :
raise RuntimeError ("cannot find job dir " + self.job_dir)
abs_job_script = self.job_dir + "/" + self.job_script
if False == os.path.exists (abs_job_script) :
raise RuntimeError ("cannot find job script " + abs_job_script)
cwd = os.getcwd()
os.chdir (self.job_dir)
ret = Popen([self.submit_cmd + " " + self.job_script], stdout=PIPE, stderr=PIPE, shell = True)
stdout, stderr = ret.communicate()
if str(stderr, encoding='ascii') != "":
raise RuntimeError (stderr)
job_id = str(stdout, encoding='ascii').replace('\n','').split()[-1]
print ("# job %s submitted, dir %s " % (job_id, self.job_dir))
fp = open (self.job_id_file, 'w')
fp.write (job_id)
fp.close()
os.chdir (cwd)
return self.get_job_id()
Loading

0 comments on commit f1fc65b

Please sign in to comment.