@@ -31,28 +31,28 @@ def __init__(self, crystal, use_existing_charges: bool = False):
31
31
self .surface_atom_charge = np .nan
32
32
self .node_projected_charge = np .nan
33
33
self .node_representative_charge = np .nan
34
+ self .triangles_properties = dict ()
34
35
35
36
@staticmethod
36
37
def sum_atom_charge (atoms : List [object ]) -> float :
37
38
return np .round (np .sum ([atom .partial_charge for atom in atoms ]), 3 )
38
39
39
- def get_average_node_charge (self ):
40
+ def get_node_charge (self ):
40
41
self .node_charge_dictionary = {}
41
42
node_list = list (self .surface .topology .nodes )
42
43
for node , atoms in self .surface .surface_node_atom_contacts .items ():
43
44
node_index = node_list .index (node )
44
- average_node_charge = 0
45
+ total_node_charge = 0
45
46
if len (atoms ) > 0 :
46
- average_node_charge = self .sum_atom_charge (atoms )
47
- self .node_charge_dictionary [node_index ] = average_node_charge
47
+ total_node_charge = self .sum_atom_charge (atoms )
48
+ self .node_charge_dictionary [node_index ] = total_node_charge
48
49
49
50
def calculate_triangles_properties (self ,
50
- tri_index : List [Tuple [int , int , int ]]) -> Dict [
51
- Tuple [int , int , int ], Dict [str , float ]]:
51
+ tri_index : List [Tuple [int , int , int ]]) -> None :
52
52
surface_area = self .surface .descriptors .surface_area
53
53
self .triangles_properties = {}
54
54
triangle_areas = self .calculate_area_of_triangles (list (self .surface .topology .triangles ))
55
- total_triangle_area = sum ( triangle_areas )
55
+
56
56
for node_index , triangle_area in zip (tri_index , triangle_areas ):
57
57
average_triangle_charge = np .mean ([self .node_charge_dictionary [i ] for i in node_index ])
58
58
triangle_representation = triangle_area / surface_area
@@ -68,7 +68,7 @@ def calculate_triangles_properties(self,
68
68
def calculate_node_charges (self ):
69
69
tri_index = self .calculated_node_index_values (list (self .surface .topology .nodes ),
70
70
list (self .surface .topology .triangles ))
71
- self .get_average_node_charge ()
71
+ self .get_node_charge ()
72
72
self .calculate_triangles_properties (tri_index )
73
73
self .representative_charge = np .sum (
74
74
[triangle ['Node Representative Charge' ] for triangle in self .triangles_properties .values ()])
@@ -83,22 +83,14 @@ def calculate_length(origin: np.ndarray, target: np.ndarray) -> float:
83
83
return np .linalg .norm (target - origin )
84
84
85
85
@staticmethod
86
- def compute_triangle_area ( a : float , b : float , c : float ) -> float :
87
- """Calculates area of triangle using Heron's formula"""
88
- s = ( a + b + c ) / 2
89
- return np .sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ))
86
+ def compute_simplex_area ( simplex : np . ndarray ) -> float :
87
+ vec_1 = simplex [ 1 ] - simplex [ 0 ]
88
+ vec_2 = simplex [ 2 ] - simplex [ 0 ]
89
+ return np .linalg . norm ( np . cross ( vec_1 , vec_2 )) / 2
90
90
91
91
def calculate_area_of_triangles (self , triangles : List ) -> List :
92
92
""" Calculates area of individual triangles from node positions using Heron's formula"""
93
- triangle_areas = []
94
- for triangle in triangles :
95
- pos_0 , pos_1 , pos_2 = np .array (triangle [0 ]), np .array (triangle [1 ]), np .array (triangle [2 ]),
96
- a_dist = self .calculate_length (pos_0 , pos_1 )
97
- b_dist = self .calculate_length (pos_0 , pos_2 )
98
- c_dist = self .calculate_length (pos_1 , pos_2 )
99
- triangle_areas .append (self .compute_triangle_area (a_dist , b_dist , c_dist ))
100
-
101
- return triangle_areas
93
+ return [self .compute_simplex_area (np .array (triangle )) for triangle in triangles ]
102
94
103
95
@staticmethod
104
96
def calculated_node_index_values (nodes : List , triangles : List ) -> List :
@@ -222,6 +214,7 @@ def generate_html_table(self):
222
214
html += """
223
215
</table>
224
216
<p><i> *-Surface charge is based on gasteiger partial charges <a href="https://www.sciencedirect.com/science/article/pii/S0040403901949779?via%3Dihub">10.1016/S0040-4039(01)94977-9</a></i> </p>
217
+ <p> Topological surface charge is defined as the average triangle charge on the surface multiplied by the % area contribution towards the total surface. </p>
225
218
</body>
226
219
</html>
227
220
"""
0 commit comments