Last active
May 1, 2017 11:50
-
-
Save larsbratholm/109a755913c1ae51cf52b9d7560422b8 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
def make_exclusionlist(fragment, capped, max_length, ignore_capping_hydrogens = True): | |
# is this int? - else change | |
frag_serials = np.asarray(fragment.serials, dtype=int) | |
valid_capped_fragments = np.fromiter((frag for frag in capped if capfrag.ignore == False), int) | |
valid_capped_fragment_serials = [[serial for serial, name in zip(capfrag.serials, capfrag.names) if (ignore_capping_hydrogens and name != " H* ")] for capfrag in valid_capped_fragments] | |
# are serials unique? - else change | |
matches = (np.intersect1d(fragment.serials, cap_serials, assume_unique = True) for cap_serials in valid_capped_fragment_serials) | |
# this can probably be done faster | |
# for each element, get all the serials of capped fragment containing element | |
excl = [[] for _ in frag_serials] | |
for i, (cap_serials, matched) in enumerate(zip(valid_capped_fragment_serials, matches)): | |
for j in matched: | |
excl[j].extend(cap_serials) | |
# all the unique elements with zeros padded | |
excl = [np.unique(x).resize(max_length).tolist() for x in excl] | |
# serial == -1 should return [-1] + [0]*(max_length-1) right? | |
for i, v in enumerate(frag_serials): | |
if v == -1: | |
excl[i] = - np.ones(1).resize(max_length).tolist() | |
return excl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment