// File: /workspace/github_cpp_makefile_star2_O1/TBody[P]atomicpp/atomicpp/ImpuritySpecies.cpp
// Function: atomicpp::ImpuritySpecies::ImpuritySpecies(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
ImpuritySpecies::ImpuritySpecies(std::string& impurity_symbol_supplied){
	// Constructor for the ImpuritySpecies class
	// Input is a std::string, which typically should be of length 1 (i.e. "c" for carbon, "n" for nitrogen)
	// Will return an ImpuritySpecies object
	
	// Convert impurity_symbol_supplied to lowercase (this is what impurity_user_input uses as a key)
	impurity_symbol_supplied[0] = tolower(impurity_symbol_supplied[0]);

	// Declare the path to the JSON file which contains hard-coded parameters for the ADAS data corresponding to the impurities
	// std::string user_file = get_impurity_user_input();
	std::string user_file = "impurity_user_input.json";

	// Declare the path the directory which contains the JSON files created from OpenADAS .dat files
	// To convert .dat to .json, see https://github.com/TBody/OpenADAS_to_JSON (should be included as a subdirectory of SD1D)
	// std::string json_database_path = get_json_database_path();
	std::string json_database_path = "json_database/json_data";

	// Define a std::map between a recognisable key for various physics process, and the 3-letter code used by OpenADAS to represent this data
	std::map<std::string,std::string>datatype_abbrevs={
		{"ionisation",           "scd"},
		{"recombination",        "acd"},
		{"cx_rec",              "ccd"},
		{"continuum_power",      "prb"},
		{"line_power",           "plt"},
		{"cx_power",             "prc"},
		{"ionisation_potential", "ecd"} //N.b. ionisation_potential is not a rate-coefficient, but most of the methods are transferable
	};

	// Save from impurity_symbol_supplied and the hard-coded data within user_file
	symbol              = impurity_symbol_supplied;
	// retrieve from JSON and std::set attributes
	
	json j_object = retrieveFromJSON(user_file);
	auto check_symbol_in_file = j_object.find(impurity_symbol_supplied);
	if ((check_symbol_in_file != j_object.end())){
		name                = j_object[impurity_symbol_supplied]["name"];
		year                = j_object[impurity_symbol_supplied]["year"];
		has_charge_exchange = j_object[impurity_symbol_supplied]["has_charge_exchange"];
		atomic_number       = j_object[impurity_symbol_supplied]["atomic_number"];
		double mass_in_amu  = j_object[impurity_symbol_supplied]["mass"]; //in amu
		mass                = mass_in_amu;
	} else {
		std::cout << "Error: "<< impurity_symbol_supplied << " not found in " << user_file << "\n";
		throw std::invalid_argument( "Key not found in user input file" );
	};

	// Add the JSON files associated with this impurity to its .adas_files_dict attribute where the key is the (extended) process name, which std::maps to a filename (std::string)
	// Mark the physics processes which rely on charge exchange
	std::set<std::string> cx_processes{datatype_abbrevs["cx_rec"],datatype_abbrevs["cx_power"]};
	// Iterate over the key -> value pairs in datatype_abbrevs
	for (auto& kv : datatype_abbrevs) {
		std::string physics_process = kv.first;
		std::string filetype_code = kv.second;
		// Check to see if physics_process is a charge exchange process
		bool code_is_cx = find(begin(cx_processes), end(cx_processes), filetype_code) != end(cx_processes);
		// If it is, and the element doesn't have charge exchange data, then skip this process
		if (get_has_charge_exchange() or not(code_is_cx)){
			// Otherwise, add the filenames of the json files corresponding to the rate-coefficients for the physics process to .adas_files_dict
		    addJSONFiles(physics_process, filetype_code, json_database_path);
		};
	}

	// Use the .adas_file_dict files to generate RateCoefficient objects for each process
	// Uses the same keys as .adas_file_dict
	makeRateCoefficients();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %rsi, %r13
movq %rdi, %r14
callq 0x4300
leaq 0x20(%r14), %rdi
movq %rdi, -0x60(%rbp)
callq 0x4300
leaq 0x58(%r14), %rdi
movq %rdi, -0x78(%rbp)
callq 0xc690
leaq 0x88(%r14), %rdi
movq %rdi, -0x70(%rbp)
callq 0xc69a
movq %r13, %rdi
xorl %esi, %esi
callq 0x4640
movsbl (%rax), %edi
callq 0x4490
movl %eax, %ebx
movq %r13, %rdi
xorl %esi, %esi
callq 0x4640
movb %bl, (%rax)
leaq -0x378(%rbp), %rbx
movq %rbx, %rdi
callq 0x4540
leaq 0x18441(%rip), %rsi     # 0x23770
leaq -0xf8(%rbp), %rdi
movq %rbx, %rdx
movq %r14, -0x38(%rbp)
callq 0x4160
leaq -0x378(%rbp), %rdi
callq 0x58c6
movq %rbx, %rdi
callq 0x4540
leaq 0x1842c(%rip), %rsi     # 0x23789
leaq -0x188(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
movq %rbx, %rdi
callq 0x58c6
leaq 0x16cc5(%rip), %rsi     # 0x22040
leaq 0x1841f(%rip), %rdx     # 0x237a1
movq %rbx, %r14
movq %rbx, %rdi
callq 0xc6a4
leaq -0x338(%rbp), %r14
leaq 0x16cb0(%rip), %rsi     # 0x2204b
leaq 0x18403(%rip), %rdx     # 0x237a5
movq %r14, %rdi
callq 0xc73e
leaq -0x2f8(%rbp), %r14
leaq 0x183f1(%rip), %rsi     # 0x237a9
leaq 0x183f1(%rip), %rdx     # 0x237b0
movq %r14, %rdi
callq 0xc7d8
leaq -0x2b8(%rbp), %r14
leaq 0x183df(%rip), %rsi     # 0x237b4
leaq 0x183e8(%rip), %rdx     # 0x237c4
movq %r14, %rdi
callq 0xc872
leaq -0x278(%rbp), %r14
leaq 0x183d6(%rip), %rsi     # 0x237c8
leaq 0x183da(%rip), %rdx     # 0x237d3
movq %r14, %rdi
callq 0xc6a4
leaq -0x238(%rbp), %r14
leaq 0x183c8(%rip), %rsi     # 0x237d7
leaq 0x183ca(%rip), %rdx     # 0x237e0
movq %r14, %rdi
callq 0xc90c
leaq -0x1f8(%rbp), %r14
leaq 0x183b8(%rip), %rsi     # 0x237e4
leaq 0x183c6(%rip), %rdx     # 0x237f9
movq %r14, %rdi
callq 0xc9a6
leaq -0xd8(%rbp), %rbx
movq %rbx, %rdi
callq 0xca40
leaq -0x168(%rbp), %rdi
leaq -0x378(%rbp), %rsi
leaq -0x1b8(%rbp), %rcx
movl $0x7, %edx
movq %rbx, %r8
movq -0x38(%rbp), %r14
callq 0xca4a
leaq -0xd8(%rbp), %rdi
callq 0xcadc
movl $0x180, %ebx            # imm = 0x180
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x5870
addq $-0x40, %rbx
cmpq $-0x40, %rbx
jne 0xb481
movq %r14, %rdi
movq %r13, %rsi
callq 0x4060
leaq -0x138(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x4480
leaq -0x58(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5c50
leaq -0x138(%rbp), %rdi
callq 0x41a0
leaq -0x118(%rbp), %rdi
movq %r13, %rsi
callq 0x4480
leaq -0xd8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0xcae2
leaq -0x118(%rbp), %rdi
callq 0x41a0
leaq -0x378(%rbp), %rbx
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0xcb32
leaq -0xd8(%rbp), %rdi
movq %rbx, %rsi
callq 0xcb24
testb %al, %al
je 0xb885
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8e74
leaq 0x182b9(%rip), %rsi     # 0x237fd
movq %rax, %rdi
callq 0xcb52
leaq -0x378(%rbp), %rdi
movq %rax, %rsi
callq 0xcc98
leaq -0x378(%rbp), %r12
movq -0x60(%rbp), %rdi
movq %r12, %rsi
callq 0x4420
movq %r12, %rdi
callq 0x41a0
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8e74
leaq 0x18279(%rip), %rsi     # 0x23802
movq %rax, %rdi
callq 0xcb52
movq %rax, %rdi
callq 0xccb0
movl %eax, 0x40(%r14)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8e74
leaq 0x18257(%rip), %rsi     # 0x23807
movq %rax, %rdi
callq 0xcb52
movq %rax, %rdi
callq 0xccba
movb %al, 0x44(%r14)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8e74
leaq 0x18244(%rip), %rsi     # 0x2381b
movq %rax, %rdi
callq 0xcb52
movq %rax, %rdi
callq 0xccb0
movl %eax, 0x48(%r14)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8e74
leaq 0x1822b(%rip), %rsi     # 0x23829
movq %rax, %rdi
callq 0xcb52
movq %rax, %rdi
callq 0xccc4
movsd %xmm0, 0x50(%r14)
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x4540
leaq 0x18182(%rip), %rsi     # 0x237a9
leaq -0xb8(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
leaq -0x168(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xccce
leaq -0x378(%rbp), %rdi
movq %rax, %rsi
callq 0x4480
leaq -0x358(%rbp), %r15
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x4540
leaq 0x18165(%rip), %rsi     # 0x237d7
leaq -0x98(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
leaq -0x168(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xccce
movq %r15, %rdi
movq %rax, %rsi
callq 0x4480
leaq -0x29(%rbp), %rbx
movq %rbx, %rdi
callq 0x60de
leaq -0x1b8(%rbp), %rdi
leaq -0x378(%rbp), %rsi
leaq -0x68(%rbp), %rcx
movl $0x2, %edx
movq %rbx, %r8
callq 0xcd8c
leaq -0x29(%rbp), %rdi
callq 0x6104
movl $0x20, %ebx
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x41a0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0xb6d8
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
callq 0x41a0
leaq -0x40(%rbp), %rdi
callq 0x58c6
leaq -0xb8(%rbp), %rdi
callq 0x41a0
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0x58c6
leaq -0x168(%rbp), %r15
movq %r15, %rdi
callq 0xce1e
movq %rax, (%rbx)
movq %r15, %rdi
callq 0xce28
movq %rax, (%r14)
leaq -0x98(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xce32
testb %al, %al
je 0xb831
leaq -0x98(%rbp), %r15
leaq -0x378(%rbp), %r12
leaq -0xb8(%rbp), %r13
leaq -0x1b8(%rbp), %r14
movq %r15, %rdi
callq 0xce42
movq %rax, %rbx
movq %r12, %rdi
movq %rax, %rsi
callq 0x4480
addq $0x20, %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4480
movq %r14, %rdi
callq 0xce85
movq %rax, %rbx
movq %r14, %rdi
callq 0xce8f
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xce5e
movq %rax, -0x40(%rbp)
movq %r14, %rdi
callq 0xce8f
movq %rax, -0x68(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xce4f
movl %eax, %ebx
movq -0x38(%rbp), %rdi
callq 0xbb0a
testb %al, %al
jne 0xb7e9
testb %bl, %bl
jne 0xb805
movq -0x38(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
leaq -0x188(%rbp), %rcx
movl $0x7cc, %r8d            # imm = 0x7CC
callq 0xbb14
movq %r13, %rdi
callq 0x41a0
movq %r12, %rdi
callq 0x41a0
movq %r15, %rdi
callq 0xce9a
movq %r15, %rdi
leaq -0x48(%rbp), %rsi
callq 0xce32
testb %al, %al
jne 0xb773
movq -0x38(%rbp), %rdi
callq 0xbfc4
leaq -0x1b8(%rbp), %rdi
callq 0xceb8
leaq -0x58(%rbp), %rdi
callq 0x5e92
leaq -0x168(%rbp), %rdi
callq 0x5716
leaq -0x188(%rbp), %rdi
callq 0x41a0
leaq -0xf8(%rbp), %rdi
callq 0x41a0
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2f724(%rip), %rdi     # 0x3afb0
leaq 0x17f9b(%rip), %rsi     # 0x2382e
callq 0x4360
movq %rax, %rdi
movq %r13, %rsi
callq 0x4320
leaq 0x17f8c(%rip), %rsi     # 0x23836
movq %rax, %rdi
callq 0x4360
leaq -0xf8(%rbp), %rsi
movq %rax, %rdi
callq 0x4320
leaq 0x19884(%rip), %rsi     # 0x2514c
movq %rax, %rdi
callq 0x4360
movl $0x10, %edi
callq 0x41b0
movq %rax, %rbx
leaq 0x17f61(%rip), %rsi     # 0x23845
movq %rax, %rdi
callq 0x45e0
movq 0x2f6e5(%rip), %rsi     # 0x3afd8
movq 0x2f6c6(%rip), %rdx     # 0x3afc0
movq %rbx, %rdi
callq 0x4560
movq %rax, %r13
movq %rbx, %rdi
callq 0x4270
jmp 0xbab1
jmp 0xba80
movq %rax, %r13
leaq -0x29(%rbp), %rdi
callq 0x6104
movl $0x20, %ebx
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x41a0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0xb928
movb $0x1, %bl
jmp 0xb9f7
movq %rax, %r13
xorl %ebx, %ebx
jmp 0xba03
movq %rax, %r13
xorl %ebx, %ebx
movq %r12, %r15
jmp 0xba26
jmp 0xba7b
movq %rax, %r13
leaq -0x118(%rbp), %rdi
callq 0x41a0
jmp 0xbab1
movq %rax, %r13
leaq -0x138(%rbp), %rdi
callq 0x41a0
jmp 0xbaba
jmp 0xb98f
movq %rax, %r13
jmp 0xbaba
movq %rax, %r13
leaq -0xd8(%rbp), %rdi
callq 0xcadc
movl $0x180, %ebx            # imm = 0x180
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x5870
addq $-0x40, %rbx
cmpq $-0x40, %rbx
jne 0xb9ab
jmp 0xbac6
movq %rax, %r13
leaq -0x378(%rbp), %rdi
callq 0x58c6
jmp 0xbad2
movq %rax, %r13
leaq -0x378(%rbp), %rdi
callq 0x58c6
jmp 0xbade
movq %rax, %r13
xorl %ebx, %ebx
leaq -0x98(%rbp), %rdi
callq 0x41a0
leaq -0x40(%rbp), %rdi
callq 0x58c6
jmp 0xba1a
movq %rax, %r13
leaq -0x378(%rbp), %r15
xorl %ebx, %ebx
leaq -0xb8(%rbp), %rdi
callq 0x41a0
leaq -0x48(%rbp), %rdi
callq 0x58c6
cmpq %r15, %r12
sete %al
orb %bl, %al
jne 0xbab1
leaq -0x378(%rbp), %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x41a0
cmpq %rbx, %r15
jne 0xba40
jmp 0xbab1
jmp 0xba7b
jmp 0xba7b
movq %rax, %r13
cmpq %r14, %rbx
je 0xbac6
leaq -0x378(%rbp), %rbx
addq $-0x40, %r14
movq %r14, %rdi
callq 0x5870
cmpq %rbx, %r14
jne 0xba66
jmp 0xbac6
jmp 0xba8a
movq %rax, %r13
jmp 0xbab1
movq %rax, %r13
jmp 0xbaa5
movq %rax, %r13
jmp 0xba99
movq %rax, %r13
leaq -0xb8(%rbp), %rdi
callq 0x41a0
leaq -0x378(%rbp), %rdi
callq 0x41a0
leaq -0x1b8(%rbp), %rdi
callq 0xceb8
leaq -0x58(%rbp), %rdi
callq 0x5e92
leaq -0x168(%rbp), %rdi
callq 0x5716
leaq -0x188(%rbp), %rdi
callq 0x41a0
leaq -0xf8(%rbp), %rdi
callq 0x41a0
movq -0x70(%rbp), %rdi
callq 0x5566
movq -0x78(%rbp), %rdi
callq 0x5716
movq -0x60(%rbp), %rdi
callq 0x41a0
movq -0x38(%rbp), %rdi
callq 0x41a0
movq %r13, %rdi
callq 0x45a0