def start(self): from aiida.orm import Calculation, DataFactory, load_node from aiida.tools.codespecific.vasp.win import modify_wannier_settings_inline params = self.get_parameters() self.append_to_report(self.helper._wf_start_msg()) cont = params['continue_from'] if isinstance(cont, dict): old_win = load_node(uuid=cont['settings']) wdat = load_node(uuid=cont['data']) else: cont = Calculation.query(uuid=cont)[0] old_win = cont.inp.wannier_settings wdat = cont.out.wannier_data ParamData = DataFactory('parameter') mods = ParamData(dict=params['settings']) mod_c, mod_d = modify_wannier_settings_inline(original=old_win, modifications=mods) win = mod_d['wannier_settings'] calc = self.get_wannier_calc(win, wdat) calc.store_all() calc.set_extras(params.get('extras', {})) self.attach_calculation(calc) self.append_to_report( self.helper._calc_start_msg('wannier.x calculation', calc)) self.next(self.end)
def start(self): """Prepare and launch the Wannier90 calculation""" from aiida.orm import Calculation, DataFactory, load_node from aiida_vasp.utils.win import modify_wannier_parameters_inline params = self.get_parameters() self.append_to_report(self.helper._wf_start_msg()) cont = params['continue_from'] if isinstance(cont, dict): old_win = load_node(uuid=cont['parameters']) wdat = load_node(uuid=cont['data']) else: cont = Calculation.query(uuid=cont)[0] old_win = cont.inp.wannier_parameters wdat = cont.out.wannier_data param_cls = DataFactory('parameter') mods = param_cls(dict=params['parameters']) _, mod_d = modify_wannier_parameters_inline(original=old_win, modifications=mods) win = mod_d['wannier_parameters'] calc = self.get_wannier_calc(win, wdat) calc.store_all() calc.set_extras(params.get('extras', {})) self.attach_calculation(calc) self.append_to_report( self.helper._calc_start_msg('wannier.x calculation', calc)) self.next(self.end)
def get_calc_maker(self): params = self.get_parameters() maker = self.helper._get_calc_maker( 'vasp.nscf', continue_from=Calculation.query(uuid=params['continue_from'])[0]) nscf_settings = {'lwannier90': params['use_wannier'], 'icharg': 11} maker.rewrite_settings(**nscf_settings) return maker
def get_calc_maker(self): """Initialize a calculation builder instance""" params = self.get_parameters() maker = self.helper._get_calc_maker( # pylint: disable=protected-access 'vasp.nscf', continue_from=Calculation.query(uuid=params['continue_from'])[0]) nscf_parameters = {'lwannier90': params['use_wannier'], 'icharg': 11} maker.rewrite_parameters(**nscf_parameters) return maker
def test_statistics_default_class(self): """ Test if the statistics query works properly. I try to implement it in a way that does not depend on the past state. """ from aiida.orm import Node, DataFactory, Calculation from collections import defaultdict from aiida.backends.general.abstractqueries import AbstractQueryManager def store_and_add(n, statistics): n.store() statistics['total'] += 1 statistics['types'][n._plugin_type_string] += 1 statistics['ctime_by_day'][n.ctime.strftime('%Y-%m-%d')] += 1 class QueryManagerDefault(AbstractQueryManager): pass qmanager_default = QueryManagerDefault() current_db_statistics = qmanager_default.get_creation_statistics() types = defaultdict(int) types.update(current_db_statistics['types']) ctime_by_day = defaultdict(int) ctime_by_day.update(current_db_statistics['ctime_by_day']) expected_db_statistics = { 'total': current_db_statistics['total'], 'types': types, 'ctime_by_day': ctime_by_day } ParameterData = DataFactory('parameter') store_and_add(Node(), expected_db_statistics) store_and_add(ParameterData(), expected_db_statistics) store_and_add(ParameterData(), expected_db_statistics) store_and_add(Calculation(), expected_db_statistics) new_db_statistics = qmanager_default.get_creation_statistics() # I only check a few fields new_db_statistics = { k: v for k, v in new_db_statistics.iteritems() if k in expected_db_statistics } expected_db_statistics = { k: dict(v) if isinstance(v, defaultdict) else v for k, v in expected_db_statistics.iteritems() } self.assertEquals(new_db_statistics, expected_db_statistics)
def setUpClass(cls): """ Create some code to test the CalculationParamType parameter type for the command line infrastructure We create an initial code with a random name and then on purpose create two code with a name that matches exactly the ID and UUID, respectively, of the first one. This allows us to test the rules implemented to solve ambiguities that arise when determing the identifier type """ super(TestCalculationParamType, cls).setUpClass() cls.param = CalculationParamType() cls.entity_01 = Calculation().store() cls.entity_02 = Calculation().store() cls.entity_03 = Calculation().store() cls.entity_04 = FunctionCalculation() cls.entity_05 = InlineCalculation() cls.entity_06 = JobCalculation() cls.entity_07 = WorkCalculation() cls.entity_01.label = 'calculation_01' cls.entity_02.label = str(cls.entity_01.pk) cls.entity_03.label = str(cls.entity_01.uuid)
def get_calc_maker(self): """Initialize a calculation builder instance""" from aiida.orm import Calculation params = self.get_parameters() cont = Calculation.query(uuid=params['continue_from'])[0] maker = self.helper._get_calc_maker('vasp.amn', copy_from=cont) # pylint: disable=protected-access nscf_parameters = {'lwannier90': True, 'icharg': 11} maker.rewrite_parameters(**nscf_parameters) cout = cont.get_outputs_dict() cinp = cont.get_inputs_dict() maker.wannier_parameters = cout.get('wannier_parameters', cinp.get('wannier_parameters', {})) return maker
def get_calc_maker(self): from aiida.orm import Calculation params = self.get_parameters() cont = Calculation.query(uuid=params['continue_from'])[0] maker = self.helper._get_calc_maker( 'vasp.amn', copy_from=cont) nscf_settings = {'lwannier90': True, 'icharg': 11} maker.rewrite_settings(**nscf_settings) cout = cont.get_outputs_dict() cinp = cont.get_inputs_dict() maker.wannier_settings = cout.get( 'wannier_settings', cinp.get( 'wannier_settings', {})) return maker
def test_computer_json(self): """ In this test we check the correct behavior of QueryBuilder when retrieving the _metadata and the transport_params with no content. Note that they are in JSON format in both backends. Forcing the decoding of a None value leads to an exception (this was the case under Django). """ from aiida.orm.querybuilder import QueryBuilder from aiida.orm import Node, Data, Calculation from aiida.orm import Computer n1 = Calculation() n1.label = 'node2' n1._set_attr('foo', 1) n1.store() # Checking the correct retrieval of transport_params which is # a JSON field (in both backends). qb = QueryBuilder() qb.append(Calculation, project=['id'], tag='calc') qb.append(Computer, project=['id', 'transport_params'], outerjoin=True, computer_of='calc') qb.all() # Checking the correct retrieval of _metadata which is # a JSON field (in both backends). qb = QueryBuilder() qb.append(Calculation, project=['id'], tag='calc') qb.append(Computer, project=['id', '_metadata'], outerjoin=True, computer_of='calc') qb.all()
def test_simple_query_django_1(self): """ Testing a simple query """ from aiida.orm.querybuilder import QueryBuilder from aiida.orm.calculation.job import JobCalculation from aiida.orm import Node, Data, Calculation from datetime import datetime from aiida.common.links import LinkType n1 = Data() n1.label = 'node1' n1._set_attr('foo', ['hello', 'goodbye']) n1.store() n2 = Calculation() n2.label = 'node2' n2._set_attr('foo', 1) n2.store() n3 = Data() n3.label = 'node3' n3._set_attr('foo', 1.0000) # Stored as fval n3.store() n4 = Calculation() n4.label = 'node4' n4._set_attr('foo', 'bar') n4.store() n5 = Data() n5.label = 'node5' n5._set_attr('foo', None) n5.store() n2.add_link_from(n1, link_type=LinkType.INPUT) n3.add_link_from(n2, link_type=LinkType.CREATE) n4.add_link_from(n3, link_type=LinkType.INPUT) n5.add_link_from(n4, link_type=LinkType.CREATE) qb1 = QueryBuilder() qb1.append(Node, filters={'attributes.foo': 1.000}) self.assertEqual(len(qb1.all()), 2) qb2 = QueryBuilder() qb2.append(Data) self.assertEqual(qb2.count(), 3) qb2 = QueryBuilder() qb2.append(type='data.Data.') self.assertEqual(qb2.count(), 3) qb3 = QueryBuilder() qb3.append(Node, project='label', tag='node1') qb3.append(Node, project='label', tag='node2') self.assertEqual(qb3.count(), 4) qb4 = QueryBuilder() qb4.append(Calculation, tag='node1') qb4.append(Data, tag='node2') self.assertEqual(qb4.count(), 2) qb5 = QueryBuilder() qb5.append(Data, tag='node1') qb5.append(Calculation, tag='node2') self.assertEqual(qb5.count(), 2) qb6 = QueryBuilder() qb6.append(Data, tag='node1') qb6.append(Data, tag='node2') self.assertEqual(qb6.count(), 0)