Calculating hydrogen bond number in periodic box

I tried to modify the script file to calculate the hydrogen number in the periodic box.

However, the script file cannot support the periodic system.

The error message is " Cannot operate upon infinite SymmetrySystem (function/property "Molecules") "

Original file is attatched belows.

Which line should I change?