/
crystal_structures.py
115 lines (89 loc) · 3.17 KB
/
crystal_structures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
pyscal module for creating crystal structures.
"""
import numpy as np
import warnings
import os
from functools import partial
from functools import update_wrapper
from pyscal.attributes import read_yaml
from pyscal.core import System
structures = read_yaml(os.path.join(os.path.dirname(__file__), "data/structure_data.yaml"))
elements = read_yaml(os.path.join(os.path.dirname(__file__), "data/element_data.yaml"))
#wrapper methods
def structure_creator(structure,
lattice_constant = 1.00,
repetitions = None,
ca_ratio = 1.633,
noise = 0,
element=None,
chemical_symbol=None):
"""
Create a crystal structure and return it as a System object.
Parameters
----------
structure : {'sc', 'bcc', 'fcc', 'hcp', 'diamond', 'a15' or 'l12'}
type of the crystal structure
lattice_constant : float, optional
lattice constant of the crystal structure, default 1
repetitions : list of ints of len 3, optional
of type `[nx, ny, nz]`, repetions of the unit cell in x, y and z directions.
default `[1, 1, 1]`.
ca_ratio : float, optional
ratio of c/a for hcp structures, default 1.633
noise : float, optional
If provided add normally distributed noise with standard deviation `noise` to the atomic positions.
element : string, optional
The chemical element
chemical_symbol : string, optional
The chemical symbol
Returns
-------
System: pyscal System
system will be populated with given atoms and simulation box
Examples
--------
>>> sys = structure_creator('bcc', lattice_constant=3.48, repetitions=[2,2,2])
"""
return System.from_structure(structure, lattice_constant=lattice_constant,
repetitions=repetitions, ca_ratio=ca_ratio,
noise=noise, element=element)
class Structure:
"""
A class for structure creation
Attributes
----------
element:
create elementary structures
lattice:
create structures by specifying lattice
"""
def __init__(self):
self.element = ElementCreator(elements)
self.lattice = LatticeCreator(structures)
class ElementCreator:
"""
Create an elementary structure
"""
def __init__(self, element_dict):
self._element_dict = element_dict
def __dir__(self):
return list(self._element_dict.keys())
def __getattr__(self, key):
#this is the element based creater
if key in self._element_dict.keys():
structure = self._element_dict[key]['structure']
pfunc = partial(structure_creator, structure,
lattice_constant=self._element_dict[key]['lattice_constant'],
element = key)
update_wrapper(pfunc, structure_creator)
return pfunc
class LatticeCreator(ElementCreator):
"""
Create a lattice
"""
def __getattr__(self, key):
if key in self._element_dict.keys():
pfunc = partial(structure_creator, key)
update_wrapper(pfunc, structure_creator)
return pfunc