def EniSearch(request): """ Creates webpage form to display detergent and deposit structures upon entering smiles as well as returns binding constants between the detergent and deposit """ from tools import getAbrahamAB if request.method == "POST": form = EniSearchForm(request.POST, error_class=DivErrorList) if form.is_valid(): detergent_adjlist = form.cleaned_data["detergent"] deposit_adjlist = form.cleaned_data["deposit"] detergent = Molecule() detergent.fromAdjacencyList(detergent_adjlist) detergent_smiles = detergent.toSMILES() detergent_structure = getStructureMarkup(detergent) deposit = Molecule() deposit.fromAdjacencyList(deposit_adjlist) deposit_smiles = deposit.toSMILES() deposit_structure = getStructureMarkup(deposit) detergentA, detergentB = getAbrahamAB(detergent_smiles) depositA, depositB = getAbrahamAB(deposit_smiles) # Estimating the binding strength assuming the the detergent to be the donor and dirt to be acceptor logK_AB = 7.354 * detergentA * depositB # Estimating the binding strength assuming the the detergent to be the acceptor and dirt to be donor logK_BA = 7.354 * detergentB * depositA else: detergentA = 0 detergentB = 0 depositA = 0 depositB = 0 logK_AB = 0 logK_BA = 0 form = EniSearchForm() return render_to_response( "EniSearch.html", { "detergentA": detergentA, "detergentB": detergentB, "depositA": depositA, "depositB": depositB, "logKAB": logK_AB, "logKBA": logK_BA, "form": form, }, context_instance=RequestContext(request), )
def example(): """Create a set of sample tables""" # In practice, you'd most likely be embedding your HTML tables in # a web page template. For demonstration purposes, we'll create a # simple page with a few default styles. htmlheader = """\ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Sample table</title> <style type="text/css"> body { font-family: Helvetica,Arial,FreeSans; } table.reporttable { border-style: solid; border-width: 1px; } table.reporttable tr.tr_odd { background-color: #eee; } table.reporttable tr.tr_even { background-color: #bbb; } table.reporttable th { background-color: blue; color: white; } table.reporttable td.cell_bold { font-weight: bold; } table.reporttable td.cell_money { text-align: right; font-family: monospace; } </style> </head> <body> """ htmlfooter = """\ </body> </html>""" exampletypes = ((PDFTable, 'pdf'), (HTMLTable, 'html'), (SpreadsheetTable, 'xls')) #### Example with several row types # mainrs = RowSpec( # ColumnSpec('foo', 'Column 1', width=1), # ColumnSpec('bar', 'Column 2', width=1), # ColumnSpec('baz', 'Column 3', width=1), # ColumnSpec('qux', 'Column 4', width=4)) # # subrow1 = RowSpec( # ColumnSpec('subfoo1', 'First wide column', bold=True, span=2, width=2), # ColumnSpec('subbar1', 'Second wide column', span=2)) # # subrow2 = RowSpec( # ColumnSpec('subfoo2', 'A table-wide column', span=4)) # # summaryrow = RowSpec( # ColumnSpec('junk1', span=2, width=2), # ColumnSpec('baz', bold=True, width=1), # ColumnSpec('junk2')) # # lines = [] # lines.append([mainrs({'foo': 1, 'bar': 2, 'baz': 3, 'qux': 'Bar. ' * 30}), # subrow1({'subfoo1': 'And', 'subbar1': 'another'}), # subrow2({'subfoo2': 'This is a test. ' * 15}), # subrow2({'subfoo2': 'And another test'})]) # for i in range(5): # lines.append(mainrs({'foo': i, 'bar': 14, 'baz': 15, 'qux': 'extra'})) # lines.append(summaryrow({'junk1': None, 'baz': 'Summary!', 'junk2': None})) # # for tableclass, extension in exampletypes: # outfile = open('showcase.%s' % extension, 'wb') # if tableclass is HTMLTable: # outfile.write(htmlheader) # outfile.write(tableclass('Sample Table', # '%s test' % extension.upper(), # headers=[mainrs, subrow1, subrow2]).render(lines)) # if tableclass is HTMLTable: # outfile.write(htmlfooter) #### Converting species dictionary from RMG-Java in bond connectivity # format into the smile and import decimal import random import numpy as np import csv import itertools from rmgpy.molecule import Molecule #reading text file of species groups= [] uniquekeys = [] def isa_group_separator(line): return line=='\n' with open('Species_Dictionary.txt') as f: for key,group in itertools.groupby(f,isa_group_separator): groups.append(list(group)) uniquekeys.append(key) #print groups , len(groups) # Since empty lines are appered as seperate lists in the groups lis, # this section is removing them from the final list groupsb = list() for sublist in groups: if not any(map(str.strip, sublist)): # this detects blanks continue # it was blank, so skip it if sublist not in groupsb: # this detects duplicates groupsb.append(sublist) #print groupsb , len (groupsb) # remove '\n' from each item in list def stripp(x): return x.strip('\n') groupsb=[list(map(stripp,x)) for x in groupsb] #print groupsb rows = [] for index, adjacency_list in enumerate(groupsb, start=1): species_name = adjacency_list[0] mol = Molecule().fromAdjacencyList('\n'.join(adjacency_list)) smiles = mol.toSMILES() rows.append({'Index': index, 'Species': species_name, 'SMILES': smiles, 'Molecule': mol, }) print "Made {num} rows".format(num=len(rows)) invoicerow = RowSpec(ColumnSpec('Index', 'Index #'), ColumnSpec('Species', 'Species Name'), ColumnSpec('SMILES', 'SMILES'), ColumnSpec('Molecule', 'Molecule'), ) lines = invoicerow.makeall(rows) def image(mol): from base64 import b64encode src = mol._repr_png_() encoded = b64encode(src) return '<img alt="{name}" src="data:image/png;base64,{data}" />'.format(name=mol.toSMILES(), data=encoded) image.htmlsafe = True def blank(mol): return '' for tableclass, extension in exampletypes: outfile = open('Species.%s' % extension, 'wb') if tableclass is HTMLTable: tableclass.castfunctions[Molecule] = image else: tableclass.castfunctions[Molecule] = blank if tableclass is HTMLTable: outfile.write(htmlheader) outfile.write(tableclass('Species dictionary', 'species list from RMG-java generated mechanism for bio-oil gasification', headers=invoicerow).render(lines)) if tableclass is HTMLTable: outfile.write(htmlfooter)
def example(): """Create a set of sample tables""" # In practice, you'd most likely be embedding your HTML tables in # a web page template. For demonstration purposes, we'll create a # simple page with a few default styles. htmlheader = """\ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Sample table</title> <style type="text/css"> body { font-family: Helvetica,Arial,FreeSans; } table.reporttable { border-style: solid; border-width: 1px; } table.reporttable tr.tr_odd { background-color: #eee; } table.reporttable tr.tr_even { background-color: #bbb; } table.reporttable th { background-color: blue; color: white; } table.reporttable td.cell_bold { font-weight: bold; } table.reporttable td.cell_money { text-align: right; font-family: monospace; } </style> </head> <body> """ htmlfooter = """\ </body> </html>""" exampletypes = ((PDFTable, 'pdf'), (HTMLTable, 'html'), (SpreadsheetTable, 'xls')) #### Example with several row types # mainrs = RowSpec( # ColumnSpec('foo', 'Column 1', width=1), # ColumnSpec('bar', 'Column 2', width=1), # ColumnSpec('baz', 'Column 3', width=1), # ColumnSpec('qux', 'Column 4', width=4)) # # subrow1 = RowSpec( # ColumnSpec('subfoo1', 'First wide column', bold=True, span=2, width=2), # ColumnSpec('subbar1', 'Second wide column', span=2)) # # subrow2 = RowSpec( # ColumnSpec('subfoo2', 'A table-wide column', span=4)) # # summaryrow = RowSpec( # ColumnSpec('junk1', span=2, width=2), # ColumnSpec('baz', bold=True, width=1), # ColumnSpec('junk2')) # # lines = [] # lines.append([mainrs({'foo': 1, 'bar': 2, 'baz': 3, 'qux': 'Bar. ' * 30}), # subrow1({'subfoo1': 'And', 'subbar1': 'another'}), # subrow2({'subfoo2': 'This is a test. ' * 15}), # subrow2({'subfoo2': 'And another test'})]) # for i in range(5): # lines.append(mainrs({'foo': i, 'bar': 14, 'baz': 15, 'qux': 'extra'})) # lines.append(summaryrow({'junk1': None, 'baz': 'Summary!', 'junk2': None})) # # for tableclass, extension in exampletypes: # outfile = open('showcase.%s' % extension, 'wb') # if tableclass is HTMLTable: # outfile.write(htmlheader) # outfile.write(tableclass('Sample Table', # '%s test' % extension.upper(), # headers=[mainrs, subrow1, subrow2]).render(lines)) # if tableclass is HTMLTable: # outfile.write(htmlfooter) #### Converting species dictionary from RMG-Java in bond connectivity # format into the smile and import decimal import random import numpy as np import csv import itertools from rmgpy.molecule import Molecule #reading text file of species groups = [] uniquekeys = [] def isa_group_separator(line): return line == '\n' with open('Species_Dictionary.txt') as f: for key, group in itertools.groupby(f, isa_group_separator): groups.append(list(group)) uniquekeys.append(key) #print groups , len(groups) # Since empty lines are appered as seperate lists in the groups lis, # this section is removing them from the final list groupsb = list() for sublist in groups: if not any(map(str.strip, sublist)): # this detects blanks continue # it was blank, so skip it if sublist not in groupsb: # this detects duplicates groupsb.append(sublist) #print groupsb , len (groupsb) # remove '\n' from each item in list def stripp(x): return x.strip('\n') groupsb = [list(map(stripp, x)) for x in groupsb] #print groupsb rows = [] for index, adjacency_list in enumerate(groupsb, start=1): species_name = adjacency_list[0] mol = Molecule().fromAdjacencyList('\n'.join(adjacency_list)) smiles = mol.toSMILES() rows.append({ 'Index': index, 'Species': species_name, 'SMILES': smiles, 'Molecule': mol, }) print "Made {num} rows".format(num=len(rows)) invoicerow = RowSpec( ColumnSpec('Index', 'Index #'), ColumnSpec('Species', 'Species Name'), ColumnSpec('SMILES', 'SMILES'), ColumnSpec('Molecule', 'Molecule'), ) lines = invoicerow.makeall(rows) def image(mol): from base64 import b64encode src = mol._repr_png_() encoded = b64encode(src) return '<img alt="{name}" src="data:image/png;base64,{data}" />'.format( name=mol.toSMILES(), data=encoded) image.htmlsafe = True def blank(mol): return '' for tableclass, extension in exampletypes: outfile = open('Species.%s' % extension, 'wb') if tableclass is HTMLTable: tableclass.castfunctions[Molecule] = image else: tableclass.castfunctions[Molecule] = blank if tableclass is HTMLTable: outfile.write(htmlheader) outfile.write( tableclass( 'Species dictionary', 'species list from RMG-java generated mechanism for bio-oil gasification', headers=invoicerow).render(lines)) if tableclass is HTMLTable: outfile.write(htmlfooter)
with open(f) as thermofile: line = thermofile.readline() match = re.match('InChI = "(.*?)(\/mult\d)*"',line) if not match: continue inchi = match.group(1) mult = match.group(2) if mult: continue mol = Molecule() mol.fromInChI(inchi) mmol = rmgpy.qm.mopac.MopacMolPM3(mol, settings) print mmol.uniqueID, f thermo = mmol.loadThermoData() if not thermo: continue assert inchi.startswith('InChI=1S/') inchimain = inchi[9:] keystart = keydict[inchimain] jthermo = thermodict[keystart] print mol.toSMILES() print inchi print keystart print thermo print jthermo print 'H', thermo.H298.value/jthermo.H298.value, thermo.H298.value-jthermo.H298.value print 'S', thermo.S298.value/jthermo.S298.value, thermo.S298.value-jthermo.S298.value print 'Cp', thermo.Cpdata.values/jthermo.Cpdata.values print
MaxCarbonNumberPerSpecies: 20 MaxOxygenNumberPerSpecies: 20 MaxRadicalNumberPerSpecies: 20 MaxSulfurNumberPerSpecies: 20 MaxSiliconNumberPerSpecies: 20 MaxHeavyAtomNumberPerSpecies: 100 MaxCycleNumberPerSpecies: 20 END PrimaryThermoLibrary: Name: RMG-minimal Location: primaryThermoLibrary END """) for f in os.listdir(folder): f = os.path.join(folder, f) stem, ext = os.path.splitext(f) if ext != '.thermo': continue data = rmgpy.qm.molecule.loadThermoDataFile(f) mol = Molecule().fromAdjacencyList(data['adjacencyList']) output.write('// {0!s}\n'.format(data['InChI'])) output.write('// {0!r}\n'.format(data['thermoData']).replace( '),', '),\n// ')) output.write(mol.toSMILES()) output.write(data['adjacencyList'] + '\n')
MaxCarbonNumberPerSpecies: 20 MaxOxygenNumberPerSpecies: 20 MaxRadicalNumberPerSpecies: 20 MaxSulfurNumberPerSpecies: 20 MaxSiliconNumberPerSpecies: 20 MaxHeavyAtomNumberPerSpecies: 100 MaxCycleNumberPerSpecies: 20 END PrimaryThermoLibrary: Name: RMG-minimal Location: primaryThermoLibrary END """) for f in os.listdir(folder): f = os.path.join(folder,f) stem, ext = os.path.splitext(f) if ext != '.thermo': continue data = rmgpy.qm.molecule.loadThermoDataFile(f) mol = Molecule().fromAdjacencyList(data['adjacencyList']) output.write('// {0!s}\n'.format(data['InChI'])) output.write('// {0!r}\n'.format(data['thermoData']).replace('),','),\n// ')) output.write(mol.toSMILES()) output.write(data['adjacencyList']+'\n')