Skip to content

Fix incompatibility of autotest module with latest pymatgen>2022.7.19 #963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 6, 2022
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
PYMATGEN_VERSION: [2019.1.13, 2019.7.30]
python-version: [3.8, 3.9]
PYMATGEN_VERSION: [2022.7.19]

steps:
- uses: actions/checkout@v2
Expand Down
28 changes: 20 additions & 8 deletions dpgen/auto_test/Interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
import json
import os
import re
import numpy as np

from monty.serialization import loadfn, dumpfn
from pymatgen.analysis.defects.generators import InterstitialGenerator
try:
from pymatgen.analysis.defects.generators import InterstitialGenerator
except ModuleNotFoundError:
print("pymatgen==2022.7.19 is the final release with `pymatgen.analysis.defects` module. Please check the version of pymatgen.")
print("Please install `pymatgen-analysis-defects`.")
print("Kindly reminder: `pybind11>=2.4` need to be installed previously.")
os._exit(0)
from pymatgen.core.structure import Structure

import dpgen.auto_test.lib.lammps as lammps
Expand Down Expand Up @@ -147,9 +155,10 @@ def make_confs(self,
os.remove(insert_element_task)

for ii in self.insert_ele:
vds = InterstitialGenerator(ss, ii)
pre_vds = InterstitialGenerator()
vds = pre_vds.generate(ss, {self.insert_ele[0]: [[0, 0.2, 0.5]]})
for jj in vds:
temp = jj.generate_defect_structure(self.supercell)
temp = jj.get_supercell_structure(sc_mat=np.eye(3) * self.supercell)
smallest_distance = list(set(temp.distance_matrix.ravel()))[1]
if 'conf_filters' in self.parameter and 'min_dist' in self.parameter['conf_filters']:
min_dist = self.parameter['conf_filters']['min_dist']
Expand Down Expand Up @@ -188,6 +197,9 @@ def make_confs(self,


if 'bcc_self' in self.parameter and self.parameter['bcc_self']:
super_size = self.supercell[0] * self.supercell[1] * self.supercell[2]
num_atom = super_size * 2
chl = -num_atom - 2
os.chdir(path_to_work)
with open('POSCAR', 'r') as fin:
fin.readline()
Expand All @@ -210,7 +222,7 @@ def make_confs(self,
with open(insert_element_task, 'a+') as fout:
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, 'supercell.json')
pos_line[-2] = '%.6f' % float(latt_param/4/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' 0.000000 ' + self.insert_ele[0]
pos_line[chl] = '%.6f' % float(latt_param/4/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' 0.000000 ' + self.insert_ele[0]
with open('POSCAR', 'w+') as fout:
for ii in pos_line:
print(ii, file=fout)
Expand All @@ -224,7 +236,7 @@ def make_confs(self,
with open(insert_element_task, 'a+') as fout:
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, 'supercell.json')
pos_line[-2] = '%.6f' % float(latt_param/2/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' 0.000000 ' + self.insert_ele[0]
pos_line[chl] = '%.6f' % float(latt_param/2/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' 0.000000 ' + self.insert_ele[0]
with open('POSCAR', 'w+') as fout:
for ii in pos_line:
print(ii, file=fout)
Expand All @@ -238,7 +250,7 @@ def make_confs(self,
with open(insert_element_task, 'a+') as fout:
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, 'supercell.json')
pos_line[-2] = '%.6f' % float(latt_param/4/super_latt_param) + ' ' + '%.6f' % float(latt_param/4/super_latt_param) + ' ' + '%.6f' % float(latt_param/4/super_latt_param) + ' ' + self.insert_ele[0]
pos_line[chl] = '%.6f' % float(latt_param/4/super_latt_param) + ' ' + '%.6f' % float(latt_param/4/super_latt_param) + ' ' + '%.6f' % float(latt_param/4/super_latt_param) + ' ' + self.insert_ele[0]
with open('POSCAR', 'w+') as fout:
for ii in pos_line:
print(ii, file=fout)
Expand All @@ -258,7 +270,7 @@ def make_confs(self,
with open(insert_element_task, 'a+') as fout:
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, 'supercell.json')
pos_line[-2] = '%.6f' % float(latt_param/3/super_latt_param) + ' ' + '%.6f' % float(latt_param/3/super_latt_param) + ' ' + '%.6f' % float(latt_param/3/super_latt_param) + ' ' + self.insert_ele[0]
pos_line[chl] = '%.6f' % float(latt_param/3/super_latt_param) + ' ' + '%.6f' % float(latt_param/3/super_latt_param) + ' ' + '%.6f' % float(latt_param/3/super_latt_param) + ' ' + self.insert_ele[0]
pos_line[replace_label] = '%.6f' % float(latt_param/3*2/super_latt_param) + ' ' + '%.6f' % float(latt_param/3*2/super_latt_param) + ' ' + '%.6f' % float(latt_param/3*2/super_latt_param) + ' ' + self.insert_ele[0]

with open('POSCAR', 'w+') as fout:
Expand All @@ -274,7 +286,7 @@ def make_confs(self,
with open(insert_element_task, 'a+') as fout:
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, 'supercell.json')
pos_line[-2] = '%.6f' % float((latt_param+2.1/2**0.5)/2/super_latt_param) + ' ' + '%.6f' % float((latt_param-2.1/2**0.5)/2/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' ' + self.insert_ele[0]
pos_line[chl] = '%.6f' % float((latt_param+2.1/2**0.5)/2/super_latt_param) + ' ' + '%.6f' % float((latt_param-2.1/2**0.5)/2/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' ' + self.insert_ele[0]
pos_line[replace_label] = '%.6f' % float((latt_param-2.1/2**0.5)/2/super_latt_param) + ' ' + '%.6f' % float((latt_param+2.1/2**0.5)/2/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' ' + self.insert_ele[0]

with open('POSCAR', 'w+') as fout:
Expand All @@ -290,7 +302,7 @@ def make_confs(self,
with open(insert_element_task, 'a+') as fout:
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, 'supercell.json')
pos_line[-2] = '%.6f' % float(latt_param/2/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' ' + '%.6f' % float((latt_param-2.1)/2/super_latt_param) + ' ' + self.insert_ele[0]
pos_line[chl] = '%.6f' % float(latt_param/2/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' ' + '%.6f' % float((latt_param-2.1)/2/super_latt_param) + ' ' + self.insert_ele[0]
pos_line[replace_label] = '%.6f' % float(latt_param/2/super_latt_param) + ' ' + '%.6f' % float(latt_param/2/super_latt_param) + ' ' + '%.6f' % float((latt_param+2.1)/2/super_latt_param) + ' ' + self.insert_ele[0]

with open('POSCAR', 'w+') as fout:
Expand Down
14 changes: 11 additions & 3 deletions dpgen/auto_test/Vacancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
import json
import os
import re
import numpy as np

from monty.serialization import loadfn, dumpfn
from pymatgen.analysis.defects.generators import VacancyGenerator
try:
from pymatgen.analysis.defects.generators import VacancyGenerator
except ModuleNotFoundError:
print("pymatgen==2022.7.19 is the final release with `pymatgen.analysis.defects` module. Please check the version of pymatgen.")
print("Please install `pymatgen-analysis-defects`.")
print("Kindly reminder: `pybind11>=2.4` need to be installed previously.")
os._exit(0)
from pymatgen.core.structure import Structure

from dpgen import dlog
Expand Down Expand Up @@ -134,10 +141,11 @@ def make_confs(self,
else:
ss = Structure.from_file(equi_contcar)

vds = VacancyGenerator(ss)
pre_vds = VacancyGenerator()
vds = pre_vds.generate(ss)
dss = []
for jj in vds:
dss.append(jj.generate_defect_structure(self.supercell))
dss.append(jj.get_supercell_structure(sc_mat=np.eye(3)*self.supercell))

print('gen vacancy with supercell ' + str(self.supercell))
os.chdir(path_to_work)
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
install_requires=[
'numpy>=1.14.3',
'dpdata>=0.2.6',
'pymatgen>=2019.1.13',
'pymatgen>=2022.7.19',
'ase',
'monty>2.0.0',
'paramiko',
Expand All @@ -29,6 +29,8 @@
'dpdispatcher>=0.3.11',
'netCDF4',
'dargs>=0.2.9',
'pybind11>=2.4',
'pymatgen-analysis-defects'
]

setuptools.setup(
Expand Down
16 changes: 11 additions & 5 deletions tests/auto_test/test_interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from pymatgen.core import Structure
from pymatgen.io.vasp import Incar
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.analysis.defects.core import Interstitial as pmg_Interstitial
try:
from pymatgen.analysis.defects.core import Interstitial as pmg_Interstitial
except ModuleNotFoundError:
print("pymatgen==2022.7.19 is the final release with `pymatgen.analysis.defects` module. Please check the version of pymatgen.")
print("Please install `pymatgen-analysis-defects`.")
print("Kindly reminder: `pybind11>=2.4` need to be installed previously.")
os._exit(0)

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
__package__ = 'auto_test'
Expand Down Expand Up @@ -85,16 +91,16 @@ def test_make_confs_bcc(self):
st_file = os.path.join(ii, 'POSCAR')
self.assertTrue(os.path.isfile(st_file))
st0 = Structure.from_file(st_file)
inter_site = st0[-1]
inter = pmg_Interstitial(ref_st, inter_site, charge=0.0)
st1 = inter.generate_defect_structure(self.prop_param[0]['supercell'])
inter_site = st0[0]
inter = pmg_Interstitial(ref_st, inter_site)
st1 = inter.get_supercell_structure(sc_mat=np.eye(3)*self.prop_param[0]['supercell'])
self.assertEqual(st0, st1)

for ii in dfm_dirs[4:]:
st_file = os.path.join(ii, 'POSCAR')
self.assertTrue(os.path.isfile(st_file))
st0 = Structure.from_file(st_file)
inter_site1 = st0.pop(-1)
inter_site1 = st0.pop(0)
inter_site2 = st0.pop(-1)
center = (inter_site1.coords + inter_site2.coords) / 2
self.assertTrue((center[0] - center[1]) < 1e-4)
Expand Down
11 changes: 9 additions & 2 deletions tests/auto_test/test_vacancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
from pymatgen.io.vasp import Incar
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.analysis.defects.core import Vacancy as pmg_Vacancy
try:
from pymatgen.analysis.defects.core import Vacancy as pmg_Vacancy
except ModuleNotFoundError:
print("pymatgen==2022.7.19 is the final release with `pymatgen.analysis.defects` module. Please check the version of pymatgen.")
print("Please install `pymatgen-analysis-defects`.")
print("Kindly reminder: `pybind11>=2.4` need to be installed previously.")
os._exit(0)

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
__package__ = 'auto_test'
Expand Down Expand Up @@ -85,6 +92,6 @@ def test_make_confs_0(self):
self.assertTrue(os.path.isfile(st_file))
st0 = Structure.from_file(st_file)
vac_site = equiv_site_seq.pop(0)
vac = pmg_Vacancy(ref_st, vac_site[0], charge=0.0)
st1 = vac.generate_defect_structure(self.prop_param[0]['supercell'])
vac = pmg_Vacancy(ref_st, vac_site[0])
st1 = vac.get_supercell_structure(sc_mat=np.eye(3)*self.prop_param[0]['supercell'])
self.assertEqual(st0, st1)