<?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=AutoMultiFit</id>
	<title>AutoMultiFit - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=AutoMultiFit"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=AutoMultiFit&amp;action=history"/>
	<updated>2026-09-02T23:10:43Z</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=AutoMultiFit&amp;diff=4219&amp;oldid=prev</id>
		<title>Pyadmin: 3 revisions</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=AutoMultiFit&amp;diff=4219&amp;oldid=prev"/>
		<updated>2014-03-28T01:31:03Z</updated>

		<summary type="html">&lt;p&gt;3 revisions&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= OVERVIEW =&lt;br /&gt;
[[AutoMultiFit]] will fit all given chain(s) in all given state(s) to any other given chain(s) in any other given state(s) for some given selection within a homo-oligomer. So, if you have an MD trajectory or NMR ensemble of a tertramer, for example, over 20 states this program could calculate the RMS values for residues 10-30 in chain A's state 17, against all of chain C. Or all states in all chains against each other.&lt;br /&gt;
&lt;br /&gt;
See the notes in the code for usage.&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;
#&lt;br /&gt;
# autoMultiFit.py -- Given a homo-oligomer in N-states, fit any combination of chains across states&lt;br /&gt;
#&lt;br /&gt;
# AUTHOR: Jason Vertrees&lt;br /&gt;
# DATE  : 2009-11-02&lt;br /&gt;
#&lt;br /&gt;
import pymol&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
&lt;br /&gt;
def autoMultiFit(sel, fromChain=&amp;quot;*&amp;quot;, fromState=&amp;quot;*&amp;quot;, toChain=&amp;quot;*&amp;quot;, toState=&amp;quot;*&amp;quot;, verbose=None):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    FUNCTION&lt;br /&gt;
      Given a homo-oligomer in N-states (say from MD), fit any&lt;br /&gt;
      combination of chains/selections across states. See Usage, Examples and Notes.&lt;br /&gt;
&lt;br /&gt;
    USAGE&lt;br /&gt;
      autoMultiFit sel, [fromChain[, fromState[, toChain[, toState[, verbose ]]]]]&lt;br /&gt;
&lt;br /&gt;
      sel&lt;br /&gt;
        The selection that must exist in all chains (what you're fitting)&lt;br /&gt;
&lt;br /&gt;
      fromChain&lt;br /&gt;
        Fit from this chain, leave blank or use '*' for all chains;&lt;br /&gt;
&lt;br /&gt;
      fromState&lt;br /&gt;
        Fit from this state, leave blank or use '*' for all states;&lt;br /&gt;
&lt;br /&gt;
      toChain&lt;br /&gt;
        Fit to this chain only, use '*' or leave blank for all chains;&lt;br /&gt;
&lt;br /&gt;
      toState&lt;br /&gt;
        Fit to this state only, use '*' or leave blank for all states&lt;br /&gt;
&lt;br /&gt;
      verbose&lt;br /&gt;
        If turned on, this prints the fit for all pairs; this could be VERY slow.&lt;br /&gt;
&lt;br /&gt;
    RETURNS&lt;br /&gt;
      A hash of hashes of hashes of hashes. :-)  Access the results like this:&lt;br /&gt;
      &lt;br /&gt;
      fitValues = autoMultiFit( mySelection )&lt;br /&gt;
      #fitValues[fromChain][fromState][toChain][toState]&lt;br /&gt;
      # to get the result of the fit from chain A, state 4 to chain C, state 17 type,&lt;br /&gt;
      fitValues['A']['4']['C']['17']&lt;br /&gt;
      &lt;br /&gt;
    EXAMPLES&lt;br /&gt;
      * Fit ALL chains to each other across ALL STATES for PDB 2kb1&lt;br /&gt;
      autoMultiFit 2kb1&lt;br /&gt;
&lt;br /&gt;
      * Fit chain A's residue 22-34 against all states&lt;br /&gt;
      autoMutliFit 2kb1 and i. 22-34, fromChain=A&lt;br /&gt;
&lt;br /&gt;
      * Fit chain A, B and C's residues 8-17, states 10 and 11, against chain D's state 8&lt;br /&gt;
      myVals = autoMultiFit(&amp;quot;2kb1 and i. 8-17&amp;quot;, fromChain=&amp;quot;a b c&amp;quot;, fromState=&amp;quot;10 11&amp;quot;, toChain=&amp;quot;d&amp;quot;, toState=8)&lt;br /&gt;
      myVals['B']['10']['D']['8']&lt;br /&gt;
&lt;br /&gt;
      NOTES&lt;br /&gt;
        * The return value uses UPPERCASE and STRINGS for ALL hash keys, so if you used chain 'a' it will&lt;br /&gt;
          be 'A' in the map; if you used 'chainXX' it will be 'CHAINXX' in the map.&lt;br /&gt;
        * Continuing from the above note, all statese are accessible by their strings, so '17' gets state&lt;br /&gt;
          17 from the hash, not just the number 17.&lt;br /&gt;
        * This can be very slow: it's O( nFromChains * nFromStates * nToChains * nToStates )&lt;br /&gt;
        * fromChain, toChain, fromStates and toStates can all be single values, like &amp;quot;8&amp;quot;, they can be a SPACE&lt;br /&gt;
          separated list of values, like &amp;quot;2 4 5&amp;quot;, or they can be &amp;quot;*&amp;quot; which means ALL.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    fromChain = processChain(fromChain,sel)&lt;br /&gt;
    fromState = processState(fromState, sel)&lt;br /&gt;
    toChain   = processChain(toChain, sel)&lt;br /&gt;
    toState   = processState(toState, sel)&lt;br /&gt;
&lt;br /&gt;
    res = {}&lt;br /&gt;
&lt;br /&gt;
    for frC in fromChain:&lt;br /&gt;
        res[frC] = {}&lt;br /&gt;
        for frS in fromState:&lt;br /&gt;
            res[frC][str(frS)] = {}&lt;br /&gt;
            cmd.create( &amp;quot;__tmpA&amp;quot;, sel + &amp;quot; and c. &amp;quot; + frC, frS, 1 )&lt;br /&gt;
            for toC in toChain:&lt;br /&gt;
                res[frC][str(frS)][toC] = {}&lt;br /&gt;
                for toS in toState:&lt;br /&gt;
                    cmd.create(&amp;quot;__tmpB&amp;quot;, sel + &amp;quot; and c. &amp;quot; + toC, toS, 1 )&lt;br /&gt;
                    curVal = cmd.pair_fit( &amp;quot;__tmpA&amp;quot;, &amp;quot;__tmpB&amp;quot;, quiet=1 )&lt;br /&gt;
                    res[frC][str(frS)][toC][str(toS)] = curVal&lt;br /&gt;
                    if verbose!=None:&lt;br /&gt;
                        print &amp;quot;Pair Fitted: from (chain: %s, state: %s) to (chain: %s, states %s) with RMSD %s&amp;quot; % (frC, frS, toC, toS, curVal)&lt;br /&gt;
                    cmd.delete(&amp;quot;__tmpB&amp;quot;)&lt;br /&gt;
            cmd.delete(&amp;quot;__tmpA&amp;quot;)&lt;br /&gt;
    return res&lt;br /&gt;
&lt;br /&gt;
def processChain(ch, sel):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Turn a string-based space separated list into an array of chains&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if ch == &amp;quot;*&amp;quot;:&lt;br /&gt;
        # just in case&lt;br /&gt;
        return map(str.upper, cmd.get_chains(sel))&lt;br /&gt;
    else:&lt;br /&gt;
        return map(str.upper, processTextList(ch))&lt;br /&gt;
&lt;br /&gt;
def processState(st, sel):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Tur a string-based space separated list into an array of states&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if st == &amp;quot;*&amp;quot;:&lt;br /&gt;
        # assumes that if there is a state X, there is a state, X-1&lt;br /&gt;
        return range(cmd.count_states(sel))&lt;br /&gt;
    else:&lt;br /&gt;
        return map(int, processTextList(st))&lt;br /&gt;
&lt;br /&gt;
def processTextList(t):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; make a space-separated list into a real Python list, eg.&lt;br /&gt;
    input: a b c d&lt;br /&gt;
    output: [ 'a', 'b', 'c', 'd' ]&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    t = str(t).split()&lt;br /&gt;
    return t&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    assert processTextList( &amp;quot;a b c d&amp;quot; ) == ['a', 'b', 'c', 'd']&lt;br /&gt;
    assert processTextList( &amp;quot; 1 45 s s s s j p k&amp;quot;) == [ '1', '45', 's', 's', 's', 's', 'j', 'p', 'k' ]&lt;br /&gt;
&lt;br /&gt;
    assert processChain( &amp;quot;a b c dd&amp;quot;, &amp;quot;blankSel&amp;quot; ) == [&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;dd&amp;quot;]&lt;br /&gt;
    assert processState( &amp;quot;1 2 3 44 5&amp;quot;, &amp;quot;blankSel&amp;quot; ) == [ 1, 2, 3, 44, 5 ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cmd.extend( &amp;quot;autoMultiFit&amp;quot;, autoMultiFit )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]]&lt;br /&gt;
[[Category:Structural_Biology_Scripts]]&lt;/div&gt;</summary>
		<author><name>Pyadmin</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=AutoMultiFit&amp;diff=4217&amp;oldid=prev</id>
		<title>Newacct at 08:01, 27 November 2009</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=AutoMultiFit&amp;diff=4217&amp;oldid=prev"/>
		<updated>2009-11-27T08:01:26Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= OVERVIEW =&lt;br /&gt;
[[AutoMultiFit]] will fit all given chain(s) in all given state(s) to any other given chain(s) in any other given state(s) for some given selection within a homo-oligomer. So, if you have an MD trajectory or NMR ensemble of a tertramer, for example, over 20 states this program could calculate the RMS values for residues 10-30 in chain A's state 17, against all of chain C. Or all states in all chains against each other.&lt;br /&gt;
&lt;br /&gt;
See the notes in the code for usage.&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;
#&lt;br /&gt;
# autoMultiFit.py -- Given a homo-oligomer in N-states, fit any combination of chains across states&lt;br /&gt;
#&lt;br /&gt;
# AUTHOR: Jason Vertrees&lt;br /&gt;
# DATE  : 2009-11-02&lt;br /&gt;
#&lt;br /&gt;
import pymol&lt;br /&gt;
from pymol import cmd&lt;br /&gt;
&lt;br /&gt;
def autoMultiFit(sel, fromChain=&amp;quot;*&amp;quot;, fromState=&amp;quot;*&amp;quot;, toChain=&amp;quot;*&amp;quot;, toState=&amp;quot;*&amp;quot;, verbose=None):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    FUNCTION&lt;br /&gt;
      Given a homo-oligomer in N-states (say from MD), fit any&lt;br /&gt;
      combination of chains/selections across states. See Usage, Examples and Notes.&lt;br /&gt;
&lt;br /&gt;
    USAGE&lt;br /&gt;
      autoMultiFit sel, [fromChain[, fromState[, toChain[, toState[, verbose ]]]]]&lt;br /&gt;
&lt;br /&gt;
      sel&lt;br /&gt;
        The selection that must exist in all chains (what you're fitting)&lt;br /&gt;
&lt;br /&gt;
      fromChain&lt;br /&gt;
        Fit from this chain, leave blank or use '*' for all chains;&lt;br /&gt;
&lt;br /&gt;
      fromState&lt;br /&gt;
        Fit from this state, leave blank or use '*' for all states;&lt;br /&gt;
&lt;br /&gt;
      toChain&lt;br /&gt;
        Fit to this chain only, use '*' or leave blank for all chains;&lt;br /&gt;
&lt;br /&gt;
      toState&lt;br /&gt;
        Fit to this state only, use '*' or leave blank for all states&lt;br /&gt;
&lt;br /&gt;
      verbose&lt;br /&gt;
        If turned on, this prints the fit for all pairs; this could be VERY slow.&lt;br /&gt;
&lt;br /&gt;
    RETURNS&lt;br /&gt;
      A hash of hashes of hashes of hashes. :-)  Access the results like this:&lt;br /&gt;
      &lt;br /&gt;
      fitValues = autoMultiFit( mySelection )&lt;br /&gt;
      #fitValues[fromChain][fromState][toChain][toState]&lt;br /&gt;
      # to get the result of the fit from chain A, state 4 to chain C, state 17 type,&lt;br /&gt;
      fitValues['A']['4']['C']['17']&lt;br /&gt;
      &lt;br /&gt;
    EXAMPLES&lt;br /&gt;
      * Fit ALL chains to each other across ALL STATES for PDB 2kb1&lt;br /&gt;
      autoMultiFit 2kb1&lt;br /&gt;
&lt;br /&gt;
      * Fit chain A's residue 22-34 against all states&lt;br /&gt;
      autoMutliFit 2kb1 and i. 22-34, fromChain=A&lt;br /&gt;
&lt;br /&gt;
      * Fit chain A, B and C's residues 8-17, states 10 and 11, against chain D's state 8&lt;br /&gt;
      myVals = autoMultiFit(&amp;quot;2kb1 and i. 8-17&amp;quot;, fromChain=&amp;quot;a b c&amp;quot;, fromState=&amp;quot;10 11&amp;quot;, toChain=&amp;quot;d&amp;quot;, toState=8)&lt;br /&gt;
      myVals['B']['10']['D']['8']&lt;br /&gt;
&lt;br /&gt;
      NOTES&lt;br /&gt;
        * The return value uses UPPERCASE and STRINGS for ALL hash keys, so if you used chain 'a' it will&lt;br /&gt;
          be 'A' in the map; if you used 'chainXX' it will be 'CHAINXX' in the map.&lt;br /&gt;
        * Continuing from the above note, all statese are accessible by their strings, so '17' gets state&lt;br /&gt;
          17 from the hash, not just the number 17.&lt;br /&gt;
        * This can be very slow: it's O( nFromChains * nFromStates * nToChains * nToStates )&lt;br /&gt;
        * fromChain, toChain, fromStates and toStates can all be single values, like &amp;quot;8&amp;quot;, they can be a SPACE&lt;br /&gt;
          separated list of values, like &amp;quot;2 4 5&amp;quot;, or they can be &amp;quot;*&amp;quot; which means ALL.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    fromChain = processChain(fromChain,sel)&lt;br /&gt;
    fromState = processState(fromState, sel)&lt;br /&gt;
    toChain   = processChain(toChain, sel)&lt;br /&gt;
    toState   = processState(toState, sel)&lt;br /&gt;
&lt;br /&gt;
    res = {}&lt;br /&gt;
&lt;br /&gt;
    for frC in fromChain:&lt;br /&gt;
        res[frC] = {}&lt;br /&gt;
        for frS in fromState:&lt;br /&gt;
            res[frC][str(frS)] = {}&lt;br /&gt;
            cmd.create( &amp;quot;__tmpA&amp;quot;, sel + &amp;quot; and c. &amp;quot; + frC, frS, 1 )&lt;br /&gt;
            for toC in toChain:&lt;br /&gt;
                res[frC][str(frS)][toC] = {}&lt;br /&gt;
                for toS in toState:&lt;br /&gt;
                    cmd.create(&amp;quot;__tmpB&amp;quot;, sel + &amp;quot; and c. &amp;quot; + toC, toS, 1 )&lt;br /&gt;
                    curVal = cmd.pair_fit( &amp;quot;__tmpA&amp;quot;, &amp;quot;__tmpB&amp;quot;, quiet=1 )&lt;br /&gt;
                    res[frC][str(frS)][toC][str(toS)] = curVal&lt;br /&gt;
                    if verbose!=None:&lt;br /&gt;
                        print &amp;quot;Pair Fitted: from (chain: %s, state: %s) to (chain: %s, states %s) with RMSD %s&amp;quot; % (frC, frS, toC, toS, curVal)&lt;br /&gt;
                    cmd.delete(&amp;quot;__tmpB&amp;quot;)&lt;br /&gt;
            cmd.delete(&amp;quot;__tmpA&amp;quot;)&lt;br /&gt;
    return res&lt;br /&gt;
&lt;br /&gt;
def processChain(ch, sel):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Turn a string-based space separated list into an array of chains&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if ch == &amp;quot;*&amp;quot;:&lt;br /&gt;
        # just in case&lt;br /&gt;
        return map(str.upper, cmd.get_chains(sel))&lt;br /&gt;
    else:&lt;br /&gt;
        return map(str.upper, processTextList(ch))&lt;br /&gt;
&lt;br /&gt;
def processState(st, sel):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Tur a string-based space separated list into an array of states&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if st == &amp;quot;*&amp;quot;:&lt;br /&gt;
        # assumes that if there is a state X, there is a state, X-1&lt;br /&gt;
        return range(cmd.count_states(sel))&lt;br /&gt;
    else:&lt;br /&gt;
        return map(int, processTextList(st))&lt;br /&gt;
&lt;br /&gt;
def processTextList(t):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; make a space-separated list into a real Python list, eg.&lt;br /&gt;
    input: a b c d&lt;br /&gt;
    output: [ 'a', 'b', 'c', 'd' ]&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    t = str(t).split()&lt;br /&gt;
    return t&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    assert processTextList( &amp;quot;a b c d&amp;quot; ) == ['a', 'b', 'c', 'd']&lt;br /&gt;
    assert processTextList( &amp;quot; 1 45 s s s s j p k&amp;quot;) == [ '1', '45', 's', 's', 's', 's', 'j', 'p', 'k' ]&lt;br /&gt;
&lt;br /&gt;
    assert processChain( &amp;quot;a b c dd&amp;quot;, &amp;quot;blankSel&amp;quot; ) == [&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;dd&amp;quot;]&lt;br /&gt;
    assert processState( &amp;quot;1 2 3 44 5&amp;quot;, &amp;quot;blankSel&amp;quot; ) == [ 1, 2, 3, 44, 5 ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cmd.extend( &amp;quot;autoMultiFit&amp;quot;, autoMultiFit )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]]&lt;br /&gt;
[[Category:Structural_Biology_Script]]&lt;/div&gt;</summary>
		<author><name>Newacct</name></author>
	</entry>
</feed>