Contents

#
# multipie.ipynb
#
from qtdraw import QtDraw

# show tag list.
def show_list(header, lst):
    print(header)
    for i in lst:
        print(" ", i)

# draw objects.
def draw_equivalent(win):
    # draw equivalent site, bond, vector, and orbital.
    win.mp_add_site("[1/4,0,1/3]")
    win.mp_add_bond("[1/4,0,1/3];[0,1/4,2/3]")
    win.mp_add_vector("Q", "[0,0,1]", "[1/2,1/2,0]")
    win.mp_add_orbital("Q", "3z**2-r**2", "[1/2,1/2,1/2]")

def draw_harmonics(win):
    # create harmonics tag, and draw one of them.
    lst = win.mp_create_harmonics("Q", 3)
    show_list("Harmonics:", lst)
    win.mp_add_harmonics(lst[0], "[1/2,1/2,1/4]")

def draw_site(win):
    # create site SAMB, and draw one of them.
    lst = win.mp_create_site_samb("[1/4,0,1/3]")
    show_list("site SAMB:", lst)
    win.mp_add_site_samb(lst[1])

def draw_bond(win):
    # create bond SAMB, and draw one of them.
    lst = win.mp_create_bond_samb("[1/2,1/2,0]@[1/4,1/4,0]")
    show_list("bond SAMB:", lst)
    win.mp_add_bond_samb(lst[3])

def draw_vector(win):
    # create vector SAMB, and draw one of them.
    lst = win.mp_create_vector_samb("Q", "[1/2, 1/2, 0]")
    show_list("vector SAMB:", lst)
    win.mp_add_vector_samb("Q02+G02")

def draw_vector_modulation(win):
    # create vector SAMB, and draw one of them.
    lst = win.mp_create_vector_samb("Q", "[1/2, 1/2, 0]")
    show_list("vector SAMB:", lst)
    win.mp_add_vector_samb_modulation("[[Q02, 1, [1,0,0], cos], [Q02, 1, [0,1,0], sin]]")

def draw_orbital(win):
    # create orbital SAMB, and draw one of them.
    lst = win.mp_create_orbital_samb("Q", 1, "[0,0,0];[1/2,1/2,0]")
    show_list("orital SAMB:", lst)
    win.mp_add_orbital_samb("Q02+G02")

def draw_orbital_modulation(win):
    # create orbital SAMB, and draw one of them.
    lst = win.mp_create_orbital_samb("Q", 1, "[0,0,0];[1/2,1/2,0]")
    show_list("orital SAMB:", lst)
    win.mp_add_orbital_samb_modulation("[[Q02, 1, [1,0,0], cos], [Q02, 1, [0,1,0], sin]]")

def draw_hopping(win):
    # draw hopping direction.
    win.mp_add_hopping("[0,0,0];[1/2,1/2,0]")

# === initialization for example ===
win = QtDraw() # create QtDraw application.
win.mp_set_group("D3^4") # set space/point group by Schoenflies notation.
win.set_model("multipie")
# === example ===
win.clear_data()
draw_equivalent(win)
draw_harmonics(win)
draw_site(win)
draw_bond(win)
draw_vector(win)
draw_orbital(win)
draw_hopping(win)
draw_vector_modulation(win)
draw_orbital_modulation(win)
Harmonics:
  Q(3,A1,,)
  Q(3,A2,1,)
  Q(3,A2,2,)
  Q(3,E,1,0)
  Q(3,E,1,1)
  Q(3,E,2,0)
  Q(3,E,2,1)
site SAMB:
  Q01: Q(0,A1,,) = Qa(0,A1,) x Qs(0,A1,)
  Q02: Q(1,A2,,) = Qa(0,A1,) x Qs(1,A2,)
  Q03: Q(1,E,,0) = Qa(0,A1,) x Qs(1,E,)
  Q04: Q(1,E,,1) = Qa(0,A1,) x Qs(1,E,)
  Q05: Q(2,E,1,0) = Qa(0,A1,) x Qs(2,E,1)
  Q06: Q(2,E,1,1) = Qa(0,A1,) x Qs(2,E,1)
bond SAMB:
  Q01: Q(0,A1,,) = Qa(0,A1,) x Qb(0,A1,)
  Q02: Q(2,E,1,0) = Qa(0,A1,) x Qb(2,E,1)
  Q03: Q(2,E,1,1) = Qa(0,A1,) x Qb(2,E,1)
  T01: T(0,A1,,) = Qa(0,A1,) x Tb(0,A1,)
  T02: T(2,E,1,0) = Qa(0,A1,) x Tb(2,E,1)
  T03: T(2,E,1,1) = Qa(0,A1,) x Tb(2,E,1)
vector SAMB:
  Q01: Q(1,A2,,) = Qa(1,A2,) x Qs(0,A1,)
  Q02: Q(1,A2,,) = Qa(1,E,) x Qs(2,E,1)
  Q03: Q(1,E,,0) = Qa(1,A2,) x Qs(2,E,1)
  Q04: Q(1,E,,0) = Qa(1,E,) x Qs(0,A1,)
  Q05: Q(1,E,,1) = Qa(1,A2,) x Qs(2,E,1)
  Q06: Q(1,E,,1) = Qa(1,E,) x Qs(0,A1,)
  G01: G(2,A1,,) = Qa(1,E,) x Qs(2,E,1)
  G02: G(2,E,2,0) = Qa(1,E,) x Qs(2,E,1)
  G03: G(2,E,2,1) = Qa(1,E,) x Qs(2,E,1)
orital SAMB:
  Q01: Q(1,A2,,) = Qa(1,A2,) x Qb(0,A1,)
  Q02: Q(1,A2,,) = Qa(1,E,) x Qb(2,E,1)
  Q03: Q(1,E,,0) = Qa(1,A2,) x Qb(2,E,1)
  Q04: Q(1,E,,0) = Qa(1,E,) x Qb(0,A1,)
  Q05: Q(1,E,,1) = Qa(1,A2,) x Qb(2,E,1)
  Q06: Q(1,E,,1) = Qa(1,E,) x Qb(0,A1,)
  G01: G(2,A1,,) = Qa(1,E,) x Qb(2,E,1)
  G02: G(2,E,2,0) = Qa(1,E,) x Qb(2,E,1)
  G03: G(2,E,2,1) = Qa(1,E,) x Qb(2,E,1)
  T01: T(1,A2,,) = Qa(1,A2,) x Tb(0,A1,)
  T02: T(1,A2,,) = Qa(1,E,) x Tb(2,E,1)
  T03: T(1,E,,0) = Qa(1,A2,) x Tb(2,E,1)
  T04: T(1,E,,0) = Qa(1,E,) x Tb(0,A1,)
  T05: T(1,E,,1) = Qa(1,A2,) x Tb(2,E,1)
  T06: T(1,E,,1) = Qa(1,E,) x Tb(0,A1,)
  M01: M(2,A1,,) = Qa(1,E,) x Tb(2,E,1)
  M02: M(2,E,2,0) = Qa(1,E,) x Tb(2,E,1)
  M03: M(2,E,2,1) = Qa(1,E,) x Tb(2,E,1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 9
      7 draw_vector(win)
      8 draw_orbital(win)
----> 9 draw_hopping(win)
     10 draw_vector_modulation(win)
     11 draw_orbital_modulation(win)

Cell In[1], line 64, in draw_hopping(win)
     62 def draw_hopping(win):
     63     # draw hopping direction.
---> 64     win.mp_add_hopping("[0,0,0];[1/2,1/2,0]")

File ~/.venv/lib/python3.13/site-packages/qtdraw/core/qtdraw_app.py:2924, in QtDraw.mp_add_hopping(self, bond, scale)
   2921     self.mp_set_group()
   2923 self.multipie_dialog.dialog.basis_edit_hopping.setText(bond)
-> 2924 self.multipie_dialog.dialog.basis_add_hopping(scale)

File ~/.venv/lib/python3.13/site-packages/qtdraw/multipie/dialog_multipie.py:1679, in MultiPieDialog.basis_add_hopping(self, scale)
   1676 bond = self.plugin.create_hopping_direction(pos)
   1677 label = "T \u21d0 " + remove_space(str(pos))
-> 1679 self.plugin.add_hopping_samb(bond, label, scale)

File ~/.venv/lib/python3.13/site-packages/qtdraw/multipie/plugin_multipie.py:1005, in MultiPiePlugin.add_hopping_samb(self, bond, label, scale)
   1003 count = self.counter("hopping") + 1
   1004 name = f"Z_{count:02}"
-> 1005 A = str_to_sympy(self._pvw.A_matrix)
   1006 for no, p in enumerate(pset):
   1007     name1 = name

File ~/.venv/lib/python3.13/site-packages/qtdraw/util/util.py:58, in str_to_sympy(s, check_var, check_shape, rational, subs, **assumptions)
     55 reserved = set(sp.__all__) | {"pi", "E", "I", "oo", "zoo"}
     57 # extract candidate variable names.
---> 58 var = sorted(set(re.findall(r"[A-Za-z_]\w*", s)))
     59 # remove reserved ones.
     60 var = [v for v in var if v not in reserved]

File /opt/homebrew/Cellar/python@3.13/3.13.9_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/re/__init__.py:278, in findall(pattern, string, flags)
    270 def findall(pattern, string, flags=0):
    271     """Return a list of all non-overlapping matches in the string.
    272 
    273     If one or more capturing groups are present in the pattern, return
   (...)    276 
    277     Empty matches are included in the result."""
--> 278     return _compile(pattern, flags).findall(string)

TypeError: cannot use a string pattern on a bytes-like object