def run_script(session): from chimerax.atomic import selected_residues from chimerax.build_structure import modify_atom from chimerax.build_structure.mod import ParamError from chimerax.core.errors import UserError sel = selected_residues(session) if len(sel) != 1 or sel[0].name not in ('ASP', 'GLU'): raise UserError('Please select a single ASP or GLU residue!') sel = sel[0] if sel.name == 'ASP': pos = 'D' else: pos = 'E' o_atom = sel.find_atom(f'O{pos}2') other_o = sel.find_atom(f'O{pos}1') if o_atom is None or other_o is None: raise UserError( 'Selected acid sidechain is missing one or both of its oxygen atoms!' ) if len(o_atom.neighbors) != 1 or len(other_o.neighbors) != 1: raise UserError( 'Selected acid sidechain already has a substituent on its carboxyl group!' ) new_h = modify_atom(o_atom, o_atom.element, 2, connect_back=False, res_name=sel.name)[1] new_h.color = [255, 255, 255, 255]
def _sel_res_type(self): from chimerax.atomic import selected_residues sel_residues = selected_residues(self.session) sel_res_types = set([r.name for r in sel_residues]) if len(sel_res_types) == 1: return self.rot_lib.map_res_name(sel_res_types.pop(), exemplar=sel_residues[0]) return None
def run_script(session): from chimerax.atomic import selected_residues models = selected_residues(session).unique_structures for m in models: atoms_with_alt_locs = m.atoms[m.atoms.num_alt_locs > 0] m.delete_alt_locs() atoms_with_alt_locs.occupancies = 1 session.logger.info( ('Removed all altlocs in #{}.' 'Occupancies for all affected atoms have been reset to 1.').format( ', '.join(m.id_string for m in models)))
def run_script(session): from chimerax.atomic import selected_residues from chimerax.isolde.atomic.building.build_utils import create_disulfide sel = selected_residues(session) if len(sel) != 2 or not all(sel.names == 'CYS'): from chimerax.core.errors import UserError raise UserError('Please select two cysteine residues!') if sel[0] not in sel[1].neighbors: create_disulfide(*sel) session.logger.info('Created disulphide bond between {}.'.format( ' and '.join([ '{}{}{}'.format(c.chain_id, c.number, c.insertion_code) for c in sel ])))
def run_script(session): sel = selected_residues(session) if not len(sel): raise UserError('No atoms selected!') sel = sel[sel.polymer_types == Residue.PT_AMINO] if not len(sel): raise UserError('No protein selected!') us = sel.unique_structures if len(us) != 1: raise UserError('Selection must be from a single model!') m = sel.unique_structures cids = sel.unique_chain_ids for cid in cids: chain = m.chains[m.chains.chain_ids == cid][0] last_res = chain.residues[-1] add_oxt(session, last_res)
def run_script(session): from chimerax.atomic import selected_residues, selected_bonds, Residues sel = selected_residues(session) if len(sel) != 2 or not all(sel.names=='CYS'): b = selected_bonds(session) if len(b) == 1: b = b[0] sel = Residues([a.residue for a in b.atoms]) if len(sel) != 2 or not all(sel.names=='CYS'): from chimerax.core.errors import UserError raise UserError('Please select exactly two cysteine residues!') from chimerax.isolde.atomic.building.build_utils import break_disulfide break_disulfide(*sel) session.logger.info('Broke disulphide bond between {}.'.format( ' and '.join(['{}{}{}'.format(c.chain_id, c.number, c.insertion_code) for c in sel]) ))
def run_script(session): from chimerax.atomic import selected_residues from chimerax.core.errors import UserError from chimerax.atomic import next_chain_id #from chimerax.isolde.atomic.building.merge import merge_fragment #from chimerax.geometry import Place session.logger.info('ISOLDE: merge models') if not hasattr(session, 'isolde'): raise UserError('ISOLDE must be running') target = session.isolde.selected_model if target is None: raise UserError('ISOLDE has no model initialised!') selres = selected_residues(session) us = selres.unique_structures others = [s for s in us if s != target] if not len(others): from chimerax.core.errors import UserError raise UserError('Must have at least two atomic models selected!') session.logger.info( f'Merging models {",".join([f"#{m.id_string}" for m in others])} into #{target.id_string}.' ) seen_ids = set(target.residues.unique_chain_ids) for s in others: chain_id_mapping = {} chain_ids = sorted(s.residues.unique_chain_ids) for cid in chain_ids: if cid in seen_ids: new_id = next_chain_id(cid) while new_id in seen_ids or new_id in chain_ids: new_id = next_chain_id(new_id) session.logger.info( f"Remapping chain ID {cid} in #{s.id_string} to {new_id}") chain_id_mapping[cid] = new_id seen_ids.add(new_id) else: seen_ids.add(cid) target.combine(s, chain_id_mapping, target.scene_position)
def launch_rotamers(self): from chimerax.atomic import selected_residues sel_residues = selected_residues(self.session) if not sel_residues: raise UserError("No residues selected") num_sel = len(sel_residues) if num_sel > 10: from chimerax.ui.ask import ask confirm = ask( self.session, "You have %d residues selected, which could bring up %d" " rotamer dialogs\nContinue?" % (num_sel, num_sel), title="Many Rotamer Dialogs") if confirm == "no": return res_type = self.res_type_option.value from chimerax.core.commands import run, StringArg from chimerax.rotamers import NoResidueRotamersError lib_name = StringArg.unparse(self.rot_lib_option.value) try: run(self.session, "swapaa interactive sel %s rotLib %s" % (res_type, lib_name)) except NoResidueRotamersError: run(self.session, "swapaa sel %s rotLib %s" % (res_type, lib_name))
def criteria(self, session): from chimerax.atomic import selected_residues return len([ r for r in selected_residues(session) if r.polymer_type == r.PT_AMINO ]) == 1