<jupyter_start><jupyter_text>---title: Elements of programming and 3D graphicsteaching: 30exercises: 0questions:- "..."objectives:- "..."--- The following is a list of points in 3D, that we wish to plot - they are actually the vertices of an icosahedron, $\tau$ is the golden ratio we had above $1/2(1+\sqrt{5})$TODO: question - could go to Hamiltonian cycles now?<jupyter_code>tau = 1.619

icos_vertex_list = [[1,0,tau], [-1,0,tau], [1,0,-tau], [-1,0,-tau], [0, tau, 1], [0, tau, -1], [0, -tau, 1], [0, -tau, -1], [tau, 1, 0], [tau, -1, 0], [-tau, 1, 0], [-tau, -1, 0]]

point3d(icos_vertex_list, size=50)<jupyter_output><empty_output><jupyter_text>For next step you need to use some programming language, as doing this interactively is not productive. First we need to introduce some notions, namely ranges, loops and conditional statements.<jupyter_code>for n in range(1,6):
    print(n)<jupyter_output>1
2
3
4
5<jupyter_text>We now do a double loop over two variables with a non-trivial 'function'. This gives the 'allowed' triangulation numbers in Caspar-Klug theory. Note that we define this as a set, so that the order does not matter and duplicates do not occur.<jupyter_code>l=set([])
for h in range(0,6):
    for k in range(0,6):
        l.add(h^2+h*k+k^2)
l<jupyter_output><empty_output><jupyter_text>Now let us loop over a larger range, and combine this with an if statement. We are generating large numbers of 'allowed' triangulation numbers. But say, we are only interested in finding potential $(h,k)$ pairs that give rise to the largest known triangulation in a virus, which for now (2018) is $499$ for Cafeteria roenbergensis virus (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5511168/).<jupyter_code>for h in range(0,20):
    for k in range(h,20):
        t = h^2+h*k+k^2
        if t == 499:
            print(h, k)<jupyter_output>(7, 18)<jupyter_text>So there is a unique pair (up to chirality).In the following example, we check that there is only one unordered 5-tuple of nonegative integers such that one of these integers is 1, and the sum of their squares is 60 (those familiar with group theory will recognise that this gives the dimensions of irreducible representations of the icosahedral group). This also uses a couple of nested for loops combined with  an if statement to show the uniquess of the solution 'by brute force'/enumeration.<jupyter_code>order = 60

for i1 in range(1,8):
    for i2 in range(i1,8):
        for i3 in range(i2,8):
             for i4 in range(i3,8):
                    if (1^2+i1^2+i2^2+i3^2+i4^2==order):
                        print(1, i1, i2, i3, i4)<jupyter_output>(1, 3, 3, 4, 5)<jupyter_text>Find the adjacencies of vertices. Which distances occur?<jupyter_code>for i in range(0,1):
    for j in range(0,12):
        print(round(norm(vector(icos_vertex_list[i])-vector(icos_vertex_list[j])),2))<jupyter_output>0.0
2.0
3.24
3.81
2.0
3.24
2.0
3.24
2.0
2.0
3.24
3.24<jupyter_text>Find all those with distance (squared) 2<jupyter_code>adj=[]
for i in range(0,len(icos_vertex_list)):
    adj.append([])
    for j in range(0,12):
        if round(norm(vector(icos_vertex_list[i])-vector(icos_vertex_list[j])),2)==2.00:
            adj[i].append(j)
    print(adj[i])<jupyter_output>[1, 4, 6, 8, 9]
[0, 4, 6, 10, 11]
[3, 5, 7, 8, 9]
[2, 5, 7, 10, 11]
[0, 1, 5, 8, 10]
[2, 3, 4, 8, 10]
[0, 1, 7, 9, 11]
[2, 3, 6, 9, 11]
[0, 2, 4, 5, 9]
[0, 2, 6, 7, 8]
[1, 3, 4, 5, 11]
[1, 3, 6, 7, 10]<jupyter_text>Getting the list of edges<jupyter_code>icos_edges = []
for i in range(0,len(adj)):
    for j in range(0,len(adj[i])):
        icos_edges.append( line3d( [icos_vertex_list[i], icos_vertex_list[adj[i][j]]], thickness=10) )
vertices = point3d(icos_vertex_list, size=100)
icosahedron = vertices
for edge in icos_edges:
    icosahedron = icosahedron + edge
show(icosahedron)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13770746887966806, 'fraction_numerical': 0.06275933609958506, 'mean_word_length': 4.101851851851852, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '136631', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1425, 'n_words': 483, 'path': '_episodes_ipynb/03-matrix-group.ipynb', 'repo_name': 'ccp-codima/sage-lesson', 'size': '3856'}