Skip to content

Commit

Permalink
fixing some phil logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Oeffner committed May 22, 2019
1 parent 2b19fb7 commit 61d1df1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 42 deletions.
68 changes: 39 additions & 29 deletions crys3d/hklview/cmdlineframes.py
Expand Up @@ -238,11 +238,9 @@ def __init__ (self, *args, **kwds) :
kwds['settings'] = self.settings
kwds['mprint'] = self.mprint
self.viewer = view_3d.hklview_3d( **kwds )
self.master_phil = libtbx.phil.parse( masterphilstr )
self.params = self.master_phil.fetch().extract()
self.ResetPhilandViewer()
self.NewFileLoaded = False
self.infostr = ""

self.useSocket=False
if kwds.has_key('useSocket'):
self.useSocket = kwds['useSocket']
Expand All @@ -261,45 +259,64 @@ def zmq_listen(self):
philstr = self.socket.recv()
philstr = str(philstr)
self.mprint("Received phil string:\n" + philstr)
new_phil = self.GetNewPhilString(philstr)
new_phil = libtbx.phil.parse(philstr)
self.update_settings(new_phil)
#print "in zmq listen"
time.sleep(1)
del self.socket


def ResetPhilandViewer(self, extraphil=None):
self.master_phil = libtbx.phil.parse( masterphilstr )
self.currentphil = self.master_phil
if extraphil:
self.currentphil = self.currentphil.fetch(source = extraphil)
self.params = self.currentphil.fetch().extract()
self.viewer.miller_array = None
self.viewer.proc_arrays = []


def GetNewCurrentPhilFromString(self, philstr, oldcurrentphil):
user_phil = libtbx.phil.parse(philstr)
newcurrentphil = oldcurrentphil.fetch(source = user_phil)
diffphil = oldcurrentphil.fetch_diff(source = user_phil)
return newcurrentphil, diffphil


def GetNewCurrentPhilFromPython(self, pyphilobj, oldcurrentphil):
newcurrentphil = oldcurrentphil.fetch(source = pyphilobj)
diffphil = oldcurrentphil.fetch_diff(source = pyphilobj)
return newcurrentphil, diffphil


def SetCurrentPhilAsPython(self, pyphil):
newphil = master_phil.format(python_object= pyphil)
currphil = master_phil.fetch(source = newphil)


def update_settings(self, new_phil=None):
if not new_phil:
new_phil = self.master_phil.format(python_object = self.params)
else:
current_phil = self.master_phil.format(python_object = self.params)
working_phil = self.master_phil.fetch(sources = [new_phil, current_phil] )
#print "in update_settings"
diff = None
# try:

working_phil = self.master_phil.fetch(source = new_phil)
diff_phil = self.master_phil.fetch_diff(source = working_phil)
self.currentphil, diff_phil = self.GetNewCurrentPhilFromPython(new_phil, self.currentphil)
diff = None
if len(diff_phil.all_definitions()) < 1:
self.mprint( "Nothing's changed")
return False

#import code, traceback; code.interact(local=locals(), banner="".join( traceback.format_stack(limit=10) ) )
diff = diff_phil.extract().NGL_HKLviewer
self.mprint("diff phil:\n" + diff_phil.as_str() )

self.master_phil = working_phil
self.params = working_phil.extract()
self.params = self.currentphil.extract()
phl = self.params.NGL_HKLviewer

if hasattr(diff, "filename"):
self.ResetPhilandViewer(diff_phil)
self.load_reflections_file(phl.filename)

if hasattr(diff, "column") or hasattr(diff, "fomcolumn") \
or hasattr(diff, "mergedata") or hasattr(diff, "columnbinthresholds"):
print "mergedata in updatesettings: " , self.params.NGL_HKLviewer.mergedata
#print "mergedata in updatesettings: " , self.params.NGL_HKLviewer.mergedata
if self.set_column(phl.column, phl.fomcolumn):
self.set_column_bin_thresholds(phl.columnbinthresholds, phl.binarray)

Expand All @@ -312,9 +329,6 @@ def update_settings(self, new_phil=None):
if hasattr(diff, "viewer"):
self.viewer.settings = phl.viewer
self.settings = phl.viewer
#except Exception, e :
# print to_str(e)
# sys.exit(-42)

msg = self.viewer.update_settings()
self.mprint( msg)
Expand Down Expand Up @@ -384,7 +398,7 @@ def process_miller_array (self, array, merge_answer=[None]) :
philstr = self.socket.recv()
philstr = str(philstr)
self.mprint("process_miller_array, Received phil:\n" + philstr)
new_phil = self.GetNewPhilString(philstr)
new_phil = libtbx.phil.parse(philstr)
#working_phil = self.master_phil.fetch(source = new_phil)
params = new_phil.extract().NGL_HKLviewer
if hasattr(params, "mergedata"): # awaiting user to tick a checkbox on the gui
Expand Down Expand Up @@ -443,7 +457,7 @@ def set_miller_array (self, array) :
# details=array_info.details_str, valid_arrays=self.valid_arrays)


def update_space_group_choices (self) :
def update_space_group_choices(self) :
from cctbx.sgtbx.subgroups import subgroups
from cctbx import sgtbx
sg_info = self.miller_array.space_group_info()
Expand Down Expand Up @@ -493,7 +507,7 @@ def load_reflections_file(self, file_name, set_array=True, data_only=False):
if (file_name != ""):
from iotbx.reflection_file_reader import any_reflection_file
self.viewer.isnewfile = True
self.params.NGL_HKLviewer.mergedata = None
#self.params.NGL_HKLviewer.mergedata = None
self.viewer.iarray = 0
self.viewer.icolourcol = 0
self.viewer.iradiicol = 0
Expand Down Expand Up @@ -616,11 +630,13 @@ def set_column(self, column, fomcolumn=None) :
self.viewer.icolourcol = column
self.viewer.iradiicol = column
if self.valid_arrays[column].is_complex_array():
if fomcolumn:
if fomcolumn and self.valid_arrays[fomcolumn].is_real_array():
self.viewer.mapcoef_fom_dict[self.valid_arrays[column].info().label_string()] = fomcolumn
self.mprint("Using array %d as FOM values for array %d" %(fomcolumn, column))
else:
if self.viewer.mapcoef_fom_dict.get(self.valid_arrays[column].info().label_string()):
del self.viewer.mapcoef_fom_dict[self.valid_arrays[column].info().label_string()]
self.mprint("No valid FOM array provided.")
self.set_miller_array(self.valid_arrays[column])
if (self.miller_array is None) :
raise Sorry("No data loaded!")
Expand Down Expand Up @@ -689,12 +705,6 @@ def SetColoursToPhases(self, val):
self.update_settings()


def GetNewPhilString(self, philstr):
user_phil = libtbx.phil.parse(philstr)
new_phil = self.master_phil.fetch(source = user_phil)
return new_phil
#import code, traceback; code.interact(local=locals(), banner="".join( traceback.format_stack(limit=10) ) )


def GetSpaceGroupChoices(self):
"""
Expand Down
28 changes: 15 additions & 13 deletions crys3d/hklview/jsview_3d.py
Expand Up @@ -35,11 +35,11 @@ def __init__(self, millarr, mprint=sys.stdout.write):
data = millarr.sigmas()
self.maxsigmas =max( data )
self.minsigmas =min( data )
self.minmaxstr = "MinMaxValues:[%s; %s], MinMaxSigmaValues:[%s; %s]" \
self.minmaxstr = "MinMax:[%s; %s], MinMaxSigs:[%s; %s]" \
%(roundoff(self.mindata), roundoff(self.maxdata), \
roundoff(self.minsigmas), roundoff(self.maxsigmas))
else:
self.minmaxstr = "MinMaxValues:[%s; %s]" %(roundoff(self.mindata), roundoff(self.maxdata))
self.minmaxstr = "MinMax:[%s; %s]" %(roundoff(self.mindata), roundoff(self.maxdata))
self.labels = self.desc = ""
#import code, traceback; code.interact(local=locals(), banner="".join( traceback.format_stack(limit=10) ) )
if millarr.info():
Expand All @@ -58,7 +58,7 @@ def __init__(self, millarr, mprint=sys.stdout.write):
issymunique = millarr.is_unique_set_under_symmetry()
self.infotpl = (self.labels, self.desc, millarr.indices().size(), self.span,
self.minmaxstr, roundoff(dmin), roundoff(dmax), issymunique )
self.infostr = "%s (%s), %s %s, %s, d_min_max: %s, %s, Symmetry unique: %d" % self.infotpl
self.infostr = "%s (%s), %s %s, %s, d_minmax: %s, %s, SymUnique: %d" % self.infotpl


class hklview_3d:
Expand All @@ -85,6 +85,9 @@ def __init__ (self, *args, **kwds) :
self.matchingarrayinfo = []
self.binstrs = []
self.mapcoef_fom_dict = {}
self.verbose = True
if kwds.has_key('verbose'):
self.verbose = kwds['verbose']
self.mprint = sys.stdout.write
if kwds.has_key('mprint'):
self.mprint = kwds['mprint']
Expand Down Expand Up @@ -142,11 +145,11 @@ def __exit__(self, exc_type, exc_value, traceback):


def set_miller_array(self, miller_array, merge=None, details="", proc_arrays=[]) :
if (miller_array is None):
return
self.miller_array = miller_array
self.proc_arrays = proc_arrays
self.merge = merge
if (miller_array is None):
return
self.d_min = miller_array.d_min()
array_info = miller_array.info()
self.binvals = [ 1.0/miller_array.d_max_min()[0], 1.0/miller_array.d_max_min()[1] ]
Expand Down Expand Up @@ -736,15 +739,14 @@ def data2bin(d):
fomlp = lp + wp
fomwp = wp3
fomtop2 = fomtop - 13
// print the FOM label
addDivBox("%s", fomtop, fomlp, fomwp, 20);
// print the 3 numbers
// print the 1 number
addDivBox("1", fomtop2, fomlp, fomwp, 20)
// print the 0.5 number
leftp = fomlp + 0.48 * gl * colourgradvalarray.length
addDivBox("0.5", fomtop2, leftp, fomwp, 20)
// print the FOM label
addDivBox("%s", fomtop, leftp, fomwp, 20);
// print the 0 number
leftp = fomlp + 0.96 * gl * colourgradvalarray.length
addDivBox("0", fomtop2, leftp, fomwp, 20)
}
Expand Down Expand Up @@ -862,7 +864,7 @@ def data2bin(d):
def OnConnectWebsocketClient(self, client, server):
#if not self.websockclient:
self.websockclient = client
self.mprint( "Browser connected:" + str( self.websockclient ) )
self.mprint( "Browser connected:" + str( self.websockclient ), self.verbose )
#else:
# self.mprint( "Unexpected browser connection was rejected" )

Expand Down Expand Up @@ -941,7 +943,7 @@ def OpenBrowser(self):
with open(self.hklfname, "w") as f:
f.write( htmlstr )
self.url = "file://" + os.path.abspath( self.hklfname )
self.mprint( "Writing %s and connecting to its websocket client" %self.hklfname )
self.mprint( "Writing %s and connecting to its websocket client" %self.hklfname, self.verbose )
if self.UseOSBrowser:
webbrowser.open(self.url, new=1)
self.isnewfile = False
Expand Down

0 comments on commit 61d1df1

Please sign in to comment.