示例#1
0
def test__on_ready():
    task_name = 'gulp_test'
    task_directory = 'gulp_test_directory'
    structure_filename = os.path.join(
            'test_GulpGammaPointPhonons',
            'MgO_NaCl_prim.gga.relax.vasp')
    restart=False
    
    configuration=copy.deepcopy(configuration_MgO)

    if os.path.exists(task_directory):
        shutil.rmtree(task_directory)
    if os.path.exists('gulp_test.results.dat'):
        os.remove('gulp_test.results.dat')
    #<--- code setup
    from pypospack.task.gulp import GulpGammaPointPhonons
    gulp_task = GulpGammaPointPhonons(
            task_name=task_name,
            task_directory=task_directory,
            structure_filename=structure_filename,
            restart=restart)
    gulp_task.configuration = copy.deepcopy(configuration)
    gulp_task.on_init()
    gulp_task.on_config()
    #<--- precondition test
    assert gulp_task.status == 'READY'

    #<--- code being tested
    gulp_task.on_ready()
    
    #<--- expected values
    symbols=configuration['potential']['symbols']
    parameter_names=configuration['potential']['parameter_names']
    
    #<------ test attribute.potential
    assert type(gulp_task.potential) is potential.BuckinghamPotential
    assert gulp_task.potential.symbols == symbols
    assert gulp_task.potential.parameter_names == parameter_names

    assert os.path.isfile(os.path.join(task_directory,'freq.gulp'))
    assert os.path.isfile(os.path.join(task_directory,'gulp.out'))
    assert os.path.isfile(os.path.join(task_directory,'phonon.gulp.dens'))
    #<------ test attribute.symbol
    assert isinstance(gulp_task.parameters,dict)
    for pn in parameter_names:
        assert pn in gulp_task.parameters
    for pn,pv in gulp_task.parameters.items():
        assert pv is not None
   
    #<----- check that status update is correct
    assert gulp_task.conditions_READY['input_file_is_written']
    assert gulp_task.all_conditions_INIT
    assert gulp_task.all_conditions_CONFIG
    assert gulp_task.all_conditions_READY
    assert gulp_task.all_conditions_RUNNING
    assert gulp_task.conditions_POST['is_freq_file_exists']
    assert gulp_task.conditions_POST['is_dens_file_exists']
    assert gulp_task.all_conditions_POST
    assert not gulp_task.all_conditions_FINISHED
    assert gulp_task.status == 'POST'
示例#2
0
def test__on_init():
    task_name = 'gulp_test'
    task_directory = 'gulp_test_directory'
    structure_filename = os.path.join(
            'test_GulpGammaPointPhonons',
            'MgO_NaCl_prim.gga.relax.vasp')
    restart=False
    configuration=copy.deepcopy(configuration_MgO)
    #<--- testing the setup
    assert 'parameters' in configuration
    #<--- setup the filesystem
    if os.path.exists(task_directory):
        shutil.rmtree(task_directory)
    #<--- code setup
    from pypospack.task.gulp import GulpGammaPointPhonons
    gulp_task = GulpGammaPointPhonons(
            task_name=task_name,
            task_directory=task_directory,
            structure_filename=structure_filename,
            restart=restart)

    #<--- expected values
    symbols=configuration['potential']['symbols']
    parameter_names=configuration['potential']['parameter_names']
    
    #<--- precondition test
    assert gulp_task.status == 'INIT'

    #<--- code being tested
    gulp_task.on_init(configuration=configuration)
    
    #<------ test attribute.potential
    assert type(gulp_task.potential) is potential.BuckinghamPotential
    assert gulp_task.potential.symbols == symbols
    assert gulp_task.potential.parameter_names == parameter_names
    #<------ test attribute.symbol
    assert isinstance(gulp_task.parameters,dict)
    for pn in parameter_names:
        assert pn in gulp_task.parameters
    for pn,pv in gulp_task.parameters.items():
        assert pv is not None
   
    #<----- check that status update is correct
    assert gulp_task.conditions_CONFIG['is_structure_configured'] is True
    assert gulp_task.conditions_CONFIG['is_potential_configured'] is True
    assert all([v for k,v in gulp_task.conditions_INIT.items()]) 
    assert all([v for k,v in gulp_task.conditions_CONFIG.items()]) 
    assert gulp_task.all_conditions_INIT
    assert gulp_task.all_conditions_CONFIG
    assert gulp_task.all_conditions_INIT and gulp_task.all_conditions_CONFIG
    assert gulp_task.status == 'CONFIG'
示例#3
0
def test__init__():
    #<--- variable setup
    task_name = 'gulp_test'
    task_directory = 'gulp_test_directory'
    structure_filename = os.path.join(
            'test_GulpGammaPointPhonons',
            'MgO_NaCl_prim.gga.relax.vasp')
    restart=False

    #<--- file directory setup
    if os.path.exists(task_directory):
        shutil.rmtree(task_directory)

    #<--- code being tested
    from pypospack.task.gulp import GulpGammaPointPhonons
    gulp_task = GulpGammaPointPhonons(
            task_name=task_name,
            task_directory=task_directory,
            structure_filename=structure_filename,
            restart=restart)

    #<--- test
    assert gulp_task.task_name == task_name
    assert os.path.abspath(gulp_task.task_directory) \
            == os.path.abspath(task_directory)
    assert gulp_task.root_directory == os.getcwd()
    assert os.path.exists(task_directory)
    assert gulp_task.structure_filename == structure_filename
    assert isinstance(
            gulp_task.structure,
            crystal.SimulationCell)
    assert gulp_task.gulp_input_filename == 'gulp.in'
    assert gulp_task.gulp_output_filename == 'gulp.out'
    assert gulp_task.gulp_bin == os.environ['GULP_BIN']
    assert gulp_task.status == 'INIT'

    #<--- cleanup
    if os.path.exists(task_directory):
        shutil.rmtree(task_directory)
    max_v_len = max_line_len - max_k_len - 1

    str_format = "{:^" + str(max_k_len) + "} {:^" + str(max_v_len) + "}\n"

    for k, v in o_task.results.items():
        s += str_format.format(k, v)

    return s


if __name__ == '__main__':
    configuration = MgO_task_configuration

    o_task = GulpGammaPointPhonons(
        task_name=MgO_task_configuration['task']['task_name'],
        task_directory=MgO_task_configuration['task']['task_directory'],
        structure_filename=os.path.join(
            configuration['structures']['structure_directory'],
            configuration['structures']['structures']['MgO_NaCl_prim']))

    o_task.on_init(configuration)
    o_task.on_config(configuration)
    o_task.on_ready(configuration)
    o_task.on_running(configuration)

    # we need a loot while the task is running, that polls for the task to be done
    while o_task.status is not 'POST':
        o_task.update_status()

    o_task.on_post(configuration)

    print(str__results(o_task))
示例#5
0
    print(80*'-')
    print('task_name={}'.format(task_name))
    print('task_directory={}'.format(task_directory))
    if os.path.exists(task_directory):
        print('\ttask_directory already exists, removing task_directory')
        shutil.rmtree(task_directory)
    print('structure_filename={}'.format(structure_filename))
    
    if os.path.exists(structure_filename):
        print('\tstructure_file exists')
    else:
        print('\tstructure_file DOES NOT EXIST')
        exit()

    task = GulpGammaPointPhonons(
            task_name=task_name,
            task_directory=task_directory,
            structure_filename=structure_filename)

    # setting up potential
    task.potential = _potential
    task.parameters = copy.deepcopy(param_dict)
    
    task.write_gulp_input_file(\
            filename=os.path.join(task.task_directory,gulp_input_filename),
            structure_filename=structure_filename)
    print(80*'-')
    print('running GulpGammaPointPhonons task')
    task.run()
    print(80*'-')