Coverage for ase/lattice/monoclinic.py: 63.16%

19 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-27 15:21 +0000

1"""Function-like object creating monoclinic lattices. 

2 

3The following lattice creator is defined: 

4 SimpleMonoclinic 

5 BaseCenteredMonoclinic 

6""" 

7 

8import numpy as np 

9 

10from ase.lattice.triclinic import TriclinicFactory 

11 

12 

13class SimpleMonoclinicFactory(TriclinicFactory): 

14 "A factory for creating simple monoclinic lattices." 

15 

16 # The name of the crystal structure in ChemicalElements 

17 xtal_name = 'monoclinic' 

18 

19 def make_crystal_basis(self): 

20 """Make the basis matrix for the crystal unit cell and the system 

21 unit cell.""" 

22 # First convert the basis specification to a triclinic one 

23 if isinstance(self.latticeconstant, type({})): 

24 self.latticeconstant['beta'] = 90 

25 self.latticeconstant['gamma'] = 90 

26 else: 

27 if len(self.latticeconstant) == 4: 

28 self.latticeconstant = self.latticeconstant + (90, 90) 

29 else: 

30 raise ValueError( 

31 'Improper lattice constants for monoclinic crystal.' 

32 ) 

33 

34 TriclinicFactory.make_crystal_basis(self) 

35 

36 

37SimpleMonoclinic = SimpleMonoclinicFactory() 

38 

39 

40class BaseCenteredMonoclinicFactory(SimpleMonoclinicFactory): 

41 # The natural basis vectors of the crystal structure 

42 int_basis = np.array([[1, -1, 0], [1, 1, 0], [0, 0, 2]]) 

43 basis_factor = 0.5 

44 

45 # Converts the natural basis back to the crystallographic basis 

46 inverse_basis = np.array([[1, 1, 0], [-1, 1, 0], [0, 0, 1]]) 

47 inverse_basis_factor = 1.0 

48 

49 

50BaseCenteredMonoclinic = BaseCenteredMonoclinicFactory()