Anders and Briegel in Python
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

53 行
1.3KB

  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(*list(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)