Interplay of Magnetic Interactions and Active Movements in the Formation of Magnetosome Chains