Skip to content

Commit

Permalink
Merge pull request #88 from pyiron/refactor_bindings
Browse files Browse the repository at this point in the history
Refactor bindings
  • Loading branch information
liamhuber authored Mar 4, 2021
2 parents 611aa29 + 829b2c3 commit 7bcae1b
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 328 deletions.
493 changes: 315 additions & 178 deletions notebooks/structures.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyiron_atomistics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# To maintain backwards compatibility until we deprecate the old structure creation functions:
from pyiron_atomistics.atomistics.structure.factory import StructureFactory as _StructureFactory
create_surface = _StructureFactory.surface
create_ase_bulk = _StructureFactory.ase_bulk
create_ase_bulk = _StructureFactory().ase.bulk
create_structure = _StructureFactory.crystal

# Make classes available for new pyiron version
Expand Down
Empty file.
85 changes: 85 additions & 0 deletions pyiron_atomistics/atomistics/structure/factories/aimsgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.

from aimsgb import GrainBoundary, Grain, GBInformation
from pyiron_base import Settings
from pyiron_atomistics.atomistics.structure.atoms import pyiron_to_pymatgen, pymatgen_to_pyiron

__author__ = "Ujjal Saikia"
__copyright__ = (
"Copyright 2021, Max-Planck-Institut für Eisenforschung GmbH - "
"Computational Materials Design (CM) Department"
)
__version__ = "1.0"
__maintainer__ = "Liam Huber"
__email__ = "huber@mpie.de"
__status__ = "production"
__date__ = "Feb 26, 2021"

s = Settings()


class AimsgbFactory:
@staticmethod
def info(axis, max_sigma):
"""
Provides a list of possible GB structures for a given rotational axis and upto the given maximum sigma value.
Args:
axis : Rotational axis for the GB you want to construct (for example, axis=[1,0,0])
max_sigma (int) : The maximum value of sigma upto which you want to consider for your
GB (for example, sigma=5)
Returns:
A list of possible GB structures in the format:
{sigma value: {'theta': [theta value],
'plane': the GB planes")
'rot_matrix': array([the rotational matrix]),
'csl': [array([the csl matrix])]}}
To construct the grain boundary select a GB plane and sigma value from the list and pass it to the
GBBuilder.gb_build() function along with the rotational axis and initial bulk structure.
"""
return GBInformation(axis=axis, max_sigma=max_sigma)

@staticmethod
def build(
axis,
sigma,
plane,
initial_struct,
to_primitive=False,
delete_layer='0b0t0b0t',
add_if_dist=0.0
):
"""
Generate a grain boundary structure based on the aimsgb.GrainBoundary module.
Args:
axis : Rotational axis for the GB you want to construct (for example, axis=[1,0,0])
sigma (int) : The sigma value of the GB you want to construct (for example, sigma=5)
plane: The grain boundary plane of the GB you want to construct (for example, plane=[2,1,0])
initial_struct : Initial bulk structure from which you want to construct the GB (a pyiron
structure object).
delete_layer : To delete layers of the GB. For example, delete_layer='1b0t1b0t'. The first
4 characters is for first grain and the other 4 is for second grain. b means
bottom layer and t means top layer. Integer represents the number of layers
to be deleted. The first t and second b from the left hand side represents
the layers at the GB interface. Default value is delete_layer='0b0t0b0t', which
means no deletion of layers.
add_if_dist : If you want to add extra interface distance, you can specify add_if_dist.
Default value is add_if_dist=0.0
to_primitive : To generate primitive or non-primitive GB structure. Default value is
to_primitive=False
Returns:
:class:`.Atoms`: final grain boundary structure
"""
basis_pymatgen = pyiron_to_pymatgen(initial_struct)
grain_init = Grain(basis_pymatgen.lattice, basis_pymatgen.species, basis_pymatgen.frac_coords)
gb_obj = GrainBoundary(axis=axis, sigma=sigma, plane=plane, initial_struct=grain_init)

return pymatgen_to_pyiron(gb_obj.build_gb(to_primitive=to_primitive, delete_layer=delete_layer,
add_if_dist=add_if_dist))
69 changes: 69 additions & 0 deletions pyiron_atomistics/atomistics/structure/factories/ase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.

from functools import wraps
from inspect import getmodule
from ase.build import cut as ase_cut, stack as ase_stack, bulk as ase_bulk
from ase.io import read as ase_read
from ase.spacegroup import crystal as ase_crystal
from pyiron_atomistics.atomistics.structure.atoms import ase_to_pyiron
from pyiron_atomistics.atomistics.structure.pyironase import publication as publication_ase
from pyiron_base import Settings

__author__ = "Ali Zendegani"
__copyright__ = (
"Copyright 2021, Max-Planck-Institut für Eisenforschung GmbH - "
"Computational Materials Design (CM) Department"
)
__version__ = "1.0.1"
__maintainer__ = "Liam Huber"
__email__ = "huber@mpie.de"
__status__ = "production"
__date__ = "Feb 26, 2021"

s = Settings()


def _ase_header(ase_func):
chain = getmodule(ase_func).__name__
name = chain.split('.')[-1]
return f"""
Returns an ASE's {name} result as a `pyiron_atomistics.atomstic.structure.atoms.Atoms`.
{chain} docstring:
"""


def _ase_wraps(ase_func):
def decorator(func):
@wraps(ase_func)
def wrapper(*args, **kwargs):
s.publication_add(publication_ase())
return func(*args, **kwargs)
wrapper.__doc__ = _ase_header(ase_func) + wrapper.__doc__
return wrapper
return decorator


class AseFactory:
@_ase_wraps(ase_bulk)
def bulk(self, *args, **kwargs):
return ase_to_pyiron(ase_bulk(*args, **kwargs))

@_ase_wraps(ase_cut)
def cut(self, *args, **kwargs):
return ase_cut(*args, **kwargs)

@_ase_wraps(ase_stack)
def stack(self, *args, **kwargs):
return ase_stack(*args, **kwargs)

@_ase_wraps(ase_crystal)
def crystal(self, *args, **kwargs):
return ase_to_pyiron(ase_crystal(*args, **kwargs))

@_ase_wraps(ase_read)
def read(self, *args, **kwargs):
return ase_to_pyiron(ase_read(*args, **kwargs))
Loading

0 comments on commit 7bcae1b

Please sign in to comment.