bsym.configuration

class bsym.configuration.Configuration(vector: list[int] | ndarray[tuple[int, ...], dtype[int64]])[source]

Bases: object

A Configuration describes a specific arrangement of objects in the vector space of possible positions. Objects are represented by integers, with indistinguishable objects denoted by identical integers. Internally, the configuration is stored as a numpy.int8 array.

count

If symmetry-inequivalent configurations have been generated for a configuration space, this records the number of configurations equivalent to this one. Value at initialisation is None.

Type:

int

lowest_numeric_representation

If the numeric representations for the set of equivalent configurations are calculated, this can be used to store the lowest valued numeric representation, for use as a simple hash.

Type:

int

Example

>>> Configuration([1, 1, 0])
Configuration([1, 1, 0])
static array_to_bytes(arr: ndarray) bytes[source]

Convert configuration array to bytes.

Assumes array is already int8. Used for transformations.

Parameters:

arr – Configuration as int8 numpy array.

Returns:

Byte representation for hashing.

Return type:

bytes

as_bytes() bytes[source]

Get byte representation of this configuration.

property as_number: int

A numeric representation of this configuration.

Examples

>>> c = Configuration([1, 2, 0])
>>> c.as_number
120
classmethod from_dict(d: dict) Configuration[source]

Create Configuration from dictionary.

Parameters:

d – Dictionary with ‘vector’ key containing configuration values.

Returns:

New Configuration instance.

classmethod from_tuple(configuration_tuple)[source]

Create a Configuration from a tuple.

Configurations are stored as int8 arrays, supporting species labels 0-255.

Parameters:

configuration_tuple – Tuple of configuration values (0-255).

Returns:

New configuration object.

Return type:

Configuration

get_byte_equivalents(symmetry_group) set[bytes][source]

Get byte representations of all symmetry-equivalent configurations.

has_equivalent_in_list(the_list: list[Configuration], symmetry_operations: list[SymmetryOperation]) bool[source]

Test whether this configuration is equivalent by symmetry to one or more in a list of configurations.

Parameters:
  • list (list(bsym.Configuration)) – A list of Configuration instances.

  • symmetry_operations (list(bsym.SymmetryOperation)) – A list of SymmetryOperation objects.

Returns:

True | False

Return type:

(bool)

is_equivalent_to(test_configuration: Configuration, symmetry_operations: list[SymmetryOperation]) bool[source]

Test whether this configuration is equivalent to another configuration under one or more of a set of symmetry operations.

Parameters:
  • test_configuration (Configuration) – The configuration to compare against.

  • symmetry_operations (list(SymmetryOperation) – A list of SymmetryOperation objects.

Returns:

True | False

Return type:

(bool)

is_in_list(the_list: list[Configuration]) bool[source]

Test whether this configuration is in a list of configurations.

Parameters:

list (list(bsym.Comfiguration)) – A list of Configuration instances.

Returns:

True | False

Return type:

(bool)

map_objects(objects: list) dict[int, Any][source]

Returns a dict of objects sorted according to this configuration.

Parameters:

[list] (objects) – A list of objects.

Returns:

A dictionary of sorted objects.

Return type:

sorted_objects [dict]

matches(test_configuration: Configuration) bool[source]

Test whether this configuration is equal to another configuration.

Parameters:

test_configuration (Configuration) – The configuration to compare against.

Returns:

True | False.

Return type:

(bool)

numeric_equivalents(symmetry_operations: list[SymmetryOperation]) list[int][source]

Returns a list of all symmetry equivalent configurations generated by a set of symmetry operations with each configuration given in numeric representation.

Parameters:

symmetry_operations (list) – A list of SymmetryOperation instances.

Returns:

A list of numbers representing each equivalent configuration.

Return type:

(list(int))

position(label: int) list[int][source]

Returns the vector indices where elements are equal to label.

Parameters:

label (int) – The label used to select the vector positions.

Returns:

A list of all positions that match label.

Return type:

(list)

pprint() None[source]
set_lowest_numeric_representation(symmetry_operations: list[SymmetryOperation]) None[source]

Sets self.lowest_numeric_representation to the lowest value numeric representation of this configuration when permutated under a set of symmetry operations.

Parameters:

symmetry_operations (list) – A list of SymmetryOperation instances.

Returns:

None

to_dict() dict[source]

Convert to JSON-serialisable dictionary.

Returns:

Dictionary with ‘vector’ key containing the configuration as a list.

tolist() list[int][source]

Returns the configuration data as a list.

Parameters:

None

Returns:

(List)

static tuple_to_bytes(tup: tuple) bytes[source]

Convert configuration tuple to bytes.

Used for initial permutation checking in enumerate_configurations.

Parameters:

tup – Configuration as tuple.

Returns:

Byte representation for hashing.

Return type:

bytes

bsym.configuration.as_number(a: list[int] | ndarray[tuple[int, ...], dtype[int64]]) int[source]
bsym.configuration.load_configurations(filename: str) list[Configuration][source]

Load configurations from a JSON file.

Parameters:

filename – Path to input file.

Returns:

List of Configuration objects.

bsym.configuration.save_configurations(configurations: list[Configuration], filename: str) None[source]

Save configurations to a JSON file.

Parameters:
  • configurations – List of Configuration objects to save.

  • filename – Path to output file.