# NOTE: Add pbc before used pbc wrap -compound res -all
package require pbctools
package require topotools
# -------------------------- Create output dir --------------------------
if {![file exists "coor-xyz-3A"]} {
file mkdir "coor-xyz-3A"
}
# Set box (only once)
pbc set [list 53 53 53 90 90 90]
pbc box -on
pbc wrap -all -compound res
set sel [atomselect top "name Li"]
foreach i [$sel list] {
set sel2 [atomselect top "same residue as {pbwithin 3.0 of index $i}"]
set selec [atomselect top "name O09 and same residue as {pbwithin 3.0 of index $i}"]
set selemc [atomselect top "name O00 and same residue as {pbwithin 3.0 of index $i}"]
set selpf6 [atomselect top "name F and same residue as {pbwithin 3.0 of index $i}"]
pbc wrap -now -compound res -center com -centersel "index $i"
set n_ec [$selec num]
set n_emc [$selemc num]
set n_pf6 [$selpf6 num]