// File: Luthaf[P]zeopp/channel.cc
// Function: CHANNEL::writeToVMD(int, std::basic_fstream<char, std::char_traits<char>>&)
void CHANNEL::writeToVMD(int n, fstream &output){
    if(!output.is_open()){
        cerr << "Error: File stream needed to print channel information was not open." << "\n"
        << "Exiting ..." << "\n";
        exit(1);
    }
    else{
        output << "set channels(" << n << ") {" << "\n"
        << "{color $channelColors(" << n << ")}" << "\n";
        
        // Draw the components located in each unit cell
        for(unsigned int i = 0; i < unitCells.size(); i++){
            vector<int> nodeIDs = ucNodes.at(i);
            DELTA_POS disp = unitCells.at(i);
            
            // Iterate over all nodes in the unit cell
            for(unsigned int j = 0; j < nodeIDs.size(); j++){
                DIJKSTRA_NODE curNode = nodes.at(nodeIDs.at(j));
                
                // Find node coordinates
                double xCoord = curNode.x + v_a.x*disp.x + v_b.x*disp.y + v_c.x*disp.z;
                double yCoord = curNode.y + v_a.y*disp.x + v_b.y*disp.y + v_c.y*disp.z;
                double zCoord = curNode.z + v_a.z*disp.x + v_b.z*disp.y + v_c.z*disp.z;
                
                // Command used to draw node
                output << "{sphere {" << xCoord <<  " " << yCoord << " " << zCoord
                << "} radius $nodeRadii(" << nodeIDs.at(j) <<") resolution $sphere_resolution}"
                << "\n";
                
                // Iterate over all connections stemming from the current node
                for(unsigned int k = 0; k < curNode.connections.size(); k++){
                    CONN curConn = curNode.connections.at(k);
                    DIJKSTRA_NODE otherNode = nodes.at(curConn.to);
                    int dx = disp.x + curConn.deltaPos.x;
                    int dy = disp.y + curConn.deltaPos.y;
                    int dz = disp.z + curConn.deltaPos.z;
                    
                    // Find end of edge coordinates
                    double newX = otherNode.x + v_a.x*dx + v_b.x*dy + v_c.x*dz;
                    double newY = otherNode.y + v_a.y*dx + v_b.y*dy + v_c.y*dz;
                    double newZ = otherNode.z + v_a.z*dx + v_b.z*dy + v_c.z*dz;
                    
                    // Command used to draw edge
                    output << "{line {" << xCoord << " " << yCoord << " " << zCoord << "} {"
                    << newX << " " << newY << " " << newZ<< "}}" <<  "\n";
                }
            }
        }
        output << "}" << "\n";
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x18(%rbp), %rdi
callq 0x58b0
testb $0x1, %al
jne 0xc8948
movq 0x1aa6eb(%rip), %rdi    # 0x272ff0
leaq 0x132dd5(%rip), %rsi    # 0x1fb6e1
callq 0x5540
movq %rax, %rdi
leaq 0x130d0a(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x12a2d9(%rip), %rsi    # 0x1f2c03
callq 0x5540
movq %rax, %rdi
leaq 0x130cec(%rip), %rsi    # 0x1f9625
callq 0x5540
movl $0x1, %edi
callq 0x67c0
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x132dcf(%rip), %rsi    # 0x1fb726
callq 0x5540
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x132724(%rip), %rsi    # 0x1fb095
callq 0x5540
movq %rax, %rdi
leaq 0x130ca5(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x132da5(%rip), %rsi    # 0x1fb734
callq 0x5540
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x132708(%rip), %rsi    # 0x1fb0b1
callq 0x5540
movq %rax, %rdi
leaq 0x130c6d(%rip), %rsi    # 0x1f9625
callq 0x5540
movl $0x0, -0x1c(%rbp)
movq -0x168(%rbp), %rdi
movl -0x1c(%rbp), %eax
movq %rax, -0x170(%rbp)
addq $0x90, %rdi
callq 0x706e0
movq %rax, %rcx
movq -0x170(%rbp), %rax
cmpq %rcx, %rax
jae 0xc9113
movq -0x168(%rbp), %rdi
addq $0xa8, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0xaf5b0
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0xeec0
movq -0x168(%rbp), %rdi
addq $0x90, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0xcd720
movq %rax, -0x178(%rbp)
jmp 0xc8a39
movq -0x178(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x44(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq %rax, -0x180(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x10090
movq %rax, %rcx
movq -0x180(%rbp), %rax
cmpq %rcx, %rax
jae 0xc90f1
movq -0x168(%rbp), %rax
addq $0x60, %rax
movq %rax, -0x190(%rbp)
movl -0x58(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x101d0
movq %rax, -0x188(%rbp)
jmp 0xc8aa3
movq -0x190(%rbp), %rdi
movq -0x188(%rbp), %rax
movslq (%rax), %rsi
callq 0x10130
movq %rax, -0x198(%rbp)
jmp 0xc8ac2
movq -0x198(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x64400
jmp 0xc8ad7
movq -0x168(%rbp), %rax
movsd -0x98(%rbp), %xmm2
cvtsi2sdl -0x44(%rbp), %xmm3
movsd 0xc0(%rax), %xmm0
movsd 0xd8(%rax), %xmm1
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
cvtsi2sdl -0x40(%rbp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0xf0(%rax), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x90(%rbp), %xmm2
cvtsi2sdl -0x44(%rbp), %xmm3
movsd 0xc8(%rax), %xmm0
movsd 0xe0(%rax), %xmm1
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
cvtsi2sdl -0x40(%rbp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0xf8(%rax), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x88(%rbp), %xmm2
cvtsi2sdl -0x44(%rbp), %xmm3
movsd 0xd0(%rax), %xmm0
movsd 0xe8(%rax), %xmm1
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
cvtsi2sdl -0x40(%rbp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x100(%rax), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x12d901(%rip), %rsi    # 0x1f64db
callq 0x5540
movq %rax, -0x1a0(%rbp)
jmp 0xc8be8
movq -0x1a0(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
callq 0x5980
movq %rax, -0x1a8(%rbp)
jmp 0xc8c05
movq -0x1a8(%rbp), %rdi
leaq 0x13369b(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x1b0(%rbp)
jmp 0xc8c21
movq -0x1b0(%rbp), %rdi
movsd -0xb0(%rbp), %xmm0
callq 0x5980
movq %rax, -0x1b8(%rbp)
jmp 0xc8c3e
movq -0x1b8(%rbp), %rdi
leaq 0x133662(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x1c0(%rbp)
jmp 0xc8c5a
movq -0x1c0(%rbp), %rdi
movsd -0xb8(%rbp), %xmm0
callq 0x5980
movq %rax, -0x1c8(%rbp)
jmp 0xc8c77
movq -0x1c8(%rbp), %rdi
leaq 0x13239a(%rip), %rsi    # 0x1fb01f
callq 0x5540
movq %rax, -0x1d0(%rbp)
jmp 0xc8c93
movl -0x58(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x101d0
movq %rax, -0x1d8(%rbp)
jmp 0xc8caa
movq -0x1d0(%rbp), %rdi
movq -0x1d8(%rbp), %rax
movl (%rax), %esi
callq 0x58d0
movq %rax, -0x1e0(%rbp)
jmp 0xc8cc8
movq -0x1e0(%rbp), %rdi
leaq 0x13235e(%rip), %rsi    # 0x1fb034
callq 0x5540
movq %rax, -0x1e8(%rbp)
jmp 0xc8ce4
movq -0x1e8(%rbp), %rdi
leaq 0x130933(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0xc8cf9
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movq %rax, -0x1f0(%rbp)
leaq -0xa0(%rbp), %rdi
addq $0x20, %rdi
callq 0x2a9e0
movq %rax, %rcx
movq -0x1f0(%rbp), %rax
cmpq %rcx, %rax
jae 0xc90c9
leaq -0x80(%rbp), %rdi
movl -0xbc(%rbp), %eax
movl %eax, %esi
callq 0x64470
movq %rax, -0x1f8(%rbp)
jmp 0xc8d4d
movq -0x168(%rbp), %rdi
movq -0x1f8(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0xd0(%rbp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, -0xe0(%rbp)
movaps %xmm0, -0xf0(%rbp)
addq $0x60, %rdi
movslq -0xec(%rbp), %rsi
callq 0x10130
movq %rax, -0x200(%rbp)
jmp 0xc8d94
movq -0x200(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x64400
jmp 0xc8da9
movq -0x168(%rbp), %rax
movl -0x44(%rbp), %ecx
movl -0xd8(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x13c(%rbp)
movl -0x40(%rbp), %ecx
movl -0xd4(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x140(%rbp)
movl -0x3c(%rbp), %ecx
movl -0xd0(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x144(%rbp)
movsd -0x130(%rbp), %xmm2
cvtsi2sdl -0x13c(%rbp), %xmm3
movsd 0xc0(%rax), %xmm0
movsd 0xd8(%rax), %xmm1
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
cvtsi2sdl -0x140(%rbp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0xf0(%rax), %xmm0
cvtsi2sdl -0x144(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x150(%rbp)
movsd -0x128(%rbp), %xmm2
cvtsi2sdl -0x13c(%rbp), %xmm3
movsd 0xc8(%rax), %xmm0
movsd 0xe0(%rax), %xmm1
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
cvtsi2sdl -0x140(%rbp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0xf8(%rax), %xmm0
cvtsi2sdl -0x144(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x158(%rbp)
movsd -0x120(%rbp), %xmm2
cvtsi2sdl -0x13c(%rbp), %xmm3
movsd 0xd0(%rax), %xmm0
movsd 0xe8(%rax), %xmm1
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
cvtsi2sdl -0x140(%rbp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x100(%rax), %xmm0
cvtsi2sdl -0x144(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x160(%rbp)
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x12d6be(%rip), %rsi    # 0x1f65b8
callq 0x5540
movq %rax, -0x208(%rbp)
jmp 0xc8f08
movq -0x208(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
callq 0x5980
movq %rax, -0x210(%rbp)
jmp 0xc8f25
movq -0x210(%rbp), %rdi
leaq 0x13337b(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x218(%rbp)
jmp 0xc8f41
movq -0x218(%rbp), %rdi
movsd -0xb0(%rbp), %xmm0
callq 0x5980
movq %rax, -0x220(%rbp)
jmp 0xc8f5e
movq -0x220(%rbp), %rdi
leaq 0x133342(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x228(%rbp)
jmp 0xc8f7a
movq -0x228(%rbp), %rdi
movsd -0xb8(%rbp), %xmm0
callq 0x5980
movq %rax, -0x230(%rbp)
jmp 0xc8f97
movq -0x230(%rbp), %rdi
leaq 0x12e596(%rip), %rsi    # 0x1f753b
callq 0x5540
movq %rax, -0x238(%rbp)
jmp 0xc8fb3
movq -0x238(%rbp), %rdi
movsd -0x150(%rbp), %xmm0
callq 0x5980
movq %rax, -0x240(%rbp)
jmp 0xc8fd0
movq -0x240(%rbp), %rdi
leaq 0x1332d0(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x248(%rbp)
jmp 0xc8fec
movq -0x248(%rbp), %rdi
movsd -0x158(%rbp), %xmm0
callq 0x5980
movq %rax, -0x250(%rbp)
jmp 0xc9009
movq -0x250(%rbp), %rdi
leaq 0x133297(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x258(%rbp)
jmp 0xc9025
movq -0x258(%rbp), %rdi
movsd -0x160(%rbp), %xmm0
callq 0x5980
movq %rax, -0x260(%rbp)
jmp 0xc9042
movq -0x260(%rbp), %rdi
leaq 0x12d60f(%rip), %rsi    # 0x1f665f
callq 0x5540
movq %rax, -0x268(%rbp)
jmp 0xc905e
movq -0x268(%rbp), %rdi
leaq 0x1305b9(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0xc9073
leaq -0x138(%rbp), %rdi
callq 0x100e0
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0xc8d03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xc9108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xc90e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x100e0
jmp 0xc90e3
leaq -0xa0(%rbp), %rdi
callq 0x100e0
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xc8a54
leaq -0xa0(%rbp), %rdi
callq 0x100e0
jmp 0xc9108
leaq -0x38(%rbp), %rdi
callq 0xec80
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xc89c4
leaq -0x38(%rbp), %rdi
callq 0xec80
jmp 0xc913f
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x131ed9(%rip), %rsi    # 0x1faffb
callq 0x5540
movq %rax, %rdi
leaq 0x1304f4(%rip), %rsi    # 0x1f9625
callq 0x5540
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x58f0
nopl (%rax,%rax)