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

19 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-08-02 00:12 +0000

1# fmt: off 

2 

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

4 

5The following lattice creator is defined: 

6 SimpleMonoclinic 

7 BaseCenteredMonoclinic 

8""" 

9 

10import numpy as np 

11 

12from ase.lattice.triclinic import TriclinicFactory 

13 

14 

15class SimpleMonoclinicFactory(TriclinicFactory): 

16 "A factory for creating simple monoclinic lattices." 

17 # The name of the crystal structure in ChemicalElements 

18 xtal_name = "monoclinic" 

19 

20 def make_crystal_basis(self): 

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

22 unit cell.""" 

23 # First convert the basis specification to a triclinic one 

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

25 self.latticeconstant['beta'] = 90 

26 self.latticeconstant['gamma'] = 90 

27 else: 

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

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

30 else: 

31 raise ValueError( 

32 "Improper lattice constants for monoclinic crystal.") 

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], 

43 [1, 1, 0], 

44 [0, 0, 2]]) 

45 basis_factor = 0.5 

46 

47 # Converts the natural basis back to the crystallographic basis 

48 inverse_basis = np.array([[1, 1, 0], 

49 [-1, 1, 0], 

50 [0, 0, 1]]) 

51 inverse_basis_factor = 1.0 

52 

53 

54BaseCenteredMonoclinic = BaseCenteredMonoclinicFactory()