def test_config(self): from atooms.trajectory import TrajectoryXYZ f = '/tmp/test_simulation/config/trajectory.xyz' # We do not accept too deep introspection with self.assertRaises(ValueError): # Mute errors temporarily setup_logging(level=50, update=True) s = Simulation(DryRun(), output_path=f, enable_speedometer=False, steps=100) s.add(write, Scheduler(20), 'output', ['system.particle.position']) s.run() # Test generic writer and write_config setup_logging(level=40, update=True) s = Simulation(DryRun(), output_path=f, enable_speedometer=True, steps=100) s.trajectory_class = TrajectoryXYZ s.add(write_config, Scheduler(20)) s.add(write, Scheduler(20), 'output', ['current_step', 'system.cell']) s.run() import os self.assertTrue(os.path.exists(f)) self.assertTrue(os.path.exists(f + '.output'))
def main(params): if params.verbose: setup_logging(level=20) if params.debug: setup_logging(level=10) if params.T is not None: params.integrator = 'nvt' if os.path.exists(params.input_file + '.ff'): params.forcefield = params.input_file + '.ff' output_base = os.path.join(params.output_dir, 'trajectory') mkdir(output_base) cp(params.forcefield, output_base + '.ff') cp(params.forcefield, output_base + '.chk.ff') report_parameters(params.__dict__, output_base + '.params', '%s+%s' % (__version__, __commit__)) report_command(sys.argv[0], params.__dict__, ['output_dir'], output_base + '.cmd') s = RUMD(params.input_file, params.forcefield, integrator=params.integrator, temperature=params.T, dt=params.dt, fixcm_interval=params.fixcm_interval) sa = Simulation(s, output_path=output_base, checkpoint_interval=params.checkpoint_interval, steps=params.steps, restart=params.restart) if params.backend_output: s._suppress_all_output = False s._initialize_output = True s.rumd_simulation.sample.SetOutputDirectory(output_base) s.rumd_simulation.SetOutputScheduling("energies", "linear", interval=params.thermo_interval) s.rumd_simulation.SetOutputScheduling("trajectory", params.config_sampling, interval=params.config_interval) s.rumd_simulation.SetOutputMetaData("trajectory", precision=6, virials=False) if params.config_interval > 0 and params.config_sampling == "logarithmic": s.rumd_simulation.SetBlockSize(params.config_interval) else: s.rumd_simulation.SetBlockSize(params.steps) # Trim target steps to be a multiple of config_interval # params.steps = params.steps / params.config_interval * params.config_interval else: sa.add(write_thermo, Scheduler(params.thermo_interval)) sa.add(write_config, Scheduler(params.config_interval)) sa.run()
def setUp(self): setup_logging(level=40, update=True)
#!/usr/bin/env python import unittest import logging import numpy from atooms.simulation import Simulation, Scheduler, write_thermo, write_config, target_rmsd, write from atooms.backends.dryrun import DryRun from atooms.core.utils import setup_logging, rmd setup_logging(level=40) class Test(unittest.TestCase): def setUp(self): setup_logging(level=40, update=True) def test_no_output(self): # Disable writers completely s = Simulation(DryRun(), output_path=None, steps=10, enable_speedometer=False) s.run() def test_multiple_run_calls(self): """ Multiple calls to run() with varying number of steps should add up correctly. This was not the case in version <= 1.4.3. """ from atooms.system import System
default='{trajectory.filename}.pp.{short_name}.{tag}', help='output path like {pp.trajectory.filename}.pp.{pp.short_name}.{pp.tag}' ) parser.add_argument('--verbose', action='store_true', dest='verbose', help='verbose output') parser.add_argument('--debug', action='store_true', dest='debug', help='debug output') parser.add_argument('--species-layout', dest='species_layout', help='force species layout to F, C or A') argh.add_commands( parser, [msd, vacf, fkt, fskt, chi4qs, chi4qs_opti, gr, sk, skopti, ik]) args = parser.parse_args() postprocessing.correlation.OUTPUT_PATH = args.output if args.verbose: setup_logging('postprocessing', level=20) setup_logging('atooms', level=40) elif args.debug: setup_logging('postprocessing', level=10) setup_logging('atooms', level=40) else: setup_logging('postprocessing', level=40) setup_logging('atooms', level=40) argh.dispatching.dispatch(parser)
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()