Trial Move Generators¶
Trial moves used in Monte Carlo (MC) sampling in Clease are provided from
clease.montecarlo.trial_move_generator.TrialMoveGenerator
classes.
The API¶
- class clease.montecarlo.trial_move_generator.TrialMoveGenerator(max_attempts: int = 10000)[source]¶
Class for producing trial moves.
- Parameters:
max_attempts – Maximum number of attempts to try to find a move that passes the constraints. If not constraints are added, this has no effect.
- add_constraint(cnst: MCConstraint)[source]¶
Add a constraint to the generator
- Parameters:
cnst – Constraint that must be satisfied for all trial moves
- abstract get_single_trial_move() Sequence[SystemChange] [source]¶
Return a single trial move, must be implemented in sub-classes
- get_trial_move() Sequence[SystemChange] [source]¶
Produce a trial move that is consistent with all cosntraints
- initialize(atoms: Atoms) None [source]¶
Initialize the generator.
- Parameters:
atoms – Atoms object used in the simulation
- on_move_accepted(changes: Sequence[SystemChange]) None [source]¶
Callback that is called by Monte Carlo after each accepted move
- param change:
Seqeunce of trial moves performed
- class clease.montecarlo.trial_move_generator.SingleTrialMoveGenerator(**kwargs)[source]¶
Interface class for generators that return only one type of trial moves
- class clease.montecarlo.trial_move_generator.RandomFlip(symbols: Set[str], atoms: Atoms, indices: List[int] | None = None, **kwargs)[source]¶
Generate trial moves where the symbol at a given site is flipped
- Parameters:
symbols – Set with all symbols considered in a move
atoms – Atoms object for the simulation
indices – List with all indices that should be considered. If None, all indices are considered
- class clease.montecarlo.trial_move_generator.RandomSwap(atoms: Atoms, indices: List[int] | None = None, **kwargs)[source]¶
Produce random swaps
- Parameters:
atoms – Atoms object in the MC simulation
indices – List with indices that can be chosen from. If None, all indices can be chosen.
- class clease.montecarlo.trial_move_generator.MixedSwapFlip(atoms: Atoms, swap_indices: Sequence[int], flip_indices: Sequence[int], flip_symbols: Sequence[str], flip_prob: float = 0.5, **kwargs)[source]¶
Class for generating trial moves in a mixed ensemble. A subset of the sites should maintain a constant concentrations, and a subset should maintain constant chemical potential. Thus, for the subset of sites where the concentration should be fixed, swap moves are proposed and for the subset that should have constant chemical potentia, flip moves are probosed (e.g. switching symbol type on a site)
- Parameters:
atoms – Atoms object used in the simulation
swap_indices – List of indices that constitue the sub-lattice that should have fixed concentration
flip_indices – List of indices that constitute the sub-lattice that should have fixed chemical potential
flip_symbols – List of possible symbols that can be substituted on the lattice with fixed chemical potential.
flip_prob – Probability of returning a flip move. The probability of returning a swap move is then 1 - flip_prob.
- get_single_trial_move() Sequence[SystemChange] [source]¶
Produce a single trial move. Return a swap move with probability
- on_move_accepted(changes: Sequence[SystemChange])[source]¶
Callback triggered when a move have been accepted.
- on_move_rejected(changes: Sequence[SystemChange]) None [source]¶
Callback triggered when a move have been accepted.
- property weights: Tuple[float]¶
The probability weights for each generator
- class clease.montecarlo.trial_move_generator.RandomFlipWithinBasis(symbols: Sequence[Sequence[str]], atoms: Atoms, indices: Sequence[Sequence[int]] | None = None, **kwargs)[source]¶
Produce trial moves consisting of flips within each basis. Each basis is defined by a list of indices.
- Parameters:
symbols – Sequence allowed symbols in each basis
atoms – Atoms object to be used in the simulation for which the trial moves are produced
indices – Sequence of sets of indices where each set specify the indices of a basis. Note len(symbols) == len(indices)
Example:
Create a generator for a rocksalt structure with two basis
>>> from ase.build import bulk >>> from clease.montecarlo import RandomFlipWithinBasis >>> atoms = bulk("LiO", crystalstructure="rocksalt", a=3.9)*(3, 3, 3) >>> basis1 = [a.index for a in atoms if a.symbol == "Li"] >>> basis2 = [a.index for a in atoms if a.symbol == "O"] >>> generator = RandomFlipWithinBasis([["Li", "X"], ["O", "V"]], atoms, [basis1, basis2])