// File: /workspace/github_cpp_makefile_star2_O3/gjoni[P]iPot/src/Chain.cpp
// Function: Chain::Chain(char const*)
Chain::Chain(const char *name) :
		atom(NULL), nAtoms(0), residue(NULL), nRes(0), kd(NULL), kdCA(
		NULL), kdCent(NULL), ca_trace(NULL) {

	/* open file */
	FILE *F;
	F = fopen(name, "r");
	if (F == NULL) {
		fprintf(stderr, "ERROR: Can't open PDB file '%s'\n", name);
		exit(1);
	}

	/* read file */
	char buf[81];
	std::vector<AtomRecord> atomRecordVector;

	/* read according to type */
	if (strncmp(name + strlen(name) - 4, ".pqr", 4) == 0) {

		/* read as PQR */
		while (fgets(buf, 81, F) != NULL) {
			if ((buf[0] == 'A') && (buf[1] == 'T')) {
				atomRecordVector.push_back(ReadAtomRecordPQR(buf));
			}
		}

	} else {

		/* read as PDB (in all other cases) */
		while (fgets(buf, 81, F) != NULL) {
			if ((buf[0] == 'A') && (buf[1] == 'T')) {
				atomRecordVector.push_back(ReadAtomRecord(buf));
			}
		}

	}
	fclose(F);

	if (atomRecordVector.size() == 0) {
		fprintf(stderr, "ERROR: No atoms were read from %s\n", name);
		exit(1);
	}

	InitChain(atomRecordVector);

	SetResMap();

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x8(%rdi), %rax
xorl %ecx, %ecx
movl %ecx, 0x8(%rdi)
movq %rcx, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movq %rcx, 0x40(%rdi)
movl %ecx, 0x48(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rdi)
movl %ecx, 0x38(%rdi)
movups %xmm0, 0x50(%rdi)
movups %xmm0, 0x60(%rdi)
leaq 0xc4c9(%rip), %rsi      # 0x1ab4d
movq %r14, %rdi
callq 0x2250
testq %rax, %rax
je 0xe81b
movq %rax, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %r14, %rdi
callq 0x2100
leaq (%r14,%rax), %rdi
addq $-0x4, %rdi
leaq 0xc48b(%rip), %rsi      # 0x1ab4a
movl $0x4, %edx
callq 0x2110
movl %eax, %ebp
leaq 0x20(%rsp), %rdi
movl $0x51, %esi
movq %r15, %rdx
callq 0x2350
testl %ebp, %ebp
je 0xe75a
testq %rax, %rax
je 0xe7cd
leaq 0x78(%rsp), %r12
leaq 0x20(%rsp), %r13
movq %rsp, %rbp
cmpb $0x41, 0x20(%rsp)
jne 0xe743
cmpb $0x54, 0x21(%rsp)
jne 0xe743
movq %r12, %rdi
movq %r13, %rdx
callq 0xe954
movq 0x8(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0xe735
movl $0xc, %ecx
movq %rax, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xe743
movq %rbp, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x1041c
movq %r13, %rdi
movl $0x51, %esi
movq %r15, %rdx
callq 0x2350
testq %rax, %rax
jne 0xe6f7
jmp 0xe7cd
testq %rax, %rax
je 0xe7cd
leaq 0x78(%rsp), %r12
leaq 0x20(%rsp), %r13
movq %rsp, %rbp
cmpb $0x41, 0x20(%rsp)
jne 0xe7b8
cmpb $0x54, 0x21(%rsp)
jne 0xe7b8
movq %r12, %rdi
movq %r13, %rdx
callq 0xe858
movq 0x8(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0xe7aa
movl $0xc, %ecx
movq %rax, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xe7b8
movq %rbp, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x1041c
movq %r13, %rdi
movl $0x51, %esi
movq %r15, %rdx
callq 0x2350
testq %rax, %rax
jne 0xe76c
movq %r15, %rdi
callq 0x2200
movq 0x8(%rsp), %rax
cmpq (%rsp), %rax
je 0xe823
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xeac0
movq %rbx, %rdi
callq 0xef7a
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xe809
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x2404
movq %r14, %rdi
callq 0x23e0
jmp 0xe82f
jmp 0xe82f
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xe848
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq %rbx, %rdi
callq 0xffc2
movq %r14, %rdi
callq 0x2380