Monte Carlo

Canonical MC

The canonical Monte Carlo class has the following API:

class clease.montecarlo.montecarlo.Montecarlo(system: Atoms | MCEvaluator, temp: float, generator: TrialMoveGenerator | None = None)[source]

Class for running Monte Carlo at a fixed composition (canonical). For more information, also see the documentation of the parent class BaseMC.

Parameters:
  • system (Union[ase.Atoms, MCEvaluator]) – Either an ASE Atoms object with an attached calculator, or a pre-initialized MCEvaluator object.

  • temp (float) – Temperature of Monte Carlo simulation in Kelvin

  • generator (TrialMoveGenerator, optional) – A TrialMoveGenerator object that produces trial moves. Defaults to None.

add_bias(potential: BiasPotential)[source]

Add a new bias potential.

Parameters:

potential:

Potential to be added

attach(obs: MCObserver, interval: int = 1)[source]

Attach observers to be called on a given MC step interval.

Parameters:

obs: MCObserver

Observer to be added

interval: int

How often the observer should be called

count_atoms() Dict[str, int][source]

Count the number of each element.

property current_accept_rate: float

Return the current accept rate as a value between 0 and 1.

get_thermodynamic_quantities() Dict[str, Any][source]

Compute thermodynamic quantities.

initialize_run()[source]

Prepare MC object for a new run.

irun(steps: int, call_observers: bool = True) Iterator[MCStep][source]

Run Monte Carlo simulation as an iterator. Can be used to inspect the MC after each step, for example, to print the energy every 5 steps, one could do:

>>> mc = Montecarlo(...)  
>>> for mc_step in mc.irun(500):  
...     if mc_step.step % 5 == 0:
...         print(f"Current energy: {mc_step.energy:.2f} eV")

The iterator yields individual instances of MCStep for each step which is taken.

Parameters:

steps: int

Number of steps in the MC simulation

call_observers: bool

Should the observers be called during this run? Can be turned off for running burn-ins. The energy averagers will still be updated, even if this flag is disabled. Defaults to True.

iter_observers() Iterator[MCObserver][source]

Directly iterate the attached observers without also getting information about the interval.

property meta_info: Dict[str, str]

Return dict with meta info.

reset() None[source]

Reset all member variables to their original values.

reset_averagers() None[source]

Reset the energy averagers.

run(steps: int = 100, call_observers: bool = True) None[source]

Run Monte Carlo simulation.

Parameters:

steps: int

Number of steps in the MC simulation

call_observers: bool

Should the observers be called during this run? Can be turned off for running burn-ins. The energy averagers will still be updated, even if this flag is disabled. Defaults to True.

Semi-grand canonical MC

The semi-grand canonical (SGC) Monte Carlo class:

class clease.montecarlo.sgc_montecarlo.SGCMonteCarlo(atoms: Atoms, temp: float, symbols: Sequence[str] = (), generator: TrialMoveGenerator | None = None, observe_singlets: bool = False)[source]

Class for running Monte Carlo in the Semi-Grand Canonical Ensebmle (i.e., fixed number of atoms, but varying composition)

See the docstring of clease.montecarlo.Montecarlo

Parameters:
  • atoms – Atoms object (with CLEASE calculator attached!)

  • temp – Temperature in kelvin

  • symbols – Possible symbols to be used in swaps

  • generator – Generator that produces trial moves

get_thermodynamic_quantities(reset_eci: bool = False) Dict[str, Any][source]

Compute thermodynamic quantities.

Parameters:

reset_eci: bool

If True, the chemical potential will be removed from the ECIs.

reset()[source]

Reset the simulation object

reset_averagers() None[source]

Reset the energy averagers, including the internal SGC Observer

reset_eci()[source]

Return the ECIs.

run(steps: int = 10, call_observers: bool = True, chem_pot: Dict[str, float] | None = None)[source]

Run Monte Carlo simulation. See run()

Parameters:

chem_pot: dict

Chemical potentials. The keys should correspond to one of the singlet terms. A typical form of this is {“c1_0”:-1.0,c1_1_1.0}

singlet2composition(avg_singlets: Dict[str, float])[source]

Convert singlets to composition.