def write_posres(chain): #### if not posres file exist create one very_low_posres = posres_header(g_var.working_dir+'PROTEIN/PROTEIN_'+str(chain)+'_very_low_posre.itp') low_posres = posres_header(g_var.working_dir+'PROTEIN/PROTEIN_'+str(chain)+'_low_posre.itp') mid_posres = posres_header(g_var.working_dir+'PROTEIN/PROTEIN_'+str(chain)+'_mid_posre.itp') high_posres = posres_header(g_var.working_dir+'PROTEIN/PROTEIN_'+str(chain)+'_high_posre.itp') very_high_posres = posres_header(g_var.working_dir+'PROTEIN/PROTEIN_'+str(chain)+'_very_high_posre.itp') ultra_posres = posres_header(g_var.working_dir+'PROTEIN/PROTEIN_'+str(chain)+'_ultra_posre.itp') ca_posres = posres_header(g_var.working_dir+'PROTEIN/PROTEIN_'+str(chain)+'_ca_posre.itp') #### read in each chain from after pdb2gmx with open(g_var.working_dir+'PROTEIN/PROTEIN_de_novo_'+str(chain)+'_gmx.pdb', 'r') as pdb_input: at_counter=0 for line in pdb_input.readlines(): if line.startswith('ATOM'): line_sep = gen.pdbatom(line) at_counter+=1 #### if atom is in the restraint list for that residue add to position restraint file if line_sep['atom_name'] == 'CA': ca_posres.write(str(at_counter)+' 1 1000 1000 1000\n') if not gen.is_hydrogen(line_sep['atom_name']): very_low_posres.write(str(at_counter)+' 1 200 200 200\n') low_posres.write(str(at_counter)+' 1 750 750 750\n') mid_posres.write(str(at_counter)+' 1 1500 1500 1500\n') high_posres.write(str(at_counter)+' 1 3000 3000 3000\n') very_high_posres.write(str(at_counter)+' 1 6000 6000 6000\n') ultra_posres.write(str(at_counter)+' 1 10000 10000 10000\n')
def read_in_atomistic(protein): #### reset location and check if pdb exists os.chdir(g_var.start_dir) if not os.path.exists(protein): sys.exit('cannot find atomistic protein : '+protein) #### read in atomistic fragments into dictionary residue_list[0]=x,y,z,atom_name atomistic_protein_input={} if g_var.input_directory in protein: chain_count=g_var.chain_count else: chain_count = 0 #### read in pdb ter_residues=[] r_b_vec, r_b_inv = real_box_vectors(g_var.box_vec) with open(protein, 'r') as pdb_input: pdb_lines_atoms = filter_input(pdb_input.readlines(), False) atomistic_protein_input[chain_count]={} for line_nr, line_sep in enumerate(pdb_lines_atoms): if line_sep['residue_name'] in g_var.alt_res_name: line_sep['residue_name'] = g_var.alt_res_name[line_sep['residue_name']] if not gen.is_hydrogen(line_sep['atom_name']) or line_sep['residue_name'] in g_var.mod_residues: if line_sep['residue_name'] in g_var.p_residues: #### sorts out wrong atoms in terminal residues if line_sep['atom_name'] in ['OT', 'O1', 'O2']: line_sep['atom_name']='O' #### makes C_terminal connecting atom variable if 'prev_atom_coord' in locals(): line_sep['x'],line_sep['y'],line_sep['z'] = brute_mic(prev_atom_coord, [line_sep['x'],line_sep['y'],line_sep['z']], r_b_vec) if line_sep['atom_name'] in g_var.res_top[line_sep['residue_name']]['CONNECT']['atoms']: if g_var.res_top[line_sep['residue_name']]['CONNECT']['atoms'][line_sep['atom_name']] > 0: if 'C_ter' in locals() and len(g_var.res_top[line_sep['residue_name']]['CONNECT']['atoms']) <=1: ter_residues.append(line_sep['residue_id']) chain_count+=1 atomistic_protein_input[chain_count]={} C_ter=[line_sep['x'],line_sep['y'],line_sep['z']] C_resid=line_sep['residue_id'] elif 'C_ter' in locals(): N_resid=line_sep['residue_id'] N_ter=[line_sep['x'],line_sep['y'],line_sep['z']] dist=gen.calculate_distance(N_ter, C_ter) if C_resid != N_resid and dist > 3.5: del N_ter, C_ter ter_residues.append(line_sep['residue_id']) chain_count+=1 atomistic_protein_input[chain_count]={} ### new chain key prev_atom_coord = [line_sep['x'],line_sep['y'],line_sep['z']] if line_sep['residue_id'] not in atomistic_protein_input[chain_count]: ## if protein does not exist add to dict atomistic_protein_input[chain_count][line_sep['residue_id']]={} #### adds atom to dictionary, every atom is given a initial mass of zero atomistic_protein_input[chain_count][line_sep['residue_id']][line_sep['atom_number']]={'coord':np.array([line_sep['x'],line_sep['y'],line_sep['z']]),'atom':line_sep['atom_name'], 'res_type':line_sep['residue_name'],'frag_mass':0, 'resid':line_sep['residue_id']} #### if atom is in the backbone list then its mass is updated to the correct one if line_sep['atom_name'] in g_var.res_top[line_sep['residue_name']]['ATOMS']: if line_sep['atom_name'] in line_sep['atom_name'] in g_var.res_top[line_sep['residue_name']]['atom_masses']: atomistic_protein_input[chain_count][line_sep['residue_id']][line_sep['atom_number']]['frag_mass']=g_var.res_top[line_sep['residue_name']]['atom_masses'][line_sep['atom_name']] return atomistic_protein_input, chain_count+1
def get_atomistic(frag_location, resname=False): if not resname: resname = frag_location.split('/')[-1][:-4] #### read in atomistic fragments into dictionary residue = { } ## a dictionary of bead in each residue eg residue[group][bead][atom number(1)][residue_name(ASP)/coordinates(coord)/atom name(C)/connectivity(2)/atom_mass(12)] fragment_mass = {} with open(frag_location, 'r') as pdb_input: for line_nr, line in enumerate(pdb_input.readlines()): if line.startswith('['): residue, group, bead = split_fragment_names( line, residue, resname) fragment_mass[bead] = [] if line.startswith('ATOM'): line_sep = gen.pdbatom(line) ## splits up pdb line residue[group][bead][line_sep['atom_number']] = { 'coord': np.array([ line_sep['x'] * g_var.sf, line_sep['y'] * g_var.sf, line_sep['z'] * g_var.sf ]), 'atom': line_sep['atom_name'], 'resid': 1, 'resid_ori': line_sep['residue_id'], 'res_type': line_sep['residue_name'], 'frag_mass': 1 } #### updates fragment mass if not gen.is_hydrogen(line_sep['atom_name']): if line_sep['atom_name'] in g_var.res_top[resname][ 'atom_masses']: residue[group][bead][line_sep['atom_number']][ 'frag_mass'] = g_var.res_top[resname][ 'atom_masses'][line_sep[ 'atom_name']] ### updates atom masses with crude approximations fragment_mass[bead].append([ line_sep['x'] * g_var.sf, line_sep['y'] * g_var.sf, line_sep['z'] * g_var.sf, g_var.res_top[resname] ['atom_masses'][line_sep['atom_name']] ]) else: fragment_mass[bead].append([ line_sep['x'] * g_var.sf, line_sep['y'] * g_var.sf, line_sep['z'] * g_var.sf, 1 ]) return residue, fragment_mass