def fillCalcsandPropsDict(self): self.checkedPropsDict = { "melting_point": self.melting_point, "boiling_point": self.boiling_point, "water_sol": self.water_sol, "vapor_press": self.vapor_press, "mol_diss": self.mol_diss, "ion_con": self.ion_con, "henrys_law_con": self.henrys_law_con, "kow_no_ph": self.kow_no_ph, "kow_wph": self.kow_wph, "kow_ph": self.kow_ph, "koc": self.koc } # calculator checkboxes' values: self.calcluatorsDict = { "chemaxon": self.chemaxon, "epi": self.epi, "test": self.test, "sparc": self.sparc, "measured": self.measured } self.parent_image = data_walks.nodeWrapper(self.smiles, None, 250, 50, 'pchem_parent_wrap', 'svg', None) # dict with keys of checked calculators and values of # checked properties that are also available for said calculators # format: { key: "calculator name", value: [checked property ids] } self.checkedCalcsAndPropsDict = {} for calcKey, calcValue in self.calcluatorsDict.items(): if calcValue == 'true' or calcValue == 'on': # get checked parameters that are available for calculator propList = [] for propKey, propValue in self.checkedPropsDict.items(): # find checked properties if propValue == 'on' or propValue == 'true': # check if property is available for calculator: if pchemprop_parameters.pchempropAvailable(calcKey, propKey): propList.append(propKey) self.checkedCalcsAndPropsDict.update({calcKey: propList}) self.run_data = { 'title': "P-Chem Properties Output", 'jid': self.jid, 'time': datetime.datetime.strptime(self.jid, '%Y%m%d%H%M%S%f').strftime('%A, %Y-%B-%d %H:%M:%S'), 'chem_struct': self.chem_struct, 'smiles': self.smiles, 'name': self.name, 'formula': self.formula, 'mass': self.mass, 'exactMass': self.exact_mass }
def parsePOST(request): pdf_t = request.POST.get('pdf_t') pdf_nop = request.POST.get('pdf_nop') pdf_p = json.loads(request.POST.get('pdf_p')) if 'pdf_json' in request.POST and request.POST['pdf_json']: pdf_json = json.loads(request.POST.get('pdf_json')) # pdf_json = request.POST.get('pdf_json') else: pdf_json = None # Append strings and check if charts are present final_str = pdf_t if 'gentrans' in request.path: headings = ['genKey', 'smiles', 'iupac', 'formula', 'mass', 'exactMass', 'routes'] calcs = ['chemaxon', 'epi', 'test', 'sparc', 'measured'] checkedCalcsAndProps = pdf_json['checkedCalcsAndProps'] products = pdf_json['nodes'] props = ['melting_point', 'boiling_point', 'water_sol', 'vapor_press', 'mol_diss', 'ion_con', 'henrys_law_con', 'kow_no_ph', 'kow_wph', 'koc'] for product in products: product_image = data_walks.nodeWrapper(product['smiles'], None, 250, 100, product['genKey'], 'png', False) product.update({'image': product_image}) # build object that's easy to make pchem table in template.. if 'pchemprops' in product: rows = [] for prop in props: data_row = [] kow_no_ph_list = [] kow_wph_list = [] data_row.append(prop) calc_index = 1 for calc in calcs: # pick out data by key, make sure not already there.. for data_obj in product['pchemprops']: if data_obj['prop'] == prop and data_obj['calc'] == calc: if prop == 'kow_no_ph' and calc == 'chemaxon': # expecting same calc/prop with 3 methods..\ already_there = False for item in kow_no_ph_list: if data_obj['method'] == item['method']: already_there = True if not already_there: kow_no_ph_list.append({ 'method': data_obj['method'], 'data': round(data_obj['data'], 2) }) elif prop == 'kow_wph' and calc == 'chemaxon': # expecting same calc/prop with 3 methods.. already_there = False for item in kow_no_ph_list: if data_obj['method'] == item['method']: already_there = True if not already_there: kow_wph_list.append({ 'method': data_obj['method'], 'data': round(data_obj['data'], 2) }) # account for kow_wph too!!!!! # elif prop == 'ion_con' and calc == 'chemaxon': elif prop == 'ion_con': # is there also pKb????? pka_string = "" pka_index = 1 for pka in data_obj['data']['pKa']: pka_string += "pka_{}: {} \n".format(pka_index, round(pka, 2)) pka_index += 1 data_row.append(pka_string) else: data_row.append(data_obj['data']) if len(data_row) <= calc_index: # should mean there wasn't data for calc-prop combo: data_row.append('') calc_index += 1 if prop == 'kow_no_ph' and calc == 'chemaxon': # insert chemaxon's kow values if they exist: kow_string = "" for kow in kow_no_ph_list: kow_string += "{} ({}) \n".format(kow['data'], kow['method']) # data_row.insert(1, kow_string) data_row[1] = kow_string # kow_values = [] if prop == 'kow_wph' and calc == 'chemaxon': # insert chemaxon's kow values if they exist: kow_string = "" for kow in kow_wph_list: kow_string += "{} ({}) \n".format(kow['data'], kow['method']) # data_row.insert(1, kow_string) data_row[1] = kow_string # kow_values = [] rows.append(data_row) product['data'] = rows final_str += buildMetaboliteTableForPDF().render( Context(dict(headings=headings, checkedCalcsAndProps=checkedCalcsAndProps, products=products, props=props, calcs=calcs))) final_str += """<br>""" if (int(pdf_nop)>0): for i in range(int(pdf_nop)): final_str += """<img id="imgChart1" src="%s" />"""%(pdf_p[i]) # final_str = final_str + """<br>""" # Styling input_css=""" <style> html { background-color:#FFFFFF; } body { font-family: 'Open Sans', sans-serif; } table, td, th { border: 1px solid #666666; } #gentrans_table td { /*word-wrap: normal;*/ max-width: 100px; word-break: break-all; } table#inputsTable td { max-width: 600px; word-break: break-all; } th {text-align:center; padding:2px; font-size:11px;} td {padding:2px; font-size:10px;} h2 {font-size:13px; color:#79973F;} h3 {font-size:12px; color:#79973F; margin-top: 8px;} h4 {font-size:12px; color:#79973F; padding-top:30px;} .pdfDiv {border: 1px solid #000000;} div.tooltiptext {display: table; border: 1px solid #333333; margin: 8px; padding: 4px} div { background-color: #FFFFFF; } img { background-color: #FFFFFF; } </style> """ input_str = input_css + final_str return input_str
def wrap_molecule(propDict, height, width, scale): """ Wraps molecule image result (source url) with a table and populates said table with molecular details. Inputs: property dict (e.g., pka, taut image urls) Outputs: name, iupac, forumula, mass data wrapped in table with image and name """ if not propDict: return "<p>could not retrieve molecule image</p>" key = None if 'key' in propDict: key = propDict['key'] # image = mark_safe(data_walks.nodeWrapper(propDict['smiles'], None, width, scale, key)) # displayed image image = mark_safe(data_walks.nodeWrapper(propDict['smiles'], None, width, scale, key, 'svg')) # displayed image formula = propDict['formula'] iupac = propDict['iupac'] mass = "{} g/mol".format(propDict['mass']) smiles = propDict['smiles'] exactMass = "{} g/mol".format(propDict['exactMass']) # call nodeWrapper again with 'png' image format and add it to infoDict # with a image_pdf key or something.... # pdf_image = mark_safe(data_walks.nodeWrapper(propDict['smiles'], None, width, scale, key, None)) infoDict = { "image": image, "formula": formula, "iupac": iupac, "mass": mass, "smiles": smiles, "exactMass": exactMass # 'pdf_image': pdf_image } # this is the actual image on the chemspec output, wrapped in a div: html = """ <div class="chemspec_molecule nopdf"> """ html += infoDict['image'] # html += infoDict['pdf_image'] html += """ </div> """ # this builds the larger-image popup: # the Molecular/Structure class/object needs to be used as well # as its location in CTS considered. Is it being in REST make sense? # the following list needs to be in that class: mol_props = ['formula', 'iupac', 'mass', 'smiles', 'exactMass'] # wrappedDict = data_walks.popupBuilder(infoDict, ['formula', 'iupac', 'mass', 'smiles'], key, 'Molecular Information') # popup table image wrappedDict = data_walks.popupBuilder(infoDict, mol_props, key, 'Molecular Information') # popup table image html += '<div class="tooltiptext ' + iupac + '">' html += wrappedDict['html'] html += '</div>' return html # def makeLogFile(chemspec_obj): # """ # Gathers data for log file and # puts it in a hidden div to be downloaded # by the user # """