Beispiel #1
0
def orthogonal_basis(X, Y=None):

    is_1d = Y is None
    b = np.zeros((3, 3))
    b[0] = X
    if not is_1d:
        b[1] = Y
    b = complete_cell(b)

    Q = np.linalg.qr(b.T)[0].T
    if np.dot(b[0], Q[0]) < 0:
        Q[0] = -Q[0]

    if np.dot(b[2], Q[1]) < 0:
        Q[1] = -Q[1]

    if np.linalg.det(Q) < 0:
        Q[2] = -Q[2]

    if is_1d:
        Q = Q[[1, 2, 0]]

    return Q
def test_cell_completion():
    import numpy as np
    from ase.geometry.cell import complete_cell

    eps = 1E-10
    rng = np.random.RandomState(0)

    def random_unit_vector():
        while 1:
            v = rng.uniform(-1, 1, 3)
            norm = np.linalg.norm(v)
            if norm > eps:
                return v / norm

    for it in range(100):

        cell = np.zeros((3, 3))
        index = rng.randint(0, 3)
        cell[index] = random_unit_vector()
        complete = complete_cell(cell)

        assert abs(np.linalg.norm(complete[index]) - 1) < eps
        assert np.linalg.det(complete) > 0
        assert np.linalg.matrix_rank(complete) == 3
Beispiel #3
0
 def complete(self):
     """Convert missing cell vectors into orthogonal unit vectors."""
     from ase.geometry.cell import complete_cell
     cell = Cell(complete_cell(self.array))
     cell._pbc = self._pbc.copy()
     return cell
Beispiel #4
0
 def complete(self):
     """Convert missing cell vectors into orthogonal unit vectors."""
     from ase.geometry.cell import complete_cell
     return Cell(complete_cell(self.array), self.pbc.copy())