// File: atfrank[P]PCASA/lib/Molecule.cpp
// Function: MoleculeCHARMM::format()
void MoleculeCHARMM::format(){
  Chain *chn;
  Residue *res;
  Atom *atm;
  Residue *lastRes;
  Residue *nextRes;
  int nUNK; //Number of unknown residues
  
  lastRes=NULL;
  nextRes=NULL;
  nUNK=0;

  for (unsigned int i=0; i< this->getChnVecSize(); i++){
    chn=this->getChain(i);
    for (unsigned int j=0; j< chn->getResVecSize(); j++){
      if (j>1){
        lastRes=chn->getResidue(j-1);
      }
      else{
        lastRes=NULL;
      }
      if (j< chn->getResVecSize()-1){
        nextRes=chn->getResidue(j+1);
      }
      else{
        nextRes=NULL;
      }
      res=chn->getResidue(j);
      if (res->getResName().compare(0,3,"UNK") == 0){
        nUNK++;
      }
      for (unsigned int k=0; k< res->getAtmVecSize(); k++){
        atm=res->getAtom(k);
        //if (selFlag == true && atm->getSel() == false){
        //  continue;
        //}
        //Perform Formatting
        if (atm->getResName().compare("HIE") == 0){
          atm->setResName("HSE");
        }
        else if (atm->getResName().compare("HID") == 0){
          atm->setResName("HSD");
        }
        else if (atm->getResName().compare("HIP") == 0){
          atm->setResName("HSP");
        }
        else if (atm->getResName().compare("CYX") == 0){
          std::cerr << "Warning: " << atm->getSummary() << " has a disulfide bond" << std::endl;
          this->addRemark("Warning: ");
          atm->setResName("CYS");
        }
        else if (atm->getResName().compare("AHE") == 0 && lastRes != NULL){
          atm->setResName(lastRes->getResName());
          atm->setResId(lastRes->getResId());
        }
        else if (atm->getResName().compare("NME") == 0 && lastRes != NULL){
          atm->setResName(lastRes->getResName());
          atm->setResId(lastRes->getResId());
        }
        else if (atm->getResName().compare("ACE") == 0 && nextRes != NULL){
          atm->setResName(nextRes->getResName());
          atm->setResId(nextRes->getResId());
        }
        else if (atm->getResName().compare("FOR") == 0 || atm->getResName().compare("CSO") == 0 || atm->getResName().compare("CME") == 0){
          std::cerr << "Warning: " << atm->getSummary();
          std::cerr << " has no matching residue name in CHARMM" << std::endl;
          this->addRemark("Warning: ");
          //Do nothing
        }
        else{
          //Do nothing
        }
      } 
    }
  }
  if (nUNK > 1){
    std::cerr << "Warning: More than one (" << nUNK << ") UNK residues found" << std::endl;
  }
}

// Assembly:
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rdi, 0x2c0(%rsp)
movq 0x2c0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq $0x0, 0x2a0(%rsp)
movq $0x0, 0x298(%rsp)
movl $0x0, 0x294(%rsp)
movl $0x0, 0x290(%rsp)
movq 0xe0(%rsp), %rdi
movl 0x290(%rsp), %eax
movl %eax, 0xdc(%rsp)
callq 0x41e20
movl %eax, %ecx
movl 0xdc(%rsp), %eax
cmpl %ecx, %eax
jae 0x46b6b
movq 0xe0(%rsp), %rdi
leaq 0x290(%rsp), %rsi
callq 0x41e40
movq %rax, 0x2b8(%rsp)
movl $0x0, 0x28c(%rsp)
movl 0x28c(%rsp), %eax
movl %eax, 0xd8(%rsp)
movq 0x2b8(%rsp), %rdi
callq 0x3a570
movl %eax, %ecx
movl 0xd8(%rsp), %eax
cmpl %ecx, %eax
jae 0x46b53
cmpl $0x1, 0x28c(%rsp)
jbe 0x46117
movq 0x2b8(%rsp), %rdi
movl 0x28c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x288(%rsp)
leaq 0x288(%rsp), %rsi
callq 0x3a490
movq %rax, 0x2a0(%rsp)
jmp 0x46123
movq $0x0, 0x2a0(%rsp)
movl 0x28c(%rsp), %eax
movl %eax, 0xd4(%rsp)
movq 0x2b8(%rsp), %rdi
callq 0x3a570
movl %eax, %ecx
movl 0xd4(%rsp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x4617e
movq 0x2b8(%rsp), %rdi
movl 0x28c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x284(%rsp)
leaq 0x284(%rsp), %rsi
callq 0x3a490
movq %rax, 0x298(%rsp)
jmp 0x4618a
movq $0x0, 0x298(%rsp)
movq 0x2b8(%rsp), %rdi
leaq 0x28c(%rsp), %rsi
callq 0x3a490
movq %rax, 0x2b0(%rsp)
movq 0x2b0(%rsp), %rsi
leaq 0x260(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x5dfa0
movq 0xc8(%rsp), %rdi
leaq 0x362a6(%rip), %rcx     # 0x7c479
xorl %eax, %eax
movl %eax, %esi
movl $0x3, %edx
callq 0x55a0
movl %eax, 0xd0(%rsp)
jmp 0x461ea
leaq 0x260(%rsp), %rdi
callq 0x5250
movl 0xd0(%rsp), %eax
cmpl $0x0, %eax
jne 0x4623c
movl 0x294(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x294(%rsp)
jmp 0x4623c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x5250
jmp 0x46bbd
movl $0x0, 0x250(%rsp)
movl 0x250(%rsp), %eax
movl %eax, 0xc4(%rsp)
movq 0x2b0(%rsp), %rdi
callq 0x5e110
movl %eax, %ecx
movl 0xc4(%rsp), %eax
cmpl %ecx, %eax
jae 0x46b3b
movq 0x2b0(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x5df30
movq %rax, 0x2a8(%rsp)
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x35190(%rip), %rsi     # 0x7b437
callq 0x5140
cmpl $0x0, %eax
jne 0x46377
movq 0x2a8(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0x22f(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x5730
movq 0xb8(%rsp), %rdx
leaq 0x350f0(%rip), %rsi     # 0x7b3d9
leaq 0x230(%rsp), %rdi
callq 0x7900
jmp 0x462f8
movq 0xb0(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0x1fda0
jmp 0x4630f
leaq 0x230(%rsp), %rdi
callq 0x5250
leaq 0x22f(%rsp), %rdi
callq 0x5480
jmp 0x46b23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x46365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x230(%rsp), %rdi
callq 0x5250
leaq 0x22f(%rsp), %rdi
callq 0x5480
jmp 0x46bbd
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x350a5(%rip), %rsi     # 0x7b433
callq 0x5140
cmpl $0x0, %eax
jne 0x4645e
movq 0x2a8(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0x207(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x5730
movq 0xa8(%rsp), %rdx
leaq 0x35005(%rip), %rsi     # 0x7b3d5
leaq 0x208(%rsp), %rdi
callq 0x7900
jmp 0x463df
movq 0xa0(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0x1fda0
jmp 0x463f6
leaq 0x208(%rsp), %rdi
callq 0x5250
leaq 0x207(%rsp), %rdi
callq 0x5480
jmp 0x46b21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x4644c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x208(%rsp), %rdi
callq 0x5250
leaq 0x207(%rsp), %rdi
callq 0x5480
jmp 0x46bbd
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x34fc6(%rip), %rsi     # 0x7b43b
callq 0x5140
cmpl $0x0, %eax
jne 0x46545
movq 0x2a8(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x1df(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x5730
movq 0x98(%rsp), %rdx
leaq 0x34f26(%rip), %rsi     # 0x7b3dd
leaq 0x1e0(%rsp), %rdi
callq 0x7900
jmp 0x464c6
movq 0x90(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x1fda0
jmp 0x464dd
leaq 0x1e0(%rsp), %rdi
callq 0x5250
leaq 0x1df(%rsp), %rdi
callq 0x5480
jmp 0x46b1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x46533
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x5250
leaq 0x1df(%rsp), %rdi
callq 0x5480
jmp 0x46bbd
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x35f21(%rip), %rsi     # 0x7c47d
callq 0x5140
cmpl $0x0, %eax
jne 0x46726
movq 0x3f4a7f(%rip), %rdi    # 0x43aff0
leaq 0x35f09(%rip), %rsi     # 0x7c481
movq %rsi, 0x80(%rsp)
callq 0x53f0
movq %rax, 0x78(%rsp)
movq 0x2a8(%rsp), %rdi
callq 0x1f7a0
movq 0x78(%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq %rax, %rdi
leaq 0x35edd(%rip), %rsi     # 0x7c48b
callq 0x53f0
movq %rax, %rdi
movq 0x3f49eb(%rip), %rsi    # 0x43afa8
callq 0x5460
leaq 0x1b7(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x5730
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
leaq 0x1b8(%rsp), %rdi
callq 0x7900
jmp 0x465f6
movq 0xe0(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x46bd0
jmp 0x4660d
leaq 0x1b8(%rsp), %rdi
callq 0x5250
leaq 0x1b7(%rsp), %rdi
callq 0x5480
movq 0x2a8(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x18f(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x5730
movq 0x70(%rsp), %rdx
leaq 0x35149(%rip), %rsi     # 0x7b79b
leaq 0x190(%rsp), %rdi
callq 0x7900
jmp 0x46661
movq 0x68(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x1fda0
jmp 0x46675
leaq 0x190(%rsp), %rdi
callq 0x5250
leaq 0x18f(%rsp), %rdi
callq 0x5480
jmp 0x46b1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x466cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x5250
leaq 0x1b7(%rsp), %rdi
callq 0x5480
jmp 0x46bbd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x46714
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x5250
leaq 0x18f(%rsp), %rdi
callq 0x5480
jmp 0x46bbd
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x35d64(%rip), %rsi     # 0x7c4a1
callq 0x5140
cmpl $0x0, %eax
jne 0x467fd
cmpq $0x0, 0x2a0(%rsp)
je 0x467fd
movq 0x2a8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x2a0(%rsp), %rsi
leaq 0x168(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x5dfa0
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x1fda0
jmp 0x46792
leaq 0x168(%rsp), %rdi
callq 0x5250
movq 0x2a8(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x2a0(%rsp), %rdi
callq 0x5df00
movq 0x50(%rsp), %rdi
movl %eax, 0x164(%rsp)
leaq 0x164(%rsp), %rsi
callq 0x1feb0
jmp 0x46b1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x5250
jmp 0x46bbd
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x35c91(%rip), %rsi     # 0x7c4a5
callq 0x5140
cmpl $0x0, %eax
jne 0x468d4
cmpq $0x0, 0x2a0(%rsp)
je 0x468d4
movq 0x2a8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x2a0(%rsp), %rsi
leaq 0x140(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x5dfa0
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x1fda0
jmp 0x46869
leaq 0x140(%rsp), %rdi
callq 0x5250
movq 0x2a8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x2a0(%rsp), %rdi
callq 0x5df00
movq 0x38(%rsp), %rdi
movl %eax, 0x13c(%rsp)
leaq 0x13c(%rsp), %rsi
callq 0x1feb0
jmp 0x46b19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x5250
jmp 0x46bbd
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x35bbe(%rip), %rsi     # 0x7c4a9
callq 0x5140
cmpl $0x0, %eax
jne 0x469ab
cmpq $0x0, 0x298(%rsp)
je 0x469ab
movq 0x2a8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x298(%rsp), %rsi
leaq 0x118(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x5dfa0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x1fda0
jmp 0x46940
leaq 0x118(%rsp), %rdi
callq 0x5250
movq 0x2a8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x298(%rsp), %rdi
callq 0x5df00
movq 0x20(%rsp), %rdi
movl %eax, 0x114(%rsp)
leaq 0x114(%rsp), %rsi
callq 0x1feb0
jmp 0x46b17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x5250
jmp 0x46bbd
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x36495(%rip), %rsi     # 0x7ce57
callq 0x5140
cmpl $0x0, %eax
je 0x46a12
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x35aca(%rip), %rsi     # 0x7c4ad
callq 0x5140
cmpl $0x0, %eax
je 0x46a12
movq 0x2a8(%rsp), %rdi
callq 0x1f620
movq %rax, %rdi
leaq 0x35aad(%rip), %rsi     # 0x7c4b1
callq 0x5140
cmpl $0x0, %eax
jne 0x46b13
movq 0x3f45d7(%rip), %rdi    # 0x43aff0
movq %rdi, 0x8(%rsp)
leaq 0x35a5c(%rip), %rsi     # 0x7c481
movq %rsi, 0x10(%rsp)
callq 0x53f0
movq %rax, (%rsp)
movq 0x2a8(%rsp), %rdi
callq 0x1f7a0
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x5390
movq 0x8(%rsp), %rdi
leaq 0x35a5d(%rip), %rsi     # 0x7c4b5
callq 0x53f0
movq %rax, %rdi
movq 0x3f4541(%rip), %rsi    # 0x43afa8
callq 0x5460
leaq 0xef(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x5730
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0xf0(%rsp), %rdi
callq 0x7900
jmp 0x46a97
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x46bd0
jmp 0x46aae
leaq 0xf0(%rsp), %rdi
callq 0x5250
leaq 0xef(%rsp), %rdi
callq 0x5480
jmp 0x46b15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x46b01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x5250
leaq 0xef(%rsp), %rdi
callq 0x5480
jmp 0x46bbd
jmp 0x46b15
jmp 0x46b17
jmp 0x46b19
jmp 0x46b1b
jmp 0x46b1d
jmp 0x46b1f
jmp 0x46b21
jmp 0x46b23
jmp 0x46b25
movl 0x250(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x250(%rsp)
jmp 0x46247
jmp 0x46b3d
movl 0x28c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28c(%rsp)
jmp 0x460b1
jmp 0x46b55
movl 0x290(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x290(%rsp)
jmp 0x4605d
cmpl $0x1, 0x294(%rsp)
jle 0x46bb5
movq 0x3f4474(%rip), %rdi    # 0x43aff0
leaq 0x3595a(%rip), %rsi     # 0x7c4dd
callq 0x53f0
movq %rax, %rdi
movl 0x294(%rsp), %esi
callq 0x56f0
movq %rax, %rdi
leaq 0x35955(%rip), %rsi     # 0x7c4f6
callq 0x53f0
movq %rax, %rdi
movq 0x3f43f8(%rip), %rsi    # 0x43afa8
callq 0x5460
addq $0x2c8, %rsp            # imm = 0x2C8
retq
movq 0x258(%rsp), %rdi
callq 0x5720
nopw (%rax,%rax)