Distancetoatom

From PyMOLWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Type Python Module
Download distancetoatom.py
Author(s) Andreas Warnecke and Jared Sampson
License BSD-2-Clause
This code has been put under version control in the project Pymol-script-repo
get distance to atoms within cutoff

About distancetoatom

distancetoatom prints all distances between a specified atom, coordinate or group selection center and all atoms within cutoff distance that are part of the selection.
All coordinates and distances can be saved in a csv-style text file report and/or can be stored in a (custom) atom property, if defined.

Usage

    distancetoatom [ origin [, cutoff [, filename [, selection [, state [, property_name [, coordinates [, decimals [, sort [, quiet ]]]]]]]]]]

Arguments

Arguments for distancetoatom
Keyword Default What it does
origin pk1 "origin" defines the coordinates for the origin and can be:

1. a list with coordinates [x,y,z]
2. a single atom selection string
3. a multi-atom selection string (center will be used)

cutoff 10 "cutoff" defines the maximum distance, atoms further away are not considered
filename None "filename" is the name of a report file that will be created (optional).

set to e.g. 'report.txt' to create a report. This file is CSV style and can be imported into EXCEL.
(omit or set to "", None, 0 or False to disable)

selection all only atoms within "selection" (and cutoff distance) will be used for calculation
state 0 "state" is the state that will be used for calculations

use 0 (omit), to automatically use the current state

property_name p.dist "property_name" defines a (custom) property in which the calculated distance will be stored.

This can be used e.g. for labeling or spectrum coloring etc. (cf. examples)
NB! older PyMOL versions only support b or q and the distance will overwrite this property if set.

coordinates 0 "coordinates" toggles whether, besides distance, the atom coordinates will be included in the report.
decimals 3 "decimals" is the number of decimal places calculated.

Note that PDB files do not support a higher resolution than 3.

sort 1 "sort" defines how the output will be sorted:

1: ascending (default)
0: no sorting (by selection)
-1: descending

quiet 1 toggle verbosity


Examples

# make function available to PyMOL
import distancetoatom

##############################
# Example 1: print all distances
frag LYS
edit name CA
distancetoatom

##############################
# Example 2: print all distances to file
fetch 1cll, async=0
distancetoatom origin=/1cll//A/CA`150/CA, filename=distances.txt, selection=elem O, property_name=b
# the file is CSV-format and can be imported, e.g. to EXCEL

# format
hide everything
select byres (resi 150 expand 5 and not resn hoh) 
show_as sticks, sele
util.cbaw sele
show_as spheres, resi 150
zoom sele

##########
# Label by stored distance (property_name)
label sele and elem O, "%.2f"%b


##############################
# Example 3: color an object by distance to a coordinate

fetch 1cll, async=0
distancetoatom [0,0,0], cutoff=1000, property_name=b
# the distance is stored in the b-factor in this case
# newer PyMOL versions support custom properties, e.g. "p.dist"
spectrum b, rainbow_rev

Example 2

Example 3


SEE ALSO