gflownet.envs.crystals.spacegroup#

Classes to represent crystal environments

Module Contents#

Classes#

Prop

Enumeration of the 3 properties of the SpaceGroup Environment:

SpaceGroup

param space_groups_subset:

A subset of space group (international) numbers to which to restrict the

Attributes#

gflownet.envs.crystals.spacegroup.CRYSTAL_LATTICE_SYSTEMS[source]#
gflownet.envs.crystals.spacegroup.POINT_SYMMETRIES[source]#
gflownet.envs.crystals.spacegroup.SPACE_GROUPS[source]#
class gflownet.envs.crystals.spacegroup.Prop[source]#

Bases: enum.Enum

Enumeration of the 3 properties of the SpaceGroup Environment:
  • Crystal lattice system

  • Point symmetry

  • Space group

CLS = 0[source]#
PS = 1[source]#
SG = 2[source]#
class gflownet.envs.crystals.spacegroup.SpaceGroup(space_groups_subset=None, n_atoms=None, **kwargs)[source]#

Bases: gflownet.envs.base.GFlowNetEnv

Parameters:
  • space_groups_subset (iterable) – A subset of space group (international) numbers to which to restrict the state space. If None (default), the entire set of 230 space groups is considered.

  • n_atoms (list of int (optional)) – A list with the number of atoms per element, used to compute constraints on the space group. 0’s are removed from the list. If None, composition/space group constraints are ignored.

property crystal_system: str[source]#
Return type:

str

property lattice_system: str[source]#
Parameters:

state (List[int]) –

Return type:

str

property crystal_lattice_system: str[source]#
Return type:

str

property point_symmetry: str[source]#
Return type:

str

property space_group_symbol: str[source]#
Return type:

str

property space_group: int[source]#
Return type:

int

property crystal_class: str[source]#
Return type:

str

property point_group: str[source]#
Return type:

str

get_action_space()[source]#

Constructs list with all possible actions. An action is described by a tuple (property, index, state_from_type), where property is (0: crystal-lattice system, 1: point symmetry, 2: space group), index is the index of the property set by the action and state_from_type is the state type of the originating state (see self.state_type_indices).

get_mask_invalid_actions_forward(state=None, done=None)[source]#
Returns a list of length the action space with values:
  • True if the forward action is invalid given the current state.

  • False otherwise.

Parameters:
  • state (Optional[List]) –

  • done (Optional[bool]) –

Return type:

List

states2proxy(states)[source]#

Prepares a batch of states in β€œenvironment format” for the proxy: the proxy format is simply the space group.

Parameters:

states (list or tensor) – A batch of states in environment format, either as a list of states or as a single tensor.

Returns:

A tensor containing all the states in the batch.

Return type:

torchtyping.TensorType[batch, state_proxy_dim]

state2readable(state=None)[source]#

Transforms the state, represented as a list of property indices, into a human-readable string with the format:

<space group idx> | <space group symbol> | <crystal-lattice system> (<crystal-lattice system idx>) | <point symmetry> (<point symmetry idx>) <crystal class> | <point group>

Example

space group: 69 space group symbol: Fmmm crystal-lattice system: orthorhombic (3) point symmetry: centrosymmetric (2) crystal class: rhombic-dipyramidal point group: mmm output:

69 | Fmmm | orthorhombic (3) | centrosymmetric (2) | rhombic-dipyramidal | mmm |

readable2state(readable)[source]#

Converts a human-readable representation of a state into the standard format. See: state2readable

get_parents(state=None, done=None, action=None)[source]#

Determines all parents and actions that lead to a state.

Parameters:
  • state (list) –

  • done (bool) – Whether the trajectory is done. If None, done is taken from instance.

  • action (None) – Ignored

Returns:

  • parents (list) – List of parents in state format

  • actions (list) – List of actions that lead to state for each parent in parents

step(action)[source]#

Executes step given an action.

Parameters:

action (tuple) – Action to be executed. See: get_action_space()

Returns:

  • self.state (list) – The new state after executing the action

  • action (tuple) – Action executed

  • valid (bool) – False, if the action is not allowed for the current state.

Return type:

Tuple[List[int], Tuple[int, int], bool]

get_max_traj_length()[source]#
get_crystal_system(state=None)[source]#

Returns the name of the crystal system given a state.

Parameters:

state (List[int]) –

Return type:

str

get_lattice_system(state=None)[source]#

Returns the name of the lattice system given a state.

Parameters:

state (List[int]) –

Return type:

str

get_crystal_lattice_system(state=None)[source]#

Returns the name of the crystal-lattice system given a state.

Parameters:

state (List[int]) –

Return type:

str

get_point_symmetry(state=None)[source]#

Returns the name of the point symmetry given a state.

Parameters:

state (List[int]) –

Return type:

str

get_space_group_symbol(state=None)[source]#

Returns the name of the space group symbol given a state.

Parameters:

state (List[int]) –

Return type:

str

get_space_group(state=None)[source]#

Returns the index of the space group symbol given a state.

Parameters:

state (List[int]) –

Return type:

int

get_crystal_class(state=None)[source]#

Returns the name of the crystal_class given a state.

Parameters:

state (List[int]) –

Return type:

str

get_point_group(state=None)[source]#

Returns the name of the point group given a state.

Parameters:

state (List[int]) –

Return type:

str

get_state_type(state=None)[source]#

Returns the index of the type of the state passed as an argument. The state type is one of the following (self.state_type_indices):

0: both crystal-lattice system and point symmetry are unset (== 0) 1: crystal-lattice system is set (!= 0); point symmetry is unset 2: crystal-lattice system is unset; point symmetry is set 3: both crystal-lattice system and point symmetry are set

Parameters:

state (List[int]) –

Return type:

int

set_n_atoms_compatibility_dict(n_atoms)[source]#

Sets self.n_atoms_compatibility_dict by calling SpaceGroup.build_n_atoms_compatibility_dict(), which contains a dictionary of {space_group: is_compatible} indicating whether each space_group in space_groups is compatible with the stoichiometry defined by n_atoms.

See: build_n_atoms_compatibility_dict()

Parameters:

n_atoms (list of int) – A list of number of atoms for each element in a composition. 0s will be removed from the list since they do not count towards the compatibility with a space group.

static build_n_atoms_compatibility_dict(n_atoms, space_groups)[source]#

Obtains which space groups are compatible with the stoichiometry given as argument (n_atoms).

It relies on a function which, internally, calls pyxtal’s pyxtal.symmetry.Group.check_compatible(). Note that sometimes that pyxtal is known to return invalid results.

Parameters:
  • n_atoms (list of int) – A list of number of atoms for each element in a stoichiometry. 0s will be removed from the list since they do not count towards the compatibility with a space group. If None, all space groups will be marked as compatible.

  • space_groups (list of int) – A list of space group international numbers, in [1, 230]

Returns:

  • A dictionary of {space_group (is_compatible} indicating whether each)

  • space_group in space_groups is compatible with the stoichiometry defined by

  • n_atoms.

get_all_terminating_states(apply_stoichiometry_constraints=True)[source]#
Parameters:

apply_stoichiometry_constraints (Optional[bool]) –

Return type:

List[List]

is_valid(x)[source]#

Determines whether a state is valid, according to the attributes of the environment.

Parameters:

x (List) –

Return type:

bool