| 1 | #
|
|---|
| 2 | # Compute mean position of each atom in an ensemble and assign an atom attribute for each atom
|
|---|
| 3 | # in each ensemble model giving its distance to the mean. This is to allow coloring atoms by
|
|---|
| 4 | # distance from the mean structure.
|
|---|
| 5 | #
|
|---|
| 6 | # This script takes all open molecules as the ensemble and assigns atom attribute distance_from_mean.
|
|---|
| 7 | #
|
|---|
| 8 | # Example commands for coloring:
|
|---|
| 9 | #
|
|---|
| 10 | # open 1mtx
|
|---|
| 11 | # show
|
|---|
| 12 | # open mean_distance.py
|
|---|
| 13 | # rangecolor distance_from_mean 0 blue 3 white 6 red
|
|---|
| 14 | #
|
|---|
| 15 | # Menu Tools / Depiction / Render by Attribute can be used to do coloring and see a histogram of distances.
|
|---|
| 16 | #
|
|---|
| 17 |
|
|---|
| 18 | from chimera import openModels, numpyArrayFromAtoms, Molecule
|
|---|
| 19 | mlist = openModels.list(modelTypes = [Molecule])
|
|---|
| 20 | ave_xyz = None
|
|---|
| 21 | for m in mlist:
|
|---|
| 22 | mxyz = numpyArrayFromAtoms(m.atoms, xformed = True)
|
|---|
| 23 | if ave_xyz is None:
|
|---|
| 24 | ave_xyz = mxyz.copy()
|
|---|
| 25 | else:
|
|---|
| 26 | ave_xyz += mxyz
|
|---|
| 27 | ave_xyz /= len(mlist)
|
|---|
| 28 |
|
|---|
| 29 | from numpy import sqrt
|
|---|
| 30 | for m in mlist:
|
|---|
| 31 | mxyz = numpyArrayFromAtoms(m.atoms, xformed = True)
|
|---|
| 32 | dxyz = mxyz - ave_xyz
|
|---|
| 33 | d = sqrt((dxyz*dxyz).sum(axis=1))
|
|---|
| 34 | for a,d in zip(m.atoms, d):
|
|---|
| 35 | a.distance_from_mean = d
|
|---|