from __future__ import division
import olex
import olx
import os
import sys
import OlexVFS
from olexFunctions import OlexFunctions
OV = OlexFunctions()
debug = bool(OV.GetParam('olex2.debug',False))
timer = debug
import glob
global have_found_python_error
have_found_python_error= False
global last_formula
last_formula = ""
global last_element_html
last_element_html = ""
global current_sNum
current_sNum = ""
global unique_selection
unique_selection = ""
haveGUI = OV.HasGUI()
import olexex
import gui
import re
import time
import math
global regex_l
regex_l = {}
global cache
cache = {}
gui_green = OV.GetParam('gui.green')
gui_orange = OV.GetParam('gui.orange')
gui_red = OV.GetParam('gui.red')
gui_grey = OV.GetParam('gui.grey')
grade_1_colour = OV.GetParam('gui.skin.diagnostics.colour_grade1').hexadecimal
grade_2_colour = OV.GetParam('gui.skin.diagnostics.colour_grade2').hexadecimal
grade_3_colour = OV.GetParam('gui.skin.diagnostics.colour_grade3').hexadecimal
grade_4_colour = OV.GetParam('gui.skin.diagnostics.colour_grade4').hexadecimal
import subprocess
class FolderView:
root = None
class node:
name = None
full_name = None
parent = None
content = None
def __init__(self, name, full_name=None):
self.name = name
if full_name:
self.full_name = full_name
else:
self.full_name = name
def toStr(self, prefix=""):
s = prefix+self.name
s += "\n%s" %(self.full_name)
if self.content:
prefix += '\t'
for c in self.content:
s += '\n%s%s' %(prefix,c.toStr(prefix))
return s
def expand(self, mask, fname=""):
self.content = []
if not fname:
fname = self.name
for i in os.listdir(fname):
dn = os.path.normpath(fname + '/' + i)
if os.path.isdir(dn) and i != '.olex':
dr = FolderView.node(i, dn)
dr.expand(mask, dn)
if len(dr.content):
self.content.append(dr)
else:
if( os.path.splitext(i)[1] in mask):
self.content.append(FolderView.node(i, dn))
def list(self, mask=".ins;.res;.cif;.oxm"):
r = OV.GetParam('user.folder_view_root')
if not r:
r = "."
try:
f = olx.ChooseDir('Select folder', '%s' %r)
except RuntimeError:
f = None
if f:
self.root = FolderView.node(f)
self.root.expand(mask=set(mask.split(';')))
olx.html.Update()
def generateHtml(self):
import OlexVFS
if not self.root:
return " "
OV.SetParam('user.folder_view_root', self.root.name)
data = self.root.toStr()
OlexVFS.write_to_olex('folder_view.data', data.encode('utf-8'))
return ""
def loadStructure(self, v):
if os.path.isfile(v):
olex.m("reap '%s'" %v)
fv = FolderView()
olex.registerFunction(fv.list, False, "gui.tools.folder_view")
olex.registerFunction(fv.generateHtml, False, "gui.tools.folder_view")
olex.registerFunction(fv.loadStructure, False, "gui.tools.folder_view")
def start_where():
if olx.IsFileLoaded() == "false":
return
from gui import SwitchPanel
# if olx.xf.au.GetAtomCount() == "0" and olx.IsFileType('ires') == "true":
# SwitchPanel('work')
# flash_gui_control('btn-solve')
# print "Use 'Solve' button in tab 'Work' to solve the structure."
# return
if olx.IsVar('start_where') == 'false':
where = OV.GetParam('user.start_where').lower()
SwitchPanel(where)
olx.SetVar('start_where',False)
olex.registerFunction(start_where, False, "gui.tools")
def flash_gui_control(control, wait=300):
''' Flashes a control on the GUI in order to highlight it's position '''
if ';' in control:
n = int(control.split(';')[1])
control = control.split(';')[0]
else:
n = 2
control_name = "IMG_%s" %control.upper()
if '@' in control:
print "@ in control"
control_image = control.lower().split('@')[0]
else:
control_image = control
if not olx.fs.Exists("%son.png" %control_image):
print "This image %s does not exist. So I can't make it blink" %control_image
return
for i in xrange(n):
if "element" in control:
new_image = "up=%son.png" %control_image
olx.html.SetImage(control_name,new_image)
elif control.endswith('_bg'):
cmd = 'html.setBG(%s,%s)' %(control_image.rstrip('_bg'), OV.GetParam('gui.html.highlight_colour','##ff0000'))
olex.m(cmd)
else:
new_image = "up=%soff.png" %control_image
olx.html.SetImage(control_name,new_image)
OV.Refresh()
olx.Wait(wait)
if "element" in control:
new_image = "up=%soff.png" %control
olx.html.SetImage(control_name,new_image)
elif control.endswith('_bg'):
cmd = 'html.setBG(%s,%s)' %(control.rstrip('_bg'), '#fffff')
olex.m(cmd)
else:
new_image = "up=%shighlight.png" %control_image
olx.html.SetImage(control_name,new_image)
OV.Refresh()
olx.Wait(wait)
if not control.endswith('_bg'):
new_image = "up=%soff.png" %control_image
olx.html.SetImage(control_name,new_image)
olex.registerFunction(flash_gui_control, False, "gui.tools")
def make_single_gui_image(img_txt="", img_type='h2'):
import PilTools
import OlexVFS
TI = PilTools.TI
states = ["on", "off", "highlight", "", "hover", "hoveron"]
alias = img_type
for state in states:
if img_type == "h2":
alias = "h1"
elif img_type == "h1":
alias = img_type
img_type = "h2"
image = TI.make_timage(item_type=alias, item=img_txt, state=state, titleCase=False)
name = "%s-%s%s.png" %(img_type, img_txt.lower(), state)
OlexVFS.save_image_to_olex(image, name, 0)
def inject_into_tool(tool, t, where, befaf='before'):
import OlexVFS
txt = OlexVFS.read_from_olex('%s/%s' %(OV.BaseDir(),tool))
if befaf == 'before':
txt = txt.replace(where, "%s%s" %(t, where))
else:
txt = txt.replace(where, "%s%s" %(where, t))
OlexVFS.write_to_olex('%s/%s' %(OV.BaseDir(), tool),txt)
def __inject_into_tool(tool, t, where,befaf='before'):
import OlexVFS
txt = OlexVFS.read_from_olex('%s/%s' %(OV.BaseDir(),tool))
if befaf == 'before':
txt = txt.replace(where, "%s%s" %(t, where))
else:
txt = txt.replace(where, "%s%s" %(where, t))
OlexVFS.write_to_olex('%s%s' %(OV.BaseDir(), tool), u, txt)
def add_tool_to_index(scope="", link="", path="", location="", before="", filetype="", level="h2", state="2", image="", onclick=""):
import OlexVFS
if not OV.HasGUI:
return
if not scope:
return
if not link:
return
if not path:
return
''' Automatically add a link to GUI to an Olex2 index file. '''
if not location:
location = OV.GetParam('%s.gui.location' %scope)
if not before:
before = OV.GetParam('%s.gui.before' %scope)
if not location:
return
_ = r"%s/%s" %(OV.BaseDir(), location)
if os.path.exists(_):
file_to_write_to = _
else:
file_to_write_to = r'%s/etc/gui/blocks/index-%s.htm' %(OV.BaseDir().replace(r"//","/"), location)
if not os.path.exists(file_to_write_to):
print "This location does not exist: %s" %file_to_write_to
file_to_write_to = '%s/etc/gui/blocks/index-%s.htm' %(OV.BaseDir().replace(r"//","/"), "tools")
before = "top"
file_to_write_to = file_to_write_to.replace(r"//","/")
txt = OlexVFS.read_from_olex(file_to_write_to)
if onclick:
OlexVFS.write_to_olex('%s/%s.htm' %(path, link), "")
if not filetype:
t = r'''
''' %(level, location, scope, link, path, link, image, onclick, state)
else:
t = r'''
''' %(filetype, level, location, scope, link, path, link, image, onclick, state)
index_text = ""
if t not in txt:
if before.lower() == "top":
u = "%s\n%s" %(t, txt)
elif before not in txt or before.lower() == "end":
u = "%s\n%s" %(txt, t)
else:
u = ""
for line in txt.strip().split("\r\n"):
if not line:
continue
li = line
if r""
OV.registerFunction(makeFormulaForsNumInfo)
def make_cell_dimensions_display():
t1 = time.time()
global current_sNum
#if OV.FileName() == current_sNum:
#return ""
l = ['a', 'b', 'c', 'alpha', 'beta', 'gamma']
d = {}
for x in l:
val = olx.xf.uc.CellEx(x)
if "90.0" in val and "(" in val or '90(' in val and not "." in val:
help_txt = "Help from File does not exist. Apologies."
help = '''
$spy.MakeHoverButton('btn-info@cell@%s',"spy.make_help_box -name=cell-not-quite-90 -popout='False' -helpTxt='%s'")''' %(x, help_txt)
_ = os.sep.join([OV.BaseDir(), "etc", "gui", "help", "cell_angle_not_quite_90.htm"])
if os.path.exists(_):
help_txt = open(_,'r').read()
href = "spy.make_help_box -name=cell-angle-not-quite-90 -popout=False -helpTxt='%s'" %help_txt
val = '%s' %(href, OV.GetParam('gui.red').hexadecimal, val)
d[x] = val
d['volume'] = olx.xf.uc.VolumeEx()
d['Z'] = olx.xf.au.GetZ()
d['Zprime'] = olx.xf.au.GetZprime()
t = '''
a = %(a)s
α = %(alpha)s°
Z = %(Z)s
b = %(b)s
β = %(beta)s°
Z' = %(Zprime)s
c = %(c)s
γ = %(gamma)s°
V = %(volume)s
''' %d
OV.write_to_olex('celldimensiondisplay.htm', t)
#if debug:
#print "Cell: %.5f" %(time.time() - t1)
return ""
OV.registerFunction(make_cell_dimensions_display,True,"gui.tools")
def weightGuiDisplay_new():
if olx.IsFileType('ires').lower() == 'false':
return ''
longest = 0
retVal = ""
current_weight = olx.Ins('weight')
if current_weight == "n/a": return ""
current_weight = current_weight.split()
if len(current_weight) == 1:
current_weight = [current_weight[0], '0']
length_current = len(current_weight)
suggested_weight = OV.GetParam('snum.refinement.suggested_weight')
if suggested_weight is None: suggested_weight = []
if len(suggested_weight) < length_current:
for i in xrange (length_current - len(suggested_weight)):
suggested_weight.append(0)
if suggested_weight:
for curr, sugg in zip(current_weight, suggested_weight):
curr = float(curr)
if curr-curr*0.01 <= sugg <= curr+curr*0.01:
colour = gui_green
elif curr-curr*0.1 < sugg < curr+curr*0.1:
colour = gui_orange
else:
colour = gui_red
sign = "▲"
if curr-sugg == 0:
sign = ""
sugg = 0
elif curr-sugg > 0:
sign = "▼"
retVal += "%.3f %s | " %(curr, colour, sign)
html_scheme = retVal.strip("| ")
else:
html_scheme = current_weight
wght_str = ""
for i in suggested_weight:
wght_str += " %.3f" %i
txt_tick_the_box = OV.TranslatePhrase("Tick the box to automatically update")
html = "%s" %html_scheme
return html
OV.registerFunction(weightGuiDisplay_new,True,"gui.tools")
def weightGuiDisplay():
if olx.IsFileType('ires').lower() == 'false':
return ''
html_scheme = ""
tol_green, tol_orange = 0.01, 0.1
current_weight = olx.Ins('weight')
if current_weight == "n/a": return ""
current_weight = current_weight.split()
if len(current_weight) == 1:
current_weight = [current_weight[0], '0']
length_current = len(current_weight)
suggested_weight = OV.GetParam('snum.refinement.suggested_weight')
if suggested_weight is None: suggested_weight = []
if len(suggested_weight) < length_current:
for i in xrange (length_current - len(suggested_weight)):
suggested_weight.append(0)
if suggested_weight:
for curr, sugg in zip(current_weight, suggested_weight):
curr = float(curr)
if curr < 1:
prec = 3
elif curr < 10:
prec = 2
elif curr < 100:
prec = 1
else:
prec = 0
if sugg >= curr*(1-tol_green) and sugg <= curr*(1+tol_green):
colour = gui_green
elif sugg >= curr*(1-tol_orange) and sugg <= curr*(1+tol_orange):
colour = gui_orange
else:
colour = gui_red
_ = "%%.%sf"%prec
curr = (_ %curr).lstrip('0')
sugg = (_ %sugg).lstrip('0')
if html_scheme:
html_scheme += "| "
html_scheme += "%s(%s)" %(colour, curr, sugg)
else:
html_scheme = current_weight
html_scheme= "%s"%html_scheme
txt_tick_the_box = OV.TranslatePhrase("Tick the box to automatically update")
txt_Weight = OV.TranslatePhrase("Weight")
html = '''
%s
''' %("Update Weighting Scheme", html_scheme)
return html
OV.registerFunction(weightGuiDisplay,True,"gui.tools")
def number_non_hydrogen_atoms():
return sum(atom['occu'][0] for atom in self.atoms() if atom['type'] not in ('H','Q'))
def getExpectedPeaks():
orm = olexex.OlexRefinementModel()
return orm.getExpectedPeaks()
def refine_extinction():
retVal = ""
_ = olx.xf.rm.Exti()
if "n/a" not in _.lower() and _ != '0':
if "(" in _:
_ = _.split('(')
exti = _[0]
esd = _[1].rstrip(')')
exti_f = float(exti)
_ = len(exti) - len(esd) -2
esd_f = float("0.%s%s" %(_*"0", esd))
else:
exti = _
esd = ""
OV.SetParam('snum.refinement.refine_extinction',1)
OV.SetParam('snum.refinement.refine_extinction_tickbox', True)
retVal = "%s(%s)"%(exti,esd)
else:
OV.SetParam('snum.refinement.refine_extinction',0)
OV.SetParam('snum.refinement.refine_extinction_tickbox', False)
return retVal
### The stuff below needs careful thinking about. For now, revert back to simple on/off operation. Sorry Guys!
## snmum.refine_extinction 0: DO NOT refine extinction AGAIN
## snmum.refine_extinction 1: Try and refine extinction
## snmum.refine_extinction 2: Refine in any case
#if getExpectedPeaks() > 2:
#OV.SetParam('snum.refinement.refine_extinction',1)
#return "Not Tested"
#retVal = "n/a"
#_ = olx.xf.rm.Exti()
#if "n/a" not in _.lower() and _ != '0':
#_ = _.split('(')
#exti = _[0]
#esd = _[1].rstrip(')')
#exti_f = float(exti)
#_ = len(exti) - len(esd) -2
#esd_f = float("0.%s%s" %(_*"0", esd))
#_ = OV.GetParam('snum.refinement.refine_extinction',1)
#if _ == 3:
#retVal = "%s(%s)"%(exti,esd)
#retVal += "* " %gui_green
#if _ == 0:
#OV.SetParam('snum.refinement.refine_extinction_tickbox',False)
#retVal="not refined* " %gui_red
#else:
#OV.SetParam('snum.refinement.refine_extinction_tickbox', True)
#if exti_f/esd_f < 2:
#print "Extinction was refined to %s(%s). From now on, it will no longer be refined, unless you tick the box in the refinement settings" %(exti, esd)
#OV.SetParam('snum.refinement.refine_extinction',1)
#olex.m("DelIns EXTI")
#retVal = "%s(%s)"%(exti,esd)
#else:
#retVal = "%s(%s)"%(exti,esd)
#else:
#if OV.GetParam('snum.refinement.refine_extinction_tickbox'):
#olex.m("AddIns EXTI")
#return retVal
OV.registerFunction(refine_extinction,True,"gui.tools")
def hasDisorder():
olx_atoms = olexex.OlexRefinementModel()
parts = olx_atoms.disorder_parts()
if not parts:
return False
else:
sp = set(parts)
if len(sp) == 1 and 0 in sp:
return False
else:
return True
OV.registerFunction(hasDisorder,False,'gui.tools')
def show_unique_only():
global unique_selection
if OV.GetParam('user.parts.keep_unique') == True:
make_unique(add_to=True)
if unique_selection:
olex.m('Sel -u')
olx.Uniq()
olx.Sel(unique_selection)
olx.Uniq()
OV.registerFunction(show_unique_only,False,'gui.tools')
def make_unique(add_to=False):
global unique_selection
if not unique_selection:
add_to = True
if add_to:
olex.m('sel -a')
_ = " ".join(scrub('Sel'))
_ = _.replace('Sel',' ')
while " " in _:
_ = _.replace(" ", " ").strip()
_l = _.split()
if _:
if add_to and unique_selection:
_l += unique_selection.split()
_l = list(set(_l))
unique_selection = " ".join(_l)
olx.Sel(unique_selection)
olx.Uniq()
OV.registerFunction(make_unique,False,'gui.tools')
def sel_part(part,sel_bonds=True):
select = OV.GetParam('user.parts.select')
if not select:
return
else:
olex.m("sel part %s" %part)
if sel_bonds:
olex.m("sel bonds where xbond.a.selected==true||xbond.b.selected==true")
OV.registerFunction(sel_part,False,'gui.tools')
def make_disorder_quicktools(scope='main', show_options=True):
import olexex
parts = set(olexex.OlexRefinementModel().disorder_parts())
select = OV.GetParam('user.parts.select')
parts_display = ""
sel = ""
for item in parts:
_ = None
d = {}
if item == 0:
continue
#item = ' '.join(str(s) for s in parts)
#d['part'] = "All"
else:
d['part'] = item
d['parts'] = item
if select:
sel = ">>sel part %s" %item
parts_display += gui.tools.TemplateProvider.get_template('part_0_and_n', force=debug)%d
d={'parts_display':parts_display, 'scope':scope}
if show_options:
retVal = gui.tools.TemplateProvider.get_template('disorder_quicktool', force=debug)%d
else:
retVal = gui.tools.TemplateProvider.get_template('disorder_quicktool_no_options', force=debug)%d
return retVal
OV.registerFunction(make_disorder_quicktools,False,'gui.tools')
def deal_with_gui_phil(action):
skin_name = OV.GetParam('gui.skin.name', 'default')
skin_extension = OV.GetParam('gui.skin.extension', None)
gui_phil_path = "%s/gui.phil" %(OV.DataDir())
if action == 'load':
OV.SetHtmlFontSize()
OV.SetHtmlFontSizeControls()
olx.gui_phil_handler.reset_scope('gui')
gui_skin_phil_path = "%s/etc/skins/%s.phil" %(OV.BaseDir(), skin_name)
if not os.path.isfile(gui_skin_phil_path):
gui_skin_phil_path = "%s/gui.params" %(OV.BaseDir())
if os.path.isfile(gui_skin_phil_path):
gui_skin_phil_file = open(gui_skin_phil_path, 'r')
gui_skin_phil = gui_skin_phil_file.read()
gui_skin_phil_file.close()
olx.gui_phil_handler.update(phil_string=gui_skin_phil)
if skin_extension:
gui_skin_phil_path = "%s/etc/skins/%s.phil" %(OV.BaseDir(), skin_extension)
if os.path.isfile(gui_skin_phil_path):
gui_skin_phil_file = open(gui_skin_phil_path, 'r')
gui_skin_phil = gui_skin_phil_file.read()
gui_skin_phil_file.close()
olx.gui_phil_handler.update(phil_string=gui_skin_phil)
else:
olx.gui_phil_handler.save_param_file(
file_name=gui_phil_path, scope_name='gui', diff_only=True)
def get_regex_l(src_file):
global regex_l
if not src_file:
return False
#if not src_file in regex_l:
re_l = []
l = open(src_file, 'r').readlines()
for item in l:
item = item.strip()
if item.startswith('#') or not item:
continue
item_l = item.split("::")
find = item_l[0].strip().strip("%%")
replace = item_l[1].strip()
re_l.append((find,replace))
regex_l.setdefault('%s'%src_file,re_l)
return regex_l[src_file]
def run_regular_expressions(txt, src_file=None, re_l=None, specific=""):
try:
global regex_l
if not re_l:
re_l = get_regex_l(src_file)
if timer:
t_timer=time.time()
for pair in re_l:
if specific:
if pair[0] != specific:
continue
regex = re.compile(r"%s" %pair[0], re.X|re.M|re.S|re.U)
replace = pair[1].strip("'")
replace = pair[1].strip('"')
try:
txt = regex.sub(r"%s" %replace, txt)
except Exception, err:
print err
if timer:
print_timer(tt, t_timer, pad=" ", sep="..")
except Exception:
if debug:
PrintException()
finally:
return txt
class LogListen():
def __init__(self):
self.printed = []
OV.registerCallback("onlog", self.onListen)
def onListen(self, txt):
self.printed.append(txt)
def endListen(self):
OV.unregisterCallback("onlog", self.onListen)
l = []
for item in self.printed:
item = item.split('\r\n')
for tem in item:
if type(tem) == unicode:
l.append(tem)
else:
for em in tem:
l.append(em)
return l
class Templates():
def __init__(self):
self.templates = {}
self.get_all_templates()
def get_template(self, name, force=debug, path=None, mask="*.*", marker='{-}'):
'''
Returns a particular template from the Template.templates dictionary. If it doesn't exist, then it will try and get it, and return a 'not found' string if this does not succeed.
-- if force==True, then the template will be reloaded
-- if path is provided, then this location will also be searched.
'''
retVal = self.templates.get(name, None)
if not retVal or force:
self.get_all_templates(path=path, mask=mask, marker=marker)
retVal = self.templates.get(name, None)
if not retVal:
return "Template %s has not been found."%name
else:
return retVal
def get_all_templates(self, path=None, mask="*.*", marker='{-}'):
'''
Parses the path for template files.
'''
if not path:
path = os.sep.join([OV.BaseDir(), 'util', 'pyUtil', 'gui', 'templates'])
if path[-4:-3] != ".": #i.e. a specific template file has been provided
g = glob.glob("%s%s%s" %(path,os.sep,mask))
else:
g = [path]
_ = os.sep.join([OV.DataDir(), 'custom_templates.html'])
if os.path.exists(_): g.append(_)
for f_path in g:
fc = open(f_path, 'r').read()
if not self._extract_templates_from_text(fc,marker=marker):
name = os.path.basename(os.path.normpath(f_path))
self.templates[name] = fc
#for name in self.templates:
#OlexVFS.write_to_olex(name, self.templates[name])
def _extract_templates_from_text(self, t, marker):
mark = marker.split('-')
regex = re.compile(r't:(.*?)\%s(.*?)\%s' %(mark[0], mark[1]),re.DOTALL)
m=regex.findall(t)
if m:
for item in m:
name = item[0]
content = item[1]
self.templates[name] = content
return True
else:
return False
TemplateProvider = Templates()
def get_diagnostics_colour(scope, item, val):
try:
val = float(val)
if "shift" in item:
if val < 0:
val = -val
except:
val = 0
mindfac = 1
if item == 'MinD':
mindfac = float(olx.xf.exptl.Radiation())/0.71
op = OV.GetParam('user.diagnostics.%s.%s.op' %(scope, item))
if op == "between":
soll = OV.GetParam('user.diagnostics.%s.%s.soll' %(scope, item))
for i in xrange(4):
i += 1
if op == "greater":
if val >= OV.GetParam('user.diagnostics.%s.%s.grade%s' %(scope, item, i)) * mindfac:
break
elif op == 'smaller':
if val <= OV.GetParam('user.diagnostics.%s.%s.grade%s' %(scope, item, i)) * mindfac:
break
elif op == 'between':
if val - (OV.GetParam('user.diagnostics.%s.%s.grade%s' %(scope, item, i))) * mindfac <= soll <= val + (OV.GetParam('user.diagnostics.%s.%s.grade%s' %(scope, item, i))) * mindfac:
break
if i == 1:
retVal = grade_1_colour
elif i == 2:
retVal = grade_2_colour
elif i == 3:
retVal = grade_3_colour
elif i == 4:
retVal = grade_4_colour
return retVal
def GetRInfo(txt="",format='html'):
if not OV.HasGUI():
return
t = "ERROR!"
use_history_for_R1_display = True
if use_history_for_R1_display:
if olx.IsFileType('cif') == "true":
R1 = olx.Cif('_refine_ls_R_factor_gt')
wR2 = olx.Cif('_refine_ls_wR_factor_ref')
else:
R1 = OV.GetParam('snum.refinement.last_R1')
wR2 = OV.GetParam('snum.refinement.last_wR2')
if not R1:
tree = History.tree
if tree.active_node is not None:
R1 = tree.active_node.R1
else:
R1 = 'n/a'
if R1 == cache.get('R1', None) and wR2 == cache.get('wR2', None):
return cache.get('GetRInfo', 'XXX')
cache['R1'] = R1
cache['wR2'] = wR2
font_size_R1 = olx.GetVar('HtmlFontSizeExtraLarge')
font_size_wR2 = olx.GetVar('HtmlFontSizeMedium')
if 'html' in format:
try:
R1 = float(R1)
col_R1 = gui.tools.get_diagnostics_colour('refinement','R1', R1)
R1 = "%.2f" %(R1*100)
wR2 = float(wR2)
col_wR2 = gui.tools.get_diagnostics_colour('refinement','wR2', wR2)
wR2 = "%.2f" %(wR2*100)
if 'report' in format:
t = r"%s%%" %(font_size, col_wR2, R2)
t += r"%s%%" %(font_size, col_R1, R1)
else:
d = {
'R1':R1,
'wR2':wR2,
'font_size_R1':font_size_R1,
'font_size_wR2':font_size_wR2,
'font_size_label':str(int(font_size_wR2) - 1),
'font_colour_R1':col_R1,
'font_colour_wR2':col_wR2,
'grey':gui_grey
}
t =gett('R_factor_display')%d
except:
t = "
%s
" %(font_size_R1, R1)
finally:
retVal = t
elif format == 'float':
try:
t = float(R1)
except:
t = 0
finally:
retVal = t
else:
if txt:
t = "