// File: gjoni[P]iPot/src/Residue.cpp
// Function: Residue::Residue(__gnu_cxx::__normal_iterator<AtomRecord*, std::vector<AtomRecord, std::allocator<AtomRecord>>>, __gnu_cxx::__normal_iterator<AtomRecord*, std::vector<AtomRecord, std::allocator<AtomRecord>>>)
Residue::Residue(std::vector<AtomRecord>::iterator begin_it,
		std::vector<AtomRecord>::iterator end_it) :
		seqNum(begin_it->resNum), insCode(begin_it->insCode), atom(NULL), nAtoms(
				end_it - begin_it + 1), chainId(begin_it->chainId), ntFlag(
				false), ctFlag(false), N(NULL), CA(
		NULL), C(NULL), O(NULL), CB(NULL) {

	assert(nAtoms > 0); /* pedantic check */

	strcpy(name, begin_it->resName); /* residue name is read from the 1st atom */

	/* check for alternative conformations */
	std::vector<AtomRecord>::iterator it;
	bool fl = false;
	for (it = begin_it; it <= end_it; it++) {
		if (it->altLoc != ' ') {
			fl = true;
			break;
		}
	}

	if (!fl) { /* no alternative conformations */

		/* use all atoms */
		atom = new Atom[nAtoms];
		int idx = 0;
		for (it = begin_it; it <= end_it; it++) {
			atom[idx] = Atom(*it);
			atom[idx].residue = this;
			idx++;
		}

	} else { /* there are alternative conformations */

		/* save top-populated conformation for each atom */
		std::map<std::string, std::vector<AtomRecord>::iterator> atoms_map;
		std::map<std::string, std::vector<AtomRecord>::iterator>::iterator itmap;

		atoms_map[begin_it->atomName] = begin_it;
		for (it = begin_it + 1; it <= end_it; it++) {

			/* save only atoms with the same residue name as the first atom */
			if (strcmp(begin_it->resName, it->resName) == 0) {
				itmap = atoms_map.find(it->atomName);
				if (itmap == atoms_map.end()) {
					atoms_map[it->atomName] = it;
				} else {
					if (itmap->second->occup < it->occup) {
						itmap->second = it;
					}
				}
			}
		}

		/* save marked atoms */
		atom = new Atom[atoms_map.size()];
		nAtoms = 0;
		for (itmap = atoms_map.begin(); itmap != atoms_map.end(); itmap++) {
			atom[nAtoms] = Atom(*(itmap->second));
			atom[nAtoms].residue = this;
			nAtoms++;
		}

	}

	SetBBAtoms(); /* N, CA, C, O, CB are pointers - they need to be reinitialized */

	type = SetType(name);

	SetCentroid();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x29b00
movq %rax, %rcx
movq -0x218(%rbp), %rax
movl 0x10(%rcx), %ecx
movl %ecx, 0x8(%rax)
leaq -0x8(%rbp), %rdi
callq 0x29b00
movq %rax, %rcx
movq -0x218(%rbp), %rax
movb 0x14(%rcx), %cl
movb %cl, 0xc(%rax)
movq $0x0, 0x10(%rax)
leaq -0x10(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x1e640
movq %rax, %rcx
movq -0x218(%rbp), %rax
addq $0x1, %rcx
movl %ecx, 0x18(%rax)
leaq -0x8(%rbp), %rdi
callq 0x29b00
movq %rax, %rcx
movq -0x218(%rbp), %rax
movb 0xe(%rcx), %cl
movb %cl, 0x1c(%rax)
addq $0x38, %rax
movq %rax, -0x210(%rbp)
movq %rax, %rcx
addq $0x120, %rcx            # imm = 0x120
movq %rcx, -0x208(%rbp)
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x18b10
jmp 0x2884b
movq -0x208(%rbp), %rcx
movq -0x220(%rbp), %rax
addq $0x60, %rax
cmpq %rcx, %rax
movq %rax, -0x200(%rbp)
jne 0x28836
movq -0x218(%rbp), %rax
movb $0x0, 0x158(%rax)
movb $0x0, 0x159(%rax)
movq $0x0, 0x160(%rax)
movq $0x0, 0x168(%rax)
movq $0x0, 0x170(%rax)
movq $0x0, 0x178(%rax)
movq $0x0, 0x180(%rax)
cmpl $0x0, 0x18(%rax)
jle 0x288bd
jmp 0x28936
leaq 0x126b4(%rip), %rdi     # 0x3af78
leaq 0x126b8(%rip), %rsi     # 0x3af83
movl $0x54, %edx
leaq 0x12710(%rip), %rcx     # 0x3afe7
callq 0x31b0
movq -0x210(%rbp), %rcx
movq %rax, %rsi
movq -0x220(%rbp), %rax
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
cmpq %rax, %rcx
movq %rax, -0x228(%rbp)
je 0x28931
movq -0x228(%rbp), %rdi
addq $-0x60, %rdi
movq %rdi, -0x230(%rbp)
callq 0x18e20
movq -0x210(%rbp), %rcx
movq -0x230(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x228(%rbp)
jne 0x28900
jmp 0x2926a
movq -0x218(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x238(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x29b00
movq -0x238(%rbp), %rdi
movq %rax, %rsi
addq $0xa, %rsi
callq 0x3270
leaq -0x30(%rbp), %rdi
callq 0x29b20
movb $0x0, -0x31(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x29b40
testb $0x1, %al
jne 0x2898c
jmp 0x289b7
leaq -0x30(%rbp), %rdi
callq 0x29b00
movsbl 0x9(%rax), %eax
cmpl $0x20, %eax
je 0x289a4
movb $0x1, -0x31(%rbp)
jmp 0x289b7
jmp 0x289a6
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x29b80
movq %rax, -0x40(%rbp)
jmp 0x28979
testb $0x1, -0x31(%rbp)
jne 0x28be5
movq -0x218(%rbp), %rax
movslq 0x18(%rax), %rax
movq %rax, -0x250(%rbp)
movl $0x60, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
movq $-0x1, %rax
cmovbq %rax, %rdi
testb %cl, %cl
cmovneq %rax, %rdi
movq %rdi, -0x248(%rbp)
callq 0x3030
movq %rax, -0x240(%rbp)
jmp 0x28a0b
movq -0x250(%rbp), %rax
movq -0x240(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x258(%rbp)
cmpq $0x0, %rax
je 0x28a86
movq -0x258(%rbp), %rax
movq -0x250(%rbp), %rcx
imulq $0x60, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x268(%rbp)
movq %rax, -0x260(%rbp)
movq -0x260(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x18b10
jmp 0x28a68
movq -0x268(%rbp), %rcx
movq -0x270(%rbp), %rax
addq $0x60, %rax
cmpq %rcx, %rax
movq %rax, -0x260(%rbp)
jne 0x28a53
movq -0x218(%rbp), %rax
movq -0x258(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x29b40
testb $0x1, %al
jne 0x28abd
jmp 0x28be0
leaq -0x30(%rbp), %rdi
callq 0x1ea50
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x18c80
jmp 0x28ad7
movq -0x218(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x44(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
addq %rax, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x18e30
jmp 0x28aff
leaq -0xa8(%rbp), %rdi
callq 0x18e20
movq -0x218(%rbp), %rcx
movq 0x10(%rcx), %rax
movslq -0x44(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x40(%rax)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x29b80
movq %rax, -0xb0(%rbp)
jmp 0x28aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x29223
movq -0x258(%rbp), %rcx
movq %rax, %rsi
movq -0x270(%rbp), %rax
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
cmpq %rax, %rcx
movq %rax, -0x278(%rbp)
je 0x28bab
movq -0x278(%rbp), %rdi
addq $-0x60, %rdi
movq %rdi, -0x280(%rbp)
callq 0x18e20
movq -0x258(%rbp), %rcx
movq -0x280(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x278(%rbp)
jne 0x28b7a
movq -0x248(%rbp), %rsi
movq -0x240(%rbp), %rdi
callq 0x34a0
jmp 0x29223
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x18e20
jmp 0x29223
jmp 0x291dc
leaq -0xe0(%rbp), %rdi
callq 0x29bc0
leaq -0xe8(%rbp), %rdi
callq 0x29be0
leaq -0x8(%rbp), %rdi
callq 0x29b00
addq $0x4, %rax
movq %rax, -0x290(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3470
movq -0x290(%rbp), %rsi
movq -0x288(%rbp), %rdx
leaq -0x108(%rbp), %rdi
callq 0x18790
jmp 0x28c40
leaq -0xe0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x29c00
movq %rax, -0x298(%rbp)
jmp 0x28c5c
movq -0x298(%rbp), %rax
movq -0x8(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x108(%rbp), %rdi
callq 0x3190
leaq -0x109(%rbp), %rdi
callq 0x32e0
leaq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x1bbe0
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x29b40
testb $0x1, %al
jne 0x28cb8
jmp 0x28f54
leaq -0x8(%rbp), %rdi
callq 0x29b00
addq $0xa, %rax
movq %rax, -0x2a0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x29b00
movq -0x2a0(%rbp), %rdi
movq %rax, %rsi
addq $0xa, %rsi
callq 0x33c0
cmpl $0x0, %eax
jne 0x28f3b
leaq -0x30(%rbp), %rdi
callq 0x29b00
addq $0x4, %rax
movq %rax, -0x2b0(%rbp)
leaq -0x141(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x3470
movq -0x2b0(%rbp), %rsi
movq -0x2a8(%rbp), %rdx
leaq -0x140(%rbp), %rdi
callq 0x18790
jmp 0x28d34
leaq -0xe0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x29ce0
movq %rax, -0x2b8(%rbp)
jmp 0x28d50
movq -0x2b8(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x3190
leaq -0x141(%rbp), %rdi
callq 0x32e0
leaq -0xe0(%rbp), %rdi
callq 0x29d40
movq %rax, -0x150(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x29d10
testb $0x1, %al
jne 0x28db3
jmp 0x28ee2
leaq -0x30(%rbp), %rdi
callq 0x29b00
addq $0x4, %rax
movq %rax, -0x2c8(%rbp)
leaq -0x171(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x3470
movq -0x2c8(%rbp), %rsi
movq -0x2c0(%rbp), %rdx
leaq -0x170(%rbp), %rdi
callq 0x18790
jmp 0x28df6
leaq -0xe0(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x29c00
movq %rax, -0x2d0(%rbp)
jmp 0x28e12
movq -0x2d0(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x170(%rbp), %rdi
callq 0x3190
leaq -0x171(%rbp), %rdi
callq 0x32e0
jmp 0x28f39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x28e63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3190
leaq -0x109(%rbp), %rdi
callq 0x32e0
jmp 0x291ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x28e9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x3190
leaq -0x141(%rbp), %rdi
callq 0x32e0
jmp 0x291ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x28ed1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3190
leaq -0x171(%rbp), %rdi
callq 0x32e0
jmp 0x291ce
leaq -0xe8(%rbp), %rdi
callq 0x29d70
movq %rax, %rdi
addq $0x20, %rdi
callq 0x29b00
movsd 0x30(%rax), %xmm0
movsd %xmm0, -0x2d8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x29b00
movsd -0x2d8(%rbp), %xmm1
movsd 0x30(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28f37
leaq -0xe8(%rbp), %rdi
callq 0x29d70
movq -0x30(%rbp), %rcx
movq %rcx, 0x20(%rax)
jmp 0x28f39
jmp 0x28f3b
jmp 0x28f3d
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x29b80
movq %rax, -0x180(%rbp)
jmp 0x28ca2
leaq -0xe0(%rbp), %rdi
callq 0x29d90
movq %rax, -0x2f8(%rbp)
movl $0x60, %ecx
mulq %rcx
movq -0x2f8(%rbp), %rdx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
movq $-0x1, %rax
cmovbq %rax, %rdi
movq %rdx, -0x2f0(%rbp)
testb %cl, %cl
cmovneq %rax, %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x3030
movq %rax, -0x2e0(%rbp)
jmp 0x28fad
movq -0x2f0(%rbp), %rax
movq -0x2e0(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x300(%rbp)
cmpq $0x0, %rax
je 0x29028
movq -0x300(%rbp), %rax
movq -0x2f0(%rbp), %rcx
imulq $0x60, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x310(%rbp)
movq %rax, -0x308(%rbp)
movq -0x308(%rbp), %rdi
movq %rdi, -0x318(%rbp)
callq 0x18b10
jmp 0x2900a
movq -0x310(%rbp), %rcx
movq -0x318(%rbp), %rax
addq $0x60, %rax
cmpq %rcx, %rax
movq %rax, -0x308(%rbp)
jne 0x28ff5
movq -0x218(%rbp), %rax
movq -0x300(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl $0x0, 0x18(%rax)
leaq -0xe0(%rbp), %rdi
callq 0x29db0
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x29d40
movq %rax, -0x190(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x29de0
testb $0x1, %al
jne 0x29091
jmp 0x291c0
leaq -0xe8(%rbp), %rdi
callq 0x29d70
movq %rax, %rdi
addq $0x20, %rdi
callq 0x1ea50
movq %rax, %rsi
leaq -0x1f0(%rbp), %rdi
callq 0x18c80
jmp 0x290ba
movq -0x218(%rbp), %rax
movq 0x10(%rax), %rdi
movslq 0x18(%rax), %rax
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x18e30
jmp 0x290e2
leaq -0x1f0(%rbp), %rdi
callq 0x18e20
movq -0x218(%rbp), %rax
movq 0x10(%rax), %rcx
movslq 0x18(%rax), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
movq %rax, 0x40(%rcx)
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
leaq -0xe8(%rbp), %rdi
xorl %esi, %esi
callq 0x29e10
movq %rax, -0x1f8(%rbp)
jmp 0x29062
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x291ce
movq -0x300(%rbp), %rcx
movq %rax, %rsi
movq -0x318(%rbp), %rax
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
cmpq %rax, %rcx
movq %rax, -0x320(%rbp)
je 0x29191
movq -0x320(%rbp), %rdi
addq $-0x60, %rdi
movq %rdi, -0x328(%rbp)
callq 0x18e20
movq -0x300(%rbp), %rcx
movq -0x328(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x320(%rbp)
jne 0x29160
movq -0x2e8(%rbp), %rsi
movq -0x2e0(%rbp), %rdi
callq 0x34a0
jmp 0x291ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x18e20
jmp 0x291ce
leaq -0xe0(%rbp), %rdi
callq 0x29e50
jmp 0x291dc
leaq -0xe0(%rbp), %rdi
callq 0x29e50
jmp 0x29223
movq -0x218(%rbp), %rdi
callq 0x27e40
jmp 0x291ea
movq -0x218(%rbp), %rdi
movq %rdi, %rsi
incq %rsi
callq 0x285f0
movb %al, -0x329(%rbp)
jmp 0x29204
movq -0x218(%rbp), %rdi
movb -0x329(%rbp), %al
movb %al, (%rdi)
callq 0x28650
jmp 0x2921a
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
movq -0x210(%rbp), %rax
addq $0x120, %rax            # imm = 0x120
movq %rax, -0x338(%rbp)
movq -0x338(%rbp), %rdi
addq $-0x60, %rdi
movq %rdi, -0x340(%rbp)
callq 0x18e20
movq -0x210(%rbp), %rcx
movq -0x340(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x338(%rbp)
jne 0x29237
jmp 0x2926a
movq -0x20(%rbp), %rdi
callq 0x3460
nopw %cs:(%rax,%rax)