def test_existing_parsers(self): """Test listing all preinstalled parsers""" from aiida.parsers import Parser pars = pl.existing_plugins(Parser, 'aiida.parsers.plugins') self.assertIsInstance(pars, list) from aiida.parsers import ParserFactory for i in pars: self.assertTrue(issubclass(ParserFactory(i), Parser))
def test_existing_parsers(self): """ Test listing all preinstalled parsers """ entry_points = get_entry_points('aiida.parsers') self.assertIsInstance(entry_points, list) for entry_point in entry_points: cls = ParserFactory(entry_point.name) self.assertTrue(issubclass(cls, Parser), 'Parser plugin class {} is not subclass of {}'.format(cls, Parser))
def test_existing_parsers(self): """ Test listing all preinstalled parsers """ parsers = all_plugins('parsers') self.assertIsInstance(parsers, list) for i in parsers: cls = ParserFactory(i) self.assertTrue( issubclass(cls, Parser), 'Parser plugin class {} is not subclass of {}'.format( cls, Parser))
def test_voronoi_parser_entry_point(aiida_env): from aiida.parsers import ParserFactory from aiida_kkr.parsers.voro import VoronoiParser parser = ParserFactory('kkr.voroparser') assert parser == VoronoiParser
def test_kkrimporter_parser_entry_point(aiida_env): from aiida.parsers import ParserFactory from aiida_kkr.parsers.kkrimporter import KkrImporterParser parser = ParserFactory('kkr.kkrimporterparser') assert parser == KkrImporterParser
def test_parser_opt(new_database, new_workdir): """ Test the parser """ from aiida.parsers import ParserFactory from aiida.common.datastructures import calc_states from aiida.common.folders import SandboxFolder from aiida.orm import DataFactory code = get_basic_code(new_workdir) calc = code.new_calc() calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1}) calc.store_all() calc._set_state(calc_states.PARSING) parser_cls = ParserFactory("crystal17.basic") parser = parser_cls(calc) with SandboxFolder() as folder: main_out_path = os.path.join( os.path.dirname(tests.__file__), "output_files", "mgo_sto3g_opt.crystal.out") with open(main_out_path) as f: folder.create_file_from_filelike(f, "main.out") fdata = DataFactory("folder")() fdata.replace_with_folder(folder.abspath) mock_retrieved = {calc._get_linkname_retrieved(): fdata} success, node_list = parser.parse_with_retrieved(mock_retrieved) assert success node_dict = dict(node_list) assert set(['output_parameters', 'output_settings', 'output_structure']) == set(node_dict.keys()) expected_params = { 'parser_version': str(aiida_crystal17.__version__), 'ejplugins_version': str(ejplugins.__version__), 'parser_class': 'CryBasicParser', 'parser_warnings': ["no initial structure available, creating new kinds for atoms"], 'errors': [], 'warnings': ['WARNING **** INT_SCREEN **** CELL PARAMETERS OPTIMIZATION ONLY'], 'energy': -2.712596206888E+02 * 27.21138602, 'energy_units': 'eV', # hartree to eV 'calculation_type': 'restricted closed shell', 'calculation_spin': False, # 'wall_time_seconds': # 102, 'number_of_atoms': 2, 'number_of_assymetric': 2, 'scf_iterations': 8, 'opt_iterations': 6, 'volume': 14.652065094424696, } out_params_dict = node_dict['output_parameters'].get_dict() out_params_dict.pop('wall_time_seconds', None) assert edict.diff( out_params_dict, expected_params, np_allclose=True) == {} expected_struct_attrs = { 'cell': [[0.0, 1.94218061274, 1.94218061274], [1.94218061274, 0.0, 1.94218061274], [1.94218061274, 1.94218061274, 0.0]], 'kinds': [{'mass': 24.305, 'name': 'Mg', 'symbols': [u'Mg'], 'weights': [1.0]}, {'mass': 15.9994, 'name': 'O', 'symbols': ['O'], 'weights': [1.0]}], 'pbc1': True, 'pbc2': True, 'pbc3': True, 'sites': [{'kind_name': 'Mg', 'position': [0.0, 0.0, 0.0]}, {'kind_name': 'O', 'position': [1.94218061274, 1.94218061274, 1.94218061274]}] } assert edict.diff( dict(node_dict['output_structure'].get_attrs()), expected_struct_attrs, np_allclose=True) == {}
def test_parser_external(new_database, new_workdir): """ Test the parser """ from aiida.parsers import ParserFactory from aiida.common.datastructures import calc_states from aiida.common.folders import SandboxFolder from aiida.orm import DataFactory code = get_basic_code(new_workdir) calc = code.new_calc() calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1}) calc.store_all() calc._set_state(calc_states.PARSING) parser_cls = ParserFactory("crystal17.basic") parser = parser_cls(calc) with SandboxFolder() as folder: main_out_path = os.path.join( os.path.dirname(tests.__file__), "output_files", "mgo_sto3g_external.crystal.out") with open(main_out_path) as f: folder.create_file_from_filelike(f, "main.out") fdata = DataFactory("folder")() fdata.replace_with_folder(folder.abspath) mock_retrieved = {calc._get_linkname_retrieved(): fdata} success, node_list = parser.parse_with_retrieved(mock_retrieved) assert success node_dict = dict(node_list) assert set(['output_parameters', 'output_settings', 'output_structure']) == set(node_dict.keys()) expected_params = { 'parser_version': str(aiida_crystal17.__version__), 'ejplugins_version': str(ejplugins.__version__), 'parser_class': 'CryBasicParser', 'parser_warnings': ["no initial structure available, creating new kinds for atoms"], 'errors': [], 'warnings': [], 'energy': -2.7121814374931E+02 * 27.21138602, 'energy_units': 'eV', # hartree to eV 'calculation_type': 'restricted closed shell', 'calculation_spin': False, # 'wall_time_seconds': # 3, 'number_of_atoms': 2, 'number_of_assymetric': 2, 'scf_iterations': 7, 'volume': 18.65461527264623, 'mulliken_charges': [0.777, -0.777], 'mulliken_electrons': [11.223, 8.777], } out_params_dict = node_dict['output_parameters'].get_dict() out_params_dict.pop('wall_time_seconds', None) assert edict.diff( out_params_dict, expected_params, np_allclose=True) == {} # read from nio_sto3g_afm.crystal.out expected_operations = [[ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 ], [0.0, 1.0, 0.0, 1.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0], [ -1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 ], [0.0, 0.0, 1.0, -1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0], [ 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 ], [0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0], [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0 ], [1.0, 0.0, 0.0, -1.0, -1.0, -1.0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1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 ], [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0], [ 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0 ], [-1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0], [ 0.0, 1.0, 0.0, -1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], [0.0, 1.0, 0.0, 0.0, 0.0, 1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0], [ -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 ], [1.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]] print(node_dict['output_settings'].data.operations) assert node_dict['output_settings'].compare_operations( expected_operations) == {} expected_struct_attrs = { 'cell': [[0.0, 2.105, 2.105], [2.105, 0.0, 2.105], [2.105, 2.105, 0.0]], 'kinds': [ {'mass': 24.305, 'name': 'Mg', 'symbols': ['Mg'], 'weights': [1.0]}, {'mass': 15.9994, 'name': 'O', 'symbols': ['O'], 'weights': [1.0]}], 'pbc1': True, 'pbc2': True, 'pbc3': True, 'sites': [{'kind_name': 'Mg', 'position': [0.0, 0.0, 0.0]}, {'kind_name': 'O', 'position': [2.105, 2.105, 2.105]}] } assert edict.diff( dict(node_dict['output_structure'].get_attrs()), expected_struct_attrs, np_allclose=True) == {}
def test_spex_parser_entry_point(aiida_env): from aiida.parsers import ParserFactory from aiida_spex.parsers.spex import SpexParser parser = ParserFactory('spex.spexparser') assert parser == SpexParser
def test_fleur_parser_entry_point(aiida_env): from aiida.parsers import ParserFactory from aiida_fleur.parsers.fleur import FleurParser parser = ParserFactory('fleur.fleurparser') assert parser == FleurParser
def test_inpgen_parser_entry_point(aiida_env): from aiida.parsers import ParserFactory from aiida_fleur.parsers.fleur_inputgen import Fleur_inputgenParser parser = ParserFactory('fleur.fleurinpgenparser') assert parser == Fleur_inputgenParser
from aiida.orm.data.base import Bool from aiida.orm.data.array import ArrayData from aiida.orm.data.folder import FolderData from aiida.orm.data.remote import RemoteData from aiida.orm.data.parameter import ParameterData from aiida.orm.data.array.kpoints import KpointsData from aiida.parsers import ParserFactory from aiida.work.workchain import while_ from aiida_quantumespresso.common.workchain.base.restart import BaseRestartWorkChain from aiida_quantumespresso.common.workchain.utils import ErrorHandlerReport from aiida_quantumespresso.common.workchain.utils import register_error_handler from aiida_quantumespresso.utils.resources import get_default_options PwCalculation = CalculationFactory('quantumespresso.pw') HpCalculation = CalculationFactory('quantumespresso.hp') HpParser = ParserFactory('quantumespresso.hp') class HpBaseWorkChain(BaseRestartWorkChain): """ Base workchain to launch a Quantum Espresso hp.x calculation """ _verbose = False _calculation_class = HpCalculation ERROR_INCORRECT_ORDER_ATOMIC_POSITIONS = 4 ERROR_MISSING_PERTURBATION_FILE = 5 @classmethod def define(cls, spec): super(HpBaseWorkChain, cls).define(spec)
def test_parser_with_init_struct(new_database, new_workdir): """ Test the parser """ from aiida.parsers import ParserFactory from aiida.common.datastructures import calc_states from aiida.common.folders import SandboxFolder from aiida.orm import DataFactory code = get_main_code(new_workdir) calc = code.new_calc() calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1}) from aiida.orm.data.structure import StructureData struct = StructureData() struct.append_atom(position=[0, 0, 0], symbols="Mg", name="Mgx") struct.append_atom(position=[0.5, 0.5, 0.5], symbols="O", name="Ox") calc.use_structure(struct) calc.store_all() calc._set_state(calc_states.PARSING) parser_cls = ParserFactory("crystal17.basic") parser = parser_cls(calc) with SandboxFolder() as folder: main_out_path = os.path.join(os.path.dirname(tests.__file__), "output_files", "mgo_sto3g_scf.crystal.out") with open(main_out_path) as f: folder.create_file_from_filelike(f, "main.out") fdata = DataFactory("folder")() fdata.replace_with_folder(folder.abspath) mock_retrieved = {calc._get_linkname_retrieved(): fdata} success, node_list = parser.parse_with_retrieved(mock_retrieved) assert success node_dict = dict(node_list) assert set(['output_parameters', 'output_settings']) == set(node_dict.keys()) expected_params = { 'parser_version': str(aiida_crystal17.__version__), 'ejplugins_version': str(ejplugins.__version__), 'parser_class': 'CryBasicParser', 'parser_warnings': [], 'errors': [], 'warnings': [], 'energy': -2.7121814374931E+02 * 27.21138602, 'energy_units': 'eV', # hartree to eV 'calculation_type': 'restricted closed shell', 'calculation_spin': False, 'wall_time_seconds': 3, 'number_of_atoms': 2, 'number_of_assymetric': 2, 'scf_iterations': 7, 'volume': 18.65461527264623, } assert edict.diff(node_dict['output_parameters'].get_dict(), expected_params, np_allclose=True) == {}
def test_siesta_parser_entry_point(siesta_develop): from aiida.parsers import ParserFactory siesta_parser = ParserFactory('siesta.parser') assert siesta_parser is not None