Comprehensive materials science analysis library for crystal structures, molecules, and materials data with extensive computational chemistry integration.
—
Fundamental classes for representing crystal structures, molecules, compositions, and lattices that form the foundation of all materials analysis in pymatgen. These classes provide rich manipulation capabilities, property calculations, and serve as the basis for all higher-level analysis functions.
Primary classes for representing atomic arrangements in crystals and molecules with comprehensive manipulation and query methods.
class Structure:
"""
Mutable 3D crystal structure representation.
Parameters:
- lattice: Lattice object or 3x3 matrix representing the unit cell
- species: List of species at each site
- coords: List of fractional coordinates for each site
- charge: Optional net charge of the structure
- validate_proximity: Whether to check for unreasonably close atoms
- to_unit_cell: Whether to map sites to unit cell
- coords_are_cartesian: Whether coordinates are in Cartesian form
- site_properties: Dict of site properties
- labels: Optional site labels
- properties: Additional structure properties
"""
def __init__(self, lattice, species, coords, charge=None,
validate_proximity=False, to_unit_cell=False,
coords_are_cartesian=False, site_properties=None,
labels=None, properties=None): ...
def get_primitive_structure(self, tolerance=0.25, use_site_props=False,
constrain_latt=None): ...
def get_reduced_structure(self, reduction_algo="niggli"): ...
def get_conventional_structure(self, international_monoclinic=True): ...
def get_neighbors(self, site, r, include_index=False, include_image=False): ...
def get_neighbors_in_shell(self, origin, r, dr): ...
def get_sites_in_sphere(self, pt, r, include_index=False, include_image=False): ...
def get_all_neighbors(self, r, include_index=False, include_image=False): ...
def get_distance(self, i, j, jimage=None): ...
def get_angle(self, i, j, k): ...
def get_dihedral(self, i, j, k, l): ...
def copy(self): ...
def __mul__(self, scaling_matrix): ...
# Site manipulation methods
def insert(self, i, species, coords, coords_are_cartesian=False,
validate_proximity=False, properties=None): ...
def append(self, species, coords, coords_are_cartesian=False,
validate_proximity=False, properties=None): ...
def remove_sites(self, indices): ...
def remove_species(self, species): ...
def replace(self, i, species, coords=None, coords_are_cartesian=False,
properties=None): ...
def substitute(self, index, func_group, bond_order=1): ...
def add_site_property(self, property_name, values): ...
def remove_site_property(self, property_name): ...
# Transformation methods
def apply_operation(self, symm_op, fractional=False): ...
def apply_strain(self, strain): ...
def perturb(self, distance, min_distance=None): ...
def make_supercell(self, scaling_matrix, to_unit_cell=True): ...
def scale_lattice(self, volume): ...
def translate_sites(self, indices, vector, frac_coords=True, to_unit_cell=True): ...
def rotate_sites(self, indices=None, theta=0, axis=None, anchor=None): ...
# Analysis properties
@property
def volume(self): ...
@property
def density(self): ...
@property
def formula(self): ...
@property
def composition(self): ...
@property
def charge(self): ...
@property
def num_sites(self): ...
@property
def lattice(self): ...
@property
def species(self): ...
@property
def sites(self): ...
@property
def frac_coords(self): ...
@property
def cart_coords(self): ...class IStructure:
"""
Immutable version of Structure. Same interface but cannot be modified.
"""
# Same properties and analysis methods as Structure
# No mutation methods (insert, append, remove_sites, etc.)class Molecule:
"""
Mutable molecular structure representation for non-periodic systems.
Parameters:
- species: List of species in molecule
- coords: List of Cartesian coordinates
- charge: Net charge of molecule
- spin_multiplicity: Spin multiplicity
- validate_proximity: Whether to check for close atoms
- site_properties: Dict of site properties
"""
def __init__(self, species, coords, charge=0, spin_multiplicity=None,
validate_proximity=False, site_properties=None): ...
def get_distance(self, i, j): ...
def get_angle(self, i, j, k): ...
def get_dihedral(self, i, j, k, l): ...
def get_neighbors(self, site, r): ...
def get_boxed_structure(self, a, b, c, images=(2, 2, 2),
random_rotation=False, min_dist=1.0,
cls=None, offset=None, reorder=True,
rotations=None): ...
# Center-of-mass operations
def get_centered_molecule(self): ...
def get_covalent_bonds(self, tol=0.2): ...
@property
def center_of_mass(self): ...
@property
def charge(self): ...
@property
def spin_multiplicity(self): ...
@property
def nelectrons(self): ...class IMolecule:
"""
Immutable version of Molecule.
"""
# Same interface as Molecule but immutableChemical composition representation with element counting, formula manipulation, and compositional analysis tools.
class Composition:
"""
Chemical composition representation with element counting and analysis.
Parameters:
- *args: Flexible arguments - dict, formula string, or key-value pairs
- strict: Only allow valid Elements and Species (default: False)
- **kwargs: Additional keyword arguments for composition data
"""
def __init__(self, *args, strict=False, **kwargs): ...
def get_atomic_fraction(self, el): ...
def get_wt_fraction(self, el): ...
def get_reduced_composition_and_factor(self): ...
def get_reduced_formula_and_factor(self): ...
def get_integer_formula_and_factor(self, max_denominator=10000): ...
def get_el_amt_dict(self): ...
def fractional_composition(self): ...
def add_charges_from_oxi_state_guesses(self, oxi_states_override=None,
target_charge=0, all_oxi_states=False,
max_sites=None): ...
def oxi_state_guesses(self, oxi_states_override=None, target_charge=0,
all_oxi_states=False, max_sites=None): ...
def replace(self, replacements_dict): ...
def __add__(self, other): ...
def __sub__(self, other): ...
def __mul__(self, other): ...
@property
def formula(self): ...
@property
def alphabetical_formula(self): ...
@property
def element_composition(self): ...
@property
def fractional_composition(self): ...
@property
def reduced_composition(self): ...
@property
def reduced_formula(self): ...
@property
def elements(self): ...
@property
def num_atoms(self): ...
@property
def weight(self): ...
@property
def average_electroneg(self): ...
@property
def total_electrons(self): ...
@property
def charge(self): ...
@property
def anonymized_formula(self): ...
@property
def chemical_system(self): ...
@property
def hill_formula(self): ...
@property
def iupac_formula(self): ...Crystal lattice representation with vector operations, reciprocal lattice calculations, and crystallographic transformations.
class Lattice:
"""
Crystal lattice representation with vector operations.
Parameters:
- matrix: 3x3 lattice matrix where rows are lattice vectors
"""
def __init__(self, matrix): ...
@classmethod
def cubic(cls, a): ...
@classmethod
def tetragonal(cls, a, c): ...
@classmethod
def orthorhombic(cls, a, b, c): ...
@classmethod
def hexagonal(cls, a, c): ...
@classmethod
def rhombohedral(cls, a, alpha): ...
@classmethod
def monoclinic(cls, a, b, c, beta): ...
@classmethod
def triclinic(cls, a, b, c, alpha, beta, gamma): ...
@classmethod
def from_parameters(cls, a, b, c, alpha, beta, gamma): ...
def get_cartesian_coords(self, fractional_coords): ...
def get_fractional_coords(self, cart_coords): ...
def get_points_in_sphere(self, frac_points, center, r, zip_results=True): ...
def get_all_distances(self, fcoords1, fcoords2): ...
def get_distance_and_image(self, frac_coords1, frac_coords2, jimage=None): ...
def get_vector_along_lattice_directions(self, cart_coords): ...
def find_neighbors(self, label, cutoff, get_length=True): ...
def get_points_in_spheres(self, all_fcoords, all_centers, all_r,
zip_results=True, return_fcoords=False): ...
# Analysis properties
@property
def a(self): ...
@property
def b(self): ...
@property
def c(self): ...
@property
def alpha(self): ...
@property
def beta(self): ...
@property
def gamma(self): ...
@property
def volume(self): ...
@property
def matrix(self): ...
@property
def inv_matrix(self): ...
@property
def metric_tensor(self): ...
@property
def reciprocal_lattice(self): ...
@property
def reciprocal_lattice_crystallographic(self): ...
@property
def parameters(self): ...
@property
def lengths(self): ...
@property
def angles(self): ...
@property
def is_orthogonal(self): ...
@property
def norm(self): ...Atomic sites and chemical species representations with properties and neighbor information.
class Site:
"""
Generic site with Cartesian coordinates and species information.
Parameters:
- species: Species at the site
- coords: Cartesian coordinates of the site
- properties: Dict of site properties
- label: Optional site label
"""
def __init__(self, species, coords, properties=None, label=None): ...
def distance(self, other): ...
def distance_from_point(self, pt): ...
@property
def species(self): ...
@property
def species_string(self): ...
@property
def coords(self): ...
@property
def x(self): ...
@property
def y(self): ...
@property
def z(self): ...
@property
def properties(self): ...
@property
def label(self): ...class PeriodicSite:
"""
Site in a periodic structure with fractional coordinates and lattice.
Parameters:
- species: Species at the site
- coords: Fractional coordinates
- lattice: Lattice object
- to_unit_cell: Whether to wrap to unit cell
- coords_are_cartesian: Whether coords are Cartesian
- properties: Dict of site properties
- label: Optional site label
"""
def __init__(self, species, coords, lattice, to_unit_cell=False,
coords_are_cartesian=False, properties=None, label=None): ...
def distance(self, other, jimage=None): ...
def distance_and_image(self, other, jimage=None): ...
def is_periodic_image(self, other, tolerance=1e-8, check_lattice=True): ...
@property
def frac_coords(self): ...
@property
def coords(self): ...
@property
def lattice(self): ...
@property
def a(self): ...
@property
def b(self): ...
@property
def c(self): ...class Element:
"""
Chemical element from periodic table.
Parameters:
- symbol: Element symbol (e.g., 'Fe', 'O')
"""
def __init__(self, symbol): ...
@property
def symbol(self): ...
@property
def name(self): ...
@property
def atomic_mass(self): ...
@property
def atomic_radius(self): ...
@property
def atomic_radius_calculated(self): ...
@property
def van_der_waals_radius(self): ...
@property
def mendeleev_no(self): ...
@property
def electrical_resistivity(self): ...
@property
def velocity_of_sound(self): ...
@property
def reflectance(self): ...
@property
def refractive_index(self): ...
@property
def poissons_ratio(self): ...
@property
def molar_volume(self): ...
@property
def electronic_structure(self): ...
@property
def atomic_orbitals(self): ...
@property
def thermal_conductivity(self): ...
@property
def boiling_point(self): ...
@property
def melting_point(self): ...
@property
def critical_temperature(self): ...
@property
def superconduction_temperature(self): ...
@property
def liquid_range(self): ...
@property
def bulk_modulus(self): ...
@property
def youngs_modulus(self): ...
@property
def brinell_hardness(self): ...
@property
def rigidity_modulus(self): ...
@property
def mineral_hardness(self): ...
@property
def vickers_hardness(self): ...
@property
def density_of_solid(self): ...
@property
def coefficient_of_linear_thermal_expansion(self): ...class Species:
"""
Chemical species with oxidation state.
Parameters:
- symbol: Element symbol
- oxidation_state: Oxidation state (int or float)
- properties: Additional properties dict
"""
def __init__(self, symbol, oxidation_state, properties=None): ...
@property
def element(self): ...
@property
def oxi_state(self): ...
@property
def ionic_radius(self): ...
@property
def spin(self): ...class Ion:
"""
Ionic species with charge.
Parameters:
- symbol: Element symbol or Species
- charge: Ionic charge
- properties: Additional properties dict
"""
def __init__(self, symbol, charge, properties=None): ...
@property
def charge(self): ...
@property
def element(self): ...
@property
def formula(self): ...Unit handling and conversion for physical quantities used in materials science calculations.
class Unit:
"""
Physical unit representation and conversion.
Parameters:
- unit_def: Unit definition string or dict
"""
def __init__(self, unit_def): ...
def __mul__(self, other): ...
def __div__(self, other): ...
def __pow__(self, i): ...
@property
def as_base_units(self): ...class FloatWithUnit:
"""
Float with associated physical unit.
Parameters:
- val: Numerical value
- unit: Unit object or string
"""
def __init__(self, val, unit): ...
def to(self, new_unit): ...
def as_base_units(self): ...
@property
def unit(self): ...
@property
def supported_units(self): ...class ArrayWithUnit:
"""
NumPy array with associated physical unit.
Parameters:
- input_array: Array-like input
- unit: Unit object or string
"""
def __init__(self, input_array, unit): ...
def to(self, new_unit): ...
def as_base_units(self): ...
@property
def unit(self): ...
@property
def supported_units(self): ...Basic symmetry operations for structure manipulation and analysis.
class SymmOp:
"""
Symmetry operation consisting of rotation and translation.
Parameters:
- rotation_matrix: 3x3 rotation matrix
- translation_vec: Translation vector
- tol: Tolerance for operations
"""
def __init__(self, rotation_matrix, translation_vec, tol=0.01): ...
def apply_rotation_only(self, vector): ...
def operate(self, point): ...
def operate_multi(self, points): ...
def transform_tensor(self, tensor): ...
def are_symmetrically_related(self, point_a, point_b, tol=0.001): ...
@classmethod
def from_axis_angle_and_translation(cls, axis, angle, angle_in_radians=False,
translation_vec=(0, 0, 0)): ...
@classmethod
def from_origin_axis_angle(cls, origin, axis, angle, angle_in_radians=False): ...
@classmethod
def reflection(cls, normal, origin=(0, 0, 0)): ...
@classmethod
def inversion(cls, origin=(0, 0, 0)): ...
@classmethod
def rotoreflection(cls, axis, angle, origin=(0, 0, 0)): ...
@property
def rotation_matrix(self): ...
@property
def translation_vector(self): ...
@property
def inverse(self): ...
@property
def affine_matrix(self): ...Helper functions for working with core materials representations.
def get_el_sp(obj):
"""
Convert various inputs to Element or Species objects.
Parameters:
obj: Element symbol string, Element, Species, or Ion
Returns:
Element or Species object
"""
def reduce_formula(sym_amt, iupac_ordering=False):
"""
Reduce chemical formula to simplest form.
Parameters:
sym_amt: Dict of {symbol: amount}
iupac_ordering: Whether to use IUPAC ordering
Returns:
str: Reduced formula
"""
def get_bond_length(sp1, sp2, bond_order=1):
"""
Get bond length between two species.
Parameters:
sp1, sp2: Species objects or symbols
bond_order: Bond order (1=single, 2=double, etc.)
Returns:
float: Bond length in Angstroms
"""
def obtain_all_bond_lengths(structure, max_bond_length=3.0):
"""
Get all bond lengths in a structure.
Parameters:
structure: Structure object
max_bond_length: Maximum bond length to consider
Returns:
dict: Bond lengths organized by species pairs
"""Install with Tessl CLI
npx tessl i tessl/pypi-pymatgen