:py:mod:`alhambra`
==================

.. py:module:: alhambra


Submodules
----------
.. toctree::
   :titlesonly:
   :maxdepth: 1

   _tilesets_dx/index.rst
   _version/index.rst
   anneal/index.rst
   classes/index.rst
   drawing/index.rst
   edotparen/index.rst
   endreorder/index.rst
   fastlatticedefect/index.rst
   fastreduce/index.rst
   fastreduceD/index.rst
   flatish/index.rst
   glues/index.rst
   grid/index.rst
   latticedefect/index.rst
   mixes/index.rst
   nuad/index.rst
   quantitate/index.rst
   seeds/index.rst
   sensitivity/index.rst
   sensitivitynew/index.rst
   seq/index.rst
   tiles/index.rst
   tilesets/index.rst
   util/index.rst


Package Contents
----------------

Classes
~~~~~~~

.. autoapisummary::

   alhambra.Glue
   alhambra.GlueList
   alhambra.Tile
   alhambra.TileList
   alhambra.TileSet




.. py:class:: Glue


   .. py:property:: etype
      :type: str
      :abstractmethod:


   .. py:property:: type
      :type: str


   .. py:property:: is_complement
      :type: bool


   .. py:property:: complement
      :type: GlueA


   .. py:attribute:: name
      :type: Optional[str]

      

   .. py:attribute:: note
      :type: Optional[str]

      

   .. py:attribute:: use
      :type: Use

      

   .. py:attribute:: abstractstrength
      :type: Optional[int]

      The stickydesign type of the glue.

   .. py:method:: _into_complement()


   .. py:method:: copy() -> T


   .. py:method:: ident() -> str


   .. py:method:: basename() -> str


   .. py:method:: update(other: Glue)


   .. py:method:: merge(other: Glue) -> Glue


   .. py:method:: __or__(other: Glue) -> Glue


   .. py:method:: __ior__(other: Glue)


   .. py:method:: __ror__(other: Glue) -> Glue


   .. py:method:: __eq__(other: object) -> bool

      Return self==value.


   .. py:method:: to_dict() -> dict[str, Any]


   .. py:method:: from_dict(d: dict[str, Any]) -> Glue
      :staticmethod:



.. py:class:: GlueList(initial: Iterable[T_NMI] = tuple())


   Bases: :py:obj:`Generic`\ [\ :py:obj:`GlueA`\ ], :py:obj:`alhambra.classes.UpdateListD`\ [\ :py:obj:`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

   .. py:method:: merge_complements() -> None


   .. py:method:: merge_glue(g: GlueA) -> GlueA


   .. py:method:: merge_glue_and_update_list(g: GlueA) -> GlueA


   .. py:method:: to_endarrays() -> Any
      :abstractmethod:



.. py:class:: Tile(edges: Optional[Iterable[alhambra.glues.Glue | str]] = None, name: Optional[str] = None, color: Optional[Color] = None, stoic: Optional[float] = None, note: Optional[str | dict[str, Any]] = None, use: Sequence[alhambra.glues.Use | int | str] | None = None, fake: bool = False, uses: Sequence[Sequence[alhambra.glues.Use | int | str]] | None = None)


   Base class for a tile.

   .. py:property:: structure


   .. py:property:: use
      :type: Sequence[alhambra.glues.Use]


   .. py:property:: edges
      :type: EdgeView


   .. py:property:: edge_directions
      :type: List[D]
      :abstractmethod:


   .. py:property:: edge_locations
      :type: List[EdgeLoc]
      :abstractmethod:


   .. py:property:: rotations
      :type: List[Tile]
      :abstractmethod:


   .. py:property:: is_fake
      :type: bool


   .. py:property:: xgname
      :type: str


   .. py:attribute:: name
      :type: Optional[str]

      

   .. py:attribute:: _edges
      :type: List[alhambra.glues.Glue]

      

   .. py:attribute:: color
      :type: Optional[Color]

      

   .. py:attribute:: stoic
      :type: Optional[float]

      

   .. py:attribute:: note
      :type: Optional[str | dict[str, Any]]

      

   .. py:attribute:: fake
      :type: bool

      

   .. py:attribute:: uses
      :type: List[List[alhambra.glues.Use]]

      

   .. py:attribute:: __slots__
      :value: ('name', '_edges', 'color', 'stoic', 'note', 'fake', 'uses')

      

   .. py:method:: get_concentration(base_concentration: float) -> float


   .. py:method:: get_stoic(base_concentration: float) -> float

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


   .. py:method:: set_edge(i: int, glue: alhambra.glues.Glue) -> None


   .. py:method:: copy() -> T


   .. py:method:: _get_edge_index(v: str) -> int
      :classmethod:
      :abstractmethod:


   .. py:method:: ident() -> str


   .. py:method:: merge(other) -> Tile


   .. py:method:: to_dict(refglues: set[str] = set()) -> dict[str, Any]


   .. py:method:: update_glues(gluedict: alhambra.glues.GlueList[alhambra.glues.Glue]) -> None


   .. py:method:: update_glues_and_list(gluedict: alhambra.glues.GlueList[alhambra.glues.Glue]) -> None


   .. py:method:: from_dict(d: dict[str, Any]) -> Tile
      :staticmethod:


   .. py:method:: to_xgrow(gluenamemap: Callable[[str], str] = lambda x: x) -> xgrow.tileset.Tile


   .. py:method:: abstract_diagram(tileset: alhambra.tilesets.TileSet | None = None, draw_names: bool = True, draw_glues: bool = True) -> alhambra.drawing.Group
      :abstractmethod:



.. py:class:: TileList(initial: Iterable[T_NMI] = tuple())


   Bases: :py:obj:`Generic`\ [\ :py:obj:`SomeTile`\ ], :py:obj:`alhambra.classes.UpdateListD`\ [\ :py:obj:`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

   .. py:method:: glues_from_tiles() -> alhambra.glues.GlueList


   .. py:method:: domains_from_tiles() -> alhambra.glues.GlueList



.. py:class:: 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)


   Bases: :py:obj:`alhambra.classes.Serializable`

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

   .. py:property:: allglues
      :type: alhambra.glues.GlueList


   .. py:property:: alldomains
      :type: alhambra.glues.GlueList


   .. py:attribute:: tiles
      :type: alhambra.tiles.TileList[alhambra.tiles.Tile]

      

   .. py:attribute:: glues
      :type: alhambra.glues.GlueList[alhambra.glues.Glue]

      

   .. py:attribute:: seeds
      :type: dict[str | int, alhambra.seeds.Seed]

      

   .. py:attribute:: lattices
      :type: dict[str | int, alhambra.grid.Lattice]

      

   .. py:attribute:: guards
      :type: dict[str | int, list[str]]

      

   .. py:attribute:: params
      :type: dict

      

   .. py:method:: 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
      :classmethod:

      Given some :any:`TileSet`\ s, or lists of :any:`Tile`\ s from which to
      take tiles, generate an TileSet from the mix.


   .. py:method:: 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

      Run the tilesystem in Xgrow.


   .. py:method:: 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)


   .. py:method:: 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)


   .. py:method:: 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

      Convert Alhambra TileSet to an XGrow TileSet


   .. py:method:: _to_xgrow_dict() -> dict

      DEPRECATED: to xgrow dict


   .. py:method:: summary()

      Returns a short summary line about the TileSet


   .. py:method:: __repr__() -> str

      Return repr(self).


   .. py:method:: __str__() -> str

      Return str(self).


   .. py:method:: from_scadnano(des: scadnano.Design, ret_fails: bool = False) -> TileSet
      :classmethod:

      Create TileSet from Scadnano Design.


   .. py:method:: to_scadnano(lattice: alhambra.grid.LatticeSupportingScadnano | None = None) -> scadnano.Design

      Export TileSet (with lattice) as Scadnano Design.


   .. py:method:: to_dict() -> dict


   .. py:method:: from_dict(d: dict) -> TileSet
      :classmethod:


   .. py:method:: _serialize() -> Any


   .. py:method:: _deserialize(input: Any) -> TileSet
      :classmethod:


   .. py:method:: 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]

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

      :param lattice: Lattice or reference to a lattice in the tileset
      :type lattice: AbstractLattice | int | str
      :param x: index in the lattice, by default None
      :type x: int | slice | None, optional
      :param y: index in the lattice, by default None
      :type y: int | slice | None, optional
      :param copy: 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
      :type copy: bool, optional


   .. py:method:: 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]


   .. py:method:: 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)

      Create an SVG layout diagram from a lattice.

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

      :param xgrowarray: 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.
      :type xgrowarray: ndarray or dict
      :param filename: File name / path of the output file.
      :type filename: string


   .. py:method:: reduce_tiles(preserve=('s22', 'ld'), tries=10, threads=1, returntype='equiv', best=1, key=None, initequiv=None)
      :abstractmethod:

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

      :param tileset: The system to reduce.
      :type tileset: TileSet
      :param preserve: 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').
      :type preserve: a tuple or list of strings, optional
      :param tries: The number of times to run the algorithm.
      :type tries: int, optional
      :param threads: The number of threads to use (using multiprocessing).
      :type threads: int, optional
      :param returntype: 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).
      :type returntype: 'TileSet' or 'equiv' (default 'equiv')
      :param best: 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)
      :type best: int or None, optional
      :param key: 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.
      :type key: function (ts, equiv1, equiv2) -> some number/comparable
      :param initequiv: If provided, the equivalence array to start from.  If None, start from the tileset without
                        any merged glues.
      :type initequiv: equiv

      :returns: **reduced** -- The reduced system/systems
      :rtype: single TileSet or equiv, or list


   .. py:method:: reduce_ends(preserve=['s22', 'ld'], tries=10, threads=1, returntype='equiv', best=1, key=None, initequiv=None)
      :abstractmethod:

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

      :param tileset: The system to reduce.
      :type tileset: TileSet
      :param preserve: 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').
      :type preserve: a tuple or list of strings, optional
      :param tries: The number of times to run the algorithm.
      :type tries: int, optional
      :param threads: The number of threads to use (using multiprocessing).
      :type threads: int, optional
      :param returntype: 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).
      :type returntype: 'TileSet' or 'equiv' (default 'equiv')
      :param best: 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)
      :type best: int or None, optional
      :param key: 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.
      :type key: function (ts, equiv1, equiv2) -> some number/comparable
      :param initequiv: If provided, the equivalence array to start from.  If None, start from the tileset without
                        any merged glues.
      :type initequiv: equiv

      :returns: **reduced** -- The reduced system/systems
      :rtype: single TileSet or equiv, or list


   .. py:method:: latticedefects(direction='e', depth=2, pp=True, rotate=False)
      :abstractmethod:

      Calculate and show possible small lattice defect configurations.


   .. py:method:: apply_equiv(equiv)
      :abstractmethod:

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

      :param equiv: An equivalence array, *for this tileset*, generated by reduction functions.
      :type equiv: ndarray

      :returns: A tileset with the equivalence array, and thus the reduction, applied.
      :rtype: TileSet


   .. py:method:: check_consistent()

      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.


   .. py:method:: copy()

      Return a full (deep) copy of the TileSet


   .. py:method:: from_file(path_or_stream: io.TextIOWrapper | str | os.PathLike[str], format: Literal[json, yaml, None] = None) -> TileSet
      :classmethod:


   .. py:method:: to_file(path_or_stream: str | os.PathLike[str] | io.TextIOWrapper)



