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]
Bases:
ABCClass 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.
- initialize(atoms: Atoms) None[source]
Initialize the generator.
- Parameters:
atoms – Atoms object used in the simulation
- property name
- add_constraint(cnst: MCConstraint)[source]
Add a constraint to the generator
- Parameters:
cnst – Constraint that must be satisfied for all trial moves
- abstractmethod 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
- class clease.montecarlo.trial_move_generator.SingleTrialMoveGenerator(**kwargs)[source]
Bases:
TrialMoveGenerator,ABCInterface class for generators that return only one type of trial moves
- CHANGE_NAME = None
- class clease.montecarlo.trial_move_generator.RandomFlip(symbols: Set[str], atoms: Atoms, indices: List[int] | None = None, **kwargs)[source]
Bases:
SingleTrialMoveGeneratorGenerate 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
- CHANGE_NAME = 'flip_move'
- class clease.montecarlo.trial_move_generator.RandomSwap(atoms: Atoms, indices: List[int] | None = None, **kwargs)[source]
Bases:
SingleTrialMoveGeneratorProduce 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.
- CHANGE_NAME = 'swap_move'
- 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]
Bases:
TrialMoveGeneratorClass 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.
- __init__(atoms: Atoms, swap_indices: Sequence[int], flip_indices: Sequence[int], flip_symbols: Sequence[str], flip_prob: float = 0.5, **kwargs) None[source]
- property generators: Tuple[SingleTrialMoveGenerator]
- property weights: Tuple[float]
The probability weights for each generator
- get_single_trial_move() Sequence[SystemChange][source]
Produce a single trial move. Return a swap move with probability
- class clease.montecarlo.trial_move_generator.RandomFlipWithinBasis(symbols: Sequence[Sequence[str]], atoms: Atoms, indices: Sequence[Sequence[int]] | None = None, **kwargs)[source]
Bases:
SingleTrialMoveGeneratorProduce 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])
- CHANGE_NAME = 'flip_within_basis_move'