// File: 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
movq %rsp, %rbp
subq $0x4a0, %rsp            # imm = 0x4A0
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5720
leaq -0x258(%rbp), %rdi
callq 0x5660
jmp 0x527e1
movq -0x10(%rbp), %rax
movq %rax, -0x3f8(%rbp)
movl $0x8, %edi
movl $0x10, %esi
callq 0x47640
movl %eax, -0x3ec(%rbp)
jmp 0x52803
movl -0x3ec(%rbp), %edx
movq -0x3f8(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x54b0
jmp 0x5281e
leaq -0x258(%rbp), %rdi
callq 0x58b0
movb %al, -0x3f9(%rbp)
jmp 0x52832
movb -0x3f9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x52e2d
movq 0x220773(%rip), %rdi    # 0x272fc0
leaq 0x1a0ad3(%rip), %rsi    # 0x1f3327
callq 0x5540
movq %rax, -0x408(%rbp)
jmp 0x52862
movq -0x408(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x410(%rbp)
jmp 0x5287b
movq -0x410(%rbp), %rdi
movq 0x22070f(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x52890
leaq -0x258(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5110
jmp 0x528a2
leaq -0x288(%rbp), %rdi
movq %rdi, -0x418(%rbp)
callq 0x5720
movq -0x418(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x56a0
jmp 0x528ca
leaq -0x288(%rbp), %rdi
leaq 0x1a0bc3(%rip), %rsi    # 0x1f349b
callq 0x51b0
cmpl $0x0, %eax
je 0x5294f
movq 0x220707(%rip), %rdi    # 0x272ff0
leaq 0x1a0bb2(%rip), %rsi    # 0x1f34a2
callq 0x5540
jmp 0x528f7
movb $0x0, -0x1(%rbp)
movl $0x1, -0x28c(%rbp)
jmp 0x52e02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x52ec4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x52eb8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x52e1c
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
leaq -0x258(%rbp), %rdi
callq 0x5420
movq %rax, -0x420(%rbp)
jmp 0x5296c
movq -0x420(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
callq 0x5420
movq %rax, -0x428(%rbp)
jmp 0x52989
movq -0x428(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
callq 0x5420
jmp 0x5299f
movq -0x18(%rbp), %rsi
addq $0x20, %rsi
leaq -0x258(%rbp), %rdi
callq 0x5420
movq %rax, -0x430(%rbp)
jmp 0x529bc
movq -0x430(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x28, %rsi
callq 0x5420
movq %rax, -0x438(%rbp)
jmp 0x529d9
movq -0x438(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x30, %rsi
callq 0x5420
jmp 0x529ef
leaq -0x258(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5110
jmp 0x52a01
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdi
addq $0x320, %rdi            # imm = 0x320
callq 0x5710
jmp 0x52a17
movq -0x18(%rbp), %rdi
callq 0x96250
jmp 0x52a22
movb $0x0, -0x28d(%rbp)
movl $0x0, -0x294(%rbp)
movb -0x28d(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x52a44
jmp 0x52d8e
leaq -0x2b8(%rbp), %rdi
movq %rdi, -0x440(%rbp)
callq 0x5720
leaq -0x2d8(%rbp), %rdi
callq 0x5720
leaq -0x2f8(%rbp), %rdi
callq 0x5720
leaq -0x318(%rbp), %rdi
callq 0x5720
movq -0x440(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x56a0
jmp 0x52a90
leaq -0x2b8(%rbp), %rdi
leaq 0x1a0a68(%rip), %rsi    # 0x1f3506
callq 0x51b0
cmpl $0x0, %eax
jne 0x52acb
movb $0x1, -0x28d(%rbp)
jmp 0x52d24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x52d59
leaq -0x3b0(%rbp), %rdi
callq 0x954b0
jmp 0x52ad9
leaq -0x258(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x56a0
jmp 0x52aee
leaq -0x370(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x56a0
jmp 0x52b03
leaq -0x258(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x56a0
jmp 0x52b18
leaq -0x258(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x5420
movq %rax, -0x448(%rbp)
jmp 0x52b34
movq -0x448(%rbp), %rdi
leaq -0x3a8(%rbp), %rsi
callq 0x5420
movq %rax, -0x450(%rbp)
jmp 0x52b50
movq -0x450(%rbp), %rdi
leaq -0x3a0(%rbp), %rsi
callq 0x5420
jmp 0x52b65
leaq -0x258(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x56a0
movq %rax, -0x458(%rbp)
jmp 0x52b81
movq -0x458(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
callq 0x56a0
movq %rax, -0x460(%rbp)
jmp 0x52b9d
movq -0x460(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x56a0
jmp 0x52bb2
movq -0x18(%rbp), %rsi
movsd -0x3b0(%rbp), %xmm0
movsd -0x3a8(%rbp), %xmm1
movsd -0x3a0(%rbp), %xmm2
leaq -0x3c8(%rbp), %rdi
callq 0x97360
jmp 0x52bdc
leaq -0x3c8(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x468(%rbp)
jmp 0x52bf3
movq -0x468(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x398(%rbp)
leaq -0x3c8(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x470(%rbp)
jmp 0x52c20
movq -0x470(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x390(%rbp)
leaq -0x3c8(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x478(%rbp)
jmp 0x52c4d
movq -0x478(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x388(%rbp)
leaq -0x370(%rbp), %rsi
leaq -0x3e8(%rbp), %rdi
callq 0x5220
jmp 0x52c75
movzbl -0x19(%rbp), %esi
andl $0x1, %esi
leaq -0x3e8(%rbp), %rdi
callq 0x466e0
movsd %xmm0, -0x480(%rbp)
jmp 0x52c92
movsd -0x480(%rbp), %xmm0
movsd %xmm0, -0x380(%rbp)
leaq -0x3e8(%rbp), %rdi
callq 0x5300
movq -0x18(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
leaq -0x3b0(%rbp), %rsi
callq 0xf190
jmp 0x52cc7
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
leaq -0x3b0(%rbp), %rdi
callq 0xf200
jmp 0x52d24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x52d16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
leaq -0x3e8(%rbp), %rdi
callq 0x5300
leaq -0x3b0(%rbp), %rdi
callq 0xf200
jmp 0x52d59
leaq -0x318(%rbp), %rdi
callq 0x5300
leaq -0x2f8(%rbp), %rdi
callq 0x5300
leaq -0x2d8(%rbp), %rdi
callq 0x5300
leaq -0x2b8(%rbp), %rdi
callq 0x5300
jmp 0x52a33
leaq -0x318(%rbp), %rdi
callq 0x5300
leaq -0x2f8(%rbp), %rdi
callq 0x5300
leaq -0x2d8(%rbp), %rdi
callq 0x5300
leaq -0x2b8(%rbp), %rdi
callq 0x5300
jmp 0x52e1c
movl -0x294(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x110(%rax)
movl -0x294(%rbp), %esi
movq 0x220215(%rip), %rdi    # 0x272fc0
callq 0x58d0
movq %rax, -0x488(%rbp)
jmp 0x52db9
movq -0x488(%rbp), %rdi
leaq 0x1a05ac(%rip), %rsi    # 0x1f3373
callq 0x5540
movq %rax, -0x490(%rbp)
jmp 0x52dd5
movq -0x490(%rbp), %rdi
movq 0x2201b5(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x52dea
leaq -0x258(%rbp), %rdi
callq 0x50a0
jmp 0x52df8
movl $0x0, -0x28c(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x5300
movl -0x28c(%rbp), %eax
testl %eax, %eax
jne 0x52e95
jmp 0x52e1a
jmp 0x52e87
leaq -0x288(%rbp), %rdi
callq 0x5300
jmp 0x52eb8
movq 0x2201bc(%rip), %rdi    # 0x272ff0
leaq 0x1a06d2(%rip), %rsi    # 0x1f350d
callq 0x5540
movq %rax, -0x498(%rbp)
jmp 0x52e49
movq -0x498(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x4a0(%rbp)
jmp 0x52e62
movq -0x4a0(%rbp), %rdi
movq 0x220128(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x52e77
movb $0x0, -0x1(%rbp)
movl $0x1, -0x28c(%rbp)
jmp 0x52e95
movb $0x1, -0x1(%rbp)
movl $0x1, -0x28c(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x5150
leaq -0x40(%rbp), %rdi
callq 0x5300
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4a0, %rsp            # imm = 0x4A0
popq %rbp
retq
leaq -0x258(%rbp), %rdi
callq 0x5150
leaq -0x40(%rbp), %rdi
callq 0x5300
movq -0x260(%rbp), %rdi
callq 0x58f0
nopl (%rax)