Skip to content
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

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

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
24 changes: 24 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.10"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: doc/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
formats: all

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: doc/requirements.txt
21 changes: 13 additions & 8 deletions dpgen/auto_test/Interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import re
import numpy as np

from monty.serialization import loadfn, dumpfn
from pymatgen.analysis.defects.generators import InterstitialGenerator
Expand Down Expand Up @@ -147,9 +148,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]]})
ZLI-afk marked this conversation as resolved.
Show resolved Hide resolved
for jj in vds:
temp = jj.generate_defect_structure(self.supercell)
temp = jj.get_supercell_structure(sc_mat=np.diag(self.supercell, k=0))
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 +190,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 +215,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]
ZLI-afk marked this conversation as resolved.
Show resolved Hide resolved
with open('POSCAR', 'w+') as fout:
for ii in pos_line:
print(ii, file=fout)
Expand All @@ -224,7 +229,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 +243,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 +263,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 +279,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 +295,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
6 changes: 4 additions & 2 deletions dpgen/auto_test/Vacancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import re
import numpy as np

from monty.serialization import loadfn, dumpfn
from pymatgen.analysis.defects.generators import VacancyGenerator
Expand Down Expand Up @@ -134,10 +135,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.diag(self.supercell, k=0))

print('gen vacancy with supercell ' + str(self.supercell))
os.chdir(path_to_work)
Expand Down
3 changes: 2 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,7 @@
'dpdispatcher>=0.3.11',
'netCDF4',
'dargs>=0.2.9',
'pymatgen-analysis-defects'
]

setuptools.setup(
Expand Down
8 changes: 4 additions & 4 deletions tests/auto_test/test_interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,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
4 changes: 2 additions & 2 deletions tests/auto_test/test_vacancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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)