// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/networkio.cc
// Function: readPDBFile(char*, ATOM_NETWORK*, bool)
bool readPDBFile(char *filename, ATOM_NETWORK *cell, bool radial){
  string garbage; //this is a garbage string to read line
  int i,j;

  fstream input;
  input.open(filename);
  if(input.is_open()==true){
    // Read the header information
    cout << "Reading input file: " << filename << endl;
    getline(input, garbage); // skip the first comment line

    string PBCline;

    input >> PBCline;
    if(PBCline.compare("CRYST1") != 0)
      {
      cerr << "This .pdb files does not contain CRYST1 in the second line. File format not compatible. Exiting...\n";
      return false;
      };

    input >> cell->a >> cell->b >> cell->c;
    input >> cell->alpha >> cell->beta >> cell->gamma;
    getline(input,garbage); // reading rest of line

    cell->name = filename;
    cell->initialize();

    bool end=false;
    int na=0;
    while(!end)
      {
      string str1, str2, str3, str4;

      input >> str1; // reads ATOM or ENDMDL keyword

      if(str1.compare("ENDMDL") == 0)
        {
        end = true;
        } else
        {
        ATOM newAtom;
        input >> str2 ; // reading ID#
        input >> newAtom.type;
        input >> str4; // reading MDL
        input >> newAtom.x >> newAtom.y >> newAtom.z;
        input >> str2 >> str3 >> str4; // ignore 2 numbers and a string with label

//        if(!CAR_USE_ATOM_TYPE_OVER_NAME) newAtom.type = str1;

        Point newCoords = cell->xyz_to_abc(newAtom.x, newAtom.y, newAtom.z);
        newAtom.a_coord = newCoords[0]; newAtom.b_coord = newCoords[1]; newAtom.c_coord = newCoords[2];
        newAtom.radius = lookupRadius(newAtom.type, radial);
        cell->atoms.push_back(newAtom);
        na++;
        };

      };

    cell->numAtoms = na;
    cout << na << " atoms read." << endl;

    input.close();
  }
  else{
    cerr << "Error: PDB failed to open " << filename << endl;
//    abort();
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3b8, %rsp            # imm = 0x3B8
movl %edx, 0xc(%rsp)
movq %rsi, (%rsp)
movq %rdi, %rbx
leaq 0xe0(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
leaq 0x1a8(%rsp), %rdi
callq 0x4520
leaq 0x1a8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x18, %edx
callq 0x43d0
leaq 0x228(%rsp), %rdi
callq 0x4120
testb %al, %al
je 0x2913d
movq 0x16deb8(%rip), %r15    # 0x196fc0
leaq 0x126fcf(%rip), %rsi    # 0x1500de
movl $0x14, %edx
movq %r15, %rdi
callq 0x44e0
testq %rbx, %rbx
je 0x29180
movq %rbx, %rdi
callq 0x41e0
movq 0x16de90(%rip), %rdi    # 0x196fc0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x44e0
jmp 0x29198
movq 0x16deac(%rip), %r14    # 0x196ff0
leaq 0x127179(%rip), %rsi    # 0x1502c4
movl $0x1a, %edx
movq %r14, %rdi
callq 0x44e0
testq %rbx, %rbx
je 0x2925a
movq %rbx, %rdi
callq 0x41e0
movq 0x16de80(%rip), %rdi    # 0x196ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x44e0
jmp 0x29272
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x4710
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq 0x16de0a(%rip), %rdi    # 0x196fc0
callq 0x4040
movq %rax, %rdi
callq 0x42c0
movq 0x1a8(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %edx
leaq 0x1a8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x47e0
leaq 0xc0(%rsp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
leaq 0x1a8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4560
leaq 0x12702a(%rip), %rsi    # 0x150252
leaq 0xb0(%rsp), %rdi
callq 0x4170
testl %eax, %eax
sete %bpl
je 0x292a4
movq 0x16ddac(%rip), %rdi    # 0x196ff0
leaq 0x12700e(%rip), %rsi    # 0x150259
movl $0x63, %edx
callq 0x44e0
jmp 0x296ef
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x4710
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq 0x16dd60(%rip), %rdi    # 0x196ff0
callq 0x4040
movq %rax, %rdi
callq 0x42c0
xorl %ebp, %ebp
jmp 0x2970c
movq (%rsp), %rax
leaq 0x8(%rax), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x42a0
movq (%rsp), %rcx
leaq 0x10(%rcx), %rsi
movq %rax, %rdi
callq 0x42a0
movq (%rsp), %rcx
leaq 0x18(%rcx), %rsi
movq %rax, %rdi
callq 0x42a0
movq (%rsp), %rax
leaq 0x20(%rax), %rsi
leaq 0x1a8(%rsp), %r14
movq %r14, %rdi
callq 0x42a0
movq (%rsp), %rcx
leaq 0x28(%rcx), %rsi
movq %rax, %rdi
callq 0x42a0
movq (%rsp), %rcx
leaq 0x30(%rcx), %rsi
movq %rax, %rdi
callq 0x42a0
movq 0x1a8(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %edx
leaq 0x1a8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x47e0
movq (%rsp), %rax
leaq 0x320(%rax), %r14
movq 0x328(%rax), %r15
movq %rbx, %rdi
callq 0x41e0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x4670
movq (%rsp), %rdi
callq 0x521f4
movl %ebp, 0x8(%rsp)
movq (%rsp), %rax
addq $0x2f0, %rax            # imm = 0x2F0
movq %rax, 0xf0(%rsp)
xorl %r13d, %r13d
leaq 0x1a8(%rsp), %r15
leaq 0x70(%rsp), %r12
leaq 0x190(%rsp), %r14
xorl %ebx, %ebx
xorl %ebp, %ebp
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq %r13, 0x78(%rsp)
movb %r13b, 0x80(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %r13, 0x38(%rsp)
movb %r13b, 0x40(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %r13, 0x58(%rsp)
movb %r13b, 0x60(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movb %r13b, 0x20(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x4560
movq %r12, %rdi
leaq 0x126ea8(%rip), %rsi    # 0x1502bd
callq 0x4170
testl %eax, %eax
je 0x295f5
leaq 0xf8(%rsp), %rdi
callq 0x5162c
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x4560
movq %r15, %rdi
leaq 0x138(%rsp), %rsi
callq 0x4560
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
callq 0x4560
movq %r15, %rdi
leaq 0xf8(%rsp), %rsi
callq 0x42a0
movq %rax, %rdi
leaq 0x100(%rsp), %rsi
callq 0x42a0
movq %rax, %rdi
leaq 0x108(%rsp), %rsi
callq 0x42a0
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x4560
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0x4560
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x4560
movsd 0xf8(%rsp), %xmm0
movsd 0x100(%rsp), %xmm1
movsd 0x108(%rsp), %xmm2
movq %r14, %rdi
movq (%rsp), %rsi
callq 0x531ea
movq %r14, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x110(%rsp)
movq %r14, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x118(%rsp)
movq %r14, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x120(%rsp)
leaq 0xa0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0xf32a
movzbl 0xc(%rsp), %esi
leaq 0x90(%rsp), %rdi
callq 0x21e42
movsd %xmm0, 0x128(%rsp)
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x29592
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xf0(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0xe936
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0x295cc
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0x295f1
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x4470
incl %ebx
jmp 0x295f8
movb $0x1, %bpl
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x29614
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x29630
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2964c
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2966e
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
testb $0x1, %bpl
je 0x293aa
movq (%rsp), %rax
movl %ebx, 0x110(%rax)
movq 0x16d937(%rip), %rdi    # 0x196fc0
movl %ebx, %esi
leaq 0xe0(%rsp), %r12
leaq 0xc0(%rsp), %r14
callq 0x4750
movl 0x8(%rsp), %ebp
movq %rax, %rbx
leaq 0x126a7c(%rip), %rsi    # 0x15012a
movl $0xc, %edx
movq %rax, %rdi
callq 0x44e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4420
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x42c0
leaq 0x1a8(%rsp), %rdi
callq 0x4090
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2970c
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x1a8(%rsp), %rdi
callq 0x4110
movq 0xd0(%rsp), %rdi
cmpq %r12, %rdi
je 0x29736
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x4470
movl %ebp, %eax
addq $0x3b8, %rsp            # imm = 0x3B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2984f
jmp 0x29754
movq %rax, %rbx
jmp 0x2981d
jmp 0x29788
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2979a
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x2979a
movq %rax, %rbx
jmp 0x297a7
movq %rax, %rbx
jmp 0x29842
jmp 0x29797
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x2f814
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x297c3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x297df
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x297fb
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2981d
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x29842
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x1a8(%rsp), %rdi
callq 0x4110
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x29874
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780