Beispiel #1
0
    def test_session_update_and_expiration_1(self):
        """
        expire_on_commit=True & adding manually and committing
        computer and code objects.
        """
        from aiida.orm.computer import Computer
        from aiida.orm.code import Code
        from aiida.orm.user import User

        self.set_connection(expire_on_commit=True)

        session = aiida.backends.sqlalchemy.get_scoped_session()

        user = User(email=get_configured_user_email())
        session.add(user._dbuser)
        session.commit()

        defaults = dict(name='localhost',
                        hostname='localhost',
                        transport_type='local',
                        scheduler_type='pbspro',
                        workdir='/tmp/aiida')
        computer = Computer(**defaults)
        session.add(computer._dbcomputer)
        session.commit()

        code = Code()
        code.set_remote_computer_exec((computer, '/x.x'))
        session.add(code.dbnode)
        session.commit()

        self.drop_connection()
Beispiel #2
0
    def run_cp2k_charge_density(self):
        """
        Compute the charge-density of a structure that can be later used for extracting ddec point charges.
        """
        options = {
            "resources": {
                "num_machines": 4,
                "num_mpiprocs_per_machine": 12,
            },
            "max_wallclock_seconds": 3 * 60 * 60,
        }

        inputs = {
            'code'       : Code.get_from_string(self.inputs.cp2k_codename.value),
            'structure'  : from_cif_to_structuredata(self.ctx.processed_structure),
            'parameters' : self.inputs.cp2k_parameters,
            '_options'   : options,
            '_label'     : "run_chargedensity_cp2k",
        }

        # Create the calculation process and launch it
        process = Cp2kCalculation.process()
        future  = submit(process, **inputs)
        self.report("pk: {} | Running cp2k to compute the charge-density")
        self.ctx.cp2k_pid=future.pid
        return ToContext(cp2k=Outputs(future))
Beispiel #3
0
def generate_scf_input_params(structure, codename, pseudo_family):
    # The inputs
    inputs = PwCalculation.process().get_inputs_template()

    # The structure
    inputs.structure = structure

    inputs.code = Code.get_from_string(codename.value)
    inputs._options.resources = {"num_machines": 1}
    inputs._options.max_wallclock_seconds = 30 * 60

    # Kpoints
    KpointsData = 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,  #  Important that this stays to get stress
                    "tprnfor": True,},
        "SYSTEM": {"ecutwfc": 30.,
                   "ecutrho": 200.,},
        "ELECTRONS": {"conv_thr": 1.e-6,}
    }
    ParameterData = DataFactory("parameter")
    inputs.parameters = ParameterData(dict=parameters_dict)

    # Pseudopotentials
    inputs.pseudo = get_pseudos(structure, str(pseudo_family))

    return inputs
def run(structure_pk, code, atomic_files, group, partition, ranks_per_node, ranks_kp, ranks_diag, kmesh):

    # load code from label@computer
    c = Code.get_from_string(code)
    if not atomic_files:
        if c.get_input_plugin_name() == 'quantumespresso.pw':
            atomic_files = 'SSSP_acc_PBE'
        if c.get_input_plugin_name() == 'exciting.exciting':
            atomic_files = 'high_quality_lapw_species'

    # create k-point mesh
    k = List()
    k.extend(kmesh)
    for spk in structure_pk:
        # load structure from PK
        structure = load_node(spk)
        # create stress tensor workflow
        stress_tensor = Stress_Tensor()
        stress_tensor.run(structure=structure,
                code=c,
                atomic_files=Str(atomic_files),
                group=Str(group),
                kmesh=k,
                partition=Str(partition),
                ranks_per_node=Int(ranks_per_node),
                ranks_kp=Int(ranks_kp),
                ranks_diag=Int(ranks_diag))
def run(structure_pk, code, atomic_files, group, partition, ranks_per_node,
        ranks_kp, ranks_diag, kmesh):

    # load code from label@computer
    c = Code.get_from_string(code)
    if not atomic_files:
        if c.get_input_plugin_name() == 'quantumespresso.pw':
            atomic_files = 'SSSP_acc_PBE'
        if c.get_input_plugin_name() == 'exciting.exciting':
            atomic_files = 'high_quality_lapw_species'

    # create k-point mesh
    k = List()
    k.extend(kmesh)
    for spk in structure_pk:
        # load structure from PK
        structure = load_node(spk)
        # create stress tensor workflow
        stress_tensor = Stress_Tensor()
        stress_tensor.run(structure=structure,
                          code=c,
                          atomic_files=Str(atomic_files),
                          group=Str(group),
                          kmesh=k,
                          partition=Str(partition),
                          ranks_per_node=Int(ranks_per_node),
                          ranks_kp=Int(ranks_kp),
                          ranks_diag=Int(ranks_diag))
Beispiel #6
0
    def run_block_zeopp(self):
        """
        This is the main function that will perform a raspa
        calculation for the current pressure
        """

        NetworkParameters = DataFactory('zeopp.parameters')
        # Create the input dictionary
        sigma = self.inputs.probe_molecule.get_dict()['sigma']
        params = {
            'ha':True,
            'block': [sigma, 200],
        }
        inputs = {
            'code'       : Code.get_from_string(self.inputs.zeopp_codename.value),
            'structure'  : self.ctx.processed_structure,
            'parameters' : NetworkParameters(dict=params),
            '_options'   : self.inputs._options,
            '_label'     : "run_block_zeopp",

        }

        # Create the calculation process and launch it
        process = ZeoppCalculation.process()
        future  = submit(process, **inputs)
        self.report("pk: {} | Running zeo++ block volume calculation".format(future.pid))
        
        self.ctx.block_pk = future.pid

        return ToContext(zeopp=Outputs(future))
Beispiel #7
0
    def run_loading_raspa(self):
        """
        This is the main function that will perform a raspa
        calculation for the current pressure
        """
        pressure = self.ctx.pressures[self.ctx.p]
        self.ctx.raspa_parameters['GeneralSettings']['ExternalPressure'] = pressure
        if self.ctx.prev_pk is not None:
            self.ctx.raspa_parameters['GeneralSettings']['RestartFile'] = True
            self.ctx.raspa_parameters['GeneralSettings']['RestartFilePk'] = self.ctx.prev_pk

        # Create the input dictionary
        inputs = {
            'code'       : Code.get_from_string(self.inputs.raspa_codename.value),
            'structure'  : self.ctx.processed_structure,
            'parameters' : ParameterData(dict=self.ctx.raspa_parameters),
            '_options'   : self.inputs._options,
            '_label'     : "run_loading_raspa",
        }

        # Create the calculation process and launch it
        process = RaspaCalculation.process()
        future  = submit(process, **inputs)
        self.report("pk: {} | Running raspa for the pressure {} [bar]".format(future.pid, pressure/1e5))

        self.ctx.p += 1
        self.ctx.prev_pk = future.pid

        return ToContext(raspa=Outputs(future))
Beispiel #8
0
    def run_henry_raspa(self):
        """
        This is the main function that will perform a raspa
        calculation for the current pressure
        """
        raspa_parameters = self.inputs.raspa_parameters.get_dict()
        raspa_parameters['GeneralSettings'].pop('ExternalPressure')
        for i, comp in enumerate(raspa_parameters['Component']):
            name = comp['MoleculeName']
            raspa_parameters['Component'][0] = {
                "MoleculeName"                     : name,
                "MoleculeDefinition"               : "TraPPE",
                "WidomProbability"                 : 1.0,
                "CreateNumberOfMolecules"          : 0,
            }
        # Create the input dictionary
        inputs = {
            'code'       : Code.get_from_string(self.inputs.raspa_codename.value),
            'structure'  : self.ctx.processed_structure,
            'parameters' : ParameterData(dict=raspa_parameters),
            '_options'   : self.inputs._options,
            '_label'     : "run_henry_raspa",
        }

        # Create the calculation process and launch it
        process = RaspaCalculation.process()
        future  = submit(process, **inputs)
        self.report("pk: {} | Running raspa for the Henry coefficients".format(future.pid))

        return 
Beispiel #9
0
def main():
    DifferenceCalculation = CalculationFactory('wait.wait')
    builder = DifferenceCalculation.get_builder()
    builder.code = Code.get_from_string('wait')
    builder.options = {'resources': {'num_machines': 1}, 'withmpi': False}

    node = submit(builder)
    print(node.pk)
 def setUpClass(cls):
     super(QETestCase, cls).setUpClass()
     cls.calc_params = {
         'computer': cls.computer,
         'resources': {
             'num_machines': 1,
             'num_mpiprocs_per_machine': 1
         }
     }
     cls.code = Code(remote_computer_exec=(cls.computer, '/x.x')).store()
Beispiel #11
0
def generate_scf_input_params(structure, codename, pseudo, element):
    # The inputs
    inputs = PwCalculation.process().get_inputs_template()

    # The structure
    inputs.structure = structure

    inputs.code = Code.get_from_string(codename)
    # calc.label = "PW test"
    # calc.description = "My first AiiDA calculation of Silicon with Quantum ESPRESSO"
    inputs._options.resources = {"num_machines": 1}
    inputs._options.max_wallclock_seconds = 23*30*60
    queue="compute"
    if queue is not None:
    	inputs._options.queue_name=queue

    # Kpoints
    KpointsData = DataFactory("array.kpoints")
    kpoints = KpointsData()
#    kpoints_mesh = 2
    kp=[0,0,0]

    f=open('/home/bosonie/AIMS/LDARESULTS/NonRelBirchLDAref', 'r')
    for line in f:
        a=line.split()
        if a[0]==element:
            kp[0]=int(a[1])
            kp[1]=int(a[3])
            kp[2]=int(a[5])
            vol=a[7]

    kpoints.set_kpoints_mesh([1,1,1])#[kp[0], kp[1], kp[2]])
    inputs.kpoints = kpoints

    # Calculation parameters
    parameters_dict = {
        "CONTROL": {"calculation": "scf",
                    "tstress": True,  #  Important that this stays to get stress
                    "tprnfor": True,
                    "disk_io": "none"},
        "SYSTEM": {"ecutwfc": 100.,
                   "ecutrho": 200.,
		   "smearing": "gauss",
		   "degauss": 0.000734986},
        "ELECTRONS": {"conv_thr": 1.e-6}
    }
    ParameterData = DataFactory("parameter")
    inputs.parameters = ParameterData(dict=parameters_dict)

    pseudos = {}
    pseudos[element] = pseudo
    inputs.pseudo = pseudos
    
    return inputs
Beispiel #12
0
    def test_session_update_and_expiration_4(self):
        """
        expire_on_commit=False & committing computer and code objects with
        their built-in store function.
        """
        self.set_connection(expire_on_commit=False)

        from aiida.orm.computer import Computer
        from aiida.orm.code import Code
        from aiida.orm.user import User

        session = aiida.backends.sqlalchemy.get_scoped_session()

        user = User(email=get_configured_user_email())
        session.add(user._dbuser)
        session.commit()

        defaults = dict(name='localhost',
                        hostname='localhost',
                        transport_type='local',
                        scheduler_type='pbspro',
                        workdir='/tmp/aiida')
        computer = Computer(**defaults)
        computer.store()

        code = Code()
        code.set_remote_computer_exec((computer, '/x.x'))
        code.store()

        self.drop_connection()
Beispiel #13
0
def run_si_scf(codename, pseudo_family):
    JobCalc = PwCalculation.process()
    inputs = JobCalc.get_inputs_template()

    inputs.code = Code.get_from_string(codename)
    # calc.label = "PW test"
    # calc.description = "My first AiiDA calculation of Silicon with Quantum ESPRESSO"
    inputs._options.resources = {"num_machines": 1}
    inputs._options.max_wallclock_seconds = 30 * 60

    # The structure
    alat = 5.4
    the_cell = [[alat / 2., alat / 2., 0], [alat / 2., 0, alat / 2.],
                [0, alat / 2., alat / 2.]]
    StructureData = DataFactory("structure")
    structure = StructureData(cell=the_cell)
    structure.append_atom(position=(0., 0., 0.), symbols="Si")
    structure.append_atom(position=(alat / 4., alat / 4., alat / 4.),
                          symbols="Si")
    inputs.structure = structure

    # Kpoints
    KpointsData = 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,
        }
    }
    ParameterData = DataFactory("parameter")
    inputs.parameters = ParameterData(dict=parameters_dict)

    # Pseudopotentials
    inputs.pseudo = get_pseudos(structure, pseudo_family)

    # calc.set_extra("element", "Si")
    # calc.submit()
    asyncd(JobCalc, **inputs)
Beispiel #14
0
def generate_pw_input_params(structure, codename, pseudo_family,parameters, calculation_set, kpoints,gamma,settings,parent_folder):
    """Generate PW input._*  from given params """
    inputs = {}
    inputs['structure'] = structure
    inputs['code'] = Code.get_from_string(codename.value)
    calculation_set = calculation_set.get_dict() 
    inputs['options'] = ParameterData(dict=calculation_set)
    if parent_folder:
        inputs['parent_folder'] = parent_folder
    inputs['kpoints']=kpoints
    inputs['parameters'] = parameters  
    inputs['pseudo_family'] =  pseudo_family
    inputs['settings']  = settings
    return  inputs
    def setUpClass(cls):
        super(LocalTestCase, cls).setUpClass()

        # Change transport type to local.
        cls.computer.set_transport_type('local')

        # Configure authinfo for cls.computer and cls.user.
        authinfo = DbAuthInfo(dbcomputer=cls.computer.dbcomputer,
                              aiidauser=cls.user)
        authinfo.set_auth_params({})
        authinfo.save()

        # Set up a code linked to cls.computer. The path is just a fake string.
        cls.code = Code(remote_computer_exec=(cls.computer, '/x.x')).store()
Beispiel #16
0
def generate_ApeCalculation(codename, element, s, p, d, f):

    inp = ApeCalculation.process().get_inputs_template()

    inp.code = Code.get_from_string(codename)
    inp._options.computer = Computer.get('localhost')
    inp._options.resources = {"num_machines": 1}

    check = False
    for ele in ELEMENTS:
        if element == ele.symbol:
            nc = int(ele.number)
            check = True

    print check, nc
    if not check:
        sys.exit("element is not valid")

    corpar = 1
    if nc <= 2:
        corpar = 0

    parameters = ParameterData(
        dict={
            'Title': '{}'.format(element),
            'CalculationMode': 'ae + pp',
            'Verbose': '40',
            'WaveEquation': 'schrodinger',
            'XCFunctional': 'lda_x + lda_c_pz',
            'NuclearCharge': '{}'.format(nc),
            'PPCalculationTolerance': '1.e-6',
            'PPOutputFileFormat': 'upf + siesta',
            'CoreCorrection': '{}'.format(corpar),
            'EigenSolverTolerance': '1.e-8',
            'ODEIntTolerance': '1.e-12'
        })

    orbitals, PPComponents = get_orb_and_PPcomp(nc, s, p, d, f)

    inp.parameters = parameters
    inp.orbitals = orbitals
    inp.PPComponents = PPComponents

    inp._label = "{0} {1} {2} {3}".format(s, p, d, f)
    inp._description = "{} pseudo generation with cut of radii in label".format(
        element)

    return inp
Beispiel #17
0
def generate_scf_input_params(structure, codename, pseudo_family):
    # The inputs
    inputs = PwCalculation.get_builder()

    # The structure
    inputs.structure = structure

    inputs.code = Code.get_from_string(codename)
    # calc.label = "PW test"
    # calc.description = "My first AiiDA calculation of Silicon with Quantum ESPRESSO"
    inputs.options.resources = {"num_machines": 1}
    inputs.options.max_wallclock_seconds = 30 * 60

    # Kpoints
    KpointsData = 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,  #  Important that this stays to get stress
            "tprnfor": True,
        },
        "SYSTEM": {
            "ecutwfc": 30.,
            "ecutrho": 200.,
        },
        "ELECTRONS": {
            "conv_thr": 1.e-6,
        }
    }
    ParameterData = DataFactory("parameter")
    inputs.parameters = ParameterData(dict=parameters_dict)

    # Pseudopotentials
    inputs.pseudo = validate_and_prepare_pseudos_inputs(
        structure, pseudo_family=pseudo_family)

    return inputs
Beispiel #18
0
    def code_rename(self, *args):
        import argparse
        from aiida.common.exceptions import NotExistent

        from aiida.orm.code import Code

        parser = argparse.ArgumentParser(
            prog=self.get_full_command_name(),
            description='Rename a code (change its label).')
        # The default states are those that are shown if no option is given
        parser.add_argument('old_name', help="The old name of the code")
        parser.add_argument('new_name', help="The new name of the code")

        parsed_args = parser.parse_args(args)

        new_name = parsed_args.new_name
        old_name = parsed_args.old_name

        try:
            code = Code.get_from_string(old_name)
        except NotExistent:
            print "ERROR! A code with name {} could not be found".format(
                old_name)
            sys.exit(1)

        suffix = '@{}'.format(code.get_computer().name)
        if new_name.endswith(suffix):
            new_name = new_name[:-len(suffix)]

        if '@' in new_name:
            print >> sys.stderr, "ERROR! Do not put '@' symbols in the code name"
            sys.exit(1)

        retrieved_old_name = '{}@{}'.format(code.label,
                                            code.get_computer().name)
        # CHANGE HERE
        code.label = new_name
        retrieved_new_name = '{}@{}'.format(code.label,
                                            code.get_computer().name)

        print "Renamed code with ID={} from '{}' to '{}'".format(
            code.pk, retrieved_old_name, retrieved_new_name)
Beispiel #19
0
 def run_ddec_point_charges(self):
     """
     Compute ddec point charges from precomputed charge-density.
     """
     cp2k_calc = load_node(self.ctx.cp2k_pid)
     options = self.inputs._options
     #options['prepend_text'] = "export OMP_NUM_THREADS=12"
     inputs = {
         'code'                   : Code.get_from_string(self.inputs.ddec_codename.value),
         'parameters'             : self.inputs.ddec_parameters,
         'electronic_calc_folder' : cp2k_calc.out.remote_folder,
         '_options'               : options,
         '_label'                 : "run_pointcharges_ddec",
     }
     # Create the calculation process and launch it
     process = DdecCalculation.process()
     future  = submit(process, **inputs)
     self.report("pk: {} | Running ddec to compute point charges based on the charge-density")
     self.ctx.ddec_pid=future.pid
     return ToContext(ddec=Outputs(future))
Beispiel #20
0
 def inner(builder, code_string):
     from aiida.orm.code import Code
     builder.code = Code.get_from_string(code_string)
#!/usr/bin/env python
from aiida import load_dbenv
from aiida.orm.code import Code
from aiida.orm import CalculationFactory

# Load the database environment.
load_dbenv()

# Load the PwimmigrantCalculation class.
PwimmigrantCalculation = CalculationFactory('quantumespresso.pwimmigrant')

# Load the Code node representative of the one used to perform the calculations.
code = Code.get('pw_on_TheHive')

# Get the Computer node representative of the one the calculations were run on.
computer = code.get_remote_computer()

# Define the computation resources used for the calculations.
resources = {'num_machines': 1, 'num_mpiprocs_per_machine': 1}

# Initialize the pw_job1 calculation node.
calc1 = PwimmigrantCalculation(computer=computer,
                               resources=resources,
                               remote_workdir='/scratch/',
                               input_file_name='pw_job1.in',
                               output_file_name='pw_job1.out')

# Initialize the pw_job2 calculation node.
calc2 = PwimmigrantCalculation(computer=computer,
                               resources=resources,
                               remote_workdir='/scratch/',
Beispiel #22
0
def generate_yambo_input_params(precodename, yambocodename, parent_folder,
                                parameters, calculation_set, settings):
    inputs = YamboCalculation.process().get_inputs_template()
    inputs.preprocessing_code = Code.get_from_string(precodename.value)
    inputs.code = Code.get_from_string(yambocodename.value)
    calculation_set = calculation_set.get_dict()
    resource = calculation_set.pop('resources', {})
    if resource:
        inputs._options.resources = resource
    inputs._options.max_wallclock_seconds = calculation_set.pop(
        'max_wallclock_seconds', 86400)
    max_memory_kb = calculation_set.pop('max_memory_kb', None)
    if max_memory_kb:
        inputs._options.max_memory_kb = max_memory_kb
    queue_name = calculation_set.pop('queue_name', None)
    if queue_name:
        inputs._options.queue_name = queue_name
    custom_scheduler_commands = calculation_set.pop(
        'custom_scheduler_commands', None)
    if custom_scheduler_commands:
        inputs._options.custom_scheduler_commands = custom_scheduler_commands
    environment_variables = calculation_set.pop("environment_variables", None)
    if environment_variables:
        inputs._options.environment_variables = environment_variables
    label = calculation_set.pop('label', None)
    if label:
        inputs._label = label
    inputs.parent_folder = parent_folder
    inputs.settings = settings
    # Get defaults:
    edit_parameters = parameters.get_dict()
    try:
        calc = parent_folder.get_inputs_dict(link_type=LinkType.CREATE)['remote_folder'].inp.parent_calc_folder.get_inputs_dict()\
               ['remote_folder'].inp.parent_calc_folder.get_inputs_dict()['remote_folder']
    except AttributeError:
        calc = None
    is_pw = False
    if isinstance(calc, PwCalculation):
        is_pw = True
        nelec = calc.out.output_parameters.get_dict()['number_of_electrons']
        nocc = None
        if calc.out.output_parameters.get_dict()['lsda']== True or\
           calc.out.output_parameters.get_dict()['non_colinear_calculation'] == True:
            nocc = nelec / 2
        else:
            nocc = nelec / 2
        bndsrnxp = gbndrnge = nocc
        ngsblxpp = int(calc.out.output_parameters.get_dict()['wfc_cutoff'] *
                       0.073498645 / 4 * 0.25)  # ev to ry then 1/4
        #ngsblxpp =  2
        nkpts = calc.out.output_parameters.get_dict()['number_of_k_points']
        if not resource:
            resource = {
                "num_mpiprocs_per_machine": 8,
                "num_machines": 1
            }  # safe trivial defaults
        tot_mpi = resource[u'num_mpiprocs_per_machine'] * resource[
            u'num_machines']
        if 'FFTGvecs' not in edit_parameters.keys():
            edit_parameters['FFTGvecs'] = 2
            edit_parameters['FFTGvecs_units'] = 'Ry'
        if 'BndsRnXp' not in edit_parameters.keys():
            edit_parameters['BndsRnXp'] = (bndsrnxp / 2, bndsrnxp / 2 + 1)
        if 'GbndRnge' not in edit_parameters.keys():
            edit_parameters['GbndRnge'] = (1.0, gbndrnge / 2)
        if 'NGsBlkXp' not in edit_parameters.keys():
            edit_parameters['NGsBlkXp'] = ngsblxpp
            edit_parameters['NGsBlkXp_units'] = 'RL'
        if 'QPkrange' not in edit_parameters.keys():
            edit_parameters['QPkrange'] = [(1, 1, int(nocc), int(nocc) + 1)
                                           ]  # To revisit
        if 'SE_CPU' not in edit_parameters.keys():
            b, qp = split_incom(tot_mpi)
            edit_parameters['SE_CPU'] = "1 {qp} {b}".format(qp=qp, b=b)
            edit_parameters['SE_ROLEs'] = "q qp b"
        if 'X_all_q_CPU' not in edit_parameters.keys():
            c, v = split_incom(tot_mpi)
            edit_parameters['X_all_q_CPU'] = "1 1 {c} {v}".format(c=c, v=v)
            edit_parameters['X_all_q_ROLEs'] = "q k c v"

    inputs.parameters = ParameterData(dict=edit_parameters)
    return inputs
Beispiel #23
0
    def test_code_local(self):
        import tempfile

        from aiida.orm.code import Code
        from aiida.common.exceptions import ValidationError

        code = Code(local_executable='test.sh')
        with self.assertRaises(ValidationError):
            # No file with name test.sh
            code.store()

        with tempfile.NamedTemporaryFile() as f:
            f.write("#/bin/bash\n\necho test run\n")
            f.flush()
            code.add_path(f.name, 'test.sh')

        code.store()
        self.assertTrue(code.can_run_on(self.computer))
        self.assertTrue(code.get_local_executable(), 'test.sh')
        self.assertTrue(code.get_execname(), 'stest.sh')
Beispiel #24
0
    def test_remote(self):
        import tempfile

        from aiida.orm.code import Code
        from aiida.orm.computer import Computer
        from aiida.common.exceptions import ValidationError

        with self.assertRaises(ValueError):
            # remote_computer_exec has length 2 but is not a list or tuple
            _ = Code(remote_computer_exec='ab')

        # invalid code path
        with self.assertRaises(ValueError):
            _ = Code(remote_computer_exec=(self.computer, ''))

        # Relative path is invalid for remote code
        with self.assertRaises(ValueError):
            _ = Code(remote_computer_exec=(self.computer, 'subdir/run.exe'))

        # first argument should be a computer, not a string
        with self.assertRaises(TypeError):
            _ = Code(remote_computer_exec=('localhost', '/bin/ls'))

        code = Code(remote_computer_exec=(self.computer, '/bin/ls'))
        with tempfile.NamedTemporaryFile() as f:
            f.write("#/bin/bash\n\necho test run\n")
            f.flush()
            code.add_path(f.name, 'test.sh')

        with self.assertRaises(ValidationError):
            # There are files inside
            code.store()

        # If there are no files, I can store
        code.remove_path('test.sh')
        code.store()

        self.assertEquals(code.get_remote_computer().pk, self.computer.pk)
        self.assertEquals(code.get_remote_exec_path(), '/bin/ls')
        self.assertEquals(code.get_execname(), '/bin/ls')

        self.assertTrue(code.can_run_on(self.computer.dbcomputer))
        self.assertTrue(code.can_run_on(self.computer))
        othercomputer = Computer(name='another_localhost',
                                 hostname='localhost',
                                 transport_type='local',
                                 scheduler_type='pbspro',
                                 workdir='/tmp/aiida').store()
        self.assertFalse(code.can_run_on(othercomputer))
Beispiel #25
0
    def setUp(self):
        """
        """
        from aiida import work
        from aiida.orm.code import Code
        from aiida.orm.nodes.parameter import Dict
        from aiida.orm.nodes.structure import StructureData
        from aiida.orm.nodes.remote import RemoteData
        from ase.spacegroup import crystal
        from aiida_quantumespresso.calculations.pw import PwCalculation
        from aiida_yambo.calculations.gw import YamboCalculation
        from aiida.common.links import LinkType
        from aiida.orm.computer import Computer as AiidaOrmComputer
        from aiida.common.datastructures import calc_states
        from aiida.plugins.utils import DataFactory
        runner = work.Runner(poll_interval=0.,
                             rmq_config=None,
                             enable_persistence=None)
        work.set_runner(runner)
        self.computer = AiidaOrmComputer(name="testcase")
        # conf_attrs hostname, description, enabled_state, transport_type, scheduler_type,  workdir
        # mpirun_command , default_mpiprocs_per_machine,
        self.computer._set_hostname_string("localhost")
        self.computer._set_enabled_state_string('True')
        self.computer._set_transport_type_string("local")
        self.computer._set_scheduler_type_string("direct")
        self.computer._set_workdir_string("/tmp/testcase/{username}/base")
        self.computer.store()
        create_authinfo(computer=self.computer).store()
        self.code_yambo = Code()
        self.code_yambo.label = "yambo"
        os_env = os.environ.copy()
        yambo_path = subprocess.check_output(['which', 'mock_yambo'],
                                             env=os_env).strip()
        self.code_yambo.set_remote_computer_exec((self.computer, yambo_path))
        self.code_yambo.set_input_plugin_name('yambo.yambo')

        self.code_p2y = Code()
        self.code_p2y.label = "p2y"
        p2y_path = subprocess.check_output(['which', 'mock_p2y'],
                                           env=os_env).strip()
        self.code_p2y.set_remote_computer_exec((self.computer, p2y_path))
        self.code_p2y.set_input_plugin_name('yambo.yambo')
        self.code_yambo.store()
        self.code_p2y.store()

        self.calc_pw = PwCalculation()
        self.calc_pw.set_computer(self.computer)
        self.calc_pw.set_resources({
            "num_machines": 1,
            "num_mpiprocs_per_machine": 16,
            'default_mpiprocs_per_machine': 16
        })
        StructureData = DataFactory('structure')
        cell = [[15.8753100000, 0.0000000000, 0.0000000000],
                [0.0000000000, 15.8753100000, 0.0000000000],
                [0.0000000000, 0.0000000000, 2.4696584760]]
        s = StructureData(cell=cell)
        self.calc_pw.use_structure(s)
        print((self.calc_pw.store_all(), " pw calc"))
        pw_remote_folder = RemoteData(computer=self.computer,
                                      remote_path="/tmp/testcase/work/calcPW")
        print((pw_remote_folder.store(), "pw remote data"))
        self.calc_pw._set_state(calc_states.PARSING)
        pw_remote_folder.add_link_from(self.calc_pw,
                                       label='remote_folder',
                                       link_type=LinkType.CREATE)

        outputs = Dict(
            dict={
                "lsda": False,
                "number_of_bands": 80,
                "number_of_electrons": 8.0,
                "number_of_k_points": 147,
                "non_colinear_calculation": False
            })
        outputs.store()
        outputs.add_link_from(self.calc_pw,
                              label='output_parameters',
                              link_type=LinkType.CREATE)

        self.calc = YamboCalculation()
        self.calc.set_computer(self.computer)
        self.calc.use_code(self.code_p2y)
        p2y_settings = {
            u'ADDITIONAL_RETRIEVE_LIST':
            [u'r-*', u'o-*', u'l-*', u'l_*', u'LOG/l-*_CPU_1'],
            u'INITIALISE':
            True
        }
        yambo_settings = {
            u'ADDITIONAL_RETRIEVE_LIST':
            [u'r-*', u'o-*', u'l-*', u'l_*', u'LOG/l-*_CPU_1']
        }
        self.calc.use_settings(Dict(dict=p2y_settings))
        self.calc.set_resources({
            "num_machines": 1,
            "num_mpiprocs_per_machine": 16,
            'default_mpiprocs_per_machine': 16
        })
        self.calc.use_parent_calculation(self.calc_pw)
        print((self.calc.store_all(), " yambo calc"))
        self.calc._set_state(calc_states.PARSING)
        a = 5.388
        cell = crystal('Si', [(0, 0, 0)],
                       spacegroup=227,
                       cellpar=[a, a, a, 90, 90, 90],
                       primitive_cell=True)
        self.struc = StructureData(ase=cell)
        self.struc.store()
        self.parameters = Dict(
            dict={
                "BndsRnXp": [1.0, 48.0],
                "Chimod": "Hartree",
                "DysSolver": "n",
                "FFTGvecs": 25,
                "FFTGvecs_units": "Ry",
                "GbndRnge": [1.0, 48.0],
                "HF_and_locXC": True,
                "LongDrXp": [1.0, 0.0, 0.0],
                "NGsBlkXp": 2,
                "NGsBlkXp_units": "Ry",
                "QPkrange": [[1, 145, 3, 5]],
                "SE_CPU": "1 2 4",
                "SE_ROLEs": "q qp b",
                "X_all_q_CPU": "1 1 4 2",
                "X_all_q_ROLEs": "q k c v",
                "em1d": True,
                "gw0": True,
                "ppa": True,
                "rim_cut": True
            })
        self.yambo_settings = Dict(
            dict={
                "ADDITIONAL_RETRIEVE_LIST": [
                    "r-*", "o-*", "l-*", "l_*", "LOG/l-*_CPU_1",
                    "aiida/ndb.QP", "aiida/ndb.HF_and_locXC"
                ]
            })
        self.p2y_settings = Dict(
            dict={
                "ADDITIONAL_RETRIEVE_LIST": [
                    'r-*', 'o-*', 'l-*', 'l_*', 'LOG/l-*_CPU_1',
                    'aiida/ndb.QP', 'aiida/ndb.HF_and_locXC'
                ],
                'INITIALISE':
                True
            })
        self.yambo_calc_set = Dict(
            dict={
                'resources': {
                    "num_machines": 1,
                    "num_mpiprocs_per_machine": 16
                },
                'max_wallclock_seconds': 60 * 29,
                'max_memory_kb': 1 * 88 * 1000000,
                "queue_name":
                "s3parvc3",  #'custom_scheduler_commands': u"#PBS -A  Pra14_3622" ,
                'environment_variables': {
                    "OMP_NUM_THREADS": "1"
                }
            })
        self.p2y_calc_set = Dict(
            dict={
                'resources': {
                    "num_machines": 1,
                    "num_mpiprocs_per_machine": 2
                },
                'max_wallclock_seconds': 60 * 2,
                'max_memory_kb': 1 * 10 * 1000000,
                "queue_name":
                "s3parvc3",  # 'custom_scheduler_commands': u"#PBS -A  Pra14_3622" ,
                'environment_variables': {
                    "OMP_NUM_THREADS": "2"
                }
            })
        self.remote_folder = RemoteData(computer=self.computer,
                                        remote_path="/tmp/testcase/work/calcX")
        self.remote_folder.store()
        self.remote_folder.add_link_from(self.calc,
                                         label='remote_folder',
                                         link_type=LinkType.CREATE)
        self.calc._set_state(calc_states.FINISHED)
Beispiel #26
0
def siesta_develop():
    sd = {}
    from aiida.orm.code import Code
    sd["code"] = Code.get_from_string('siesta@develop')
    return sd
Beispiel #27
0
 def inner(inputs, code_string):
     from aiida.orm.code import Code
     inputs.code = Code.get_from_string(code_string)
Beispiel #28
0
def get_pw_calculation(wf_params, only_initialization=False, parent_calc=None,
                         parent_remote_folder=None):
    """
    Returns a stored calculation
    """
    # default max number of seconds for a calculation with only_initialization=True
    # (should be largely sufficient)
    default_max_seconds_only_init = 1800
    
    from aiida.orm.code import Code
    
    calculation = wf_params['input']['relaxation_scheme']
    
    if only_initialization:
        wf_params['calculation_set'] = update_nested_dict(
            wf_params.get('calculation_set',{}),
            {'max_wallclock_seconds': default_max_seconds_only_init,
             'resources': {'num_machines': 1}})
    
    if parent_calc is None:
        code = Code.get_from_string(wf_params["codename"])
        calc = code.new_calc()
        calc.use_structure(wf_params["structure"])
        calc.use_pseudos_from_family(wf_params["pseudo_family"])
        if parent_remote_folder is None:
            pw_parameters = get_pwparameterdata_from_wfparams(wf_params, calculation=calculation)
        else:
            # restart from a remote folder (typically, with charge density)
            pw_parameters = get_pwparameterdata_from_wfparams(wf_params, restart_mode='restart',
                                                              calculation=calculation)
            calc._set_parent_remotedata(parent_remote_folder)
    else:
        if calculation in ['bands']:
            calc = parent_calc.create_restart(force_restart=True,use_output_structure=True)
        else:
            calc = parent_calc.create_restart(force_restart=True)
        pw_parameters = get_pwparameterdata_from_wfparams(wf_params, 
                                restart_mode='restart', calculation=calculation)
    
    if 'vdw_table' in wf_params:
        calc.use_vdw_table(wf_params['vdw_table'])
    calc.use_parameters(pw_parameters)
    calc.use_kpoints(wf_params['kpoints'])
    calc = set_the_set(calc,wf_params.get('calculation_set',{}))
    
    # set the settings if present        
    try:
        settings_dict = wf_params['settings']
    except KeyError:
        try:
            settings_dict = parent_calc.inp.settings.get_dict()
            if calc.inp.parameters.get_dict()['CONTROL']['calculation'] == 'bands':
                # for bands calculation we take out the npools specification
                # from the parent settings as the number of kpoints will
                # be different
                cmdline = settings_dict.get('cmdline',[])
                the_cmdline = take_out_npools_from_cmdline(cmdline)
                if the_cmdline:
                    settings_dict['cmdline'] = the_cmdline
        except AttributeError:
            settings_dict = {}

    if calc.inp.parameters.get_dict()['CONTROL']['calculation'] == 'bands':
        settings_dict['also_bands'] = True
    if only_initialization:
        settings_dict['ONLY_INITIALIZATION'] = only_initialization
        _ = settings_dict.pop('also_bands',None)
    if settings_dict:
        settings = ParameterData(dict=settings_dict)
        calc.use_settings(settings)
    
    calc.store_all()
    return calc
Beispiel #29
0
def deposit(what,
            type,
            author_name=None,
            author_email=None,
            url=None,
            title=None,
            username=None,
            password=False,
            user_email=None,
            code_label=default_options['code'],
            computer_name=None,
            replace=None,
            message=None,
            **kwargs):
    """
    Launches a
    :py:class:`aiida.orm.implementation.general.calculation.job.AbstractJobCalculation`
    to deposit data node to \*COD-type database.

    :return: launched :py:class:`aiida.orm.implementation.general.calculation.job.AbstractJobCalculation`
        instance.
    :raises ValueError: if any of the required parameters are not given.
    """
    from aiida.common.setup import get_property

    parameters = {}

    if not what:
        raise ValueError("Node to be deposited is not supplied")
    if not type:
        raise ValueError("Deposition type is not supplied. Should be "
                         "one of the following: 'published', "
                         "'prepublication' or 'personal'")
    if not username:
        username = get_property('tcod.depositor_username')
        if not username:
            raise ValueError("Depositor username is not supplied")
    if not password:
        parameters['password'] = get_property('tcod.depositor_password')
        if not parameters['password']:
            raise ValueError("Depositor password is not supplied")
    if not user_email:
        user_email = get_property('tcod.depositor_email')
        if not user_email:
            raise ValueError("Depositor email is not supplied")

    parameters['deposition-type'] = type
    parameters['username'] = username
    parameters['user_email'] = user_email

    if type == 'published':
        pass
    elif type in ['prepublication', 'personal']:
        if not author_name:
            author_name = get_property('tcod.depositor_author_name')
            if not author_name:
                raise ValueError("Author name is not supplied")
        if not author_email:
            author_email = get_property('tcod.depositor_author_email')
            if not author_email:
                raise ValueError("Author email is not supplied")
        if not title:
            raise ValueError("Publication title is not supplied")
    else:
        raise ValueError("Unknown deposition type '{}' -- should be "
                         "one of the following: 'published', "
                         "'prepublication' or 'personal'".format(type))

    if replace:
        if str(int(replace)) != replace or int(replace) < 10000000 \
            or int(replace) > 99999999:
            raise ValueError("ID of the replaced structure ({}) does not "
                             "seem to be valid TCOD ID: must be in "
                             "range [10000000,99999999]".format(replace))
    elif message:
        raise ValueError("Message is given while the structure is not "
                         "redeposited -- log message is relevant to "
                         "redeposition only")

    kwargs['additional_tags'] = {}
    if title:
        kwargs['additional_tags']['_publ_section_title'] = title
    if author_name:
        kwargs['additional_tags']['_publ_author_name'] = author_name
    if replace:
        kwargs['additional_tags']['_tcod_database_code'] = replace
        kwargs['datablock_names'] = [replace]

    cif = export_cifnode(what, store=True, **kwargs)

    from aiida.orm.code import Code
    from aiida.orm.computer import Computer
    from aiida.orm.data.parameter import ParameterData
    from aiida.common.exceptions import NotExistent

    code = Code.get_from_string(code_label)
    computer = None
    if computer_name:
        computer = Computer.get(computer_name)
    calc = code.new_calc(computer=computer)
    calc.set_resources({'num_machines': 1, 'num_mpiprocs_per_machine': 1})

    if password:
        import getpass
        parameters['password'] = getpass.getpass("Password: ")
    if author_name:
        parameters['author_name'] = author_name
    if author_email:
        parameters['author_email'] = author_email
    if url:
        parameters['url'] = url
    if replace:
        parameters['replace'] = True
    if message:
        parameters['log-message'] = str(message)
    pd = ParameterData(dict=parameters)

    calc.use_cif(cif)
    calc.use_parameters(pd)

    calc.store_all()
    calc.submit()

    return calc