GroupSelector contains parent classes for all group selectors. A GroupSelector is used at the stochastic engine’s runtime to select groups upon which a move will be applied. Therefore it has become possible to fully customize the selection of groups of atoms and to choose when and how frequently a group can be chosen to perform a move upon.

Inheritance diagram of fullrmc.Core.GroupSelector
class fullrmc.Core.GroupSelector.GroupSelector(engine=None)

Bases: object

Group selector is the parent class that selects groups to perform moves at stochastic engine’s runtime.

Parameters:
  1. engine (None, fullrmc.Engine): Selector’s stochastic engine instance.
engine

Stochastic engine’s instance.

refine

Get refine flag value. It will always return False because refine is a property of RecursiveGroupSelector instances only.

explore

Get explore flag value. It will always return False because explore is a property of RecursiveGroupSelector instances only.

willSelect

Get whether next step a new selection is occur or still the same group is going to be selected again. It will always return True because recurrence is a property of RecursiveGroupSelector instances only.

willRecur

Get whether next step the same group will be returned. It will always return False because this is a property of RecursiveGroupSelector instances only.

willRefine

Get whether selection is recurring and refine flag is True. It will always return False because recurrence is a property of RecursiveGroupSelector instances only.

willExplore

Get whether selection is recurring and explore flag is True. It will always return False because recurrence is a property of RecursiveGroupSelector instances only.

isNewSelection

Get whether the last step a new selection was made. It will always return True because recurrence is a property of RecursiveGroupSelector instances only.

isRecurring

Get whether the last step the same group was returned. It will always return False because this is a property of RecursiveGroupSelector instances only.

isRefining

Get whether selection is recurring and refine flag is True. It will always return False because recurrence is a property of RecursiveGroupSelector instances only.

isExploring

Get whether selection is recurring and explore flag is True. It will always return False because recurrence is a property of RecursiveGroupSelector instances only.

set_engine(engine)

Set selector’s stochastic engine instance.

Parameters:
  1. engine (None, fullrmc.Engine): Selector’s stochastic engine.
select_index()

This method must be overloaded in every GroupSelector sub-class

Returns:
  1. index (integer): the selected group index in engine groups list.
move_accepted(index)

This method is called by the stochastic engine when a move generated on a group is accepted. This method is empty must be overloaded when needed.

Parameters:
  1. index (integer): the selected group index in engine groups list.
move_rejected(index)

This method is called by the stochastic engine when a move generated on a group is rejected. This method is empty must be overloaded when needed.

Parameters:
  1. index (integer): the selected group index in engine groups list.
class fullrmc.Core.GroupSelector.RecursiveGroupSelector(selector, recur=10, override=True, refine=False, explore=False)

Bases: fullrmc.Core.GroupSelector.GroupSelector

Recursive selector is the only selector that can use the recursive property on a selection. It is used as a wrapper around a GroupSelector instance.

Parameters:
  1. selector (fullrmc.Core.GroupSelector.GroupSelector): The selector instance to wrap.
  2. recur (integer): Set number of times to recur. It must be a positive integer.
  3. override (boolean): Override temporary recur value. recur value will be overridden only when selected group move generator is a PathGenerator instance. In this particular case, recur value will be temporary changed to the number of moves stored in the PathGenerator. If selected group move generator is not a PathGenerator instance, recur value will take back its original value.
  4. refine (boolean): Its an engine flag that is used to refine the position of a group until recurrence expires and a new group is selected. Refinement is done by applying moves upon the selected group always from its initial position at the time it was selected until recurrence expires, then the best position is kept.
  5. explore (boolean): Its an engine flag that is used to make a group explore the space around it until recurrence expires and a new group is selected. Exploring is done by applying moves upon the selected group starting from its initial position and evolving in a trajectory like way until recurrence expires, then the best position is kept.

NB: refine and explore flags can’t both be set to True at the same time. When this happens refine flag gets automatically switched to False. The usage of those flags is very important because they allow groups of atoms to go out of local minima in the energy surface. The way traditional reverse mote carlo works is by minimizing the total energy of the system (error) using gradient descent method. Using of those flags allows the system to go up hill in the energy surface searching for other lower minimas, while always conserving the lowest energy state found and not changing the system structure until a better structure with smaller error is found.

The following video compares the Reverse Monte Carlo traditional fitting mode with fullrmc's recursive selection one with explore flag set to True. From a potential point of view, exploring allows to cross forbidden unlikely energy barriers and going out of local minimas.

The following video is an example of refining the position of a molecule using RecursiveGroupSelector and setting refine flag to True. The molecule is always refined from its original position towards a new one generated by the move generator.

The following video is an example of exploring the space of a molecule using RecursiveGroupSelector and setting explore flag to True. The molecule explores the allowed space by wandering via its move generator and only moves enhancing the structure are stored.

# import fullrmc modules
from fullrmc.Engine import Engine
from fullrmc.Core.GroupSelector import RecursiveGroupSelector

# create engine
ENGINE = Engine(path='my_engine.rmc')

# set pdb file
ENGINE.set_pdb('system.pdb')

# Add constraints ...
# Re-define groups if needed ...
# Re-define groups selector if needed ...

##### Wrap engine group selector with a recursive group selector. #####
# create recursive group selector. Recurrence is set to 20 with explore flag set to True.
RGS = RecursiveGroupSelector(ENGINE.groupSelector, recur=20, refine=False, explore=True)
ENGINE.set_group_selector(RGS)
selector

The wrapped selector instance.

lastSelectedIndex

The last selected group index.

willSelect

Get whether next step a new selection is occur or still the same group is going to be selected again.

willRecur

Get whether next step the same group will be returned.

willRefine

Get whether next step the same group will be returned and refine flag is True.

willExplore

Get whether next step the same group will be returned and explore flag is True.

isNewSelection

Get whether this last step a new selection was made.

isRecurring

Get whether this last step the same group was returned.

isRefining

Get whether this last step the same group was returned and refine flag is True.

isExploring

Get whether this last step the same group was returned and explore flag is True.

override

Override flag value.

refine

Refine flag value.

explore

Explore flag value.

currentRecur

The current recur value which is selected group dependant when override flag is True.

recur

The current recur value. The set recur value can change during engine runtime if override flag is True. To get the recur value as set by set_recur method recurAsSet must be used.

recurAsSet

Get recur value as set but set_recur method.

position

Get the position of the selector in the path.

engine

Get the wrapped selector engine instance.

set_engine(engine)

Sets the wrapped selector stochastic engine instance.

Parameters:
  1. engine (None, fullrmc.Engine): The selector stochastic engine.
set_recur(recur)

Sets the recur value.

Parameters:
  1. recur (integer): Set the recur value. It must be a positive integer.
set_override(override)

Select override value.

Parameters:
  1. override (boolean): Override selector recur value only when selected group move generator is a PathGenerator instance. Overridden recur value is temporary and totally selected group dependant. If selected group move generator is not a PathGenerator instance, recur value will take back selector’s recur value.
set_refine(refine)

Select override value.

Parameters:
  1. refine (boolean): Its an engine flag that is used to refine the position of a group until recurrence expires and a new group is selected. Refinement is done by applying moves upon the selected group always from its initial position at the time it was selected until recurrence expires, then the best position is kept.
set_explore(explore)

Select override value.

Parameters:
  1. explore (boolean): Its an engine flag that is used to make a group explore the space around it until recurrence expires and a new group is selected. Exploring is done by applying moves upon the selected group starting from its initial position and evolving in a trajectory like way until recurrence expires, then the best position is kept.
select_index()

Select new index.

Returns:
  1. index (integer): the selected group index in engine groups list.

fullrmc.Selectors package

OrderedSelectors

OrderedSelectors contains GroupSelector classes of defined order of selection.

Inheritance diagram of fullrmc.Selectors.OrderedSelectors
class fullrmc.Selectors.OrderedSelectors.DefinedOrderSelector(engine, order=None)

Bases: fullrmc.Core.GroupSelector.GroupSelector

DefinedOrderSelector is a group selector with a defined order of selection.

Parameters:
  1. engine (None, fullrmc.Engine): The selector stochastic engine.
  2. order (None, list, set, tuple, numpy.ndarray): The selector order of groups. If None, order is set automatically to all groups indexes list.
# import external libraries
import numpy as np

# import fullrmc modules
from fullrmc.Engine import Engine
from fullrmc.Selectors.OrderedSelectors import DefinedOrderSelector

# create engine
ENGINE = Engine(path='my_engine.rmc')

# set pdb file
ENGINE.set_pdb('system.pdb')

# Add constraints ...
# Re-define groups if needed ...
# Re-define groups generators as needed ...

##### set the order of selection from closest to the origin to the further. #####
# compute groups centers
centers   = [np.sum(ENGINE.realCoordinates[g.indexes], axis=0)/len(g) for g in ENGINE.groups]
# compute distances to origin
distances = [np.sqrt(np.add.reduce(c**2)) for c in centers]
# compute increasing order
order     = np.argsort(distances)
# set group selector
ENGINE.set_group_selector( DefinedOrderSelector(engine=ENGINE, order=order) )
order

List copy of the order of selection.

index

The current selection index.

set_order(order)

Set selector groups order.

Parameters:
  1. order (None, list, set, tuple, numpy.ndarray): The selector order of groups.
select_index()

Select index.

Returns:
  1. index (integer): The selected group index in engine groups list.
class fullrmc.Selectors.OrderedSelectors.DirectionalOrderSelector(engine, center=None, expand=True, adjustMoveGenerators=False, generatorsParams={'RG': {'amplitude': 10}, 'TG': {'amplitude': 0.1, 'angle': 90, 'damping': 0.1}})

Bases: fullrmc.Selectors.OrderedSelectors.DefinedOrderSelector

DirectionalOrderSelector is a group selector with a defined order of selection. The order of selection is computed automatically at engine runtime by computing Groups distance to center, and setting the order from the further to the closest if expand argument is True or from the closest to the further if expand is False.

Parameters:
  1. engine (None, fullrmc.Engine): The selector stochastic engine.

  2. center (None, list, set, tuple, numpy.ndarray): The center of expansion. If None, the center is automatically set to the origin (0,0,0).

  3. expand (bool): Whether to set the order from the the further to the closest or from the closest to the further if it is set to False.

  4. adjustMoveGenerators (bool): If set to True, all groups move generator instances will be changed automatically at engine runtime to a MoveGeneratorCollector of TranslationTowardsCenterGenerator and a randomRotation (for only more than 2 atoms groups). Generators parameters can be given by generatorsParams. It is advisable to set this flag to True in order to take advantage of an automatic and intelligent directional moves.

  5. generatorsParams (None, dict): The automatically created moves generators parameters. If None is given, default parameters are used. If a dictionary is given, only two keys are allowed. ‘TG’ key is for TranslationTowardsCenterGenerator parameters and ‘RG’ key is for RotationGenerator parameters. TranslationTowardsCenterGenerator amplitude parameter is not the same for all groups but intelligently allowing certain groups to move more than others according to damping parameter.

    Parameters are the following:

    • TG_amp = generatorsParams[‘TG’][‘amplitude’]: Used for TranslationTowardsCenterGenerator amplitude parameters.
    • TG_ang = generatorsParams[‘TG’][‘angle’]: Used as TranslationTowardsCenterGenerator angle parameters.
    • TG_dam = generatorsParams[‘TG’][‘damping’]: Also used for TranslationTowardsCenterGenerator amplitude parameters.
    • RG_ang = generatorsParams[‘RG’][‘amplitude’]: Used as RotationGenerator angle parameters.

    Parameters are used as the following:

    • TG = TranslationTowardsCenterGenerator(center={“fixed”:center}, amplitude=AMPLITUDE, angle=TG_ang)

      Where TG_amp < AMPLITUDE < TG_amp.TG_dam

    • RG = RotationGenerator(amplitude=RG_ang)

    • MoveGeneratorCollector(collection=[TG,RG], randomize=True)

    NB: The parameters are not checked for errors until engine runtime.

# import fullrmc modules
from fullrmc.Engine import Engine
from fullrmc.Selectors.OrderedSelectors import DirectionalOrderSelector

# create engine
ENGINE = Engine(path='my_engine.rmc')

# set pdb file
ENGINE.set_pdb('system.pdb')

# Add constraints ...
# Re-define groups if needed ...
# Re-define groups generators as needed ...

# Set the order of selection from further to the closest to a (1,1,1).
# Automatically adjust the groups move generators allowing modulation of amplitudes.
ENGINE.set_group_selector( DirectionalOrderSelector(engine = ENGINE,
                                                    center = (1,1,1),
                                                    adjustMoveGenerators = True) )
expand

expand flag.

center

center (X,Y,Z) coordinates.

adjustMoveGenerators

adjustMoveGenerators flag.

generatorsParams

Automatic generators parameters.

set_generators_parameters(generatorsParams)

Set move generators parameters.

  1. generatorsParams (None, dict): The automatically created moves generators parameters. If None is given, default parameters are used. If a dictionary is given, only two keys are allowed. ‘TG’ key is for TranslationTowardsCenterGenerator parameters and ‘RG’ key is for RotationGenerator parameters. TranslationTowardsCenterGenerator amplitude parameter is not the same for all groups but intelligently allowing certain groups to move more than others according to damping parameter.

    Parameters are the following:

    • TG_amp = generatorsParams[‘TG’][‘amplitude’]: Used for TranslationTowardsCenterGenerator amplitude parameters.
    • TG_ang = generatorsParams[‘TG’][‘angle’]: Used as TranslationTowardsCenterGenerator angle parameters.
    • TG_dam = generatorsParams[‘TG’][‘damping’]: Also used for TranslationTowardsCenterGenerator amplitude parameters.
    • RG_ang = generatorsParams[‘RG’][‘amplitude’]: Used as RotationGenerator angle parameters.

    Parameters are used as the following:

    • TG = TranslationTowardsCenterGenerator(center={“fixed”:center}, amplitude=AMPLITUDE, angle=TG_ang)

      Where TG_amp < AMPLITUDE < TG_amp.TG_dam

    • RG = RotationGenerator(amplitude=RG_ang)

    • MoveGeneratorCollector(collection=[TG,RG], randomize=True)

    NB: The parameters are not checked for errors until engine runtime.

set_center(center)

Set the center.

Parameters:
  1. center (None, list, tuple, numpy.ndarray): The center of expansion. If None, the center is automatically set to the origin (0,0,0).
set_expand(expand)

Set expand.

Parameters:
  1. expand (bool): Whether to set the order from the the further to the closest or from the closest to the further if it is set to False.
set_adjust_move_generators(adjustMoveGenerators)

Set expand.

Parameters:
  1. adjustMoveGenerators (bool): If set to True, all groups move generator instances will be changed automatically at engine runtime to a MoveGeneratorCollector of TranslationTowardsCenterGenerator and a randomRotation (for only more than 2 atoms groups). Generators parameters can be given by generatorsParams. It is advisable to set this flag to True in order to take advantage of an automatic and intelligent directional moves.

RandomSelectors

RandomSelectors contains GroupSelector classes of random order of selections.

Inheritance diagram of fullrmc.Selectors.RandomSelectors
Machine learning on group selection is shown herein. Groups are set to single atom where only random translation moves generators with different amplitudes are used allowing moves to be accepted in different ratios. In those two examples SmartRandomSelector allowing machine learning upon group selection. No experimental constraints are used but only inter-molecular distances, intra-molecular bonds, angles and improper angles constraints are used to keep the integrity of the system and molecules. As one can see, group selection machine learning is very effective allowing consequent improvement on the accepted moves. Still, fast convergence of the system and the ratio of accepted moves is highly correlated with the move generator assigned to the groups.
_images/machineLearningSelectionAmp0p3.png

25% of assigned moves generators amplitude is set to 10A allowing very few moves on those groups to be accepted and the rest of moves generators amplitudes is set to 0.3A.

_images/machineLearningSelectionAmp0p25.png

25% of assigned moves generators amplitude is set to 10A allowing very few moves on those groups to be accepted and the rest of moves generators amplitudes is set to 0.25A.

class fullrmc.Selectors.RandomSelectors.RandomSelector(engine=None)

Bases: fullrmc.Core.GroupSelector.GroupSelector

RandomSelector generates indexes randomly for engine group selection.

Parameters:
  1. engine (None, fullrmc.Engine): The selector fullrmc engine instance.
 # import external libraries
 import numpy as np

 # import fullrmc modules
 from fullrmc.Engine import Engine
 from fullrmc.Selectors.RandomSelectors import RandomSelector

# create engine
 ENGINE = Engine(path='my_engine.rmc')

 # set pdb file
 ENGINE.set_pdb('system.pdb')

 # Add constraints ...
 # Re-define groups if needed ...
 # Re-define groups generators as needed ...

 # set group selector as random selection from all defined groups.
 ENGINE.set_group_selector( RandomSelector(engine=ENGINE) )
select_index()

Select index.

Returns:
  1. index (integer): the selected group index in engine groups list
class fullrmc.Selectors.RandomSelectors.WeightedRandomSelector(engine, weights=None)

Bases: fullrmc.Selectors.RandomSelectors.RandomSelector

WeightedRandomSelector generates indexes randomly following groups weighting scheme.

Parameters:
  1. engine (fullrmc.Engine): The selector stochastic engine.
  2. weights (None, list): Weights list. It must be None for equivalent weighting or list of (groupIndex, weight) tuples.
# import fullrmc modules
from fullrmc.Engine import Engine
from fullrmc.Selectors.RandomSelectors import WeightedRandomSelector

# create engine
ENGINE = Engine(path='my_engine.rmc')

# set pdb file
ENGINE.set_pdb('system.pdb')

# Add constraints ...
# Re-define groups if needed ...
# Re-define groups generators as needed ...

# set group selector as random selection but with double likelihood to
# selecting the first and the last group.
WEIGHTS = [[idx,1] for idx in range(len(ENGINE.groups))]
WEIGHTS[0][1] = WEIGHTS[-1][1] = 2
ENGINE.set_group_selector( WeightedRandomSelector(engine=ENGINE, weights=WEIGHTS) )
weights

Groups weight of selection as initialized.

groupsWeight

Groups weight of selection at current state.

selectionScheme

Groups selection scheme used upon group selection.

set_weights(weights)

Set groups selection weighting scheme.

Parameters:
  1. weights (None, list): Weights list. It must be None for equivalent weighting or list of (groupIndex, weight) tuples.
set_group_weight(groupWeight)

Set a single group weight.

Parameters:
  1. groupWeight (list, set, tuple): Group weight list composed of groupIndex as first element and groupWeight as second.
select_index()

Select index.

Returns:
  1. index (integer): the selected group index in engine groups list
class fullrmc.Selectors.RandomSelectors.SmartRandomSelector(engine, weights=None, biasFactor=1, unbiasFactor=None)

Bases: fullrmc.Selectors.RandomSelectors.WeightedRandomSelector

SmartRandomSelector is a random group selector fed with machine learning algorithm. The indexes generation is biased and it evolves throughout the simulation towards selecting groups with more successful moves history.

Parameters:
  1. engine (fullrmc.Engine): The selector stochastic engine.
  2. weights (None, list): Weights list fed as initial biasing scheme. It must be None for equivalent weighting or list of (groupIndex, weight) tuples.
  3. biasFactor (Number): The biasing factor of every group when a step get accepted. Must be a positive number.
  4. unbiasFactor(None, Number): Whether to un-bias a group’s weight when a move is rejected. If None, un-biasing is turned off. Un-biasing will be performed only if group weight remains positive.
# import fullrmc modules
from fullrmc.Engine import Engine
from fullrmc.Selectors.RandomSelectors import SmartRandomSelector

# create engine
ENGINE = Engine(path='my_engine.rmc')

# set pdb file
ENGINE.set_pdb('system.pdb')

# Add constraints ...
# Re-define groups if needed ...
# Re-define groups generators as needed ...

# set group selector as random smart selection that will adjust its
# weighting scheme to improve the chances of moves getting accepted.
ENGINE.set_group_selector( SmartRandomSelector(engine=ENGINE) )
biasFactor

The biasing factor.

unbiasFactor

The unbiasing factor.

set_bias_factor(biasFactor)

Set the biasing factor.

Parameters:
  1. biasFactor (Number): The biasing factor of every group when a step get accepted. Must be a positive number.
set_unbias_factor(unbiasFactor)

Set the unbiasing factor.

Parameters:
  1. unbiasFactor(None, Number): Whether to unbias a group’s weight when a move is rejected. If None, unbiasing is turned off. Unbiasing will be performed only if group weight remains positive.
move_accepted(index)

This method is called by the engine when a move generated on a group is accepted. This method is empty must be overloaded when needed.

Parameters:
  1. index (integer): the selected group index in engine groups list
move_rejected(index)

This method is called by the engine when a move generated on a group is rejected. This method is empty must be overloaded when needed.

Parameters:
  1. index (integer): the selected group index in engine groups list
select_index()

Select index.

Returns:
  1. index (integer): the selected group index in engine groups list
fullrmc.Selectors.RandomSelectors.generate_random_float()

random() -> x in the interval [0, 1).