Exemple #1
0
    def __init__(self,
                 trajectory,
                 kgrid=None,
                 tgrid=None,
                 nk=8,
                 tsamples=60,
                 dk=0.1,
                 kmin=1.0,
                 kmax=10.0,
                 ksamples=10,
                 norigins=-1):
        FourierSpaceCorrelation.__init__(self, trajectory, [kgrid, tgrid], ('k', 't'), \
                                         'fkt.self', 'self intermediate scattering function F_s(k,t)',
                                         'pos-unf', nk, dk, kmin, kmax, ksamples)
        # Setup time grid
        # Before setting up the time grid, we need to check periodicity over blocks
        check_block_size(self.trajectory.steps, self.trajectory.block_size)
        if tgrid is None:
            self.grid[1] = [0.0] + logx_grid(
                trajectory.timestep, trajectory.total_time * 0.75, tsamples)
        self._discrete_tgrid = setup_t_grid(trajectory, self.grid[1])
        self.skip = adjust_skip(trajectory, norigins)

        # TODO: Can this be moved up?
        self.k_sorted, self.k_selected = self._decimate_k()
Exemple #2
0
    def __init__(self,
                 trajectory,
                 kgrid=None,
                 tgrid=None,
                 nk=1,
                 tsamples=1,
                 dk=0.1,
                 kmin=1.0,
                 kmax=10.0,
                 ksamples=10,
                 norigins=-1,
                 fix_cm=False,
                 normalize=True):
        FourierSpaceCorrelation.__init__(self, trajectory, [kgrid, tgrid],
                                         norigins, nk, dk, kmin, kmax,
                                         ksamples, fix_cm, normalize)
        # Before setting up the time grid, we need to check periodicity over blocks
        try:
            check_block_size(self.trajectory.steps, self.trajectory.block_size)
        except IndexError as e:
            _log.warn(
                'issue with trajectory blocks, the time grid may not correspond to the requested one (%s)',
                e.message)

        # Setup time grid
        if self.grid[1] is None:
            self.grid[1] = logx_grid(0.0, self.trajectory.total_time * 0.75,
                                     tsamples)
        else:
            # If the values are normalized, we make sure the
            # user-provided time grid includes t=0. It is removed
            # after normalization
            if self.normalize:
                if self.grid[1][0] > 0:
                    _log.info(
                        'adding t=0 to the time grid to normalize F_s(k,t)')
                    self.grid[1] = [0.0] + self.grid[1]

        # When a single time origin is requested,
        # make sure no additional time origins except the first frame is used
        self._discrete_tgrid = setup_t_grid(self.trajectory,
                                            self.grid[1],
                                            offset=norigins != '1'
                                            and norigins != 1)
Exemple #3
0
 def __init__(self,
              trajectory,
              kgrid=None,
              tgrid=None,
              nk=100,
              dk=0.1,
              tsamples=60,
              kmin=1.0,
              kmax=10.0,
              ksamples=10):
     FourierSpaceCorrelation.__init__(
         self, trajectory, [kgrid, tgrid], ('k', 't'), 'fkt.total',
         'intermediate scattering function F(k,t)', 'pos', nk, dk, kmin,
         kmax, ksamples)
     # Setup time grid
     check_block_size(self.trajectory.steps, self.trajectory.block_size)
     if tgrid is None:
         self.grid[1] = logx_grid(0.0, trajectory.total_time * 0.75,
                                  tsamples)
     self._discrete_tgrid = setup_t_grid(trajectory, self.grid[1])
Exemple #4
0
 def test_block_size(self):
     from atooms.trajectory.utils import check_block_size, get_block_size
     steps = [2**i for i in range(5)]
     block = get_block_size(steps)
     check_block_size(steps, block)
Exemple #5
0
def main(args):
    """Convert trajectory `file_inp` to `file_out`."""
    args.file_inp = args.file_inp[0]

    if args.fields is not None:
        args.fields = args.fields.split(',')

    if args.out is not None and not args.out in trajectory.Trajectory.formats:
        # available_formats()
        __import__('pdb').set_trace()
        raise ValueError('Unknown output format %s' % args.out)

    if args.file_out == '-':
        args.file_out = '/dev/stdout'

    if args.verbose:
        setup_logging('atooms', 20)
        import atooms.core.progress
        if args.file_out != '/dev/stdout':
            atooms.core.progress.active = True

    if args.folder:
        t = trajectory.folder.Foldered(args.file_inp, cls=args.inp)
    else:
        t = trajectory.Trajectory(args.file_inp, fmt=args.inp)

    # If no output format is provided we use the input one
    if args.out is None:
        out_class = t.__class__
    else:
        out_class = args.out

    if args.precision is not None:
        t.precision = args.precision

    if args.flatten_steps:
        t.steps = range(1, len(t) + 1)

    # Reset random number generator
    if args.seed:
        random.seed(args.seed)

    # Trick to allow some trajectory formats to set the box side.
    # This way the cell is defined as we read the sample (callbacks
    # will not do that).
    if args.side is not None:

        def fix_cell(system, side):
            from atooms.system import Cell
            system.cell = Cell(side)
            return system

        L = args.side.split(',')
        if len(L) == 1:
            t.add_callback(fix_cell, [L, L, L])
        else:
            t.add_callback(fix_cell, [float(_) for _ in L])

    # Define slice.
    # We interpret --first N --last N as a request of step N
    if args.last == args.first and args.last is not None:
        args.last += 1
    sl = fractional_slice(args.first, args.last, args.skip, len(t))

    # Unfold if requested
    if args.unfold:
        tu = trajectory.Unfolded(t)  #, fix_cm=True)
    else:
        tu = t

    # Fix CM and fold back
    if args.fix_cm:
        tu.add_callback(trajectory.fix_cm)
        tu.add_callback(trajectory.fold)

    # Here we could you a trajectory slice t[sl] but this will load
    # everything in ram (getitem doesnt provide a generator). This
    # will be fixed with python 3.
    ts = trajectory.Sliced(tu, sl)

    # Change number of particles
    if args.N > 0:

        def decimate_system(system, N):
            from atooms.system.particle import decimate
            system.particle = decimate(system.particle, N)
            return system

        ts.register_callback(decimate_system, args.N)
    # Change density and temperature
    if args.rho is not None:
        ts.register_callback(trajectory.decorators.set_density, args.rho)
    if args.temperature is not None:
        ts.register_callback(trajectory.decorators.set_temperature,
                             args.temperature)
    # Change species layout if requested
    if args.species_layout is not None:
        ts.register_callback(trajectory.decorators.change_species,
                             args.species_layout)
    # Sort by species id
    if args.species_sort:
        ts.register_callback(trajectory.decorators.sort)

    # We enforce regular periodicity; steps is None is trajectory is not periodic
    try:
        steps = check_block_size(ts.steps, ts.block_size, prune=True)
    except IndexError:
        print('# Warning: something wrong with periodicity check.')
        print(
            '# We will proceed, but you should check the converted trajectory.'
        )
        steps = ts.steps

    #
    # ---------------------
    # Trajectory conversion
    # ---------------------
    #
    include_list, exclude_list = [], []
    if len(args.fields_include) > 0:
        include_list = args.fields_include.split(',')
    if len(args.fields_exclude) > 0:
        exclude_list = args.fields_exclude.split(',')
    fout = trajectory.convert(ts,
                              out_class,
                              args.file_out,
                              fields=args.fields,
                              include=include_list,
                              exclude=exclude_list,
                              steps=steps)

    if args.ff:
        from atooms.trajectory.hdf5 import add_interaction_hdf5
        add_interaction_hdf5(fout, args.ff)

    if args.verbose and args.file_out != '/dev/stdout':
        print('# converted %s to %s' % (args.file_inp, fout))

    t.close()
Exemple #6
0
 def test_block_size_5(self):
     more = [0, 1, 2, 4, 8, 16, 24, 32]
     more += [40 + i for i in more]
     self.assertEqual(utils.get_block_size(more), 8)
     self.assertEqual(
         utils.check_block_size(more, utils.get_block_size(more)), more)
Exemple #7
0
 def test_block_size_4(self):
     more = [0, 1, 2, 4, 8, 16]
     more += [32 + i for i in more]
     self.assertEqual(utils.get_block_size(more), 6)
     self.assertEqual(
         utils.check_block_size(more, utils.get_block_size(more)), more)
Exemple #8
0
 def test_block_size_3(self):
     more = [0, 1, 2, 4, 8, 16]
     more += [32, 33, 34, 36, 40, 48]
     self.assertEqual(utils.get_block_size(more), 6)
     self.assertEqual(
         utils.check_block_size(more, utils.get_block_size(more)), more)
Exemple #9
0
 def test_block_size_2(self):
     more = [0, 1, 10, 11, 20, 21]
     self.assertEqual(utils.get_block_size(more), 2)
     self.assertEqual(
         utils.check_block_size(more, utils.get_block_size(more)), more)
Exemple #10
0
 def test_block_size_1(self):
     more = [0, 1, 2, 3, 4]
     self.assertEqual(utils.get_block_size(more), 1)
     self.assertEqual(
         utils.check_block_size(more, utils.get_block_size(more)), None)