code: def select_by_ids(selname, idlist, selection_exists=False, chunksize=20, restrict=None):
      
      idlist = list(set(idlist))  # Remove duplicates
      if not selection_exists:
          cmd.select(selname, 'None')  # Empty selection first
      idchunks = [idlist[i:i+chunksize] for i in range(0, len(idlist), chunksize)]
      for idchunk in idchunks:
          cmd.select(selname, '%s or (id %s)' % (selname, '+'.join(map(str, idchunk))))
      if restrict is not None:
          cmd.select(selname, '%s and %s' % (selname, restrict))
docs: Selection with a large number of ids concatenated into a selection
      list can cause buffer overflow in PyMOL. This function takes a selection
      name and and list of IDs (list of integers) as input and makes a careful
      step-by-step selection (packages of 20 by default)