Exemplo n.º 1
0
    def test_ram_copy(self):
        particle = [Particle(position=[0.0, 0.0, 0.0])]
        system = System(particle)
        t = TrajectoryRam()
        t[0] = system
        t[0].particle[0].position = numpy.array([1.0, 1.0, 1.0])
        # print system.particle[0].position, t[0].particle[0].position
        # print id(t[0].particle[0])
        # print id(t[0].particle[0])

        particle = [Particle(position=[0.0, 0.0, 0.0])]
        system = System(particle)
        s = System(particle)
        t = TrajectoryRamFull()
        t[0] = system
        s.update(t[0])
        s.particle[0].position = numpy.array([1.0, 1.0, 1.0])
        # print system.particle[0].position, t[0].particle[0].position, s.particle[0].position
        # print id(t[0].particle[0])
        # print id(t[0].particle[0])

        particle = [Particle(position=[0.0, 0.0, 0.0])]
        system = System(particle)
        t = TrajectoryRamFull()
        t[0] = system
        system.particle[0].position = numpy.array([1.0, 1.0, 1.0])
Exemplo n.º 2
0
 def test_callback_copy(self):
     import copy
     from atooms.trajectory.decorators import filter_species
     particle = [Particle(species='A'), Particle(species='B')]
     system = System(particle)
     t = TrajectoryRamFull()
     t[0] = system
     t.add_callback(copy.deepcopy)
     t.add_callback(filter_species, 'A')
     self.assertEqual(t[0].distinct_species(), ['A'])
     t.callbacks.pop()
     t.callbacks.pop()
     self.assertEqual(t[0].distinct_species(), ['A', 'B'])
Exemplo n.º 3
0
 def setUp(self):
     import copy
     particle = [
         Particle(position=[0.0, 0.0, 0.0], species='A', mass=1.0),
         Particle(position=[1.0, 1.0, 1.0], species='B', mass=2.0),
     ]
     cell = Cell([2.0, 2.0, 2.0])
     self.system = []
     self.system.append(System(copy.deepcopy(particle), cell))
     self.system.append(System(copy.deepcopy(particle), cell))
     self.inpfile = '/tmp/test_trajectory'
     self.inpdir = '/tmp/test_trajectory.d'
     from atooms.core.utils import mkdir
     mkdir(self.inpdir)
Exemplo n.º 4
0
 def test_ram(self):
     particle = [Particle(position=[0.0, 0.0, 0.0])]
     system = System(particle)
     t = TrajectoryRam()
     t[0] = system
     particle[0].position = numpy.array([1.0, 1.0, 1.0])
     self.assertFalse(
         (t[0].particle[0].position == particle[0].position).all())
Exemplo n.º 5
0
 def test_ram_inplace(self):
     particle = [Particle(position=[0.0, 0.0, 0.0])]
     system = System(particle)
     t = TrajectoryRam()
     t[0] = system
     particle[0].position += 1.0
     self.assertFalse(
         (t[0].particle[0].position == particle[0].position).all())
Exemplo n.º 6
0
 def test_ram_full(self):
     particle = [Particle(position=[0.0, 0.0, 0.0])]
     system = System(particle)
     t = TrajectoryRamFull()
     t[0] = system
     system.particle[0].position = numpy.array([2.0, 2.0, 2.0])
     t[0] = system
     particle[0].position += 1.0
     self.assertFalse(
         (t[0].particle[0].position == particle[0].position).all())
Exemplo n.º 7
0
 def test_change_species(self):
     from copy import deepcopy
     from atooms.system import System, Particle
     system_A = System([Particle(species='A'), Particle(species='B')])
     system_C = System([Particle(species='0'), Particle(species='1')])
     system_F = System([Particle(species='1'), Particle(species='2')])
     from atooms.trajectory.decorators import change_species
     # DO nothing here
     self.assertTrue(
         _equal(system_A, change_species(deepcopy(system_A), 'A')))
     self.assertTrue(
         _equal(system_C, change_species(deepcopy(system_C), 'C')))
     self.assertTrue(
         _equal(system_F, change_species(deepcopy(system_F), 'F')))
     # Change
     self.assertTrue(
         _equal(system_C, change_species(deepcopy(system_A), 'C')))
     self.assertTrue(
         _equal(system_F, change_species(deepcopy(system_A), 'F')))
     self.assertTrue(
         _equal(system_A, change_species(deepcopy(system_C), 'A')))
     self.assertTrue(
         _equal(system_F, change_species(deepcopy(system_C), 'F')))
     self.assertTrue(
         _equal(system_A, change_species(deepcopy(system_F), 'A')))
     self.assertTrue(
         _equal(system_C, change_species(deepcopy(system_F), 'C')))
Exemplo n.º 8
0
    def test_write_initial_state(self):
        p = [
            PairPotential("lennard_jones", {
                "epsilon": 1.0,
                "sigma": 1.0
            }, [1, 1], CutOff("CS", 2.5))
        ]
        i = [Interaction(p, "atomic")]
        s = System()
        s.particle = [
            Particle(position=[1.0, 1.0, 1.0], velocity=[0.0, 0.0, 0.0])
        ]
        s.cell = Cell([1.0, 1.0, 1.0])
        with TrajectoryHDF5('/tmp/test_hdf5.h5', 'w') as t:
            t.write_interaction(i)
            t.write(s, 0)

        with TrajectoryHDF5('/tmp/test_hdf5.h5', 'r') as t:
            i = t.read_interaction()
            s = t[0]
Exemplo n.º 9
0
    def read_sample(self, frame):
        # Read number of particles
        idx, _ = self._index_db['NUMBER OF ATOMS'][frame]
        self._fh.seek(idx)
        self._fh.readline()
        data = self._fh.readline()
        npart = int(data)

        # Build the system
        system = System()
        system.particle = []
        for i in range(npart):
            if self.first_particle > 0 and i < self.first_particle:
                continue
            if self.last_particle > 0 and i >= self.last_particle:
                break
            system.particle.append(Particle())

        # Add cell
        idx, data = self._index_db['BOX BOUNDS'][frame]
        self._fh.seek(idx)
        self._fh.readline()
        ndim = len(data.split())  # line is ITEM: BOX BONDS pp pp pp
        L, center = [], []
        for i in range(ndim):
            data = [float(x) for x in self._fh.readline().split()]
            L.append(data[1] - data[0])
            center.append((data[1] + data[0]) / 2)
        system.cell = Cell(numpy.array(L), center=numpy.array(center))

        # Read atoms data
        idx, data = self._index_db['ATOMS'][frame]
        fields = data.split()  # fields on a line
        _ = self._fh.readline()

        # Add interaction if forces are present
        # In atooms, forces belong to the interaction, not to particles
        if 'fx' in fields or 'fy' in fields or 'fz' in fields:
            # TODO: this won't work with first and last particles
            system.interaction = Interaction([])  # empty list of potentials
            system.interaction.forces = numpy.ndarray((npart, ndim))
        else:
            interaction = None

        for i in range(npart):
            # Limit reading the ATOMS section if requested
            if self.first_particle > 0 and i < self.first_particle:
                continue
            if self.last_particle > 0 and i >= self.last_particle:
                break
            data = self._fh.readline().split()
            # Accept unsorted particles by parsing their id
            if 'id' in fields:
                idx = int(data[0]) - 1
            else:
                idx = i
            # Populate particle's attributes by reading fields
            for j, field in enumerate(fields):
                if field in self._cbk:
                    self._cbk[field](data[j], idx, system)
                else:
                    # We should store these fields in particle anyway
                    pass

        return system
Exemplo n.º 10
0
        self.system = system
        self.delta = delta

    def run(self, steps):
        for i in range(steps):
            for nr, particle in enumerate(self.system.particle):
                #TODO: dodaj zmianę pozycji w każdym kroku o wartość [nr+1] w każdym kierunku
                pass


#callback function, called by atooms after specified amount of steps
def callback(sim, initial_position, db=None):
    positions = numpy.array([x.position for x in sim.system.particle])
    #TODO: narysuj pozycje punktów w każdym kroku
    # hint: ax2d.scatter(?,?,label=sim.current_step), ax3d.scatter(?,?,?,label=sim.current_step)


ax2d = plt.subplot(121)
ax3d = plt.subplot(122, projection='3d')

system = System(
    particle=[Particle(position=[10.0, 10.0, 10.0]) for _ in range(10)])

simulation = Simulation(RandomWalk(system))
simulation.add(callback,
               5,
               initial_position=[p.position.copy() for p in system.particle])
simulation.run(10)
simulation.run(10)
simulation.run(10)
plt.show()