To Do:

  1. find a method to convert dict of lists to list of dicts .. post pone for now
  2. clean up data in API
  3. think of collections of data for API: ReferenceExperiment, Precisions_Kpoints_and_Values
  4. multiple window plotting for bokeh
  5. integration of Shiny app like Pade manipulation feature

In [ ]:
# for azure notebook
# !conda install pandas numpy bokeh=0.12.4 requests

In [1]:
# API connection stuff
import requests
import json

In [2]:
# Data management pandas and numpy
import pandas as pd
import numpy as np

In [3]:
# general system management
import os
from glob import glob

In [4]:
# bokeh packages
import bokeh
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox, column
from bokeh.models import Select, Div, Column, HoverTool, ColumnDataSource, Button, CheckboxButtonGroup
from bokeh.models.widgets import RangeSlider
from bokeh.plotting import figure

In [5]:
bokeh.__version__


Out[5]:
'0.12.4'

In [6]:
# plotting package matplotlib
import matplotlib.pyplot as plt
%matplotlib inline

In [36]:
# function to manage query requests
def dict_to_api(query_dict):
    """
    simple version of single value to dict query
    """
    r = requests.post(url='http://0.0.0.0:5900/bench/v1/query',data=json.dumps(query_dict))
    ListOfDicts = r.json()['content']
    return pd.concat([pd.DataFrame({k:[ld[k]] for k in list(ld.keys())}) for ld in ListOfDicts])

def user_to_dict(query):
    """
    breaks up the user query into single value dicts for the api query
    Example: {'code':['VASP','DMol3'],'exchange':['PBE','LDA'], 'element':['Ag'],'structure':['fcc','bcc','hcp'] }
    """
    new_query_template = {key:[] for key in query}
    ListOfDicts = []
    
    for k in new_query_template:
        new_query = new_query_template
        for v in query[k]:
            
            new_query[k].append(v[0])
        for j in new_query_template:
            
            new_query[k].append(query[k][0])
            print (new_query)
    # let's say 3 keys, 2 values each
    # means 6 single value dicts 
    # 

    
    #multiple_value_keys = [k for k in query if len(query[k])>1]
    #single_value_keys = [k for k in query if len(query[k])==1]
    #print (multiple_value_keys, single_value_keys)
    #matrix_of_queries = []

In [34]:
# testing for multiple value comparison plot user requests - NOT DONE yet
user_to_dict({'code':['VASP','DMol3'],'exchange':['PBE','LDA'], 'element':['Ag','Au'],'structure':['fcc','bcc'] })


{'code': ['VASP'], 'exchange': [], 'element': [], 'structure': []}
{'code': ['VASP'], 'exchange': ['PBE'], 'element': [], 'structure': []}
{'code': ['VASP'], 'exchange': ['PBE'], 'element': ['Ag'], 'structure': []}
{'code': ['VASP'], 'exchange': ['PBE'], 'element': ['Ag'], 'structure': ['fcc']}

In [38]:
user_request1 = dict_to_api({'code':'VASP','exchange':'PBE','element':'Au','structure':'hcp','properties':'B'})

In [41]:
user_request2 = dict_to_api({'code':'DMol3','exchange':'PBE','element':'Au','structure':'fcc','properties':'B'})

Widget testing


In [46]:
plot_data = {'x':np.unique(user_request1['k-point']), 'y': np.unique(user_request1['precision'])}

In [48]:
p = figure()

In [49]:
p.circle(plot_data['x'], plot_data['y'][0:len(plot_data['x'])])


Out[49]:
GlyphRenderer(
id = '33fdf1fd-a4e5-4b3f-a958-70d252a70ce1', …)

In [52]:
from bokeh.plotting import show

In [54]:
show(p)

In [58]:
R = RangeSlider(title='Choice',start=0,end=10,step=0.1)

In [59]:
show(R)

In [ ]: