def get_secondary_structure(self, chain_id): if self.template_obj is None: raise ModelRunError("template object is not set") return ''.join( self.yasara.SecStrRes('obj %i and protein and mol %s' % (self.template_obj, chain_id)))
def get_chain_ids(self): if self.template_obj is None: raise ModelRunError("template object is not set") chain_ids = self.yasara.ListMol( 'obj %i and protein' % self.template_obj, 'MOL') return chain_ids
def _pick_identical_chains(self, main_chain_id, context): identical_chain_groups = self._group_identical_chains(context) for group in identical_chain_groups: if main_chain_id in group: return group raise ModelRunError("chain not found in identical groups: {}".format(main_chain_id))
def residue_interacts_with(self, residue, interacting_residues): if self.template_obj is None: raise ModelRunError("template object is not set") if 'CA' not in residue.atom_numbers: return False interacting_residues = list( filter(lambda res: 'CA' in res.atom_numbers, interacting_residues)) atoms = self.yasara.ListAtom( "CA and atom %i-%i and obj %i with distance<6 from %i" % (interacting_residues[0].atom_numbers['CA'], interacting_residues[-1].atom_numbers['CA'], self.template_obj, residue.atom_numbers['CA'])) return len(atoms) > 0
def get_residues(self, chain_id): if self.template_obj is None: raise ModelRunError("template object is not set") residues = [] for s in self.yasara.ListAtom( "obj %i and mol %s and protein" % (self.template_obj, chain_id), "RESNUM RESNAME ATOMNAME ATOMNUM"): resnum, resname, atomname, atomnum = s.split() if len(residues) <= 0 or residues[-1].residue_number != resnum: amino_acid = AminoAcid.from_three_letter_code(resname) residues.append(ModelingResidue(resnum, amino_acid)) residues[-1].atom_numbers[atomname] = int(atomnum) return residues
def _handle_error_txt(self, error_path, work_dir_path, context, main_domain_alignment): with open(error_path, 'r') as f: msg = f.read() if 'reward for reporting' in msg.lower(): model_name = model_storage.get_model_name(context.get_main_target_sequence(), context.target_species_id, main_domain_alignment, TemplateID(context.template_pdbid, context.main_target_chain_id)) tar_path = model_storage.get_error_tar_path(context.get_main_target_sequence(), context.target_species_id, main_domain_alignment, TemplateID(context.template_pdbid, context.main_target_chain_id)) with tarfile.open(tar_path, mode="w:gz") as ar: ar.add(work_dir_path, arcname=model_name) raise ModelRunError(msg)
def _model_run(self, main_domain_alignment, chain_alignments, context, main_target_sequence, require_resnum): model_name = model_storage.get_model_name(context.get_main_target_sequence(), context.target_species_id, main_domain_alignment, TemplateID(context.template_pdbid, context.main_target_chain_id)) work_dir_path = tempfile.mkdtemp() full_target_path = os.path.join(work_dir_path, 'target.fa') align_fasta_path = os.path.join(work_dir_path, 'align.fa') output_yob_path = os.path.join(work_dir_path, 'target.yob') error_path = os.path.join(work_dir_path, 'errorexit.txt') error_scene_path = os.path.join(work_dir_path, 'errorexit.sce') before_scene_path = os.path.join(work_dir_path, 'beforemodel.sce') write_fasta(full_target_path, {'target': context.get_main_target_sequence()}) try: context.yasara.CD(work_dir_path) context.yasara.SaveSce(before_scene_path) chain_ids_before_model = context.get_chain_ids() sequences_before_model = {chain_id: context.get_sequence(chain_id) for chain_id in chain_ids_before_model} self._write_model_alignment_fasta(context, chain_alignments, align_fasta_path) context.yasara.Processors(1) context.yasara.ExperimentHomologyModeling(templateobj=context.template_obj, alignfile=align_fasta_path, templates="1, sameseq = 1", alignments=1, termextension=0, oligostate=32, looplenmax=10, animation='fast', speed='fast', loopsamples=20, resultfile='target') context.yasara.Experiment("On") context.yasara.Wait("Expend") if os.path.isfile(error_path): self._handle_error_txt(error_path, work_dir_path, context, main_domain_alignment) elif os.path.isfile(error_scene_path): raise ModelRunError("yasara exited with an error") if not os.path.isfile(output_yob_path): chain_ids_after_failure = context.get_chain_ids() if chain_ids_before_model != chain_ids_after_failure: raise ModelRunError("During modeling, yasara changed the chains {} to {}" .format(chain_ids_before_model, chain_ids_after_failure)) for chain_id in chain_ids_before_model: sequence_after_failure = context.get_sequence(chain_id) if sequence_after_failure != sequences_before_model[chain_id]: raise ModelRunError("During modeling, yasara changed chain {} sequence {} to {}" .format(chain_id, sequences_before_model[chain_id], sequence_after_failure)) raise ModelRunError("yasara generated no output yob, check the console for further details") chain_ids_after_build = context.get_chain_ids() if context.main_target_chain_id not in chain_ids_after_build: raise ModelRunError(f"The chain {context.main_target_chain_id} is not in the final model output by yasara") _log.debug("after modeling {}".format([(chain_id, context.get_sequence(chain_id)) for chain_id in context.get_chain_ids()])) _log.debug("input target aligned sequence:\n{}".format(main_domain_alignment.get_target_sequence_without_insertions())) if not any([context.get_sequence(chain_id) == main_domain_alignment.get_target_sequence_without_insertions() for chain_id in context.get_chain_ids()]): if require_resnum is not None and not self._model_covers_residue(context, main_target_sequence, require_resnum): raise ModelRunError("yasara generated a model that doesn't match the input alignment") model_path = os.path.join(work_dir_path, 'target.pdb') context.yasara.SavePDB(context.template_obj, model_path) self._write_selected_targets(chain_alignments, os.path.join(work_dir_path, 'selected-targets.txt')) log_path = os.path.join(work_dir_path, 'model.log') ModelLogger.get_current().write(log_path) tar_path = model_storage.get_tar_path(context.get_main_target_sequence(), context.target_species_id, main_domain_alignment, TemplateID(context.template_pdbid, context.main_target_chain_id)) with tarfile.open(tar_path, mode="w:gz") as ar: ar.add(work_dir_path, arcname=model_name) return tar_path except RuntimeError as e: self._log_additional_error_info(e, chain_alignments, context) if os.path.isfile(error_path): self._handle_error_txt(error_path, work_dir_path, context, main_domain_alignment) elif os.path.isfile(error_scene_path): raise ModelRunError("yasara exited with an error") else: raise e finally: if os.path.isdir(work_dir_path): shutil.rmtree(work_dir_path)
def _model_run(self, main_domain_alignment, chain_alignments, context): model_name = model_storage.get_model_name( context.get_main_target_sequence(), context.target_species_id, main_domain_alignment, TemplateID(context.template_pdbid, context.main_target_chain_id)) work_dir_path = tempfile.mkdtemp() align_fasta_path = os.path.join(work_dir_path, 'align.fa') output_yob_path = os.path.join(work_dir_path, 'target.yob') error_path = os.path.join(work_dir_path, 'errorexit.txt') error_scene_path = os.path.join(work_dir_path, 'errorexit.sce') before_scene_path = os.path.join(work_dir_path, 'beforemodel.sce') try: context.yasara.CD(work_dir_path) context.yasara.SaveSce(before_scene_path) self._write_model_alignment_fasta(context, chain_alignments, align_fasta_path) context.yasara.Processors(1) context.yasara.ExperimentHomologyModeling( templateobj=context.template_obj, alignfile=align_fasta_path, templates="1, sameseq = 1", alignments=1, termextension=0, oligostate=32, looplenmax=10, animation='fast', speed='fast', loopsamples=20, resultfile='target') context.yasara.Experiment("On") context.yasara.Wait("Expend") if os.path.isfile(error_path): self._handle_error_txt(error_path, work_dir_path, context, main_domain_alignment) elif os.path.isfile(error_scene_path): raise ModelRunError("yasara exited with an error") if not os.path.isfile(output_yob_path): raise ModelRunError("yasara generated no output yob") model_path = os.path.join(work_dir_path, 'target.pdb') context.yasara.SavePDB(context.template_obj, model_path) self._write_selected_targets( chain_alignments, os.path.join(work_dir_path, 'selected-targets.txt')) tar_path = model_storage.get_tar_path( context.get_main_target_sequence(), context.target_species_id, main_domain_alignment, TemplateID(context.template_pdbid, context.main_target_chain_id)) with tarfile.open(tar_path, mode="w:gz") as ar: ar.add(work_dir_path, arcname=model_name) return tar_path except RuntimeError as e: self._log_additional_error_info(e, chain_alignments, context) if os.path.isfile(error_path): self._handle_error_txt(error_path, work_dir_path, context, main_domain_alignment) elif os.path.isfile(error_scene_path): raise ModelRunError("yasara exited with an error") else: raise e finally: if os.path.isdir(work_dir_path): shutil.rmtree(work_dir_path)
def delete_chain(self, chain_id): if self.template_obj is None: raise ModelRunError("template object is not set") self.yasara.DelMol('obj %i and protein and mol %s' % (self.template_obj, chain_id))