<?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=Cart_to_frac</id>
	<title>Cart to frac - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/index.php?action=history&amp;feed=atom&amp;title=Cart_to_frac"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Cart_to_frac&amp;action=history"/>
	<updated>2026-05-07T17:34:49Z</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=Cart_to_frac&amp;diff=13610&amp;oldid=prev</id>
		<title>Cchem: 1 revision</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Cart_to_frac&amp;diff=13610&amp;oldid=prev"/>
		<updated>2016-09-19T02:19:31Z</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;
This script will convert the real space orthonormal cartesian coordinates of a selection to the fractional coordinates given the loaded cell symmetry.&lt;br /&gt;
&lt;br /&gt;
* Thanks to [http://en.wikipedia.org/wiki/Fractional_coordinates Wikipedia].&lt;br /&gt;
&lt;br /&gt;
= Example =&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# load the script&lt;br /&gt;
&lt;br /&gt;
run cart_to_frac.py&lt;br /&gt;
&lt;br /&gt;
# fetch a protein and test&lt;br /&gt;
&lt;br /&gt;
fetch 1rx1, async=0&lt;br /&gt;
&lt;br /&gt;
# get the coordinates for the organic small&lt;br /&gt;
# molecule as fractional coordinates&lt;br /&gt;
&lt;br /&gt;
print cart_to_frac(&amp;quot;org&amp;quot;)&lt;br /&gt;
&amp;lt;/source&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;
from pymol import cmd&lt;br /&gt;
&lt;br /&gt;
def cart_to_frac(objSel,quiet=0,_self=cmd):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Returns an array of fractional atomic coordinates&lt;br /&gt;
    for a given object or selection.&lt;br /&gt;
&lt;br /&gt;
    PARAMS&lt;br /&gt;
      objSel -- any object or selection&lt;br /&gt;
&lt;br /&gt;
      quiet -- suppress output (default, no)&lt;br /&gt;
&lt;br /&gt;
      _self -- core CMD object; or none&lt;br /&gt;
&lt;br /&gt;
    RETURNS&lt;br /&gt;
      Python list of fractional coordinates&lt;br /&gt;
&lt;br /&gt;
    NOTES/EXAMPLES&lt;br /&gt;
      cart_to_frac org&lt;br /&gt;
&lt;br /&gt;
      x = cart_to_frac(&amp;quot;solvent&amp;quot;, quiet=1)&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    import numpy&lt;br /&gt;
    from numpy import cos, sin, sqrt&lt;br /&gt;
&lt;br /&gt;
    a2r = numpy.pi / 180.0&lt;br /&gt;
&lt;br /&gt;
    # get the model and coordinates&lt;br /&gt;
&lt;br /&gt;
    m = _self.get_model(objSel)&lt;br /&gt;
    cart_coord = numpy.matrix(m.get_coord_list())&lt;br /&gt;
&lt;br /&gt;
    # get the symmetry information&lt;br /&gt;
    try:&lt;br /&gt;
        a,b,c,alpha,beta,gamma,gp = _self.get_symmetry(objSel)&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;Error-Failed to get symmetry. Please ensure you have a&amp;quot;&lt;br /&gt;
        print &amp;quot;valid object with proper crystal symmetry loaded.&amp;quot;&lt;br /&gt;
        return None&lt;br /&gt;
&lt;br /&gt;
    # convert to radians&lt;br /&gt;
&lt;br /&gt;
    alpha = a2r * alpha&lt;br /&gt;
    beta  = a2r * beta&lt;br /&gt;
    gamma = a2r * gamma&lt;br /&gt;
    &lt;br /&gt;
    # (scaled) volume of the cell&lt;br /&gt;
    &lt;br /&gt;
    v = sqrt(1 -cos(alpha)*cos(alpha) - cos(beta)*cos(beta) - cos(gamma)*cos(gamma) + 2*cos(alpha)*cos(beta)*cos(gamma))&lt;br /&gt;
&lt;br /&gt;
    tmat = numpy.matrix( [&lt;br /&gt;
      [ 1.0 / a, -cos(gamma)/(a*sin(gamma)), (cos(alpha)*cos(gamma)-cos(beta)) / (a*v*sin(gamma))  ],&lt;br /&gt;
      [ 0.0,     1.0 / (b*sin(gamma)),         (cos(beta) *cos(gamma)-cos(alpha))/ (b*v*sin(gamma))  ],&lt;br /&gt;
      [ 0.0,     0.0,                        sin(gamma) / (c*v)                                    ] ]&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
    r = cart_coord * tmat.T&lt;br /&gt;
&lt;br /&gt;
    if not quiet:&lt;br /&gt;
        for (x,y,z) in r.tolist():&lt;br /&gt;
            print '%8.5f %8.5f %8.5f' % (x,y,z)&lt;br /&gt;
&lt;br /&gt;
    # return the Nx3 results&lt;br /&gt;
    return r&lt;br /&gt;
    &lt;br /&gt;
cmd.extend(&amp;quot;cart_to_frac&amp;quot;, cart_to_frac)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]]&lt;br /&gt;
[[Category:Structural_Biology_Scripts]]&lt;br /&gt;
[[Category:Math_Scripts]]&lt;/div&gt;</summary>
		<author><name>Cchem</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Cart_to_frac&amp;diff=935&amp;oldid=prev</id>
		<title>Pyadmin: 4 revisions</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Cart_to_frac&amp;diff=935&amp;oldid=prev"/>
		<updated>2014-03-28T01:06:31Z</updated>

		<summary type="html">&lt;p&gt;4 revisions&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:06, 28 March 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Pyadmin</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Cart_to_frac&amp;diff=934&amp;oldid=prev</id>
		<title>Speleo3: nicer output</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Cart_to_frac&amp;diff=934&amp;oldid=prev"/>
		<updated>2011-11-30T13:35:51Z</updated>

		<summary type="html">&lt;p&gt;nicer output&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Overview =&lt;br /&gt;
This script will convert the real space orthonormal cartesian coordinates of a selection to the fractional coordinates given the loaded cell symmetry.&lt;br /&gt;
&lt;br /&gt;
* Thanks to [http://en.wikipedia.org/wiki/Fractional_coordinates Wikipedia].&lt;br /&gt;
&lt;br /&gt;
= Example =&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# load the script&lt;br /&gt;
&lt;br /&gt;
run cart_to_frac.py&lt;br /&gt;
&lt;br /&gt;
# fetch a protein and test&lt;br /&gt;
&lt;br /&gt;
fetch 1rx1, async=0&lt;br /&gt;
&lt;br /&gt;
# get the coordinates for the organic small&lt;br /&gt;
# molecule as fractional coordinates&lt;br /&gt;
&lt;br /&gt;
print cart_to_frac(&amp;quot;org&amp;quot;)&lt;br /&gt;
&amp;lt;/source&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;
from pymol import cmd&lt;br /&gt;
&lt;br /&gt;
def cart_to_frac(objSel,quiet=0,_self=cmd):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Returns an array of fractional atomic coordinates&lt;br /&gt;
    for a given object or selection.&lt;br /&gt;
&lt;br /&gt;
    PARAMS&lt;br /&gt;
      objSel -- any object or selection&lt;br /&gt;
&lt;br /&gt;
      quiet -- suppress output (default, no)&lt;br /&gt;
&lt;br /&gt;
      _self -- core CMD object; or none&lt;br /&gt;
&lt;br /&gt;
    RETURNS&lt;br /&gt;
      Python list of fractional coordinates&lt;br /&gt;
&lt;br /&gt;
    NOTES/EXAMPLES&lt;br /&gt;
      cart_to_frac org&lt;br /&gt;
&lt;br /&gt;
      x = cart_to_frac(&amp;quot;solvent&amp;quot;, quiet=1)&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    import numpy&lt;br /&gt;
    from numpy import cos, sin, sqrt&lt;br /&gt;
&lt;br /&gt;
    a2r = numpy.pi / 180.0&lt;br /&gt;
&lt;br /&gt;
    # get the model and coordinates&lt;br /&gt;
&lt;br /&gt;
    m = _self.get_model(objSel)&lt;br /&gt;
    cart_coord = numpy.matrix(m.get_coord_list())&lt;br /&gt;
&lt;br /&gt;
    # get the symmetry information&lt;br /&gt;
    try:&lt;br /&gt;
        a,b,c,alpha,beta,gamma,gp = _self.get_symmetry(objSel)&lt;br /&gt;
    except:&lt;br /&gt;
        print &amp;quot;Error-Failed to get symmetry. Please ensure you have a&amp;quot;&lt;br /&gt;
        print &amp;quot;valid object with proper crystal symmetry loaded.&amp;quot;&lt;br /&gt;
        return None&lt;br /&gt;
&lt;br /&gt;
    # convert to radians&lt;br /&gt;
&lt;br /&gt;
    alpha = a2r * alpha&lt;br /&gt;
    beta  = a2r * beta&lt;br /&gt;
    gamma = a2r * gamma&lt;br /&gt;
    &lt;br /&gt;
    # (scaled) volume of the cell&lt;br /&gt;
    &lt;br /&gt;
    v = sqrt(1 -cos(alpha)*cos(alpha) - cos(beta)*cos(beta) - cos(gamma)*cos(gamma) + 2*cos(alpha)*cos(beta)*cos(gamma))&lt;br /&gt;
&lt;br /&gt;
    tmat = numpy.matrix( [&lt;br /&gt;
      [ 1.0 / a, -cos(gamma)/(a*sin(gamma)), (cos(alpha)*cos(gamma)-cos(beta)) / (a*v*sin(gamma))  ],&lt;br /&gt;
      [ 0.0,     1.0 / b*sin(gamma),         (cos(beta) *cos(gamma)-cos(alpha))/ (b*v*sin(gamma))  ],&lt;br /&gt;
      [ 0.0,     0.0,                        sin(gamma) / (c*v)                                    ] ]&lt;br /&gt;
      )&lt;br /&gt;
&lt;br /&gt;
    r = cart_coord * tmat.T&lt;br /&gt;
&lt;br /&gt;
    if not quiet:&lt;br /&gt;
        for (x,y,z) in r.tolist():&lt;br /&gt;
            print '%8.5f %8.5f %8.5f' % (x,y,z)&lt;br /&gt;
&lt;br /&gt;
    # return the Nx3 results&lt;br /&gt;
    return r&lt;br /&gt;
    &lt;br /&gt;
cmd.extend(&amp;quot;cart_to_frac&amp;quot;, cart_to_frac)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]]&lt;br /&gt;
[[Category:Structural_Biology_Scripts]]&lt;br /&gt;
[[Category:Math_Scripts]]&lt;/div&gt;</summary>
		<author><name>Speleo3</name></author>
	</entry>
</feed>