Formal charge Calculate

Dear

I'm writing a script for the Materials Studio where I need to calculate the total formal charge of each xsd file. So far, only managed to calculate the formal charge for each atom individually and print these results in the output file. My question is:

it is possible to add up the formal charges of each atom previously calculated for the total formal charge of the \$ doc?

Below is the script I am using to calculate the formal charge for each atom.

foreach my \$atom (@{\$doc->Atoms}){


my \$formalCharge = \$atom->FormalCharge

printf "Formal charge on atom %s = %d\n", \$atom->Name, \$formalCharge->Numerator;

}