adsorpy.rsa_calculator module

RSA Calculator module. Import needed for the Random Sequential Adsorption script to run.

There is no real reason for the user to need to use any of this, but the functions are accessible just in case.

adsorpy.rsa_calculator.squared_cdist(coords1, coords2)[source]

Calculate the square distance between two sets of coordinates.

Parameters:
Return type:

ndarray[tuple[int, int], dtype[double]]

Returns:

The squared distance array.

adsorpy.rsa_calculator.calculate_square_distance(candidate_coords, other_coords, placed_index, molgridx, max_interdist, rtree, existing)[source]

Compute the square distance for the coordinates.

The square distance is computed between the new coordinate and the existing molecule coordinates nearby. The square distance can be compared to the square of the radius. (Computationally cheaper than taking the Euclidean distance of the entire array).

Parameters:
Return type:

tuple[ndarray[tuple[Any, ...], dtype[double]], ndarray[tuple[int], dtype[int_]], ndarray[tuple[int], dtype[int_]]]

Returns:

Squared distance of molecule centre to other molecule centres, indices of nearby molecules, molgroup idx.

adsorpy.rsa_calculator.check_outer_radius(distance_squared, mol_gr_idx, near_index, gap_dists)[source]

Check whether the outer radius is clear.

If no molecules are present within twice the length of the longest side of the molecule, the molecule is approved automatically, and no shape checks need to be performed.

Parameters:
Return type:

tuple[bool, ndarray[tuple[int], dtype[int_]], ndarray[tuple[Any, ...], dtype[double]]]

Returns:

Bool whether the outer radius is clear, index of values that are not clear, and array of nearby distances.

adsorpy.rsa_calculator.check_hard_border(candidate_coords, x_max, y_max, max_radius)[source]

Check whether there is guaranteed clearance between the molecule candidate and the hard border.

Parameters:
  • candidate_coords (ndarray[tuple[Literal[2], Literal[1]], dtype[double]]) – 2x1 array of coordinates of the candidate.

  • x_max (float) – Maximum x coordinate of the grid.

  • y_max (float) – Maximum y-coordinate of the grid.

  • max_radius (float) – Maximum radius of the molecule.

Return type:

bool

Returns:

bool: is there guaranteed clearance between the molecule radius and the edge?

adsorpy.rsa_calculator.check_hard_molecule(candidate_coords, x_max, y_max, fmg)[source]

Check whether positioned molecules fit within the hard boundaries.

This is done by checking whether all bounding box coordinates lie within the min/max x and y of grid.

Parameters:
  • candidate_coords (ndarray[tuple[Literal[2], Literal[1]], dtype[double]]) – 2x1 array of coordinates of the candidate.

  • x_max (float) – Maximum x coordinate of the grid.

  • y_max (float) – Maximum y-coordinate of the grid.

  • fmg (MoleculeGroup) – Object of the first molecule group. The boundary parameters are needed.

Return type:

ndarray[tuple[int], dtype[bool]]

Returns:

Is there guaranteed clearance between the molecule polygon and the edge?

adsorpy.rsa_calculator.check_shape_overlap(cand, neighbour_index, simul, pmg, try_angle_first=None)[source]

Check whether there the new molecule overlaps with existing molecules.

If molecules are in the intermediate range between guaranteed clearance and guaranteed overlap, the shape needs to be compared to other molecules. The first for-loop places the candidate molecule at an allowed angle in random order. The nested for-loop compares the placed molecule to the nearest neighbours. If any neighbour overlaps, the molecule rotation is rejected and a new angle is tried. If no neighbours overlap, the angle is accepted and the check terminates. If neighbours overlap for all angles, the molecule is rejected and the check ends.

Parameters:
Return type:

tuple[bool, CandidateMolecule]

Returns:

Bool flag that indicates whether the candidate is fully disjoint, and the candidate molecule.

adsorpy.rsa_calculator.make_rtree_filter(candidate_coordinates, rtree, circumradius, existing)[source]

Filter on nearby polygons using the RTree index.

Parameters:
  • candidate_coordinates (ndarray[tuple[Literal[2]], dtype[double]]) – Coords of the candidate molecule.

  • rtree (Index) – Index of the nearest neighbour.

  • circumradius (float) – Cirucmradius of the candidate molecule.

  • existing (ndarray[tuple[int], dtype[bool]]) – BoolArray indicating if the candidate molecule exists.

Return type:

ndarray[tuple[int], dtype[int_]]

adsorpy.rsa_calculator.make_rectangular_filter(candidate_coordinates, other_coordinates, x_offset, y_offset=None)[source]

Make a rectangular boolean list out of x and y coordinates. Can be used to make a window.

Parameters:
  • candidate_coordinates (ndarray[tuple[Literal[2]], dtype[double]]) – 2 array of coordinate pair that is of interest.

  • other_coordinates (ndarray[tuple[Literal[2], int], dtype[double]]) – 2xN array of coordinates that need to be filtered.

  • x_offset (float) – The offset over which the window is taken in x. So candidate plusminus x_off.

  • y_offset (float | None) – Same as x_offset, but in y direction. If None, then y_offset = x_offset.

Return type:

ndarray[tuple[int], dtype[bool]]

Returns:

Nx1 boolean array to filter the coordinates over.

adsorpy.rsa_calculator.create_periodic_images(coordinates, x_max, y_max, z_max=None)[source]

Create a padding of coordinates.

Repeats the images above, below, and on the diagonals (9 tiles).

Parameters:
Return type:

TypeVar(T, ndarray[tuple[Literal[2], int], dtype[double]], ndarray[tuple[Literal[3], int], dtype[double]])

Returns:

2 by 9*N coordinate array if 2D, otherwise 3 by 27*N array.