3131from jinja2 import Template
3232from pathlib import Path
3333
34- from tkinter import Tk , Text , TOP , BOTH , X , N , LEFT , RIGHT
34+ from tkinter import BOTH , X , LEFT
3535from tkinter .ttk import Frame , Label , Entry , Button
3636
3737pore_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+
4243
4344class VoidDialog (Frame ):
4445
@@ -62,8 +63,8 @@ def initUI(self):
6263 self .master .title ("Simple Dialog" )
6364 self .pack (fill = BOTH , expand = True )
6465
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+
6768 frame_button = Frame (self )
6869 frame_button .pack (fill = X )
6970
@@ -75,7 +76,7 @@ def initUI(self):
7576 def onSubmit (self ):
7677 self .outputs = [x .get () for x in self .entries ]
7778 self .quit ()
78-
79+
7980
8081def get_query_text ():
8182 """Open a GUI dialog to ask for a search term.
@@ -86,11 +87,11 @@ def get_query_text():
8687 root = Tkinter .Tk ()
8788 root .geometry ("400x300+300+300" )
8889 app = VoidDialog ()
89-
90+
9091 root .mainloop ()
9192
9293 # 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 )}
9495
9596 try :
9697 root .destroy ()
@@ -100,7 +101,7 @@ def get_query_text():
100101 return vars
101102
102103
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 ):
104105 """this converts a string to a tuple of values representing the upper and lower bounds.
105106 Compatible with a single value (x, <x, >x) or a range (x-y)"""
106107 if "-" in query_string :
@@ -113,24 +114,26 @@ def query_string_to_tuple(query_string, default_upper_limit = 9999.9):
113114 ul , _ , ll = query_string .partition (">" )
114115 ll = ll .lstrip ("=" )
115116 ul = ul .rstrip ("=" )
116- elif query_string in ("0" ,"0.0" ):
117+ elif query_string in ("0" , "0.0" ):
117118 ll , ul = 0.0 , 0.1
118119 else :
119120 ll , ul = float (query_string )* 0.95 , float (query_string )* 1.05
120-
121- if ll != "" :
121+
122+ if ll != "" :
122123 lower_limit = float (ll )
123124 else :
124- lower_limit = 0.0
125- if ul != "" :
125+ lower_limit = 0.0
126+ if ul != "" :
126127 upper_limit = float (ul )
127128 else :
128129 upper_limit = default_upper_limit
129130 return (lower_limit , upper_limit )
130-
131+
132+
131133def convert_to_ascii (text ):
132134 return unicodedata .normalize ('NFKD' , text ).encode ('ascii' , 'ignore' ).decode ('ascii' )
133135
136+
134137def run_search (interface = None ):
135138 """Search the CSD for a set of void descriptors. This will generate a list of structures
136139
@@ -160,8 +163,8 @@ def run_search(interface=None):
160163
161164 # Parse the commandline including checking for the compound parameter.
162165 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.
165168 void_search_dict = get_query_text ()
166169
167170 query_report = str ()
@@ -173,31 +176,31 @@ def run_search(interface=None):
173176
174177 # Set up and run the CSD search
175178 interface .update_progress ('Running search for pore %s ...' % str (void_search_dict ))
176-
179+
177180 TNS = TextNumericSearch ()
178181 if void_search_dict .get ("total_surface_area" , False ):
179182 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>"
181184 TNS .add_pore_analysis_total_surface_area (tsa )
182-
185+
183186 if void_search_dict .get ("total_geometric_volume" , False ):
184187 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>"
186189 TNS .add_pore_analysis_total_geometric_volume (tgv )
187190
188191 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>"
191194 TNS .add_pore_analysis_pore_limiting_diameter (pld )
192195
193196 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>"
196199 TNS .add_pore_analysis_max_pore_diameter (pmd )
197200
198201 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>"
201204 TNS .add_pore_analysis_max_pore_diameter (npd )
202205
203206 hits = TNS .search ()
@@ -208,12 +211,12 @@ def run_search(interface=None):
208211 with ccdc .utilities .output_file (interface .output_gcd_file ) as gcd_file , \
209212 ccdc .utilities .CSVWriter (interface .output_tsv_file ,
210213 header = ["Identifier" ,
211- "Pore Total Surface Area (\u212b ^2)" ,
214+ "Pore Total Surface Area (\u212b ^2)" ,
212215 "Pore Total Geometric Volume (\u212b ^3)" ,
213216 "Pore Limiting Diameter (\u212b )" ,
214217 "Pore Maximum Diameter (\u212b )" ,
215218 "Pore Number of Percolated Dimensions" ,
216- 'Chemical Name(s)' ,
219+ 'Chemical Name(s)' ,
217220 ],
218221 delimiter = '\t ' ) as tsv_file :
219222
@@ -227,14 +230,14 @@ def run_search(interface=None):
227230 print (h .identifier , file = gcd_file )
228231 pa = h .entry .calculated_properties .pore_analyser
229232 refcode_list .append (h .identifier )
230- tsv_file .write_row ([h .identifier ,
233+ tsv_file .write_row ([h .identifier ,
231234 pa .total_surface_area ,
232235 pa .total_geometric_volume ,
233236 pa .pore_limiting_diameter ,
234237 pa .max_pore_diameter ,
235238 pa .num_percolated_dimensions ,
236239 names ])
237-
240+
238241 with open (interface .output_html_file , "w" ) as report :
239242 tl = Template (
240243 open (
@@ -244,7 +247,7 @@ def run_search(interface=None):
244247 )
245248 report .write (
246249 tl .render (
247- title = "Voids_search" ,
250+ title = "Voids_search" ,
248251 data = f"""
249252 Query: { query_report } <br>
250253 Result:{ len (refcode_list )} hits in { len (set (refcode_list ))} structures <br>
0 commit comments