In case it is useful to anyone else, the following key binding seems to work 
okay for this purpose:

rotamer_number=1
def cycle_rotamers():
  global rotamer_number
  mol_id=active_residue()[0]
  ch_id=active_residue()[1]
  res_here=active_residue()[2]
  ins_code=""
  alt_conf=""
  n_rots=n_rotamers(mol_id, ch_id, res_here, ins_code)
  turn_off_backup(mol_id)
  if rotamer_number>n_rots:
    rotamer_number=1
    
set_residue_to_rotamer_number(mol_id,ch_id,res_here,ins_code,alt_conf,rotamer_number)
  elif rotamer_number==n_rots:
    set_residue_to_rotamer_number(mol_id,ch_id,res_here,ins_code,alt_conf,1)
    rotamer_number=1
  else:
    
set_residue_to_rotamer_number(mol_id,ch_id,res_here,ins_code,alt_conf,rotamer_number)
    rotamer_number=rotamer_number+1
  turn_on_backup(mol_id)
add_key_binding("Cycle rotamers","R",
lambda: cycle_rotamers())
> On Nov 4, 2015, at 9:08 AM, Paul Emsley <[email protected]> wrote:
> 
> On 04/11/15 13:41, Clarke, Oliver wrote:
>> 
>> With  regards to set_residue_to_rotamer_number, it seems to take six 
>> arguments (I guess there is an “alt_conf” after “ins_code”) but otherwise 
>> works fine.
> 
> You are right.
> 
>> 
>> One problem though - it returns the same value (1) regardless, whether that 
>> rotamer number exists for that residue type (and hence the rotamer switch 
>> was successful) or not. This makes it a little bit of a pain to write a 
>> shortcut to cycle through rotamers for the active residue, unless there is 
>> an easy way that I’m missing? Would it be possible to have this function 
>> return -1 on failure?
> 
> It returns 0 if it didn't update the atoms for some reason.
> 
>> That way it’s easy to catch when one has reached the end of the available 
>> list of rotamers and go back to the first one.
>> 
> 
> Use n_rotamers(imol, chain_id, res_no, ins_code) to know the number of 
> rotamers for a given residue.
> 
> Paul
> 

Reply via email to