<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=Focus_alignment</id>
	<title>Focus alignment - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=Focus_alignment"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Focus_alignment&amp;action=history"/>
	<updated>2026-05-11T06:05:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Focus_alignment&amp;diff=5873&amp;oldid=prev</id>
		<title>Pyadmin: 1 revision</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Focus_alignment&amp;diff=5873&amp;oldid=prev"/>
		<updated>2014-03-28T01:46:43Z</updated>

		<summary type="html">&lt;p&gt;1 revision&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Overview =&lt;br /&gt;
&lt;br /&gt;
When aligning binding sites, it's useful to focus on a particular subset of atoms. However, alignments can go haywire when choosing non-contiguous subsets of atoms. To get around this we first perform a sequence alignment to establish an initial pairing. Then, the user-specified sub-selection is used to pare down the equivalenced atoms for pair-fitting. See the examples.&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
focus_alignment 1cll, 1ggz, 1cll and i. 4-20&lt;br /&gt;
&lt;br /&gt;
focus_alignment 2erk, 2b9f, 2erk and i. 50-75&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery widths=300 heights=240&amp;gt;&lt;br /&gt;
Image:fa.png|global alignment of 1cll and 1ggz&lt;br /&gt;
Image:fa2.png|focused alignment on residues 4-20 in 1cll on original atoms from global pairing; notice the white-colored residues are the focus of this alignment&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= The Code=&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# focus_alignment&lt;br /&gt;
#&lt;br /&gt;
# Author: Jason Vertrees&lt;br /&gt;
# Date  : 08-17-2011&lt;br /&gt;
#&lt;br /&gt;
import pymol&lt;br /&gt;
&lt;br /&gt;
# example usage&lt;br /&gt;
# focus_alignment 2erk, 2b9f, i. 50-70 and 2erk&lt;br /&gt;
# focus_alignment 1cll, 1ggz, 1cll and i. 4-20&lt;br /&gt;
&lt;br /&gt;
def focus_alignment(obj1, obj2, sel, debug=False):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    PARAMS&lt;br /&gt;
      obj1&lt;br /&gt;
          structure 1&lt;br /&gt;
&lt;br /&gt;
      obj2&lt;br /&gt;
          structure 2&lt;br /&gt;
&lt;br /&gt;
      sel&lt;br /&gt;
          the selection from either obj1 or&lt;br /&gt;
          obj2 to focus the pair_fitting on.&lt;br /&gt;
          When providing this selection, please&lt;br /&gt;
          make sure you also specify selected&lt;br /&gt;
          atoms from ONE object.&lt;br /&gt;
&lt;br /&gt;
    NOTES&lt;br /&gt;
    &lt;br /&gt;
    This function will first align obj1 and obj2 using&lt;br /&gt;
    a sequence alignment. This creates a mapping of&lt;br /&gt;
    residues from obj1 to obj2. Next, the selection, sel,&lt;br /&gt;
    is used to find only those atoms in the alignment and&lt;br /&gt;
    in sel. These atoms are paired with their mapped&lt;br /&gt;
    atoms from the alignment in the other object. These&lt;br /&gt;
    two subsets of atoms are then pair_fit to give&lt;br /&gt;
    an optimal sub-alignment.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    aln = &amp;quot;aln&amp;quot;&lt;br /&gt;
    _sel = &amp;quot;__sel&amp;quot;&lt;br /&gt;
    ssel_model = &amp;quot;&amp;quot;&lt;br /&gt;
    a1, a2, a_target, modelA, modelB, sel_model = [],[],[],[],[],[]&lt;br /&gt;
    obj1, obj2 = &amp;quot;poly and &amp;quot; + obj1,  &amp;quot;poly and &amp;quot; + obj2&lt;br /&gt;
&lt;br /&gt;
    # space dictionary for iterate&lt;br /&gt;
    space = { 'a1' : a1, &lt;br /&gt;
              'a2' : a2,&lt;br /&gt;
              'a_target' : a_target, &lt;br /&gt;
              'sel_model' : sel_model,&lt;br /&gt;
              'modelA' : modelA,&lt;br /&gt;
              'modelB' : modelB }&lt;br /&gt;
&lt;br /&gt;
    # initial unfocused alignment&lt;br /&gt;
    cmd.align(obj1, obj2, cycles=0, object=aln)&lt;br /&gt;
&lt;br /&gt;
    # record the initial indices&lt;br /&gt;
    s = &amp;quot;n. CA and (%s and %s)&amp;quot;&lt;br /&gt;
    cmd.iterate(s % (obj1,aln), &amp;quot;a1.append(index)&amp;quot;,space=space)&lt;br /&gt;
    cmd.iterate(s % (obj2,aln), &amp;quot;a2.append(index)&amp;quot;,space=space)&lt;br /&gt;
&lt;br /&gt;
    if debug:&lt;br /&gt;
        print &amp;quot;# [debug] num atom in aln1 = &amp;quot;, len(a1)&lt;br /&gt;
        print &amp;quot;# [debug] num atom in aln2 = &amp;quot;, len(a2)&lt;br /&gt;
&lt;br /&gt;
    # determine who owns the focused selection and&lt;br /&gt;
    # get canonical object names&lt;br /&gt;
    cmd.iterate(&amp;quot;first %s&amp;quot; % sel, &amp;quot;sel_model.append(model)&amp;quot;,space=space)&lt;br /&gt;
    cmd.iterate(&amp;quot;first %s&amp;quot; % obj1, &amp;quot;modelA.append(model)&amp;quot;,space=space)&lt;br /&gt;
    cmd.iterate(&amp;quot;first %s&amp;quot; % obj2, &amp;quot;modelB.append(model)&amp;quot;,space=space)&lt;br /&gt;
    ssel_model = sel_model[0]&lt;br /&gt;
&lt;br /&gt;
    if debug:&lt;br /&gt;
        print &amp;quot;# [debug] selection is in object %s&amp;quot; % ssel_model&lt;br /&gt;
&lt;br /&gt;
    # focus the target selection&lt;br /&gt;
    cmd.iterate(sel + &amp;quot; and n. CA&amp;quot;, &amp;quot;a_target.append(index)&amp;quot;,space=space)&lt;br /&gt;
&lt;br /&gt;
    if debug:&lt;br /&gt;
        print &amp;quot;# [debug] a_target has %d members.&amp;quot; % len(a_target)&lt;br /&gt;
&lt;br /&gt;
    # select the correct object from which to index&lt;br /&gt;
    target_list = None&lt;br /&gt;
    if ssel_model==modelA[0]:&lt;br /&gt;
        target_list = a1&lt;br /&gt;
    elif sel_model==modelB[0]:&lt;br /&gt;
        target_list = a2&lt;br /&gt;
    else:&lt;br /&gt;
        print &amp;quot;# error: selection on which to focus was not found&amp;quot;&lt;br /&gt;
        print &amp;quot;# error: in either object passed in.&amp;quot;&lt;br /&gt;
        print sel_model&lt;br /&gt;
        print modelA&lt;br /&gt;
        print modelB&lt;br /&gt;
        return False&lt;br /&gt;
&lt;br /&gt;
    id1, id2 = [], []&lt;br /&gt;
    for x in a_target:&lt;br /&gt;
        try:&lt;br /&gt;
            idx = target_list.index(x)&lt;br /&gt;
            if debug:&lt;br /&gt;
                print &amp;quot;Current index: %d&amp;quot; % idx&lt;br /&gt;
            id1.append( str(a1[idx]) )&lt;br /&gt;
            id2.append( str(a2[idx]) )&lt;br /&gt;
        except:&lt;br /&gt;
            pass&lt;br /&gt;
&lt;br /&gt;
    if debug: &lt;br /&gt;
        print &amp;quot;# [debug] id1 = %s&amp;quot; % id1&lt;br /&gt;
        print &amp;quot;# [debug] id2 = %s&amp;quot; % id2&lt;br /&gt;
        &lt;br /&gt;
    sel1 = &amp;quot;+&amp;quot;.join(id1)&lt;br /&gt;
    sel2 = &amp;quot;+&amp;quot;.join(id2)&lt;br /&gt;
    &lt;br /&gt;
    if debug:&lt;br /&gt;
        print &amp;quot;# [debug] sel1 = %s&amp;quot; % sel1&lt;br /&gt;
&lt;br /&gt;
    cmd.pair_fit(obj1 + &amp;quot; and aln and index &amp;quot; + sel1,&lt;br /&gt;
                 obj2 + &amp;quot; and aln and index &amp;quot; + sel2)&lt;br /&gt;
&lt;br /&gt;
cmd.extend(&amp;quot;focus_alignment&amp;quot;, focus_alignment)&lt;br /&gt;
print &amp;quot; A new function 'focus_alignment' was added to PyMOL.&amp;quot;&lt;br /&gt;
print &amp;quot; Type 'help focus_alignment' if you need help.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pyadmin</name></author>
	</entry>
</feed>