Skip to content

Commit

Permalink
Merge 5edc365 into f4f8051
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrv committed Jun 1, 2020
2 parents f4f8051 + 5edc365 commit 4f5a56c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 37 deletions.
36 changes: 36 additions & 0 deletions pyiron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,42 @@
# jedi fix
fix_ipython_autocomplete()

# populate namespace with default job classes, this also populates the job
# class dict in pyiron.base.job.jobtype
from pyiron.atomistics.structure.atoms import Atoms
from pyiron.testing.randomatomistic import AtomisticExampleJob
from pyiron.dft.master.convergence_encut_parallel import ConvEncutParallel
from pyiron.dft.master.convergence_encut_serial import ConvEncutSerial
from pyiron.atomistics.master.convergence_volume import ConvergenceVolume
from pyiron.dft.master.convergence_kpoint_parallel import ConvKpointParallel
from pyiron.testing.randomatomistic import ExampleJob
from pyiron.base.master.flexible import FlexibleMaster
from pyiron.gaussian.gaussian import Gaussian
from pyiron.gpaw.gpaw import GpawJob
from pyiron.thermodynamics.hessian import HessianJob
from pyiron.lammps.lammps import Lammps
from pyiron.atomistics.master.parallel import MapMaster
from pyiron.atomistics.master.murnaghan import Murnaghan
from pyiron.dft.master.murnaghan_dft import MurnaghanDFT
from pyiron.atomistics.master.phonopy import PhonopyJob
from pyiron.quickff.quickff import QuickFF
from pyiron.interactive.scipy_minimizer import ScipyMinimizer
from pyiron.base.job.script import ScriptJob
from pyiron.atomistics.master.serial import SerialMaster
from pyiron.base.master.serial import SerialMasterBase
from pyiron.sphinx.sphinx import Sphinx
from pyiron.atomistics.job.structurecontainer import StructureContainer
from pyiron.atomistics.master.structure import StructureListMaster
from pyiron.thermodynamics.sxphonons import SxDynMat
from pyiron.interactive.sxextoptint import SxExtOptInteractive
from pyiron.thermodynamics.sxphonons import SxHarmPotTst
from pyiron.thermodynamics.sxphonons import SxPhonons
from pyiron.thermodynamics.sxphonons import SxUniqDispl
from pyiron.table.datamining import TableJob
from pyiron.vasp.vasp import Vasp
from pyiron.vasp.metadyn import VaspMetadyn
from pyiron.vasp.vaspsol import VaspSol
from pyiron.yaff.yaff import Yaff

def install():
install_dialog()
44 changes: 43 additions & 1 deletion pyiron/base/job/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import copy
import os
import posixpath
import sys
from six import with_metaclass
import time
import math
import stat
from pyiron.base.settings.generic import Settings
from pyiron.base.generic.template import PyironObject
from pyiron.base.job.jobtype import JOB_CLASS_DICT
from tables import NoSuchNodeError
import tarfile
import shutil
Expand All @@ -33,7 +36,41 @@
s = Settings()


class JobCore(PyironObject):
# `RegisterJobTypeMeta` and `JobCore.__init_subclass__` (depending on python
# version) contain some magic that runs at *class creation* and registers
# subtypes of JobCore in the JOB_CLASS_DICT of `pyiron.base.job.jobtype` as
# they are created without the need to manually maintain it or search all
# modules for subclasses as we previously did.
# `__init_subclass__` is easier to understand, it is a
# `@classmethod` python calls after creating a subclass of the class it is
# defined on. Its `cls` argument is then the newly created class.
# https://docs.python.org/3.8/reference/datamodel.html#object.__init_subclass__
# In case of python3.5 and earlier this mechanism didn't exist, so we have to
# create a metaclass with the same purpose. Normally classes are created by
# python via the `type()` function/metaclass. The `__init__` method on a
# metaclass initializes the class object, the same way it initializes the
# instance object when defined on a normal class. Deriving our metaclass from
# type means we just have to add our logic and then fallback on `super()`.
# https://docs.python.org/3.5/library/functions.html#type

PRE_PY36 = sys.version_info.major < 3 or \
(sys.version_info.major >= 3 and sys.version_info.minor < 6)

if PRE_PY36:
class RegisterJobTypeMeta(type):
def __init__(self, *args, **kwargs):
if args[0] != 'JobCore':
JOB_CLASS_DICT[args[0]] = args[2]['__module__']
# delegate proper class initialization to type()
super().__init__(*args, **kwargs)
else:
# for >= python3.6 using the __init_subclass__ hook is much more
# convenient, so there's no need to provide a special meta class, but since
# the class statement needs to work for all versions, default to type()
# which is the default metaclass of all types anyway
RegisterJobTypeMeta = type

class JobCore(PyironObject, with_metaclass(RegisterJobTypeMeta)):
"""
The JobCore the most fundamental pyiron job class. From this class the GenericJob as well as the reduced JobPath
class are derived. While JobPath only provides access to the HDF5 file it is about one order faster.
Expand Down Expand Up @@ -91,6 +128,11 @@ class are derived. While JobPath only provides access to the HDF5 file it is abo
path to the job as a combination of absolute file system path and path within the HDF5 file.
"""

if not PRE_PY36:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
JOB_CLASS_DICT[cls.__name__] = cls.__module__

def __init__(self, project, job_name):
self._is_valid_job_name(job_name)
self._name = job_name
Expand Down
37 changes: 1 addition & 36 deletions pyiron/base/job/jobtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,7 @@
__date__ = "Sep 1, 2017"


JOB_CLASS_DICT = {
"Atoms": "pyiron.atomistics.structure.atoms",
"AtomisticExampleJob": "pyiron.testing.randomatomistic",
"ConvEncutParallel": "pyiron.dft.master.convergence_encut_parallel",
"ConvEncutSerial": "pyiron.dft.master.convergence_encut_serial",
"ConvergenceVolume": "pyiron.atomistics.master.convergence_volume",
"ConvKpointParallel": "pyiron.dft.master.convergence_kpoint_parallel",
"ExampleJob": "pyiron.testing.randomatomistic",
"FlexibleMaster": "pyiron.base.master.flexible",
"Gaussian": "pyiron.gaussian.gaussian",
"GpawJob": "pyiron.gpaw.gpaw",
"HessianJob": "pyiron.thermodynamics.hessian",
"Lammps": "pyiron.lammps.lammps",
"MapMaster": "pyiron.atomistics.master.parallel",
"Murnaghan": "pyiron.atomistics.master.murnaghan",
"MurnaghanDFT": "pyiron.dft.master.murnaghan_dft",
"PhonopyJob": "pyiron.atomistics.master.phonopy",
"QuickFF": "pyiron.quickff.quickff",
"ScipyMinimizer": "pyiron.interactive.scipy_minimizer",
"ScriptJob": "pyiron.base.job.script",
"SerialMaster": "pyiron.atomistics.master.serial",
"SerialMasterBase": "pyiron.base.master.serial",
"Sphinx": "pyiron.sphinx.sphinx",
"StructureContainer": "pyiron.atomistics.job.structurecontainer",
"StructureListMaster": "pyiron.atomistics.master.structure",
"SxDynMat": "pyiron.thermodynamics.sxphonons",
"SxExtOptInteractive": "pyiron.interactive.sxextoptint",
"SxHarmPotTst": "pyiron.thermodynamics.sxphonons",
"SxPhonons": "pyiron.thermodynamics.sxphonons",
"SxUniqDispl": "pyiron.thermodynamics.sxphonons",
"TableJob": "pyiron.table.datamining",
"Vasp": "pyiron.vasp.vasp",
"VaspMetadyn": "pyiron.vasp.metadyn",
"VaspSol": "pyiron.vasp.vaspsol",
"Yaff": "pyiron.yaff.yaff",
}
JOB_CLASS_DICT = {}


class Singleton(type):
Expand Down

0 comments on commit 4f5a56c

Please sign in to comment.