Hi there,
Is there a convenient way to set the different path_type
, aka, ‘setyawan_curtarolo’, ‘hinuma’, or ‘latimer_munro’ when using RelaxBandStructureMaker?
Regards,
Zhao
Hi there,
Is there a convenient way to set the different path_type
, aka, ‘setyawan_curtarolo’, ‘hinuma’, or ‘latimer_munro’ when using RelaxBandStructureMaker?
Regards,
Zhao
I got it, as shown below:
Method 1:
from atomate2.vasp.flows.core import RelaxBandStructureMaker
from jobflow import Flow
from jobflow_remote import submit_flow
from pymatgen.core import Structure
from atomate2.vasp.powerups import (
update_user_incar_settings,
update_user_potcar_functional,
update_user_kpoints_settings,
)
from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
#https://www.vasp.at/wiki/index.php/NBANDS
def calculate_optimal_nbands(structure, ncores=16):
"""计算最优NBANDS值"""
# 计算总价电子数
nelect = 0
for site in structure:
if site.specie.symbol == "Mg":
nelect += 2 # Mg价电子
elif site.specie.symbol == "O":
nelect += 6 # O价电子
# 可以根据需要添加其他元素
# 计算总离子数
nions = len(structure)
# 根据VASP文档计算NBANDS
nbands_safe = int(nelect/2 + nions)
# 确保NBANDS是核心数的倍数
nbands = ((nbands_safe + ncores - 1) // ncores) * ncores
print(f"总价电子数: {nelect}, 离子数: {nions}, 推荐NBANDS: {nbands}")
return nbands
# 从静态计算中获取结构
#static_dir = "/home/werner/Desktop/std/38/bd/0c/38bd0c24-3463-445d-91e3-a2fb0d72ceca_1"
#vasprun = Vasprun(f"{static_dir}/vasprun.xml")
#structure = vasprun.final_structure
# 创建MgO惯用晶胞
#https://materialsproject.github.io/atomate2/user/running-workflows.html#bandstructure-workflows
#https://next-gen.materialsproject.org/materials/mp-1265
a = 4.19
structure = Structure.from_spacegroup(
225, # Fm-3m
[[a, 0, 0], [0, a, 0], [0, 0, a]],
["Mg", "O"],
[[0, 0, 0], [0.5, 0.5, 0.5]]
)
#Public/repo/github.com/materialsproject/pymatgen/get_primitive_standard_structure-and-k-path_implementation_and_usage.py
analyzer = SpacegroupAnalyzer(structure, symprec=0.01, angle_tolerance=5.0)
primitive = analyzer.get_primitive_standard_structure(international_monoclinic=False)
# 计算最优NBANDS
ncores = 16
nbands = calculate_optimal_nbands(primitive, ncores)
# 创建流并更新NBANDS
maker = RelaxBandStructureMaker()
maker = update_user_incar_settings(maker, {"NBANDS": nbands})
bandstructure_flow = maker.make(primitive,
# prev_dir=static_dir
)
nscf_line_user_kpoints_settings = {
"line_density": 20,
"kpath_kwargs": {
"has_magmoms":True,
"path_type": "latimer_munro" # 关键参数
}
}
# ref:
#Public/repo/github.com/materialsproject/pymatgen/elastic2ieee/reproduce_mp_elastic_constants_atomate2/reproduce-mp-elastic.py
#https://github.com/Neraaz/HTESP/issues/1#issuecomment-2451363600
bandstructure_flow = update_user_kpoints_settings(bandstructure_flow, nscf_line_user_kpoints_settings, name_filter="non-scf line")
jf_flow = Flow(bandstructure_flow, name='MgO_bands')
resources = {
"nodes": 1,
"ntasks_per_node": ncores,
"partition": "batch",
"time": "2400:00:00",
"qout_path": "%j.log"
}
# 提交计算
print(submit_flow(jf_flow, project='std', worker="vasp_slurm", resources=resources))
Method 2:
from atomate2.vasp.flows.core import RelaxBandStructureMaker, BandStructureMaker
from atomate2.vasp.jobs.core import NonSCFMaker
from atomate2.vasp.sets.core import NonSCFSetGenerator
from jobflow import Flow
from jobflow_remote import submit_flow
from pymatgen.core import Structure
from atomate2.vasp.powerups import update_user_incar_settings
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
def calculate_optimal_nbands(structure, ncores=16):
"""计算最优NBANDS值"""
nelect = sum(2 if site.specie.symbol == "Mg" else 6 for site in structure)
nions = len(structure)
nbands_safe = int(nelect/2 + nions)
nbands = ((nbands_safe + ncores - 1) // ncores) * ncores
print(f"总价电子数: {nelect}, 离子数: {nions}, 推荐NBANDS: {nbands}")
return nbands
# 创建MgO结构
a = 4.19
structure = Structure.from_spacegroup(225, [[a,0,0],[0,a,0],[0,0,a]], ["Mg", "O"], [[0,0,0],[0.5,0.5,0.5]])
# 获取原胞
analyzer = SpacegroupAnalyzer(structure, symprec=0.01, angle_tolerance=5.0)
primitive = analyzer.get_primitive_standard_structure(international_monoclinic=False)
# 计算NBANDS
ncores = 16
nbands = calculate_optimal_nbands(primitive, ncores)
# 创建自定义生成器
custom_generator = NonSCFSetGenerator(
user_kpoints_settings={
"line_density": 20,
"kpath_kwargs": {"path_type": "latimer_munro"} # 关键参数
}
)
# 创建maker链(确保BandStructureMaker已导入)
maker = RelaxBandStructureMaker(
band_structure_maker=BandStructureMaker(
bs_maker=NonSCFMaker(input_set_generator=custom_generator)
)
)
# 更新INCAR设置
maker = update_user_incar_settings(maker, {"NBANDS": nbands})
# 创建流程
bandstructure_flow = maker.make(primitive)
jf_flow = Flow(bandstructure_flow, name='MgO_bands')
# 提交计算
resources = {"nodes": 1, "ntasks_per_node": ncores, "partition": "batch", "time": "2400:00:00"}
print(submit_flow(jf_flow, project='std', worker="vasp_slurm", resources=resources))