def has_nwchem_plugin(): from aiida.common.pluginloader import get_plugin from aiida.common.exceptions import MissingPluginError from aiida.tools.dbexporters.tcod_plugins import BaseTcodtranslator try: get_plugin('tools.dbexporters.tcod_plugins', 'nwchem.nwcpymatgen') except MissingPluginError: return False return True
def plugins(entry_point): from aiida.backends.utils import load_dbenv, is_dbenv_loaded if not is_dbenv_loaded(): load_dbenv() from aiida.common.exceptions import LoadingPluginFailed, MissingPluginError from aiida.common.pluginloader import plugin_list, get_plugin if entry_point: try: plugin = get_plugin('workflows', entry_point) except (LoadingPluginFailed, MissingPluginError) as exception: click.echo("Error: {}".format(exception)) else: click.echo(plugin.get_description()) else: entry_points = sorted(plugin_list('workflows')) if entry_points: click.echo('Registered workflow entry points:') for entry_point in entry_points: click.echo("* {}".format(entry_point)) click.echo( "\nPass the entry point of a workflow as an argument to display detailed information" ) else: click.echo("# No workflows found")
def test_nwcpymatgen_translation(self): from aiida.tools.dbexporters.tcod \ import translate_calculation_specific_values # from aiida.tools.dbexporters.tcod_plugins.nwcpymatgen \ # import NwcpymatgenTcodtranslator as NPT from aiida.orm.data.parameter import ParameterData from tcodexporter import FakeObject from aiida.common.pluginloader import get_plugin NPT = get_plugin('tools.dbexporters.tcod_plugins', 'nwchem.nwcpymatgen') calc = FakeObject({ "out": { "output": ParameterData( dict={ "basis_set": { "H": { "description": "6-31g", "functions": "2", "shells": "2", "types": "2s" }, "O": { "description": "6-31g", "functions": "9", "shells": "5", "types": "3s2p" } }, "corrections": {}, "energies": [-2057.99011937535], "errors": [], "frequencies": None, "has_error": False, "job_type": "NWChem SCF Module" }), "job_info": ParameterData( dict={ "0 permanent": ".", "0 scratch": ".", "argument 1": "aiida.in", "compiled": "Sun_Dec_22_04:02:59_2013", "data base": "./aiida.db", "date": "Mon May 11 17:10:07 2015", "ga revision": "10379", "global": "200.0 Mbytes (distinct from heap & stack)", "hardfail": "no", "heap": "100.0 Mbytes", "hostname": "theospc11", "input": "aiida.in", "nproc": "6", "nwchem branch": "6.3", "nwchem revision": "24277", "prefix": "aiida.", "program": "/usr/bin/nwchem", "source": "/build/buildd/nwchem-6.3+r1", "stack": "100.0 Mbytes", "status": "startup", "time left": "-1s", "total": "400.0 Mbytes", "verify": "yes", }) } }) res = translate_calculation_specific_values(calc, NPT) self.assertEquals( res, { '_tcod_software_package': 'NWChem', '_tcod_software_package_version': '6.3', '_tcod_software_package_compilation_date': '2013-12-22T04:02:59', '_atom_type_symbol': ['H', 'O'], '_dft_atom_basisset': ['6-31g', '6-31g'], '_dft_atom_type_valence_configuration': ['2s', '3s2p'], })
def test_pw_translation(self): from aiida.tools.dbexporters.tcod \ import translate_calculation_specific_values # from aiida.tools.dbexporters.tcod_plugins.pw \ # import PwTcodtranslator as PWT # from aiida.tools.dbexporters.tcod_plugins.cp \ # import CpTcodtranslator as CPT from aiida.orm.code import Code from aiida.orm.data.array import ArrayData from aiida.orm.data.array.kpoints import KpointsData from aiida.orm.data.parameter import ParameterData import numpy from aiida.common.pluginloader import get_plugin PWT = get_plugin('tools.dbexporters.tcod_plugins', 'quantumespresso.pw') CPT = get_plugin('tools.dbexporters.tcod_plugins', 'quantumespresso.cp') code = Code() code._set_attr('remote_exec_path', '/test') kpoints = KpointsData() kpoints.set_kpoints_mesh([2, 3, 4], offset=[0.25, 0.5, 0.75]) def empty_list(): return [] calc = FakeObject({ "inp": { "parameters": ParameterData(dict={}), "kpoints": kpoints, "code": code }, "out": { "output_parameters": ParameterData(dict={}) }, "get_inputs": empty_list }) res = translate_calculation_specific_values(calc, PWT) self.assertEquals( res, { '_dft_BZ_integration_grid_X': 2, '_dft_BZ_integration_grid_Y': 3, '_dft_BZ_integration_grid_Z': 4, '_dft_BZ_integration_grid_shift_X': 0.25, '_dft_BZ_integration_grid_shift_Y': 0.5, '_dft_BZ_integration_grid_shift_Z': 0.75, '_dft_pseudopotential_atom_type': [], '_dft_pseudopotential_type': [], '_dft_pseudopotential_type_other_name': [], '_tcod_software_package': 'Quantum ESPRESSO', '_tcod_software_executable_path': '/test', }) calc = FakeObject({ "inp": { "parameters": ParameterData(dict={ 'SYSTEM': { 'ecutwfc': 40, 'occupations': 'smearing' } }) }, "out": { "output_parameters": ParameterData(dict={ 'number_of_electrons': 10, }) }, "get_inputs": empty_list }) res = translate_calculation_specific_values(calc, PWT) self.assertEquals( res, { '_dft_cell_valence_electrons': 10, '_tcod_software_package': 'Quantum ESPRESSO', '_dft_BZ_integration_smearing_method': 'Gaussian', '_dft_pseudopotential_atom_type': [], '_dft_pseudopotential_type': [], '_dft_pseudopotential_type_other_name': [], '_dft_kinetic_energy_cutoff_EEX': 2176.910676048, '_dft_kinetic_energy_cutoff_charge_density': 2176.910676048, '_dft_kinetic_energy_cutoff_wavefunctions': 544.227669012, }) calc = FakeObject({ "inp": { "parameters": ParameterData(dict={}) }, "out": { "output_parameters": ParameterData(dict={ 'energy_xc': 5, }) }, "get_inputs": empty_list }) with self.assertRaises(ValueError): translate_calculation_specific_values(calc, PWT) calc = FakeObject({ "inp": { "parameters": ParameterData(dict={}) }, "out": { "output_parameters": ParameterData(dict={ 'energy_xc': 5, 'energy_xc_units': 'meV' }) }, "get_inputs": empty_list }) with self.assertRaises(ValueError): translate_calculation_specific_values(calc, PWT) energies = { 'energy': -3701.7004199449257, 'energy_one_electron': -984.0078459766, 'energy_xc': -706.6986753641559, 'energy_ewald': -2822.6335103043157, 'energy_hartree': 811.6396117001462, 'fermi_energy': 10.25208617898623, } dct = energies for key in energies.keys(): dct["{}_units".format(key)] = 'eV' calc = FakeObject({ "inp": { "parameters": ParameterData(dict={'SYSTEM': { 'smearing': 'mp' }}) }, "out": { "output_parameters": ParameterData(dict=dct) }, "get_inputs": empty_list }) res = translate_calculation_specific_values(calc, PWT) self.assertEquals( res, { '_tcod_total_energy': energies['energy'], '_dft_1e_energy': energies['energy_one_electron'], '_dft_correlation_energy': energies['energy_xc'], '_dft_ewald_energy': energies['energy_ewald'], '_dft_hartree_energy': energies['energy_hartree'], '_dft_fermi_energy': energies['fermi_energy'], '_tcod_software_package': 'Quantum ESPRESSO', '_dft_BZ_integration_smearing_method': 'Methfessel-Paxton', '_dft_BZ_integration_MP_order': 1, '_dft_pseudopotential_atom_type': [], '_dft_pseudopotential_type': [], '_dft_pseudopotential_type_other_name': [], }) dct = energies dct['number_of_electrons'] = 10 for key in energies.keys(): dct["{}_units".format(key)] = 'eV' calc = FakeObject({ "inp": { "parameters": ParameterData(dict={'SYSTEM': { 'smearing': 'unknown-method' }}) }, "out": { "output_parameters": ParameterData(dict=dct) }, "get_inputs": empty_list }) res = translate_calculation_specific_values(calc, CPT) self.assertEquals( res, { '_dft_cell_valence_electrons': 10, '_tcod_software_package': 'Quantum ESPRESSO' }) ad = ArrayData() ad.set_array("forces", numpy.array([[[1, 2, 3], [4, 5, 6]]])) calc = FakeObject({ "inp": { "parameters": ParameterData(dict={'SYSTEM': { 'smearing': 'unknown-method' }}) }, "out": { "output_parameters": ParameterData(dict={}), "output_array": ad }, "get_inputs": empty_list }) res = translate_calculation_specific_values(calc, PWT) self.assertEquals( res, { '_tcod_software_package': 'Quantum ESPRESSO', '_dft_BZ_integration_smearing_method': 'other', '_dft_BZ_integration_smearing_method_other': 'unknown-method', '_dft_pseudopotential_atom_type': [], '_dft_pseudopotential_type': [], '_dft_pseudopotential_type_other_name': [], ## Residual forces are no longer produced, as they should ## be in the same CIF loop with coordinates -- to be ## implemented later, since it's not yet clear how. # '_tcod_atom_site_resid_force_Cartn_x': [1,4], # '_tcod_atom_site_resid_force_Cartn_y': [2,5], # '_tcod_atom_site_resid_force_Cartn_z': [3,6], })
def _collect_tags( node, calc, parameters=None, dump_aiida_database=default_options['dump_aiida_database'], exclude_external_contents=default_options['exclude_external_contents'], gzip=default_options['gzip'], gzip_threshold=default_options['gzip_threshold']): """ Retrieve metadata from attached calculation and pseudopotentials and prepare it to be saved in TCOD CIF. """ from aiida.common.links import LinkType import os, json import aiida tags = { '_audit_creation_method': "AiiDA version {}".format(aiida.__version__) } # Recording the dictionaries (if any) if len(conforming_dictionaries): for postfix in ['name', 'version', 'location']: key = '_audit_conform_dict_{}'.format(postfix) if key not in tags: tags[key] = [] for dictionary in conforming_dictionaries: tags['_audit_conform_dict_name'].append(dictionary['name']) tags['_audit_conform_dict_version'].append(dictionary['version']) tags['_audit_conform_dict_location'].append(dictionary['url']) # Collecting metadata from input files: calc_data = [] if calc is not None: calc_data = _collect_calculation_data(calc) for tag in tcod_loops['_tcod_computation'] + tcod_loops['_tcod_file']: tags[tag] = [] export_files = [] sn = 1 for step in calc_data: tags['_tcod_computation_step'].append(sn) tags['_tcod_computation_command'].append('cd {}; ./{}'.format( sn, aiida_executable_name)) tags['_tcod_computation_reference_uuid'].append(step['uuid']) if 'env' in step: tags['_tcod_computation_environment'].append("\n".join( ["%s=%s" % (key, step['env'][key]) for key in step['env']])) else: tags['_tcod_computation_environment'].append('') if 'stdout' in step and step['stdout'] is not None: tags['_tcod_computation_stdout'].append(step['stdout']) else: tags['_tcod_computation_stdout'].append('') if 'stderr' in step and step['stderr'] is not None: tags['_tcod_computation_stderr'].append(step['stderr']) else: tags['_tcod_computation_stderr'].append('') export_files.append({ 'name': "{}{}".format(sn, os.sep), 'type': 'folder' }) for f in step['files']: f['name'] = os.path.join(str(sn), f['name']) export_files.extend(step['files']) sn = sn + 1 # Creating importable AiiDA database dump in CIF tags if dump_aiida_database and node.is_stored: import json from aiida.common.exceptions import LicensingException from aiida.common.folders import SandboxFolder from aiida.orm.importexport import export_tree with SandboxFolder() as folder: try: export_tree([node.dbnode], folder=folder, silent=True, allowed_licenses=['CC0']) except LicensingException as e: raise LicensingException(e.message + \ ". Only CC0 license is accepted.") files = _collect_files(folder.abspath) with open(folder.get_abs_path('data.json')) as f: data = json.loads(f.read()) md5_to_url = {} if exclude_external_contents: for pk in data['node_attributes']: n = data['node_attributes'][pk] if 'md5' in n.keys() and 'source' in n.keys() and \ 'uri' in n['source'].keys(): md5_to_url[n['md5']] = n['source']['uri'] for f in files: f['name'] = os.path.join('aiida', f['name']) if f['type'] == 'file' and f['md5'] in md5_to_url.keys(): f['uri'] = md5_to_url[f['md5']] export_files.extend(files) # Describing seen files in _tcod_file_* loop encodings = list() fn = 0 for f in export_files: # ID and name tags['_tcod_file_id'].append(fn) tags['_tcod_file_name'].append(f['name']) # Checksums md5sum = None sha1sum = None if f['type'] == 'file': md5sum = f['md5'] sha1sum = f['sha1'] else: md5sum = '.' sha1sum = '.' tags['_tcod_file_md5sum'].append(md5sum) tags['_tcod_file_sha1sum'].append(sha1sum) # Content, encoding and URI contents = '?' encoding = None if 'uri' in f.keys(): contents = '.' tags['_tcod_file_URI'].append(f['uri']) else: tags['_tcod_file_URI'].append('?') if f['type'] == 'file': contents,encoding = \ cif_encode_contents(f['contents'], gzip=gzip, gzip_threshold=gzip_threshold) else: contents = '.' if encoding is None: encoding = '.' elif encoding not in encodings: encodings.append(encoding) tags['_tcod_file_contents'].append(contents) tags['_tcod_file_content_encoding'].append(encoding) # Role role = '?' if 'role' in f.keys(): role = f['role'] tags['_tcod_file_role'].append(role) fn = fn + 1 # Describing the encodings if encodings: for tag in tcod_loops['_tcod_content_encoding']: tags[tag] = [] for encoding in encodings: layers = encoding.split('+') for i in range(0, len(layers)): tags['_tcod_content_encoding_id'].append(encoding) tags['_tcod_content_encoding_layer_id'].append(i + 1) tags['_tcod_content_encoding_layer_type'].append(layers[i]) # Describing Brillouin zone (if used) if calc is not None: from aiida.orm.data.array.kpoints import KpointsData kpoints_list = calc.get_inputs(KpointsData, link_type=LinkType.INPUT) # TODO: stop if more than one KpointsData is used? if len(kpoints_list) == 1: kpoints = kpoints_list[0] density, shift = kpoints.get_kpoints_mesh() tags['_dft_BZ_integration_grid_X'] = density[0] tags['_dft_BZ_integration_grid_Y'] = density[1] tags['_dft_BZ_integration_grid_Z'] = density[2] tags['_dft_BZ_integration_grid_shift_X'] = shift[0] tags['_dft_BZ_integration_grid_shift_Y'] = shift[1] tags['_dft_BZ_integration_grid_shift_Z'] = shift[2] from aiida.common.exceptions import MultipleObjectsError from aiida.common.pluginloader import all_plugins, get_plugin category = 'tools.dbexporters.tcod_plugins' plugins = list() if calc is not None: for entry_point in all_plugins(category): plugin = get_plugin(category, entry_point) if calc._plugin_type_string.endswith(plugin._plugin_type_string + '.'): plugins.append(plugin) if len(plugins) > 1: raise MultipleObjectsError('more than one plugin found for {}'.format( calc._plugin_type_string)) if len(plugins) == 1: plugin = plugins[0] translated_tags = translate_calculation_specific_values(calc, plugin) tags.update(translated_tags) return tags