gflownet.envs.crystals.composition ================================== .. py:module:: gflownet.envs.crystals.composition .. autoapi-nested-parse:: Classes to represent material compositions (stoichiometry) Attributes ---------- .. autoapisummary:: gflownet.envs.crystals.composition.N_ELEMENTS_ORACLE Classes ------- .. autoapisummary:: gflownet.envs.crystals.composition.Composition Module Contents --------------- .. py:data:: N_ELEMENTS_ORACLE :value: 94 .. py:class:: Composition(elements = 94, max_diff_elem = 5, min_diff_elem = 2, min_atoms = 2, max_atoms = 20, min_atom_i = 1, max_atom_i = 16, oxidation_states = None, alphabet = None, required_elements = (), space_group = None, do_charge_check = False, do_spacegroup_check = True, **kwargs) Bases: :py:obj:`gflownet.envs.base.GFlowNetEnv` :param elements: Elements that will be used for construction of crystal. Either list, in which case every value should indicate the atomic number of an element, or int, in which case n consecutive atomic numbers will be used. Note that we assume this will correspond to real atomic numbers, i.e. start from 1, not 0. :type elements: list or int :param max_diff_elem: Maximum number of unique elements in the crystal :type max_diff_elem: int :param min_diff_elem: Minimum number of unique elements in the crystal :type min_diff_elem: int :param min_atoms: Minimum number of atoms that needs to be used to construct a crystal :type min_atoms: int :param max_atoms: Maximum number of atoms that can be used to construct a crystal :type max_atoms: int :param min_atom_i: Minimum number of elements of each kind that needs to be used to construct a crystal :type min_atom_i: int :param max_atom_i: Maximum number of elements of each kind that can be used to construct a crystal :type max_atom_i: int :param oxidation_states: Mapping from ints (representing elements) to lists of different oxidation states :type oxidation_states: (optional) dict :param alphabet: Mapping from ints (representing elements) to strings containing human-readable elements' names :type alphabet: (optional) dict :param required_elements: List of elements that must be present in a crystal for it to represent a valid end state :type required_elements: (optional) list :param space_group: International number of a space group to be used for compatibility check, using pyxtal.symmetry.Group.check_compatible(). :type space_group: (optional) int :param do_charge_check: Whether to do neutral charge check and forbid compositions for which neutral charge is not possible. :type do_charge_check: bool :param do_spacegroup_check: Whether to do a space group compatibility check and forbid compositions with incompatible Wyckoff positions with the given space group. :type do_spacegroup_check: bool .. py:attribute:: elements .. py:attribute:: max_diff_elem :value: 5 .. py:attribute:: min_diff_elem :value: 2 .. py:attribute:: min_atoms :value: 2 .. py:attribute:: max_atoms :value: 20 .. py:attribute:: min_atom_i :value: 1 .. py:attribute:: max_atom_i :value: 16 .. py:attribute:: oxidation_states .. py:attribute:: alphabet .. py:attribute:: alphabet_rev .. py:attribute:: required_elements :value: () .. py:attribute:: space_group :value: None .. py:attribute:: do_charge_check :value: False .. py:attribute:: do_spacegroup_check :value: True .. py:attribute:: elem2idx .. py:attribute:: source .. py:attribute:: eos .. py:method:: set_space_group(space_group) Sets the space group. :param space_group: Space group number. :type space_group: int .. py:method:: get_action_space() Constructs list with all possible actions. An action is described by a tuple (element, n), indicating that the count of element will be set to n. .. py:method:: get_mask_invalid_actions_forward(state=None, done=None) Returns a vector of length the action space + 1: True if 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 output is a tensor of dtype long with N_ELEMENTS_ORACLE + 1 columns, where the positions of self.elements are filled with the number of atoms of each element in the state. :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: in order to not waste memory and for backward compatibility, the policy state only contains the number of atoms of the allowed elements. For example, if self.elements is [1, 2, 3, 4]: states: [{2: 1, 4: 2}, {1: 3}] states2policy(states): tensor([[0, 1, 0, 2], [3, 0, 0, 0]]) :param states: A batch of states in environment format, that is a list of dictionaries. :type states: list :returns: *A tensor containing all the states in the batch.* .. py:method:: state2readable(state=None) Transforms the state, represented as a dictionary of element: n_atoms key-value pairs, into a human-readable version: a non-reduced formula, following the Hill system. See: https://en.wikipedia.org/wiki/Chemical_formula#Hill_system .. admonition:: Example state: {1: 2, 3: 1} 1: atomic number of H 3: atomic number of Li output: H2Li1 .. py:method:: readable2state(readable) Converts the readable representation of a state (a chemical formula) into the environment format. .. admonition:: Example readable: H2Li1 self.alphabet: {1: "H", 2: "He", 3: "Li", 4: "Be"} output: {1: 2, 3: 1} .. py:method:: reset(env_id=None) Resets the environment. .. py:method:: get_parents(state=None, done=None, action=None) Determines all parents and actions that lead to a state. :param state: Representation of a state as a dictionary of element: n_atoms key-value pairs. Elements whose atomic number is not a key of the dictionary have zero atoms. :type state: dict :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 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_n_atoms_per_element(state = None) Returns the number of atoms per element. The result is returned as a list of integers, with no particular order. That is, the output does not allow to identify which element has how many atoms, since the intended use is mainly to check the compatibility with a space group. :param state: A state in environment format. If None, self.state is used. :type state: list :returns: *list* -- A list of integers containing the number of atoms per element in the state. .. py:method:: is_valid(state) Determines whether a state is valid, according to the attributes of the environment. :param state: A state in environment format. :type state: dict :returns: *bool* -- True if the state is valid according to the attributes of the environment; False otherwise.