def main(): """Main execution when called as a script.""" warnings.filterwarnings('ignore') profile = 'asc' pseudo_family_id = 'SSSP/1.1/PBE/efficiency' load_profile(profile) controller = PwBaseSubmissionController( pw_code_id='pw-6.7MaX_conda', structure_group_id='structures/mp/2018_10_18', structure_filters={ 'attributes.sites': { 'longer': 0, 'shorter': 3 }, }, pseudo_family_id=pseudo_family_id, group_label='tests/pw_base', max_concurrent=2) print('Max concurrent :', controller.max_concurrent) print('Active slots :', controller.num_active_slots) print('Available slots:', controller.num_available_slots) print('Already run :', controller.num_already_run) print('Still to run :', controller.num_to_run) print() print('Submitting...') run_processes = controller.submit_new_batch(dry_run=False) for run_process_extras, run_process in run_processes.items(): print(f'{run_process_extras} --> <{run_process}>') print('Done.')
def main(): # TODO: change this, it's not the recommended way (things written on the command line are default commands) parser = argparse.ArgumentParser('aiida-node-shell') parser.add_argument('-p', '--profile', required=False, default=None, help="The profile to load") parser.add_argument('node_identifier', nargs='?') parsed = parser.parse_args() aiida.load_profile(parsed.profile) try: sys.argv = ['aiida-node-shell'] shell = AiiDANodeShell( node_identifier=parsed.node_identifier, startup_script=os.path.expanduser('~/.aiidashellrc')) except Exception as exc: print("ERROR: {}: {}".format(exc.__class__.__name__, exc)) else: while True: try: retcode = shell.cmdloop() print() sys.exit(retcode) break except KeyboardInterrupt: # CTRL+C pressed # Ignore CTRL+C print() print()
def create_profile(self): """ Set AiiDA to use the tests config dir and create a default profile there Warning: the AiiDA dbenv must not be loaded when this is called! """ from aiida.manage.configuration import settings, load_profile, Profile if not self._has_test_db: self.create_aiida_db() if not self.root_dir: self.root_dir = tempfile.mkdtemp() configuration.CONFIG = None settings.AIIDA_CONFIG_FOLDER = self.config_dir configuration.PROFILE = None create_instance_directories() profile_name = self.profile_info['name'] config = configuration.get_config(create=True) profile = Profile(profile_name, self.profile_dictionary) config.add_profile(profile) config.set_default_profile(profile_name).store() self._profile = profile load_profile(profile_name) backend = manager.get_manager()._load_backend(schema_check=False) backend.migrate() self._select_db_test_case(backend=self._profile.database_backend) self.init_db()
def pull(self, *, profile: Optional[str] = None, **kwargs: Any) -> None: """Import nodes from an archive. :param profile: The AiiDA profile name (or use default) """ if "uuids" in kwargs: raise NotImplementedError("Cannot specify particular UUIDs") load_profile(profile) import_data(str(self.location))
def query_aiida_1(): """Statistics query for AiiDA 1.0 and above.""" from aiida import load_profile from aiida.orm import QueryBuilder, Node load_profile() qb = QueryBuilder() qb.append(Node, project=['node_type', 'process_type']) return qb.all()
def push(self, uuids: List[str], *, profile: Optional[str] = None, **kwargs: Any) -> None: """Export nodes to an archive. :param uuids: the list of node UUIDs to push to the archive. :param profile: The AiiDA profile name (or use default) """ load_profile(profile) export([load_node(uid) for uid in uuids], filename=str(self.location))
def run(obj: dict, log_level: str, debug: bool): """Run AiiDA-OPTIMADE server.""" import os import uvicorn log_level = log_level.lower() if debug and log_level == "info": log_level = "debug" if log_level == "debug": os.environ["OPTIMADE_DEBUG"] = "1" else: os.environ["OPTIMADE_DEBUG"] = "0" os.environ["AIIDA_OPTIMADE_LOG_LEVEL"] = log_level.upper() if os.getenv("AIIDA_PROFILE") is None: from aiida import load_profile try: profile: str = obj.get("profile").name except AttributeError: profile = None profile_name: str = load_profile(profile).name os.environ["AIIDA_PROFILE"] = profile_name uvicorn.run("aiida_optimade.main:APP", reload=True, port=5000, log_level=log_level)
def init(obj: dict): """Initialize an AiiDA database to be served with AiiDA-OPTIMADE.""" from aiida import load_profile try: profile: str = obj.get("profile").name except AttributeError: profile = None profile = load_profile(profile).name try: from aiida_optimade.routers.structures import STRUCTURES click.echo( f"Initializing {profile!r}. Note: This may take several minutes!") STRUCTURES._filter_fields = set() STRUCTURES._alias_filter({"nelements": "2"}) updated_pks = STRUCTURES._check_and_calculate_entities() except Exception as exc: # pylint: disable=broad-except click.echo( f"An exception ({exc.__class__.__name__}) happened while trying to " f"initialize {profile!r}:\n{exc}") return if updated_pks: click.echo( f"Success! {profile!r} has been initialized for use with AiiDA-OPTIMADE." ) click.echo( f"{len(updated_pks)} StructureData Nodes have been initialized.") else: click.echo( f"No new StructureData Nodes found to initialize for {profile!r}.")
def create_authinfo(computer): """ Allow the current user to use the given computer. Deal with backwards compatibility down to aiida 0.11 """ from aiida import load_profile load_profile() from aiida.orm import backend as orm_backend authinfo = None if hasattr(orm_backend, 'construct_backend'): backend = orm_backend.construct_backend() authinfo = backend.authinfos.create(computer=computer, user=get_current_user()) else: from aiida.backends.djsite.db.models import DbAuthInfo authinfo = DbAuthInfo(dbcomputer=computer.dbcomputer, aiidauser=get_current_user()) return authinfo
def list(): # pylint: disable=redefined-builtin """ Display all KkrstructureData nodes """ from aiida import load_profile load_profile() from aiida.orm.querybuilder import QueryBuilder from aiida.plugins import DataFactory KKrStructure = DataFactory('kkr.kkrstructure') qb = QueryBuilder() qb.append(KkrStructure) results = qb.all() s = "" for result in results: obj = result[0] s += "{}, pk: {}\n".format(str(obj), obj.pk) sys.stdout.write(s)
def load_aiida_profile(): """ Load aiida profile. """ try: from aiida import load_profile except ImportError: err_msg = "Aiida is not installed. Skip loading aiida profile." print(err_msg) raise from aiida.common.exceptions import ProfileConfigurationError try: load_profile() except ProfileConfigurationError as err: err_msg = "Failed to load aiida profile. " \ + "Please check your aiida configuration." print(err_msg) raise ImportError from err
def __init__(self, profile_name): """ Use an existing profile. :param profile_name: Name of the profile to be loaded """ from aiida import load_profile from aiida.backends.testbase import check_if_tests_can_run self._profile = None self._user = None try: self._profile = load_profile(profile_name) manager.get_manager()._load_backend(schema_check=False) # pylint: disable=protected-access except Exception: raise TestManagerError('Unable to load test profile \'{}\'.'.format(profile_name)) check_if_tests_can_run() self._select_db_test_case(backend=self._profile.database_backend)
import aiida from aiida.orm import Code, Str, Dict import pytest import deliver from deliver import deliver_stage, stage_solution aiida.load_profile("<profile>") deliver.GENERAL_INPUTS = { "code": Code.get_from_string('<code>'), "pseudo_family": Str("<pseudo-family>"), "options": Dict(dict={ 'withmpi': False, 'max_wallclock_seconds': 3600 * 2 }), "parameters": Dict(), } @pytest.mark.parametrize("stage", [1, 2, 3, 4]) def test_solution(stage): deliver_stage(stage, stage_solution(stage).deliverable)
from aiida_optimade.common import LOGGER from aiida_optimade.middleware import RedirectOpenApiDocs from aiida_optimade.routers import ( info, links, structures, ) from aiida_optimade.utils import get_custom_base_url_path, OPEN_API_ENDPOINTS if CONFIG.debug: # pragma: no cover LOGGER.info("DEBUG MODE") # Load AiiDA profile PROFILE_NAME = os.getenv("AIIDA_PROFILE") load_profile(PROFILE_NAME) LOGGER.debug("AiiDA Profile: %s", PROFILE_NAME) # Load links in mongomock LINKS_DATA = Path(__file__).parent.joinpath("data/links.json").resolve() with open(LINKS_DATA) as handle: data = json.load(handle) processed = [] for link in data: link["_id"] = {"$oid": mongo_id_for_database(link["id"], link["type"])} processed.append(link) links.LINKS.collection.insert_many( bson.json_util.loads(bson.json_util.dumps(processed)))
#!/usr/bin/env python import aiida aiida.load_profile() import click import ase import glob import json import os from aiida_create_solutesupercell_structures import * @click.command() @click.option('-pbd', '--phonopy_basedir', required=True, help="path to a directory containing a dump of OQMD entries") @click.option('-sg', '--structure_group_label', required=True, help="Output AiiDA group to store created structures") @click.option('-sgd', '--structure_group_description', default="", help="Description for output AiiDA group") @click.option('-dr', '--dryrun', is_flag=True, help="Prints structures and extras but does not store anything") def launch(phonopy_basedir, structure_group_label, structure_group_description, dryrun): """ Load an 'OQMD' dump (created by an custom script). Expects a directory containing a set of OQMD_<ID> vasp-formatted POSCAR, and for each of these a corresponding OQMD_<ID>.json json file wich contains a dump of the meta-data """ print("loading dataset: {} to group: {}".format(phonopy_basedir, structure_group_label)) # Setup/Retrieve the Group structure_group = Group.objects.get_or_create(label=structure_group_label, description=structure_group_description)[0]
def load_profile(): import aiida update_config() aiida.load_profile()
app = FastAPI( title="OPTiMaDe API for AiiDA", description= ("The [Open Databases Integration for Materials Design (OPTiMaDe) consortium](http://www.optimade.org/) " "aims to make materials databases inter-operational by developing a common REST API.\n\n" "[Automated Interactive Infrastructure and Database for Computational Science (AiiDA)](http://www.aiida.net) " "aims to help researchers with managing complex workflows and making them fully reproducible." ), version=CONFIG.version, docs_url="/optimade/extensions/docs", redoc_url="/optimade/extensions/redoc", openapi_url="/optimade/extensions/openapi.json", ) profile_name = os.getenv("AIIDA_PROFILE") profile = load_profile(profile_name) valid_prefixes = ["/optimade"] version = [int(_) for _ in CONFIG.version[1:].split(".")] while version: if version[0] or len(version) >= 2: valid_prefixes.append("/optimade/v{}".format(".".join( [str(_) for _ in version]))) version.pop(-1) @app.middleware("http") async def backend_middleware(request: Request, call_next): response = None try: if profile.database_backend == "django":
def test_process(): """Test running a calculation note this does not test that the expected outputs are created of output parsing""" from aiida.plugins import DataFactory, CalculationFactory from aiida.engine import run from aiida.orm import Code, SinglefileData, Int, Float, Str, Bool, List, Dict, ArrayData, XyData, SinglefileData, FolderData, RemoteData import numpy as np import aiida import os aiida.load_profile() #pre-prepared files dmdata = SinglefileData( file=os.path.join(os.getcwd(), "input_files", 'dmdata')) jij = SinglefileData( file=os.path.join(os.getcwd(), "input_files", 'jij')) momfile = SinglefileData( file=os.path.join(os.getcwd(), "input_files", 'momfile')) posfile = SinglefileData( file=os.path.join(os.getcwd(), "input_files", 'posfile')) qfile = SinglefileData( file=os.path.join(os.getcwd(), "input_files", 'qfile')) # inpsd.dat file selection simid = Str('SCsurf_T') ncell = ArrayData() ncell.set_array('matrix', np.array([128, 128, 1])) BC = Str('P P 0 ') cell = ArrayData() cell.set_array('matrix', np.array([[1.00000, 0.00000, 0.00000], [ 0.00000, 1.00000, 0.00000], [0.00000, 0.00000, 1.00000]])) do_prnstruct = Int(2) maptype = Int(2) SDEalgh = Int(1) Initmag = Int(3) ip_mode = Str('Q') qm_svec = ArrayData() qm_svec.set_array('matrix', np.array([1, -1, 0])) qm_nvec = ArrayData() qm_nvec.set_array('matrix', np.array([0, 0, 1])) mode = Str('S') temp = Float(0.000) damping = Float(0.500) Nstep = Int(5000) timestep = Str('1.000d-15') qpoints = Str('F') plotenergy = Int(1) do_avrg = Str('Y') code = Code.get_from_string('uppasd_dev@uppasd_local') r_l = List(list= [f'coord.{simid.value}.out', f'qm_minima.{simid.value}.out', f'qm_sweep.{simid.value}.out', f'qpoints.out', f'totenergy.{simid.value}.out', f'averages.{simid.value}.out', 'fort.2000', 'inp.SCsurf_T.yaml', 'qm_restart.SCsurf_T.out', 'restart.SCsurf_T.out']) # set up calculation inputs = { 'code': code, 'dmdata': dmdata, 'jij': jij, 'momfile': momfile, 'posfile': posfile, 'qfile': qfile, 'simid': simid, 'ncell': ncell, 'BC': BC, 'cell': cell, 'do_prnstruct': do_prnstruct, 'maptype': maptype, 'SDEalgh': SDEalgh, 'Initmag': Initmag, 'ip_mode': ip_mode, 'qm_svec': qm_svec, 'qm_nvec': qm_nvec, 'mode': mode, 'temp': temp, 'damping': damping, 'Nstep': Nstep, 'timestep': timestep, 'qpoints': qpoints, 'plotenergy': plotenergy, 'do_avrg': do_avrg, 'retrieve_list_name': r_l, 'metadata': { 'options': { 'max_wallclock_seconds': 60, 'resources': {'num_machines': 1}, 'input_filename': 'inpsd.dat', 'parser_name': 'UppASD_core_parsers', }, }, } result = run(CalculationFactory('UppASD_core_calculations'), **inputs) computed_diff = result['UppASD_core_calculations'].get_content() assert 'content1' in computed_diff assert 'content2' in computed_diff
"""Reusable widgets for AiiDA lab applications.""" # pylint: disable=unused-import,wrong-import-position from aiida import load_profile load_profile() from .codes import CodeDropdown, AiiDACodeSetup, valid_aiidacode_args from .computers import SshComputerSetup, valid_sshcomputer_args from .computers import AiidaComputerSetup, valid_aiidacomputer_args from .computers import ComputerDropdown from .databases import CodQueryWidget from .export import ExportButtonWidget from .process import ProgressBarWidget, ProcessFollowerWidget, ProcessInputsWidget, ProcessOutputsWidget from .process import ProcessCallStackWidget, RunningCalcJobOutputWidget, SubmitButtonWidget, ProcessReportWidget from .process import ProcessListWidget from .structures import StructureManagerWidget from .structures import StructureBrowserWidget, StructureExamplesWidget, StructureUploadWidget, SmilesWidget from .structures import BasicStructureEditor from .structures_multi import MultiStructureUploadWidget from .viewers import viewer __version__ = "1.0.0b10"
def load_profile(): """Load AiiDA profile according to environment variables.""" import aiida update_config() aiida.load_profile()