class LammpsNptSimulationScaffold(object):
    """ a development scafford for LammpsNptSimulation

    Tasks are usually run within the TaskManager.  This scafford provides a standard
    interface for running tasks

    """
    def __init__(self,
                 potential_definition,
                 structures_definition,
                 task_configuration,
                 parameters):

        self.potential_definition = potential_definition 
        self.structure_definition = structures_definition
        self.task_configuration = task_configuration
        self.parameters = parameters

        self.lammps_task = LammpsNptSimulation(**task_configuration)

    def run(self,task_configuration=None): 

        if task_configuration is not None:
            self.task_configuration = task_configuration
        self.on_init(self.task_configuration)
        self.on_config(self.task_configuration)
        self.on_ready(self.task_configuration)

    def on_init(self,task_configuration):
        self.task_configuration['potential'] = self.potential_definition
        self.task_configuration['parameters'] = self.parameters
        self.lammps_task.on_init(task_configuration)

    def on_config(self,task_configuration):
        self.lammps_task.on_config(task_configuration)

    def on_ready(self,task_configuration):
        self.lammps_task.on_ready(task_configuration)

        time_sleep = 0.1
        while (self.lammps_task.process.poll() is None):
            time.sleep(time_sleep)
        lammps_task = None
def test__on_ready():
    task_name = configuration['task']['task_name']
    task_directory = configuration['task']['task_directory']
    structure_filename = configuration['structure']['filename']
    restart=False
    fullauto=False

    cleanup(task_directory)
    assert not os.path.exists(task_directory)
    assert 'potential' in configuration
    assert 'parameters' in configuration
    #<--- code setup
    from pypospack.task.lammps import LammpsNptSimulation
    lammps_task = LammpsNptSimulation(
            task_name = task_name,
            task_directory = task_directory,
            structure_filename = structure_filename)
    lammps_task.on_init(configuration)
    lammps_task.on_config(configuration)
    #<--- test setup
    assert os.path.exists(task_directory)
    assert lammps_task.status == 'READY'
    #<--- code being testing
    lammps_task.on_ready(configuration)

    assert type(lammps_task.conditions_INIT) == OrderedDict
    assert type(lammps_task.conditions_CONFIG) == OrderedDict
    assert type(lammps_task.conditions_READY) == OrderedDict
    assert type(lammps_task.conditions_RUNNING) == OrderedDict
    assert type(lammps_task.conditions_POST) == OrderedDict
    assert type(lammps_task.conditions_FINISHED) == OrderedDict

    assert lammps_task.conditions_INIT['task_directory_created']
    assert all([v for k,v in lammps_task.conditions_INIT.items()]) == True
    assert lammps_task.conditions_CONFIG['potential_initialized'] == True
    assert lammps_task.conditions_CONFIG['parameters_processed'] == True
    assert all([v for k,v in lammps_task.conditions_CONFIG.items()]) == True
    assert all([v for k,v in lammps_task.conditions_READY.items()]) == True
    assert lammps_task.conditions_RUNNING['process_initialized']== True
    assert all([v for k,v in lammps_task.conditions_RUNNING.items()]) == True
    assert lammps_task.conditions_POST['process_finished'] == False
    assert all([v for k,v in lammps_task.conditions_POST.items()]) == False
    assert all([v for k,v in lammps_task.conditions_FINISHED.items()]) == False
Esempio n. 3
0
for temperature in range(temp_0, temp_f + 1, 100):
    configuration['task']['task_name'] = 'MgO_NaCl_unit.npt.T{}'.format(
        temperature)
    configuration['task']['task_directory'] = 'MgO_NaCl_unit.npt.T{}'.format(
        temperature)
    configuration['task']['temperature'] = temperature
    configuration['task']['task_type'] = 'lmps_npt'

    task_name = configuration['task']['task_name']
    task_directory = configuration['task']['task_directory']
    structure_filename = configuration['structure']['filename']
    restart = False
    fullauto = False

    if os.path.isdir(task_directory):
        shutil.rmtree(task_directory)

    lammps_task = LammpsNptSimulation(task_name=task_name,
                                      task_directory=task_directory,
                                      structure_filename=structure_filename)
    lammps_task.on_init(configuration)
    lammps_task.on_config(configuration)
    lammps_task.on_ready(configuration)

    _time_sleep = 0.1
    time.sleep(_time_sleep)
    print("t={}".format(temperature))
    while (lammps_task.process.poll() is None):
        time.sleep(_time_sleep)
    lammps_task = None