// File: 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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x168(%rbp)
movq %rdi, %rax
movq %rax, -0x170(%rbp)
callq 0x1b880
movq -0x168(%rbp), %rax
movq $0x0, 0x30(%rax)
movl $0x0, 0x38(%rax)
movq $0x0, 0x40(%rax)
movl $0x0, 0x48(%rax)
movq $0x0, 0x50(%rax)
movq $0x0, 0x58(%rax)
movq $0x0, 0x60(%rax)
movq $0x0, 0x68(%rax)
movq -0x10(%rbp), %rdi
leaq 0x1ba70(%rip), %rsi     # 0x34b4d
callq 0x3310
movq %rax, -0x160(%rbp)
jmp 0x190eb
movq -0x160(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x19134
movq 0x34edc(%rip), %rax     # 0x4dfe0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1ba17(%rip), %rsi     # 0x34b29
movb $0x0, %al
callq 0x33d0
movl $0x1, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x192f7
leaq -0x98(%rbp), %rdi
callq 0x1b8a0
movq -0x10(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3130
movq -0x178(%rbp), %rdi
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x1b9e1(%rip), %rsi     # 0x34b4a
movl $0x4, %edx
callq 0x3140
cmpl $0x0, %eax
jne 0x1920c
jmp 0x1917e
movq -0x18(%rbp), %rdx
leaq -0x80(%rbp), %rdi
movl $0x51, %esi
callq 0x3410
movq %rax, -0x180(%rbp)
jmp 0x19199
movq -0x180(%rbp), %rax
cmpq $0x0, %rax
je 0x1920a
movsbl -0x80(%rbp), %eax
cmpl $0x41, %eax
jne 0x19205
movsbl -0x7f(%rbp), %eax
cmpl $0x54, %eax
jne 0x19205
movq -0x170(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x19310
jmp 0x191d1
leaq -0x98(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x1b8c0
jmp 0x191e6
jmp 0x19205
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1b920
jmp 0x192f7
jmp 0x1917e
jmp 0x1927c
jmp 0x1920e
movq -0x18(%rbp), %rdx
leaq -0x80(%rbp), %rdi
movl $0x51, %esi
callq 0x3410
movq %rax, -0x188(%rbp)
jmp 0x19229
movq -0x188(%rbp), %rax
cmpq $0x0, %rax
je 0x1927a
movsbl -0x80(%rbp), %eax
cmpl $0x41, %eax
jne 0x19278
movsbl -0x7f(%rbp), %eax
cmpl $0x54, %eax
jne 0x19278
movq -0x170(%rbp), %rsi
leaq -0x158(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x19490
jmp 0x19261
leaq -0x98(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x1b8c0
jmp 0x19276
jmp 0x19278
jmp 0x1920e
jmp 0x1927c
movq -0x18(%rbp), %rdi
callq 0x3290
jmp 0x19287
leaq -0x98(%rbp), %rdi
callq 0x1b8f0
cmpq $0x0, %rax
jne 0x192bf
movq 0x34d40(%rip), %rax     # 0x4dfe0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1b8a1(%rip), %rsi     # 0x34b4f
movb $0x0, %al
callq 0x33d0
movl $0x1, %edi
callq 0x3330
movq -0x170(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x196b0
jmp 0x192d4
movq -0x170(%rbp), %rdi
callq 0x19da0
jmp 0x192e2
leaq -0x98(%rbp), %rdi
callq 0x1b920
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x168(%rbp), %rdi
callq 0x1b980
movq -0x20(%rbp), %rdi
callq 0x3460
nopl (%rax)