Anders and Briegel in Python
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1KB

  1. from abp.viz import VisibleGraphState
  2. import numpy as np
  3. import time
  4. import itertools
  5. square_unit_cell = (((0, 0), (0, 1)), ((0, 0), (1, 0)), ((1, 0), (1, 1)), ((0, 1), (1, 1)))
  6. funny_unit_cell = (((0, 0), (0, 1)), ((0, 0), (1, 0)), ((1, 0), (1, 1)), ((0, 1), (1, 1)), ((0, 0), (.5, .5)))
  7. def add_offset(vector, offset):
  8. """ Offset a vector in n-dimensional space """
  9. return tuple(v+o for v, o in zip(vector, offset))
  10. def offset_unit_cell(unit_cell, offset):
  11. """ Offset a unit cell """
  12. return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell}
  13. def lattice(unit_cell, size):
  14. """ Generate a lattice from a unit cell """
  15. edges = set()
  16. for offset in itertools.product(*map(range, size)):
  17. edges |= offset_unit_cell(unit_cell, offset)
  18. nodes = set(itertools.chain(*edges))
  19. return nodes, edges
  20. #s = VisibleGraphState()
  21. nodes, edges = lattice(funny_unit_cell, (10, 10))
  22. psi = VisibleGraphState()
  23. for node in nodes:
  24. pos = {"x": node[0], "y": node[1], "z": 0}
  25. psi.add_node(str(node), meta={"position":pos})
  26. for edge in edges:
  27. psi.add_edge(str(edge[0]), str(edge[1]))