Python API
The Python layer mirrors the CLI and adds programmatic access to parsed VASP data with persistent caching.
VASP directory handling: MRFVaspDir
MRFVaspDir gives
dictionary-like access to a VASP directory with a persistent disk cache,
so repeated analysis of large trees does not re-parse XML or OUTCAR files
every time.
The cache is optimized for supercomputer file system, avoiding excessive IO.
from matrifflow.pymatgen.io.vasp.vaspdir import MRFVaspDir
vdir = MRFVaspDir("path/to/vasp/calculation")
structure = vdir.final_structure
energy = vdir.final_energy
incar = vdir["INCAR"]
if vdir.converged:
print("Calculation converged")
# NEB directories
if vdir.nebp:
for image_dir in vdir.neb_dirs():
print(f"Image {image_dir.path}: {image_dir.final_energy}")
The example reads three properties:
final_structure,
final_energy,
and converged.
NEB image directories come from
nebp and
neb_dirs().
final_energy_reliable
returns a float only when the energy is judged usable, otherwise
"unreliable" (for example, a volume/shape relaxation) or
"unconverged".
The cache is change-aware: it stores a file signature and re-parses only directories whose relevant files changed.
Derive new VASP input
MRFDerivedInputSet
inherits the inputs and final structure from an existing calculation,
changes them, and writes a new directory:
from matrifflow.pymatgen.io.vasp.sets import MRFDerivedInputSet
from matrifflow.pymatgen.io.vasp.vaspdir import MRFVaspDir
source = MRFVaspDir('relaxed_calculation')
print(source['INCAR'])
print(source.final_structure)
if source.final_structure:
print("Using final structure")
else:
print("Falling back to POSCAR")
inputs = MRFDerivedInputSet(
directory=source,
functional='optB88-vdW',
user_incar_settings={'NSW': 500, 'IBRION': 2},
)
if inputs.structure is None:
raise ValueError('No structure found in the source VASP directory')
inputs.structure = inputs.structure.copy()
inputs.structure.translate_sites([0], [0, 0, 0.02], frac_coords=True)
inputs.write_input('displaced_calculation', potcar_spec=True)
MRFDerivedInputSet inherits the source settings and writes new
modified VASP inputs to displaced_calculation, and logs settings to
MRFVaspInputSet.log, and INCAR.toml. potcar_spec=True
writes POTCAR.spec instead of requiring local pseudopotentials.
ATAT structure files
from matrifflow.pymatgen.core.structure import MRFStructure
s = MRFStructure.from_file("str.out") # vacancies become "X"
MRFStructure is a
pymatgen.core.Structure that also reads and writes ATAT str.out
files.
Transformations
Inserting molecules
from matrifflow.pymatgen.transformations.insert_molecule import InsertMoleculeTransformation
transformer = InsertMoleculeTransformation(
molecule="Li",
step=0.2,
proximity_threshold=0.75,
)
inserts = transformer.all_inserts("host_structure.cif")
InsertMoleculeTransformation
documents the grid parameters (step, step_noise, anglestep) and the
filtering options;
Symmetry cloning
Given a host structure and a defect structure, generate every
symmetry-equivalent placement of an interstitial under the host’s
space group.
This is used by mrf derive . fill.
from matrifflow.pymatgen.transformations.symmetry_clone import SymmetryCloneTransformation
from pymatgen.core import Structure
host = Structure.from_file("host.cif")
defect = Structure.from_file("host_with_interstitial.cif")
trans = SymmetryCloneTransformation(sym_operations=host)
clones = trans.get_all_clones(host_with_interstitial)
SymmetryCloneTransformation
takes the symmetry operations of the host.
Diffusion analysis
from matrifflow.pymatgen.diffusion.neb import get_neb_pairs
pairs = get_neb_pairs(
structures=stable_sites_list,
prototype=host_structure,
cutoff="auto",
remove_compound=True,
)
for start, end in pairs:
print(f"Path from {start} to {end}")
get_neb_pairs() generates and
filters the candidate pairs; the graph behind the diffusion paths, with
its distance and barrier helpers, is
NEB_Graph.