예제 #1
0
    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'))
예제 #2
0
 def test_python_stop(self):
     from atooms.simulation import target_python_stop
     f = '/tmp/test_simulation/python/trajectory'
     s = Simulation(DryRun(), output_path=f)
     s.add(target_python_stop, Scheduler(20), '{current_step} == 40')
     s.add(write_thermo, Scheduler(10))
     s.run(100)
     self.assertEqual(s.current_step, 40)
예제 #3
0
 def test_target_rmsd(self):
     f = '/tmp/test_simulation/config/trajectory'
     with self.assertRaises(IndexError):
         s = Simulation(DryRun(), output_path=f, steps=100)
         s.add(target_rmsd, Scheduler(20))
         s.run()
     s = Simulation(DryRun(), output_path=f, steps=100)
     s.add(target_rmsd, Scheduler(20), 1.0)
     s.run()
예제 #4
0
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()
예제 #5
0
    def test_target_restart(self):
        f = '/tmp/test_simulation/restart/trajectory'
        s = Simulation(DryRun(), output_path=f)
        s.add(write_thermo, Scheduler(20))
        s.run(100)
        data = numpy.loadtxt(f + '.thermo', unpack=True)
        self.assertEqual(int(data[0][-1]), 100)

        s = Simulation(DryRun(), output_path=f, restart=True)
        s.add(write_thermo, Scheduler(20))
        s.run(200)
        data = numpy.loadtxt(f + '.thermo', unpack=True)
        self.assertEqual(int(data[0][-1]), 200)
예제 #6
0
 def test_target_walltime(self):
     """Check that walltime targeting works."""
     from atooms.simulation.observers import target_walltime
     f = '/tmp/test_simulation/config/trajectory'
     s = Simulation(DryRun(), output_path=f, steps=1000000000)
     s.add(target_walltime, Scheduler(20), 1.)
     s.run()
     self.assertTrue(s.wall_time() > 1.)
예제 #7
0
    def test_steps(self):
        """Test steps scheduling"""
        def store_list(s, db):
            db.append(s.current_step)

        db = []
        s = Simulation(DryRun(), output_path=None, steps=18)
        s.add(store_list, Scheduler(steps=[1, 2, 4, 8]), db=db)
        s.run()
        self.assertEqual(db, [0, 1, 2, 4, 8])
예제 #8
0
    def test_block(self):
        """Test periodic block scheduling"""
        def store_list(s, db):
            db.append(s.current_step)

        db = []
        s = Simulation(DryRun(), output_path=None, steps=18)
        s.add(store_list, Scheduler(block=[1, 2, 4, 8]), db=db)
        s.run()
        self.assertEqual(db, [0, 1, 2, 4, 8, 9, 10, 12, 16, 17, 18])
예제 #9
0
    def test_shell_stop(self):
        from atooms.simulation import shell_stop
        f = '/tmp/test_simulation/shell/trajectory'
        s = Simulation(DryRun(), output_path=f)
        s.add(shell_stop, Scheduler(steps=[20]), 'exit 1')
        s.add(write_thermo, Scheduler(10))
        s.run(100)
        self.assertEqual(s.current_step, 20)

        s = Simulation(DryRun(), output_path=f)
        s.add(shell_stop, Scheduler(20), 'exit 0')
        s.add(write_thermo, Scheduler(10))
        s.run(100)
        self.assertEqual(s.current_step, 100)

        # Test formatted string
        s = Simulation(DryRun(), output_path=f)
        s.add(shell_stop, Scheduler(20),
              '[ {sim.current_step} -eq 40 ] && exit 1 || exit 0')
        s.run(100)
        self.assertEqual(s.current_step, 40)
예제 #10
0
    def test_scheduler(self):
        class Simulation:
            def __init__(self):
                self.current_step = 0

        s = Scheduler(3)
        sim = Simulation()
        inext = []
        for i in range(8):
            sim.current_step = i
            inext.append(s(sim))

        self.assertEqual(inext, [3, 3, 3, 6, 6, 6, 9, 9])