pymatgen 使用 介绍
用于表示 Element、Site、Structure、Molecule 的高度灵活的类
文件输入/输出支持广泛,如 VASP、ABINIT、CIF、Gaussian、XYZ 等(主要依靠 Open Babel 包)
强大的分析工具,包括生成相图、Pourbaix 图、扩散分析、反应等
电子结构分析,如态密度和能带结构
集成 Materials Project REST API、Crystallography Open Database 等其他外部数据源
代码文档详细
参考资料
安装
1 2 3 4 pip install -U pymatgen pip install -U git+https://github.com/materialsproject/pymatgen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 from pymatgen import IMolecule, IStructure, Molecule, Structurefrom pymatgen import PeriodicSite, Sitefrom pymatgen import Compositionfrom pymatgen import Latticefrom pymatgen import DummySpecie, DummySpecies, Element, Specie, Speciesfrom pymatgen import SymmOpfrom pymatgen import ArrayWithUnit, FloatWithUnit, Unitfrom pymatgen import Orbital, Spinfrom pymatgen import MPResterfrom pymatgen.core.structure ...from pymatgen.core.sites ...from pymatgen.core.composition import Compositionfrom pymatgen.core.lattice import Latticefrom pymatgen.core.periodic_table ...from pymatgen.core.operations import SymmOpfrom pymatgen.core.units ...from pymatgen.electronic_structure.core ...from pymatgen.ext.matproj ...from pymatgen.core import Structure, Composition ...
使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import pymatgen.coreimport syssys.version pymatgen.core.__version__ pymatgen.core.__file__ from pymatgen.core import SETTINGSPMG_VASP_PSP_DIR = SETTINGS.get("PMG_VASP_PSP_DIR" ) from monty.os.path import zpathpath = ... path = zpath(path)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 FileFormats = Literal [ "cif" , "poscar" , "cssr" , "json" , "yaml" , "yml" , "xsf" , "mcsqs" , "res" , "pwmat" , "aims" , "" , ]
1 FUNCTIONAL_CHOICES= ['PBE' , 'PBE_52' , 'PBE_54' , 'LDA' , 'LDA_52' , 'LDA_54' , 'PW91' , 'LDA_US' , 'PW91_US' , 'Perdew-Zunger81' ]
MP 晶体 DFT code 用的是 VASP,分子用的是 Q-Chem
MSONable
类:MSON(Monty JSON);MSONable 对象必须实现 as_dict()
方法,该方法须返回可序列化为 JSON 的字典,且须支持无参数。静态方法 from_dict()
,从 as_dict()
方法生成的字典中重建对象。as_dict()
方法应该包含 @module
和 @class
键,这将允许 MontyEncoder 动态反序列化该类。
monty 包:对 json/yaml/msgpack 等文件格式进行 serialization
1 from monty.serialization import loadfn, dumpfn
工作流 pymatgen 典型工作流
CLI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 pmg subcommand -h pmg analyze . pmg structure -s 0.00001 -f POSCAR pmg structure --convert --filenames POSCAR *.cif pmg view POSCAR
pymatgen 的 cli 可以使用 argcomplete 库(pyamtgen/cli/pmg.py
;用于 cli 命令的补全)
1 2 3 4 5 6 7 try : import argcomplete argcomplete.autocomplete(parser) except ImportError: pass
操作 structure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 from pymatgen.core.composition import Compositionfrom pymatgen.core.lattice import Latticefrom pymatgen.core.structure import Structurefrom pymatgen.symmetry.analyzer import SpacegroupAnalyzerstructure = Structure( Lattice.cubic(4.2 ), ["Cs" , "Cl" ], [[0 , 0 , 0 ], [0.5 , 0.5 , 0.5 ]], ) structure = Structure.from_spacegroup( "Fm-3m" , Lattice.cubic(3 ), ["Li" , "O" ], [[0.25 , 0.25 , 0.25 ], [0 , 0 , 0 ]], ) structure.to(filename="POSCAR" , fmt="poscar" ) structure.to(fmt="poscar" ) structure.to(filename="POSCAR" ) structure.to(filename="CsCl.cif" ) structure = Structure.from_str(open ("CsCl.cif" ).read(), fmt="cif" ) structure = Structure.from_file("CsCl.cif" ) structure[1 ] = "F" structure[1 ] = "Cl" , [0.51 , 0.51 , 0.51 ] structure["Cs" ] = "K" structure["K" ] = "K0.5Na0.5" structure.reverse() structure.append("F" , [0.9 , 0.9 , 0.9 ]) structure * 2 structure * (2 , 2 , 2 ) structure.make_supercell([2 , 2 , 2 ])
pymatgen 的许多类都有 as_dict()
方法和 from_dict()
静态方法的实现。虽然 python 确实提供了 pickling 功能(实现对象序列化和反序列化的方式),但 pickle 在代码修改方面往往是非常脆弱的。as_dict()
提供了一种以更稳健的方式保存工作的方法,且更容易阅读。将 object 输入某些数据库,如 MongoDB,也特别有用。as_dict()
规范是由 monty 库(pymatgen 产生的一个通用 python 补充库)提供的。
1 2 with open ('structure.json' , 'w' ) as file: json.dump(structure.as_dict(), file)
1 2 3 with open ('structure.json' ) as file: dct = json.load(file) structure = Structure.from_dict(dct)
可使用 PyYAML 包的 yaml 代替上述任何 json 命令来创建 yaml 文件(JSON 格式效率高,读写速度快,但可读性差;YAML 解析速度慢,但更适合人类阅读)
更精细地控制从文件读取解析结构,可以使用特定的 io 包。这些包也提供了导出文件格式的方法。
1 2 3 4 from pymatgen.io.cif import CifParserparser = CifParser("mycif.cif" ) structure = parser.get_structures()[0 ]
1 2 3 4 from pymatgen.io.vasp.inputs import Poscarposcar = Poscar.from_file("POSCAR" ) structure = poscar.structure
1 2 3 4 5 6 7 from pymatgen.io.xyz import XYZfrom pymatgen.io.gaussian import GaussianInputxyz = XYZ.from_file('methane.xyz' ) gau = GaussianInput(xyz.molecule, route_parameters={'SP' : "" , "SCF" : "Tight" }) gau.write_file('methane.inp' )
Entry
Entry 的最基本形式:一个构型成分 + 对应计算的能量(可包含其他输入或计算数据);可作为 pymatgen 创建相图的计算数据集
计算输入输出管理
pymatgen.io 模块包含一些计算软件(主要是 VASP)的输入文件编写、解析与输出文件解析子模块
输入管理的核心类是 InputSet
。 InputSet
object 包含计算输入文件所需的所有数据。具体来说,write_input()
方法,可将所有文件写到指定位置。InputGenerator
类可以看作是完成特定计算任务的 recipe,而 InputSet
则包含这些 recipes 以应用于特定体系或结构
也可以使用 InputSet.from_directory()
从计算目录中构建 pymatgen InputSet
许多解析输出文件的类继承自 InputFile
,其提供了一个读写文件的标准接口
其他
1 2 3 4 5 import nglviewnglview.show_pymatgen() nglview.show_ase()
生成元素置换后的非等同结构
借助 bsym 包;适用于复杂结构,如金属间化合物;可理解为置换找到的非等同原子中等同原子的第一个原子
bsym_examples
1 2 3 4 5 6 7 8 9 from bsym.interface.pymatgen import unique_structure_substitutionssubs_structures = unique_structure_substitutions( structure=structure, to_substitute="Nb" , site_distribution={"Al" : 2 , "Nb" : 14 }, verbose=True , show_progress=True , )
1 2 3 4 5 6 from atomate.vasp.drones import VaspDronedrone = VaspDrone() task_doc = drone.assimilate(path=...) task_doc.keys()
求助:过渡态计算新版pymatgen中找不到iddp插值方法 - 第一性原理 (First Principle) - 计算化学公社
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 from pymatgen.analysis import transition_statefrom pymatgen.analysis.diffusion.neb.pathfinder import IDPPSolverfrom pymatgen.analysis.defects.generators import SubstitutionGeneratorsubs = SubstitutionGenerator(structure, "Bi" ) from pymatgen.core.interface import GrainBoundary, GrainBoundaryGeneratorread_neb() MITNEBSet class
相关问题
常用模块 pymatgen.core
pymatgen 核心模块,常用的子模块有:structure
、sites
、lattice
、composition
structure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 from pymatgen.core.structure import Structureindex num_sites composition.num_atoms n_elems symbol_set types_of_species formula compsition cart_coords frac_coords lattice .abc volume density center_of_mass site_properties charge make_supercell() append() remove_species() remove_sites() replace_species() translate_sites() add_site_property() remove_site_property() get_neighbors() get_all_neighbors() get_distance() get_space_group_info() to_cell() to_conventional() to_primitive() interpolate() sort() get_sorted_structure() apply_strain() perturb() make_supercell() from_spacegroup() from_prototype() bcc fcc hcp fluorite, caf2 antifluorite rocksalt cscl diamond zincblende perovskite indices_Nb = [i for i, site in enumerate (structure) if site.species_string == "Nb" ]
composition 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 from pymatgen.core.composition import Compositioncomp = Composition("LiFePO4" ) num_atoms weight alphabetical_formula reduced_formula chemical_system chemical_system_set fractional_composition reduced_composition get_atomic_fraction() get_wt_fraction() get_el_amt_dict() as_dict()
periodic_table
查看元素周期表中元素的信息;Element 类继承自 ElementBase
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 from pymatgen.core.periodic_table import Elementdata Z number symbol long_name atomic_mass atomic_radius_calculated van_der_waals_radius ionic_radii electronic_structure n_electrons full_electronic_structure melting_point boiling_point liquid_range bulk_modulus youngs_modulus ionization_energies is_metal is_transition_metal print_periodic_table()
sites
1 2 3 4 5 6 from pymatgen.core.sites import Site, PeriodicSitecoords frac_coords specie
lattice
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 from pymatgen.core.lattice import LatticeLattice([[5 , 0 , 0 ], [0 , 5 , 0 ], [0 , 0 , 5 ]]) Lattice.from_parameters(5 , 5 , 5 , 90 , 90 , 90 ) Lattice.cubic(5 ) abc angles a b c alpha beta gamma reciprocal_lattice is_orthogonal is_3d_periodic matrix inv_matrix is_hexagonal d_hkl() get_wigner_seitz_cell() get_brillouin_zone()
units
surface
1 2 3 4 5 6 7 8 9 10 11 from pymatge.core.surface import ...get_symmetrically_distinct_miller_indices() get_symmetrically_equivalent_miller_indices() get_d()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 from pymatge.core.surface import SlabGeneratorSlabGenerator initial_structure miller_index min_slab_size min_vacuum_size center_slab in_unit_planes primitive max_normal_search reorient_lattice get_slabs() structure = Structure.from_prototype("bcc" , ["Nb" ], a=3.32 ) slabgen = SlabGenerator( initial_structure=structure, miller_index=(1 , 1 , 0 ), min_slab_size=10 , min_vacuum_size=10 , center_slab=True , in_unit_planes=False , primitive=True , ) slabs = slabgen.get_slabs() slabs[0 ]
pymatgen.io.ase
AseAtomsAdaptor
:将 ase 中的 atoms
类与 pymatgen 中的 Structure
类互相转换
1 2 3 4 5 from pymatgen.io.ase import AseAtomsAdaptorget_structure() get_atoms()
pymatgen.io.atat 只有 Mcsqs 类(功能较一般)
pymatgen.io.vasp.help 查看 VASP 参数 help
1 2 3 4 5 6 7 8 9 10 from pymatgen.io.vasp.help import VaspDocVaspDoc.get_incar_tags() VaspDoc.get_help("IBRION" ) VaspDoc().print_help("IBRION" ) VaspDoc().print_jupyter_help("IBRION" )
Incar
在解析 INCAR 文件时,得到的字典的键和值都是字符串,需要对 INCAR 中不同参数的键的值的类型进行正确的转换,因此定义了 proc_val()
函数
1 2 3 4 5 6 7 8 9 10 11 12 13 from pymatgen.io.vasp.inputs import IncarIncar(params: dict [str , Any ] | None = None ) incar_parameters = dict ( ISTART=0 , ISPIN=2 , ... ) incar = Incar.from_dict(incar_parameters) incar.write_file("INCAR" )
Kpoints
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 from pymatgen.io.vasp.inputs import Kpointsautomatic() gamma_automatic() monkhorst_automatic() automatic_density() automatic_gamma_density() automatic_density_by_vol() automatic_density_by_lengths() automatic_linemode() kpoints_dict = { "comment" : "Automatic mesh" , "nkpoints" : 0 , "generation_style" : "Gamma" , "kpoints" : [[10 , 10 , 10 ]], "usershift" : [0 , 0 , 0 ], } kpoints_dict = { '@module' : 'pymatgen.io.vasp.inputs' , '@class' : 'Kpoints' , 'comment' : 'k-point density of [20, 20, 20]/[a, b, c]' , 'nkpoints' : 0 , 'generation_style' : 'Gamma' , 'kpoints' : [(4 , 4 , 2 )], 'usershift' : (0 , 0 , 0 ), 'kpts_weights' : None , 'coord_type' : None , 'labels' : None , 'tet_number' : 0 , 'tet_weight' : 0 , 'tet_connections' : None , } kpoints = Kpoints.from_dict(kpoints_dict)
Poscar 1 2 3 4 5 6 7 8 9 10 from pymatgen.io.vasp.inputs import Poscarstructure comment natoms site_symbols
Potcar 读取和写入 POTCAR 文件的 object,由 PotcarSingle object (单个 POTCAR) 的列表组成
1 2 3 4 5 6 7 8 9 from pymatgen.io.vasp.inputs import Potcarpotcar = Potcar( symbols=["Nb_sv" , "Si" ], functional="PBE" , ) potcar.write_file("POTCAR" )
pymatgen.io.vasp.sets
1 2 3 4 5 6 7 grid_density reciprocal_density length line_density added_kpoints zero_weighted_reciprocal_density zero_weighted_line_density
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 pymatgen/io/vasp/MPRelaxSet.yaml pymatgen/io/vasp/VASPIncarBase.yaml pymatgen/io/vasp/MITRelaxSet.yaml MPRelaxSet MPStaticSet MPMetalRelaxSet MPHSERelaxSet MatPESStaticSet MPHSEBSSet MPSOCSet MVLElasticSet MVLGWSet MVLSlabSet MVLGBSet LobsterSet from pymatgen.io.vasp.sets import VaspInputSetVaspInputSet(...) user_incar_settings user_kpoints_settings user_potcar_settings user_potcar_functional force_gamma config_dict use_structure_charge write_input() output_dir=... potcar_spec=True from_prev_calc()
pymatgen.io.vasp.outputs
Outcar
Outcar 类能获取的较普适数据的属性和方法较少(主要解析 Vasprun.xml 文件无法获取到的数据)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 from pymatgen.io.vasp.ouputs import Outcardrift run_stats final_energy final_energy_wo_entrp final_fr_energy read_pattern() read_table_pattern() read_neb() outcar = Outcar(...) table_data = outcar.read_table_pattern( header_pattern=r"\sPOSITION\s+TOTAL-FORCE \(eV/Angst\)\n\s-+" , row_pattern=r"\s+([+-]?\d+\.\d+)\s+([+-]?\d+\.\d+)\s+([+-]?\d+\.\d+)\s+([+-]?\d+\.\d+)\s+([+-]?\d+\.\d+)\s+([+-]?\d+\.\d+)" , footer_pattern=r"\s--+" , postprocess=lambda x: float (x), last_one_only=False , )
Oszicar
Oszicar 类的 final_energy
属性选择的是 E0
;Vasprun 类的 final_energy
属性选择的也是 E0
1 2 3 4 5 6 7 8 9 10 from pymatgen.io.vasp.ouputs import Oszicarionic_steps electronic_steps final_energy all_energies as_dict()
Vasprun BSVasprun 类:Vasprun 的优化版本(继承至 Vasprun),只解析能带结构的本征值(忽略结构,参数等)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 from pymatgen.io.vasp.ouputs import Vasprunconverged converged_electronic converged_ionic incar kpoints potcar_spec potcar_symbols vasp_version initial_structure final_structure structures final_energy nionic_steps ionic_steps complete_dos tdos idos pdos as_dict() get_computed_entry() get_band_structure() dict_keys( [ "e_fr_energy" , "e_wo_entrp" , "e_0_energy" , "forces" , "stress" , "electronic_steps" , "structure" , ] )
Vasprun 类在解析未收敛的计算时,会有 Warning,并说明电子步和离子步的收敛情况
1 2 3 4 UnconvergedVASPWarning: vasprun.xml is an unconverged VASP run. Electronic convergence reached: True. Ionic convergence reached: False. warnings.warn(msg, UnconvergedVASPWarning)
pymatgen.electronic_structure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 import matplotlib.pyplot as pltfrom pymatgen.electronic_structure.plotter import DosPlotterfrom pymatgen.io.vasp.outputs import Vasprun, BSVasprunfrom pymatgen.electronic_structure.core import OrbitalType, Orbital, Spinfrom pymatgen.core.periodic_table import Elementdos_vasprun=Vasprun("./dos/vasprun.xml" ) dos_data=dos_vasprun.complete_dos fermi = dos_data.efermi energy = dos_data.energies - fermi dos_data.densities dos_data.get_spd_dos() dos_data.get_element_dos() dos_data.get_element_spd_dos() dos_data.get_site_dos() dos_data.get_site_spd_dos() total_densities = dos_data.densities total_densities[Spin.up] spd_dos = dos_data.get_spd_dos() dos_s = spd_dos[OrbitalType.s].densities[Spin.up] element_dos = dos_data.get_element_dos() dos_Si = element_dos[Element("Si" )].densities[Spin.up] dos_vasprun.tdos.as_dict()["energies" ] dos_vasprun.tdos.as_dict()["densities" ]["1" ] dos_vasprun.pdos[0 ][Orbital.s][Spin.up] dos_plot = DosPlotter() dos_plot.add_dos("Total" , dos=dos_data) dos_plot.get_plot() pdos_plot = DosPlotter() pdos_plot.add_dos_dict(dos_data.get_spd_dos()) pdos_plot.get_plot() edos_plot = DosPlotter() edos_plot.add_dos_dict(dos_data.get_element_dos()) edos_plot.get_plot() edos_plot = DosPlotter() pdos_Nb = dos_data.get_element_spd_dos("Nb" ) dos_plot.add_dos("Nb(s)" , dos=pdos_Nb[OrbitalType.s]) dos_plot.add_dos("Nb(p)" , dos=pdos_Nb[OrbitalType.p]) dos_plot.add_dos("Nb(d)" , dos=pdos_Nb[OrbitalType.d]) edos_plot.get_plot() ados_plot = DosPlotter() ados_plot.add_dos("Site 0 Total" , dos=dos_data.get_site_dos(structure[0 ])) ados_plot.get_plot() apdos_plot = DosPlotter() dos_site0 = dos_data.get_site_spd_dos(structure[0 ]) apdos_plot.add_dos("Nb0(s)" , dos=dos_site0[OrbitalType.s]) apdos_plot.add_dos("Nb0(p)" , dos=dos_site0[OrbitalType.p]) apdos_plot.add_dos("Nb0(d)" , dos=dos_site0[OrbitalType.d]) apdos_plot.get_plot() ax = dos_plot.get_plot() ax.set_xlim(...) plt.savefig(...)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import matplotlib.pyplot as pltfrom pymatgen.electronic_structure.core import OrbitalType, Orbitalfrom pymatgen.io.vasp.outputs import Vasprun, BSVasprunfrom pymatgen.electronic_structure.plotter import ( BSPlotter, BSPlotterProjected, BSDOSPlotter, ) bs_vasprun = Vasprun("./bs/vasprun.xml" , parse_projected_eigen=True ) bs_data = bs_vasprun.get_band_structure(line_mode=True ) bs_plot = BSPlotter(bs=bs_data) bs_plot.get_plot() bsdos_plot = BSDOSPlotter(bs_projection=None , dos_projection=None ) bsdos_plot.get_plot(bs=bs_data, dos=dos_data)
COHP (Crystal orbital Hamilton population)
1 from pymatgen.electronic_structure.cohp import ...
pymatgen.analysis structure_matcher
1 2 3 4 from pymatgen.analysis.structure_matcher import StructureMatchersm = StructureMatcher() sm.fit(structure1, structure2)
eos
EOS 类:BirchMurnaghan
、Birch
、Murnaghan
、PourierTarantola
、Vinet
等
1 2 3 4 5 6 7 8 9 10 11 from pymatgen.analysis.eos import BirchMurnaghaneos = BirchMurnaghan(volumes=..., energies=...) eos.fit() eos.results eos.v0 eos.e0 eos.b0_GPa eos.plot()
interface
1 2 3 4 5 6 7 8 9 from pymatgen.analysis.interfaces.coherent_interfaces import CoherentInterfaceBuilderfrom pymatgen.analysis.interfaces.zsl import ZSLGeneratorzsl ZSLGenerator coherent_interfaces CoherentInterfaceBuilder
elasticity 1 2 3 4 from pymatgen.analysis.elasticity import DeformedStructureSetDeformedStructureSet()
electronic_structure
pymatgen 电子结构相关分析很多都是建立在 vasprun.xml 文件中提取数据之上的(与 vaspkit 有不同)
phase_diagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 from pymatgen.analysis.phase_diagram import PDEntry, PhaseDiagramfrom pymatgen.core.composition import Compositionentry1 = PDEntry(composition=..., energy=...) entry2 = ... ... entries = [entry1, entry2, ...] phasediagram = PhaseDiagram(entries) stable_entries get_decomposition() get_decomp_and_e_above_hull() get_plot() ax = phasediagram.get_plot( backend="matplotlib" , show_unstable=False , ) ax.figure.savefig()
diffraction
1 2 3 4 5 6 7 8 9 10 11 12 from pymatgen.analysis.diffraction.xrd import XRDCalculatorfrom pymatgen.analysis.diffraction.neutron import NDCalculatorfrom pymatgen.analysis.diffraction.tem import TEMCalculatorc = XRDCalculator() get_plot(structure) get_pattern(structure) get_pattern(structure).hkls get_pattern(structure).d_hkls
adsorption
1 2 3 4 5 6 7 8 from pymatgen.analysis.adsorption import AdsorbateSiteFinder, plot_slabfind_adsorption_sites() add_adsorbate() plot_slab()
prototype
匹配晶体结构的 prototype(调用的是 AFLOW 的 prototype 数据)
1 from pymatgen.analysis.prototype import ...
diffusion
1 pip install -U pymatgen-analysis-diffusion
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 from pymatgen.analysis.diffusion.neb.pathfinder import IDPPSolverrun() from_endpoints() idpp_solver = IDPPSolver.from_endpoints() idpp_solver.run() from pymatgen.analysis.diffusion.aimd.pathway import ProbabilityDensityAnalysisfrom pymatgen.analysis.diffusion.analyzer import DiffusionAnalyzerdiffusion_ana = DiffusionAnalyzer.from_structures() diffusion_ana.export_msdt() diffusion_ana.conductivity pda = ProbabilityDensityAnalysis.from_diffusion_analyzer(diffusion_ana) pda.to_chgcar()
pymatgen.symmetry.bandstructure
1 2 3 4 5 6 7 8 9 from pymatgen.symmetry.bandstructure import HighSymmKpathstructure = ... kpath = HighSymmKpath(structure=structure) kpath.kpath kpath.kpath["kpoints" ] kpath.kpath["path" ]
pymatgen.symmetry.analyzer SpacegroupAnalyzer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 from pymatgen.symmetry.analyzer import SpacegroupAnalyzersga_analyzer = SpacegroupAnalyzer(structure, symprec=...,) get_conventional_standard_structure() get_primitive_standard_structure() get_symmetrized_structure() get_symmetry_dataset() get_crystal_system() get_space_group_number() get_space_group_symbol() get_crystal_system() symmetry_dataset = sga_analyzer.get_symmetry_dataset() number international equivalent_atoms wyckoffs
参考:
简单的变换操作:添加和删除原子位点,元素替换,到更高级的一对多的转换
pymatgen 无置换 Wyckoff Site 中的元素的类
SQSTransformation
类中调用的是 ATAT 中的 mcsqs 工具或 ICET 中的 enumeration、monte carlo 模块;建议直接使用其调用的原生工具
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 from pymatgen.transformations.standard_transformations import ...from pymatgen.transformations.advanced_transformations import ...from pymatgen.transformations.site_transformations import ...structure = ... transformation = XXX() structure_new = transformation.apply_transformation(structure) RemoveSpecieTransformations AutoOxiStateDecorationTransformation ChargedCellTransformation SubstitutionTransformation SQSTransformation EnumerateStructureTransformation ReplaceSiteSpeciesTransformation apply_transformation(structure) sqs = SQSTransformation([2 , 2 , 2 ]) enum = EnumerateStructureTransformation() enumerated = enum.apply_transformation(structure, return_ranked_list=100 ) species_map = {"Si" : "C" } species_map = {"Si" :{"Si" :0.9 , "C" :0.1 }}
pymatgen.phonon
API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 from mp_api.client import MPResterwith MPRester("api-key" ) as mpr: docs = mpr.materials.summary.search(...) mpr.materials.summary.available_fields mpr.get_entries_in_chemsys() mpr.get_bandstructure_by_material_id() mpr.get_dos_by_material_id() mpr.get_phonon_bandstructure_by_material_id() mpr.get_phonon_dos_by_material_id() mpr.materials.thermo.get_phase_diagram_from_chemsys(chemsys=...,) chemsys="Ti-Al" chemsys="Ti-Al-Nb" chemsys="Ti-Al-Nb-Zr" material_ids=["mp-149" ] chemsys="Si-O" , elements=["Si" , "O" ] has_props=["dos" ] fields=["band_gap" ] is_stable=True material_id composition_reduced formula_pretty structure symmetry .crystal_system .symbol nsites energy_per_atom formation_energy_per_atom energy_above_hull is_stable fields_not_requested
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 from pymatgen.ext.matproj import MPResterwith MPRester("api-key" ) as mpr: mpr.query() mpr.get_structure_by_material_id() mpr.get_download_info() mpr.get_gb_data() mpr.get_surface_data() criteria properties formula spacegroup formation_energy_per_atom elasticity