Skip to content

Asymmetric Unit

AsymmetricUnit

Storage class for the coordinates and labels in a crystal asymmetric unit

Attributes:

Name Type Description
elements List[Element]

N length list of elements associated with the sites in this asymmetric unit

positions array_like

(N, 3) array of site positions in fractional coordinates

labels array_like

N length array of string labels for each site

formula property readonly

Molecular formula for this asymmetric unit

__init__(self, elements, positions, labels=None, **kwargs) special

Create an asymmetric unit object from a list of Elements and an array of fractional coordinates.

Parameters:

Name Type Description Default
elements List[Element]

N length list of elements associated with the sites

required
positions array_like

(N, 3) array of site positions in fractional coordinates

required
labels array_like

labels (array_like): N length array of string labels for each site

None
**kwargs

Additional properties (will populate the properties member) to store in this asymmetric unit

{}
Source code in chmpy/crystal/asymmetric_unit.py
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
def __init__(self, elements, positions, labels=None, **kwargs):
    """
    Create an asymmetric unit object from a list of Elements and 
    an array of fractional coordinates.


    Arguments:
        elements (List[Element]): N length list of elements associated with the sites
        positions (array_like): (N, 3) array of site positions in fractional coordinates
        labels (array_like, optional): labels (array_like): N length array of string labels for each site
        **kwargs: Additional properties (will populate the properties member)
            to store in this asymmetric unit

    """
    self.elements = elements
    self.atomic_numbers = np.asarray([x.atomic_number for x in elements])
    self.positions = np.asarray(positions)
    self.properties = {}
    self.properties.update(kwargs)
    if labels is None:
        self.labels = []
        label_index = defaultdict(int)
        for el in self.elements:
            label_index[el] += 1
            self.labels.append("{}{}".format(el, label_index[el]))
    else:
        self.labels = labels
    self.labels = np.array(self.labels)

from_records(records) classmethod

Initialize an AsymmetricUnit from a list of dictionary like objects

Parameters:

Name Type Description Default
records iterable

An iterable containing dict_like objects with label, element, position and optionally occupation stored.

required
Source code in chmpy/crystal/asymmetric_unit.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@classmethod
def from_records(cls, records):
    """Initialize an AsymmetricUnit from a list of dictionary like objects

    Arguments:
        records (iterable): An iterable containing dict_like objects with `label`,
            `element`, `position` and optionally `occupation` stored.
    """
    labels = []
    elements = []
    positions = []
    occupation = []
    for r in records:
        labels.append(r["label"])
        elements.append(Element[r["element"]])
        positions.append(r["position"])
        occupation.append(r.get("occupation", 1.0))
    positions = np.asarray(positions)
    return AsymmetricUnit(elements, positions, labels=labels, occupation=occupation)