Skip to content

Commit

Permalink
Merge pull request #6 from haidi-ustc/atest-refact
Browse files Browse the repository at this point in the history
fix unittest bug
  • Loading branch information
kevinwenminion committed Jun 28, 2020
2 parents 744356f + 19f90b0 commit fb37368
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/auto_test/equi/vasp/OUTCAR
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


--------------------------------------------------------------------------------------------------------

TITEL = PAW_PBE Li 04Oct2007

INCAR:
POTCAR: PAW_PBE Li 17Jan2003
Expand Down
5 changes: 1 addition & 4 deletions tests/auto_test/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ def test_make_confs_0(self):
self.assertEqual(os.path.realpath(os.path.join(self.equi_path, 'CONTCAR')),
os.path.realpath(os.path.join(self.target_path, 'POSCAR')))
ref_st = Structure.from_file(os.path.join(self.target_path, 'POSCAR'))
dfm_dirs.sort()
for ii in dfm_dirs:
st_file = os.path.join(ii, 'POSCAR')
self.assertTrue(os.path.isfile(st_file))
st0 = Structure.from_file(st_file)
strain_json_file = os.path.join(ii, 'strain.json')
self.assertTrue(os.path.isfile(strain_json_file))
strain_json = loadfn(strain_json_file)
df = Deformation(strain_json)
st1 = df.apply_to_structure(ref_st)
self.assertEqual(st0, st1)
37 changes: 31 additions & 6 deletions tests/auto_test/test_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import dpdata
import numpy as np
import unittest
from dpgen.generator.lib.vasp import incar_upper
from dpdata import LabeledSystem
from pymatgen.io.vasp import Incar
from monty.serialization import loadfn, dumpfn

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
Expand All @@ -25,17 +28,23 @@ def setUp(self):
"potcars": {"Li": "vasp_input/POTCAR"}
},
"relaxation": {
"cal_type": "relaxation",
"cal_setting": {"relax_pos":True,
"relax_shape":True,
"relax_vol":True}
}
}

self.conf_path = 'confs/hp-Li'
self.equi_path = 'confs/hp-Li/relaxation'
self.source_path = 'equi/vasp'
if not os.path.exists(self.equi_path):
os.mkdir(self.equi_path)

self.confs = self.jdata["structures"]
inter_param = self.jdata["interaction"]
self.VASP = VASP(inter_param, os.path.join(self.source_path, 'POSCAR'))
self.tasl_param = self.jdata["relaxation"]
self.VASP = VASP(inter_param, os.path.join(self.conf_path, 'POSCAR'))

def tearDown(self):
if os.path.exists('confs/hp-Li/relaxation'):
Expand All @@ -46,14 +55,30 @@ def tearDown(self):
os.remove('POTCAR')

def test_make_potential_files(self):
self.VASP.make_potential_files(".")
self.assertTrue(os.path.isfile("POTCAR"))
self.assertTrue(os.path.isfile('inter.json'))

if not os.path.exists(os.path.join(self.equi_path, 'POSCAR')):
with self.assertRaises(FileNotFoundError):
self.VASP.make_potential_files(self.equi_path)
shutil.copy(os.path.join(self.conf_path, 'POSCAR'), os.path.join(self.equi_path, 'POSCAR'))
self.VASP.make_potential_files(self.equi_path)
self.assertTrue(os.path.isfile(os.path.join(self.equi_path, "POTCAR")))
self.assertTrue(os.path.isfile(os.path.join(self.equi_path, 'inter.json')))

def test_make_input_file(self):
self.VASP.make_input_file(self.equi_path,'relaxation',self.tasl_param)
self.assertTrue(os.path.isfile(os.path.join(self.equi_path, "task.json")))
self.assertTrue(os.path.isfile(os.path.join(self.equi_path, "KPOINTS")))
self.assertTrue(os.path.isfile(os.path.join(self.equi_path, "INCAR")))
incar=incar_upper(Incar.from_file(os.path.join(self.equi_path, "INCAR")))
self.assertTrue(incar['ISIF'],3)

def test_compuate(self):
ret=self.VASP.compute(os.path.join(self.conf_path,'relaxation'))
self.assertIsNone(ret)
shutil.copy(os.path.join(self.source_path, 'OUTCAR'), os.path.join(self.equi_path, 'OUTCAR'))
ret=self.VASP.compute(os.path.join(self.conf_path,'relaxation'))
ret_ref=LabeledSystem(os.path.join(self.source_path, 'OUTCAR'))
self.assertTrue(ret,ret_ref.as_dict())

def test_backward_files(self):
backward_files = ['OUTCAR', 'outlog', 'CONTCAR', 'OSZICAR']
backward_files = ['OUTCAR', 'outlog', 'CONTCAR', 'OSZICAR', 'XDATCAR']
self.assertEqual(self.VASP.backward_files(), backward_files)
7 changes: 1 addition & 6 deletions tests/auto_test/test_vasp_equi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ def test_make_equi(self):
target_path = 'confs/hp-Li/relaxation'
source_path = 'vasp_input'

incar0 = Incar.from_file(os.path.join('vasp_input', 'INCAR.rlx'))
incar0 = Incar.from_file(os.path.join('vasp_input', 'INCAR'))
incar1 = Incar.from_file(os.path.join(target_path, 'INCAR'))
self.assertFalse(incar0 == incar1)
incar0['KSPACING'] = 0.1
incar0['EDIFF'] = 1e-6
self.assertTrue(incar0 == incar1)

with open(os.path.join('vasp_input', 'POTCAR')) as fp:
Expand Down Expand Up @@ -86,5 +83,3 @@ def test_post_equi(self):
result_json_file = os.path.join(target_path, 'result.json')
result_json = loadfn(result_json_file)
self.assertTrue(os.path.isfile(result_json_file))
# self.assertEqual(inter_json,inter_param)
# calc=make_calculator(inter_param, poscar)

0 comments on commit fb37368

Please sign in to comment.