// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
callq 0x4300
leaq 0x20(%r15), %rdi
movq %rdi, -0x60(%rbp)
callq 0x4300
leaq 0x58(%r15), %rdi
movq %rdi, -0x78(%rbp)
callq 0xc610
leaq 0x88(%r15), %rdi
movq %rdi, -0x70(%rbp)
callq 0xc61a
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 0x184c9(%rip), %rsi     # 0x23770
leaq -0xf8(%rbp), %rdi
movq %rbx, %rdx
movq %r15, -0x38(%rbp)
callq 0x4160
leaq -0x378(%rbp), %rdi
callq 0x58c6
movq %rbx, %rdi
callq 0x4540
leaq 0x184b4(%rip), %rsi     # 0x23789
leaq -0x188(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
leaq -0x378(%rbp), %rdi
callq 0x58c6
leaq 0x16d49(%rip), %rsi     # 0x22040
leaq 0x184a3(%rip), %rdx     # 0x237a1
movq %rbx, %rdi
callq 0xc624
leaq -0x338(%rbp), %r14
leaq 0x16d37(%rip), %rsi     # 0x2204b
leaq 0x1848a(%rip), %rdx     # 0x237a5
movq %r14, %rdi
callq 0xc6be
leaq -0x2f8(%rbp), %r14
leaq 0x18478(%rip), %rsi     # 0x237a9
leaq 0x18478(%rip), %rdx     # 0x237b0
movq %r14, %rdi
callq 0xc758
leaq -0x2b8(%rbp), %r14
leaq 0x18466(%rip), %rsi     # 0x237b4
leaq 0x1846f(%rip), %rdx     # 0x237c4
movq %r14, %rdi
callq 0xc7f2
leaq -0x278(%rbp), %r14
leaq 0x1845d(%rip), %rsi     # 0x237c8
leaq 0x18461(%rip), %rdx     # 0x237d3
movq %r14, %rdi
callq 0xc624
leaq -0x238(%rbp), %r14
leaq 0x1844f(%rip), %rsi     # 0x237d7
leaq 0x18451(%rip), %rdx     # 0x237e0
movq %r14, %rdi
callq 0xc88c
leaq -0x1f8(%rbp), %r14
leaq 0x1843f(%rip), %rsi     # 0x237e4
leaq 0x1844d(%rip), %rdx     # 0x237f9
movq %r14, %rdi
callq 0xc926
leaq -0xd8(%rbp), %rbx
movq %rbx, %rdi
callq 0xc9c0
leaq -0x168(%rbp), %rdi
leaq -0x378(%rbp), %rsi
leaq -0x1b8(%rbp), %rcx
movl $0x7, %edx
movq %rbx, %r8
callq 0xc9ca
leaq -0xd8(%rbp), %rdi
callq 0xca5c
movl $0x180, %ebx            # imm = 0x180
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x5870
addq $-0x40, %rbx
cmpq $-0x40, %rbx
jne 0xb3f6
movq %r15, %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 0xca62
leaq -0x118(%rbp), %rdi
callq 0x41a0
leaq -0x378(%rbp), %rbx
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0xcab2
leaq -0xd8(%rbp), %rdi
movq %rbx, %rsi
callq 0xcaa4
testb %al, %al
je 0xb806
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8d88
leaq 0x18344(%rip), %rsi     # 0x237fd
movq %rax, %rdi
callq 0xcad2
leaq -0x378(%rbp), %rdi
movq %rax, %rsi
callq 0xcc1a
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 0x8d88
leaq 0x18304(%rip), %rsi     # 0x23802
movq %rax, %rdi
callq 0xcad2
movq %rax, %rdi
callq 0xcc32
movq -0x38(%rbp), %rcx
movl %eax, 0x40(%rcx)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8d88
leaq 0x182df(%rip), %rsi     # 0x23807
movq %rax, %rdi
callq 0xcad2
movq %rax, %rdi
callq 0xcc3c
movq -0x38(%rbp), %rcx
movb %al, 0x44(%rcx)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8d88
leaq 0x182c9(%rip), %rsi     # 0x2381b
movq %rax, %rdi
callq 0xcad2
movq %rax, %rdi
callq 0xcc32
movq -0x38(%rbp), %rcx
movl %eax, 0x48(%rcx)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8d88
leaq 0x182ad(%rip), %rsi     # 0x23829
movq %rax, %rdi
callq 0xcad2
movq %rax, %rdi
callq 0xcc46
movq -0x38(%rbp), %rax
movsd %xmm0, 0x50(%rax)
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x4540
leaq 0x18201(%rip), %rsi     # 0x237a9
leaq -0xb8(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
leaq -0x168(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xcc50
leaq -0x378(%rbp), %rdi
movq %rax, %rsi
callq 0x4480
leaq -0x358(%rbp), %r15
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x4540
leaq 0x181e4(%rip), %rsi     # 0x237d7
leaq -0x98(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
leaq -0x168(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xcc50
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 0xcd0e
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 0xb659
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
callq 0x41a0
leaq -0x48(%rbp), %rdi
callq 0x58c6
leaq -0xb8(%rbp), %rdi
callq 0x41a0
leaq -0x40(%rbp), %r14
movq %r14, %rdi
callq 0x58c6
leaq -0x168(%rbp), %r15
movq %r15, %rdi
callq 0xcda0
movq %rax, (%rbx)
movq %r15, %rdi
callq 0xcdaa
movq %rax, (%r14)
leaq -0x98(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xcdb4
testb %al, %al
je 0xb7b2
leaq -0x98(%rbp), %r15
leaq -0x378(%rbp), %r12
leaq -0xb8(%rbp), %r13
leaq -0x1b8(%rbp), %r14
movq %r15, %rdi
callq 0xcdc4
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 0xce07
movq %rax, %rbx
movq %r14, %rdi
callq 0xce11
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xcde0
movq %rax, -0x48(%rbp)
movq %r14, %rdi
callq 0xce11
movq %rax, -0x68(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xcdd1
movl %eax, %ebx
movq -0x38(%rbp), %rdi
callq 0xba88
testb %al, %al
jne 0xb76a
testb %bl, %bl
jne 0xb786
movq -0x38(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
leaq -0x188(%rbp), %rcx
movl $0x7cc, %r8d            # imm = 0x7CC
callq 0xba92
movq %r13, %rdi
callq 0x41a0
movq %r12, %rdi
callq 0x41a0
movq %r15, %rdi
callq 0xce1c
movq %r15, %rdi
leaq -0x40(%rbp), %rsi
callq 0xcdb4
testb %al, %al
jne 0xb6f4
movq -0x38(%rbp), %rdi
callq 0xbf42
leaq -0x1b8(%rbp), %rdi
callq 0xce3a
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 0x2f7a3(%rip), %rdi     # 0x3afb0
leaq 0x1801a(%rip), %rsi     # 0x2382e
callq 0x4360
movq %rax, %rdi
movq %r13, %rsi
callq 0x4320
leaq 0x1800b(%rip), %rsi     # 0x23836
movq %rax, %rdi
callq 0x4360
leaq -0xf8(%rbp), %rsi
movq %rax, %rdi
callq 0x4320
leaq 0x19903(%rip), %rsi     # 0x2514c
movq %rax, %rdi
callq 0x4360
movl $0x10, %edi
callq 0x41b0
movq %rax, %rbx
leaq 0x17fe0(%rip), %rsi     # 0x23845
movq %rax, %rdi
callq 0x45e0
movq 0x2f764(%rip), %rsi     # 0x3afd8
movq 0x2f745(%rip), %rdx     # 0x3afc0
movq %rbx, %rdi
callq 0x4560
movq %rax, %r13
movq %rbx, %rdi
callq 0x4270
jmp 0xba2e
jmp 0xb9fd
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 0xb8a9
movb $0x1, %bl
jmp 0xb984
movq %rax, %r13
xorl %ebx, %ebx
jmp 0xb990
movq %rax, %r13
leaq -0x40(%rbp), %rdi
callq 0x58c6
jmp 0xba2e
jmp 0xb9f8
movq %rax, %r13
leaq -0x118(%rbp), %rdi
callq 0x41a0
jmp 0xba2e
movq %rax, %r13
leaq -0x138(%rbp), %rdi
callq 0x41a0
jmp 0xba37
jmp 0xb914
movq %rax, %r13
jmp 0xba37
movq %rax, %r13
leaq -0xd8(%rbp), %rdi
callq 0xca5c
movl $0x180, %ebx            # imm = 0x180
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x5870
addq $-0x40, %rbx
cmpq $-0x40, %rbx
jne 0xb930
jmp 0xba43
movq %rax, %r13
jmp 0xba43
movq %rax, %r13
leaq -0x378(%rbp), %rdi
callq 0x58c6
jmp 0xba4f
movq %rax, %r13
leaq -0x378(%rbp), %rdi
callq 0x58c6
jmp 0xba5b
movq %rax, %r13
xorl %ebx, %ebx
leaq -0x98(%rbp), %rdi
callq 0x41a0
leaq -0x48(%rbp), %rdi
callq 0x58c6
jmp 0xb9a3
movq %rax, %r13
xorl %ebx, %ebx
movq %r12, %r15
leaq -0xb8(%rbp), %rdi
callq 0x41a0
leaq -0x40(%rbp), %rdi
callq 0x58c6
cmpq %r15, %r12
sete %al
orb %bl, %al
jne 0xba2e
leaq -0x378(%rbp), %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x41a0
cmpq %rbx, %r15
jne 0xb9c9
jmp 0xba2e
jmp 0xb9f8
jmp 0xb9f8
movq %rax, %r13
addq $-0x40, %r14
movq %r14, %rdi
callq 0x5870
cmpq %rbx, %r14
jne 0xb9e3
jmp 0xba43
jmp 0xba07
movq %rax, %r13
jmp 0xba2e
movq %rax, %r13
jmp 0xba22
movq %rax, %r13
jmp 0xba16
movq %rax, %r13
leaq -0xb8(%rbp), %rdi
callq 0x41a0
leaq -0x378(%rbp), %rdi
callq 0x41a0
leaq -0x1b8(%rbp), %rdi
callq 0xce3a
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
nop