// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0x80(%rdx), %rdi
callq 0x4130
testb %al, %al
je 0x55239
addq $0x10, %rbx
leaq 0xaedee(%rip), %rsi     # 0x103a2e
movq %rbx, %rdi
callq 0x4480
movq %rax, %rdi
movl %ebp, %esi
callq 0x4760
leaq 0xae71f(%rip), %rsi     # 0x103378
movq %rax, %rdi
callq 0x4480
leaq 0xad916(%rip), %r15     # 0x10257e
movq %rax, %rdi
movq %r15, %rsi
callq 0x4480
leaq 0xaedc2(%rip), %rsi     # 0x103a3c
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movl %ebp, %esi
callq 0x4760
leaq 0xae701(%rip), %rsi     # 0x103394
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movq %r15, %rsi
callq 0x4480
leaq 0x90(%r14), %rax
movq %rax, 0x90(%rsp)
leaq 0xa8(%r14), %rax
movq %rax, 0x88(%rsp)
leaq 0x60(%r14), %rax
movq %rax, 0x68(%rsp)
xorl %r15d, %r15d
leaq 0xaf83b(%rip), %r13     # 0x104512
movq %r14, %rbp
movl %r15d, %r15d
movq 0x98(%rbp), %rax
subq 0x90(%rbp), %rax
cqto
pushq $0xc
popq %rcx
idivq %rcx
cmpq %r15, %rax
jbe 0x55209
movq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x4bbec
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0xa6ce
movq 0x90(%rsp), %rdi
movq %r15, 0x98(%rsp)
movq %r15, %rsi
callq 0x576b6
movl (%rax), %ecx
movl 0x4(%rax), %edx
movl %ecx, 0x5c(%rsp)
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0xb0(%rsp)
movl %edx, 0x58(%rsp)
cvtsi2sd %edx, %xmm0
movsd %xmm0, 0xa8(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x54(%rsp)
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0xa0(%rsp)
xorl %esi, %esi
movl %esi, %esi
movq 0x78(%rsp), %rax
subq 0x70(%rsp), %rax
sarq $0x2, %rax
cmpq %rsi, %rax
jbe 0x551ef
leaq 0x70(%rsp), %rdi
movq %rsi, 0x60(%rsp)
callq 0xac00
movslq (%rax), %rsi
movq 0x68(%rsp), %rdi
callq 0xabe2
leaq 0xd8(%rsp), %rdi
movq %rax, %rsi
callq 0x29ebe
movsd 0xc0(%rbp), %xmm1
movsd 0xb0(%rsp), %xmm0
mulsd %xmm0, %xmm1
addsd 0xe0(%rsp), %xmm1
movsd %xmm1, 0x48(%rsp)
movsd 0xd8(%rbp), %xmm2
movsd 0xa8(%rsp), %xmm1
mulsd %xmm1, %xmm2
movsd %xmm2, 0x40(%rsp)
movsd 0xf0(%rbp), %xmm3
movsd 0xa0(%rsp), %xmm2
mulsd %xmm2, %xmm3
movsd %xmm3, 0x18(%rsp)
movsd 0xc8(%rbp), %xmm3
mulsd %xmm0, %xmm3
addsd 0xe8(%rsp), %xmm3
movsd %xmm3, 0x38(%rsp)
movsd 0xe0(%rbp), %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, 0x30(%rsp)
movsd 0xf8(%rbp), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x10(%rsp)
movsd 0xd0(%rbp), %xmm3
mulsd %xmm0, %xmm3
addsd 0xf0(%rsp), %xmm3
movsd %xmm3, 0x28(%rsp)
movsd 0xe8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x100(%rbp), %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
leaq 0xab5be(%rip), %rsi     # 0x100453
callq 0x4480
movsd 0x40(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movq %rax, %rdi
movsd %xmm0, 0x18(%rsp)
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
movsd 0x30(%rsp), %xmm1
addsd 0x38(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movq %rax, %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
movsd 0x20(%rsp), %xmm1
addsd 0x28(%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movq %rax, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x46c0
movq %rax, %rdi
leaq 0xae3dc(%rip), %rsi     # 0x103302
callq 0x4480
movq %rax, %r12
leaq 0x70(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0xac00
movl (%rax), %esi
movq %r12, %rdi
callq 0x4760
movq %rax, %rdi
leaq 0xae3c6(%rip), %rsi     # 0x103317
callq 0x4480
movq %rax, %rdi
leaq 0xad61e(%rip), %rsi     # 0x10257e
callq 0x4480
xorl %r14d, %r14d
movl %r14d, %r14d
movq 0x100(%rsp), %rax
subq 0xf8(%rsp), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %r14, %rax
jbe 0x551d6
leaq 0xf8(%rsp), %rdi
movq %r14, %rsi
callq 0x29efa
movq %r14, 0xb8(%rsp)
movq %rbp, %r12
movq %r13, %r14
movq %rbx, %r15
movslq 0x4(%rax), %rsi
movl 0x18(%rax), %ebp
movl 0x1c(%rax), %ebx
movl 0x20(%rax), %r13d
movq 0x68(%rsp), %rdi
callq 0xabe2
leaq 0x120(%rsp), %rdi
movq %rax, %rsi
callq 0x29ebe
addl 0x5c(%rsp), %ebp
addl 0x58(%rsp), %ebx
addl 0x54(%rsp), %r13d
cvtsi2sd %ebp, %xmm0
movq %r12, %rbp
movsd 0xc0(%r12), %xmm1
mulsd %xmm0, %xmm1
addsd 0x128(%rsp), %xmm1
movsd %xmm1, 0x48(%rsp)
cvtsi2sd %ebx, %xmm2
movsd 0xd8(%r12), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, 0x38(%rsp)
cvtsi2sd %r13d, %xmm1
movsd 0xf0(%r12), %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, 0x40(%rsp)
movsd 0xc8(%r12), %xmm3
mulsd %xmm0, %xmm3
addsd 0x130(%rsp), %xmm3
movsd %xmm3, 0x30(%rsp)
movsd 0xe0(%r12), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, 0x20(%rsp)
movsd 0xf8(%r12), %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, 0x28(%rsp)
mulsd 0xd0(%r12), %xmm0
addsd 0x138(%rsp), %xmm0
movsd %xmm0, 0xd0(%rsp)
mulsd 0xe8(%r12), %xmm2
movsd %xmm2, 0xc0(%rsp)
mulsd 0x100(%r12), %xmm1
movsd %xmm1, 0xc8(%rsp)
movq %r15, %rbx
movq %r15, %rdi
leaq 0xab465(%rip), %rsi     # 0x100530
callq 0x4480
movq %r14, %r13
movq %rax, %rdi
movsd 0x18(%rsp), %xmm0
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
movq %rax, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x46c0
movq %rax, %rdi
leaq 0xac27e(%rip), %rsi     # 0x10139b
callq 0x4480
movsd 0x38(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
movsd 0x20(%rsp), %xmm1
addsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
movsd 0xc0(%rsp), %xmm1
addsd 0xd0(%rsp), %xmm1
movsd 0xc8(%rsp), %xmm0
addsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0xab45a(%rip), %rsi     # 0x1005ff
callq 0x4480
movq %rax, %rdi
leaq 0xad3ca(%rip), %rsi     # 0x10257e
callq 0x4480
leaq 0x140(%rsp), %rdi
callq 0xaf14
movq 0xb8(%rsp), %r14
incl %r14d
jmp 0x54f68
leaq 0xf8(%rsp), %rdi
callq 0xaf14
movq 0x60(%rsp), %rsi
incl %esi
jmp 0x54d6e
leaq 0x70(%rsp), %rdi
callq 0xb290
movq 0x98(%rsp), %r15
incl %r15d
jmp 0x54cda
leaq 0xae0ce(%rip), %rsi     # 0x1032de
movq %rbx, %rdi
callq 0x4480
leaq 0xad35f(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xfadb0(%rip), %rdi     # 0x14fff0
leaq 0xae7a2(%rip), %rsi     # 0x1039e9
callq 0x4480
leaq 0xad32b(%rip), %rbx     # 0x10257e
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
leaq 0xa794e(%rip), %rsi     # 0xfcbb3
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
pushq $0x1
popq %rdi
callq 0x524c
jmp 0x55282
movq %rax, %rbx
jmp 0x552ad
jmp 0x5528b
jmp 0x5528b
movq %rax, %rbx
jmp 0x552a0
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0xaf14
leaq 0xf8(%rsp), %rdi
callq 0xaf14
leaq 0x70(%rsp), %rdi
callq 0xb290
movq %rbx, %rdi
callq 0x4780
nop