-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conformor prevent clash #23
Merged
joaomcteixeira
merged 12 commits into
julie-forman-kay-lab:develop
from
AlaaShamandy:conformorPreventClash
Dec 2, 2019
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a188a87
Merge pull request #3 from julie-forman-kay-lab/develop
AlaaShamandy 6bbf53c
added clash checks and integrated it with script
AlaaShamandy d359374
removed personal path
AlaaShamandy 95699e4
moved clash validator to its separate class
AlaaShamandy 960f09c
done but finds clash at every loop
AlaaShamandy ce034b5
vecotizing to calculate the distance is done
AlaaShamandy 0ff84c2
made one instance of the ClashValidator to keep stats about clashing
AlaaShamandy 4459aca
error in bb_complete fixed
AlaaShamandy 0d3d41c
cleaned clash_validator and conformer_builder
AlaaShamandy 132af1b
changed clash function to accept last conformer and new chain instead…
AlaaShamandy b6cbbcb
kdtree implemented
AlaaShamandy 9331719
cleaner version of clash_validator
AlaaShamandy File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import numpy as np | ||
from scipy.spatial import distance | ||
from scipy.spatial import KDTree | ||
from numpy import array | ||
import math | ||
|
||
class ClashValidator: | ||
|
||
def __init__(self): | ||
self.clashes = 0 | ||
# VDW = {"N":1.55, "CA":1.7, "C":1.7, "O":1.52} | ||
VDW = np.array([1.55, 1.7, 1.7, 1.52]) | ||
self.allowed_distances = np.add.outer(VDW,VDW) | ||
|
||
def clash_found_vectorized(self, new_chain, last_chain): | ||
""" | ||
This method calculates every possible distance between | ||
each atom within new_chain and last_chain using | ||
numpy. | ||
""" | ||
|
||
# concatenate every residue containing four atoms into one numpy array | ||
last_chain_vector = np.array([atoms_array for residue in last_chain[:-2] for atoms_array in residue.values()]) | ||
new_chain_vector = np.array([atoms_array for residue in new_chain for atoms_array in residue.values()]) | ||
|
||
# get the euclidean distance between each atom | ||
distances = distance.cdist(last_chain_vector, new_chain_vector, 'euclidean') | ||
|
||
x, y = distances.shape | ||
#the extra slicing is to allow us to include the last 3 atoms | ||
allowed_distances = np.tile(self.allowed_distances, (math.ceil(x/4), math.ceil(y/4)))[:,:y] | ||
|
||
clashes = (distances < allowed_distances) | ||
|
||
if np.any(clashes): | ||
self.clashes += 1 | ||
return True | ||
return False | ||
|
||
def clash_found_kdtree(self, new_chain,last_chain ): | ||
""" | ||
Abstract and pretend all molecules are one. This will make things a lot faster | ||
""" | ||
# concatenate every residue containing four atoms into one numpy array | ||
last_chain_vector = np.array([atoms_array for residue in last_chain[:-2] for atoms_array in residue.values()]) | ||
new_chain_vector = np.array([atoms_array for residue in new_chain for atoms_array in residue.values()]) | ||
|
||
# init kdtrees | ||
last_chain_kdtree = KDTree(last_chain_vector) | ||
new_chain_kdtree = KDTree(new_chain_vector) | ||
|
||
clashes = last_chain_kdtree.sparse_distance_matrix(new_chain_kdtree, 3.4) #maximum value to consider | ||
for indices, distance in zip(clashes.keys(),clashes.values()): | ||
if distance <= 3.04: | ||
# we don't care what the atoms are, this is a clash | ||
return True | ||
|
||
row = indices[0] % 4 | ||
column = indices[1] % 4 | ||
|
||
if distance <= self.allowed_distances[row, column]: | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quick note: this can be written as
clashes.items()
.