Beispiel #1
0
 def find_neighbours(self, position: np.array) -> np.array:
     """
     Find neighbours of prospective position, including any overlapping sites
     """
     distances = norm(self.position_buffer - position, axis=1)
     neighbours = np.nonzero(
         (distances == 1.) | (distances == np.sqrt(0.5) |
                              (distances == 0.)))  #indexes of neighbours
     return neighbours
Beispiel #2
0
 def check_self_avoiding(self, index: int, new_pos: np.array) -> bool:
     """
     Measure the distance between previous index and next index to maintain the backbone
     """
     last_index = norm(new_pos -
                       self.position_buffer[(index - 1) %
                                            len(self.position_buffer)]) in [
                                                np.sqrt(0.5), 1.
                                            ]
     next_index = norm(new_pos -
                       self.position_buffer[(index + 1) %
                                            len(self.position_buffer)]) in [
                                                np.sqrt(0.5), 1.
                                            ]
     if index == 0:
         return next_index
     elif index == self.num_residues - 1:
         return last_index
     else:
         return next_index and last_index
Beispiel #3
0
    def calc_desireability(self, position: np.array,
                           num_neighbours: int) -> float:
        """
        Calculate the desirebiilty of a prospective point according to agent density)
        """
        position = position.reshape(-1, 1)
        mean_pos = np.mean(self.position_buffer, axis=1).reshape(-1, 1)
        Sigma = np.cov(self.position_buffer.T)  #Covariance
        offset = position - mean_pos.reshape(-1, 1)

        numerator = np.exp(-offset.T.dot(inv(Sigma).dot(offset))).item()
        coeff = (2 * pi * np.sqrt(norm(Sigma)))**-1
        denom = (1 + (num_neighbours / 12)
                 )**-self.alpha  #Max number of neighbours = 12 for FCC lattice

        return coeff * numerator * denom
Beispiel #4
0
 def compute_sim(self, feat1, feat2):
     from np.linalg import norm
     feat1 = feat1.ravel()
     feat2 = feat2.ravel()
     sim = np.dot(feat1, feat2) / (norm(feat1) * norm(feat2))
     return sim