Symmetry-adapted Force Constants (symfc)

1.6.1 · active · verified Thu Apr 16

symfc is a Python library designed for calculating symmetry-adapted force constants, a critical component for phonon calculations in materials science. It utilizes crystal symmetry to significantly reduce the computational expense of determining these constants. The current version is 1.6.1, with new releases occurring periodically for bug fixes, performance enhancements, and new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `Symfc` class and instantiate a `Symfc` object. It uses dummy data for crystal structure (lattice, positions, numbers) and simulation results (forces, displacements). In a real application, these inputs would come from ab initio calculations or experimental data. The `run()` method would then be called on the instantiated object to compute the force constants.

import numpy as np
from symfc.symfc import Symfc

# In a real scenario, these would come from your simulation or experiment.
# lattice: 3x3 matrix representing the supercell lattice vectors.
# positions: Nx3 array of atomic positions in fractional coordinates within the supercell.
# numbers: N array of atomic numbers for each atom in the supercell.
# forces: M x (N*3) array of forces for M displacement datasets.
# displacements: M x (N*3) array of displacements for M displacement datasets.

# --- Dummy Data for demonstration (replace with your actual data) ---
# Example: a 1-atom supercell (highly simplified, not practical for real phonon calcs)
num_atom_supercell = 1
num_displacement_datasets = 1

lattice = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
positions = np.array([[0.0, 0.0, 0.0]]) # Single atom at origin
numbers = np.array([1]) # Hydrogen atom

forces = np.random.rand(num_displacement_datasets, num_atom_supercell * 3)
displacements = np.random.rand(num_displacement_datasets, num_atom_supercell * 3)
dataset_weights = np.ones(num_displacement_datasets)
# --- End Dummy Data ---

# Instantiate the Symfc calculator
try:
    calculator = Symfc(
        forces=forces,
        displacements=displacements,
        supercell_lattice=lattice,
        supercell_positions=positions,
        supercell_numbers=numbers,
        # For this quickstart, assume primitive cell is the same as supercell
        primitive_lattice=lattice,
        primitive_positions=positions,
        primitive_numbers=numbers,
        dataset_weights=dataset_weights,
        physical_units=True # Set to False if your units are already compatible
    )
    print("Symfc object instantiated successfully.")

    # To compute force constants, you would typically call:
    # force_constants = calculator.run()
    # print("Force constants calculated (shape will vary):", force_constants.shape)

except Exception as e:
    print(f"Error instantiating Symfc: {e}")

view raw JSON →