gflownet.envs.crystals.lattice_parameters ========================================= .. py:module:: gflownet.envs.crystals.lattice_parameters .. autoapi-nested-parse:: Classes to represent continuous lattice parameters environments. An implementation for discrete lattice parameters preceded this one but has been removed for simplicity. Check commit 9f3477d8e46c4624f9162d755663993b83196546 to see these changes or the history previous to that commit to consult previous implementations. Attributes ---------- .. autoapisummary:: gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEM_INDEX gflownet.envs.crystals.lattice_parameters.LENGTH_PARAMETER_NAMES gflownet.envs.crystals.lattice_parameters.ANGLE_PARAMETER_NAMES gflownet.envs.crystals.lattice_parameters.PARAMETER_NAMES gflownet.envs.crystals.lattice_parameters.IGNORED_DIMS gflownet.envs.crystals.lattice_parameters.B1 gflownet.envs.crystals.lattice_parameters.B2 gflownet.envs.crystals.lattice_parameters.B3 gflownet.envs.crystals.lattice_parameters.B4 gflownet.envs.crystals.lattice_parameters.B5 gflownet.envs.crystals.lattice_parameters.B6 Classes ------- .. autoapisummary:: gflownet.envs.crystals.lattice_parameters.LatticeParameters gflownet.envs.crystals.lattice_parameters.LatticeParametersSGCCG Module Contents --------------- .. py:data:: LATTICE_SYSTEM_INDEX .. py:data:: LENGTH_PARAMETER_NAMES :value: ('a', 'b', 'c') .. py:data:: ANGLE_PARAMETER_NAMES :value: ('alpha', 'beta', 'gamma') .. py:data:: PARAMETER_NAMES :value: ('a', 'b', 'c', 'alpha', 'beta', 'gamma') .. py:data:: IGNORED_DIMS .. py:data:: B1 .. py:data:: B2 .. py:data:: B3 .. py:data:: B4 .. py:data:: B5 .. py:data:: B6 .. py:class:: LatticeParameters(lattice_system, min_length = 1.0, max_length = 350.0, min_angle = 50.0, max_angle = 150.0, **kwargs) Bases: :py:obj:`gflownet.envs.composite.stack.Stack` :param lattice_system: One of the seven lattice systems. By default, the triclinic lattice system is used, which has no constraints. :type lattice_system: str :param min_length: Minimum value of the lengths. :type min_length: float :param max_length: Maximum value of the lengths. :type max_length: float :param min_angle: Minimum value of the angles. :type min_angle: float :param max_angle: Maximum value of the angles. :type max_angle: float .. py:attribute:: continuous :value: True .. py:attribute:: min_length :value: 1.0 .. py:attribute:: max_length :value: 350.0 .. py:attribute:: length_range :value: 349.0 .. py:attribute:: min_angle :value: 50.0 .. py:attribute:: max_angle :value: 150.0 .. py:attribute:: angle_range :value: 100.0 .. py:attribute:: condition .. py:attribute:: idx_condition :value: 0 .. py:attribute:: cube .. py:attribute:: idx_cube :value: 1 .. py:attribute:: source_cube_value .. py:method:: get_lattice_system_idx(state) Returns the lattice system index, retrieved from the condition state. :param state: A state in environment format. :type state: dict :returns: *int* -- The index of the lattice system contained in the condition state. .. py:method:: get_lattice_system(state) Returns the lattice system name, retrieved from the condition state. :param state: A state in environment format. :type state: dict :returns: *str* -- The name of the lattice system contained in the condition state. .. py:method:: set_lattice_system(lattice_system, state = None) Sets the lattice system of the unit cell as the condition of the environment. If the input state is not None, it is updated with the given lattice system. Otherwise ``self.state`` is updated. :param lattice_system: The index of the lattice system, as stored in :py:const:`gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEMS` or the string identifier. :type lattice_system: int or str :param state: A state in environment format. :type state: dict (optional) :returns: *state* -- The input state updated with the given lattice system. This is a state of the LatticeParameters environment in environment format. .. py:property:: lattice_system_idx :type: int Returns the lattice system index of the environment as per ``self.state``. :returns: *int* -- The index of the lattice system contained in the condition state. .. py:property:: lattice_system :type: str Returns the name of the lattice system of the environment as per ``self.state``. :returns: *str* -- The name of the lattice system contained in the condition state. .. py:method:: apply_lattice_constraints(state, lattice_system) Applies lattice system constraints to a single cube state. The input state is expected to be a state of the ContinuousCube in environment format. :param state: A state of the ContinuousCube in environment format. :type state: dict :param lattice_system: The index of the lattice system, as stored in :py:const:`gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEMS` or the string identifier. :type lattice_system: int or str :returns: * **a, b, c** (*float*) -- Lattice lengths of the state, in angstroms. * **alpha, beta, gamma** (*float*) -- Lattice angles, in degrees. .. py:method:: revert_lattice_constraints(parameters, lattice_system) Reverts lattice system constraints to a set of lattice parameters. The output is in the format of a ContinuousCube state in environment format, with the parameters in the [0, 1] range. :param parameters: A list of lattice parameters in angstroms and degrees. :type parameters: list :param lattice_system: The index of the lattice system, as stored in :py:const:`gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEMS` or the string identifier. :type lattice_system: int or str :returns: **state** (*list*) -- A ContinuousCube state in environment format. .. py:method:: apply_lattice_constraints_batch(states, lattice_system) :staticmethod: Applies lattice system constraints to a batch of states. The input states are expected to be a tensor with values already mapped from [0; 1] to `min_length`, `max_length`, `min_angle` and `max_angle`. Depending on the lattice system passed as an input, the corresponding constraints are applied to the entire batch. states : tensor A batch of ContinuousCube states (6D) in an intermediate format between the environment states and the proxy format. The values of the states are assumed to be already converted into lattice parameters with the correct units (angstroms and angles), but no lattice system constraints. lattice_system : int The index of the lattice system, as stored in :py:const:`gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEMS` or the string identifier. .. py:method:: states2proxy(states) Prepares a batch of states in environment format for a proxy. The proxy representation is the Cube states, mapped from [0; 1] to edge lengths and angles using min_length, max_length, min_angle and max_angle, via _statevalue2length() and _statevalue2angle(). Furthermore, the lattice system constraints are applied to the lenghts and angles. The batch may contain states with different lattice systems (conditions). The constraints are applied by taking the lattice system from the state (the Dummy part of the Stack). Paramters --------- 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.* .. py:method:: states2policy(states) Prepares a batch of states in "environment format" for the policy model. The policy representation is identical to that of the Cube environment and it is agnostic to the lattice system. Also, the action of the condition (Dummy) environment is deterministic. Therefore, instead of using the Stack's method, the Cube part of the states is first extracted and then the entire batch is converted into the policy representation using the Cube environment. :param states: A batch of states in environment format. :type states: list :returns: *A tensor containing all the states in the batch.* .. py:method:: state2readable(state = None) Converts the state into a human-readable string in the format "(a, b, c), (alpha, beta, gamma)". :param state: A state in environment format. :type state: dict :returns: *str* -- A human-readable version of the state. .. py:method:: readable2state(readable) Converts a human-readable representation of a state into the standard format. :param readable: A human-readable version of a state. :type readable: str :returns: **state** (*dict*) -- A state in environment format. .. 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. If None, then lengths and angles will be used instead. :type state: dict :returns: *bool* -- True if the state is valid according to the attributes of the environment; False otherwise. .. py:method:: get_grid_terminating_states(n_states, kappa = None) Constructs a grid of terminating states within the range of the hyper-cube. This method uses the Cube's corresponding method to generate the Cube states, and then creates LatticeParameters states from them. :param n_states: Requested number of states. The actual number of states will be rounded up such that all dimensions have the same number of states. :type n_states: int :param kappa: Small constant indicating the distance to the theoretical limits of the cube [0, 1], in order to avoid innacuracies in the computation of the log probabilities due to clamping. The grid will thus be in [kappa, 1 - kappa]. If None, self.kappa will be used. :type kappa: float .. py:method:: get_uniform_terminating_states(n_states, seed = None, kappa = None) Constructs a set of terminating states sampled uniformly within the range of the hyper-cube. This method uses the Cube's corresponding method to generate the Cube states, and then creates LatticeParameters states from them. :param n_states: Number of states in the returned list. :type n_states: int :param kappa: Small constant indicating the distance to the theoretical limits of the cube [0, 1], in order to avoid innacuracies in the computation of the log probabilities due to clamping. The states will thus be uniformly sampled in [kappa, 1 - kappa]. If None, self.kappa will be used. :type kappa: float .. py:class:: LatticeParametersSGCCG(lattice_system, **kwargs) Bases: :py:obj:`gflownet.envs.cube.ContinuousCube` :param lattice_system: One of the seven lattice systems. By default, the triclinic lattice system is used, which has no constraints. :type lattice_system: str .. py:attribute:: continuous :value: True .. py:attribute:: lattice_system .. py:attribute:: min_projection_values .. py:attribute:: max_projection_values .. py:method:: state2lattice(state=None) Transforms a state into its equivalent lattice parameters :param state: A state in environment format. If None, then the current state will be used instead :type state: list :returns: **proj** (*list*) -- Lattice parameters equivalent to the provided state representation. In format [[a, b, c], [alpha, beta, gamma]] for compatibility with previous lattice parameter environment. .. py:method:: apply_projection_constraints(projection_vector) Apply the environment constraints to a state representation in projection space. :param projection_vector: State representation in projection space :type projection_vector: list :returns: **constrained_projection_vector** (*list*) -- State representation in projection space, compatible with the environment constraints. .. py:method:: apply_lattice_constraints(lattice_params) Apply the environment constraints to a set of lattice parameters. :param lattice_params: Lattice parameters, in order (a, b, c, alpha, beta, gamma). :type lattice_params: list :returns: **constrained_lattice_params** (*list*) -- Lattice parameters in the same order as in the input, modified if needed to be compatible with the environment constraints. .. py:method:: set_lattice_system(lattice_system) Sets the lattice system of the unit cell and updates the constraints. :param lattice_system: Name of the lattice system for which to produce lattice parameters. :type lattice_system: str .. py:method:: parameters2state(parameters = None, lengths = None, angles = None) Converts a set of lattice parameters in angstroms and degrees into a ContinuousCube state, with the parameters in the [0, 1] range. The parameters may be passed as a single tuple parameters containing the six parameters or via separate lengths and angles. If parameters is not None, lengths and angles are ignored. :param parameters: The six lattice parameters (a, b, c, alpha, beta, gamma) in target units (angstroms and degrees). :type parameters: tuple (optional) :param lengths: A triplet of length lattice parameters (a, b, c) in angstroms. Ignored if parameters is not None. :type lengths: tuple (optional) :param angles: A triplet of angle lattice parameters (alpha, beta, gamma) in degrees. Ignored if parameters is not None. :type angles: tuple (optional) :returns: *state* -- A state in environment format. .. py:method:: states2proxy(states) Prepares a batch of states in "environment format" for a proxy: states are mapped from [0; 1] to edge lengths and angles. :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:: state2readable(state = None) Converts the state into a human-readable string in the format "(a, b, c), (alpha, beta, gamma)". .. py:method:: readable2state(readable) Converts a human-readable representation of a state into the state format. .. 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. If None, then the current state will be used instead :type state: list :returns: *bool* -- True if the state is valid according to the attributes of the environment; False otherwise.