A gradient field defeats the inherent repulsion between magnetic nanorods

When controlling the assembly of magnetic nanorods and chains of magnetic nanoparticles, it is extremely challenging to bring them together side by side while keeping a desired spacing between their axes. We show that this challenge can be successfully resolved by using a non-uniform magnetic field that defeats an inherent repulsion between nanorods. Nickel nanorods were suspended in a viscous film and a non-uniform field was used to control their placement. The in-plane movement of nanorods was tracked with a high-speed camera and a detailed image analysis was conducted to quantitatively characterize the behaviour of the nanorods. The analysis focused on the behaviour of a pair of neighbour nanorods, and a corresponding dynamic model was formulated and investigated. The complex two-dimensional dynamics of a nanorod pair was analysed analytically and numerically, and a phase portrait was constructed. Using this phase portrait, we classified the nanorod behaviour and revealed the experimental conditions in which nanorods could be placed side by side. Dependence of the distance between a pair of neighbour nanorods on physical parameters was analysed. With the aid of the proposed theory, one can build different lattices and control their spacing by applying different field gradients.


Summary
When controlling the assembly of magnetic nanorods and chains of magnetic nanoparticles, it is extremely challenging to bring them together side by side while keeping a desired spacing between their axes. We show that this challenge can be successfully resolved by using a non-uniform magnetic field that defeats an inherent repulsion between nanorods. Nickel nanorods were suspended in a viscous film and a nonuniform field was used to control their placement. The in-plane movement of nanorods was tracked with a high-speed camera and a detailed image analysis was conducted to quantitatively characterize the behaviour of the nanorods. The analysis focused on the behaviour of a pair of neighbour nanorods, and a corresponding dynamic model was formulated and investigated. The complex two-dimensional dynamics of a nanorod pair was analysed analytically and numerically, and a phase portrait was constructed. Using this phase portrait, we classified the nanorod behaviour and revealed the experimental conditions in which nanorods could be placed side by side. Dependence of the distance between a pair of neighbour nanorods on physical parameters was analysed. With the aid of the proposed theory, one can build different lattices and control their spacing by applying different field gradients.

Introduction
In the past decade, one-dimensional magnetic nanostructures, such as magnetic nanorods, chains of magnetic nanoparticles and nanotubes filled with magnetic nanoparticles, have offered great opportunities for the design of multi-functional devices and for the manufacturing of anisotropic nano-and microstructures [1][2][3][4]. These applications include, for example, optofluidics [5][6][7][8][9], microrheology [10][11][12][13][14], magnetic swimming [15][16][17][18][19][20], photonics [21], drug delivery [22] and electromagnetic shielding [23].  The magnetic field and its gradient calculated along the y-axis of the system. Solid blue line represents magnetic field and dashed green line, field gradient. different configurations of magnetic fields are usually applied to obtain the desired pattern of magnetic rods or chains [2,4,[24][25][26][27]. A uniform magnetic field is usually used to align the nanorods in one direction or to form self-assembled chains from magnetic nanoparticles. Recently, the strategies for aligning an assembly of non-interacting magnetic nanorods in both Newtonian and non-Newtonian fluids under a uniform magnetic field have been proposed and developed [28,29]. However, in many cases, one needs to deal with a concentrated colloid of magnetic nanorods where the interactions between nanorods are crucial for the patterning of the microstructures [30][31][32][33][34][35][36].
The main challenge when attempting to control the assembly of magnetic nanorods is bringing them together and placing them side by side [7,35,36]. Indeed, when two identical magnetic nanorods come together side by side, they are prone to move away owing to their inherent repulsion. A uniform magnetic field keeps them parallel to each other but they tend to form a tandem with a head-to-tail ordering. Phase diagrams for the long nanorods demonstrate a significant enlargement of the region of repulsion compared with the point dipoles [7,37]. Therefore, one needs to develop a new strategy in order to defeat this inherent repulsion.
One possible strategy is to use a non-uniform magnetic field with a field gradient [30,33,35,38]. In a non-uniform magnetic field generated by a magnet, the magnetic force acting on a nanorod with magnetization vector M is written as F = V(M · ∇)B, where B is the magnetic field vector and V is the volume of the nanorod. As follows from this formula, magnetic nanorods can be pushed towards each other by generating a special field gradient. For example, in the region close to the axis of a cylindrical magnet, the radial component of the magnetic field B r is much weaker than the axial component B y , B r B y , where the y-axis is taken along the axis of the cylinder. The magnetic force can be approximately calculated as F = V(M∂/∂y)B, where M is the magnetization of the nanorod. For a cylindrical magnet like the one shown in figure 1a,b, the radial component of the magnetic field is positive (B r > 0) and its gradient is negative along the y-axis (dB r /dy < 0). Thus, the radial component of magnetic force F r is negative (F r < 0) and the nanorods tend to cluster at the central axis. These arguments show that the placement of magnetic nanorods next to each other can be accomplished by applying a non-uniform magnetic field with a strong axial gradient of the radial component of a magnetic field [39]. However, such strong gradients are difficult to produce at the micrometre scale. On the other hand, the gradient dB y /dy of the axial component of a magnetic field is much easier to create and control. Taking advantage of this type of field non-uniformity, various microstructures have already been successfully fabricated [30,33,35], and interest in using this type of field gradient is growing [3,9,30,33,34,[40][41][42]. However, owing to the lack of complete understanding about the behaviour of nanorods in a strong dB y /dy gradient, the inter-rod spacing is still difficult to control [2,9,43].
In this paper, we overcome this challenge by modelling the behaviour of a pair of magnetic nanorods in a non-uniform magnetic field with a dB y /dy gradient. We analyse the dynamics of the nanorods suspended in a two-dimensional Newtonian film. The nanorods are pulled together by the dB y /dy gradient. They also interact with each other through their magnetic poles. In experiments, we use nickel nanorods; their dynamics is filmed using dark field microscopy. We develop a particle-tracking algorithm to follow the nanorod movement and analyse the nanorod trajectories. The analysis of experiments shows that the model adequately describes the behaviour of interacting magnetic nanorods. The conditions for controlled placement of magnetic nanorods were theoretically studied and experimentally examined.

Preparation of a dispersion of nickel nanorods
To make nickel nanorods, we used electrochemical template synthesis [44,45]. Nanorods were synthesized inside 200 nm pores of alumina membranes (Watman Ltd.). We exactly followed the procedure described in the supporting information of Tokarev et al. [11]. This experimental protocol enables one to produce nanorods of approximately 6 µm in length and less than 200 nm in diameter. Following the protocol as described in [28,40], we stabilized the nanorods with a layer of polyvinylpyrrolidone (PVP). The PVP-coated nickel nanorods were dispersed in a 76 wt% water-glycerol mixture (76% glycerol, 24% water). In experiments, a dispersion of nickel nanorods of low concentration (0.005 wt%) was used. A 1 µl droplet of this dispersion was placed on a glass slide (VWR International, LLC) and immediately covered by another glass cover slide (VWR International, LLC). Two 26 µm thick Nylon fibres were placed as spacers between slides. This gap thickness was chosen in order that the effect of hydrodynamic interactions between the nanorods and the substrates could be neglected. In our earlier publication [28], we confirmed that the chosen gap thickness is optimal; measuring viscosity of different standard liquids with same set-up and using magnetic rotational spectroscopy, we reproduced viscosity of these standards [11,46].

Optical cell
The schematic of the optical cell is shown in figure 1a. Two cylindrical magnets were used in this experiment. The rear face of the smaller magnet was attached to the front face of the larger one so that both magnets had a common axis as shown in figure 1b. The smaller magnet was 1.6 mm in diameter and 1.6 mm in length, and the larger magnet was 12.7 mm in diameter and 12.7 mm in length (Grade N52, K&J Magnetics). This construction allowed for a sufficiently strong field of the order of 1 T. The gradient changes by as much as two orders of magnitude within a distance of approximately 5 mm from the front face of the smaller magnet as illustrated in figure 1c. The field distribution was simulated using COMSOL, taking magnetization as 1.48 × 10 6 A m −1 for both magnets and placing the origin of coordinates at the free surface of the small magnet 2.
This construct was positioned under the microscope (Olympus BX 51) with the common axis parallel to the optical stage. The position of the construct was controlled by a linear stage (VT-21, MICOS). The Olympus BX 51 microscope was equipped with a digital camera (SPOT Imaging Solutions, Inc.) allowing for the application of dark field imaging. The sample was positioned under the microscope in front of the smaller cylindrical magnet as shown in figure 1a, and the behaviour of nanorods was studied by focusing the camera on four different spots along the common axis of the magnets at the following positions: y = 5, 3, 2 and 1.5 mm.

Experimental protocol
The main challenge in studying the interactions between nanorods subject to a non-uniform field is that the nanorods always move within the fluid. The nanorods keep moving towards the region of a stronger   field until they reach a boundary, e.g. the liquid-air interface. When a nanorod hits a boundary, it does not move anymore and stays pinned to the boundary. It is therefore convenient to focus the camera to a pinned nanorod and watch the behaviour of incoming nanorods (figure 2b).
Initially, the magnets were placed far away from the sample to eliminate any translational motion of the nanorods. The recording started when the magnets were brought closer to the sample. Figure 3 shows two sequences of images illustrating different scenarios of the nanorods landing: (a) landing on top of the pinned nanord and (b) landing next to each other.

Magnetostatic interactions between nanorods and external field
In the focal plane of observation, it is convenient to introduce the local Cartesian system of coordinates (X, Y) with the Y-axis aligned along the common axis of the magnets. The origin of the local system of coordinates is taken at the centre of mass of the pinned nanorod as illustrated in figure 2b. The position of the incoming nanorod is measured by its centre of mass (X, Y). The length of the pinned nanorod and the length of the incoming nanorod are denoted as L and l, respectively. As illustrated in figure 2c, the x-component of the magnetic field B is almost zero at these points. Therefore, the magnetization M of all nanorods is expected to point in the y-direction. If the nanorods were non-interacting, they would move only in the y-direction. Within the small field of view (approx. 20 × 20 µm 2 ) shown in figure 2b, the dB y /dy gradient is almost constant, dB y /dy = α. For a strong gradient (α ∼ 100 T m −1 ), the variation of the field over a 20 µm distance is approximately B y ∼ 2 mT. On the other hand, the magnitude of the field is greater than |B| > 0.1 T. Therefore, we assume that the magnetization of nanorods is constant and that the two neighbour nanorods have the same magnetization M. In experiments, the applied magnetic field was sufficiently strong to ensure that the nanorods were not able to change their orientations even in close proximity to each other.
As the distance between the nanorods is comparable with their lengths, the nanorods cannot be treated as point dipoles [7]. We therefore use the model of 'magnetic charges' [7,47,48]. To determine the charge Q, we divide the magnetic nanorod into a chain of infinitesimally small magnets as shown in figure 2a. Each elementary magnet has the moment m i = Q l with an elementary 'magnetic charge' Q.
If we sum up all elementary magnets within the nanorod, all internal poles of the opposite sign will be cancelled out and 'magnetic charges' of the opposite sign will remain only at the ends of the nanorod. For a nanorod with diameter d and magnetization M, the 'magnetic charge' Q can be therefore calculated as: Q = π d 2 M/4. Following the chosen system of coordinates, figure 2b, the energy of the nanorod subject to an external field can be calculated by introducing magnetostatic potential ϕ(X, Y). It has to satisfy the Laplace equation written in cylindrical coordinates as: In the vicinity of the central axis, the potential is represented as: where B 0 is the constant component of a non-uniform external magnetic field taken at the centre of mass of the pinned nanorod (0, 0). In our experiments, the gradient α = −dB y /dy is always positive. This implies that the nanorods tend to move to the boundary (X, −L/2) as illustrated in figure 2b.
With the given potential, the magnetic field is obtained as B = −∇ϕ = (αX/2, B 0 − αY). The magnetostatic energy of the incoming nanorod in the external magnetic field is calculated as: The second term is independent of the position of the incoming nanorod, and hence it does not contribute to the force balance. The total magnetostatic energy of two interacting magnetic nanorods under the field gradient is therefore written as: where μ 0 is the permeability of a vacuum. As follows from equation (4.1), magnetostatic energy scales as U ∝ μ 0 Q 2 /(4π L). We can make equation (4.1) dimensionless by dividing it by μ 0 Q 2 /(4π L), provided that all coordinates (X, Y) are normalized by the length of the pinned nanorod L: The factor β = 4π L 2 α/(μ 0 Q) measures the strength of the field gradient with respect to the energy of mutual magnetostatic interactions between two nanorods. When this parameter is small, β 1, the field gradient has almost no effect on the incoming nanorod and the two nanorods interact as if there was no field gradient. If this parameter is large, β 1, the incoming nanorod should not feel any presence of the neighbour nanorod hence it should be able to land on the boundary. Figure 4 shows the energy landscape generated by the incoming nanorod in the presence of the pinned nanorod and external magnetic field B = (αX/2, B 0 − αY). In calculations, we assumed that the two nanorods have the same length, L = l. Different colours correspond to the different energy levels.
Using this energy landscape, one can calculate the force acting on the incoming nanorod. The magnetic force is obtained through the gradient of the total magnetostatic energy U(X, Y) as The black arrows in figure 4 show the direction of magnetic force acting on the incoming nanorod.   In the absence of an external magnetic field gradient, β = 0, the nanorods tend to come together forming a head-to-tail configuration (figure 4a). This case corresponds to points 1 (0, 1) and 2 (0, −1) in figure 4d providing the same energy level. Owing to the impermeable boundary, the incoming nanorod cannot reach point 2. Therefore, point 1 is energetically favourable because two opposite 'magnetic charges' cancel each other at the junction point.
In the absence of a magnetic field gradient, when two nanorods are placed side by side, point 3 (0, 0) in figure 4d, they produce the energy maximum. Strong repulsion between the nearest 'magnetic charges' of the same sign forces the nanorods to run away from this configuration 3.
In a field gradient, the energy landscape deforms, and one finds new minima. These minima appear as a result of topological transformations of the energy surface as illustrated in figure 4b,c. When the field gradient is not strong and parameter β is of the order of 1, the deformation of the energy surface is insignificant, yet the topography changes to decrease the region with a strong x-component of the magnetic force. This change occurs in regions |X/L| > 1, where the magnetic force undergoes significant change. The arrows in figure 4b, β = 2.5, show that the x-component of the force becomes small in these regions. Therefore, the incoming nanorod is expected to land at the boundary and the static friction offered by the boundary is sufficient to keep nanorods from moving in the x-direction. Points 1 and 2 are still the energy minimum and point 3 is the energy maximum. The field gradient causes the energy level at point 2 to decrease relative to point 1.
When the field gradient is strong and parameter β is much greater than 1, the energy surface deforms significantly.  Even for extremely high β, the incoming nanorod can never land right next to the pinned one owing to the inherent repulsion between them. However, the variation of parameter β provides a possibility to control the inter-rod distance, which will be further discussed in the next section ( figure 5d). This analysis of the energy landscape favours a possibility of placement of the incoming nanorod side by side next to the pinned one. In applications, it is important to control the nanorod placement, hence it is necessary to specify the range of initial positions of the incoming nanorod (X, Y) leading to its landing on the boundary or on top of the pinned nanorod.

Dynamics of magnetic nanorods: phase portrait
Assume that the nanorods are suspended in a simple Newtonian fluid with viscosity η. In the limit of low Reynolds numbers when the inertial force is much smaller than the viscous force, the velocity field of the incoming nanorod is described by the following dynamic system [49]: where γ X and γ Y are the translational drag coefficients of the nanorods moving in the X and Y directions, respectively [49], and t is the time. The dynamic system (5.1) was analysed numerically: each pair of initial conditions (X 0 , Y 0 ) generated a trajectory. Two nanorods with the same length (L = l), diameter d and magnetization M were used in these calculations. The aspect ratio l/d was taken as 25. As the centre of coordinates was chosen at the centre of mass of the pinned nanorod, the substrate was located at Y/L = −1/2. Therefore, when the incoming nanorod reaches position Y/L = 0, it lands on the boundary; the static friction from the boundary is expected to pin it there. The calculation will stop at this moment of time. In figure 5a-c, the blue line solutions describe the trajectories (X(t), Y(t)) of the incoming nanorods. In order to distinguish the scenarios of the nanorod landing, we have to analyse all initial conditions and classify the trajectories on the phase portrait of equation (5.1).
We first look at the Y-axis of the phase portrait. Along this axis, the following equality F X (0, Y) = 0 holds true. This equality implies that magnetic force is always directed along the Y-axis and that the nanorods starting at any point (0, Y 0 ) will move along the Y-axis.
There are two singular points of this system where the Y-component of magnetic force F Y goes to infinity. The first singular point, shown as the black dot with coordinates (0, 1) in figure 5a-c, corresponds to the energy minimum. It is the attractor of the dynamic system: the pinned nanorod attracts the incoming one and forces it to land on top. The local trajectories converge towards this attractor and the arrows show the velocity vectors of the incoming nanorods.
The second singular point is the centre of coordinates attached to the centre of mass of the pinned nanorod, point (0, 0). This point corresponds to the energy maximum: two nanorods which are brought together and placed right next to each other cannot stay in equilibrium. The local trajectories emanate from this unstable stationary point.
Besides these two singular points, there are two more stationary points of the dynamic system (5.1) satisfying the following equations: F X = 0, F Y = 0. These stationary points are the saddle points of the dynamic system. Along some sets of local trajectories, the velocity vectors are always directed towards these stationary points and along some other sets of trajectories the velocity vectors are always directed away from them. These two stationary points are marked as the empty black circles in figure 5a-c. In figure 5b, these two saddle points merge at the Y-axis.
The separatrices, the solid purple lines, are defined as the trajectories of nanorods emanating from the saddle points. The details of their calculations are given in appendix A.

Classification of the landing scenarios for the nanorods
With the aid of this analysis of the phase portrait of dynamic system (5.1), we can classify the scenarios of the nanorod landing. The solid purple separatrices in figure 5a-c divide the phase portrait onto three regions: region I (dark green), region II (dark yellow) and the forbidden region (pink) where no nanorod can reach. The nanorods are pushed away from the forbidden region by the strong repulsion from the pinned nanorod.
The boundaries of regions I, II and the forbidden region are sensitive to the applied magnetic field gradient α as β is proportional to α. In the limiting case β = 0, when the external field is uniform, the two saddle points are infinitely far from each other and region II occupies an infinitely large area. This implies that the incoming nanorod will always land on top of the pinned one. This statement is supported by the energy map shown in figure 4a.
By increasing the field gradient, i.e. parameter β, one opens the possibility of landing the incoming nanorod next to the pinned one. In the phase portrait, the two saddle points are pushed to come from infinity closer to the Y-axis. Therefore, the area of region II shrinks and the area of region I increases to offer the incoming nanorod a possibility to land next to the pinned one.
There is a critical field gradient when the two saddle points merge at the Y-axis. In figure 5b, this case corresponds to β cr = 11.1. At this critical field gradient, only one saddle point (0, Y cr ) exists and it is attached to the y-axis. At this point, the x-component of the magnetic force is zero. In other words, the force caused by the interpole interactions is balanced by the force caused by the field gradient. The critical field gradient separates two topologically different portraits: when β < β cr and when the expansion of region I, the contraction of region II and the forbidden region occur mainly in the x-direction. In the opposite case when β > β cr , the two saddle points move along the Y-axis separating region II from the forbidden region. Region I expands mainly in the Y-direction.
In the limit β → ∞, when the field gradient is much stronger than the field of the pinned nanorod, one saddle point moves to coincide with the energy maximum at (0, 0) and the other merges with the energy  minimum at (0, 1). In this limit, the areas of region II and the forbidden region shrink to zero, implying that the incoming nanorod will always land on the boundary side by side with the pinned nanorod. Figure 6 summarizes the topological change of the phase portrait. When β < β cr , the two saddle points are symmetric with respect to the Y-axis. As β increases, the two saddles points come closer to the Y-axis implying the expansion of region I and shrinkage of both region II and the forbidden region. When β = β cr , the two saddle points merge at the Y-axis and stay there as β further increases. When β goes to infinity, one saddle point moves along the Y-axis towards point (0, 0) and the other moves along the Y-axis towards point (0, 1). Simultaneously, region II and the forbidden region disappear. This topological change of the phase portrait is illustrated in the electronic supplementary material, movie S1.
For the practical applications, it is instructive to analyse the change of the half width of the forbidden region, X min , as a function of β. This parameter, X min , corresponds to the minimum spacing between two nanorods landed at the boundary. In figure 5d, we plot this minimum spacing as a function of β for the nanorods with different length ratios l/L. In all cases, the minimum spacing decreases as β increases. It follows that the minimum spacing, X min , asymptotically approaches zero as the field gradient increases. Using the relations shown in figure 5d, the inter-rod spacing can be controlled by varying the β parameter.

Experimental verification of different scenarios of nanorod landing
Experimental reproduction of the phase portrait requires tracking multiple pairs of incoming and pinned nanorods with the same length ratios l/L as well as with the same dimensionless parameter β. Therefore, figure 5a-c is difficult to reproduce experimentally. However, the trajectories of the incoming nanorods are traceable. The length ratio l/L can be measured directly from the images and only one unknown parameter β requires determination from the experiments. As the β-parameter has a strong dependence on the diameter of the pinned nanorod, β ∝ 1/d 2 , but the dark field images do not allow one to accurately measure the nanorod diameters, we determined this parameter by fitting the experimental trajectories with the numerical solutions of equation (5.1).
Several frames including the initial and final frames were first extracted from each video and the initial frame was then overlaid with all the following frames. Therefore, we can form an image showing the trajectory of the incoming nanorod. In figure 7, we demonstrate five composite images. These pictures illustrate different scenarios of the nanorod landing. The centre of mass of the incoming nanorod is denoted by the purple circle and the pinned nanorod is marked by the red rectangle.
Using parameter β as the adjustable parameter, in each case we obtained the best fits for the experimental trajectories. These best fits are shown in figure 4 as the blue lines. The theoretical curves demonstrate an excellent agreement with the experimental trajectories. Based on the proposed theory taking β = 98, and the ratio l/L = 1, the minimum spacing should be equal to X min /L = 0.18 (figure 5d). The experimental inter-rod spacing extracted from figure 7e is equal to X/L = 0.2. Thus, the theory is in excellent agreement with the experiment. This confirms the validity of the proposed model.
In figure 7a-e, the dimensionless parameter β increases gradually from 5 to 98. In figure 7a, where parameter β is the smallest, the field gradient is considered weak. According to the model predictions,  the incoming nanorod lands directly on top of the pinned one. In figure 7b, parameter β is greater than in figure 7a and the incoming nanorod also starts movement from a more distant position. As a result, the trajectory of the incoming nanorod is distinct: the incoming nanorod first passes the pinned one and is tempted to land next to it. But when its head almost passes the pole of the pinned nanorod where the local field is stronger than the external one, its Y-component of velocity reverses the sign reflecting the change in the force field. The incoming nanorod first moves downward then drifts upward and finally jumps on top of the pinned one. These manoeuvres are illustrated by the last three purple points in figure 7b. A similar behaviour of a nanorod is shown in figure 7c with its initial position closer to the pinned one and a stronger field gradient acting on it. Figure 8 shows the Y-coordinate of the centre of mass of the incoming nanorod as a function of time for the manoeuvres illustrated in figure 7b,c. The transition region, pointed to by the arrows, where the nanorod is about to change the direction of movement cannot be resolved owing to an insufficient frame rate of the camera. However, one can clearly see that the slopes, i.e. the Y-components of velocity, remain almost constant before and after the moment when the nanorod stops. The time needed for a nanorod to change the direction of movement is approximately 0.1 s, and after this transition period the nanorod takes on a constant velocity and quickly approaches the pinned one.
This overshooting is not related to inertia because the Reynolds number is very small [49][50][51][52][53][54][55]. This change of velocity direction is completely governed by the non-uniform magnetic field and can be understood by considering the interactions between the head of the incoming nanorod (−Q) and the tail of the pinned one (+Q). One can neglect the interactions between other distant poles. Following this assumption, the Y-component of the magnetic force between these two poles can be calculated using where α is always positive. When the head of the incoming nanorod is above the tail of the pinned one and the inequality Y − l/2 − L/2 > 0 holds true, the force F Y is always negative indicating that the nanorod moves always downwards. If the incoming nanorod passes the pinned nanorod by an infinitesimally small distance as shown in figure 7b,c, the first term on the right hand side of equation (6.1) becomes positive. As the incoming nanorod keeps moving downwards, the force F Y may decrease to zero and then flip the direction at some critical point. After this moment, the incoming nanorod will drift upwards and finally will jump on top of the pinned one. The nanorods in figure 7d,e had the same initial X-coordinate (X/L = 0.1). However, as the field gradient for the case in figure 7d is smaller relative to that in figure 7e, the smaller gradient was not able to defeat the force field of the pinned nanorod, and the incoming nanorod landed on top of the pinned one. By contrast, at the dimensionless field gradient β = 98, we were able to place the nanorods side by side next to each other. Thus, the proposed theory completely explains the experimental observations and can guide the remote controlled placement of the nanorods [35].

Conclusion
We present a complete analysis of the dynamics of interacting magnetic nanorods subject to a nonuniform external magnetic field. The magnetostatic interactions between long magnetic nanorods are described through the interactions of their poles carrying 'magnetic charges'. The energy landscape was studied theoretically and all minima and maxima of the energy surface were specified. Then we described the two-dimensional dynamics of magnetic nanorods when their resistance is controlled by the viscous drag. Using the phase portrait of this dynamic system we described the regions of initial positions from which the free nanorod can be placed sidewise next to the pinned one. This theory was then confirmed in experiments with nickel nanorods. We showed that a strong repulsion between nanorods can be defeated by applying a non-uniform magnetic field with a strong gradient in the direction of nanorod alignment. With the aid of the proposed theory, one can build different lattices, microstructures and composite materials with the controlled inter-rod spacing. Therefore, various properties of nanocomposites, such as magnetic, optical, electrical and mechanical properties, can be tuned by changing the inter-rod spacing by applying a non-uniform magnetic field during the composite formation.
Data accessibility. All movies used in the presented analysis are available in the electronic supplementary material. Funding statement. We greatly acknowledge support of the US Air Force Office of Scientific Research, grant FA9550-12-1-0459 managed, by Dr Ali Sayir.

Appendix A. Numerical generation of separatrices
To generate the separatrices numerically, we have to linearize the dynamic system in the vicinities of the saddle points [51]. This linearization results in the following equations where all partial derivatives in the matrix are evaluated at the saddle points (X * , Y * ). Each saddle point generates four branches of separatrices shown in figure 5a-c. Whether the velocity vector is pointing towards or away from the saddle point depends on the sign of the corresponding eigenvalue with the 'plus' implying the divergence of the vector field and 'minus' implying convergence of the vector field towards the saddle point. After this movement from the singular points, the separatrices can be generated by solving equation (5.1) with the initial condition at (X 1 , Y 1 ).  Resulting separatrices generated using the described movement from two saddle points.
The linearized matrix at these two points is calculated as Taking δs = 5 × 10 −3 , this movement is illustrated in figure 9a.