code: public static Set<PhysicalEntity> getRelatedPhysicalEntities(BioPAXElement element,
  		Set<PhysicalEntity> pes)
  	{
  		if (pes == null) pes = new HashSet<PhysicalEntity>();
  
  		if (element instanceof PhysicalEntity)
  		{
  			PhysicalEntity pe = (PhysicalEntity) element;
  			if (!pes.contains(pe))
  			{
  				pes.add(pe);
  	
  				for (Complex cmp : pe.getComponentOf())
  				{
  					getRelatedPhysicalEntities(cmp, pes);
  				}
  
  				// This is a hack for BioPAX graph. Equivalence relations do not link members and
  				// complexes because members cannot be addressed. Below call makes sure that if the
  				// source node has a generic parents or children and they appear in a complex, we
  				// include the complex in the sources.
  				addEquivalentsComplexes(pe, pes);
  			}
  		}
  		else if (element instanceof Xref)
  		{
  			for (XReferrable xrable : ((Xref) element).getXrefOf())
  			{
  				getRelatedPhysicalEntities(xrable, pes);
  			}
  		}
  		else if (element instanceof EntityReference)
  		{
  			EntityReference er = (EntityReference) element;
  
  			for (SimplePhysicalEntity spe : er.getEntityReferenceOf())
  			{
  				getRelatedPhysicalEntities(spe, pes);
  			}
  
  			for (EntityReference parentER : er.getMemberEntityReferenceOf())
  			{
  				getRelatedPhysicalEntities(parentER, pes);
  			}
  		}
  
  		return pes;
  	}
docs: Gets the related PhysicalEntity objects of the given BioPAXElement, in level 3 models.
  
  @param element Element to get related PhysicalEntity objects
  @param pes Result set. If not supplied, a new set will be initialized.
  @return Related PhysicalEntity objects