How to use the matscipy.neighbours.mic function in matscipy

To help you get started, we’ve selected a few matscipy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libAtoms / matscipy / tests / neighbours.py View on Github external
def test_neighbour_list_atoms_outside_box(self):
        for pbc in [True, False, [True, False, True]]:
            a = io.read('aC.cfg')
            a.set_pbc(pbc)
            a.positions[100, :] += a.cell[0, :]
            a.positions[200, :] += a.cell[1, :]
            a.positions[300, :] += a.cell[2, :]
            j, dr, i, abs_dr, shift = neighbour_list("jDidS", a, 1.85)

            self.assertTrue((np.bincount(i) == np.bincount(j)).all())

            r = a.get_positions()
            dr_direct = mic(r[j]-r[i], a.cell)
            self.assertArrayAlmostEqual(r[j]-r[i]+shift.dot(a.cell), dr_direct)

            abs_dr_from_dr = np.sqrt(np.sum(dr*dr, axis=1))
            abs_dr_direct = np.sqrt(np.sum(dr_direct*dr_direct, axis=1))

            self.assertTrue(np.all(np.abs(abs_dr-abs_dr_from_dr) < 1e-12))
            self.assertTrue(np.all(np.abs(abs_dr-abs_dr_direct) < 1e-12))

            self.assertTrue(np.all(np.abs(dr-dr_direct) < 1e-12))
github libAtoms / matscipy / tests / neighbours.py View on Github external
def test_neighbour_list(self):
        for pbc in [True, False, [True, False, True]]:
            a = io.read('aC.cfg')
            a.set_pbc(pbc)
            j, dr, i, abs_dr, shift = neighbour_list("jDidS", a, 1.85)

            self.assertTrue((np.bincount(i) == np.bincount(j)).all())

            r = a.get_positions()
            dr_direct = mic(r[j]-r[i], a.cell)
            self.assertArrayAlmostEqual(r[j]-r[i]+shift.dot(a.cell), dr_direct)

            abs_dr_from_dr = np.sqrt(np.sum(dr*dr, axis=1))
            abs_dr_direct = np.sqrt(np.sum(dr_direct*dr_direct, axis=1))

            self.assertTrue(np.all(np.abs(abs_dr-abs_dr_from_dr) < 1e-12))
            self.assertTrue(np.all(np.abs(abs_dr-abs_dr_direct) < 1e-12))

            self.assertTrue(np.all(np.abs(dr-dr_direct) < 1e-12))
github libAtoms / matscipy / matscipy / atomic_strain.py View on Github external
"""
    Calculate the D^2_min norm of Falk and Langer
    """
    nat = len(atoms_now)
    assert len(atoms_now) == len(atoms_old)

    pos_now = atoms_now.positions
    pos_old = atoms_old.positions

    # Compute current and old distance vectors. Note that current distance
    # vectors cannot be taken from the neighbor calculation, because neighbors
    # are calculated from the sheared cell while these distance need to come
    # from the unsheared cell. Taking the distance from the unsheared cell
    # make periodic boundary conditions (and flipping of cell) a lot easier.
    dr_now = mic(pos_now[i_now] - pos_now[j_now], atoms_now.cell)
    dr_old = mic(pos_old[i_now] - pos_old[j_now], atoms_old.cell)

    # Sanity check: Shape needs to be identical!
    assert dr_now.shape == dr_old.shape

    if delta_plus_epsilon is None:
        # Get minimum strain tensor
        delta_plus_epsilon = get_delta_plus_epsilon(nat, i_now, dr_now, dr_old)

    # Spread epsilon out for each neighbor index
    delta_plus_epsilon_n = delta_plus_epsilon[i_now]

    # Compute D^2_min (residual of the least squares fit)
    residual_n = np.sum(
        (
        dr_now-
        np.sum(delta_plus_epsilon_n.reshape(-1,3,3)*dr_old.reshape(-1,1,3),
github libAtoms / matscipy / matscipy / dislocation.py View on Github external
mapping = {}

    for i in range(len(bulk)):
        mapping[i] = np.linalg.norm(bulk_ref.positions -
                                    bulk.positions[i], axis=1).argmin()

    u_ref = dislo_ref.positions - bulk_ref.positions

    u = dislo.positions - bulk.positions
    u_extended = np.zeros(u_ref.shape)
    u_extended[list(mapping.values()), :] = u

    du = u_extended - u_ref

    Du = np.linalg.norm(np.linalg.norm(mic(du[J_core, :] - du[I_core, :],
                                           bulk.cell), axis=1))
    return Du
github libAtoms / matscipy / matscipy / atomic_strain.py View on Github external
def get_D_square_min(atoms_now, atoms_old, i_now, j_now, delta_plus_epsilon=None):
    """
    Calculate the D^2_min norm of Falk and Langer
    """
    nat = len(atoms_now)
    assert len(atoms_now) == len(atoms_old)

    pos_now = atoms_now.positions
    pos_old = atoms_old.positions

    # Compute current and old distance vectors. Note that current distance
    # vectors cannot be taken from the neighbor calculation, because neighbors
    # are calculated from the sheared cell while these distance need to come
    # from the unsheared cell. Taking the distance from the unsheared cell
    # make periodic boundary conditions (and flipping of cell) a lot easier.
    dr_now = mic(pos_now[i_now] - pos_now[j_now], atoms_now.cell)
    dr_old = mic(pos_old[i_now] - pos_old[j_now], atoms_old.cell)

    # Sanity check: Shape needs to be identical!
    assert dr_now.shape == dr_old.shape

    if delta_plus_epsilon is None:
        # Get minimum strain tensor
        delta_plus_epsilon = get_delta_plus_epsilon(nat, i_now, dr_now, dr_old)

    # Spread epsilon out for each neighbor index
    delta_plus_epsilon_n = delta_plus_epsilon[i_now]

    # Compute D^2_min (residual of the least squares fit)
    residual_n = np.sum(
        (
        dr_now-