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 test____init___(): 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) #<--- code being tested from pypospack.task.lammps import LammpsNptSimulation lammps_task = LammpsNptSimulation( task_name = task_name, task_directory = task_directory, structure_filename = structure_filename) #<--- check directory structure assert os.path.isdir( os.path.abspath(lammps_task.task_directory)) assert os.listdir(lammps_task.task_directory) == [] #<--- check attributes assert lammps_task.task_name == task_name assert os.path.abspath(lammps_task.task_directory)\ == os.path.abspath(task_directory) assert lammps_task.task_type == 'single_point' assert lammps_task.lammps_bin == os.environ['LAMMPS_BIN'] assert lammps_task.lammps_input_filename == 'lammps.in' assert lammps_task.lammps_output_filename == 'lammps.out' assert lammps_task.lammps_structure_filename == 'lammps.structure' assert lammps_task.lammps_setfl_filename is None assert lammps_task.potential is None assert lammps_task.structure_filename == structure_filename assert isinstance(lammps_task.structure,crystal.SimulationCell) assert lammps_task.status == 'INIT'
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
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
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
def create_tasks(self): self.tasks = OrderedDict() for k, v in self.task_configurations.items(): self.tasks[k] = LammpsNptSimulation(**v)
MgO_LC_configuration['parameters'] = MgO_LC_parameters MgO_LC_configuration['structure'] = MgO_structure_definition configuration = MgO_LC_configuration task_name = configuration['task']['task_name'] task_directory = configuration['task']['task_directory'] structure_filename = configuration['structure']['filename'] restart = False fullauto = False from pypospack.task.lammps import LammpsNptSimulation lammps_task = LammpsNptSimulation(task_name=task_name, task_directory=task_directory, structure_filename=structure_filename, temperature=100, time_total=10, time_step=0.001, supercell=[5, 5, 5], pressure=0) lammps_task.on_init(configuration) lammps_task.on_config(configuration) lammps_task.on_ready(configuration) while lammps_task.status is 'RUNNING': lammps_task.on_running(configuration) lammps_task.on_post(configuration) print(lammps_task.results)
def test__get_task_name(): task_name = LammpsNptSimulation.get_task_name(structure='structure',temperature=10) assert task_name == 'structure.lmps_npt_10'