// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
leaq 0x88(%rdi), %rax
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
leaq 0x18(%rsp), %r12
leaq 0x111ed(%rip), %r13     # 0x2d51b
movl $0x0, 0x10(%rsp)
movq %rdi, 0x50(%rsp)
movl %ecx, 0x3c(%rsp)
movq 0x10(%rdi), %rax
subq 0x8(%rdi), %rax
shrq $0x3, %rax
cmpl %eax, %ecx
jae 0x1c78c
movq %rcx, 0x58(%rsp)
leaq 0x3c(%rsp), %rsi
callq 0x19fb0
movq %rax, %r14
xorl %ebx, %ebx
movq %rax, 0x60(%rsp)
movl %ebx, 0xc(%rsp)
movq %r14, %rdi
callq 0x1786c
cmpl %eax, %ebx
jae 0x1c77b
movl 0xc(%rsp), %ebx
cmpl $0x2, %ebx
jb 0x1c3a3
decl %ebx
movl %ebx, 0x18(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x17802
movq %rax, %rbp
movl 0xc(%rsp), %ebx
jmp 0x1c3a5
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x1786c
decl %eax
cmpl %eax, %ebx
jae 0x1c3cf
movl 0xc(%rsp), %eax
incl %eax
movl %eax, 0x18(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x17802
movq %rax, 0x40(%rsp)
jmp 0x1c3d8
movq $0x0, 0x40(%rsp)
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x17802
movq %rax, %r14
movq %r12, %rdi
movq %rax, %rsi
callq 0x23a16
movq %r12, %rdi
xorl %esi, %esi
pushq $0x3
popq %rdx
leaq 0x120a3(%rip), %rcx     # 0x2e4a5
callq 0x43f0
movl %eax, %r15d
movq %r12, %rdi
callq 0x4170
cmpl $0x1, %r15d
adcl $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movl %ebx, 0x14(%rsp)
movq %r14, %rdi
callq 0x23aee
cmpl %eax, %ebx
jae 0x1c76b
movq %r14, %rdi
leaq 0x14(%rsp), %rsi
callq 0x239f2
movq %rax, %r15
movq %rax, %rdi
callq 0xea0c
movq %rax, %rdi
movq %r13, %rsi
callq 0x4100
testl %eax, %eax
je 0x1c4fc
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x110a9(%rip), %rsi     # 0x2d517
callq 0x4100
testl %eax, %eax
je 0x1c51d
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x11092(%rip), %rsi     # 0x2d51f
callq 0x4100
testl %eax, %eax
je 0x1c53e
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x11ffd(%rip), %rsi     # 0x2e4a9
callq 0x4100
testl %eax, %eax
je 0x1c570
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x12002(%rip), %rsi     # 0x2e4cd
callq 0x4100
testq %rbp, %rbp
je 0x1c60b
testl %eax, %eax
jne 0x1c60b
movq %r12, %rdi
movq %rbp, %rsi
callq 0x23a16
movq %r15, %rdi
movq %r12, %rsi
callq 0xed82
jmp 0x1c641
movq %r12, %rdi
leaq 0x10fb7(%rip), %rsi     # 0x2d4bd
leaq 0xb(%rsp), %rdx
callq 0x58d8
movq %r15, %rdi
movq %r12, %rsi
callq 0xed82
jmp 0x1c55d
movq %r12, %rdi
leaq 0x10f92(%rip), %rsi     # 0x2d4b9
leaq 0xb(%rsp), %rdx
callq 0x58d8
movq %r15, %rdi
movq %r12, %rsi
callq 0xed82
jmp 0x1c55d
movq %r12, %rdi
leaq 0x10f79(%rip), %rsi     # 0x2d4c1
leaq 0xb(%rsp), %rdx
callq 0x58d8
movq %r15, %rdi
movq %r12, %rsi
callq 0xed82
movq %r12, %rdi
callq 0x4170
movl 0x14(%rsp), %ebx
incl %ebx
jmp 0x1c41d
movq 0x3c8a79(%rip), %rdi    # 0x3e4ff0
leaq 0x11f2f(%rip), %r13     # 0x2e4ad
movq %r13, %rsi
callq 0x4300
movq %rax, %rbx
movq %r15, %rdi
callq 0xea6c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq %rax, %rdi
leaq 0x11f11(%rip), %rsi     # 0x2e4b7
callq 0x4300
movq %rax, %rdi
callq 0x4180
movq %r12, %rdi
movq %r13, %rsi
leaq 0xb(%rsp), %rdx
callq 0x58d8
movq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x45e0
movq %r12, %rdi
callq 0x4170
movq %r12, %rdi
leaq 0x1120b(%rip), %rsi     # 0x2d7ed
leaq 0xb(%rsp), %rdx
callq 0x58d8
movq %r15, %rdi
movq %r12, %rsi
callq 0xed82
movq %r12, %rdi
callq 0x4170
leaq 0x10f15(%rip), %r13     # 0x2d51b
jmp 0x1c565
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x11eb4(%rip), %rsi     # 0x2e4d1
callq 0x4100
testq %rbp, %rbp
je 0x1c665
testl %eax, %eax
jne 0x1c665
movq %r12, %rdi
movq %rbp, %rsi
callq 0x23a16
movq %r15, %rdi
movq %r12, %rsi
callq 0xed82
movq %r12, %rdi
callq 0x4170
movq %rbp, %rdi
callq 0x239d8
movl %eax, 0x18(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xedea
jmp 0x1c565
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x11e5e(%rip), %rsi     # 0x2e4d5
callq 0x4100
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x1c6ad
testl %eax, %eax
jne 0x1c6ad
movq %r12, %rdi
movq %rbx, %rsi
callq 0x23a16
movq %r15, %rdi
movq %r12, %rsi
callq 0xed82
movq %r12, %rdi
callq 0x4170
movq %rbx, %rdi
jmp 0x1c64c
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x127c4(%rip), %rsi     # 0x2ee83
callq 0x4100
testl %eax, %eax
je 0x1c702
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x11dff(%rip), %rsi     # 0x2e4d9
callq 0x4100
testl %eax, %eax
je 0x1c702
movq %r15, %rdi
callq 0xea0c
movq %rax, %rdi
leaq 0x11de8(%rip), %rsi     # 0x2e4dd
callq 0x4100
testl %eax, %eax
jne 0x1c565
movq 0x3c88e7(%rip), %rdi    # 0x3e4ff0
leaq 0x11d9d(%rip), %r13     # 0x2e4ad
movq %r13, %rsi
callq 0x4300
movq %rax, %rbx
movq %r15, %rdi
callq 0xea6c
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42c0
movq 0x3c88bb(%rip), %rdi    # 0x3e4ff0
leaq 0x11da5(%rip), %rsi     # 0x2e4e1
callq 0x4300
movq %rax, %rdi
callq 0x4180
movq %r12, %rdi
movq %r13, %rsi
leaq 0xb(%rsp), %rdx
callq 0x58d8
movq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x45e0
jmp 0x1c5f7
movl 0xc(%rsp), %ebx
incl %ebx
movq 0x60(%rsp), %r14
jmp 0x1c36c
movq 0x58(%rsp), %rcx
incl %ecx
movq 0x50(%rsp), %rdi
jmp 0x1c33b
movl 0x10(%rsp), %ebx
cmpl $0x1, %ebx
jle 0x1c7c9
movq 0x3c8854(%rip), %rdi    # 0x3e4ff0
leaq 0x11d66(%rip), %rsi     # 0x2e509
callq 0x4300
movq %rax, %rdi
movl %ebx, %esi
callq 0x4520
leaq 0x11d69(%rip), %rsi     # 0x2e522
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c7f4
jmp 0x1c803
jmp 0x1c7f4
jmp 0x1c7f4
jmp 0x1c7f4
jmp 0x1c7f4
jmp 0x1c803
jmp 0x1c803
jmp 0x1c7f4
jmp 0x1c7f4
jmp 0x1c7f4
jmp 0x1c803
jmp 0x1c803
jmp 0x1c7f4
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4170
jmp 0x1c806
movq %rax, %rbx
movq %rbx, %rdi
callq 0x4560