Coverage for ase/lattice/tetragonal.py: 55.56%

18 statements  

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

1"""Function-like objects creating tetragonal lattices. 

2 

3The following lattice creators are defined: 

4 SimleTetragonal 

5 CenteredTetragonal 

6""" 

7 

8from ase.lattice.orthorhombic import ( 

9 BodyCenteredOrthorhombicFactory, 

10 SimpleOrthorhombicFactory, 

11) 

12 

13 

14class _Tetragonalize: 

15 "A mixin class for implementing tetragonal crystals as orthorhombic ones." 

16 

17 # The name of the crystal structure in ChemicalElements 

18 xtal_name = 'tetragonal' 

19 

20 def make_crystal_basis(self): 

21 lattice = self.latticeconstant 

22 if isinstance(lattice, type({})): 

23 lattice['b/a'] = 1.0 

24 else: 

25 if len(lattice) == 2: 

26 lattice = (lattice[0], lattice[0], lattice[1]) 

27 else: 

28 raise ValueError( 

29 'Improper lattice constants for tetragonal crystal.' 

30 ) 

31 self.latticeconstant = lattice 

32 self.orthobase.make_crystal_basis(self) 

33 

34 

35class SimpleTetragonalFactory(_Tetragonalize, SimpleOrthorhombicFactory): 

36 "A factory for creating simple tetragonal lattices." 

37 

38 orthobase = SimpleOrthorhombicFactory 

39 

40 

41SimpleTetragonal = SimpleTetragonalFactory() 

42 

43 

44class CenteredTetragonalFactory( 

45 _Tetragonalize, BodyCenteredOrthorhombicFactory 

46): 

47 "A factory for creating centered tetragonal lattices." 

48 

49 orthobase = BodyCenteredOrthorhombicFactory 

50 

51 

52CenteredTetragonal = CenteredTetragonalFactory()