def non_solvent(box_vec, system, atomistic_fragments, residue_type): #### loop through all resids of that residue type for resid in atomistic_fragments[residue_type]: skip = os.path.exists(g_var.working_dir + residue_type + '/' + residue_type + '_' + str(resid) + '.pdb') if not skip: pdb_output = gen.create_pdb( g_var.working_dir + residue_type + '/' + residue_type + '_' + str(resid) + '.pdb', box_vec) atomistic_fragments[residue_type][resid] = at_mod.check_hydrogens( atomistic_fragments[residue_type][resid]) ####### check if any atoms in residue overlap ####### coord = [] for atom in atomistic_fragments[residue_type][resid]: coord.append( atomistic_fragments[residue_type][resid][atom]['coord']) coord = at_mod.check_atom_overlap(coord) for atom_val, atom in enumerate( atomistic_fragments[residue_type][resid]): atomistic_fragments[residue_type][resid][atom][ 'coord'] = coord[atom_val] for at_id, atom in enumerate( atomistic_fragments[residue_type][resid]): #### write residue out to a pdb file short_line = atomistic_fragments[residue_type][resid][at_id + 1] pdb_output.write(g_var.pdbline % ( (at_id + 1, short_line['atom'], short_line['res_type'], ' ', 1, short_line['coord'][0], short_line['coord'][1], short_line['coord'][2], 0.00, 0.00)) + '\n') system[residue_type] = int(resid) + 1 return system, atomistic_fragments
def solvent_sol(box_vec, system, atomistic_fragments, residue_type): #### creates solvent directory and SOL key in system dictionay otherwise it appends solvent molecules to sol pdb skip = os.path.exists(g_var.working_dir + 'SOL' + '/SOL_0.pdb') if not skip: pdb_sol = gen.create_pdb(g_var.working_dir + 'SOL' + '/SOL_0.pdb', box_vec) for resid in atomistic_fragments[residue_type]: ####### check if any atoms in residue overlap ####### if not skip: coord = [] for atom in atomistic_fragments[residue_type][resid]: coord.append( atomistic_fragments[residue_type][resid][atom]['coord']) coord = at_mod.check_atom_overlap(coord) for atom_val, atom in enumerate( atomistic_fragments[residue_type][resid]): atomistic_fragments[residue_type][resid][atom][ 'coord'] = coord[atom_val] for at_id, atom in enumerate(atomistic_fragments[residue_type][resid]): #### separates out the water molecules from the ion in the fragment if atomistic_fragments[residue_type][resid][at_id + 1]['frag_mass'] > 1: system['SOL'] += 1 if not skip: short_line = atomistic_fragments[residue_type][resid][at_id + 1] pdb_sol.write(g_var.pdbline % ( (at_id + 1, short_line['atom'], short_line['res_type'], ' ', 1, short_line['coord'][0], short_line['coord'][1], short_line['coord'][2], 0.00, 0.00)) + '\n') return system, atomistic_fragments
def solvent_ion(box_vec, 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', box_vec) 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] pdb_ion.write(g_var.pdbline % ( (at_id + 1, short_line['atom'], short_line['res_type'], ' ', 1, short_line['coord'][0], short_line['coord'][1], short_line['coord'][2], 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, atomistic_fragments
def merge_minimised(residue_type, np_system, box_vec): 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', box_vec) if residue_type == 'SOL': resid_range = 1 else: resid_range = np_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) if residue_type != 'SOL': merge_coords = at_mod.check_atom_overlap(merge_coords) for line_val, line in enumerate(merge): pdb_output.write(g_var.pdbline%((int(line['atom_number']), line['atom_name'], line['residue_name'],' ',line['residue_id'],\ merge_coords[line_val][0],merge_coords[line_val][1],merge_coords[line_val][2],1,0))+'\n') pdb_output.write('TER\nENDMDL') pdb_output.close()
def merge_system_pdbs(system, protein, cg_residues, box_vec): os.chdir(g_var.working_dir + 'MERGED') #### create merged pdb pdb_output = gen.create_pdb( g_var.working_dir + 'MERGED/merged_cg2at' + protein + '.pdb', box_vec) merge = [] merge_coords = [] #### run through every residue type in cg_residues for segment, residue_type in enumerate(cg_residues): #### if file contains user input identifier if residue_type != 'PROTEIN': input_type = '' else: input_type = protein merge, merge_coords = read_in_merged_pdbs( merge, merge_coords, g_var.working_dir + residue_type + '/' + residue_type + input_type + '_merged.pdb') if protein in ['_at_rep_user_supplied', '_novo']: print('checking for atom overlap in : ' + protein[1:]) merge_coords = check_atom_overlap(merge_coords) for line_val, line in enumerate(merge): pdb_output.write(g_var.pdbline%((int(line['atom_number']), line['atom_name'], line['residue_name'],' ',line['residue_id'],\ merge_coords[line_val][0],merge_coords[line_val][1],merge_coords[line_val][2],1,0))+'\n') pdb_output.write('TER\nENDMDL') pdb_output.close()
def merge_minimised(residue_type, np_system, box_vec): os.chdir(g_var.working_dir+residue_type+'/min') print('Merging individual residues : '+residue_type) #### create merged pdb in min folder pdb_output=gen.create_pdb(g_var.working_dir+residue_type+'/min/'+residue_type+'_merged.pdb', box_vec) if residue_type =='SOL': resid_range=1 else: resid_range=np_system[residue_type] merge,merge_coords=[],[] #### run through every resid for resid in range(resid_range): #### check if it exists merge_temp = [] if os.path.exists(g_var.working_dir+residue_type+'/min/'+residue_type+'_'+str(resid)+'.pdb'): #### read in resid and write straight to merged pdb with open(g_var.working_dir+residue_type+'/min/'+residue_type+'_'+str(resid)+'.pdb', 'r') as pdb_input: for line in pdb_input.readlines(): if line.startswith('ATOM'): line_sep=gen.pdbatom(line) merge_temp.append(line_sep) else: sys.exit('cannot find minimised residue: \n'+ g_var.working_dir+residue_type+'/'+residue_type+'_merged.pdb') merge, merge_coords = at_mod.fix_chirality(merge,merge_temp,merge_coords) if residue_type !='SOL': merge_coords = at_mod.check_atom_overlap(merge_coords) for line_val, line in enumerate(merge): pdb_output.write(g_var.pdbline%((int(line['atom_number']), line['atom_name'], line['residue_name'],' ',line['residue_id'],\ merge_coords[line_val][0],merge_coords[line_val][1],merge_coords[line_val][2],1,0))+'\n') pdb_output.write('TER\nENDMDL') pdb_output.close()
def write_to_pdb(cg_residues, box_vec, solvent_dict): pdb_output = gen.create_pdb(g_var.final_dir + 'AT2CG_merged.pdb', box_vec) at_count = 1 for residue_type in cg_residues: if residue_type not in ['PROTEIN', 'SOL', 'ION']: for resid in cg_residues[residue_type]: for bead in cg_residues[residue_type][resid]: coord = cg_residues[residue_type][resid][bead] pdb_output.write(g_var.pdbline%((at_count, bead, residue_type,' ',resid,\ coord[0],coord[1],coord[2],1,0))+'\n') at_count += 1 elif residue_type == 'SOL': for resid, coord in enumerate(cg_residues[residue_type]): pdb_output.write(g_var.pdbline%((at_count, 'W', residue_type,' ',resid+1,\ coord[0],coord[1],coord[2],1,0))+'\n') at_count += 1 elif residue_type == 'ION': for ion_type in cg_residues[residue_type]: for resid, coord in enumerate( cg_residues[residue_type][ion_type]): pdb_output.write(g_var.pdbline%((at_count, ion_type, residue_type,' ',resid+1,\ coord[0],coord[1],coord[2],1,0))+'\n') at_count += 1 else: for resid in cg_residues[residue_type]: for amino_acid in cg_residues[residue_type][resid]: for bead in cg_residues[residue_type][resid][amino_acid]: coord = cg_residues[residue_type][resid][amino_acid][ bead] pdb_output.write(g_var.pdbline%((at_count, bead, amino_acid,' ',resid,\ coord[0],coord[1],coord[2],1,0))+'\n') at_count += 1
def write_merged_pdb(merge, protein, box_vec): #### creates merged pdb and writes chains to it if not os.path.exists(g_var.working_dir+'PROTEIN/PROTEIN'+protein+'_merged.pdb'): pdb_output=gen.create_pdb(g_var.working_dir+'PROTEIN/PROTEIN'+protein+'_merged.pdb', box_vec) for line in merge: pdb_output.write(line) pdb_output.close()
def finalise_novo_atomistic(atomistic, cg_residues, box_vec): final_at_residues={} final_at = {} for chain in atomistic: at_number=0 final_at_residues[chain]={} final_at[chain]={} coords=[] skip = os.path.exists(g_var.working_dir+'PROTEIN/PROTEIN_novo_'+str(chain)+'.pdb') if not skip: pdb_output = gen.create_pdb(g_var.working_dir+'PROTEIN/PROTEIN_novo_'+str(chain)+'.pdb', box_vec) for res_index, residue_id in enumerate(atomistic[chain]): if atomistic[chain][residue_id][1]['res_type'] in f_loc.mod_residues: atomistic[chain][residue_id] = at_mod.check_hydrogens(atomistic[chain][residue_id]) if res_index < len(atomistic[chain])-2: atomistic[chain][residue_id] = fix_carbonyl(residue_id, cg_residues, atomistic[chain][residue_id]) else: atomistic[chain][residue_id] = atomistic[chain][residue_id] for at_val, atom in enumerate(atomistic[chain][residue_id]): atomistic[chain][residue_id][at_val+1]['resid'] = res_index coords.append(atomistic[chain][residue_id][at_val+1]['coord']) final_at[chain][at_number]=atomistic[chain][residue_id][at_val+1] at_number+=1 final_at_residues[chain][res_index]=atomistic[chain][residue_id] coords = at_mod.check_atom_overlap(coords) for atom in final_at[chain]: final_at[chain][atom]['coord']=coords[atom] final_at_residues[chain][final_at[chain][atom]['resid']][atom]=final_at[chain][atom] if not skip: pdb_output.write(g_var.pdbline%((atom,final_at[chain][atom]['atom'],final_at[chain][atom]['res_type'],ascii_uppercase[chain],\ final_at[chain][atom]['resid'],final_at[chain][atom]['coord'][0],final_at[chain][atom]['coord'][1],final_at[chain][atom]['coord'][2],1,0))+'\n') if 'pdb_output' in locals(): pdb_output.close() return final_at_residues
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 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 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')
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 hybridise_protein_inputs(final_coordinates_atomistic, atomistic_protein_centered, cg_com, xyz_rot_apply, chain, box_vec): pdb_output = gen.create_pdb(g_var.working_dir+'PROTEIN/PROTEIN_at_rep_user_supplied_'+str(chain)+'.pdb', box_vec) final_atom={} coord=[] at_id=0 for residue in final_coordinates_atomistic: exists=False for initial_index in final_coordinates_atomistic[residue]: if final_coordinates_atomistic[residue][initial_index]['res_type'] in f_loc.mod_residues: for atom in final_coordinates_atomistic[residue]: short_line=final_coordinates_atomistic[residue][atom] final_atom[at_id]={'atom':short_line['atom'], 'res_type':short_line['res_type'], 'chain':ascii_uppercase[chain], 'residue':residue,\ 'x':short_line['coord'][0],'y':short_line['coord'][1],'z':short_line['coord'][2]} at_id+=1 coord.append(short_line['coord']) elif final_coordinates_atomistic[residue][initial_index]['res_type'] not in f_loc.mod_residues: for part_val, part in enumerate(atomistic_protein_centered): if residue in atomistic_protein_centered[part]: exists=True for atom in atomistic_protein_centered[part][residue]: if atomistic_protein_centered[part][residue][atom]['res_type'] != final_coordinates_atomistic[residue][initial_index]['res_type']: print('de_novo' , final_coordinates_atomistic[residue][initial_index]['res_type'],'at_user', atomistic_protein_centered[part][residue][atom]['res_type']) sys.exit('de novo and at user supplied don\'t match') atomistic_protein_centered[part][residue][atom]['coord'] = at_mod.rotate_atom(atomistic_protein_centered[part][residue][atom]['coord'], cg_com[part_val], xyz_rot_apply[part_val]) short_line = atomistic_protein_centered[part][residue][atom] final_atom[at_id]={'atom':short_line['atom'], 'res_type':short_line['res_type'], 'chain':ascii_uppercase[chain], 'residue':residue,\ 'x':short_line['coord'][0],'y':short_line['coord'][1],'z':short_line['coord'][2]} at_id+=1 coord.append(short_line['coord']) if not exists: for atom in final_coordinates_atomistic[residue]: short_line=final_coordinates_atomistic[residue][atom] final_atom[at_id]={'atom':short_line['atom'], 'res_type':short_line['res_type'], 'chain':ascii_uppercase[chain], 'residue':residue,\ 'x':short_line['coord'][0],'y':short_line['coord'][1],'z':short_line['coord'][2]} at_id+=1 coord.append(short_line['coord']) break merge_coords = at_mod.check_atom_overlap(coord) for at_id, coord in enumerate(merge_coords): pdb_output.write(g_var.pdbline%((at_id+1,final_atom[at_id]['atom'],final_atom[at_id]['res_type'],final_atom[at_id]['chain'],final_atom[at_id]['residue'], coord[0],coord[1],coord[2],1,0))+'\n')
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 at_id, atom in enumerate(atomistic_fragments[residue_type]): #### write ion coordinate out if not skip: x, y, z = gen.trunc_coord( [atom['coord'][0], atom['coord'][1], atom['coord'][2]]) pdb_ion.write(g_var.pdbline % ((at_id + 1, atom['atom_name'], atom['residue_name'], ' ', 1, x, y, z, 0.00, 0.00)) + '\n') if atom['residue_name'] not in system: system[atom['residue_name']] = 1 else: system[atom['residue_name']] += 1 return system
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