adsorpy.randomsequentialadsorption module¶
Random sequential adsorption (RSA) simulator on a grid.
In this module, all the classes are defined. This is the base of the simulation. This module contains the lowest level methods for the library. run_simulation is preferred.
- class adsorpy.randomsequentialadsorption.Config(rsa_config, sites, xsize, ysize, zsize, max_molecule_count, lattice_a, boundary_type, sticking_probability)[source]¶
Bases:
objectDataclass containing the config variables read from data/config.
- rsa_config: RsaConfig¶
The RSA config.
- __init__(rsa_config, sites, xsize, ysize, zsize, max_molecule_count, lattice_a, boundary_type, sticking_probability)¶
- class adsorpy.randomsequentialadsorption.BoundaryParameters(boundary_type, rot_cnt=0, dbl_max_radius=0.0)[source]¶
Bases:
objectStore the boundary parameters for the surface and the molecule groups.
Mostly empty for ‘soft’ boundaries, utilises different parameters for ‘hard’ and ‘periodic’ boundaries.
Initialise the boundary parameters for soft, periodic, hard.
- Parameters:
- __init__(boundary_type, rot_cnt=0, dbl_max_radius=0.0)[source]¶
Initialise the boundary parameters for soft, periodic, hard.
- molecules_flag: Final[bool]¶
True if this is the boundary parameter class for molecules, False if it used for a surface.
- hard_inner: ndarray[tuple[int], dtype[bool]]¶
All sites close to the edge of the hard boundary. These sites are True, others False.
- molecules_bounding_coords: ndarray[tuple[int, Literal[4]], dtype[float64]]¶
min/max x/y values.
- Type:
Molecule bounding box coordinates
- allowed_idx: ndarray[tuple[int], dtype[int64]]¶
Index of allowed rotations. When close to a hard boundary, some rotations are no longer possible.
- allowed_bools: ndarray[tuple[int], dtype[bool]]¶
Booleans belonging to the allowed rotations. When near the hard boundary, some rotations are impossible.
- extended_grid: ndarray[tuple[Literal[2], int], dtype[float64]]¶
The surface site coordinates of the extended (periodic) grid.
- extended_occupied_by: ndarray[tuple[int], dtype[int64]]¶
The occupancy of the extended (periodic) grid. Filled with the indices of the molecules on the grid.
- close_to_edge: ndarray[tuple[int], dtype[bool]]¶
Boolean array denoting closeness to the edge. If close to the edge, periodicity must be taken into account.
- extended_vacant: ndarray[tuple[int], dtype[bool]]¶
Boolean array denoting vacantness of the extended (periodic) grid. True if a site is vacant, False otherwise.
- tree: STRtree¶
STRtree, currently unused.
- static set_boundary_flags(boundary_type)[source]¶
Take a string of the boundary flags and turns it into any of three bools.
Boolean checking is cheaper than string evaluation.
- Parameters:
boundary_type (
str) – The boundary type. Either soft, hard, or periodic. Throws an error otherwise.- Return type:
- Returns:
The soft, hard, and periodic flags. One is set to True. If not, an error is thrown.
- Raises:
TypeError – If boundary_type is not a string.
ValueError – If boundary_type is not ‘soft’, ‘hard’, or ‘periodic’.
- generate_boundary_conditions(surf, molgr=None)[source]¶
Generate the boundary conditions and modifies the available sites.
If the boundary condition is soft, generate nothing.
- Parameters:
surf (
Surface) – The surface.molgr (
MoleculeGroup|None) – The molecule group for which the boundary conditions are defined. Optional.
- Return type:
- class adsorpy.randomsequentialadsorption.MoleculeGroup(rsa_config, molecule, rotation_symmetry, reflection_symmetry, site_count, mgc, rotation_count=360, sticking_probability=None)[source]¶
Bases:
objectCreate the molecule group class.
It stores the basic shapes of rotated molecules such that they can be translated later. It also keeps track of several other values such as radius.
Initialise the data for molecule groups.
Molecule groups are how data is stored per molecule footprint shape.
- Parameters:
rsa_config – RsaConfig class.
molecule – (2D) polygon data representing the molecule.
rotation_symmetry – Rotation symmetry of the molecule group. Set 0 for circular symmetry.
reflection_symmetry – Bool denoting reflection symmetry of the molecule group.
site_count – The total amount of surface sites.
mgc – Molecule group counter.
rotation_count – The amount of allowed rotations. If not provided, assumes 360.
- __init__(rsa_config, molecule, rotation_symmetry, reflection_symmetry, site_count, mgc, rotation_count=360, sticking_probability=None)[source]¶
Initialise the data for molecule groups.
Molecule groups are how data is stored per molecule footprint shape.
- Parameters:
rsa_config – RsaConfig class.
molecule – (2D) polygon data representing the molecule.
rotation_symmetry – Rotation symmetry of the molecule group. Set 0 for circular symmetry.
reflection_symmetry – Bool denoting reflection symmetry of the molecule group.
site_count – The total amount of surface sites.
mgc – Molecule group counter.
rotation_count – The amount of allowed rotations. If not provided, assumes 360.
- group_id: Final[int]¶
ID value of the molecule group. Automatically iterates when making new molecule groups.
- rotation_symmetry: Final[int]¶
Rotation symmetry. 0 for no symmetry, 1 for circle, n (int >= 2) for n-fold.
- reflection_symmetry: Final[bool]¶
Reflection symmetry. True for reflection symmetry over the y-axis, False for no reflection symmetry.
- __max_rotation: Final[int]¶
Molecules can only rotate between 0 and 360 degrees (excluding the endpoint). Do not touch.
- rot_refl_count: Final[int]¶
Rotation + reflection count. If the molecule has no reflection symmetry, all rotations must also be attempted while reflected. 360 rotations without reflection symmetry: 720 counts.
- rotated_molecules: ndarray[tuple[int], dtype[Polygon]]¶
Array of rotated molecules. Used as templates, only translation is needed to get into position.
- rotated_buffer_molecules: ndarray[tuple[int, int], dtype[Polygon]]¶
Buffer molecules are a special type of polygon used for vectorised calculations. They are used to determine whether surface sites are covered by these polygons.
- occupied_by: ndarray[tuple[int], dtype[int64]]¶
Which molecule hinders what? This shows whic molecule occupies which site. Defaults to -1, an invalid molecule index. Special value -2: unoccupied by a particular molecule but still unreachable.
- vacant: ndarray[tuple[int], dtype[bool]]¶
Vacancy array for the molecule. Shows which sites are guaranteed to be unreachable (False) and which are free.
- bp: BoundaryParameters¶
Boundary parameter class.
- gap_dists: ndarray[tuple[Any, ...], dtype[float64]]¶
Distances for the molecules, measured as the sum of the circumradii..
- minmax_gaps: ndarray[tuple[Any, ...], dtype[float64]]¶
Distance as the sum between the circumradius and inradius of two molecules.
- generate_rotated_molecules(bopa, amgs)[source]¶
Generate rotated molecules and prepared buffer molecules. Generate bounding box in case of hard boundary.
- Parameters:
bopa (
BoundaryParameters) – The boundary parameters.amgs (
list[MoleculeGroup]) – All molecule groups.
- Return type:
- Returns:
The updated boundary parameters of the molecule group we are interested in.
- class adsorpy.randomsequentialadsorption.CandidateMolecule(molecule_group_idx=-1, grid_index=-1, coordinates=<factory>, molecule=<factory>, rot_idx=-1, molecule_number=-1, close_to_border=False, exists=True)[source]¶
Bases:
objectCreate a candidate molecule with temporary data.
All relevant data for a candidate molecule. The molecule group index, grid index, coordinates, molecules, rotation index, molecule number, bool to denote closeness to the border, and existence. Re-used every time. All index values are illegal by default for easier debugging.
- coordinates: ndarray[tuple[Literal[2], Literal[1]], dtype[float64]]¶
Coordinates of the molecule. Defaults to np.empty((2, 1), dtype=np.float64).
- molecule: Polygon¶
Candidate molecule. Initially empty.
- __init__(molecule_group_idx=-1, grid_index=-1, coordinates=<factory>, molecule=<factory>, rot_idx=-1, molecule_number=-1, close_to_border=False, exists=True)¶
- class adsorpy.randomsequentialadsorption.Simulator(rsa_config, include_rejected_flux, surf, mol_groups, rng, boundary_type=None)[source]¶
Bases:
objectPerform Random Sequential Adsorption (RSA).
The class that brings it all together. Places/(re)moves the molecules, updates positioning, keeps track of a lot of things. Allows for plotting as well, as well as gap size analysis.
Initialise the simulator, combine the other classes.
- Parameters:
rsa_config (
RsaConfig) – RsaConfig class.include_rejected_flux (
bool) – allows adsorption attempts to occupied sites.surf (
Surface) – Surface class.mol_groups (
list[MoleculeGroup]) – the molecule groups.rng (
Generator) – random number generator. This is needed for seeded runs (all are seeded).boundary_type (
str|None) – type of boundary conditions, optional. If None, defaults to config.json (periodic).
- Raises:
ValueError – if no molecules are provided.
- __init__(rsa_config, include_rejected_flux, surf, mol_groups, rng, boundary_type=None)[source]¶
Initialise the simulator, combine the other classes.
- Parameters:
rsa_config (
RsaConfig) – RsaConfig class.include_rejected_flux (
bool) – allows adsorption attempts to occupied sites.surf (
Surface) – Surface class.mol_groups (
list[MoleculeGroup]) – the molecule groups.rng (
Generator) – random number generator. This is needed for seeded runs (all are seeded).boundary_type (
str|None) – type of boundary conditions, optional. If None, defaults to config.json (periodic).
- Raises:
ValueError – if no molecules are provided.
- molgroups: list[MoleculeGroup]¶
List of the molecule group classes.
- bp: BoundaryParameters¶
Boundary parameter class.
- flux_flag: bool¶
Flag denoting whether occupied sites can be re-attempted for placement. False fails, but adds a stepcount.
- total_molecule_counter: int64¶
Counter for all of the molecules on the surface.
- minmax_rads: ndarray[tuple[Any, ...], dtype[float64]]¶
Sums of inradii and circumradii of all of the molecules.
- mol_data: MoleculeData¶
Molecule data. This is where the values of the placed molecules and mirror molecules are stored.
- __unclaimed: Final[int]¶
sites that are not covered by a molecule but still not reachable. Do not change.
- Type:
Value for unreachable but unclaimed sites
- attempt_place_molecule(surf, pmg, grid_idx=None, first_rot_idx=None)[source]¶
Try to place a molecule.
It calls functions to check for adjacency and intersection. If the molecule does not touch any others, it is stored. Otherwise, it is discarded.
- Parameters:
surf (
Surface) – The surface.pmg (
MoleculeGroup) – The primary molecule group (pmg) we want to place.grid_idx (
int|int_|None) – A grid index value, optional. If set, try to place on this index instead of a random one.first_rot_idx (
int|int_|None) – The first rotation to attempt, optional.
- Return type:
- Returns:
Bool for placement of mol, the mol counter, mol group, placement index, rot index, and vacant count.
- update_placement(cand, surf, pmg, amgs)[source]¶
Update the stored molecules, coordinates, and index arrays.
Add a new molecule.
- Parameters:
cand (
CandidateMolecule) – The candidate molecule.surf (
Surface) – The surface.pmg (
MoleculeGroup) – The molecule group that was attempted to be placed.amgs (
list[MoleculeGroup]) – All molecule groups.
- Return type:
- Returns:
The total placed molecule count.
- trim_buffer(occupier_idx, pmg, mol_group, surf)[source]¶
Trim the available sites by removing inaccessible sites.
Take a buffered (isodistance) area around the positioned molecule of the minimum radius of the other molecule, then removes all coordinates within the buffer area from the list of available positions for the other. Nothing can be placed closer to existing molecules than this minimum radius.
- Parameters:
occupier_idx (
int) – Index of the molecule that covers the sites.pmg (
MoleculeGroup) – Primary molecule group, the group that has been positioned.mol_group (
MoleculeGroup) – One of the molecule groups. The group whose data is updated.surf (
Surface) – The Surface.
- Return type:
- Returns:
The molecule group whose availability has been updated.
- plot_covered_grid(surf, amgs, save_flag=False, plt_flag=False, timestr='', results_folder='')[source]¶
Plot the molecules with the grid and save it as a figure.
- Parameters:
surf (
Surface) – The surface.amgs (
list[MoleculeGroup]) – All molecule groups.save_flag (
bool) – True: save the figure.plt_flag (
bool) – True: plot the figure.timestr (
str) – The timestring, can be used for saving the name.results_folder (
str|Path) – The folder in which the results will be saved.
- Return type:
- attempt_cascading_placement(surf, *molgrs, site_idx=None)[source]¶
Try to place molecules in the order of the arguments on the same random site. Stops when one fits.
- Parameters:
surf (
Surface) – The surface.molgrs (
MoleculeGroup) – The molecule groups. Placement occurs in the order of this argument.site_idx (
int|None) – Site to attempt placement on. If not given, pick random.
- Return type:
- Returns:
The output of Simulator.attempt_place_molecule().
- attempt_random_placement(surf, *molgrs, weights=None)[source]¶
Pick from a list of molecule groups and places a random one.
- Parameters:
- Return type:
- Returns:
The output of Simulator.attempt_place_molecule().
- class adsorpy.randomsequentialadsorption.Surface(rsa_config, lattice_type='triangular', site_count=None, lattice_a=None, boundary_type=None, sticking_probability=None)[source]¶
Bases:
objectStore coordinates and occupation data.
Initialise the surface.
- Parameters:
rsa_config (
RsaConfig) – The input parameters defined in the config.lattice_type (
str) – The type of lattice to use. Can be triangular, square, or honeycomb.site_count (
int|None) – The number of sites, optional. If None, defaults to the default in config.json.lattice_a (
float|None) – The lattice spacing, optional. If None, defaults to the default in config.json.boundary_type (
str|None) – The boundary type, optional. If None, defaults to the default in config.json (periodic).sticking_probability (
float|None) – Sticking probability. Default is 1.0 from config.
- Raises:
ValueError – If only x or y is provided for a custom surface. Currently unusable.
- __init__(rsa_config, lattice_type='triangular', site_count=None, lattice_a=None, boundary_type=None, sticking_probability=None)[source]¶
Initialise the surface.
- Parameters:
rsa_config (
RsaConfig) – The input parameters defined in the config.lattice_type (
str) – The type of lattice to use. Can be triangular, square, or honeycomb.site_count (
int|None) – The number of sites, optional. If None, defaults to the default in config.json.lattice_a (
float|None) – The lattice spacing, optional. If None, defaults to the default in config.json.boundary_type (
str|None) – The boundary type, optional. If None, defaults to the default in config.json (periodic).sticking_probability (
float|None) – Sticking probability. Default is 1.0 from config.
- Raises:
ValueError – If only x or y is provided for a custom surface. Currently unusable.
- lattice_type: Final[str]¶
Lattice type of the surface. Can be ‘triangular’/’hexagonal’, ‘square’ or ‘honeycomb’.
- x_max¶
Maximum x value of the surface. Adjusted properly for periodic surfaces.
- y_max¶
Maximum y value of the surface. Adjusted properly for periodic surfaces.
- area¶
Area of the surface. Adjusted properly for periodic surfaces.
- bp¶
Boundary parameters of the surface.
- tree: STRtree¶
STRtree, currently unused.
- _estimate_site_count()[source]¶
Estimates the total site count.
- Return type:
- Returns:
Total site count.
- generate_grid(rng=None)[source]¶
Create a hexagonal grid as a 2D numpy array with x the first index and y on the second.
- Parameters:
rng (
Generator|None) – The random generator. Used when generating an amorphous surface with the Delone lib.- Raises:
ValueError – If the lattice string is not supported (name and type are printed).
TypeError – If the lattice type is not supported (name and type are printed).
- Return type:
- _set_xy_max(x_all, y_all, sqrt3)[source]¶
Set the x_max and y_max based on boundary condition and surface type.
- generate_custom_surface(site_x_coords, site_y_coords, bounding_x_coord, bounding_y_coord)[source]¶
Generate a custom surface from user input.
Ensure that the origin is (0,0) and that all values are positive. Ensure that the arrays are equal in length.
- Parameters:
site_x_coords (
ndarray[tuple[int],dtype[double]]) – The x coordinates of the surface sites.site_y_coords (
ndarray[tuple[int],dtype[double]]) – The y coordinates of the surface sites.bounding_x_coord (
float) – The x coordinate of the bounding box.bounding_y_coord (
float) – The y coordinate of the bounding box.
- Raises:
ValueError – If the x or y (bounding box) coordinates are not positive or unequal in length.
- Return type:
- class adsorpy.randomsequentialadsorption.MoleculeData(max_array_length=100, current_mirror_num=-1, last_accessed_idx=-1, mol_tree=<factory>, mirr_tree=<factory>, _otomir_fill_vals=(False, []))[source]¶
Bases:
objectStores the data associated with all the molecules on the surface, as well as periodic molecules.
- __init__(max_array_length=100, current_mirror_num=-1, last_accessed_idx=-1, mol_tree=<factory>, mirr_tree=<factory>, _otomir_fill_vals=(False, []))¶
- max_array_length: int¶
Maximum length of all arrays. Extends by this amount when the maximum is reached.
- _header_names = ('self_id', 'exists', 'mol_group', 'grid_idx', 'rot_idx', 'has_periodic_images', 'x_coord', 'y_coord', 'polygon')¶
Names of the headers.
- _column_datatypes = (<class 'int'>, <class 'bool'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'bool'>, <class 'float'>, <class 'float'>, <class 'shapely.geometry.polygon.Polygon'>)¶
Datatypes of the columns of the molecule struct array.
- _fill_vals = (-1, False, -1, -1, -1, False, 0.0, 0.0, <POLYGON EMPTY>)¶
Fill value for the new molecule. Defaults to strictly invalid values.
- stored_data: np.ndarray[tuple[int], np.dtype[np.void]]¶
Molecule struct array. Here, all data for the molecules is stored.
- mol_tree: Index¶
Molecules RTree.
- _mirr_names = ('orig_id', 'exists', 'self_id', 'mol_group', 'grid_idx', 'rot_idx', 'x_coord', 'y_coord', 'polygon')¶
Names of the columns in the mirror molecule struct array.
- _mirr_datatypes = (<class 'int'>, <class 'bool'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>, <class 'float'>, <class 'float'>, <class 'shapely.geometry.polygon.Polygon'>)¶
Datatypes of the mirror molecule struct array.
- _mirr_heads_dtypes: list[tuple[str, type]]¶
Data types + names for the mirror molecules struct array.
- _mirr_fill_vals = (-1, False, -1, -1, -1, -1, 0.0, 0.0, <POLYGON EMPTY>)¶
Fill values for the new mirror molecule. Defaults to strictly invalid values.
- stored_mirr_data: np.ndarray[tuple[int], np.dtype[np.void]]¶
Mirror molecule struct array. Here, all data for the mirror molecules is stored.
- mirr_tree: Index¶
Mirror molecules RTree.
- _otomir_names = ('exists', 'mirr_ids')¶
Names for the origin to mirror array.
- _otomir_types = (<class 'bool'>, <class 'object'>)¶
Types of the origin to mirror array.
- _otomir_heads_dtypes: list[tuple[str, type]]¶
Data types for the original molecule to mirror (otomir) struct array.
- _otomir_fill_vals: Final[tuple[bool, list[int]]]¶
fill values for the origin to mirror array. Defaults to strictly invalid values.
- orig_to_mirrors: np.ndarray[tuple[int], np.dtype[np.void]]¶
Origin to mirror struct array. Stores which mirror indices are associated with which original molecule.
- coords: CoordsArray¶
Coordinates of the molecules.
- mirror_coords: CoordsArray¶
Mirror coordinates of the molecules.
- static make_struct_array(size, nameddtypes, fillvals)[source]¶
Make a structured array for the molecule storage.
- Parameters:
- Return type:
- Returns:
The new structured array.
- add_entry(_, exists, mol_group, grid_idx, rot_idx, has_periodic_images, x_coord, y_coord, polygon)[source]¶
Add a new entry to the stored data. All fields are mandatory.
- Parameters:
_ – Currently unused. The molecule index. Generated automatically though. # TODO: Not used?
exists (
bool) – Flag to determine whether the molecule exists on the surface.mol_group (
int) – Molecule group index. Set to -1 if invalid.grid_idx (
int) – Grid site index. Set to -1 if invalid.rot_idx (
int) – Rotation index.has_periodic_images (
bool) – Flag to determine whether the molecule has periodic images.x_coord (
float) – X-coordinate of the molecule centre.y_coord (
float) – Y-coordinate of the molecule centre.polygon (
Polygon) – The molecule polygon.
- Return type:
- add_mirror(mirr_num, orig_id, exists, mol_group, grid_idx, rot_idx, x_coord, y_coord, polygon)[source]¶
Add a mirror molecule to the stored molecule data.
- Parameters:
mirr_num (
int) – The mirror number for this idx. Number between 0 and 3 (inclusive).orig_id (
int) – The ID of the molecule for which the mirror images are added.exists (
bool) – Bool, denotes whether the molecule exists.mol_group (
int) – The molecule group ID.grid_idx (
int) – The grid index.rot_idx (
int) – The rotation index.x_coord (
float) – The x-coordinate.y_coord (
float) – The y-coordinate.polygon (
Polygon) – The molecule polygon at the mirrored location.
- Return type: