Exemple #1
0
    def test_computer_delete(self):
        """
        Test if 'verdi computer delete' command works
        """
        from aiida.orm.computer import Computer as AiidaOrmComputer
        from aiida.common.exceptions import NotExistent

        # Setup a computer to delete during the test
        comp = AiidaOrmComputer(name='computer_for_test_delete',
                                hostname='localhost',
                                transport_type='local',
                                scheduler_type='direct',
                                workdir='/tmp/aiida')
        comp.store()

        # See if the command complains about not getting an invalid computer
        options = ['non_existent_computer_name']
        result = self.runner.invoke(computer_delete, options)
        # Exception should be raised
        self.assertIsNotNone(result.exception)

        # Delete a computer name successully.
        options = ['computer_for_test_delete']
        result = self.runner.invoke(computer_delete, options)
        # Exception should be not be raised
        self.assertIsNone(result.exception)
        # Check that the computer really was deleted
        with self.assertRaises(NotExistent):
            AiidaOrmComputer.get('computer_for_test_delete')
Exemple #2
0
    def get_computer(self, name):
        """
        Get a Computer object with given name, or raise NotExistent
        """
        from aiida.orm.computer import Computer as AiidaOrmComputer

        return AiidaOrmComputer.get(name)
Exemple #3
0
    def setUpClass(cls):
        from aiida.orm.user import User
        from aiida.orm.computer import Computer
        from aiida.common.utils import get_configured_user_email
        # I create the user only once:

        # We create the user only once:
        # Otherwise, get_automatic_user() will fail when the
        # user is recreated because it caches the user!
        # In any case, store it in cls.user though
        # Other possibility: flush the user cache on delete
        users = User.search_for_users(email=get_configured_user_email())
        assert (len(users) <= 1)
        if users:
            cls.user = users[0]
        else:
            cls.user = User(get_configured_user_email())
            cls.user.password = '******'
            cls.user.save()

        try:
            cls.computer = Computer.get('test_comp')
        except NotExistent:
            cls.computer = Computer(name='test_comp',
                                    hostname='localhost',
                                    transport_type='local',
                                    scheduler_type='pbspro',
                                    workdir='/tmp/aiida')
            cls.computer.store()
Exemple #4
0
    def test_computer_rename(self):
        """
        Test if 'verdi computer rename' command works
        """
        from aiida.orm.computer import Computer as AiidaOrmComputer
        from aiida.common.exceptions import NotExistent

        # See if the command complains about not getting an invalid computer
        options = ['not_existent_computer_name']
        result = self.runner.invoke(computer_rename, options)
        # Exception should be raised
        self.assertIsNotNone(result.exception)

        # See if the command complains about not getting both names
        options = ['comp_cli_test_computer']
        result = self.runner.invoke(computer_rename, options)
        # Exception should be raised
        self.assertIsNotNone(result.exception)

        # The new name must be different to the old one
        options = ['comp_cli_test_computer', 'comp_cli_test_computer']
        result = self.runner.invoke(computer_rename, options)
        # Exception should be raised
        self.assertIsNotNone(result.exception)

        # Change a computer name successully.
        options = ['comp_cli_test_computer', 'renamed_test_computer']
        result = self.runner.invoke(computer_rename, options)
        # Exception should be not be raised
        self.assertIsNone(result.exception)

        # Check that the name really was changed
        # The old name should not be available
        with self.assertRaises(NotExistent):
            AiidaOrmComputer.get('comp_cli_test_computer')
        # The new name should be avilable
        try:
            AiidaOrmComputer.get('renamed_test_computer')
        except NotExistent:
            assertTrue(False)

        # Now change the name back
        options = ['renamed_test_computer', 'comp_cli_test_computer']
        result = self.runner.invoke(computer_rename, options)
        # Exception should be not be raised
        self.assertIsNone(result.exception)

        # Check that the name really was changed
        # The old name should not be available
        with self.assertRaises(NotExistent):
            AiidaOrmComputer.get('renamed_test_computer')
        # The new name should be avilable
        try:
            AiidaOrmComputer.get('comp_cli_test_computer')
        except NotExistent:
            assertTrue(False)
Exemple #5
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
Exemple #6
0
def get_computers_work_dir(calculations, user):
    """
    Get a list of computers and their remotes working directory.

   `calculations` should be a list of JobCalculation object.
    """

    from aiida.orm.computer import Computer
    from aiida.backends.utils import get_authinfo

    computers = [Computer.get(c.dbcomputer) for c in calculations]

    remotes = {}
    for computer in computers:
        remotes[computer.name] = {
            'transport':
            get_authinfo(computer=computer, aiidauser=user).get_transport(),
            'computer':
            computer,
        }

    return remotes
Exemple #7
0
    def computer_update(self, *args):
        """
        Update an existing computer
        """
        import argparse
        from aiida.common.exceptions import NotExistent

        if not is_dbenv_loaded():
            load_dbenv()

        # from aiida.backends.djsite.db.models import DbNode
        from aiida.orm.computer import Computer

        parser = argparse.ArgumentParser(prog=self.get_full_command_name(),
                                         description='Update a computer')
        # The default states are those that are shown if no option is given
        parser.add_argument('computer_name', help="The name of the computer")
        parsed_args = parser.parse_args(args)
        computer_name = parsed_args.computer_name

        try:
            computer = Computer.get(computer_name)
        except NotExistent:
            print "No computer {} was found".format(computer_name)
            sys.exit(1)

        calculation_on_computer = computer.get_calculations_on_computer()

        if calculation_on_computer:
            # Note: this is an artificial comment.
            # If you comment the following lines, you will be able to overwrite
            # the old computer anyway, at your own risk.
            print "You cannot modify a computer, after you run some calculations on it."
            print "Disable this computer and set up a new one."
            sys.exit(1)

        print "*" * 75
        print "WARNING! Modifying existing computer with name '{}'".format(
            computer_name)
        print "Are you sure you want to continue? The UUID will remain the same!"
        print "Continue only if you know what you are doing."
        print "If you just want to rename a computer, use the 'verdi computer rename'"
        print "command. In most cases, it is better to create a new computer."
        print "Moreover, if you change the transport, you must also reconfigure"
        print "each computer for each user!"
        print "*" * 75
        print "Press [Enter] to continue, or [Ctrl]+C to exit."
        raw_input()

        prompt_for_computer_configuration(computer)

        try:
            computer.store()
        except ValidationError as e:
            print "Unable to store the computer: {}. Exiting...".format(
                e.message)
            sys.exit(1)

        print "Computer '{}' successfully updated.".format(computer_name)
        print "pk: {}, uuid: {}".format(computer.pk, computer.uuid)
        print "(Note: machine_dependent transport parameters cannot be set via "
        print "the command-line interface at the moment)"

        print "OK"
        pass
Exemple #8
0
    def computer_list(self, *args):
        """
        List available computers
        """
        import argparse

        if not is_dbenv_loaded():
            load_dbenv()
        from aiida.orm.computer import Computer as AiiDAOrmComputer
        from aiida.backends.utils import get_automatic_user

        parser = argparse.ArgumentParser(
            prog=self.get_full_command_name(),
            description='List the computers in the database.')
        # The default states are those that are shown if no option is given
        parser.add_argument(
            '-C',
            '--color',
            action='store_true',
            help="Use colors to help visualizing the different categories",
        )
        parser.add_argument(
            '-o',
            '--only-usable',
            action='store_true',
            help="Show only computers that are usable (i.e., "
            "configured for the given user and enabled)",
        )
        parser.add_argument(
            '-p',
            '--parsable',
            action='store_true',
            help="Show only the computer names, one per line, "
            "without any other information or string.",
        )
        parser.add_argument(
            '-a',
            '--all',
            action='store_true',
            help="Show also disabled or unconfigured computers",
        )
        parser.set_defaults(also_disabled=False)
        parsed_args = parser.parse_args(args)
        use_colors = parsed_args.color
        only_usable = parsed_args.only_usable
        parsable = parsed_args.parsable
        all_comps = parsed_args.all

        computer_names = self.get_computer_names()

        if use_colors:
            color_id = 90  # Dark gray
            color_id = None  # Default color
            if color_id is not None:
                start_color = "\x1b[{}m".format(color_id)
                end_color = "\x1b[0m"
            else:
                start_color = ""
                end_color = ""
        else:
            start_color = ""
            end_color = ""

        if not parsable:
            print "{}# List of configured computers:{}".format(
                start_color, end_color)
            print(
                "{}# (use 'verdi computer show COMPUTERNAME' "
                "to see the details){}".format(start_color, end_color))
        if computer_names:
            for name in sorted(computer_names):
                computer = AiiDAOrmComputer.get(name)

                # color_id = 90 # Dark gray
                # color_id = 34 # Blue

                is_configured = computer.is_user_configured(
                    get_automatic_user())
                is_user_enabled = computer.is_user_enabled(
                    get_automatic_user())

                is_usable = False  # True if both enabled and configured

                if not all_comps:
                    if not is_configured or not is_user_enabled or not computer.is_enabled(
                    ):
                        continue

                if computer.is_enabled():
                    if is_configured:
                        configured_str = ""
                        if is_user_enabled:
                            symbol = "*"
                            color_id = None
                            enabled_str = ""
                            is_usable = True
                        else:
                            symbol = "x"
                            color_id = 31  # Red
                            enabled_str = "[DISABLED for this user]"
                    else:
                        symbol = "x"
                        color_id = 90  # Dark gray
                        enabled_str = ""
                        configured_str = " [unconfigured]"
                else:  # GLOBALLY DISABLED
                    symbol = "x"
                    color_id = 31  # Red
                    if is_configured and not is_user_enabled:
                        enabled_str = " [DISABLED globally AND for this user]"
                    else:
                        enabled_str = " [DISABLED globally]"
                    if is_configured:
                        configured_str = ""
                    else:
                        configured_str = " [unconfigured]"

                if use_colors:
                    if color_id is not None:
                        start_color = "\x1b[{}m".format(color_id)
                        bold_sequence = "\x1b[1;{}m".format(color_id)
                        nobold_sequence = "\x1b[0;{}m".format(color_id)
                    else:
                        start_color = "\x1b[0m"
                        bold_sequence = "\x1b[1m"
                        nobold_sequence = "\x1b[0m"
                    end_color = "\x1b[0m"
                else:
                    start_color = ""
                    end_color = ""
                    bold_sequence = ""
                    nobold_sequence = ""

                if parsable:
                    print "{}{}{}".format(start_color, name, end_color)
                else:
                    if (not only_usable) or is_usable:
                        print "{}{} {}{}{} {}{}{}".format(
                            start_color, symbol, bold_sequence, name,
                            nobold_sequence, enabled_str, configured_str,
                            end_color)

        else:
            print "# No computers configured yet. Use 'verdi computer setup'"
Exemple #9
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
def computer_list(only_usable, parsable, all_comps):
    """
    List available computers
    """
    from aiida.orm.computer import Computer as AiiDAOrmComputer
    from aiida.orm.backend import construct_backend

    backend = construct_backend()

    computer_names = get_computer_names()

    if not parsable:
        echo.echo("# List of configured computers:")
        echo.echo("# (use 'verdi computer show COMPUTERNAME' "
                  "to see the details)")
    if computer_names:
        for name in sorted(computer_names):
            computer = AiiDAOrmComputer.get(name)

            is_configured = computer.is_user_configured(
                backend.users.get_automatic_user())
            is_user_enabled = computer.is_user_enabled(
                backend.users.get_automatic_user())

            is_usable = False  # True if both enabled and configured

            if not all_comps:
                if not is_configured or not is_user_enabled or not computer.is_enabled(
                ):
                    continue

            if computer.is_enabled():
                if is_configured:
                    configured_str = ""
                    if is_user_enabled:
                        symbol = "*"
                        color = 'green'
                        enabled_str = ""
                        is_usable = True
                    else:
                        symbol = "x"
                        color = 'red'
                        enabled_str = "[DISABLED for this user]"
                else:
                    symbol = "x"
                    color = 'reset'
                    enabled_str = ""
                    configured_str = " [unconfigured]"
            else:  # GLOBALLY DISABLED
                symbol = "x"
                color = 'red'
                if is_configured and not is_user_enabled:
                    enabled_str = " [DISABLED globally AND for this user]"
                else:
                    enabled_str = " [DISABLED globally]"
                if is_configured:
                    configured_str = ""
                else:
                    configured_str = " [unconfigured]"

            if parsable:
                echo.echo(click.style("{}".format(name), fg=color))
            else:
                if (not only_usable) or is_usable:
                    echo.echo(click.style("{} ".format(symbol), fg=color),
                              nl=False)
                    echo.echo(click.style("{} ".format(name),
                                          bold=True,
                                          fg=color),
                              nl=False)
                    echo.echo(
                        click.style("{}{}".format(enabled_str, configured_str),
                                    fg=color))

    else:
        echo.echo("# No computers configured yet. Use 'verdi computer setup'")