def write_superposed_pdbs(self, output_pdb_folder, alignments: dict = None): """ Superposes PDBs according to alignment and writes transformed PDBs to files (View with Pymol) Parameters ---------- alignments output_pdb_folder """ if alignments is None: alignments = self.alignment output_pdb_folder = Path(output_pdb_folder) if not output_pdb_folder.exists(): output_pdb_folder.mkdir() reference_name = self.structures[0].name reference_pdb = pd.parsePDB( str(self.output_folder / f"cleaned_pdb/{self.structures[0].name}.pdb") ) core_indices = np.array( [ i for i in range(len(alignments[reference_name])) if -1 not in [alignments[n][i] for n in alignments] ] ) aln_ref = alignments[reference_name] ref_coords_core = ( reference_pdb[helper.get_alpha_indices(reference_pdb)] .getCoords() .astype(np.float64)[np.array([aln_ref[c] for c in core_indices])] ) ref_centroid = helper.nb_mean_axis_0(ref_coords_core) ref_coords_core -= ref_centroid transformation = pd.Transformation(np.eye(3), -ref_centroid) reference_pdb = pd.applyTransformation(transformation, reference_pdb) pd.writePDB(str(output_pdb_folder / f"{reference_name}.pdb"), reference_pdb) for i in range(1, len(self.structures)): name = self.structures[i].name pdb = pd.parsePDB( str(self.output_folder / f"cleaned_pdb/{self.structures[i].name}.pdb") ) aln_name = alignments[name] common_coords_2 = ( pdb[helper.get_alpha_indices(pdb)] .getCoords() .astype(np.float64)[np.array([aln_name[c] for c in core_indices])] ) ( rotation_matrix, translation_matrix, ) = superposition_functions.svd_superimpose( ref_coords_core, common_coords_2 ) transformation = pd.Transformation(rotation_matrix.T, translation_matrix) pdb = pd.applyTransformation(transformation, pdb) pd.writePDB(str(output_pdb_folder / f"{name}.pdb"), pdb)
def getInitLig(lig, rec_init_cent, lig_init_cent): """ rec_init_cent, lig_init_cent should be numpy arraay lig: ligand structure data""" init_translation = rec_init_cent - lig_init_cent t = prody.Transformation( np.identity( 3 ), init_translation ) initlig = lig.copy() t.apply( initlig ) return initlig
def write_superposed_pdbs_reference(self, output_pdb_folder, alignments): """ Superposes PDBs according to reference structure and writes transformed PDBs to files (View with Pymol) Parameters ---------- alignments output_pdb_folder """ reference_name = self.structures[self.reference_structure_index].name reference_pdb = pd.parsePDB( str(self.output_folder / f"cleaned_pdb/{self.structures[self.reference_structure_index].name}.pdb" )) aln_ref = alignments[reference_name] reference_coords = (reference_pdb[helper.get_alpha_indices( reference_pdb)].getCoords().astype(np.float64)) pd.writePDB(str(output_pdb_folder / f"{reference_name}.pdb"), reference_pdb) for i in range(1, len(self.structures)): name = self.structures[i].name pdb = pd.parsePDB( str(self.output_folder / f"cleaned_pdb/{self.structures[i].name}.pdb")) aln_name = alignments[name] common_coords_1, common_coords_2 = get_common_coordinates( reference_coords, pdb[helper.get_alpha_indices(pdb)].getCoords().astype( np.float64), aln_ref, aln_name, ) ( rotation_matrix, translation_matrix, ) = superposition_functions.svd_superimpose( common_coords_1, common_coords_2) transformation = pd.Transformation(rotation_matrix.T, translation_matrix) pdb = pd.applyTransformation(transformation, pdb) pd.writePDB(str(output_pdb_folder / f"{name}.pdb"), pdb)
rec_dict = initialize_res_score(rec) lig_dict = initialize_res_score(lig) for line in outFileLines[4:254]: decoylig = lig.copy() rotation = [float(x) for x in line.split('\t')[0:3]] rotation = getRotationMatrix(rotation) translation = [float(x) for x in line.split('\t')[3:6]] translation = getTranslation(translation) score = float(line.split('\t')[-1]) decoylig.setCoords(decoylig.getCoords() - lig_init_cent) # apply rotation t = prody.Transformation(rotation, np.zeros(3)) t.apply(decoylig) decoylig.setCoords(decoylig.getCoords() + translation + rec_init_cent) mobile = rec + decoylig decoy_contacts_rec = prody.Contacts(rec) decoy_contacts_rec = decoy_contacts_rec.select(4, decoylig) decoy_contacts_lig = prody.Contacts(decoylig) decoy_contacts_lig = decoy_contacts_lig.select(4, rec) #lig_contact_atoms = prody.matchChains( lig, decoy_contacts_lig, overlap=0.01, subset='all' )[0][0] interface_resnums += (list(set(decoy_contacts_rec.getResnums()))) l_interface_resnums += (list(set(decoy_contacts_lig.getResnums()))) interface_residue_pairs.append([