Esempio n. 1
0
    def plot_ads_sites(self, filename='ads_sites.png', size=(3, 3)):

        fig = plt.figure()
        plt.axis('off')
        fig.set_size_inches(size[0], size[1])
        ax = fig.add_subplot(111)
        plot_slab(self.blank_slab_pym, ax, adsorption_sites=True)
        plt.savefig(filename, dpi=300, bbox_inches='tight')
Esempio n. 2
0
    def sol(self,
            EB_K_2,
            miller_index_2,
            min_slab_size_2=8.0,
            min_vacuum_size_2=15):
        from pymatgen.analysis.adsorption import AdsorbateSiteFinder, plot_slab, reorient_z
        from pymatgen.core.surface import Slab, SlabGenerator, generate_all_slabs, Structure, Lattice, ReconstructionGenerator
        from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
        from pymatgen.core.structure import Structure
        from pymatgen.ext.matproj import MPRester
        from matplotlib import pyplot as plt
        from pymatgen.io.vasp.inputs import Poscar
        from pymatgen.io.vasp.sets import MVLSlabSet
        import shutil
        import os
        mpr = MPRester()  #密钥

        mp_id = self.mp_id  #通过mp_id来索引结构
        struct = mpr.get_structure_by_material_id(mp_id)
        #获取结构信息
        struct = SpacegroupAnalyzer(
            struct).get_conventional_standard_structure()
        #空间群分析
        need_miller_index = miller_index_2  #通过米勒指数,确定要切的晶面

        slab = SlabGenerator(struct, miller_index=need_miller_index, min_slab_size=min_slab_size_2,\
                             min_vacuum_size=min_vacuum_size_2, center_slab=True)
        #晶面生成器参数

        for n, slabs in enumerate(slab.get_slabs()):
            slabs_bak = slabs.copy()  #可能的晶面
            slabs.make_supercell(self.supercell)
            #晶胞扩充

            A = Poscar(slabs)  #将切面转换为Poscar
            relax = A.structure  #将Poscar 转换为结构信息
            custom_settings = {"NPAR": 4}  # 用户的INCAR 设置
            relax = MVLSlabSet(relax, user_incar_settings=custom_settings)
            #Vasp输入文件生成器

            fig = plt.figure()  #绘图--确立画布
            ax = fig.add_subplot(111)  #绘图--确立位置
            plot_slab(slabs, ax, adsorption_sites=False)  #绘图
            dire = str(mp_id) + "---" + "sol" + str(EB_K_2) + str(
                need_miller_index) + '----' + str(n)
            #设置一个用作存储输入文件的名称
            plt.savefig(dire)  #将该名称用于保存图片
            relax.write_input(dire)  #将生成的VASP输入文件写入存储

            os.chdir("./" + dire)
            #定义一个更改当前目录的变量
            dire2 = './vaspstd_sub'
            #确立脚本名称
            shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2)
            #将脚本写入VASP输入文件所在文件夹

            eb = str(EB_K_2)
            ls = str('TURE')
            with open('INCAR', 'a') as file_object:
                file_object.write('LSOL = ' + ls + '\n' + 'EB_K = ' + eb)

            # os.chdir("../")
            #将当前目录改为默认目录
            os.chdir(r"D:\Desktop\VASP practical\workdir")
            print(os.getcwd())
            print('finished')
Esempio n. 3
0
    def fix_absorbed(self,
                     need_miller_index,
                     mole,
                     num,
                     selective_dynamic,
                     min_slab_size_1=8.0,
                     min_vacuum_size_1=15,
                     judge='fuchdi',
                     appendage=""):
        from pymatgen import Structure, Lattice, MPRester, Molecule
        import pymatgen.core.structure

        import pymatgen.core.sites
        from pymatgen.analysis.adsorption import AdsorbateSiteFinder, reorient_z, plot_slab
        from pymatgen.core.surface import generate_all_slabs
        from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
        from matplotlib import pyplot as plt
        from pymatgen.ext.matproj import MPRester
        from pymatgen.io.vasp.inputs import Poscar
        from pymatgen.io.vasp.sets import MVLSlabSet
        from pymatgen.io.cif import CifWriter
        import os
        import shutil
        from openbabel import openbabel
        from pymatgen.core.surface import Slab, SlabGenerator, generate_all_slabs, Structure, Lattice, ReconstructionGenerator
        mp_id = self.mp_id
        os.chdir(r"F:\VASP practical\Input")
        print(os.getcwd())

        # Note that you must provide your own API Key, which can
        # be accessed via the Dashboard at materialsproject.org
        mpr = MPRester()
        struct = mpr.get_structure_by_material_id(mp_id)
        struct = SpacegroupAnalyzer(
            struct).get_conventional_standard_structure()
        # fcc_ni = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni", "Ni"],
        # [[0, 0, 0], [0.5, 0.5, 0.5]])
        slab = SlabGenerator(struct,
                             miller_index=need_miller_index,
                             min_slab_size=min_slab_size_1,
                             min_vacuum_size=min_vacuum_size_1,
                             center_slab=True)

        for n, slabs in enumerate(slab.get_slabs()):
            if str(n) in str(num):
                slabs_bak = slabs.copy()  #可能的晶面
                slabs.make_supercell(self.supercell)
                print(n)
                #晶胞扩充

                asf_ni_111 = AdsorbateSiteFinder(
                    slabs, selective_dynamics=selective_dynamic)
                ads_sites = asf_ni_111.find_adsorption_sites()

                # print(ads_sites)
                assert len(ads_sites) == 4

                fig0 = plt.figure()
                ax = fig0.add_subplot(111)
                plot_slab(slabs, ax, adsorption_sites=False)

                fig1 = plt.figure()
                ax = fig1.add_subplot(111)
                os.chdir(r"D:\Desktop\VASP practical\Cif library")
                print(os.getcwd())
                obConversion = openbabel.OBConversion()
                obConversion.SetInAndOutFormats("pdb", "gjf")
                mol = openbabel.OBMol()
                print(mol)
                c = obConversion.ReadFile(mol, "CH3OH.pdb")
                obConversion.WriteFile(mol, "CH3OH.pdb" + '1.gjf')
                adsorbate = Molecule.from_file("CH3OH.pdb" + '.gjf')
                os.chdir(r"F:\VASP practical\Input")
                print(os.getcwd())

                print(adsorbate.sites)
                ads_structs = asf_ni_111.add_adsorbate(
                    adsorbate,
                    (20, 20, 20),
                    translate=False,
                )
                # ads_structs = asf_ni_111.generate_adsorption_structures(adsorbate,
                # repeat=[1, 1, 1])
                # A = Poscar(ads_structs[0])
                A = Poscar(reorient_z(ads_structs))  #将切面转换为Poscar
                open('POSCAR', 'w').write(str(A))
                p = Poscar.from_file('POSCAR')
                # w = CifWriter(A.struct)
                # w.write_file('mystructure.cif')
                path = r'F:\VASP practical\Input\POSCAR'  # 文件路径
                if os.path.exists(path):  # 如果文件存在
                    # 删除文件,可使用以下两种方法。
                    os.remove(path)
                #os.unlink(path)
                else:
                    print('no such file:%s' % my_file)  # 则返回文件不存在
                # w = CifWriter(A.struct)
                # w.write_file('mystructure.cif')

                relax = p.structure  #将Poscar 转换为结构信息
                custom_settings = {"NPAR": 4}  # 用户的INCAR 设置
                relaxs = MVLSlabSet(relax, user_incar_settings=custom_settings)
                # Vasp输入文件生成器
                dire = str(mp_id) + str(selective_dynamic) + str(mole) + str(
                    need_miller_index).replace(" ", "") + str(n)
                # print (relax)
                relaxs.write_input(dire)
                os.chdir("./" + dire)
                print(os.getcwd())
                fig0.savefig('slab.png',
                             bbox_inches='tight',
                             transparent=True,
                             dpi=600,
                             format='png')
                plot_slab(ads_structs, ax, adsorption_sites=False, decay=0.09)
                fig1.savefig('slab_adsobate.png',
                             bbox_inches='tight',
                             transparent=True,
                             dpi=600,
                             format='png')
                #定义一个更改当前目录的变量
                dire2 = './vaspstd_sub'
                #确立脚本名称
                shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2)

                eb = appendage  #添加其他INCAR参数

                with open('INCAR', 'r') as f1:
                    lines = f1.readlines()

                with open('INCAR', 'w') as f2:
                    for line in lines:
                        if judge in line:
                            continue
                        f2.write(line)

                with open('INCAR', 'a') as f3:
                    f3.write(eb)

                # open('POSCAR001', 'w').write(str(Poscar(reorient_z(ads_structs[0]))))

                os.chdir(r"D:\Desktop\VASP practical\workdir")
                print(os.getcwd())
                print('finished')


# my_lattace = Lattace('mp-698074')#半水石膏
# # my_lattace.phase_out()#生成晶胞优化的输入文件
# go = my_lattace.phase_sol(66,judge='LWAVE',  appendage= '\nLWAVE = Ture')
# print('yoo')
Esempio n. 4
0
    def slab(self, miller_index_1, min_slab_size_1=8.0, min_vacuum_size_1=15):

        from pymatgen.analysis.adsorption import AdsorbateSiteFinder, plot_slab, reorient_z
        from pymatgen.core.surface import Slab, SlabGenerator, generate_all_slabs, Structure, Lattice, ReconstructionGenerator
        from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
        from pymatgen.core.structure import Structure
        from pymatgen.ext.matproj import MPRester
        from matplotlib import pyplot as plt
        from pymatgen.io.vasp.inputs import Poscar
        from pymatgen.io.vasp.sets import MVLSlabSet
        import shutil
        import os
        mpr = MPRester()  #密钥

        mp_id = self.mp_id  #通过mp_id来索引结构
        struct = mpr.get_structure_by_material_id(mp_id)
        #获取结构信息
        struct = SpacegroupAnalyzer(
            struct).get_conventional_standard_structure()
        #空间群分析
        need_miller_index = miller_index_1  #通过米勒指数,确定要切的晶面

        slab = SlabGenerator(struct, miller_index=need_miller_index, min_slab_size=min_slab_size_1,\
                             min_vacuum_size=min_vacuum_size_1, center_slab=True)
        #晶面生成器参数
        gh = str(miller_index_1).replace(" ", "")
        for n, slabs in enumerate(slab.get_slabs()):
            slabs_bak = slabs.copy()  #可能的晶面
            slabs.make_supercell(self.supercell)
            #晶胞扩充
            cc = slabs.surface_area
            os.chdir(r"F:\VASP practical\Input")
            print(os.getcwd())
            print(n)

            A = Poscar(slabs)  #将切面转换为Poscar
            relax = A.structure  #将Poscar 转换为结构信息
            custom_settings = {"NPAR": 4}  # 用户的INCAR 设置
            relax = MVLSlabSet(relax, user_incar_settings=custom_settings)
            #Vasp输入文件生成器

            fig = plt.figure()  #绘图--确立画布
            ax = fig.add_subplot(111)  #绘图--确立位置
            plot_slab(slabs, ax, adsorption_sites=False)  #绘图
            dire = str(mp_id) + "---" + str(gh) + '----' + str(n)

            #设置一个用作存储输入文件的名称
            plt.show()
            # plt.savefig(dire)#将该名称用于保存图片
            relax.write_input(str(gh) + '--' + str(n))  #将生成的VASP输入文件写入存储
            dire_1 = str(gh) + '--' + str(n)

            diree = os.chdir("./" + dire_1)
            fig.savefig('slab.png',
                        bbox_inches='tight',
                        transparent=True,
                        dpi=600,
                        format='png')
            #定义一个更改当前目录的变量
            dire2 = './vaspstd_sub'
            #确立脚本名称
            shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2)
            #将脚本写入VASP输入文件所在文件夹
            with open('surface_area', 'w') as f:
                f.write(str(cc))
            print(cc)
        # os.chdir("../")
        #将当前目录改为默认目录

        os.chdir(r"D:\Desktop\VASP practical\workdir")
        print(os.getcwd())
        print('finished')
Esempio n. 5
0
print(Cu_111.miller_index, Cu_111.shift)

# ### Gerando Imagem da Estrutura e do Plano

# In[22]:

from pymatgen.analysis.adsorption import plot_slab
from matplotlib import pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')

# In[23]:

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
plot_slab(Cu_111, ax, adsorption_sites=False)
ax.set_title("Cu (1, 1, 1) surface")
ax.set_xticks([])
ax.set_yticks([])
plt.show()

# ### Verificando os locais de adsorção no plano e entre as camadas

# In[24]:

from pymatgen.analysis.adsorption import AdsorbateSiteFinder

# In[25]:

asf = AdsorbateSiteFinder(Cu_111)
Esempio n. 6
0
    def absorbed(self,
                 millerindex_1,
                 absorbate_1,
                 absorba,
                 judge='',
                 appendage=""):

        from pymatgen import Structure, Lattice, MPRester, Molecule
        import pymatgen.core.structure

        import pymatgen.core.sites
        from pymatgen.analysis.adsorption import AdsorbateSiteFinder, reorient_z, plot_slab
        from pymatgen.core.surface import generate_all_slabs
        from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
        from matplotlib import pyplot as plt
        from pymatgen.io.cif import CifParser
        from pymatgen.io.vasp.inputs import Poscar
        from pymatgen.io.vasp.sets import MVLSlabSet
        from pymatgen.io.cif import CifWriter
        import os
        import shutil

        ass = self.cif_route
        print(ass)
        # os.chdir(r"E:\VASP practical\Input")
        # print (os.getcwd())

        # Note that you must provide your own API Key, which can
        # be accessed via the Dashboard at materialsproject.org
        #mpr = MPRester()#密钥
        struct = CifParser(ass)
        structure = struct.get_structures()[0]
        print(structure)

        os.chdir(r"E:\VASP practical\Input")
        print(os.getcwd())
        # fcc_ni = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni", "Ni"],
        # [[0, 0, 0], [0.5, 0.5, 0.5]])
        slabs = generate_all_slabs(structure,
                                   max_index=1,
                                   min_slab_size=8.0,
                                   min_vacuum_size=10.0)

        millerindex = millerindex_1
        struct_111 = [
            slab for slab in slabs if slab.miller_index == millerindex_1
        ][0]

        asf_ni_111 = AdsorbateSiteFinder(struct_111)
        ads_sites = asf_ni_111.find_adsorption_sites()

        # print(ads_sites)
        assert len(ads_sites) == 4

        fig = plt.figure()
        ax = fig.add_subplot(111)
        plot_slab(struct_111, ax, adsorption_sites=True)

        fig = plt.figure()
        ax = fig.add_subplot(111)

        adsorbate = Molecule(absorbate_1, absorba)
        ads_structs = asf_ni_111.generate_adsorption_structures(
            adsorbate, repeat=[1, 1, 1])
        A = Poscar(reorient_z(ads_structs[0]))  #将切面转换为Poscar
        open('POSCAR', 'w').write(str(A))
        p = Poscar.from_file('POSCAR')
        # w = CifWriter(A.struct)
        # w.write_file('mystructure.cif')
        path = r'E:\VASP practical\Input\POSCAR'  # 文件路径
        if os.path.exists(path):  # 如果文件存在
            # 删除文件,可使用以下两种方法。
            os.remove(path)
        #os.unlink(path)
        else:
            print('no such file:%s' % my_file)  # 则返回文件不存在
        # w = CifWriter(A.struct)
        # w.write_file('mystructure.cif')

        relax = p.structure  #将Poscar 转换为结构信息
        custom_settings = {"NPAR": 4}  # 用户的INCAR 设置
        relaxs = MVLSlabSet(relax, user_incar_settings=custom_settings)
        # Vasp输入文件生成器
        dire = str(ass) + "---" + str(absorbate_1) + str(millerindex_1)
        # print (relax)
        relaxs.write_input(dire)
        os.chdir("./" + dire)
        print(os.getcwd())
        #定义一个更改当前目录的变量
        dire2 = './vaspstd_sub'
        #确立脚本名称
        shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2)

        eb = appendage  #添加其他INCAR参数

        with open('INCAR', 'r') as f1:
            lines = f1.readlines()

        with open('INCAR', 'w') as f2:
            for line in lines:
                if judge in line:
                    continue
                f2.write(line)

        with open('INCAR', 'a') as f3:
            f3.write(eb)

        plot_slab(ads_structs[0], ax, adsorption_sites=False, decay=0.09)
        # open('POSCAR001', 'w').write(str(Poscar(reorient_z(ads_structs[0]))))

        os.chdir(r"D:\Desktop\VASP practical\workdir")
        print(os.getcwd())
        print('finished')


# my_lattace = Lattace('mp-698074')#半水石膏
# # my_lattace.phase_out()#生成晶胞优化的输入文件
# go = my_lattace.phase_sol(66,judge='LWAVE',  appendage= '\nLWAVE = Ture')
# print('yoo')
Esempio n. 7
0
    def slab(self, miller_index_1, min_slab_size_1=8.0, min_vacuum_size_1=15):

        from pymatgen.analysis.adsorption import AdsorbateSiteFinder, plot_slab, reorient_z
        from pymatgen.core.surface import Slab, SlabGenerator, generate_all_slabs, Structure, Lattice, ReconstructionGenerator
        from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
        from pymatgen.core.structure import Structure
        from pymatgen.io.cif import CifParser
        from matplotlib import pyplot as plt
        from pymatgen.io.vasp.inputs import Poscar
        from pymatgen.io.vasp.sets import MVLSlabSet
        import shutil
        import os
        ##mpr = MPRester()#密钥#密钥

        ass = self.cif_route
        print(ass)
        # os.chdir(r"E:\VASP practical\Input")
        # print (os.getcwd())

        # Note that you must provide your own API Key, which can
        # be accessed via the Dashboard at materialsproject.org
        #mpr = MPRester()#密钥
        struct = CifParser(ass)
        structure = struct.get_structures()[0]
        print(structure)
        os.chdir(r"E:\VASP practical\Input")
        print(os.getcwd())

        structure = SpacegroupAnalyzer(
            structure).get_conventional_standard_structure()
        #空间群分析
        need_miller_index = miller_index_1  #通过米勒指数,确定要切的晶面

        slab = SlabGenerator(structure, miller_index=need_miller_index, min_slab_size=min_slab_size_1,\
                             min_vacuum_size=min_vacuum_size_1, center_slab=True)
        #晶面生成器参数

        for n, slabs in enumerate(slab.get_slabs()):
            slabs_bak = slabs.copy()  #可能的晶面
            slabs.make_supercell(self.supercell)
            #晶胞扩充

            A = Poscar(slabs)  #将切面转换为Poscar
            relax = A.structure  #将Poscar 转换为结构信息
            custom_settings = {"NPAR": 4}  # 用户的INCAR 设置
            relax = MVLSlabSet(relax, user_incar_settings=custom_settings)
            #Vasp输入文件生成器

            fig = plt.figure()  #绘图--确立画布
            ax = fig.add_subplot(111)  #绘图--确立位置
            plot_slab(slabs, ax, adsorption_sites=False)  #绘图
            dire = str(ass) + "---" + str(need_miller_index) + '----' + str(n)
            #设置一个用作存储输入文件的名称
            relax.write_input(dire)  #将生成的VASP输入文件写入存储
            os.chdir(r"E:\VASP practical\Input")
            print(os.getcwd())

            plt.savefig('002', format='png')  #将该名称用于保存图片

        os.chdir("./" + dire)
        #定义一个更改当前目录的变量
        dire2 = './vaspstd_sub'
        #确立脚本名称
        shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2)
        #将脚本写入VASP输入文件所在文件夹

        # os.chdir("../")
        #将当前目录改为默认目录
        os.chdir(r"D:\Desktop\VASP practical\workdir")
        print(os.getcwd())
        print('finished')