Esempio n. 1
0
def dev__defect_calculation():
    print(80*'-')
    print('{:^80}'.format('defect_calculation'))
    print(80*'-')
    simulation_dir = 'rank_test'

    testing_set = testing_set_Si_sw.get_testing_set_Si()

    configuration = PyposmatConfigurationFile()
    configuration.qois = testing_set['qoi_db'].qois
    configuration.structures = testing_set['structure_db']

    qoi_manager = QoiManager(
            qoi_database=configuration.qois,
            fullauto=False
    )
    qoi_manager.configure()
    qoi_manager.determine_tasks()

    print('qoi_manager.tasks')
    print(len('qoi_manager.tasks')*'-')
    for k,v in qoi_manager.tasks.items():
        print(k,v)

    task_manager = TaskManager(base_directory=simulation_dir)
    task_manager.configure(
            tasks = qoi_manager.tasks,
            structures = testing_set['structure_db']
    )
    task_managger.evaluate_tasks()
    
    qoi_manager.calculate_qois(
            task_results=task_manager.results
    )
    qoi_manager.qois
def test__get_required_tasks(qoi):
    _qoidb_filename_in = "pypospack.qoi.yaml"

    from pypospack.qoi import QoiDatabase
    from pypospack.qoi import QoiManager

    _qoi_type = qoi
    _qoi_structure = 'MgO_NaCl'
    _qoi_name = "{}.{}".format(_qoi_structure, _qoi_type)
    _qoi_structures = OrderedDict()
    _qoi_structures['ideal'] = 'MgO_NaCl'
    _qoidb_QoiDatabase = QoiDatabase()
    _qoidb_QoiDatabase.add_qoi(qoi_name=_qoi_name,
                               qoi_type=_qoi_type,
                               structures=_qoi_structures,
                               target=4.5)

    qoimanager = QoiManager(qoi_database=_qoidb_QoiDatabase, fullauto=False)
    qoimanager.configure()
    qoimanager.determine_tasks()

    _task_type = 'lmps_min_all'
    _qoi_task_name = "{}.{}".format(_qoi_structures['ideal'], _task_type)
    assert isinstance(qoimanager.tasks, OrderedDict)
    assert _qoi_task_name in qoimanager.tasks
    assert qoimanager.tasks[_qoi_task_name]['task_type'] == _task_type
    assert qoimanager.tasks[_qoi_task_name]['task_structure'] \
            == _qoi_structures['ideal']
def test__calculate_stacking_fault(potential,qoi_db,structure_db):
    simulation_directory = 'rank_test'

    configuration = PyposmatConfigurationFile()
    configuration.qois = qoi_db.qois
    configuration.structures = structure_db

    qoi_manager = QoiManager(qoi_database=configuration.qois,fullauto=False)
    qoi_manager.configure()
    qoi_manager.determine_tasks()

    task_manager = TaskManager(base_directory='rank_test')
    task_manager.configure(tasks=qoi_manager.tasks,structures=structure_db)
    task_manager.evaluate_tasks(parameters=potential,potential=potential)

    qoi_manager.calculate_qois(
            task_results=task_manager.results)
    qoi_manager.qois
Esempio n. 4
0
    print(80*'-')
    print('{:^80}'.format('STRUCTURE DATABASE'))
    print(80*'-')
    print('Structure directory:{}'.format(structure_db['structure_directory']))
    print(20*'-' + ' ' + 59*'-')
    print('{:^20} {:^59}'.format('structure_name','structure_filename'))
    print(20*'-' + ' ' + 59*'-')
    for k,v in structure_db['structures'].items():
        print('{:<20} {:<59}'.format(k,v))


    qoi_manager = QoiManager(
            qoi_database=configuration.qois,
            fullauto=False)
    qoi_manager.configure()
    qoi_manager.determine_tasks()

    print(80*'-')
    print('{:^80}'.format('TASKS DATABASE'))
    print(80*'-')
    for k,v in qoi_manager.tasks.items():
        tsk_name = k
        tsk_type = v['task_type']
        tsk_structure = v['task_structure']
        print(tsk_name,tsk_type,tsk_structure,tsk_structure)

    task_manager = TaskManager(base_directory='rank_test')
    task_manager.configure(
            tasks=qoi_manager.tasks,
            structures=structure_db
        )
class TestQoi(object):
    def __init__(self,qoi_db,structure_db,potential):
       
        self.configuration = None
        self.qoi_manager = None
        self.task_directory = 'rank_test'
        self.task_manager = None

        self.setup_configuration_file(qoi_db=qoi_db,structure_db=structure_db)
        self.check_structure_db(structure_db)
        self.configure_qoi_manager(qoi_database=self.configuration.qois)
        self.check_task_database()
        self.configure_task_manager(task_directory=self.task_directory,
                                    tasks=self.qoi_manager.tasks,
                                    structures=self.configuration.structures)
        self.evaluate_tasks(parameters=potential,
                            potential=potential)
        self.check_task_results(task_results=self.task_manager.results)
        self.calculate_qois()
        self.check_qoi_results()

    def setup_configuration_file(self,qoi_db,structure_db):
        print('setup_configuration_file')
        self.configuration = PyposmatConfigurationFile()
        self.configuration.qois = qoi_db.qois
        self.configuration.structures = structure_db

    def check_structure_db(self,structure_db):
        print('check_structures')
        structure_directory = self.configuration.structures['structure_directory']
        assert os.path.isdir(structure_directory)
        for structure_name,structure_fn in self.configuration.structures['structures'].items():
            print(structure_name,structure_fn)
            assert os.path.isfile(os.path.join(structure_directory,structure_fn))

    def configure_qoi_manager(self,qoi_database):
        self.qoi_manager = QoiManager(qoi_database=qoi_database,fullauto=False)
        self.qoi_manager.configure()
        self.qoi_manager.determine_tasks()

    def check_task_database(self):
        print('{} {} {}'.format('task_name','task_type','task_structure'))
        for k,v in self.qoi_manager.tasks.items():
            task_name = k
            task_type = v['task_type']
            task_structure = v['task_structure']
            print('{} {} {}'.format(task_name,task_type,task_structure))

            assert k in task_list
            assert task_type == task_list[k]['task_type']
            assert task_structure == task_list[k]['task_structure']

        assert len(self.qoi_manager.tasks) == len(task_list)

    def configure_task_manager(self,task_directory,tasks,structures):
        self.task_manager = TaskManager(base_directory=task_directory)
        self.task_manager.configure(tasks=tasks,
                                    structures=structures)
   
    def evaluate_tasks(self,parameters,potential):
        self.task_manager.evaluate_tasks(parameters=parameters,potential=potential)

    def check_task_results(self,task_results):
        table_col_names = ['name','value']
        table_rows = []
        for k,v in task_results.items():
            table_rows.append([str(k),str(v)])

        print('\n'.join([','.join(v) for v in table_rows]))
    
    def calculate_qois(self):
        self.qoi_manager.calculate_qois(task_results=self.task_manager.results)

    def check_qoi_results(self):
        print(self.qoi_manager.qois)