pyiron集成开发环境(IDE)的计算材料科学的核心组件
项目描述
pyiron_base
pyiron_base
工作流程管理器为 pyiron 项目提供数据存储和工作流管理。作为 2018 年 pyiron 项目模块化的部分,从 2011 年开始的单体代码库 pyCMW
被拆分为 pyiron_base
和 pyiron_atomistics
。这种拆分突出了 pyiron_base
中的技术复杂性和工作流程管理,以及 pyiron_atomistics
中的原子模拟的物理建模之间的分离。
功能
- 可以在
pyiron_base
中封装的计算可以是简单的 Python 函数或任何编程语言编写的外部可执行文件,从而实现成千上万的计算参数研究。 - 计算可以在同一台计算机上本地执行,也可以在高性能计算 (HPC) 资源上执行。使用 python 简单排队系统适配器 pysqa 直接从 python 接口与 HPC 排队系统,并使用 pympipool 软件包分配专用资源,如多个 CPU 内核和 GPU,到单个 python 函数。
- 使用 层次化数据格式 (HDF) 通过 h5py python 库有效地存储科学数据,特别是通过 h5io 软件包将 python 数据类型与 HDF5 数据类型相匹配。
借助此功能,pyiron_base
工作流程管理器能够快速原型设计和扩展参数研究,适用于广泛的科学应用。从没有 Python 绑定的 Fortran 编写的模拟代码开始,到具有 Python 绑定的更现代的建模代码(用 C 或 C++ 编写),再到需要 GPU 加速的机器学习模型,该方法遵循相同的三个步骤
- 为模拟代码实现包装器,该包装器接受一组输入参数,调用模拟代码,并返回一组输出参数。对于具有 Python 绑定的模拟代码,这可以通过
wrap_python_function()
函数实现,对于需要基于文件通信的任何外部可执行文件,这可以通过需要write_input()
函数和collect_output()
函数(用于解析外部可执行文件的输入和输出文件)的create_job_class()
函数实现。这两个函数都返回一个job
对象。这是pyiron_base
工作流程管理器的核心构建块。 - 遵循map-reduce模式,创建并提交一系列
job
对象到可用的计算资源。当直接在HPC集群的登录节点上执行pyiron_base
工作流管理器时,计算将直接提交到排队系统。或者,pyiron_base
工作流管理器也支持通过安全壳(SSH)连接到HPC集群进行提交。与许多其他工作流管理器不同,pyiron_base
工作流管理器不需要与远程计算资源保持持续连接。一旦提交了job
对象,工作流就可以关闭。 - 最后,在单个
job
对象的执行完成后,pyiron_table
对象将单个job
对象的数据汇总到一个表中。该表作为pandas.DataFrame
提供,因此它兼容大多数机器学习和绘图库,以便进行进一步分析。
示例
pyiron_base
工作流管理器是作为pyiron项目的一部分开发的,因此选择在pyiron_base
工作流管理器中实现量子 espresso密度泛函理论(DFT)模拟代码作为示例。尽管如此,相同的步骤适用于任何类型的模拟代码。
import os
import matplotlib.pyplot as plt
import numpy as np
from ase.build import bulk
from ase.calculators.espresso import Espresso
from ase.io import write
from pwtools import io
def write_input(input_dict, working_directory="."):
filename = os.path.join(working_directory, 'input.pwi')
os.makedirs(working_directory, exist_ok=True)
write(
filename=filename,
images=input_dict["structure"],
Crystal=True,
kpts=input_dict["kpts"],
input_data={"calculation": input_dict["calculation"]},
pseudopotentials=input_dict["pseudopotentials"],
tstress=True,
tprnfor=True
)
def collect_output(working_directory="."):
filename = os.path.join(working_directory, 'output.pwo')
try:
return {"structure": io.read_pw_md(filename)[-1].get_ase_atoms()}
except TypeError:
out = io.read_pw_scf(filename)
return {
"energy": out.etot,
"volume": out.volume,
}
def workflow(project, structure):
# Structure optimization
job_qe_minimize = pr.create.job.QEJob(job_name="qe_relax")
job_qe_minimize.input["calculation"] = "vc-relax"
job_qe_minimize.input.structure = structure
job_qe_minimize.run()
structure_opt = job_qe_minimize.output.structure
# Energy Volume Curve
energy_lst, volume_lst = [], []
for i, strain in enumerate(np.linspace(0.9, 1.1, 5)):
structure_strain = structure_opt.copy()
structure_strain = structure.copy()
structure_strain.set_cell(
structure_strain.cell * strain**(1/3),
scale_atoms=True
)
job_strain = pr.create.job.QEJob(
job_name="job_strain_" + str(i)
)
job_strain.input.structure = structure_strain
job_strain.run(delete_existing_job=True)
energy_lst.append(job_strain.output.energy)
volume_lst.append(job_strain.output.volume)
return {"volume": volume_lst, "energy": energy_lst}
from pyiron_base import Project
pr = Project("test")
pr.create_job_class(
class_name="QEJob",
write_input_funct=write_input,
collect_output_funct=collect_output,
default_input_dict={ # Default Parameter
"structure": None,
"pseudopotentials": {"Al": "Al.pbe-n-kjpaw_psl.1.0.0.UPF"},
"kpts": (3, 3, 3),
"calculation": "scf",
},
executable_str="mpirun -np 1 pw.x -in input.pwi > output.pwo",
)
job_workflow = pr.wrap_python_function(workflow)
job_workflow.input.project = pr
job_workflow.input.structure = bulk('Al', a=4.15, cubic=True)
job_workflow.run()
plt.plot(job_workflow.output.result["volume"], job_workflow.output.result["energy"])
plt.xlabel("Volume")
plt.ylabel("Energy")
在定义量子 espresso DFT模拟代码的write_input()
和collect_output()
函数后,定义了workflow()
函数以组合多个量子 espresso DFT模拟。首先优化结构以识别平衡体积,然后应用从90%到110%的五个应变以确定体积模量。最后,在最后几行中,通过创建基于write_input()
和collect_output()
函数的量子 espresso作业类QEJob
,然后使用wrap_python_function()
包装workflow()
函数,将所有单个部分组合在一起。在调用run()
函数时执行整个工作流。之后,使用matplotlib
库绘制结果。
免责声明
虽然我们试图开发一个稳定可靠的软件库,但该项目仍是一个无任何保证的开源项目,遵循BSD 3-Clause许可证。
BSD 3-Clause License
Copyright (c) 2018, Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
文档
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。