def non_solvent(system, atomistic_fragments, residue_type): #### loop through all resids of that residue type system[residue_type] = len(atomistic_fragments[residue_type]) if not os.path.exists(g_var.working_dir + residue_type + '/' + residue_type + '_all.pdb') and not os.path.exists( g_var.working_dir + residue_type + '/' + residue_type + '_merged.pdb'): NP = {} count = 0 coord = [] index_conversion = {} for resid in atomistic_fragments[residue_type]: if not os.path.exists(g_var.working_dir + residue_type + '/' + residue_type + '_merged.pdb'): atomistic_fragments[residue_type][ resid] = at_mod.check_hydrogens( atomistic_fragments[residue_type][resid]) for at_id, atom in enumerate( atomistic_fragments[residue_type][resid], 1): if not atomistic_fragments[residue_type][resid][at_id][ 'atom'].startswith('M'): index_conversion[count] = len(coord) coord.append(atomistic_fragments[residue_type][resid] [at_id]['coord']) NP[count] = atomistic_fragments[residue_type][resid][at_id] count += 1 coord = at_mod.check_atom_overlap(coord) pdb_output_all = gen.create_pdb(g_var.working_dir + residue_type + '/' + residue_type + '_all.pdb') atom_counter = 0 for at_val, atom in enumerate(NP): if at_val in index_conversion: x, y, z = gen.trunc_coord(coord[index_conversion[at_val]]) else: x, y, z = gen.trunc_coord([ NP[atom]['coord'][0], NP[atom]['coord'][1], NP[atom]['coord'][2] ]) if atom_counter >= 99_999: atom_counter = 1 else: atom_counter += 1 pdb_output_all.write(g_var.pdbline % ( (atom_counter, NP[atom]['atom'], NP[atom]['res_type'], ' ', 1, x, y, z, 0.00, 0.00)) + '\n') return system
def merge_minimised(residue_type): os.chdir(g_var.working_dir + residue_type + '/MIN') print('Merging individual residues : ' + residue_type) #### create merged pdb in min folder if not os.path.exists(g_var.working_dir + residue_type + '/MIN/' + residue_type + '_merged.pdb'): pdb_output = gen.create_pdb(g_var.working_dir + residue_type + '/MIN/' + residue_type + '_merged.pdb') if residue_type == 'SOL': resid_range = 1 else: resid_range = g_var.system[residue_type] merge, merge_coords = [], [] #### run through every resid for resid in range(resid_range): merge_temp, dump = at_mod.read_in_merged_pdbs( [], [], g_var.working_dir + residue_type + '/MIN/' + residue_type + '_' + str(resid) + '.pdb') merge, merge_coords = at_mod.fix_chirality(merge, merge_temp, merge_coords, residue_type) if residue_type != 'SOL': merge_coords = at_mod.check_atom_overlap(merge_coords) for line_val, line in enumerate(merge): x, y, z = gen.trunc_coord([ merge_coords[line_val][0], merge_coords[line_val][1], merge_coords[line_val][2] ]) pdb_output.write(g_var.pdbline%((int(line['atom_number']), line['atom_name'], line['residue_name'],' ',line['residue_id'],\ x, y, z,1,0))+'\n') pdb_output.write('TER\nENDMDL') pdb_output.close()
def solvent_ion(system, atomistic_fragments, residue_type): #### creates ion pdb with header gen.mkdir_directory(g_var.working_dir + 'ION/MIN') skip = os.path.exists(g_var.working_dir + residue_type + '/' + residue_type + '_merged.pdb') if not skip: pdb_ion = gen.create_pdb(g_var.working_dir + residue_type + '/' + residue_type + '_merged.pdb') for resid in atomistic_fragments[residue_type]: for at_id, atom in enumerate(atomistic_fragments[residue_type][resid]): #### write ion coordinate out if not skip: short_line = atomistic_fragments[residue_type][resid][at_id + 1] x, y, z = gen.trunc_coord([ short_line['coord'][0], short_line['coord'][1], short_line['coord'][2] ]) pdb_ion.write(g_var.pdbline % ( (at_id + 1, short_line['atom'], short_line['res_type'], ' ', 1, x, y, z, 0.00, 0.00)) + '\n') if atomistic_fragments[residue_type][resid][ at_id + 1]['res_type'] != 'SOL': if atomistic_fragments[residue_type][resid][ at_id + 1]['res_type'] not in system: system[atomistic_fragments[residue_type][resid][at_id + 1] ['res_type']] = 1 else: system[atomistic_fragments[residue_type][resid][at_id + 1] ['res_type']] += 1 return system
def write_pdb(merge, merge_coords, index_conversion, write_file): #### creates merged pdb and writes chains to it if not os.path.exists(write_file): pdb_output = gen.create_pdb(write_file) atom_counter = 1 for line_val, line in enumerate(merge): if line_val in index_conversion: x, y, z = gen.trunc_coord( merge_coords[index_conversion[line_val]]) else: x, y, z = gen.trunc_coord([line['x'], line['y'], line['z']]) if atom_counter >= 99_999: atom_counter = 1 else: atom_counter += 1 pdb_output.write(g_var.pdbline%((atom_counter, line['atom_name'], line['residue_name'],' ',line['residue_id'],\ x,y,z,1,0))+'\n') pdb_output.close()
def finalise_novo_atomistic(coord_atomistic, sys_type): final_at_residues = {} final_at = {} for chain in coord_atomistic: at_number = 0 final_at_residues[chain] = {} final_at[chain] = {} coords = [] skip = os.path.exists(g_var.working_dir + sys_type + '/' + sys_type + '_de_novo_' + str(chain) + '.pdb') if not skip: pdb_output = gen.create_pdb(g_var.working_dir + sys_type + '/' + sys_type + '_de_novo_' + str(chain) + '.pdb') for res_index, residue_id in enumerate(coord_atomistic[chain]): if coord_atomistic[chain][residue_id][next( iter(coord_atomistic[chain][residue_id]) )]['res_type'] in g_var.mod_residues + g_var.o_residues: coord_atomistic[chain][residue_id] = at_mod.check_hydrogens( coord_atomistic[chain][residue_id]) if sys_type == 'PROTEIN': if res_index <= len(coord_atomistic[chain]) - 3: coord_atomistic[chain][ residue_id], cross_vector = fix_carbonyl( residue_id, g_var.cg_residues['PROTEIN'], coord_atomistic[chain][residue_id], False) elif res_index < len( coord_atomistic[chain]) and 'cross_vector' in locals(): coord_atomistic[chain][ residue_id], cross_vector = fix_carbonyl( residue_id, g_var.cg_residues['PROTEIN'], coord_atomistic[chain][residue_id], cross_vector) order = np.sort( np.array(list(coord_atomistic[chain][residue_id].keys()))) for at_val, atom in enumerate(order): coord_atomistic[chain][residue_id][atom]['resid'] = res_index coords.append( coord_atomistic[chain][residue_id][atom]['coord']) final_at[chain][at_number] = coord_atomistic[chain][ residue_id][atom] at_number += 1 final_at_residues[chain][res_index] = coord_atomistic[chain][ residue_id] coords = at_mod.check_atom_overlap(coords) for atom in final_at[chain]: final_at[chain][atom]['coord'] = coords[atom] if not skip: x, y, z = gen.trunc_coord(final_at[chain][atom]['coord']) pdb_output.write(g_var.pdbline%((atom,final_at[chain][atom]['atom'],final_at[chain][atom]['res_type'],' ',\ final_at[chain][atom]['resid'],x,y,z,1,0))+'\n') if 'pdb_output' in locals(): pdb_output.close() return final_at_residues
def solvent_sol(system, atomistic_fragments, residue_type): #### creates solvent directory and SOL key in system dictionay otherwise it appends solvent molecules to sol pdb sol = {} coord = [] count = 0 index_conversion = {} if not os.path.exists(g_var.working_dir + 'SOL' + '/SOL_all.pdb'): pdb_sol = gen.create_pdb(g_var.working_dir + 'SOL' + '/SOL_all.pdb') for resid in atomistic_fragments[residue_type]: ####### check if any atoms in residue overlap ####### for atom in atomistic_fragments[residue_type][resid]: if not atomistic_fragments[residue_type][resid][atom][ 'atom'].startswith('M'): index_conversion[count] = len(coord) coord.append(atomistic_fragments[residue_type][resid][atom] ['coord']) sol[count] = atomistic_fragments[residue_type][resid][atom] count += 1 coord = at_mod.check_atom_overlap(coord) atom_counter = 0 for at_val, atom in enumerate(sol): if sol[atom]['frag_mass'] > 1: system['SOL'] += 1 if at_val in index_conversion: x, y, z = gen.trunc_coord(coord[index_conversion[at_val]]) else: x, y, z = gen.trunc_coord([ sol[atom]['coord'][0], sol[atom]['coord'][1], sol[atom]['coord'][2] ]) if atom_counter >= 99_999: atom_counter = 1 else: atom_counter += 1 pdb_sol.write(g_var.pdbline % ( (atom_counter, sol[atom]['atom'], sol[atom]['res_type'], ' ', 1, x, y, z, 0.00, 0.00)) + '\n') return system
def write_user_chains_to_pdb(atomistic_user_supplied, chain): if not os.path.exists(g_var.working_dir+'PROTEIN/PROTEIN_aligned_'+str(chain)+'.pdb'): pdb_output = gen.create_pdb(g_var.working_dir+'PROTEIN/PROTEIN_aligned_'+str(chain)+'.pdb') final_atom={} at_id=0 coord=[] for resid in atomistic_user_supplied: for atom in atomistic_user_supplied[resid]: coord.append(atomistic_user_supplied[resid][atom]['coord']) short_line=atomistic_user_supplied[resid][atom] final_atom[at_id]={'atom':short_line['atom'], 'res_type':short_line['res_type'], 'chain':chain, 'residue':resid,\ 'x':short_line['coord'][0],'y':short_line['coord'][1],'z':short_line['coord'][2]} at_id+=1 merge_coords=at_mod.check_atom_overlap(coord) for at_id, coord in enumerate(merge_coords): x, y, z = gen.trunc_coord(coord) pdb_output.write(g_var.pdbline%((at_id+1,final_atom[at_id]['atom'],final_atom[at_id]['res_type'],'A',final_atom[at_id]['residue'], x,y,z,1,0))+'\n')