31
31
from jinja2 import Template
32
32
from pathlib import Path
33
33
34
- from tkinter import Tk , Text , TOP , BOTH , X , N , LEFT , RIGHT
34
+ from tkinter import BOTH , X , LEFT
35
35
from tkinter .ttk import Frame , Label , Entry , Button
36
36
37
37
pore_query_dict = {"total_surface_area" : "Pore Total Surface Area (Å^2)" ,
38
- "total_geometric_volume" : "Pore Total Geometric Volume (Å^3)" ,
39
- "pore_limiting_diameter" : "Pore Limiting Diameter (Å)" ,
40
- "max_pore_diameter" :"Pore Maximum Diameter (Å)" ,
41
- "num_percolated_dimensions" :"Number of Percolated Dimensions" }
38
+ "total_geometric_volume" : "Pore Total Geometric Volume (Å^3)" ,
39
+ "pore_limiting_diameter" : "Pore Limiting Diameter (Å)" ,
40
+ "max_pore_diameter" : "Pore Maximum Diameter (Å)" ,
41
+ "num_percolated_dimensions" : "Number of Percolated Dimensions" }
42
+
42
43
43
44
class VoidDialog (Frame ):
44
45
@@ -62,8 +63,8 @@ def initUI(self):
62
63
self .master .title ("Simple Dialog" )
63
64
self .pack (fill = BOTH , expand = True )
64
65
65
- [self .generate_entry (text , output ) for text ,output in zip (pore_query_dict .values (), self .outputs )]
66
-
66
+ [self .generate_entry (text , output ) for text , output in zip (pore_query_dict .values (), self .outputs )]
67
+
67
68
frame_button = Frame (self )
68
69
frame_button .pack (fill = X )
69
70
@@ -75,7 +76,7 @@ def initUI(self):
75
76
def onSubmit (self ):
76
77
self .outputs = [x .get () for x in self .entries ]
77
78
self .quit ()
78
-
79
+
79
80
80
81
def get_query_text ():
81
82
"""Open a GUI dialog to ask for a search term.
@@ -86,11 +87,11 @@ def get_query_text():
86
87
root = Tkinter .Tk ()
87
88
root .geometry ("400x300+300+300" )
88
89
app = VoidDialog ()
89
-
90
+
90
91
root .mainloop ()
91
92
92
93
# Vars are where it retrieves the app outputs (the values you entered) into the query
93
- vars = {k :v for k ,v in zip (pore_query_dict .keys (), app .outputs )}
94
+ vars = {k : v for k , v in zip (pore_query_dict .keys (), app .outputs )}
94
95
95
96
try :
96
97
root .destroy ()
@@ -100,7 +101,7 @@ def get_query_text():
100
101
return vars
101
102
102
103
103
- def query_string_to_tuple (query_string , default_upper_limit = 9999.9 ):
104
+ def query_string_to_tuple (query_string , default_upper_limit = 9999.9 ):
104
105
"""this converts a string to a tuple of values representing the upper and lower bounds.
105
106
Compatible with a single value (x, <x, >x) or a range (x-y)"""
106
107
if "-" in query_string :
@@ -113,24 +114,26 @@ def query_string_to_tuple(query_string, default_upper_limit = 9999.9):
113
114
ul , _ , ll = query_string .partition (">" )
114
115
ll = ll .lstrip ("=" )
115
116
ul = ul .rstrip ("=" )
116
- elif query_string in ("0" ,"0.0" ):
117
+ elif query_string in ("0" , "0.0" ):
117
118
ll , ul = 0.0 , 0.1
118
119
else :
119
120
ll , ul = float (query_string )* 0.95 , float (query_string )* 1.05
120
-
121
- if ll != "" :
121
+
122
+ if ll != "" :
122
123
lower_limit = float (ll )
123
124
else :
124
- lower_limit = 0.0
125
- if ul != "" :
125
+ lower_limit = 0.0
126
+ if ul != "" :
126
127
upper_limit = float (ul )
127
128
else :
128
129
upper_limit = default_upper_limit
129
130
return (lower_limit , upper_limit )
130
-
131
+
132
+
131
133
def convert_to_ascii (text ):
132
134
return unicodedata .normalize ('NFKD' , text ).encode ('ascii' , 'ignore' ).decode ('ascii' )
133
135
136
+
134
137
def run_search (interface = None ):
135
138
"""Search the CSD for a set of void descriptors. This will generate a list of structures
136
139
@@ -160,8 +163,8 @@ def run_search(interface=None):
160
163
161
164
# Parse the commandline including checking for the compound parameter.
162
165
interface .parse_commandline ()
163
-
164
- ## open a GUI dialog asking for the search query.
166
+
167
+ # open a GUI dialog asking for the search query.
165
168
void_search_dict = get_query_text ()
166
169
167
170
query_report = str ()
@@ -173,31 +176,31 @@ def run_search(interface=None):
173
176
174
177
# Set up and run the CSD search
175
178
interface .update_progress ('Running search for pore %s ...' % str (void_search_dict ))
176
-
179
+
177
180
TNS = TextNumericSearch ()
178
181
if void_search_dict .get ("total_surface_area" , False ):
179
182
tsa = query_string_to_tuple (void_search_dict ["total_surface_area" ], 10000.0 )
180
- query_report += f"Pore Total Surface Area (Å^2) { tsa [0 ]} -{ tsa [1 ]} <br>"
183
+ query_report += f"Pore Total Surface Area (Å^2) { tsa [0 ]} -{ tsa [1 ]} <br>"
181
184
TNS .add_pore_analysis_total_surface_area (tsa )
182
-
185
+
183
186
if void_search_dict .get ("total_geometric_volume" , False ):
184
187
tgv = query_string_to_tuple (void_search_dict ["total_geometric_volume" ], 100000.0 )
185
- query_report += f"Pore Total Geometric Volume (Å^3): { tgv [0 ]} -{ tgv [1 ]} <br>"
188
+ query_report += f"Pore Total Geometric Volume (Å^3): { tgv [0 ]} -{ tgv [1 ]} <br>"
186
189
TNS .add_pore_analysis_total_geometric_volume (tgv )
187
190
188
191
if void_search_dict .get ("pore_limiting_diameter" , False ):
189
- pld = query_string_to_tuple (void_search_dict ["pore_limiting_diameter" ],200.0 )
190
- query_report += f"Pore Limiting Diameter (Å): { pld [0 ]} -{ pld [1 ]} <br>"
192
+ pld = query_string_to_tuple (void_search_dict ["pore_limiting_diameter" ], 200.0 )
193
+ query_report += f"Pore Limiting Diameter (Å): { pld [0 ]} -{ pld [1 ]} <br>"
191
194
TNS .add_pore_analysis_pore_limiting_diameter (pld )
192
195
193
196
if void_search_dict .get ("max_pore_diameter" , False ):
194
- pmd = query_string_to_tuple (void_search_dict ["max_pore_diameter" ],200.0 )
195
- query_report += f"Pore Maximum Diameter (Å): { pmd [0 ]} -{ pmd [1 ]} <br>"
197
+ pmd = query_string_to_tuple (void_search_dict ["max_pore_diameter" ], 200.0 )
198
+ query_report += f"Pore Maximum Diameter (Å): { pmd [0 ]} -{ pmd [1 ]} <br>"
196
199
TNS .add_pore_analysis_max_pore_diameter (pmd )
197
200
198
201
if void_search_dict .get ("num_percolated_dimensions" , False ):
199
- npd = query_string_to_tuple (void_search_dict ["num_percolated_dimensions" ],3.1 )
200
- query_report += f"Number of Percolated Dimensions: { npd [0 ]} -{ npd [1 ]} <br>"
202
+ npd = query_string_to_tuple (void_search_dict ["num_percolated_dimensions" ], 3.1 )
203
+ query_report += f"Number of Percolated Dimensions: { npd [0 ]} -{ npd [1 ]} <br>"
201
204
TNS .add_pore_analysis_max_pore_diameter (npd )
202
205
203
206
hits = TNS .search ()
@@ -208,12 +211,12 @@ def run_search(interface=None):
208
211
with ccdc .utilities .output_file (interface .output_gcd_file ) as gcd_file , \
209
212
ccdc .utilities .CSVWriter (interface .output_tsv_file ,
210
213
header = ["Identifier" ,
211
- "Pore Total Surface Area (\u212b ^2)" ,
214
+ "Pore Total Surface Area (\u212b ^2)" ,
212
215
"Pore Total Geometric Volume (\u212b ^3)" ,
213
216
"Pore Limiting Diameter (\u212b )" ,
214
217
"Pore Maximum Diameter (\u212b )" ,
215
218
"Pore Number of Percolated Dimensions" ,
216
- 'Chemical Name(s)' ,
219
+ 'Chemical Name(s)' ,
217
220
],
218
221
delimiter = '\t ' ) as tsv_file :
219
222
@@ -227,14 +230,14 @@ def run_search(interface=None):
227
230
print (h .identifier , file = gcd_file )
228
231
pa = h .entry .calculated_properties .pore_analyser
229
232
refcode_list .append (h .identifier )
230
- tsv_file .write_row ([h .identifier ,
233
+ tsv_file .write_row ([h .identifier ,
231
234
pa .total_surface_area ,
232
235
pa .total_geometric_volume ,
233
236
pa .pore_limiting_diameter ,
234
237
pa .max_pore_diameter ,
235
238
pa .num_percolated_dimensions ,
236
239
names ])
237
-
240
+
238
241
with open (interface .output_html_file , "w" ) as report :
239
242
tl = Template (
240
243
open (
@@ -244,7 +247,7 @@ def run_search(interface=None):
244
247
)
245
248
report .write (
246
249
tl .render (
247
- title = "Voids_search" ,
250
+ title = "Voids_search" ,
248
251
data = f"""
249
252
Query: { query_report } <br>
250
253
Result:{ len (refcode_list )} hits in { len (set (refcode_list ))} structures <br>
0 commit comments