Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
15f0a714
Commit
15f0a714
authored
12 years ago
by
Niklaus Johner
Browse files
Options
Downloads
Patches
Plain Diff
Added functions to calculate the distance matrix from a trajectory
from pairwise distances (d-RMSD).
parent
f2bb4a63
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/mol/alg/pymod/trajectory_analysis.py
+65
-0
65 additions, 0 deletions
modules/mol/alg/pymod/trajectory_analysis.py
with
65 additions
and
0 deletions
modules/mol/alg/pymod/trajectory_analysis.py
+
65
−
0
View file @
15f0a714
...
...
@@ -82,3 +82,68 @@ def RMSD_Matrix_From_Traj(t,sele,first=0,last=-1):
raise
def
PairwiseDistancesFromTraj
(
t
,
sele
,
first
=
0
,
last
=-
1
,
seq_sep
=
1
):
"""
This function calculates the distances between any pair of atoms in the
EntityView sele with sequence separation larger than seq_sep from a trajectory t.
It return a matrix containing one line for each atom pair and N columns, where
N is the length of the trajectory.
Its inputs are:
t : the trajectory (CoordGroupHandle)
sele : the EntityView used to determine the atom pairs
first=0 : the first frame of t to be used
last=-1 : the last frame of t to be used
seq_sep=1 : The minimal sequence separation between
Returns a numpy NpairsxNframes matrix.
"""
try
:
import
numpy
as
npy
if
last
==-
1
:
last
=
t
.
GetFrameCount
()
n_frames
=
last
-
first
n_var
=
0
for
i
,
a1
in
enumerate
(
sele
.
atoms
):
for
j
,
a2
in
enumerate
(
sele
.
atoms
):
if
not
j
-
i
<
seq_sep
:
n_var
+=
1
#n_var=sele.GetAtomCount()
#n_var=(n_var-1)*(n_var)/2.
dist_matrix
=
npy
.
zeros
(
n_frames
*
n_var
)
dist_matrix
=
dist_matrix
.
reshape
(
n_var
,
n_frames
)
k
=
0
for
i
,
a1
in
enumerate
(
sele
.
atoms
):
for
j
,
a2
in
enumerate
(
sele
.
atoms
):
if
j
-
i
<
seq_sep
:
continue
dist_matrix
[
k
]
=
ost
.
mol
.
alg
.
AnalyzeDistanceBetwAtoms
(
t
,
a1
.
GetHandle
(),
a2
.
GetHandle
())[
first
:
last
]
k
+=
1
return
dist_matrix
except
ImportError
:
LogError
(
"
Function needs numpy, but I could not import it.
"
)
raise
def
DistanceMatrixFromPairwiseDistances
(
distances
,
p
=
2
):
"""
This function calculates an distance matrix M(NxN) from
the pairwise distances matrix D(MxN), where N is the number
of frames in the trajectory and M the number of atom pairs.
M[i,j] is the distance between frame i and frame j
calculated as a p-norm of the differences in distances
from the two frames (distance-RMSD for p=2).
Inputs:
distances : a pairwise distance matrix as obtained from PairwiseDistancesFromTraj()
Returns a numpy NxN matrix, where N is the number of frames.
"""
try
:
import
numpy
as
npy
n1
=
distances
.
shape
[
0
]
n2
=
distances
.
shape
[
1
]
dist_mat
=
npy
.
identity
(
n2
)
for
i
in
range
(
n2
):
for
j
in
range
(
n2
):
if
j
<=
i
:
continue
d
=
(((
abs
(
distances
[:,
i
]
-
distances
[:,
j
])
**
p
).
sum
())
/
float
(
n1
))
**
(
1.
/
p
)
dist_mat
[
i
,
j
]
=
d
dist_mat
[
j
,
i
]
=
d
return
dist_mat
except
ImportError
:
LogError
(
"
Function needs numpy, but I could not import it.
"
)
raise
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment