mlff_attack.relaxation module

This module provides utilities for structure loading, MACE calculator setup, and geometry optimization (relaxation) of atomic structures.

MACE relaxation functionality.

mlff_attack.relaxation.get_optimizer_class(optimizer_name)[source]

Get the ASE optimizer class from name.

Parameters:

optimizer_name (str) – Name of optimizer (“BFGS” or “LBFGS”)

Returns:

ASE Optimizer class

Return type:

type

mlff_attack.relaxation.load_structure(input_path)[source]

Load structure from input file.

Parameters:

input_path (str or Path) – Path to input structure file (CIF, POSCAR, etc.)

Returns:

ASE Atoms object, or None if loading fails

Return type:

ase.Atoms or None

mlff_attack.relaxation.run_relaxation(atoms, traj_path, fmax=0.01, max_steps=300, optimizer='LBFGS')[source]

Run structural relaxation.

Parameters:
  • atoms (ase.Atoms) – ASE Atoms object with calculator attached

  • traj_path (str or Path) – Path to save trajectory file

  • fmax (float, optional) – Force convergence criterion (eV/Å), by default 0.01

  • max_steps (int, optional) – Maximum number of optimization steps, by default 300

  • optimizer (str, optional) – Name of optimizer to use (“BFGS” or “LBFGS”), by default “LBFGS”

Returns:

True if relaxation completed successfully, False otherwise

Return type:

bool

mlff_attack.relaxation.save_results(atoms, output_dir, base_name='relaxed')[source]

Save relaxed structure to output files.

Parameters:
  • atoms (ase.Atoms) – ASE Atoms object to save

  • output_dir (str or Path) – Output directory path

  • base_name (str, optional) – Base name for output files, by default “relaxed”

Returns:

Path to saved CIF file, or None if saving fails

Return type:

Path or None

mlff_attack.relaxation.setup_calculator(atoms, model_path, device='cuda', dtype_str='float64')[source]

Initialize and attach MACE calculator to atoms object.

Parameters:
  • atoms (ase.Atoms) – ASE Atoms object

  • model_path (str or Path or MACECalculator) – Path to MACE model file or existing MACECalculator instance

  • device (str, optional) – Device to use (cuda or cpu), by default “cuda”

  • dtype_str (str, optional) – Data type for calculations (“float32” or “float64”), by default “float64”

Returns:

ASE Atoms object with calculator attached, or None if setup fails

Return type:

ase.Atoms or None