def get_builder(self): """ Create and return a new ProcessBuilder for the default Calculation plugin, as obtained by the self.get_input_plugin_name() method. :note: it also sets the ``builder.code`` value. :raise MissingPluginError: if the specified plugin does not exist. :raise ValueError: if no default plugin was specified. :return: """ from aiida.orm.utils import CalculationFactory plugin_name = self.get_input_plugin_name() if plugin_name is None: raise ValueError( "You did not specify a default input plugin for this code") try: C = CalculationFactory(plugin_name) except MissingPluginError: raise MissingPluginError("The input_plugin name for this code is " "'{}', but it is not an existing plugin" "name".format(plugin_name)) builder = C.get_builder() # Setup the code already builder.code = self return builder
def launch(code, structure, pseudo_family, kpoints, max_num_machines, max_wallclock_seconds, daemon, mode): """ Run a PwCalculation for a given input structure """ from aiida.orm import load_node from aiida.orm.data.parameter import ParameterData from aiida.orm.data.upf import get_pseudos_from_structure from aiida.orm.utils import CalculationFactory from aiida.work.run import run, submit from aiida_quantumespresso.utils.resources import get_default_options PwCalculation = CalculationFactory('quantumespresso.pw') parameters = { 'CONTROL': { 'calculation': mode, }, 'SYSTEM': { 'ecutwfc': 30., 'ecutrho': 240., }, } inputs = { 'code': code, 'structure': structure, 'pseudo': get_pseudos_from_structure(structure, pseudo_family), 'kpoints': kpoints, 'parameters': ParameterData(dict=parameters), 'settings': ParameterData(dict={}), '_options': get_default_options(max_num_machines, max_wallclock_seconds), } process = PwCalculation.process() if daemon: calculation = submit(process, **inputs) click.echo('Submitted {}<{}> to the daemon'.format( PwCalculation.__name__, calculation.pid)) else: click.echo('Running a PwCalculation in the {} mode... '.format(mode)) results, pk = run(process, _return_pid=True, **inputs) calculation = load_node(pk) click.echo('PwCalculation<{}> terminated with state: {}'.format( pk, calculation.get_state())) click.echo('\n{link:25s} {node}'.format(link='Output link', node='Node pk and type')) click.echo('{s}'.format(s='-' * 60)) for link, node in sorted(calculation.get_outputs(also_labels=True)): click.echo('{:25s} <{}> {}'.format(link, node.pk, node.__class__.__name__))
def launch(code, calculation, kpoints, max_num_machines, max_wallclock_seconds, daemon): """ Run a HpCalculation for a previously completed PwCalculation """ from aiida.orm import load_node from aiida.orm.data.parameter import ParameterData from aiida.orm.data.upf import get_pseudos_from_structure from aiida.orm.utils import CalculationFactory from aiida.work.launch import run_get_pid, submit from aiida_quantumespresso.utils.resources import get_default_options from aiida_quantumespresso_hp.utils.validation import validate_parent_calculation HpCalculation = CalculationFactory('quantumespresso.hp') try: validate_parent_calculation(calculation) except ValueError as exception: raise click.BadParameter( 'invalid parent calculation: {}'.format(exception)) parameters = {'INPUTHP': {}} inputs = { 'code': code, 'qpoints': kpoints, 'parameters': ParameterData(dict=parameters), 'parent_folder': calculation.out.remote_folder, 'options': get_default_options(max_num_machines, max_wallclock_seconds), } click.echo('Running a hp.x calculation ... ') process = HpCalculation.process() if daemon: calculation = submit(process, **inputs) pk = calculation.pk click.echo('Submitted {}<{}> to the daemon'.format( HpCalculation.__name__, calculation.pk)) else: results, pk = run_get_pid(process, **inputs) calculation = load_node(pk) click.echo('HpCalculation<{}> terminated with state: {}'.format( pk, calculation.get_state())) click.echo('\n{link:25s} {node}'.format(link='Output link', node='Node pk and type')) click.echo('{s}'.format(s='-' * 60)) for link, node in sorted(calculation.get_outputs(also_labels=True)): click.echo('{:25s} <{}> {}'.format(link, node.pk, node.__class__.__name__))
def launch( code, parent_calc, kpoints, max_num_machines, max_wallclock_seconds, daemon): """ Run the PhBaseWorkChain for a previously completed PwCalculation """ from aiida.orm.data.parameter import ParameterData from aiida.orm.utils import CalculationFactory, WorkflowFactory from aiida.work.run import run, submit from aiida_quantumespresso.utils.resources import get_default_options PwCalculation = CalculationFactory('quantumespresso.pw') PhBaseWorkChain = WorkflowFactory('quantumespresso.ph.base') parameters = { 'INPUTPH': { } } options = get_default_options(max_num_machines, max_wallclock_seconds) inputs = { 'code': code, 'qpoints': kpoints, 'parent_folder': parent_calc.out.remote_folder, 'parameters': ParameterData(dict=parameters), 'options': ParameterData(dict=options), } if daemon: workchain = submit(PhBaseWorkChain, **inputs) click.echo('Submitted {}<{}> to the daemon'.format(PhBaseWorkChain.__name__, workchain.pid)) else: run(PhBaseWorkChain, **inputs)
def generate_scf_input_params(structure, codename, pseudo_family): # The inputs pw_calculation_class = CalculationFactory("quantumespresso.pw") inputs = pw_calculation_class.process().get_builder() # The structure inputs.structure = structure inputs.code = orm.Code.get_from_string(codename.value) inputs.options.resources = {"num_machines": 1} inputs.options.max_wallclock_seconds = 30 * 60 # Kpoints KpointsData = orm.DataFactory("array.kpoints") kpoints = KpointsData() kpoints_mesh = 2 kpoints.set_kpoints_mesh([kpoints_mesh, kpoints_mesh, kpoints_mesh]) inputs.kpoints = kpoints # Calculation parameters parameters_dict = { "CONTROL": { "calculation": "scf", "tstress": True, "tprnfor": True, }, "SYSTEM": { "ecutwfc": 30., "ecutrho": 200., }, "ELECTRONS": { "conv_thr": 1.e-6, } } orm.data.ParameterData = orm.DataFactory("parameter") inputs.parameters = orm.data.ParameterData(dict=parameters_dict) # Pseudopotentials inputs.pseudo = get_pseudos(structure, str(pseudo_family)) return inputs
def new_calc(self, *args, **kwargs): """ Create and return a new Calculation object (unstored) with the correct plugin subclass, as obtained by the self.get_input_plugin_name() method. Parameters are passed to the calculation __init__ method. :note: it also directly creates the link to this code (that will of course be cached, since the new node is not stored yet). :raise MissingPluginError: if the specified plugin does not exist. :raise ValueError: if no default plugin was specified in the code. """ import warnings warnings.warn( 'directly creating and submitting calculations is deprecated, use the {}\nSee:{}' .format('ProcessBuilder', DEPRECATION_DOCS_URL), DeprecationWarning) from aiida.orm.utils import CalculationFactory plugin_name = self.get_input_plugin_name() if plugin_name is None: raise ValueError("You did not specify an input plugin " "for this code") try: C = CalculationFactory(plugin_name) except MissingPluginError: raise MissingPluginError("The input_plugin name for this code is " "'{}', but it is not an existing plugin" "name".format(plugin_name)) # For remote codes, automatically set the computer, # unless explicitly set by the user if not self.is_local(): if 'computer' not in kwargs: kwargs['computer'] = self.get_remote_computer() new_calc = C(*args, **kwargs) # I link to the code new_calc.use_code(self) return new_calc
from aiida.work.run import submit from aiida.work.workchain import ToContext, if_, while_ from aiida_quantumespresso.common.exceptions import UnexpectedCalculationFailure from aiida_quantumespresso.common.workchain.utils import ErrorHandlerReport from aiida_quantumespresso.common.workchain.utils import register_error_handler from aiida_quantumespresso.common.workchain.base.restart import BaseRestartWorkChain from aiida_quantumespresso.utils.defaults.calculation import pw as qe_defaults from aiida_quantumespresso.utils.mapping import update_mapping from aiida_quantumespresso.utils.pseudopotential import validate_and_prepare_pseudos_inputs from aiida_quantumespresso.utils.resources import get_default_options from aiida_quantumespresso.utils.resources import get_pw_parallelization_parameters from aiida_quantumespresso.utils.resources import cmdline_remove_npools from aiida_quantumespresso.utils.resources import create_scheduler_resources PwCalculation = CalculationFactory('quantumespresso.pw') class PwBaseWorkChain(BaseRestartWorkChain): """ Base workchain to launch a Quantum Espresso pw.x calculation """ _verbose = True _calculation_class = PwCalculation _error_handler_entry_point = 'aiida_quantumespresso.workflow_error_handlers.pw.base' defaults = AttributeDict({ 'qe': qe_defaults, 'delta_threshold_degauss': 30, 'delta_factor_degauss': 0.1, 'delta_factor_mixing_beta': 0.8,
from aiida.common.extendeddicts import AttributeDict from aiida.work.run import submit from aiida.work.workchain import WorkChain, Outputs from aiida.orm import Code from aiida.orm.data.base import Str from aiida.orm.data.parameter import ParameterData from aiida.orm.data.remote import RemoteData from aiida.orm.data.structure import StructureData from aiida.orm.utils import CalculationFactory from aiida.work.workchain import ToContext, if_, while_ Cp2kCalculation = CalculationFactory('cp2k') spin = { "H": 0.0, "Li": 0.0, "Be": 0.0, "B": 0.0, "C": 0.0, "N": 0.0, "O": 0.0, "F": 0.0, "Na": 0.0, "Mg": 0.0, "Al": 0.0, "Si": 0.0, "P": 0.0, "S": 0.0, "Cl": 0.0, "K": 0.0, "Ca": 0.0,
# -*- coding: utf-8 -*- from aiida.common.extendeddicts import AttributeDict from aiida.orm import Code from aiida.orm.data.folder import FolderData from aiida.orm.data.remote import RemoteData from aiida.orm.data.parameter import ParameterData from aiida.orm.utils import CalculationFactory from aiida.work.workchain import while_ from aiida_quantumespresso.common.workchain.base.restart import BaseRestartWorkChain from aiida_quantumespresso.data.forceconstants import ForceconstantsData from aiida_quantumespresso.utils.resources import get_default_options Q2rCalculation = CalculationFactory('quantumespresso.q2r') class Q2rBaseWorkChain(BaseRestartWorkChain): """ Base Workchain to launch a Quantum Espresso q2r.x calculation and restart it until successfully finished or until the maximum number of restarts is exceeded """ _verbose = True _calculation_class = Q2rCalculation @classmethod def define(cls, spec): super(Q2rBaseWorkChain, cls).define(spec) spec.input('code', valid_type=Code) spec.input('parent_folder', valid_type=FolderData) spec.input('parameters', valid_type=ParameterData, required=False) spec.input('settings', valid_type=ParameterData, required=False) spec.input('options', valid_type=ParameterData, required=False)
# -*- coding: utf-8 -*- from aiida.common.extendeddicts import AttributeDict from aiida.orm import Code from aiida.orm.data.parameter import ParameterData from aiida.orm.data.array.bands import BandsData from aiida.orm.data.array.kpoints import KpointsData from aiida.orm.utils import CalculationFactory from aiida.work.workchain import while_ from aiida_quantumespresso.common.workchain.base.restart import BaseRestartWorkChain from aiida_quantumespresso.data.forceconstants import ForceconstantsData from aiida_quantumespresso.utils.resources import get_default_options MatdynCalculation = CalculationFactory('quantumespresso.matdyn') class MatdynBaseWorkChain(BaseRestartWorkChain): """ Base Workchain to launch a Quantum Espresso matdyn.x calculation and restart it until successfully finished or until the maximum number of restarts is exceeded """ _calculation_class = MatdynCalculation @classmethod def define(cls, spec): super(MatdynBaseWorkChain, cls).define(spec) spec.input('code', valid_type=Code) spec.input('kpoints', valid_type=KpointsData) spec.input('parent_folder', valid_type=ForceconstantsData) spec.input('parameters', valid_type=ParameterData, required=False) spec.input('settings', valid_type=ParameterData, required=False) spec.input('options', valid_type=ParameterData, required=False)
from aiida.common.extendeddicts import AttributeDict from aiida.work.run import submit from aiida.work.workchain import WorkChain, Outputs from aiida.orm.code import Code from aiida.orm.utils import CalculationFactory, DataFactory from aiida.work.workchain import ToContext, while_ import six # data objects CifData = DataFactory('cif') FolderData = DataFactory('folder') ParameterData = DataFactory('parameter') SinglefileData = DataFactory('singlefile') RaspaCalculation = CalculationFactory('raspa') default_options = { "resources": { "num_machines": 1, "num_mpiprocs_per_machine": 1, }, "max_wallclock_seconds": 1 * 60 * 60, } # pylint: disable=too-many-locals def multiply_unit_cell(cif, threshold): """Returns the multiplication factors (tuple of 3 int) for the cell vectors to respect, in every direction: min(perpendicular_width) > threshold """
from aiida.orm.utils import CalculationFactory from aiida.common.extendeddicts import AttributeDict from aiida.work.run import submit from aiida.work.workchain import ToContext, if_, while_ # imports of common workchain utils. these might be independent of the actual code # and probably could be part of aiida-core? from aiida_quantumespresso.common.exceptions import UnexpectedCalculationFailure from aiida_quantumespresso.common.workchain.utils import ErrorHandlerReport from aiida_quantumespresso.common.workchain.utils import register_error_handler from aiida_quantumespresso.common.workchain.base.restart import BaseRestartWorkChain # calculation specific utils, which have to be implemented for each plugin from aiida_vasp.utils.pseudopotential import validate_and_prepare_pseudos_inputs VASPCalculation = CalculationFactory('vasp.vasp') class VASPBaseWorkChain(BaseRestartWorkChain): """ Base workchain to launch a VASP calculation """ _verbose = True _calculation_class = VASPCalculation _error_handler_entry_point = 'aiida_quantumespresso.workflow_error_handlers.pw.base' def __init__(self, *args, **kwargs): super(VASPBaseWorkChain, self).__init__(*args, **kwargs) @classmethod def define(cls, spec):
import sys from ase.io import read, write from aiida.orm.calculation.work import WorkCalculation from aiida.orm.data.structure import StructureData from aiida.orm.utils import CalculationFactory cp2k_calc = CalculationFactory('cp2k') def parse_out(cp2k_calc, grep_string, n_word_print): path = cp2k_calc.out.retrieved.get_abs_path() + '/path/aiida.out' with open(path) as f: for line in f.readlines(): if grep_string in line: #print line result = line.split()[n_word_print] return result def print_field(to_parse, cp2k_calc=None, title=False): for element in to_parse: length = element["print_field"] if title: print element["title"].rjust(length)[:length], else: print parse_out(cp2k_calc, element["grep_string"], element["n_word_print"]).rjust(length)[:length], print " |",
def launch(code, structure, pseudo_family, kpoints, max_num_machines, max_wallclock_seconds, daemon, ecutwfc, ecutrho, hubbard_u, hubbard_v, hubbard_file_pk, starting_magnetization, smearing, mode): """ Run a PwCalculation for a given input structure """ from aiida.orm.data.parameter import ParameterData from aiida.orm.data.upf import get_pseudos_from_structure from aiida.orm.utils import CalculationFactory from aiida.work.launch import run_get_node, submit from aiida_quantumespresso.utils.resources import get_default_options PwCalculation = CalculationFactory('quantumespresso.pw') parameters = { 'CONTROL': { 'calculation': mode, }, 'SYSTEM': { 'ecutwfc': ecutwfc, 'ecutrho': ecutrho, }, } try: hubbard_file = validate.validate_hubbard_parameters( structure, parameters, hubbard_u, hubbard_v, hubbard_file_pk) except ValueError as exception: raise click.BadParameter(exception.message) try: validate.validate_starting_magnetization(structure, parameters, starting_magnetization) except ValueError as exception: raise click.BadParameter(exception.message) try: validate.validate_smearing(parameters, smearing) except ValueError as exception: raise click.BadParameter(exception.message) inputs = { 'code': code, 'structure': structure, 'pseudo': get_pseudos_from_structure(structure, pseudo_family), 'kpoints': kpoints, 'parameters': ParameterData(dict=parameters), 'settings': ParameterData(dict={}), 'options': get_default_options(max_num_machines, max_wallclock_seconds), } if hubbard_file: inputs['hubbard_file'] = hubbard_file if daemon: calculation = submit(PwCalculation, **inputs) click.echo('Submitted {}<{}> to the daemon'.format( PwCalculation.__name__, calculation.pk)) else: click.echo( 'Running a pw.x calculation in the {} mode... '.format(mode)) results, calculation = run_get_node(PwCalculation, **inputs) click.echo('PwCalculation<{}> terminated with state: {}'.format( calculation.pk, calculation.get_state())) click.echo('\n{link:25s} {node}'.format(link='Output link', node='Node pk and type')) click.echo('{s}'.format(s='-' * 60)) for link, node in sorted(calculation.get_outputs(also_labels=True)): click.echo('{:25s} <{}> {}'.format(link, node.pk, node.__class__.__name__))