Hi Jared-

I just use the C-alpha xyz coordinates and use d = math.sqrt(dx**2 + dy**2
+ dz**2).
I've been using python alone without pymol...using your code with the pymol
api works for individual distances but I'm calculating hundreds of
distances and need to write to a csv which does not seem to be working.
I get an error:  NameError: name 'csvfile' is not defined

for k,v in AA_dict.items():
    vA = v[0:3]
    for k2, v2 in AA_dict.items():
        vA2 = v2[0:3]
        point1 = '/5p21//A/'+ vA2 + '`' + str(k2) + '/CA'
        point2 = '/5p21//A/' + vA + '`' + str(k) + '/CA'
        o = cmd.get_coords(point1)[0]
        h = cmd.get_coords(point2)[0]
        dx = h[0] - o[0]
        dy = h[1] - o[1]
        dz = h[2] - o[2]
        d = math.sqrt(dx ** 2 + dy ** 2 + dz ** 2)
        dist_dict[(v, v2)] = d

with open(protein + '_distances.csv', 'w') as csvfile:
    fieldnames = dist_dict.keys()
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    writer.writeheader()
    writer.writerow(dist_dict)  # writes the chi angles
    csvfile.close()


Thanks

Leigh

On Thu, Oct 12, 2017 at 8:44 PM, Jared Sampson <jared.samp...@columbia.edu>
wrote:

> Hi Leigh -
>
> How are you getting the coordinates?  This works for me:
>
> ```
> import math
>
> # Show more digits for the distance label
> set label_distance_digits, 10
>
> # Make an alanine residue
> fab A, ala
>
> # Get coordinates from 2 atoms
> o = cmd.get_coords("/ala///1/O")[0]
> h = cmd.get_coords("/ala///1/H")[0]
>
> # Calculate the distance
> dx = h[0] - o[0]
> dy = h[1] - o[1]
> dz = h[2] - o[2]
> d = math.sqrt(dx**2 + dy**2 + dz**2)
> print(d)
>
> # Distance from script: 2.3546268062493567
> # Distance from wizard: 2.354626655  (label maxes out at 10 digits)
> ```
>
> Those values seem close enough to me.  Is it possible that in your script
> you're getting the coordinates for the i+1 or i-1 atom instead, or a
> different state?  Or maybe picking the other side of a symmetric side chain
> (e.g. OD1 vs OD2)?  If you could share the relevant portion of the script,
> you might get some more useful feedback; right now all we can do is guess!
>
> Cheers,
> Jared
>
>
> On October 12, 2017 at 2:19:36 PM, Leigh M (leigh.j.man...@gmail.com)
> wrote:
>
> Anyone know how pymol calculates distance between two atoms?
> I wrote a python script that calculates distance using the distance
> formula and the xyz coordinates in the pdb, and it differs from the wizard
> by ~40%. Any ideas on what might be going on would be helpdul
>
> Thanks!
>
> Leigh
> ------------------------------------------------------------------------------
>
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot______
> _________________________________________
> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to