Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

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

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

# coding: utf-8 

# Copyright (c) Pymatgen Development Team. 

# Distributed under the terms of the MIT License. 

 

from __future__ import unicode_literals 

 

""" 

Defines an abstract base class contract for Transformation object. 

""" 

 

__author__ = "Shyue Ping Ong" 

__copyright__ = "Copyright 2011, The Materials Project" 

__version__ = "0.1" 

__maintainer__ = "Shyue Ping Ong" 

__email__ = "shyuep@gmail.com" 

__date__ = "Sep 23, 2011" 

 

import abc 

 

from monty.json import MSONable 

import six 

 

 

class AbstractTransformation(six.with_metaclass(abc.ABCMeta, MSONable)): 

""" 

Abstract transformation class. 

""" 

 

@abc.abstractmethod 

def apply_transformation(self, structure): 

""" 

Applies the transformation to a structure. Depending on whether a 

transformation is one-to-many, there may be an option to return a 

ranked list of structures. 

 

Args: 

structure: 

input structure 

return_ranked_list: 

Boolean stating whether or not multiple structures are 

returned. If return_ranked_list is a number, that number of 

structures is returned. 

 

Returns: 

depending on returned_ranked list, either a transformed structure 

or 

a list of dictionaries, where each dictionary is of the form 

{'structure' = .... , 'other_arguments'} 

the key 'transformation' is reserved for the transformation that 

was actually applied to the structure. 

This transformation is parsed by the alchemy classes for generating 

a more specific transformation history. Any other information will 

be stored in the transformation_parameters dictionary in the 

transmuted structure class. 

""" 

return 

 

@abc.abstractproperty 

def inverse(self): 

""" 

Returns the inverse transformation if available. 

Otherwise, should return None. 

""" 

return 

 

@abc.abstractproperty 

def is_one_to_many(self): 

""" 

Determines if a Transformation is a one-to-many transformation. If a 

Transformation is a one-to-many transformation, the 

apply_transformation method should have a keyword arg 

"return_ranked_list" which allows for the transformed structures to be 

returned as a ranked list. 

""" 

return False 

 

@property 

def use_multiprocessing(self): 

""" 

Indicates whether the transformation can be applied by a 

subprocessing pool. This should be overridden to return True for 

transformations that the transmuter can parallelize. 

""" 

return False 

 

@classmethod 

def from_dict(cls, d): 

return cls(**d["init_args"])