def setUp(self):
     self.resource_path = Path(
         '.').expanduser().resolve().absolute().as_posix()
     self.test_config = Settings(
         config={
             'file': 'genericsettings.db',
             'top_level_dirs': self.resource_path,
             'resource_paths': self.resource_path
         })
 def setUp(self):
     if sys.version_info.major < 3 and os.name == 'nt':
         # In Python 2.7 on Windows for pathlib2 it is required that the directories exist, so we create them
         if not os.path.exists(os.path.expanduser('~/pyiron/resources')):
             os.makedirs(os.path.expanduser('~/pyiron/resources'))
         if not os.path.exists(os.path.expanduser('~/pyiron/projects')):
             os.makedirs(os.path.expanduser('~/pyiron/projects'))
     self.user_path = Path('~').expanduser().resolve().absolute().as_posix()
     self.resource_path = Path(
         '~/pyiron/resources').expanduser().resolve().absolute().as_posix()
     self.project_path = Path('~/pyiron/projects').expanduser().resolve(
     ).absolute().as_posix() + '/'
     self.file_config = Settings()
Ejemplo n.º 3
0
    def _get_project_from_path(full_path):
        """
        Split the absolute path in root_path and project_path using the top_path function in Settings()

        Args:
            full_path (str): absolute path

        Returns:
            str, str: root_path, project_path
        """
        root = Settings().top_path(full_path)
        pr_path = posixpath.relpath(full_path, root)
        return root, pr_path
Ejemplo n.º 4
0
def set_logging_level(level, channel=None):
    """
    Set level for logger

    Args:
        level (str): 'DEBUG, INFO, WARN'
        channel (int): 0: file_log, 1: stream, None: both
    """
    from pyiron_base.core.settings.generic import Settings
    s = Settings()
    if channel:
        s.logger.handlers[channel].setLevel(level)
    else:
        s.logger.handlers[0].setLevel(level)
        s.logger.handlers[1].setLevel(level)
Ejemplo n.º 5
0
def database():
    """
    Convenience function to update an existing (older) version of the database to the latest version, by modifying the
    database columns. This is only possible if no other pyiron session is accessing the database. Therefore the script
    might take some time to be executed successfully.
    """
    s = Settings()
    s.open_connection()
    for db_name in s.db_dict:
        db = s.db_dict[db_name]
        try:
            if "projectPath".lower() not in db.get_table_headings(db.table_name):
                print("add missing column: " + "projectPath")
                db.add_column(col_name="projectPath", col_type="varchar(255)")
            if "subJob".lower() not in db.get_table_headings(db.table_name):
                print("add missing column: " + "subJob")
                db.add_column(col_name="subJob", col_type="varchar(255)")
            else:
                print("change data type of subJob")
                db.change_column_type(col_name="subJob", col_type="varchar(255)")
            if "masterID".lower() not in db.get_table_headings(db.table_name):
                print("add missing column: " + "masterid")
                db.add_column(col_name="masterid", col_type="bigint")

            if "hamversion" in db.get_table_headings(db.table_name):
                print("change data type hamversion")
                db.change_column_type(col_name="hamversion", col_type="varchar(50)")

            if "job" in db.get_table_headings(db.table_name):
                print("change data type job")
                db.change_column_type(col_name="job", col_type="varchar(50)")
            print(db.table_name, " - database successful updated")
        except ValueError:
            print(db.table_name, " - database failed")

    print("database update done")
class TestConfigSettingsStatic(unittest.TestCase):
    def setUp(self):
        if sys.version_info.major < 3 and os.name == 'nt':
            # In Python 2.7 on Windows for pathlib2 it is required that the directories exist, so we create them
            if not os.path.exists(os.path.expanduser('~/pyiron/resources')):
                os.makedirs(os.path.expanduser('~/pyiron/resources'))
            if not os.path.exists(os.path.expanduser('~/pyiron/projects')):
                os.makedirs(os.path.expanduser('~/pyiron/projects'))
        self.user_path = Path('~').expanduser().resolve().absolute().as_posix()
        self.resource_path = Path(
            '~/pyiron/resources').expanduser().resolve().absolute().as_posix()
        self.project_path = Path('~/pyiron/projects').expanduser().resolve(
        ).absolute().as_posix() + '/'
        self.file_config = Settings()

    def test_file_db_connection_name(self):
        self.assertEqual(self.file_config.db_connection_name, 'DEFAULT')

    def test_file_db_connection_string(self):
        self.assertEqual(self.file_config.db_connection_string,
                         'sqlite:///' + self.resource_path + '/sqlite.db')

    def test_file_db_connection_table(self):
        self.assertEqual(self.file_config.db_connection_table, 'jobs_pyiron')

    def test_file_db_translate_dict(self):
        self.assertEqual(self.file_config.db_translate_dict,
                         {'DEFAULT': {
                             self.project_path: self.project_path
                         }})

    def test_file_db_name(self):
        self.assertEqual(self.file_config.db_name, 'DEFAULT')

    def test_file_top_path(self):
        self.assertEqual(
            self.file_config.top_path(self.project_path + '/test'),
            self.project_path)

    def test_file_resource_paths(self):
        self.assertEqual(self.file_config.resource_paths, [self.resource_path])

    def test_file_login_user(self):
        self.assertEqual(self.file_config.login_user, 'pyiron')
class TestConfigSettingsStatic(unittest.TestCase):
    def setUp(self):
        self.resource_path = Path(
            '.').expanduser().resolve().absolute().as_posix()
        self.test_config = Settings(
            config={
                'file': 'genericsettings.db',
                'top_level_dirs': self.resource_path,
                'resource_paths': self.resource_path
            })

    def test_db_connection_name(self):
        self.assertEqual(self.test_config.db_connection_name, 'test')

    def test_db_connection_string(self):
        self.assertEqual(self.test_config.db_connection_string,
                         'sqlite:///genericsettings.db')

    def test_db_connection_table(self):
        self.assertEqual(self.test_config.db_connection_table, 'jobs_pyiron')

    def test_db_translate_dict(self):
        self.assertEqual(
            self.test_config.db_translate_dict,
            {'test': {
                self.resource_path + '/': self.resource_path + '/'
            }})

    def test_db_name(self):
        self.assertEqual(self.test_config.db_name, 'test')

    def test_top_path(self):
        self.assertEqual(
            self.test_config.top_path(self.resource_path + '/test'),
            self.resource_path + '/')

    def test_resource_paths(self):
        self.assertEqual(self.test_config.resource_paths, [self.resource_path])

    def test_login_user(self):
        self.assertEqual(self.test_config.login_user, 'pyiron')
Ejemplo n.º 8
0
    def __new__(cls, class_name, project, job_name, job_class_dict):
        """
        The __new__() method allows to create objects from other classes - the class selected by class_name

        Args:
            class_name (str): The specific class name of the class this object belongs to.
            project (Project): Project object (defines path where job will be created and stored)
            job_name (str): name of the job (must be unique within this project path)
            job_class_dict (dict): dictionary with the jobtypes to choose from.

        Returns:
            GenericJob: object of type class_name
        """
        cls.job_class_dict = job_class_dict
        job_type_lst = class_name.split(".")
        if len(job_type_lst) > 1:
            class_name = class_name.split()[-1][1:-2]
            job_type = class_name.split(".")[-1]
        else:
            job_type = job_type_lst[-1]
        for job_class_name in list(cls.job_class_dict.keys()
                                   ):  # for job_class in cls.JOB_CLASSES:
            if job_type == job_class_name:
                job_module = importlib.import_module(
                    cls.job_class_dict[job_class_name])
                job_class = getattr(job_module, job_class_name)
                job = job_class(project, job_name)
                if job.status.aborted:
                    job.logger.warn(
                        'Job aborted - please remove it and run again! {}'.
                        format(job.job_name))
                if not job.status.initialized:
                    Settings().logger.info("job_exists -> load from hdf")
                    job.from_hdf()
                return job
        raise ValueError(
            "Unknown job type: ", class_name,
            [job.__name__ for job in list(cls.job_class_dict.keys())])
Ejemplo n.º 9
0
import os
from pyiron_base.core.settings.generic import Settings

s = Settings(
    config={
        'file': 'genericparameters.db',
        'top_level_dirs': os.path.abspath(os.getcwd()),
        'resource_paths': os.path.abspath(os.getcwd())
    })

from copy import deepcopy
import pandas
from pyiron_base.objects.generic.parameters import GenericParameters
import unittest


class TestGenericParameters(unittest.TestCase):
    def setUp(self):
        self.generic_parameters_empty = GenericParameters()
        self.generic_parameters_str = GenericParameters()
        my_str = '''\
                par_1 1
                par_2 ab
                count 0
                write_restart True
                read_restart False'''
        self.generic_parameters_str.load_string(my_str)

    def test_load_string(self):
        self.assertEqual(self.generic_parameters_str.get("par_1"), 1)
        self.assertEqual(self.generic_parameters_str.get("par_2"), 'ab')
Ejemplo n.º 10
0
from pyiron_base.objects.job.core import JobCore
from pyiron_base.objects.server.generic import Server
import subprocess
"""
Generic Job class extends the JobCore class with all the functionality to run the job object.
"""

__author__ = "Joerg Neugebauer, Jan Janssen"
__copyright__ = "Copyright 2017, Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department"
__version__ = "1.0"
__maintainer__ = "Jan Janssen"
__email__ = "*****@*****.**"
__status__ = "production"
__date__ = "Sep 1, 2017"

s = Settings()

intercepted_signals = [signal.SIGINT, signal.SIGTERM,
                       signal.SIGABRT]  #, signal.SIGQUIT]


class GenericJob(JobCore):
    """
    Generic Job class extends the JobCore class with all the functionality to run the job object. From this class
    all specific Hamiltonians are derived. Therefore it should contain the properties/routines common to all jobs.
    The functions in this module should be as generic as possible.
     
    Args:
        project (ProjectHDFio): ProjectHDFio instance which points to the HDF5 file the job is stored in
        job_name (str): name of the job, which has to be unique within the project
Ejemplo n.º 11
0
import os
from pyiron_base.core.settings.generic import Settings
import unittest

s = Settings(
    config={
        'file': 'copyto.db',
        'top_level_dirs': os.path.abspath(os.getcwd()),
        'resource_paths': os.path.abspath(os.getcwd())
    })

from pyiron_base.project import Project


class TestChildids(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.project = Project('testing_copyto')

    @classmethod
    def tearDownClass(cls):
        project = Project('testing_copyto')
        sub_project = project.open('sub_project_ex')
        sub_project.remove()
        sub_project = project.open('sub_project')
        sub_project.remove()
        s.close_connection()
        os.remove('copyto.db')

    # def test_copy_to_job(self):
    #     job_ser = self.project.create_job("SerialMaster", "sequence_single")
import unittest
import os
from pyiron_base.core.settings.generic import Settings
s = Settings(
    config={
        'sql_file': 'container.db',
        'project_paths': os.path.abspath(os.getcwd()),
        'resource_paths': os.path.join(os.path.abspath(os.getcwd()),
                                       '../static')
    })

from pyiron.project import Project


class TestStructureContainer(unittest.TestCase):
    def setUp(self):
        self.lattice_constant = 3.5
        self.project = Project('structure_testing')
        self.basis = self.project.create_structure(
            element="Fe",
            bravais_basis='fcc',
            lattice_constant=self.lattice_constant)
        self.structure_container = self.project.create_job(
            "StructureContainer", "structure_container")
        self.structure_container.structure = self.basis

    @classmethod
    def tearDownClass(cls):
        project = Project('structure_testing')
        ham = project.load(1)
        ham.remove()
import os
import unittest
from pyiron_base.core.settings.generic import Settings, convert_path

s = Settings(
    config={
        'sql_file': 'murnaghan.db',
        'project_paths': convert_path(os.getcwd()),
        'resource_paths': os.path.join(convert_path(os.getcwd()), '../static')
    })

from pyiron.project import Project


def convergence_goal(self, **qwargs):
    import numpy as np
    eps = 0.2
    if "eps" in qwargs:
        eps = qwargs["eps"]
    erg_lst = self.get_from_childs("output/generic/energy")
    var = 1000 * np.var(erg_lst)
    print(var / len(erg_lst))
    if var / len(erg_lst) < eps:
        return True
    ham_prev = self[-1]
    job_name = self.first_child_name() + "_" + str(len(self))
    ham_next = ham_prev.restart(job_name=job_name)
    return ham_next


class TestMurnaghan(unittest.TestCase):