Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

auto_layout.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from abp import GraphState, VizClient
  2. from abp.util import xyz
  3. import numpy as np
  4. import time
  5. import itertools
  6. import networkx as nx
  7. threedee_unit_cell = (
  8. (( 0, 0, 0), (0, 1, 0)),
  9. (( 0, 0, 0), (1, 0, 0)),
  10. (( 1, 0, 0), (1, 1, 0)),
  11. (( 0, 1, 0), (1, 1, 0)),
  12. (( 0, 0, 1), (0, 1, 1)),
  13. (( 0, 0, 1), (1, 0, 1)),
  14. (( 1, 0, 1), (1, 1, 1)),
  15. (( 0, 1, 1), (1, 1, 1)),
  16. (( 0, 0, 0), (0, 0, 1)),
  17. (( 0, 1, 0), (0, 1, 1)),
  18. (( 1, 0, 0), (1, 0, 1)),
  19. (( 1, 1, 0), (1, 1, 1))
  20. )
  21. def add_offset(vector, offset):
  22. """ Offset a vector in n-dimensional space """
  23. return tuple(v + o for v, o in zip(vector, offset))
  24. def offset_unit_cell(unit_cell, offset):
  25. """ Offset a unit cell """
  26. return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell}
  27. def lattice(unit_cell, size):
  28. """ Generate a lattice from a unit cell """
  29. edges = set()
  30. for offset in itertools.product(*map(range, size)):
  31. edges |= offset_unit_cell(unit_cell, offset)
  32. nodes = set(itertools.chain(*edges))
  33. return nodes, edges
  34. nodes, edges = lattice(threedee_unit_cell, (3, 3, 3))
  35. psi = GraphState(nodes)
  36. for a, b in edges:
  37. psi.act_cz(a, b)
  38. v = VizClient()
  39. v.update(psi)