Would it be possible to just extend binary_shan_chen.mako to handle the case of more than 2 lattices? len(grids) in mako should give you the total number of lattices in use.