TMMC Class

The TMMC class serves as the main interface for handling TMMC simulation logic.

class flames.tmmc.TMMC(model, framework_atoms, adsorbate_atoms, temperature, pressure, device, vdw_radii, vdw_factor=0.6, max_overlap_tries=100, max_deltaE=25.0, save_frequency=100, output_to_file=True, output_folder=None, debug=False, random_seed=None, cutoff_radius=6.0)[source]

Bases: BaseSimulator

Base class for transition matrix Monte Carlo (TMMC) simulations using ASE.

This class implements TMMC deletion/insertion moves, recording the deletion/insertion energies of the adsorbate.

Parameters:
  • model (ase.calculators.calculator.Calculator) – The calculator to use for energy calculations. Can be any ASE-compatible calculator. The output of the calculator should be in eV.

  • framework_atoms (ase.Atoms) – The framework structure as an ASE Atoms object.

  • adsorbate_atoms (ase.Atoms) – The adsorbate structure as an ASE Atoms object.

  • temperature (float) – Temperature of the ideal reservoir in Kelvin.

  • pressure (float) – Pressure of the ideal reservoir in Pascal.

  • device (str) – Device to run the simulation on, e.g., 'cpu' or 'cuda'.

  • vdw_radii (np.ndarray) – Van der Waals radii for the atoms in the framework and adsorbate. Should be an array of the same length as the number of atomic numbers in ASE.

  • vdw_factor (float, optional) – Factor to scale the Van der Waals radii. Default is 0.6.

  • save_frequency (int, optional) – Frequency at which to save the simulation state and results. Default is 100.

  • output_to_file (bool, optional) – If True, writes the output to a file named output_{temperature}_{pressure}.out in the results directory. Default is True.

  • output_folder (str or None, optional) – Folder to save the output files. If None, a folder named results_<T>_<P> will be created.

  • debug (bool, optional) – If True, prints detailed debug information during the simulation. Default is False.

  • random_seed (int or None, optional) – Random seed for reproducibility. Default is None and will generate a random seed automatically if not provided.

  • cutoff_radius (float, optional) – Interaction potential cut-off radius used to estimate the minimum unit cell. Default is 6.0.

Max_overlap_tries:

Maximum tries for the insertion move. Default is 100.

get_framework_mass()

Calculate the mass of the framework in kg.

Returns:

The mass of the framework in kg.

Return type:

float

get_ideal_supercell()

Get the ideal supercell dimensions based on the cutoff radius.

Returns:

An array of three integers representing the number of unit cells in each dimension.

Return type:

np.ndarray

load_state(state_file)[source]

Load the state of the simulation from a file.

Parameters:

state_file (str) – Path to the file containing the saved state of the simulation.

Return type:

None

npt(nsteps, time_step=0.5, mode='iso_shape', driver='MTKNPT', set_momenta=True, output_interval=100, movie_interval=100, calculator=None, **kwargs)

Run a NPT simulation using the Berendsen thermostat and barostat.

Parameters:
  • nsteps (int) – Number of steps to run the NPT simulation.

  • time_step (float, optional) – Time step for the NPT simulation (default is 0.5 fs).

  • mode (str, optional) – The mode of the NPT simulation (default is “iso_shape”). Can be one of “iso_shape”, “aniso_shape”, or “aniso_flex”.

  • driver (str, optional) – The driver to use for the NPT simulation. Can be Berendsen, NoseHoover or MTKNPT (default is “MTKNPT”).

  • set_momenta (bool, optional) – Whether to set the atomic momenta to a Maxwell-Boltzmann distribution of the simulation temperature.

  • output_interval (int, optional) – The interval for logging output (default is 100 steps).

  • movie_interval (int, optional) – The interval for saving trajectory frames (default is 100 step).

  • calculator (ase.calculators.calculator.Calculator or None, optional) – The calculator to use for energy calculations. If None, the default model will be used.

  • kwargs (optional) – Arguments passed to the ase molecular dynamics class.

nvt(nsteps, time_step=0.5, set_momenta=True, output_interval=100, movie_interval=100, calculator=None, **kwargs)

Run a NVT simulation using the Berendsen thermostat.

Parameters:
  • nsteps (int) – Number of steps to run the NVT simulation.

  • time_step (float, optional) – Time step for the NVT simulation (default is 0.5 fs).

  • set_momenta (bool, optional) – Whether to set the atomic momenta to a Maxwell-Boltzmann distribution of the simulation temperature.

  • output_interval (int, optional) – The interval for logging output (default is 100 steps).

  • movie_interval (int, optional) – The interval for saving trajectory frames (default is 100 step).

  • calculator (ase.calculators.calculator.Calculator or None, optional) – The calculator to use for energy calculations. If None, the default model will be used.

  • kwargs (optional) – Arguments passed to the ase molecular dynamics class.

optimize_adsorbate(max_steps=1000, max_force=0.05)

Optimize the adsorbate structure using the provided calculator.

Parameters:
  • max_steps (int, optional) – Maximum number of optimization steps (default is 1000).

  • symm_tol (float, optional) – Tolerance for symmetry (default is 1e-3).

  • max_force (float, optional) – Maximum force tolerance for convergence (default is 0.05 eV/Å).

Returns:

The optimized adsorbate structure.

Return type:

ase.Atoms

optimize_framework(max_steps=1000, opt_cell=True, fix_symmetry=True, hydrostatic_strain=True, symm_tol=0.001, max_force=0.05)

Optimize the framework structure using the provided calculator.

Parameters:
  • max_steps (int, optional) – Maximum number of optimization steps (default is 1000).

  • tol (float, optional) – Tolerance for convergence (default is 1e-5).

Returns:

The optimized framework structure.

Return type:

ase.Atoms

restart()[source]

Restart the simulation from the last state.

This method loads the last saved state from the trajectory file and restores the simulation to that state. It also loads the uptake, total energy, and total adsorbates lists from the saved files if they exist.

Return type:

None

run(N)[source]

Run the transition matrix Monte Carlo simulation for N iterations.

Return type:

None

save_results(file_name=None)[source]

Save a json file with the main results of the simulation.

Parameters:

file_name (str) – Name of the output file. Default is ‘results_{T}_{n_adsorbates}.json’.

Return type:

None

set_adsorbate(adsorbate_atoms, adsorbate_energy=None, n_adsorbates=0)

Set the adsorbate structure for the simulation.

Parameters:
  • adsorbate_atoms (ase.Atoms) – The new adsorbate structure as an ASE Atoms object.

  • adsorbate_energy (float or None, optional) – The energy of the adsorbate in eV. If None, the energy will be calculated using the provided model.

  • n_adsorbates (int) – Number of adsorbate molecules in the framework.

Return type:

None

set_framework(framework_atoms, framework_energy=None)

Set the framework structure for the simulation.

Parameters:
  • framework_atoms (ase.Atoms) – The new framework structure as an ASE Atoms object.

  • framework_energy (float or None, optional) – The energy of the framework in eV. If None, the energy will be calculated using the provided model.

Return type:

None

set_state(state)

Set the current state of the simulation.

Parameters:

state (ase.Atoms) – The current state of the simulation as an ASE Atoms object.

Return type:

None

try_deletion()[source]

Try to delete an adsorbate molecule from the framework. This method randomly selects an adsorbate molecule and try to apply the deletion.

Returns:

Deletion energy.

Return type:

deltaE

try_insertion()[source]

Try to insert a new adsorbate molecule into the framework. This method randomly places the adsorbate in the framework and checks for van der Waals overlap. If there is no overlap, it calculates the new potential energy and decides whether to accept the insertion based on the acceptance criteria. If after a number of tries (self.max_overlap_tries) no valid position is found, the insertion is rejected.

Returns:

Insertion energy.

Return type:

deltaE

property base_iteration: int

Get the base iteration for the TMMC simulation.

Returns:

The base iteration count.

Return type:

int

property n_adsorbates: int

Get the number of adsorbates in the current system.

Returns:

The number of adsorbates.

Return type:

int