I realised the script I posted previously to delete a chain doesn't take 
account of insertion codes etc.

The attached script hopefully fixes that and adds a couple of other widgets 
that I find useful into a "Custom" menu (when placed in the ~/.coot-preferences 
 directory).

Oliver.

#Deletes active chain based on residue nearest to the pointer.
def delete_chain():
  def is_polymer(mol_id,ch_id):
        a=is_protein_chain_p(mol_id,"%s"%(ch_id))
        b=is_nucleotide_chain_p(mol_id,"%s"%(ch_id))
        if (a==1) or (b==1):
                result=1
        else:
                result=0
        return result
  def first_residue(mol_id,ch_id):
          result=seqnum_from_serial_number(mol_id,"%s"%(ch_id),0)
          return result
  def last_residue(mol_id,ch_id):
          n=chain_n_residues(ch_id,mol_id)-1
          result=seqnum_from_serial_number(mol_id,"%s"%(ch_id),n)
          return result
  active_chain_id=active_residue()[1]
  active_mol_id=active_residue()[0]
  while (is_polymer(active_mol_id,active_chain_id)==1) or (is_solvent_chain_p(active_mol_id,active_chain_id)!=-1):
    first_res=first_residue(active_mol_id,active_chain_id)
    last_res=last_residue(active_mol_id,active_chain_id)
    delete_residue_range(active_mol_id,active_chain_id,first_res,last_res)
#Add menu item "Delete active chain"  
menu=coot_menubar_menu("Custom")
add_simple_coot_menu_menuitem(menu,"Delete active chain", lambda func: delete_chain())

#Switches all molecules to CA symmetry
add_simple_coot_menu_menuitem(
       menu, "All Molecules use \"C-alpha\" Symmetry",
       lambda func: map(lambda imol: valid_model_molecule_qm(imol) and
                         symmetry_as_calphas(imol, 1),
                         molecule_number_list()))

#Toggles symmetry on/off
add_simple_coot_menu_menuitem(menu, "Toggle Symmetry", lambda func: set_show_symmetry_master(not get_show_symmetry()))

#Fits each chain to map
def rigid_fit_all_chains():
  mol_id=active_residue()[0]
  turn_off_backup(mol_id)
  def is_polymer(mol_id,ch_id):
        a=is_protein_chain_p(mol_id,"%s"%(ch_id))
        b=is_nucleotide_chain_p(mol_id,"%s"%(ch_id))
        if (a==1) or (b==1):
                result=1
        else:
                result=0
        return result
  for ch_id in chain_ids(mol_id): #Rigid body refine each chain
    if is_polymer(mol_id,ch_id)==1:
      rigid_body_refine_by_atom_selection(mol_id, "//%s//"%(ch_id))
      accept_regularizement()
#Add menu item to "Custom"
add_simple_coot_menu_menuitem(menu, "Fit all chains to map", lambda func: rigid_fit_all_chains())

#Fits active chain to map
def rigid_fit_active_chain():
  mol_id=active_residue()[0]
  ch_id=active_residue()[1]
  rigid_body_refine_by_atom_selection(mol_id, "//%s//"%(ch_id))
#Add menu item to "Custom"
add_simple_coot_menu_menuitem(menu, "Fit current chain to map", lambda func: rigid_fit_active_chain())

#Sets "Backrub" rotamers as default (best at low res)
set_rotamer_search_mode("ROTAMERSEARCHLOWRES")


Reply via email to