Exemple #1
0
 def test_distance_matrix_periodic(self):
     for i in range(1000):
         N = 6
         unit_cell = get_random_uc(1.0, np.random.randint(0, 4))
         fractional = np.random.uniform(0,1,(N,3))
         coordinates = unit_cell.to_cartesian(fractional)
         from molmod.ext import molecules_distance_matrix
         dm = molecules_distance_matrix(coordinates, unit_cell.matrix,
                                        unit_cell.reciprocal)
         for i in range(N):
             for j in range(i,N):
                 delta = coordinates[j]-coordinates[i]
                 delta = unit_cell.shortest_vector(delta)
                 distance = np.linalg.norm(delta)
                 self.assertAlmostEqual(dm[i,j], distance)
Exemple #2
0
    def test_distances_intra_random_periodic(self):
        for i in range(10):
            coordinates = np.random.uniform(0, 1, (20, 3))
            unit_cell = get_random_uc(5.0, np.random.randint(0, 4), 0.5)
            coordinates = unit_cell.to_cartesian(
                coordinates) * 3 - unit_cell.matrix.sum(axis=1)
            cutoff = np.random.uniform(1, 6)

            pair_search = PairSearchIntra(coordinates, cutoff, unit_cell)
            self.verify_bins_intra_periodic(pair_search.bins)

            distances = [(frozenset([i0, i1]), distance)
                         for i0, i1, delta, distance in pair_search]
            self.verify_distances_intra(coordinates, cutoff, distances,
                                        unit_cell)
Exemple #3
0
    def test_distances_inter_random_periodic(self):
        raise SkipTest
        for i in range(10):
            fractional0 = np.random.uniform(0,1,(20,3))
            fractional1 = np.random.uniform(0,1,(20,3))
            unit_cell = get_random_uc(5.0, np.random.randint(0, 4), 0.5)
            coordinates0 = unit_cell.to_cartesian(fractional0)*3-unit_cell.matrix.sum(axis=1)
            coordinates1 = unit_cell.to_cartesian(fractional1)*3-unit_cell.matrix.sum(axis=1)
            cutoff = np.random.uniform(1, 6)

            pair_search = PairSearchInter(coordinates0, coordinates1, cutoff, unit_cell)
            self.verify_bins_inter_periodic(pair_search.bins0, pair_search.bins1)

            distances = [
                ((i0, i1), distance)
                for i0, i1, delta, distance
                in pair_search
            ]
            self.verify_distances_inter(coordinates0, coordinates1, cutoff, distances, unit_cell)
Exemple #4
0
    def get_random_ff(self):
        N = 6

        mask = np.zeros((N, N), bool)
        for i in range(N):
            for j in range(i):
                mask[i, j] = True

        from molmod.ext import molecules_distance_matrix
        while True:
            unit_cell = get_random_uc(3.0, np.random.randint(0, 4), 0.2)
            fractional = np.random.uniform(0, 1, (N, 3))
            coordinates = unit_cell.to_cartesian(fractional)
            if np.random.randint(0, 2):
                unit_cell = None
                dm = molecules_distance_matrix(coordinates)
            else:
                dm = molecules_distance_matrix(coordinates, unit_cell.matrix,
                                               unit_cell.reciprocal)
            if dm[mask].min() > 1.0:
                break

        edges = set([])
        while len(edges) < 2 * N:
            v1 = np.random.randint(N)
            while True:
                v2 = np.random.randint(N)
                if v2 != v1:
                    break
            edges.add(frozenset([v1, v2]))
        edges = tuple(edges)
        numbers = np.random.randint(6, 10, N)
        graph = MolecularGraph(edges, numbers)
        ff = ToyFF(graph, unit_cell)

        return ff, coordinates, dm, mask, unit_cell