alhambra#

Submodules#

Package Contents#

Classes#

Glue

GlueList

Abstract base class for generic types.

Tile

Base class for a tile.

TileList

Abstract base class for generic types.

TileSet

Class representing a tileset, whether abstract or sequence-level.

class alhambra.Glue[source]#
abstract property etype: str#
property type: str#
property is_complement: bool#
property complement: GlueA#
name: str | None#
note: str | None#
use: Use#
abstractstrength: int | None#

The stickydesign type of the glue.

_into_complement()[source]#
copy() T[source]#
ident() str[source]#
basename() str[source]#
update(other: Glue)[source]#
merge(other: Glue) Glue[source]#
__or__(other: Glue) Glue[source]#
__ior__(other: Glue)[source]#
__ror__(other: Glue) Glue[source]#
__eq__(other: object) bool[source]#

Return self==value.

to_dict() dict[str, Any][source]#
static from_dict(d: dict[str, Any]) Glue[source]#
class alhambra.GlueList(initial: Iterable[T_NMI] = tuple())[source]#

Bases: Generic[GlueA], alhambra.classes.UpdateListD[GlueA]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
merge_complements() None[source]#
merge_glue(g: GlueA) GlueA[source]#
merge_glue_and_update_list(g: GlueA) GlueA[source]#
abstract to_endarrays() Any[source]#
class alhambra.Tile(edges: Iterable[alhambra.glues.Glue | str] | None = None, name: str | None = None, color: Color | None = None, stoic: float | None = None, note: str | dict[str, Any] | None = None, use: Sequence[alhambra.glues.Use | int | str] | None = None, fake: bool = False, uses: Sequence[Sequence[alhambra.glues.Use | int | str]] | None = None)[source]#

Base class for a tile.

property structure#
property use: Sequence[alhambra.glues.Use]#
property edges: EdgeView#
abstract property edge_directions: List[D]#
abstract property edge_locations: List[EdgeLoc]#
abstract property rotations: List[Tile]#
property is_fake: bool#
property xgname: str#
name: str | None#
_edges: List[alhambra.glues.Glue]#
color: Color | None#
stoic: float | None#
note: str | dict[str, Any] | None#
fake: bool#
uses: List[List[alhambra.glues.Use]]#
__slots__ = ('name', '_edges', 'color', 'stoic', 'note', 'fake', 'uses')#
get_concentration(base_concentration: float) float[source]#
get_stoic(base_concentration: float) float[source]#

Returns the stoichiometric ratio of this tile to the base concentration.

set_edge(i: int, glue: alhambra.glues.Glue) None[source]#
copy() T[source]#
abstract classmethod _get_edge_index(v: str) int[source]#
ident() str[source]#
merge(other) Tile[source]#
to_dict(refglues: set[str] = set()) dict[str, Any][source]#
update_glues(gluedict: alhambra.glues.GlueList[alhambra.glues.Glue]) None[source]#
update_glues_and_list(gluedict: alhambra.glues.GlueList[alhambra.glues.Glue]) None[source]#
static from_dict(d: dict[str, Any]) Tile[source]#
to_xgrow(gluenamemap: Callable[[str], str] = lambda x: ...) xgrow.tileset.Tile[source]#
abstract abstract_diagram(tileset: alhambra.tilesets.TileSet | None = None, draw_names: bool = True, draw_glues: bool = True) alhambra.drawing.Group[source]#
class alhambra.TileList(initial: Iterable[T_NMI] = tuple())[source]#

Bases: Generic[SomeTile], alhambra.classes.UpdateListD[SomeTile]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
glues_from_tiles() alhambra.glues.GlueList[source]#
domains_from_tiles() alhambra.glues.GlueList[source]#
class alhambra.TileSet(tiles: Iterable[alhambra.tiles.Tile] = tuple(), glues: Iterable[alhambra.glues.Glue] = tuple(), seeds: Mapping[str | int, alhambra.seeds.Seed] | None = None, *, seed: alhambra.seeds.Seed | None = None, lattices: Mapping[str | int, alhambra.grid.Lattice] | None = None, guards: Mapping[str | int, list[str]] = dict(), params: dict | None = None)[source]#

Bases: alhambra.classes.Serializable

Class representing a tileset, whether abstract or sequence-level.

property allglues: alhambra.glues.GlueList#
property alldomains: alhambra.glues.GlueList#
tiles: alhambra.tiles.TileList[alhambra.tiles.Tile]#
glues: alhambra.glues.GlueList[alhambra.glues.Glue]#
seeds: dict[str | int, alhambra.seeds.Seed]#
lattices: dict[str | int, alhambra.grid.Lattice]#
guards: dict[str | int, list[str]]#
params: dict#
classmethod from_mix(mix: alhambra_mixes.Mix, tilesets_or_lists: TileSet | alhambra.tiles.TileList | Iterable[TileSet | alhambra.tiles.TileList], *, seed: bool | alhambra.seeds.Seed = False, base_conc: alhambra_mixes.ureg.Quantity | str = Q_(100.0, nM)) TileSet[source]#

Given some TileSets, or lists of Tiles from which to take tiles, generate an TileSet from the mix.

run_xgrow(to_lattice: bool = True, _include_out: bool = False, glues: XgrowGlueOpts | str | None = None, seed: str | int | alhambra.seeds.Seed | None | Literal[False] = None, seed_offset: tuple[int, int] | None = None, xgrow_seed: tuple[int, int, int | str] | None = None, **kwargs: Any) Any[source]#

Run the tilesystem in Xgrow.

to_rgrow(glue_handling: XgrowGlueOpts | str | None = None, seed: str | int | alhambra.seeds.Seed | None | Literal[False] = None, seed_offset: tuple[int, int] | None = None, **kwargs)[source]#
to_rgrow_dict(glue_handling: XgrowGlueOpts | str | None = None, seed: str | int | alhambra.seeds.Seed | None | Literal[False] = None, seed_offset: tuple[int, int] | None = None, **kwargs)[source]#
to_xgrow(glue_handling: XgrowGlueOpts | str | None = None, seed: str | int | alhambra.seeds.Seed | None | Literal[False] = None, seed_offset: tuple[int, int] | None = None) xgrow.tileset.TileSet[source]#

Convert Alhambra TileSet to an XGrow TileSet

_to_xgrow_dict() dict[source]#

DEPRECATED: to xgrow dict

summary()[source]#

Returns a short summary line about the TileSet

__repr__() str[source]#

Return repr(self).

__str__() str[source]#

Return str(self).

classmethod from_scadnano(des: scadnano.Design, ret_fails: bool = False) TileSet[source]#

Create TileSet from Scadnano Design.

to_scadnano(lattice: alhambra.grid.LatticeSupportingScadnano | None = None) scadnano.Design[source]#

Export TileSet (with lattice) as Scadnano Design.

to_dict() dict[source]#
classmethod from_dict(d: dict) TileSet[source]#
_serialize() Any[source]#
classmethod _deserialize(input: Any) TileSet[source]#
lattice_tiles(lattice: alhambra.grid.AbstractLattice | int | str | numpy.ndarray, *, x: int | slice | None = None, y: int | slice | None = None, copy: bool = False) list[alhambra.tiles.Tile][source]#

Return a list of (unique) tiles in a lattice, potentially taking a slice of the lattice.

Parameters:
  • lattice (AbstractLattice | int | str) – Lattice or reference to a lattice in the tileset

  • x (int | slice | None, optional) – index in the lattice, by default None

  • y (int | slice | None, optional) – index in the lattice, by default None

  • copy (bool, optional) – return copies if True (useful for creating a new set) or tiles in the set if False (useful for modifying the set), by default False

create_guards_square(lattice: alhambra.grid.AbstractLattice, square_size: int, init_x: int = 0, init_y: int = 0, skip: Callable[[alhambra.glues.Glue], bool] = _skip_polyT_and_inertname) list[str][source]#
create_abstract_diagram(lattice: alhambra.grid.AbstractLattice | str | int | numpy.ndarray | None, filename=None, scale=1, guards: Collection[str] | str | int = tuple(), seed: str | bool | alhambra.seeds.Seed = True, seed_offset: tuple[int, int] = (0, 0), **options)[source]#

Create an SVG layout diagram from a lattice.

This currently uses the abstract diagram bases to create the layout diagrams.

Parameters:
  • xgrowarray (ndarray or dict) – Xgrow output. This may be a numpy array of an xgrow state, obtained in some way, or may be the ‘array’ output of xgrow.run.

  • filename (string) – File name / path of the output file.

abstract reduce_tiles(preserve=('s22', 'ld'), tries=10, threads=1, returntype='equiv', best=1, key=None, initequiv=None)[source]#

Apply tile reduction algorithm, preserving some set of properties, and using a multiprocessing pool.

Parameters:
  • tileset (TileSet) – The system to reduce.

  • preserve (a tuple or list of strings, optional) – The properties to preserve. Currently supported are ‘s1’ for first order sensitivity, ‘s2’ for second order sensitivity, ‘s22’ for two-by-two sensitivity, ‘ld’ for small lattice defects, and ‘gs’ for glue sense (to avoid spurious hierarchical attachment). Default is currently (‘s22’, ‘ld’).

  • tries (int, optional) – The number of times to run the algorithm.

  • threads (int, optional) – The number of threads to use (using multiprocessing).

  • returntype ('TileSet' or 'equiv' (default 'equiv')) – The type of object to return. If ‘equiv’, returns an array of glue equivalences (or list, if best != 1) that can be applied to the tileset with apply_equiv, or used for further reduction. If ‘TileSet’, return a TileSet with the equiv already applied (or a list, if best != 1).

  • best (int or None, optional) – The number of systems to return. If 1, the result will be returned directly; if k > 1, a list will be returned of the best k results (per cmp); if k = None, a list of all results will be returned, sorted by cmp. (default 1)

  • key (function (ts, equiv1, equiv2) -> some number/comparable) – A comparison function for equivs, to sort the results. FIXME: documentation needed. Default (if None) here is to sort by number of glues in the system, regardless of number of tiles.

  • initequiv (equiv) – If provided, the equivalence array to start from. If None, start from the tileset without any merged glues.

Returns:

reduced – The reduced system/systems

Return type:

single TileSet or equiv, or list

abstract reduce_ends(preserve=['s22', 'ld'], tries=10, threads=1, returntype='equiv', best=1, key=None, initequiv=None)[source]#

Apply end reduction algorithm, preserving some set of properties, and using a multiprocessing pool.

Parameters:
  • tileset (TileSet) – The system to reduce.

  • preserve (a tuple or list of strings, optional) – The properties to preserve. Currently supported are ‘s1’ for first order sensitivity, ‘s2’ for second order sensitivity, ‘s22’ for two-by-two sensitivity, ‘ld’ for small lattice defects, and ‘gs’ for glue sense (to avoid spurious hierarchical attachment). Default is currently (‘s22’, ‘ld’).

  • tries (int, optional) – The number of times to run the algorithm.

  • threads (int, optional) – The number of threads to use (using multiprocessing).

  • returntype ('TileSet' or 'equiv' (default 'equiv')) – The type of object to return. If ‘equiv’, returns an array of glue equivalences (or list, if best != 1) that can be applied to the tileset with apply_equiv, or used for further reduction. If ‘TileSet’, return a TileSet with the equiv already applied (or a list, if best != 1).

  • best (int or None, optional) – The number of systems to return. If 1, the result will be returned directly; if k > 1, a list will be returned of the best k results (per cmp); if k = None, a list of all results will be returned, sorted by cmp. (default 1)

  • key (function (ts, equiv1, equiv2) -> some number/comparable) – A comparison function for equivs, to sort the results. FIXME: documentation needed. Default (if None) here is to sort by number of glues in the system, regardless of number of tiles.

  • initequiv (equiv) – If provided, the equivalence array to start from. If None, start from the tileset without any merged glues.

Returns:

reduced – The reduced system/systems

Return type:

single TileSet or equiv, or list

abstract latticedefects(direction='e', depth=2, pp=True, rotate=False)[source]#

Calculate and show possible small lattice defect configurations.

abstract apply_equiv(equiv)[source]#

Apply an equivalence array (from, eg, TileSet.reduce_ends or TileSet.reduce_tiles).

Parameters:

equiv (ndarray) – An equivalence array, for this tileset, generated by reduction functions.

Returns:

A tileset with the equivalence array, and thus the reduction, applied.

Return type:

TileSet

check_consistent()[source]#

Check the TileSet consistency.

Check a number of properties of the TileSet for consistency. In particular:

  • Each tile must pass Tile.check_consistent()

  • TileSet.ends and TileSet.tiles.endlist() must not contain conflicting ends or end sequences.

  • If there is a seed:
    • It must be of an understood type (it must be in seeds.seedtypes)

    • All adapter locations must be valid.

    • The seed must pass its check_consistent and check_sequence.

copy()[source]#

Return a full (deep) copy of the TileSet

classmethod from_file(path_or_stream: io.TextIOWrapper | str | os.PathLike[str], format: Literal[json, yaml, None] = None) TileSet[source]#
to_file(path_or_stream: str | os.PathLike[str] | io.TextIOWrapper)[source]#