def spin_system_from_p_state(p_state, idx_image=-1, copy=False):
    from spirit import geometry, system
    spin_system = Spin_System()
    spin_system.positions     = geometry.get_positions(p_state, idx_image = idx_image)
    spin_system.spins         = system.get_spin_directions(p_state, idx_image = idx_image)
    spin_system.n_cell_atoms  = geometry.get_n_cell_atoms(p_state)
    spin_system.n_cells       = geometry.get_n_cells(p_state)

    if copy:
        spin_system.positions    = np.array(spin_system.positions   )
        spin_system.spins        = np.array(spin_system.spins       )
        spin_system.n_cell_atoms = np.array(spin_system.n_cell_atoms)
        spin_system.n_cells      = np.array(spin_system.n_cells     )

    return spin_system
Exemple #2
0
    def test_energy(self, p_state, mu=None):

        nos = system.get_nos(p_state)
        pos = np.array(geometry.get_positions(p_state)).reshape(nos, 3)
        spins = np.array(system.get_spin_directions(p_state)).reshape(nos, 3)

        if type(mu) == type(None):
            mu_s = np.ones(len(pos))
        else:
            mu_s = mu

        E_BF = self.E_DDI_BF(pos, spins, mu_s)
        E_Spirit = system.get_energy(p_state)

        return E_BF, E_Spirit
Exemple #3
0
    def run(self):
        passed = True
        l_cube = 100
        radius = l_cube / 4

        with state.State(self.inputfile, quiet=True) as p_state:
            configuration.plus_z(p_state)
            simulation.start(p_state,
                             simulation.METHOD_LLG,
                             simulation.SOLVER_SIB,
                             n_iterations=1)
            system.update_data(p_state)

            #query some quantities
            nos = system.get_nos(p_state)
            field = np.array(system.get_effective_field(p_state)).reshape(
                nos, 3)
            pos = np.array(geometry.get_positions(p_state)).reshape(nos, 3)
            spins = np.array(system.get_spin_directions(p_state)).reshape(
                nos, 3)

            #get quantitities in sphere
            center = np.array([l_cube / 2, l_cube / 2, l_cube / 2], dtype=int)
            idx_in_sphere = np.linalg.norm(pos - center, axis=1) <= radius
            mu_s = np.array([1 if idx_in_sphere[i] else 0 for i in range(nos)])

            # field_bf = self.Gradient_DDI_BF(pos, spins, mu_s)
            # field_bf_in_sphere = field_bf[idx_in_sphere]

            field_in_sphere = field[idx_in_sphere]

            # deviation_sphere = np.std(field_in_sphere - mean_grad_sphere, axis=0)

            theory = np.array(
                [0, 0, 1]) * 2 / 3 * self.mu_0 * self.mu_B * self.mu_B * 1e30

            print("Mean field                  = ",
                  np.mean(field / self.mu_B, axis=0))
            # print("Mean field (BF)             = ", np.mean(field_bf/self.mu_B, axis=0))
            print("Mean field in sphere        = ",
                  np.mean(field_in_sphere / self.mu_B, axis=0))
            # print("Mean field in sphere (BF)   = ", np.mean(field_bf_in_sphere/self.mu_B, axis=0))
            print("Theory                      = ", theory)

        return passed
Exemple #4
0
 def test_positions(self):
     positions = geometry.get_positions(self.p_state)
     # spin at (0,0,0)
     self.assertAlmostEqual(positions[0][0], 0)
     self.assertAlmostEqual(positions[0][1], 0)
     self.assertAlmostEqual(positions[0][2], 0)
     # spin at (1,0,0)
     self.assertAlmostEqual(positions[1][0], 1)
     self.assertAlmostEqual(positions[1][1], 0)
     self.assertAlmostEqual(positions[1][2], 0)
     # spin at (0,1,0)
     self.assertAlmostEqual(positions[2][0], 0)
     self.assertAlmostEqual(positions[2][1], 1)
     self.assertAlmostEqual(positions[2][2], 0)
     # spin at (1,1,0)
     self.assertAlmostEqual(positions[3][0], 1)
     self.assertAlmostEqual(positions[3][1], 1)
     self.assertAlmostEqual(positions[3][2], 0)
Exemple #5
0
def test_gradient(p_state, mu = None):
    
    nos = system.get_nos(p_state)
    pos = np.array(geometry.get_positions(p_state)).reshape(nos, 3)
    spins = np.array(system.get_spin_directions(p_state)).reshape(nos, 3)

    simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1)
    system.update_data(p_state)
    
    if type(mu) == type(None):
        mu_s = np.ones(len(pos))
    else:
        mu_s = mu

    Gradient_BF = Gradient_DDI_BF(pos, spins, mu_s)
    Gradient_Spirit = np.array(system.get_effective_field(p_state)).reshape(nos, 3)

    return Gradient_BF, Gradient_Spirit
def plot_basis_cell(p_state, ax=None):
    from spirit import geometry, system

    # Read out the information we need
    n_cell_atoms  = geometry.get_n_cell_atoms(p_state)
    n_cells       = geometry.get_n_cells(p_state)
    positions     = geometry.get_positions(p_state)

    def idx(i,a,b,c):
        return i + n_cell_atoms * (a + n_cells[0] * (b + n_cells[1] * c))

    # Draw the outlines of the basis cell
    lattice_points = np.array([ positions[idx(0,0,0,0)], positions[idx(0,1,0,0)], positions[idx(0,1,1,0)], positions[idx(0,0,1,0)] ])

    patch=[Polygon(lattice_points[:,:2])]
    pc = PatchCollection(patch, linestyle="--", facecolor = [0,0,0,0], edgecolor = [0,0,0,1])
    ax.add_collection(pc)
    ax.scatter(positions[:n_cell_atoms,0], positions[:n_cell_atoms,1], color="red", s=100)
    ax.set_xlabel(r"$x\;\;[\AA]$")
    ax.set_ylabel(r"$y\;\;[\AA]$")