gflownet.envs.crystals.spacegroup ================================= .. py:module:: gflownet.envs.crystals.spacegroup .. autoapi-nested-parse:: Classes to represent crystal environments Attributes ---------- .. autoapisummary:: gflownet.envs.crystals.spacegroup.CRYSTAL_LATTICE_SYSTEMS gflownet.envs.crystals.spacegroup.POINT_SYMMETRIES gflownet.envs.crystals.spacegroup.SPACE_GROUPS Classes ------- .. autoapisummary:: gflownet.envs.crystals.spacegroup.Prop gflownet.envs.crystals.spacegroup.SpaceGroup Module Contents --------------- .. py:data:: CRYSTAL_LATTICE_SYSTEMS :value: None .. py:data:: POINT_SYMMETRIES :value: None .. py:data:: SPACE_GROUPS :value: None .. py:class:: Prop Bases: :py:obj:`enum.Enum` Enumeration of the 3 properties of the SpaceGroup Environment: - Crystal lattice system - Point symmetry - Space group .. py:attribute:: CLS :value: 0 .. py:attribute:: PS :value: 1 .. py:attribute:: SG :value: 2 .. py:class:: SpaceGroup(space_groups_subset = None, n_atoms = None, policy_fmt = 'onehot', **kwargs) Bases: :py:obj:`gflownet.envs.base.GFlowNetEnv` :param space_groups_subset: 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. :type space_groups_subset: iterable :param n_atoms: 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. policy_fmt : str Specifies the policy encoding. Options: - onehot: One-hot encoding of each property (crystal-lattice system, point symmetry, space group), all concatenated to make the overall input. - indices: A three-dimensional vector with the indices of each property :type n_atoms: list of int (optional) .. py:attribute:: policy_fmt :value: 'onehot' .. py:attribute:: crystal_lattice_systems :value: None .. py:attribute:: point_symmetries :value: None .. py:attribute:: space_groups :value: None .. py:attribute:: cls_valid .. py:attribute:: ps_valid .. py:attribute:: sg_valid .. py:attribute:: properties .. py:attribute:: state_type_indices :value: [0, 1, 2, 3] .. py:attribute:: eos .. py:attribute:: source .. py:method:: get_action_space() 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). .. py:method:: get_mask_invalid_actions_forward(state = None, done = None) Returns a list of length the action space with values: - True if the forward action is invalid given the current state. - False otherwise. .. py:method:: states2proxy(states) Prepares a batch of states in "environment format" for the proxy: the proxy format is simply the space group. :param states: A batch of states in environment format, either as a list of states or as a single tensor. :type states: list or tensor :returns: *A tensor containing all the states in the batch.* .. py:method:: states2policy(states) Prepares a batch of states in "environment format" for the policy model, by calling the appropriate conversion method depending on the settings. :param states: A batch of states in environment format, that is a list of lists. :type states: list :returns: *A tensor containing the policy representation of all the states in the batch.* .. py:method:: states2policy_onehot(states) Prepares a batch of states in "environment format" for the policy model: states are one-hot encoded. In particular, the policy input for a state is a vector containing the following encodings, in this order: - One-hot encoding of the crystal-lattice system (max length 8). - One-hot encoding of the point symmetry (max length 5). - One-hot encoding of the space group (max length 230). Besides, the states in which each property has not been set yet are included as an additional class in the encoding. Thus, each property is one-hot encoded with a vector of length the number of classes in the property plus one. .. admonition:: Notes In order to not waste memory and for backward compatibility, the one-hot encodings have a maximum length equal to the maximum number of options in the configuration. To obtain the one-hot encoding of a given property index, while accounting for the fact that not all possible indices might be valid given the current configuration, we use torch.searchsorted, which receives as first input the valid set of indices and as second input the value to be encoded, and outputs the corresponding index. This index in then one-hot encoded. See: `torch.searchsorted `_ .. admonition:: Example Consider a configuration with valid space groups [1, 17, 39], and then valid crystal-lattice systems [1, 3] and valid point symmetries [1, 3, 4]. Additionally, each property can take the value 0 for the case where it is not set yet. states = [[0, 0, 0], [1, 1, 1], [3, 4, 17], [3, 3, 39]] self.states2policy(states) tensor( [ [1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1], ] ) :param states: A batch of states in environment format, that is a list of lists. :type states: list :returns: *A tensor containing the policy representation of all the states in the batch.* .. py:method:: state2readable(state=None) Transforms the state, represented as a list of property indices, into a human-readable string with the format: | | () | () | .. admonition:: 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 | .. py:method:: readable2state(readable) Converts a human-readable representation of a state into the standard format. See: state2readable .. py:method:: get_parents(state=None, done=None, action=None) Determines all parents and actions that lead to a state. :param state: :type state: list :param done: Whether the trajectory is done. If None, done is taken from instance. :type done: bool :param action: Ignored :type action: None :returns: * **parents** (*list*) -- List of parents in state format * **actions** (*list*) -- List of actions that lead to state for each parent in parents .. py:method:: step(action) Executes step given an action. :param action: Action to be executed. See: get_action_space() :type action: tuple :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. .. py:method:: get_crystal_system(state = None) Returns the name of the crystal system given a state. .. py:property:: crystal_system :type: str .. py:method:: get_lattice_system(state = None) Returns the name of the lattice system given a state. .. py:property:: lattice_system :type: str .. py:method:: get_crystal_lattice_system(state = None) Returns the name of the crystal-lattice system given a state. .. py:property:: crystal_lattice_system :type: str .. py:method:: get_point_symmetry(state = None) Returns the name of the point symmetry given a state. .. py:property:: point_symmetry :type: str .. py:method:: get_space_group_symbol(state = None) Returns the name of the space group symbol given a state. .. py:property:: space_group_symbol :type: str .. py:method:: get_space_group(state = None) Returns the index of the space group symbol given a state. .. py:property:: space_group :type: int .. py:method:: get_crystal_class(state = None) Returns the name of the crystal_class given a state. .. py:property:: crystal_class :type: str .. py:method:: get_point_group(state = None) Returns the name of the point group given a state. .. py:property:: point_group :type: str .. py:method:: get_state_type(state = None) 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 .. py:method:: set_n_atoms_compatibility_dict(n_atoms) 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() :param n_atoms: 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. :type n_atoms: list of int .. py:method:: build_n_atoms_compatibility_dict(n_atoms, space_groups) :staticmethod: 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. :param n_atoms: 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. :type n_atoms: list of int :param space_groups: A list of space group international numbers, in [1, 230] :type space_groups: list of int :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.* .. py:method:: get_all_terminating_states(apply_stoichiometry_constraints = True) .. py:method:: is_valid(x) Determines whether a state is valid, according to the attributes of the environment.