// File: /workspace/github_cpp_makefile_star2_O1/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 0xc345(%rip), %rsi      # 0x1ab4d
movq %r14, %rdi
callq 0x2260
testq %rax, %rax
je 0xe99f
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 0xc307(%rip), %rsi      # 0x1ab4a
movl $0x4, %edx
callq 0x2110
movl %eax, %ebp
leaq 0x20(%rsp), %rdi
movl $0x51, %esi
movq %r15, %rdx
callq 0x2360
testl %ebp, %ebp
je 0xe8de
testq %rax, %rax
je 0xe951
leaq 0x78(%rsp), %r12
leaq 0x20(%rsp), %r13
movq %rsp, %rbp
cmpb $0x41, 0x20(%rsp)
jne 0xe8c7
cmpb $0x54, 0x21(%rsp)
jne 0xe8c7
movq %r12, %rdi
movq %r13, %rdx
callq 0xeae0
movq 0x8(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0xe8b9
movl $0xc, %ecx
movq %rax, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xe8c7
movq %rbp, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x105e0
movq %r13, %rdi
movl $0x51, %esi
movq %r15, %rdx
callq 0x2360
testq %rax, %rax
jne 0xe87b
jmp 0xe951
testq %rax, %rax
je 0xe951
leaq 0x78(%rsp), %r12
leaq 0x20(%rsp), %r13
movq %rsp, %rbp
cmpb $0x41, 0x20(%rsp)
jne 0xe93c
cmpb $0x54, 0x21(%rsp)
jne 0xe93c
movq %r12, %rdi
movq %r13, %rdx
callq 0xe9dc
movq 0x8(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0xe92e
movl $0xc, %ecx
movq %rax, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xe93c
movq %rbp, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x105e0
movq %r13, %rdi
movl $0x51, %esi
movq %r15, %rdx
callq 0x2360
testq %rax, %rax
jne 0xe8f0
movq %r15, %rdi
callq 0x2210
movq 0x8(%rsp), %rax
cmpq (%rsp), %rax
je 0xe9a7
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xec4c
movq %rbx, %rdi
callq 0xf114
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xe98d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x2414
movq %r14, %rdi
callq 0x23f0
jmp 0xe9b3
jmp 0xe9b3
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xe9cc
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x1017a
movq %r14, %rdi
callq 0x2390