def unfold_entities(entity_list, target_level):
 if (target_level not in entity_levels):
  raise PDBException(('%s: Not an entity level.' % target_level))
 if (entity_list == []):
  return []
 if isinstance(entity_list, (Entity, Atom)):
  entity_list = [entity_list]
 level = entity_list[0].get_level()
 if (not all(((entity.get_level() == level) for entity in entity_list))):
  raise PDBException('Entity list is not homogeneous.')
 target_index = entity_levels.index(target_level)
 level_index = entity_levels.index(level)
 if (level_index == target_index):
  return entity_list
 if (level_index > target_index):
  for i in range(target_index, level_index):
   entity_list = itertools.chain.from_iterable(entity_list)
 else:
  for i in range(level_index, target_index):
   entity_list = set((entity.get_parent() for entity in entity_list))
 return list(entity_list)

def unfold_entities ( entity_list , target_level ) : if ( target_level not in entity_levels ) : raise PDBException ( ( '%s: Not an entity level.' % target_level ) ) if ( entity_list == [ ] ) : return [ ] if isinstance ( entity_list , ( Entity , Atom ) ) : entity_list = [ entity_list ] level = entity_list [ 0 ] . get_level ( ) if ( not all ( ( ( entity . get_level ( ) == level ) for entity in entity_list ) ) ) : raise PDBException ( 'Entity list is not homogeneous.' ) target_index = entity_levels . index ( target_level ) level_index = entity_levels . index ( level ) if ( level_index == target_index ) : return entity_list if ( level_index > target_index ) : for i in range ( target_index , level_index ) : entity_list = itertools . chain . from_iterable ( entity_list ) else : for i in range ( level_index , target_index ) : entity_list = set ( ( entity . get_parent ( ) for entity in entity_list ) ) return list ( entity_list )
unfold entities list to a child level .