def _rehash_cmd(all, class_name, pks): try_load_dbenv() from aiida.orm.querybuilder import QueryBuilder # Get the Node class to match try: node_class = load_class(class_name) except ClassNotFoundException: click.echo("Could not load class '{}'.\nAborted!".format(class_name)) sys.exit(1) # Add the filters for the class and PKs. qb = QueryBuilder() qb.append(node_class, tag='node') if pks: qb.add_filter('node', {'id': {'in': pks}}) else: if not all: click.echo( "Nothing specified, nothing re-hashed.\nExplicitly specify the PK of the nodes, or use '--all'." ) return if not qb.count(): click.echo('No matching nodes found.') return for i, (node, ) in enumerate(qb.iterall()): if i % 100 == 0: click.echo('.', nl=False) node.rehash() click.echo('\nAll done! {} node(s) re-hashed.'.format(i + 1))
def can_document_member(cls, member, membername, isattr, parent): try: import aiida aiida.try_load_dbenv() from aiida.work.workchain import WorkChain return issubclass(member, WorkChain) except: return False
def load_workchain(self): """Loads the workchain and sets up additional attributes.""" # pylint: disable=attribute-defined-outside-init aiida.try_load_dbenv() self.class_name = self.arguments[0].split('(')[0] self.module_name = self.options['module'] self.workchain_name = self.module_name + '.' + self.class_name self.workchain = get_object_from_string(self.workchain_name) self.workchain_spec = self.workchain.spec()
def command(): """ Wrapped decorator for click's command decorator, which makes sure that the database environment is loaded """ from aiida import try_load_dbenv try_load_dbenv() @click.decorators.command def inner(): func(*args, **kwargs) return inner
def complete_plugins(self, subargs_idx, subargs): """ Return the list of plugins registered under the 'workflows' category """ from aiida import try_load_dbenv try_load_dbenv() from aiida.common.pluginloader import plugin_list plugins = sorted(plugin_list('workflows')) # Do not return plugins that are already on the command line other_subargs = subargs[:subargs_idx] + subargs[subargs_idx + 1:] return_plugins = [_ for _ in plugins if _ not in other_subargs] return "\n".join(return_plugins)
def kill(pks): from aiida import try_load_dbenv try_load_dbenv() from aiida.orm import load_node from aiida.orm.calculation.work import WorkCalculation nodes = [load_node(pk) for pk in pks] workchain_nodes = [n for n in nodes if isinstance(n, WorkCalculation)] running_workchain_nodes = [n for n in nodes if not n.has_finished()] num_workchains = len(running_workchain_nodes) if num_workchains > 0: answer = click.prompt( 'Are you sure you want to kill {} workflows and all their children? [y/n]' .format(num_workchains)).lower() if answer == 'y': click.echo('Killing workflows.') for n in running_workchain_nodes: n.kill() else: click.echo('Abort!') else: click.echo('No pks of valid running workchains given.')
#!/usr/bin/env python from __future__ import absolute_import import aiida from six.moves import range aiida.try_load_dbenv() from aiida.orm import Group, StructureData from aiida_alloy.utils import * import ase from ase.build import sort import click import copy import numpy as np import pandas as pd import sys @click.command() @click.option('-a', '--lattice_size', required=True, help="lattice length (in Ang) to use") @click.option('-spsh', '--supercell_shape', required=True, help="shape of the supercell to use, format: Nx,Ny,Nz") @click.option('-me', '--matrix_element', required=True, help="element to be used as the ") @click.option(
def run(self): aiida.try_load_dbenv() self.load_workchain() return self.build_node_tree()