The last function I posted didn’t work optimally - when merge_molecules is called, imol_daughter is undisplayed, but imol_ref is not updated straight away (which is a little confusing as it looks like you’ve deleted a mol rather than merged) - adding a toggle_display step fixes that, as below:
def merge_fragments():
def merge_2_fragments(res1,res2):
mol_daughter=[res2[1]]
mol_ref=res1[1]
merge_molecules(mol_daughter,mol_ref)
toggle_display_mol(mol_ref)
toggle_display_mol(mol_ref)
user_defined_click(2,merge_2_fragments)
add_simple_coot_menu_menuitem(menu, "Merge two mols (click two)", lambda func: merge_fragments())
On Apr 3, 2014, at 7:49 AM, Oliver Clarke <[log in to unmask]> wrote:
> I knew that I was missing something obvious. Thanks Paul. Although as it turns out, in Python the arguments are switched around (the first one is a list and the second one is imol_ref).
>
> Thanks!
>
> Then, for the record, the function that I wanted to write goes something like this:
>
> def merge_fragments():
> def merge_2_fragments(res1,res2):
> mol_daughter=[res2[1]]
> mol_ref=res1[1]
> merge_molecules(mol_daughter,mol_ref)
> user_defined_click(2,merge_2_fragments)
> add_simple_coot_menu_menuitem(menu, "Merge two fragments (click two fragments)", lambda func: merge_fragments())
>
> Oliver.
> On Apr 3, 2014, at 5:04 AM, Paul Emsley <[log in to unmask]> wrote:
>
>> On 03/04/14 04:45, Oliver Clarke wrote:
>>> Hi all,
>>>
>>> Is the functionality of ‘Calculate-->Merge Molecules’ available from the scripting interface?
>>
>> Yes.
>>>
>>> I couldn’t find it in the manual. There is a function named merge_molecules, but I don’t know what arguments it takes and it does not do what I would expect - I’d like it to take two mol_ids and merge the second one with the first, but that does not seem to be the case.
>>
>> Recall that you can merge many molecules with a "first" molecule, then you're golden.
>>
>> merge_molecules(imol_ref, [imol_daughter])
>>
>> Although not written in python, I believe that the documentation hints that the second argument is a list of molecule numbers.
>>
>>>
>>> I’d like this function so I can write a little shortcut that will allow me to click on two fragments and join them, rather than having to scroll through the list of mol_ids of various newly placed helices etc.
>>>
>>> I guess I could use replace_fragment if I add a dummy atom to the first molecule and then replace it with the second -
>>
>> Yikes! :-)
>>
>> HTH,
>>
>> Paul.
>>
>
|