1"""Function-like object creating monoclinic lattices.
2
3The following lattice creator is defined:
4    SimpleMonoclinic
5    BaseCenteredMonoclinic
6"""
7
8from ase.lattice.triclinic import TriclinicFactory
9import numpy as np
10
11
12class SimpleMonoclinicFactory(TriclinicFactory):
13    "A factory for creating simple monoclinic lattices."
14    # The name of the crystal structure in ChemicalElements
15    xtal_name = "monoclinic"
16
17    def make_crystal_basis(self):
18        "Make the basis matrix for the crystal unit cell and the system unit cell."
19        # First convert the basis specification to a triclinic one
20        if isinstance(self.latticeconstant, type({})):
21            self.latticeconstant['beta'] = 90
22            self.latticeconstant['gamma'] = 90
23        else:
24            if len(self.latticeconstant) == 4:
25                self.latticeconstant = self.latticeconstant + (90, 90)
26            else:
27                raise ValueError("Improper lattice constants for monoclinic crystal.")
28
29        TriclinicFactory.make_crystal_basis(self)
30
31
32SimpleMonoclinic = SimpleMonoclinicFactory()
33
34
35class BaseCenteredMonoclinicFactory(SimpleMonoclinicFactory):
36    # The natural basis vectors of the crystal structure
37    int_basis = np.array([[1, -1, 0],
38                          [1, 1, 0],
39                          [0, 0, 2]])
40    basis_factor = 0.5
41
42    # Converts the natural basis back to the crystallographic basis
43    inverse_basis = np.array([[1, 1, 0],
44                              [-1, 1, 0],
45                              [0, 0, 1]])
46    inverse_basis_factor = 1.0
47
48
49BaseCenteredMonoclinic = BaseCenteredMonoclinicFactory()
50