def run_bond(self, *args): # TODO: switch to `bond sel` in 1.2 sel = selected_atoms(self.session) halfbond = self.bond_halfbond.checkState() == Qt.Checked self.settings.bond_halfbond = halfbond if not halfbond: color = self.bond_color.get_color() color = tuple(x / 255. for x in color) self.settings.bond_color = color radius = self.bond_radius.value() self.settings.bond_radius = radius for b in selected_bonds(self.session): b.halfbond = halfbond if not halfbond: b.color = np.array([int(x * 255) for x in color]) b.radius = radius for i, a1 in enumerate(sel): for a2 in sel[:i]: if a1.structure is a2.structure and a2 not in a1.neighbors: new_bond = a1.structure.new_bond(a1, a2) new_bond.halfbond = halfbond if not halfbond: new_bond.color = np.array( [int(x * 255) for x in color]) new_bond.radius = radius
def selected_edges(session): from chimerax.atomic import selected_bonds bonds = selected_bonds(session) from numpy import array, bool cbonds = bonds.filter(array([hasattr(b, 'polygon') for b in bonds], bool)) return cbonds
def run_script(session): from chimerax.atomic import selected_bonds sel_bonds = selected_bonds(session) if len(sel_bonds) != 1: from chimerax.core.errors import UserError raise UserError('Select exactly one bond first!') sel_bonds.delete()
def change_bond_length(self, *args): dist = self.bond_distance.value() atom_pairs = [] sel = selected_atoms(self.session) if len(sel) == 2 and sel[0].structure is sel[1].structure: atom_pairs.append(sel) for bond in selected_bonds(self.session): if not all(atom in sel for atom in bond.atoms): atom_pairs.append(bond.atoms) for bond in selected_pseudobonds(self.session): if not all(atom in sel for atom in bond.atoms): atom_pairs.append(bond.atoms) for pair in atom_pairs: atom1, atom2 = pair frag1 = get_fragment(atom1, stop=atom2, max_len=atom1.structure.num_atoms) frag2 = get_fragment(atom2, stop=atom1, max_len=atom1.structure.num_atoms) v = atom2.coord - atom1.coord cur_dist = np.linalg.norm(v) change = dist - cur_dist if self.move_fragment.currentText() == "both": change = 0.5 * change frag1.coords -= change * v / cur_dist frag2.coords += change * v / cur_dist elif self.move_fragment.currentText() == "smaller": if len(frag1) < len(frag2) or (len(frag1) == len(frag2) and sum(frag1.elements.masses) < sum(frag2.elements.masses)): frag1.coords -= change * v / cur_dist else: frag2.coords += change * v / cur_dist elif self.move_fragment.currentText() == "larger": if len(frag1) > len(frag2) or (len(frag1) == len(frag2) and sum(frag1.elements.masses) > sum(frag2.elements.masses)): frag1.coords -= change * v / cur_dist else: frag2.coords += change * v / cur_dist
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 all_connected_selector(session, models, results): """select all atoms connected to the current selection""" # TODO: right mouse mode for this cur_sel = selected_atoms(session) bond_sel = selected_bonds(session) for bond in bond_sel: cur_sel = cur_sel.merge(Atoms(bond.atoms)) atoms = Atoms() for atom in cur_sel: if atom in atoms: continue elif atom.structure not in models: continue connected_atoms = get_fragment(atom, max_len=len(atom.structure.atoms)) atoms = atoms.merge(connected_atoms) results.add_atoms(atoms)
def set_bonds(self, *args): bonds = selected_bonds(self.session) if len(bonds) == 0: self.session.logger.error("no bonds selected") return models = [bond.structure for bond in bonds] if any(models.count(m) > 1 for m in models): self.session.logger.error( "multiple bonds selected on the same structure") return self.bonds = { model: (bond.atoms[0].coord - bond.atoms[1].coord) for model, bond in zip(models, bonds) } self.bond_centers = { model: bond.atoms[1].coord for model, bond in zip(models, bonds) }
def intersect_selection(objects, session, undo_state, full_residues = False): atoms, bonds, pbonds, models = _atoms_bonds_models(objects, full_residues = full_residues) from chimerax import atomic selatoms = atomic.selected_atoms(session) subatoms = selatoms - atoms selbonds = atomic.selected_bonds(session) subbonds = selbonds - bonds selpbonds = atomic.selected_pseudobonds(session) subpbonds = selpbonds - pbonds from chimerax.atomic import Structure, PseudobondGroup selmodels = set(m for m in session.selection.models() if not isinstance(m, (Structure, PseudobondGroup))) submodels = selmodels.difference(models) undo_state.add(subatoms, "selected", subatoms.selected, False) undo_state.add(subbonds, "selected", subbonds.selected, False) undo_state.add(subpbonds, "selected", subpbonds.selected, False) subatoms.selected = False subbonds.selected = False subpbonds.selected = False for m in submodels: undo_state.add(m, "selected", m.selected, False) m.selected = False
def selected_links(session): from chimerax import atomic bonds = atomic.selected_bonds(session) mask = [isinstance(b.structure, MarkerSet) for b in bonds] return bonds.filter(mask)
def _ms_del_cb(self, *args): from chimerax.atomic import selected_atoms, selected_bonds if not selected_atoms(self.session) and not selected_bonds(self.session): raise UserError("No atoms or bonds selected") run(self.session, "del atoms sel; del bonds sel")