Skip to content

Commit

Permalink
Merge branch 'devel' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLI-afk authored Jul 3, 2022
2 parents 93351c8 + 28a3f97 commit 8e1db56
Show file tree
Hide file tree
Showing 6 changed files with 2,766 additions and 10 deletions.
16 changes: 6 additions & 10 deletions dpgen/auto_test/Gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

class Gamma(Property):
"""
Calculation of gamma line for bcc and fcc (v1.1 add half z judgement)
Calculation of common gamma lines for bcc and fcc
"""

def __init__(self,
parameter):
parameter['reproduce'] = parameter.get('reproduce', False)
Expand All @@ -34,9 +33,11 @@ def __init__(self,
self.miller_index = parameter['miller_index']
self.displace_direction = parameter['displace_direction']
self.lattice_type = parameter['lattice_type']

# parameter['min_slab_size'] = parameter.get('min_slab_size', 10)
# self.min_slab_size = parameter['min_slab_size']
parameter['min_supercell_size'] = parameter.get('min_supercell_size', (1,1,5))

self.min_supercell_size = parameter['min_supercell_size']
parameter['min_vacuum_size'] = parameter.get('min_vacuum_size', 20)
self.min_vacuum_size = parameter['min_vacuum_size']
Expand All @@ -45,10 +46,6 @@ def __init__(self,
parameter['n_steps'] = parameter.get('n_steps', 10)
self.n_steps = parameter['n_steps']
self.atom_num = None
# parameter['pert_xz'] = parameter.get('pert_xz', 0.01)
# self.pert_xz = parameter['pert_xz']
# default_max_miller = 2
# parameter['max_miller'] = parameter.get('max_miller', default_max_miller)
parameter['cal_type'] = parameter.get('cal_type', 'relaxation')
self.cal_type = parameter['cal_type']
default_cal_setting = {"relax_pos": True,
Expand Down Expand Up @@ -276,8 +273,7 @@ def __displace_slab(self,
all_slabs.append(slab.copy())
return all_slabs

def __poscar_fix(self,
poscar):
def __poscar_fix(self, poscar) -> None:
# add position fix condition of x and y in POSCAR
insert_pos = -self.atom_num
fix_dict = {
Expand All @@ -297,8 +293,7 @@ def __poscar_fix(self,
for ii in range(len(contents)):
fin2.write(contents[ii])

def __inLammpes_fix(self,
inLammps):
def __inLammpes_fix(self, inLammps) -> None:
# add position fix condition of x and y of in.lammps
fix_dict = {
'true': '0',
Expand Down Expand Up @@ -378,6 +373,7 @@ def _compute_lower(self,
str(miller_index) + '-' + structure_dir + ':', int(ii[-4:])/self.n_steps, sfe, epa, equi_epa)
res_data[int(ii[-4:])/self.n_steps] = [sfe, epa, equi_epa]


else:
if 'init_data_path' not in self.parameter:
raise RuntimeError("please provide the initial data path to reproduce")
Expand Down
13 changes: 13 additions & 0 deletions tests/auto_test/confs/hp-Mo/POSCAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Mo2
1.0000000000000000
3.1623672675177916 -0.0000000000000000 -0.0000000000000000
-0.0000000000000000 3.1623672675177916 -0.0000000000000000
0.0000000000000000 0.0000000000000000 3.1623672675177916
Mo
2
Direct
0.0000000000000000 0.0000000000000000 0.0000000000000000
0.5000000000000000 0.5000000000000000 0.5000000000000000

0.00000000E+00 0.00000000E+00 0.00000000E+00
0.00000000E+00 0.00000000E+00 0.00000000E+00
10 changes: 10 additions & 0 deletions tests/auto_test/equi/vasp/CONTCAR_Mo_bcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Mo2
1.0
3.1617699325125632e+00 0.0000000000000000e+00 0.0000000000000000e+00
-2.9607253805968378e-17 3.1617699325125632e+00 0.0000000000000000e+00
-6.1517551630255350e-18 -4.3742379676789617e-17 3.1617699325125632e+00
Mo
2
Cartesian
0.0000000000 0.0000000000 0.0000000000
1.5808849663 1.5808849663 1.5808849663
101 changes: 101 additions & 0 deletions tests/auto_test/test_gamma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import os, sys, json, glob, shutil
import dpdata
import numpy as np
import unittest
import dpdata

from monty.serialization import loadfn, dumpfn
from pymatgen.core.structure import Structure
from pymatgen.core.surface import SlabGenerator
from pymatgen.io.vasp import Incar
from pymatgen.io.ase import AseAtomsAdaptor
from ase.lattice.cubic import BodyCenteredCubic as bcc
from ase.lattice.cubic import FaceCenteredCubic as fcc
from ase.lattice.hexagonal import HexagonalClosedPacked as hcp

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
__package__ = 'auto_test'

from .context import make_kspacing_kpoints
from .context import setUpModule

from dpgen.auto_test.Gamma import Gamma

class TestGamma(unittest.TestCase):

def setUp(self):
_jdata = {
"structures": ["confs/hp-Mo"],
"interaction": {
"type": "vasp",
"incar": "vasp_input/INCAR_Mo",
"potcar_prefix": "vasp_input",
"potcars": {"Mo": "POTCAR_Mo"}
},
"properties": [
{
"type": "gamma",
"lattice_type": "bcc",
"miller_index": [1, 1, 0],
"displace_direction": [1, 1, 1],
"min_supercell_size": [1, 1, 10],
"min_vacuum_size": 10,
"add_fix": ["true", "true", "false"],
"n_steps": 20
}
]
}

self.equi_path = 'confs/hp-Mo/relaxation/relax_task'
self.source_path = 'equi/vasp'
self.target_path = 'confs/hp-Mo/gamma_00'
if not os.path.exists(self.equi_path):
os.makedirs(self.equi_path)
if not os.path.exists(self.target_path):
os.makedirs(self.target_path)

self.confs = _jdata["structures"]
self.inter_param = _jdata["interaction"]
self.prop_param = _jdata['properties']

self.gamma = Gamma(_jdata['properties'][0])

def tearDown(self):
if os.path.exists(self.equi_path):
shutil.rmtree(self.equi_path)
if os.path.exists(self.target_path):
shutil.rmtree(self.target_path)

def test_task_type(self):
self.assertEqual('gamma', self.gamma.task_type())

def test_task_param(self):
self.assertEqual(self.prop_param[0], self.gamma.task_param())

def test_make_confs_bcc(self):
if not os.path.exists(os.path.join(self.equi_path, 'CONTCAR')):
with self.assertRaises(RuntimeError):
self.gamma.make_confs(self.target_path, self.equi_path)
shutil.copy(os.path.join(self.source_path, 'CONTCAR_Mo_bcc'), os.path.join(self.equi_path, 'CONTCAR'))
task_list = self.gamma.make_confs(self.target_path, self.equi_path)
dfm_dirs = glob.glob(os.path.join(self.target_path, 'task.*'))
self.assertEqual(len(dfm_dirs), self.gamma.n_steps+1)

incar0 = Incar.from_file(os.path.join('vasp_input', 'INCAR.rlx'))
incar0['ISIF'] = 4

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)
st1_file = os.path.join(ii, 'POSCAR.tmp')
self.assertTrue(os.path.isfile(st1_file))
st1 = Structure.from_file(st1_file)
with open(st1_file, mode='r') as f:
z_coord_str = f.readlines()[-1].split()[-2]
z_coord = float(z_coord_str)
self.assertTrue(z_coord <= 1)
33 changes: 33 additions & 0 deletions tests/auto_test/vasp_input/INCAR_Mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#Parameters
SYSTEM = Mo_hcp
PREC = Accurate
ISTART = 0
ICHARG = 2
#Electronic Relaxation
ENCUT = 800 # test
NELM = 100
NELMIN = 6
NELMDL = -5
EDIFF = 1e-06 # test
LREAL = False
ALGO = Normal # or normal
#Ionic relaxation
IBRION = 2
#POTIM = 0.3
ISIF = 3
EDIFFG = -0.01 # test
#ISYM = 0
NSW = 100
ISMEAR = 1
SIGMA = 0.1 # test
# Write flags
LWAVE = False
LCHARG = False
#parallel related
#KPAR = 16
NPAR = 4
#KPAR = 1
KSPACING = 0.1 # test
KGAMMA = False

PSTRESS = 0.0
Loading

0 comments on commit 8e1db56

Please sign in to comment.