Exemple #1
0
    def get_code(self, code_id):
        """
        Get a Computer object with given identifier, that can either be
        the numeric ID (pk), or the label (if unique).

        .. note:: Since all command line arguments get converted to string types, we
            cannot assess the intended type (an integer pk or a string label) from the
            type of the variable code_id. If the code_id can be converted into an integer
            we will assume the value corresponds to a pk. This means, however, that if there
            would be another code, with a label directly equivalent to the string value of that
            pk, that this code can not be referenced by its label, as the other code, corresponding
            to the integer pk, will get matched first.
        """
        from aiida.common.exceptions import NotExistent, MultipleObjectsError, InputValidationError
        from aiida.orm import Code as AiidaOrmCode

        try:
            pk = int(code_id)
            try:
                return AiidaOrmCode.get(pk=pk)
            except (NotExistent, MultipleObjectsError,
                    InputValidationError) as e:
                print >> sys.stderr, e.message
                sys.exit(1)
        except ValueError:
            try:
                return AiidaOrmCode.get_from_string(code_id)
            except (NotExistent, MultipleObjectsError) as e:
                print >> sys.stderr, e.message
                sys.exit(1)
Exemple #2
0
# For further information on the license, see the LICENSE.txt file        #
# For further information please visit http://www.aiida.net               #
###########################################################################
# Load the database environment.
from aiida import load_dbenv

load_dbenv()

from aiida.orm import Code
from aiida.plugins import CalculationFactory

# 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.
# KPOINTS
kpoints = vaspio.Kpoints.monkhorst_automatic(
    kpts=(10, 10, 10), shift=(0.0, 0.0, 0.0)
)

# split the poscar for AiiDA serialization
poscar_parts = vplugin.disassemble_poscar(poscar)

# === Prepare Calculation
ParameterData = DataFactory('parameter')
StructureData = DataFactory('structure')

submit_test = True  # CAUTION: changing this will affect your database

codename = 'Vasp'  # this may be differ from user-to-user
code = Code.get(codename)  # executable to call, module imports etc

calc = code.new_calc()
calc.label = "VASP plugin development"
calc.description = "Test input plugin"
calc.set_max_wallclock_seconds(5*60)  # 5 min
calc.set_resources({
    "num_machines": 1,
    "num_mpiprocs_per_machine": 1,
    'num_cores_per_machine': 24  # this will differ from machine-to-machine
})
calc.set_withmpi(True)

calc.use_poscar(poscar_parts['poscar'])
calc.use_structure(poscar_parts['structure'])
calc.use_incar(
                argkey, argval = sys.argv.pop(0).split('=', 1)
            else:
                argkey = sys.argv.pop(0)
                argval = True
            if argkey not in options.keys():
                options[argkey] = []
            options[argkey].append(argval)
        else:
            files.append(arg)

    expected_code_type = "codtools.cifcoddeposit"

    try:
        if codename is None:
            raise ValueError
        code = Code.get(codename)
        if code.get_input_plugin_name() != expected_code_type:
            raise ValueError
    except (NotExistent, ValueError):
        valid_code_labels = [c.label for c in Code.query(
            dbattributes__key="input_plugin",
            dbattributes__tval=expected_code_type)]
        if valid_code_labels:
            print >> sys.stderr, "Pass as further parameter a valid code label."
            print >> sys.stderr, "Valid labels with a {} executable are:".format(expected_code_type)
            for l in valid_code_labels:
                print >> sys.stderr, "*", l
        else:
            print >> sys.stderr, "Code not valid, and no valid codes for {}. Configure at least one first using".format(
                expected_code_type)
            print >> sys.stderr, "    verdi code setup"