Mannul Collection

  • 安装:conda install -c matsci pymatgen

  • 创建分子结构与晶体结构:

    • 自己创建
    from pymatgen import Lattice, Structure, Molecule
    
    coords = [[0, 0, 0], [0.75,0.5,0.75]]
    lattice = Lattice.from_parameters(a=3.84, b=3.84, c=3.84, alpha=120,
                                      beta=90, gamma=60)
    struct = Structure(lattice, ["Si", "Si"], coords)
    
    coords = [[0.000000, 0.000000, 0.000000],
              [0.000000, 0.000000, 1.089000],
              [1.026719, 0.000000, -0.363000],
              [-0.513360, -0.889165, -0.363000],
              [-0.513360, 0.889165, -0.363000]]
     methane = Molecule(["C", "H", "H", "H", "H"], coords)
    
    • 读入和写出:

      # Read a POSCAR and write to a CIF.
      structure = Structure.from_file("POSCAR")
      structure.to(filename="CsCl.cif")
      
      # Read an xyz file and write to a Gaussian Input file.
      methane = Molecule.from_file("methane.xyz")
       methane.to(filename="methane.gjf")
      

      其他方法:

      from pymatgen.io.cif import CifParser
      parser = CifParser("mycif.cif")
       structure = parser.get_structures()[0]
      
      from pymatgen.io.vasp import Poscar
      poscar = Poscar.from_file("POSCAR")
       structure = poscar.structure
      
      from pymatgen.io.vasp import Poscar
      from pymatgen.io.cif import CifWriter
      
      p = Poscar.from_file('POSCAR')
      w = CifWriter(p.struct)
       w.write_file('mystructure.cif')
      
      from pymatgen.io.xyz import XYZ
      from pymatgen.io.gaussian import GaussianInput
      
      xyz = XYZ.from_file('methane.xyz')
      gau = GaussianInput(xyz.molecule,
                          route_parameters={'SP': "", "SCF": "Tight"})
       gau.write_file('methane.inp')
      

      只要安装了OpenBabel,就可以支持100多种格式的读取与相互转化

    There is also support for more than 100 file types via the OpenBabel interface. But that requires you to install openbabel with Python bindings. Please see the installation guide.

  • 改变结构或分子:

    • 对分子的操作:

      # Change the specie at site position 1 to a fluorine atom.
      structure[1] = "F"
      molecule[1] = "F"
      
      # Change species and coordinates (fractional assumed for Structures,
      # cartesian for Molecules)
      structure[1] = "Cl", [0.51, 0.51, 0.51]
      molecule[1] = "F", [1.34, 2, 3]
      
      # Structure/Molecule also supports typical list-like operators,
      # such as reverse, extend, pop, index, count.
      structure.reverse()
      molecule.reverse()
      
      structure.append("F", [0.9, 0.9, 0.9])
      molecule.append("F", [2.1, 3.2 4.3])
      
  • 对结构的操作:(超胞,单胞,NEB搜索)

    # Make a supercell
    structure.make_supercell([2, 2, 2])
    
    # Get a primitive version of the Structure
    structure.get_primitive_structure()
    
    # Interpolate between two structures to get 10 structures (typically for
    # NEB calculations.
    structure.interpolate(another_structure, nimages=10)
    
  • 高通量转化:

    pymatgen.alchemy.materials.TransformedStructure可通过cif或POSCAR生成转化结构

    pymatgen.alchemy.transmuters.StandardTransmuter通过cif或POSCAR生成变形结构

    应用例:将所有铁元素换为锰并移除所有Li元素

    from pymatgen.alchemy.transmuters import CifTransmuter
    from pymatgen.transformations.standard_transformations import SubstitutionTransformation, RemoveSpeciesTransformation
    
    trans = []
    trans.append(SubstitutionTransformation({"Fe":"Mn"}))
    trans.append(RemoveSpecieTransformation(["Li"]))
    transmuter = CifTransmuter.from_filenames(["MultiStructure.cif"], trans)
    structures = transmuter.transformed_structures
    
  • 兼容性:Mixing GGA and GGA+U runs

    • Ceder组提出的混合GGA和GGA+U的计算,例如为了生成$\ce{Fe-P-O}$相图,金属相如$\ce{Fe,Fe_xP}$适合使用标准GGA,而氧化物如$\ce{FeO_y,Fe_xP_yO_z}$则适合GGA+U

    • pymatgen.io.vasp.sets模块支持生成vasp输入文件

    • 例如如果需要计算$\ce{Fe-P-O}$相图需要生成的一系列vasp输入文件可通过以下脚本实现

      from pymatgen.entries.compatibility import MaterialsProjectCompatibility
      from pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter
      
      # Get unprocessed_entries using pymatgen.borg or other means.
      
      # Process the entries for compatibility
      compat = MaterialsProjectCompatibility()
      processed_entries = compat.process_entries(unprocessed_entries)
      
      # These few lines generates the phase diagram using the ComputedEntries.
      pd = PhaseDiagram(processed_entries)
      plotter = PDPlotter(pd)
      plotter.show()
      
    • 在计算完$\ce{Li-O}$以后可分析结果相图:

      from pymatgen.borg.hive import VaspToComputedEntryDrone
      from pymatgen.borg.queen import BorgQueen
      from pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter
      
      # These three lines assimilate the data into ComputedEntries.
      drone = VaspToComputedEntryDrone()
      queen = BorgQueen(drone, "Li-O_runs", 2)
      entries = queen.get_data()
      
      # It's a good idea to perform a save_data, especially if you just assimilated
      # a large quantity of data which took some time. This allows you to reload
      # the data using a BorgQueen initialized with only the drone argument and
      # calling queen.load_data("Li-O_entries.json")
      queen.save_data("Li-O_entries.json")
      
      # These few lines generates the phase diagram using the ComputedEntries.
      pd = PhaseDiagram(entries)
      plotter = PDPlotter(pd)
      plotter.show()
      
  • 计算反应能量:

    from pymatgen.apps.borg.hive import VaspToComputedEntryDrone
    from pymatgen.apps.borg.queen import BorgQueen
    from pymatgen.analysis.reaction_calculator import ComputedReaction
    
    # These three lines assimilate the data into ComputedEntries.
    drone = VaspToComputedEntryDrone()
    queen = BorgQueen(drone)
    queen.load_data("Li-O_entries.json")
    entries = queen.get_data()
    
    #Extract the correct entries and compute the reaction.
    rcts = filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries)
    prods = filter(lambda e: e.composition.reduced_formula == "Li2O", entries)
    rxn = ComputedReaction(rcts, prods)
    print(rxn)
    print(rxn.calculated_reaction_energy)
    

results matching ""

    No results matching ""