def pdb_dist(pdb_f, pdb_id): structure = PDBParser().get_structure(pdb_id, pdb_f) atom_list = Selection.unfold_entities(structure, 'A') ns = NeighborSearch(atom_list) center = [a for a in structure.get_atoms() if a.get_parent().get_resname( ) in ['PTR', 'SEP', 'TPO'] and a.get_name() in ['O1P', 'O2P', 'O3P', 'OH', 'OG', 'OG1']] # neighbors = [a for a in structure.get_atoms() if a.get_parent().get_resname( # ) in ['ARG'] and a.get_name() in ['NE', 'NH2', 'NH1']] # neighbors = [a for a in structure.get_atoms() if a.get_parent().get_resname( # ) in ['Lys'] and a.get_name() in ['NZ']] neighbors = [a for a in structure.get_atoms() if a.get_parent().get_resname( ) in ['HIS'] and a.get_name() in ['ND1','NE2']] def calc_dist(a, b): vector = a.coord - b.coord return np.sqrt(np.sum(vector * vector)) dist = {} for c in center: for n in neighbors: value = calc_dist(c, n) key = str(c.get_parent()) + '_' + str(n.get_parent()) if not key in dist.keys(): dist[key] = [value] else: dist[key].append(value) for k, v in dist.items(): dist[k] = min(v) dist = [v for k, v in dist.items()] return dist
def draw_OXY(self, O, X, Y, chaintop=None): """ Draws the network using the O X Y method, O, X, Y are 3d coordinate points that should frame the representation""" Ox = [c1 - c2 for c1, c2 in zip(O, X)] Oy = [c1 - c2 for c1, c2 in zip(O, Y)] normOx = np.linalg.norm(Ox) normOy = np.linalg.norm(Oy) structure = PDBParser().get_structure('X', self.pdb_path)[0] pos = {} distance_thresh = 1 for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent if chaintop: c = 1 * (residue.parent.id == chaintop) else: c = 0 if residue.resname in three2one: "we compute the coordinates using the distance of the point to the lines of the frame" AO = [c1 - c2 for c1, c2 in zip(O, atom.coord)] x = np.linalg.norm(np.cross(AO, Ox)) / normOx y = np.linalg.norm(np.cross(AO, Oy)) / normOy + 1 * c pos[three2one[residue.resname] + str(residue.id[1]) + ':' + residue.parent.id] = (x, y) if not self.single: self.draw_default(pos) else: self.drawing(self.output, pos)
def filter_structure(pdb,chain,lig,lig_num): # pdb_input = pdb_path + "/" + pdb + ":" + chain + ":" + lig + ":" + lig_num + ".atoms.pdb" pdb_input = pdb_path + "/" + pdb + ".pdb" pdb_output = output_path + "/" + pdb + ":" + chain + ":" + lig + ":" + lig_num + ".atoms.pdb" structure = PDBParser(QUIET=1).get_structure(pdb, pdb_input) atoms_pairs = NeighborSearch( list( structure.get_atoms() ) ).search_all(search_radius) res_list = set() for atom_pair in atoms_pairs: res1 = atom_pair[0].parent res_chain1 = res1.parent.id res_name1 = res1.resname res_num1 = str(res1.id[1]) res2 = atom_pair[1].parent res_chain2 = res2.parent.id res_name2 = res2.resname res_num2 = str(res2.id[1]) if ( (res_chain1 == chain and res_name1 == lig and res_num1 == lig_num) or (res_chain2 == chain and res_name2 == lig and res_num2 == lig_num) ): res_list.add(res1) res_list.add(res2) io = PDBIO() io.set_structure(structure) io.save(pdb_output, ResSelect(res_list))
def pdb_neighbors(pdb_f, pdb_id): structure = PDBParser().get_structure(pdb_id, pdb_f) atom_list = Selection.unfold_entities(structure, 'A') ns = NeighborSearch(atom_list) center = [(a, a.get_coord()) for a in structure.get_atoms() if a.get_parent().get_resname() in ['PTR', 'SEP', 'TPO'] and a.get_name() in ['O1P', 'O2P', 'O3P', 'OH', 'OG', 'OG1']] # if there are no phos-atomes, return if len(center) == 0: return '' neighbors = {} for a, c in center: # set neighbor distance cutoff neighbor_list = ns.search(c, BOND_CUTOFF) residue_list = list(set(Selection.unfold_entities(neighbor_list, 'R'))) try: neighbors[Selection.unfold_entities(a, 'R')[0]] = [ x for x in residue_list if not x == Selection.unfold_entities(a, 'R')[0] ] except: continue # add residue id and chain id neighbors_full = dict([('_'.join( [k.get_resname(), str(k.get_id()[1]), str(k.get_parent().get_id())]), [ '_'.join([ vi.get_resname(), str(vi.get_id()[1]), str(vi.get_parent().get_id()) ]) for vi in v ]) for k, v in neighbors.iteritems()]) return neighbors_full
def draw_4CFF(self): """A specific drawing adapted for 4CFF""" structure = PDBParser().get_structure('X', self.pdb_path)[0] pos = {} for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent if residue.resname in three2one: db = sqrt((atom.coord[0] - 37.726)**2 + (atom.coord[1] - 23.815)**2 + (atom.coord[2] - 34.728)**2) dc = sqrt((atom.coord[0] - 32.102)**2 + (atom.coord[1] - 24.797)**2 + (atom.coord[2] - 59.026)**2) dd = sqrt((atom.coord[0] - 70.621)**2 + (atom.coord[1] - 72.942)**2 + (atom.coord[2] - 43.637)**2) y = sqrt( abs(dc**2 - ((dc**2 - db**2) / (2 * 24.959) + 24.959 / 2)**2)) x = sqrt( abs(dd**2 - ((dd**2 - db**2) / (2 * 59.79) + 59.79 / 2)**2)) pos[three2one[residue.resname] + str(residue.id[1]) + ':' + residue.parent.id] = (x, y) if not self.single: self.draw_default(pos) else: self.drawing(self.output, pos)
def get_3d_pos(self): structure = PDBParser().get_structure('X', self.pdb_path)[0] pos = {} for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent if residue.resname in three2one: pos[three2one[residue.resname] + str(residue.id[1]) + ':' + residue.parent.id] = atom.coord return pos
def get_pos_3D(self, pdb_path): structure = PDBParser().get_structure('X', pdb_path)[0] node2CA = {} for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent coords = ' '.join(map(str, atom.coord)) node2CA[t2o(residue.resname)+str(residue.id[1])+':'+residue.parent.id] = coords self.pos_3D = node2CA
def pdb_dist(pdb_f, pdb_id): structure = PDBParser().get_structure(pdb_id, pdb_f) atom_list = Selection.unfold_entities(structure, 'A') ns = NeighborSearch(atom_list) center = [ a for a in structure.get_atoms() if a.get_parent().get_resname() in ['PTR', 'SEP', 'TPO'] and a.get_name() in ['O1P', 'O2P', 'O3P', 'OH', 'OG', 'OG1'] ] N_neighbors = [ a for a in structure.get_atoms() if 'N' in a.get_name() and a.get_name() != 'N' ] O_neighbors = [ a for a in structure.get_atoms() if 'O' in a.get_name() and a.get_name() != 'O' ] # all N and O except those on main chain neighbors = N_neighbors + O_neighbors def calc_dist(a, b): vector = a.coord - b.coord return np.sqrt(np.sum(vector * vector)) dist = {} for c in center: for n in neighbors: # atoms not on same residue if c.get_parent() != n.get_parent(): value = calc_dist(c, n) key = str(c.get_parent()) + '_' + str(n.get_parent()) if not key in dist.keys(): dist[key] = [value] else: dist[key].append(value) for k, v in dist.items(): dist[k] = min(v) dist = [v for k, v in dist.items()] return dist
def get_pos_2D(self, pdb_path): structure = PDBParser().get_structure('X', pdb_path)[0] pos = {} for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent "these values represents the 2D projection of IGPS in our classical view" y = (0.1822020302*atom.coord[0] + 0.6987674421*atom.coord[1] - 0.6917560857*atom.coord[2]) x = 0.9980297273*atom.coord[0]+ 0.0236149631*atom.coord[1]+ 0.05812914*atom.coord[2] pos[t2o(residue.resname)+str(residue.id[1])+':'+residue.parent.id] = (x, y) self.pos_2D = pos
def get_inspecting_atoms(path: str, element_process_priority: list) -> list: structure = PDBParser(QUIET=True).get_structure('structure', 'Data/CHO_surface.pdb') # get Bio.PDB.Atom objects atoms = [a for a in structure.get_atoms()] # remove unknown atoms atoms = [a for a in atoms if a.get_id()[0] in element_process_priority] # sort atoms by element process priority atoms = sorted(atoms, key=lambda a: element_process_priority.index(a.get_id()[0])) return atoms
def __init__(self, pdb_path, nc): structure = PDBParser().get_structure('X', pdb_path)[0] self.color = not nc self.node2CA = {} for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent if residue.resname in three2one: coords = str(atom.coord[0]) + ' ' + str( atom.coord[1]) + ' ' + str(atom.coord[2]) self.node2CA[three2one[residue.resname] + str(residue.id[1]) + ':' + residue.parent.id] = coords
def get_pos(self, pdb): structure = PDBParser().get_structure('X', pdb)[0] pos = {} for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent c = 1 * (residue.parent.id == 'A') #Separate chains if residue.resname in three2one: "tbh these are random values" y = (atom.coord[2]) * (1 - 0.5 * c) x = atom.coord[1] pos[three2one[residue.resname] + str(residue.id[1]) + ':' + residue.parent.id] = (x, y) return pos
class IterationTests(unittest.TestCase): def setUp(self): self.struc = PDBParser(PERMISSIVE=True).get_structure('X', "PDB/a_structure.pdb") def test_get_chains(self): """Yields chains from different models separately.""" chains = [chain.id for chain in self.struc.get_chains()] self.assertEqual(chains, ['A','A', 'B', ' ']) def test_get_residues(self): """Yields all residues from all models.""" residues = [resi.id for resi in self.struc.get_residues()] self.assertEqual(len(residues), 167) def test_get_atoms(self): """Yields all atoms from the structure, excluding duplicates and ALTLOCs which are not parsed.""" atoms = ["%12s"%str((atom.id, atom.altloc)) for atom in self.struc.get_atoms()] self.assertEqual(len(atoms), 756)
class IterationTests(unittest.TestCase): def setUp(self): self.struc = PDBParser(PERMISSIVE=True).get_structure('X', "PDB/a_structure.pdb") def test_get_chains(self): """Yields chains from different models separately.""" chains = [chain.id for chain in self.struc.get_chains()] self.assertEqual(chains, ['A','A', 'B', ' ']) def test_get_residues(self): """Yields all residues from all models.""" residues = [resi.id for resi in self.struc.get_residues()] self.assertEqual(len(residues), 167) def test_get_atoms(self): """Yields all atoms from the structure, excluding duplicates and ALTLOCs which are not parsed.""" atoms = ["%12s"%str((atom.id, atom.altloc)) for atom in self.struc.get_atoms()] self.assertEqual(len(atoms), 756)
def draw_IGPS(self): """A specific drawing adapted to IGPS this should be tunable for other proteins""" structure = PDBParser().get_structure('X', self.pdb_path)[0] pos = {} distance_thresh = 1 for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent c = 1 * (residue.parent.id == 'H') #Separate hisH and hisF if residue.resname in three2one: "these values represents the 2D projection of IGPS in our classical view" y = (0.1822020302 * atom.coord[0] + 0.6987674421 * atom.coord[1] - 0.6917560857 * atom.coord[2]) * (1 - 0.5 * c) x = 0.9980297273 * atom.coord[ 0] + 0.0236149631 * atom.coord[ 1] + 0.05812914 * atom.coord[2] pos[three2one[residue.resname] + str(residue.id[1]) + ':' + residue.parent.id] = (x, y) if not self.single: self.draw_default(pos) else: self.drawing(self.output, pos)
def get_pos_OXY(pdb_path, O, X, Y, output, chaintop=None): """ Draws the network using the O X Y method, O, X, Y are 3d coordinate points that should frame the representation""" Ox = [c1 - c2 for c1, c2 in zip(O, X)] Oy = [c1 - c2 for c1, c2 in zip(O, Y)] normOx = np.linalg.norm(Ox) normOy = np.linalg.norm(Oy) structure = PDBParser().get_structure('X', pdb_path)[0] pos = {} distance_thresh = 1 for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent if chaintop: c = 1 * (residue.parent.id == chaintop) else: c = 0 AO = [c1 - c2 for c1, c2 in zip(O, atom.coord)] x = np.linalg.norm(np.cross(AO, Ox)) / normOx y = np.linalg.norm(np.cross(AO, Oy)) / normOy + 1 * c pos[t2o(residue.resname) + str(residue.id[1]) + ':' + residue.parent.id] = (x, y) pkl.dump(pos, open(output, 'wb'))
def get_residues_df(pdb_id, path): pdb_file = path + pdb_id + '.pdb' structure = PDBParser().get_structure(pdb_id, pdb_file) atoms = structure.get_atoms() ###Get residue coordinates temp_listy = [] cols = [ 'residue_number', 'amino_acid', 'chain', 'CA_coords', 'CB_coords', 'SCcenter_coords' ] for residue in structure.get_residues(): if is_aa(residue): temp_dict = process_residue(residue) if type(temp_dict) == str: continue temp_listy.append([temp_dict[col] for col in cols]) else: #print('Problem with this residue: {}'.format(residue)) qwe = 1 residues_df = pd.DataFrame(temp_listy, columns=cols) return residues_df
def main(argv): reference_structure = '' pandda_analyse_centroids = '' name = '' processing_directory = '' database_file = 'database/soakDBDataFile.sqlite' try: opts, args = getopt.getopt(argv, "hr:p:n:d:", ["rfile=", "pfile=", "name="]) except getopt.GetoptError: print 'usage: generate_leads.py -r <reference_pdb.pdb> -p <pandda_analyse_sites.csv> -n <name>' sys.exit(2) except: print 'usage: generate_leads.py -r <reference_pdb.pdb> -p <pandda_analyse_sites.csv> -n <name>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'usage: generate_leads.py -r <reference_pdb.pdb> -p <pandda_analyse_sites.csv> -n <name>' sys.exit() elif opt in ("-r", "--rfile"): reference_structure = arg elif opt in ("-p", "--pfile"): pandda_analyse_centroids = arg elif opt in ("-n", "--name"): name = arg elif opt in ("-d", "--dir"): processing_directory = arg print('\n The apo structure ' + str(name) + ' in ' + str(reference_structure) + ' will be searched for leads defined by the site centroids in ' + str(pandda_analyse_centroids) + '\n') # read structure from reference file with BioPy PDBParser structure = PDBParser(PERMISSIVE=0).get_structure(str(name), str(reference_structure)) # read centroids from pandda analyse sites list (native) site_list = pd.read_csv(str(pandda_analyse_centroids))['native_centroid'] print(' Searching for residue atoms for ' + str(len(site_list)) + ' site centroids \n') print(' NOTE: 3 residue atoms are required for each site centroid \n') print site_list no = 0 for centroid in site_list: print('next centroid') structure = PDBParser(PERMISSIVE=0).get_structure( str(name), str(reference_structure)) no += 1 res_list = [] # initial distance for nearest neighbor (NN) search is 2A neighbor_distance = 20 centroid_coordinates = centroid.replace('(', '[') centroid_coordinates = centroid_coordinates.replace(')', ']') centroid_coordinates = eval(str(centroid_coordinates)) # define centroid as an atom object for NN search centroid_atom = Atom.Atom('CEN', centroid_coordinates, 0, 0, 0, 0, 9999, 'C') atoms = list(structure.get_atoms()) center = np.array(centroid_atom.get_coord()) ns = NeighborSearch(atoms) # calculate NN list neighbors = ns.search(center, neighbor_distance) res_list = [] # for each atom in the NN list for neighbor in neighbors: try: # get the residue that the neighbor belongs to parent = Atom.Atom.get_parent(neighbor) # if the residue is not a water etc. (amino acids have blank) if parent.get_id()[0] == ' ': # get the chain that the residue belongs to chain = Residue.Residue.get_parent(parent) # if statements for fussy proasis formatting if len(str(parent.get_id()[1])) == 3: # residue string = 'RES CHAIN NUMBER :...' res = (str(parent.get_resname()) + ' ' + str(chain.get_id()) + ' ' + str(parent.get_id()[1])) res_list.append(res) if len(str(parent.get_id()[1])) == 2: res = (str(parent.get_resname()) + ' ' + str(chain.get_id()) + ' ' + str(parent.get_id()[1])) res_list.append(res) except: break res_list = (list(set(res_list))) print res_list lig1 = str("'" + str(res_list[0]) + ' :' + str(res_list[1]) + ' :' + str(res_list[2]) + " ' ") print lig1 res_string = "-o '" for i in range(3, len(res_list) - 1): res_string += str(res_list[i] + ' ,') res_string += str(res_list[i + 1] + ' ') #print str(res_string[i+1]) submit_to_proasis = str( '/usr/local/Proasis2/utils/submitStructure.py -p ' + str(name) + ' -t ' + str(name + '_lead -d admin -f ' + str(reference_structure) + ' -l ' + str(lig1)) + str(res_string) + "' -x XRAY -n") process = subprocess.Popen(submit_to_proasis, stdout=subprocess.PIPE, shell=True) out, err = process.communicate() print out strucidstr = re.search(r"strucid='.....'", out) strucidstr = strucidstr.group() strucidstr = strucidstr.replace('strucid=', '') strucidstr = strucidstr.replace("'", '') add_lead = str('/usr/local/Proasis2/utils/addnewlead.py -p ' + str(name) + ' -s ' + str(strucidstr)) os.system(add_lead) #process = subprocess.Popen(add_lead, stdout=subprocess.PIPE, shell=True) #out, err = process.communicate() #strucidstr = get_id_string(out) if strucidstr != '': print('Success... ' + name + ' submitted. ProasisID: ' + str(strucidstr)) conn = sqlite3.connect( os.path.join(processing_directory, database_file)) c = conn.cursor() c.execute("CREATE TABLE IF NOT EXISTS 'proasisLead' ('protein' TEXT, " "'leadDir' TEXT, 'proasisID');") c.execute( str("INSERT INTO proasisLead (protein, leadDir, proasisID) VALUES ('" + str(name) + "','" + str(reference_structure) + "','" + str(strucidstr) + "');")) conn.commit() c.close() else: print('Error: ' + str(err))
atom = structure[int(model)][chain][(' ', int(resnum), inscode if inscode else ' ')][atomname] atoms.append(atom) for atom in atoms: # MAKE A FAKE ATOM FROM THE REAL ONE, # AND ADD THIS TO THE FAKE RESIDUE copy = atom.copy() copy.id = 'X' + str(atom_counter) copy.element = 'H' copy.name = 'X' copy.serial_number = max( [a.serial_number for a in structure.get_atoms()]) + 1 copy.detach_parent() fake.add(copy) atom_counter += 1 # ADD FAKE RESIDUE TO FIRST CHAIN IN STRUCTURE structure[0].get_list()[0].add(fake) # SAVE MODIFIED PDB io = PDBIO() io.set_structure(structure) io.save(mod_pdb) # MAKE THE DPOCKET INPUT FILE input_file = mod_pdb + '.input'
def run(self): pandda_analyse_centroids = str(self.pandda_directory + '/analyses/pandda_analyse_sites.csv') if os.path.isfile(pandda_analyse_centroids): site_list = pandas.read_csv( str(pandda_analyse_centroids))['native_centroid'] print(' Searching for residue atoms for ' + str(len(site_list)) + ' site centroids \n') print( ' NOTE: 3 residue atoms are required for each site centroid \n' ) print site_list else: print('file does not exist!') no = 0 for centroid in site_list: # print('next centroid') structure = PDBParser(PERMISSIVE=0).get_structure( str(self.name), str(self.reference_structure)) no += 1 res_list = [] # initial distance for nearest neighbor (NN) search is 20A neighbor_distance = 20 centroid_coordinates = centroid.replace('(', '[') centroid_coordinates = centroid_coordinates.replace(')', ']') centroid_coordinates = eval(str(centroid_coordinates)) # define centroid as an atom object for NN search centroid_atom = Atom.Atom('CEN', centroid_coordinates, 0, 0, 0, 0, 9999, 'C') atoms = list(structure.get_atoms()) center = np.array(centroid_atom.get_coord()) ns = NeighborSearch(atoms) # calculate NN list neighbors = ns.search(center, neighbor_distance) res_list = [] # for each atom in the NN list for neighbor in neighbors: try: # get the residue that the neighbor belongs to parent = Atom.Atom.get_parent(neighbor) # if the residue is not a water etc. (amino acids have blank) if parent.get_id()[0] == ' ': # get the chain that the residue belongs to chain = Residue.Residue.get_parent(parent) # if statements for fussy proasis formatting if len(str(parent.get_id()[1])) == 3: space = ' ' if len(str(parent.get_id()[1])) == 2: space = ' ' if 'HOH' not in str(parent.get_resname()): res = (str(parent.get_resname()) + ' ' + str(chain.get_id()) + space + str(parent.get_id()[1])) res_list.append(res) except: continue res_list = (list(set(res_list))) print res_list lig1 = str("'" + str(res_list[0]) + ' :' + str(res_list[1]) + ' :' + str(res_list[2]) + " ' ") print lig1 # some faff to get rid of waters and add remaining ligands in multiples of 3 - proasis is fussy alt_lig_option = " -o '" res_string = "" full_res_string = '' count = 0 for i in range(3, len(res_list)): count += 1 multiple = int(round(count / 3) * 3) count = 0 for i in range(3, multiple): if count == 0: res_string += alt_lig_option if count <= 1: res_string += str(res_list[i] + ' ,') count += 1 elif count == 2: res_string += str(res_list[i] + " '") full_res_string.join(res_string) count = 0 # copy reference structure to proasis directories ref_structure_file_name = str(self.reference_structure).split('/')[-1] proasis_project_directory = str( str(self.proasis_directory) + '/' + str(self.name)) proasis_reference_directory = str( str(proasis_project_directory) + '/reference/') proasis_reference_structure = str(proasis_reference_directory + '/' + str(ref_structure_file_name)) if not os.path.isdir(str(proasis_project_directory)): os.system(str('mkdir ' + str(proasis_project_directory))) if not os.path.isdir(proasis_reference_directory): os.system(str('mkdir ' + str(proasis_reference_directory))) os.system( str('cp ' + str(self.reference_structure) + ' ' + str(proasis_reference_structure))) #submit_to_proasis = str('/usr/local/Proasis2/utils/submitStructure.py -p ' + str(self.name) + ' -t ' + str(self.name) + '_lead -d admin -f ' + str(proasis_reference_structure) + ' -l ' + str(lig1) + str(res_string) + " -x XRAY -n") submit_to_proasis = str( '/usr/local/Proasis2/utils/submitStructure.py -p ' + str(self.name) + ' -t ' + str(self.name) + '_lead -d admin -f ' + str(proasis_reference_structure) + ' -l ' + str(lig1) + "-x XRAY -n") print submit_to_proasis process = subprocess.Popen(submit_to_proasis, stdout=subprocess.PIPE, shell=True) out, err = process.communicate() print(out) if err: raise Exception('There was a problem submitting this lead: ' + str(err)) strucidstr = misc_functions.get_id_string(out) if len(strucidstr) < 5: raise Exception('No strucid was detected!') add_lead = str('/usr/local/Proasis2/utils/addnewlead.py -p ' + str(self.name) + ' -s ' + str(strucidstr)) process = subprocess.Popen(add_lead, stdout=subprocess.PIPE, shell=True) out, err = process.communicate() print(out) if err: raise Exception('There was a problem submitting this lead: ' + str(err)) conn, c = db_functions.connectDB() c.execute( 'UPDATE proasis_leads SET strucid = %s WHERE reference_pdb = %s and pandda_path = %s', (strucidstr, self.reference_structure, self.pandda_directory)) conn.commit() with self.output().open('wb') as f: f.write('')
def run(self): for centroid in self.site_centroids: # print('next centroid') structure = PDBParser(PERMISSIVE=0).get_structure( str(self.target).upper(), str(self.reference_structure)) # initial distance for nearest neighbor (NN) search is 10A neighbor_distance = 10 centroid_coordinates = list(centroid) # define centroid as an atom object for NN search centroid_atom = Atom.Atom('CEN', centroid_coordinates, 0, 0, 0, 0, 9999, 'C') atoms = list(structure.get_atoms()) center = np.array(centroid_atom.get_coord()) ns = NeighborSearch(atoms) # calculate NN list neighbors = ns.search(center, neighbor_distance) res_list = [] # for each atom in the NN list for neighbor in neighbors: try: # get the residue that the neighbor belongs to parent = Atom.Atom.get_parent(neighbor) # if the residue is not a water etc. (amino acids have blank) if parent.get_id()[0] == ' ': # get the chain that the residue belongs to chain = Residue.Residue.get_parent(parent) # if statements for fussy proasis formatting # establish string spacing for proasis if len(str(parent.get_id()[1])) >= 3: space = ' ' if len(str(parent.get_id()[1])) == 2: space = ' ' if len(str(parent.get_id()[1])) == 1: space = ' ' # ignore waters if 'HOH' not in str(parent.get_resname()): res = (str(parent.get_resname()) + ' ' + str(chain.get_id()) + space + str(parent.get_id()[1])) res_list.append(res) except: continue res_list = (list(set(res_list))) print(res_list) colon = ' :' if len(str(res_list[0])) >= 10: colon = ':' lig1 = str("'" + str(res_list[0]) + colon) if len(str(res_list[1])) >= 10: colon = ':' lig1 += str(str(res_list[1]) + colon) close = " ' " if len(str(res_list[2])) >= 10: close = "' " lig1 += str(str(res_list[2]) + close) # some faff to get rid of waters and add remaining ligands in multiples of 3 - proasis is fussy alt_lig_option = " -o '" res_string = "" full_res_string = '' count = 0 for i in range(3, len(res_list)): count += 1 multiple = int(round(count / 3) * 3) count = 0 for i in range(3, multiple): print(len(str(res_list[i]))) if count == 0: res_string += alt_lig_option if count <= 1: if len(str(res_list[i])) >= 10: res_string += str(res_list[i] + ',') else: res_string += str(res_list[i] + ' ,') count += 1 elif count == 2: if len(str(res_list[i])) >= 10: res_string += str(res_list[i] + "'") else: res_string += str(res_list[i] + " '") full_res_string = full_res_string + res_string count = 0 # string to submit structure as lead submit_to_proasis = str( '/usr/local/Proasis2/utils/submitStructure.py -p ' + str(self.target).upper() + ' -t ' + str(self.target).upper() + '_lead -d admin -f ' + str(self.reference_structure) + ' -l ' + str(lig1) + ' ' + full_res_string + " -x XRAY -n") # for debug print(submit_to_proasis) # submit and read output - raise exception if neccessary process = subprocess.Popen(submit_to_proasis, stdout=subprocess.PIPE, shell=True) out, err = process.communicate() out = out.decode('ascii') if err: err = err.decode('ascii') # find strucid from submission output strucidstr = misc_functions.get_id_string(out) # if no strucid in output, raise an exception and print error if len(strucidstr) == 0: raise Exception('No strucid was detected: ' + str(out) + ' ; ' + str(err)) # add the new structure as a lead add_lead = str('/usr/local/Proasis2/utils/addnewlead.py -p ' + str(self.target).upper() + ' -s ' + str(strucidstr)) process = subprocess.Popen(add_lead, stdout=subprocess.PIPE, shell=True) out, err = process.communicate() out = out.decode('ascii') # report any errors if err: err = err.decode('ascii') print(out) if err: raise Exception('There was a problem submitting this lead: ' + str(err)) # update lead object strucid field lead = ProasisLeads.objects.get(reference_pdb=Reference.objects.get( reference_pdb=self.reference_structure)) lead.strucid = strucidstr lead.save()
parser = argparse.ArgumentParser() parser.add_argument("--pdb", required=True) parser.add_argument("--chain1", nargs='+', required=True) parser.add_argument("--chain2", nargs='+', required=True) args = parser.parse_args() from Bio.PDB import NeighborSearch, PDBParser, Selection structure = PDBParser().get_structure('X', args.pdb) center_atoms = [] pymol_command = "" all_atom_list = [atom for atom in structure.get_atoms() if atom.name == 'CA' ] for k in args.chain1 : chain_atoms = [atom for atom in structure[0][k].get_atoms() if atom.name == 'CA' ] center_atoms += chain_atoms #atom_list = [x for x in all_atom_list if x not in center_atoms] for j in args.chain2 : atom_list = [atom for atom in structure[0][j].get_atoms() if atom.name == 'CA' ] ns = NeighborSearch(atom_list) nearby_residues = {res for center_atom in center_atoms for res in ns.search(center_atom.coord, 8.5, 'R')}
parser.add_argument('-same', type=bool, default=False, help="use the same normalization factor for all drawn networks") parser.add_argument('-c', type=str, nargs=3, default=['red', 'blue', 'silver'], help="changes the colors used to draw the network. In the order: edges that increases in contact number, edges that decreases in contact number, node") parser.add_argument('-m', nargs=2, type=str, help="""Allows to draw on a non amino acid based molecule First argument: Molecule name Second argument: Atom of the molecule to center on""") args = parser.parse_args() structure = PDBParser().get_structure('X', args.p)[0] color = not args.nc node2CA = {} for atom in structure.get_atoms(): if atom.id == 'CA': residue = atom.parent if residue.resname in three2one: coords = str(atom.coord[0]) + ' ' + str(atom.coord[1]) + ' ' + str(atom.coord[2]) node2CA[three2one[residue.resname]+str(residue.id[1])+':'+residue.parent.id] = coords if args.m: if atom.id == args.m[1] and atom.parent.resname == args.m[0]: coords = str(atom.coord[0]) + ' ' + str(atom.coord[1]) + ' ' + str(atom.coord[2]) node2CA[atom.parent.resname+str(atom.parent.id[1])+':'+atom.parent.parent.id] = coords print(atom.parent.resname+str(atom.parent.id[1])+':'+atom.parent.parent.id) div = None for fichier in tqdm(args.f): out_path = fichier[:-2]+'.tcl' with open(out_path, 'w') as output: