From the varaible doc page:
The sum(x), min(x), max(x), ave(x), and trap(x) functions each take 1
argument which is of the form "c_ID" or "c_ID\[N\]" or "f_ID" or
"f_ID\[N\]". The first two are computes and the second two are fixes;
the ID in the reference should be replaced by the ID of a compute or
fix defined elsewhere in the input script. The compute or fix must
produce either a global vector or array.
It looks like you are giving sum() a per-atom array, which you can't do.
You want to use compute reduce instead in that case.
Steve