src/amuse/datamodel/particles.py
def ensure_presence_of(self, x):
        """
        Add one particle to the set, but only if not already in set.

        :parameter particle: particle to add

        >>> particles = Particles()
        >>> print len(particles)
        0
        >>> particle = Particle()
        >>> p1=particles.ensure_presence_of(particle)  # doctest:+ELLIPSIS
        >>> print len(particles)
        1
        >>> p2=particles.ensure_presence_of(particle)  # doctest:+ELLIPSIS
        >>> print len(particles)
        1
        >>> p1==p2
        True
        >>> particle2 = Particle()
        >>> set=particle.as_set()
        >>> p3=set.add_particle(particle2)
        >>> set2=particles.ensure_presence_of(set)
        >>> len(particles)
        2
        >>> len(set2)
        2


        """
        try:
          not_in_set=x-x.get_intersecting_subset_in(self)
          self.add_particles(not_in_set)
          return x.get_intersecting_subset_in(self)
        except:  
          if x in self:
              return x.as_particle_in_set(self)
          else:
              return self.add_particle(x)

        Add one particle to the set, but only if not already in set.

        :parameter particle: particle to add

        >>> particles = Particles()
        >>> print len(particles)
        0
        >>> particle = Particle()
        >>> p1=particles.ensure_presence_of(particle)  # doctest:+ELLIPSIS
        >>> print len(particles)
        1
        >>> p2=particles.ensure_presence_of(particle)  # doctest:+ELLIPSIS
        >>> print len(particles)
        1
        >>> p1==p2
        True
        >>> particle2 = Particle()
        >>> set=particle.as_set()
        >>> p3=set.add_particle(particle2)
        >>> set2=particles.ensure_presence_of(set)
        >>> len(particles)
        2
        >>> len(set2)
        2


        
Add one particle to the set, but only if not already in set.
Add one particle to the set but only if not already in set .
def ensure_presence_of(self, x):
        try:
          not_in_set=x-x.get_intersecting_subset_in(self)
          self.add_particles(not_in_set)
          return x.get_intersecting_subset_in(self)
        except:  
          if x in self:
              return x.as_particle_in_set(self)
          else:
              return self.add_particle(x)
def ensure_presence_of ( self , x ) : try : not_in_set = x - x . get_intersecting_subset_in ( self ) self . add_particles ( not_in_set ) return x . get_intersecting_subset_in ( self ) except : if x in self : return x . as_particle_in_set ( self ) else : return self . add_particle ( x )
Add one particle to the set, but only if not already in set.
Add one particle to the set but only if not already in set .
"""
        Add one particle to the set, but only if not already in set.

        :parameter particle: particle to add

        >>> particles = Particles()
        >>> print len(particles)
        0
        >>> particle = Particle()
        >>> p1=particles.ensure_presence_of(particle)  # doctest:+ELLIPSIS
        >>> print len(particles)
        1
        >>> p2=particles.ensure_presence_of(particle)  # doctest:+ELLIPSIS
        >>> print len(particles)
        1
        >>> p1==p2
        True
        >>> particle2 = Particle()
        >>> set=particle.as_set()
        >>> p3=set.add_particle(particle2)
        >>> set2=particles.ensure_presence_of(set)
        >>> len(particles)
        2
        >>> len(set2)
        2


        """
self
x
particle
particle to add
>>> particles = Particles()
>>> print len(particles)
0
>>> particle = Particle()
>>> p1=particles.ensure_presence_of(particle)  # doctest:+ELLIPSIS
>>> print len(particles)
1
>>> p2=particles.ensure_presence_of(particle)  # doctest:+ELLIPSIS
>>> print len(particles)
1
>>> p1==p2
True
>>> particle2 = Particle()
>>> set=particle.as_set()
>>> p3=set.add_particle(particle2)
>>> set2=particles.ensure_presence_of(set)
>>> len(particles)
2
>>> len(set2)
2
particle to add >>> particles = Particles () >>> print len ( particles ) 0 >>> particle = Particle () >>> p1 = particles . ensure_presence_of ( particle ) # doctest : + ELLIPSIS >>> print len ( particles ) 1 >>> p2 = particles . ensure_presence_of ( particle ) # doctest : + ELLIPSIS >>> print len ( particles ) 1 >>> p1 == p2 True >>> particle2 = Particle () >>> set = particle . as_set () >>> p3 = set . add_particle ( particle2 ) >>> set2 = particles . ensure_presence_of ( set ) >>> len ( particles ) 2 >>> len ( set2 ) 2