Pymatgen

Overview

Like ASE,  Pymatgen  is a Python code to enable materials informatics analyses. The main distinction between Pymatgen and ASE is that Pymatgen can be used to carry out much more complex manipulations of structures and has more in-depth parsing of VASP-related input and output files. Pymatgen also has capabilities to run certain DFT codes, but we will generally use ASE for this purpose since it is more seamless.

Installation

To install Pymatgen, simply run pip install pymatgen.

Overview

Pymatgen has substantial  documentation  for each of its relevant functions and classes. However, if you are new to using Python classes, it may take some getting used to in order to understand some of the syntax. The tutorial video below can help.

intro_pymatgen.zip
12KB, Uploaded 2 years ago

The Structure and Molecule Objects

The main objects in Pymatgen are the Structure and Molecule object. As the name suggests, these entities describe periodic crystal structures and molecules, respectively. They can be generated from a file as follows:
from pymatgen.core.structure import Molecule, Structure

structure = Structure.from_file("MOF5.cif")
molecule = Molecule.from_file("N2.xyz")

MOF5.cif
5KB, Uploaded 2 years ago

N2.xyz
157Bytes, Uploaded 2 years ago
It is also possible to write out the Structure and Molecule objects to new files. For instance, the command below would write out the Structure object in POSCAR format.
structure.to(filename="POSCAR")

Interfacing ASE and Pymatgen

Many times, you may wish to transform between an ASE Atoms object and Pymatgen Structure or Molecule object that way you can use the features of both codes interchangeably. This can be easily achieved using the AseAtomsAdaptor class in Pymatgen, as described below:
from pymatgen.core.structure import Molecule, Structure
from pymatgen.io.ase import AseAtomsAdaptor

structure = Structure.from_file("MOF5.cif")
molecule = Molecule.from_file("N2.xyz")
bridge = AseAtomsAdaptor()

atoms = bridge.get_atoms(structure) # convert Structure to Atoms
structure = bridge.get_structure(atoms) # convert Atoms to Structure

atoms = bridge.get_atoms(molecule) # convert Molecule to Atoms
molecule = bridge.get_structure(atoms) # convert Atoms to Molecule