-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathshape_classification.py
More file actions
71 lines (60 loc) · 2.59 KB
/
Copy pathshape_classification.py
File metadata and controls
71 lines (60 loc) · 2.59 KB
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
#
# This script can be used for any purpose without limitation subject to the
# conditions at https://www.ccdc.cam.ac.uk/Community/Pages/Licences/v2.aspx
#
# This permission notice and the following statement of attribution must be
# included in all copies or substantial portions of this script.
#
# 2023-06-21: created by Pietro Sacchi, The Cambridge Crystallographic Data Centre
# 2024-04-15: modified by Alex Moldovan, The Cambridge Crystallographic Data Centre
#
from typing import TypeVar, TYPE_CHECKING
MorphologyBase = TypeVar('MorphologyBase')
if TYPE_CHECKING:
from ccdc.morphology import MorphologyBase
class ShapeClassification:
"""
Calculate parameters for shape classification as defined by Angelidakis et al. in
Powder Technology, 396 (2022), 689-695
"""
def __init__(self, major: float, medium: float, minor: float):
self.minor_length = minor
self.medium_length = medium
self.major_length = major
@classmethod
def from_morphology(cls, morphology: MorphologyBase):
"""Return object from morphology"""
return cls(major=morphology.oriented_bounding_box.major_length,
medium=morphology.oriented_bounding_box.median_length,
minor=morphology.oriented_bounding_box.minor_length)
def shape_classification_data(self):
""" returns data as dictionary for database """
return {"shape_classification": self.shape_description,
'S/M': self.minor_length / self.medium_length,
'M/L': self.medium_length / self.major_length}
@property
def elongation(self) -> float:
return (self.major_length * self.minor_length) / (
self.major_length * self.minor_length + self.medium_length ** 2) - self.minor_length / (
self.major_length + self.minor_length)
@property
def flatness(self) -> float:
return self.medium_length ** 2 / (
self.major_length * self.minor_length + self.medium_length ** 2) - self.minor_length / (
self.major_length + self.minor_length)
@property
def compactness(self) -> float:
return 2 * self.minor_length / (self.major_length + self.minor_length)
@property
def shape_description(self) -> str:
"""Return the classification of the shape"""
if self.elongation >= 0.2:
if self.flatness >= 0.2:
return "Lath"
else:
return "Needle"
if self.elongation <= 0.2:
if self.flatness <= 0.2:
return "Block"
else:
return "Plate"