# How does a magnetic field do work on rotating a current loop?

Lorentz force tells us that the force on a charged particle by a magnetic field is always perpendicular to its velocity. So its a pretty well known fact that a magnetic field doesn't do work.

But we can also calculate the magnetic torque on a current loop placed in a magnetic field, and We can see that the work done in rotating the loop would be $$\int𝜏dθ$$ and we can end up with the expression for the work done by magnetic field in rotating the current loop by an angle $$θ$$, and it would be$$MB(cos θ_1−cosθ_2)$$

Where does this work arise from? The Magnetic field cant do work on the individual electrons, so how can it do some work on the wire as a whole?

Magnetic force on current-carrying piece of wire, $$I\mathbf L\times\mathbf B$$ (the "BIL force", the motor effect force, the Ampere force, the Lagrange force) is not the Lorentz force. It is a macroscopic force acting on the conductor body, rather than on a single charged particle. Since the conductor can and does move in direction of this force, this force can and does work on the conductor. This is how electric motors work.

This macroscopic force, since it acts on the whole conductor, rather than just on the mobile charge carriers, is result of 1) the Lorentz force due to external magnetic field acting on the conductor lattice, and 2) the internal forces from the mobile charge carriers acting on the conductor lattice.

In terms of which forces are working when loop turns due to unstable angle in external magnetic field, it is the above macroscopic magnetic force, which is a net result of both external forces and internal forces, that does the work.

In terms of which bodies are doing the work, it is not the magnetic field that does the work, but the mobile charge carriers do the work on the conductor lattice, and the conductor lattice does work back on those mobile charge carriers. These two works need not be the same in magnitude, because velocities are not the same (the current moves with respect to the conductor lattice). The difference between these two work magnitudes is, due to work-energy theorem, related to change of total kinetic energy of the loop (not exactly equal, due to work of current on itself (self-induced EMF)).

Yes you are quite right, all work done by electromagnetic fields on charged particles comes from the electric contribution. This is because the formula for force on a particle owing to a electromagnetic field is $${\bf f} = q \left( {\bf E} + {\bf v} \times {\bf B} \right)$$ and therefore the rate of doing work on the charge is $${\bf f} \cdot {\bf v} = q {\bf E} \cdot {\bf v}.$$

For a current-carrying wire in a magnetic field, if the wire does not move then no work is done. The magnetic force on the charges moving along the wire is in a direction perpendicular to their motion. It causes the charges (electrons in practice) to bunch up a little on one side of the wire. This in turn means the other charges in the wire push back on them, with mostly electric forces, so that they settle down to no net acceleration. There is also a force on whatever is holding the wire in place: this is the Newton's third law partner to the force on the charges inside the wire.

If we now allow the wire to move in the direction of this net force then work will be done. At the point of interaction of charge and field, this work is coming from the electric contribution to the force, as we already noted.