d3tales_api.D3database package

Submodules

d3tales_api.D3database.d3database module

class d3tales_api.D3database.d3database.BackDB(collection_name=None, instance=None, create_hash=False, last_updated=False)[source]

Bases: D3Database

Class for accessing the backend D3TaLES database Copyright 2021, University of Kentucky

__init__(collection_name=None, instance=None, create_hash=False, last_updated=False)[source]
Parameters
  • collection_name – str, name of collection

  • instance – dict, instance to insert or validate

  • create_hash – bool, generate new instance hash id if True

  • last_updated – bool, insert attribute last_updated to instance with the current date and time if True

get_geometry(hash_id)[source]

Get molecule geometry form hash ID

Parameters

hash_id – ID

Returns

molecule geometry sites

class d3tales_api.D3database.d3database.D3Database(database=None, collection_name=None, instance=None, schema_layer='', schema_directory=None, public=None, schema_db=None, default_id=None, validate_schema=True)[source]

Bases: object

Base class for connecting to a database Copyright 2021, University of Kentucky

__init__(database=None, collection_name=None, instance=None, schema_layer='', schema_directory=None, public=None, schema_db=None, default_id=None, validate_schema=True)[source]
Parameters
  • database – str, name of database (should be a key in the DB_INFO_FILE)

  • collection_name – str, name of collection

  • instance – dict, instance to insert or validate

  • schema_layer – str, schema layer

  • schema_directory – str, schema directory

  • public – bool, instance is marked as public if True

  • schema_db – str, database containing schema

  • default_id – str, default instance ID

  • validate_schema – bool, validate schema if True

array_checker(field_path, _id)[source]

Create empty array in filed if this field does not already exists. Prepare for set insertion (avoid duplicates)

Parameters
  • field_path – str, path to check

  • _id – str, instance ID

static dot2dict(dot_dict)[source]

Convert a dotted dictionary to a nested dictionary

Parameters

dot_dict – dotted dictionary

Returns

nested final dictionary

field_checker(entry, field)[source]

Check if field exists and return result or {}

Parameters
  • entry – value

  • field – field name

Returns

{} or the match

insert(_id, nested=False, update_public=True, instance=None, override_lists=False)[source]

Upserts a dictionary into a collection

Parameters
  • _id – str, _id for insertion

  • nested – bool, insert nested attributes if True

  • update_public – bool, update the public status if true

  • instance – dict, instance to be inserted

  • override_lists – bool, override existing lists in insertion if True

make_query(query: Optional[dict] = None, projection: Optional[dict] = None, output='pandas', multi=True, limit=200)[source]

Make MongoDB database query

Parameters
  • query – dict, query

  • projection – dict, projection

  • output – str, output type

  • multi – bool, return multiple query responses if True

  • limit – int, limit to the number of responses the query will return

Returns

  1. A dataframe if output=”pandas”

  2. A list if multi=False and a pymongo dursor if multi=True; output != “pandas

path_insert(_id, path, value)[source]

Insert a piece of data to a specific path, updating array if the path leads to an array

Parameters
  • _id – str, instance ID

  • path – str, path to insertion

  • value – value to insert

class d3tales_api.D3database.d3database.DBconnector(db_information: dict)[source]

Bases: object

Class to retrieve a collection from a database and insert new entry. Requires a db_infos.json file with credentials Copyright 2021, University of Kentucky

__init__(db_information: dict)[source]
Parameters

db_information – dictionary of database info

get_collection(coll_name=None)[source]

Returns a collection from the database

Parameters

coll_name – name of collection

Returns

db.collection

get_database(**kwargs)[source]

Returns a database object

Returns

a database object

class d3tales_api.D3database.d3database.Expflow(collection_name='experimentation', instance=None, create_hash=False)[source]

Bases: D3Database

Class for accessing the ExpFlow experimental database Copyright 2021, University of Kentucky

__init__(collection_name='experimentation', instance=None, create_hash=False)[source]
Parameters
  • collection_name – str, name of collection

  • instance – dict, instance to insert or validate

  • create_hash – bool, generate new instance hash id if True

class d3tales_api.D3database.d3database.FrontDB(schema_layer=None, instance=None, _id=None, smiles=None, group=None, collection_name='base', generate_mol=False, public=None)[source]

Bases: D3Database

Class for accessing the frontend D3TaLES database Copyright 2021, University of Kentucky

__init__(schema_layer=None, instance=None, _id=None, smiles=None, group=None, collection_name='base', generate_mol=False, public=None)[source]
Parameters
  • schema_layer – str, schema layer

  • instance – dict, instance to insert or validate

  • _id – str, default instance ID

  • collection_name – str, name of collection

  • public – bool, instance is marked as public if True

  • smiles – str, SMILES string for a new molecule

  • group – str, origin group for instance

  • generate_mol – bool, generate new molecule instance if True

check_if_in_db()[source]

Check if molecule with object SMILES string exists in the database

Returns

molecule ID if exists, else False

generate_id()[source]

Generate a new molecule ID with origin group

Returns

new molecule ID

class d3tales_api.D3database.d3database.ParamsDB(database='frontend', collection_name=None, instance=None, schema_directory=None, _id=None, update=False)[source]

Bases: D3Database

Class for accessing the parameters D3TaLES database Copyright 2021, University of Kentucky

__init__(database='frontend', collection_name=None, instance=None, schema_directory=None, _id=None, update=False)[source]
Parameters
  • database – str, name of database (should be a key in the DB_INFO_FILE)

  • collection_name – str, name of collection

  • instance – dict, instance to insert or validate

  • schema_directory – str, schema directory

  • _id – str, parameter ID

  • update – bool, create new parameter ID if False

check_id(id_to_check)[source]

Check if parameter ID already exists, create new one if it already exists and object is not set to update Copyright 2021, University of Kentucky

Parameters

id_to_check – parameter ID to check

Returns

parameter ID (checked ID or new ID)

class d3tales_api.D3database.d3database.QueryDB(query: Optional[dict] = None, projection: Optional[dict] = None, collection_name=None, db_file=None, output='pandas', multi=True)[source]

Bases: object

Class to query the database. Use mongoDB style query and projections. Copyright 2021, University of Kentucky

__init__(query: Optional[dict] = None, projection: Optional[dict] = None, collection_name=None, db_file=None, output='pandas', multi=True)[source]
Parameters
  • query – dict, query

  • projection – dict, projection

  • collection_name – str, name of collection

  • db_file – str, database info file

  • output – str, output type

make_query()[source]
Returns

  1. A dataframe if output=”pandas”

  2. A list if multi=False and a pymongo dursor if multi=True; output != “pandas

class d3tales_api.D3database.d3database.RobotStatusDB(apparatus_type: str, _id: Optional[str] = None, instance: Optional[dict] = None, override_lists: bool = True, wflow_name: Optional[str] = None)[source]

Bases: D3Database

Class for accessing the Robot Status database Copyright 2021, University of Kentucky

__init__(apparatus_type: str, _id: Optional[str] = None, instance: Optional[dict] = None, override_lists: bool = True, wflow_name: Optional[str] = None)[source]

Initiate class :param apparatus_type: str, name of apparatus :param _id: str, _id :param instance: dict, instance to insert or validate :param override_lists: bool, :param wflow_name: str, name of active workflow; checks if database instance has appropriate wflow_name if set

check_wflow_name()[source]
property exists
get_prop(prop: str)[source]

Get database prop for instance with _id :param prop: str, property name :return: prop

update_status(new_status, status_name='location')[source]

Update status for a vial location or station vial :param new_status: str, new vial location or new vial in station :param status_name: str, name for status properties

d3tales_api.D3database.dft_calculation_list module

d3tales_api.D3database.dft_calculation_list.calc_tuple_list()[source]

Get list of tuples for Django website dropdowns

Returns

list of tuples

d3tales_api.D3database.dft_calculation_list.calculation_list()[source]

Get list of D3TaLES workflow calculation names

Returns

list of calculations

d3tales_api.D3database.info_from_smiles module

class d3tales_api.D3database.info_from_smiles.GenerateMolInfo(smiles, origin_group='', names=[], extra_info=True, database='frontend', schema_name='mol_info', ground_spin=None, ground_charge=None)[source]

Bases: object

Generate json object for insertion from smiles string Copyright 2021, University of Kentucky

Parameters
  • names – list of names for molecule

  • smiles – smiles string

  • origin_group – which group the molecule comes from

Returns

mol_info class object

__init__(smiles, origin_group='', names=[], extra_info=True, database='frontend', schema_name='mol_info', ground_spin=None, ground_charge=None)[source]
get_mol_info()[source]

Get molecule information

Returns

mol_info as dict

d3tales_api.D3database.info_from_smiles.base64_to_image(base64_str, image_path=None)[source]

Produce python Image object from base 64 string representation of image

Parameters
  • base64_str – base64 string representing image

  • image_path – path for image to be saved (optional)

Returns

python Image object

d3tales_api.D3database.info_from_smiles.find_lowest_e_conf(smiles, num_conf=50)[source]

Find the lowest energy conformer for a molecule with RDKit :param smiles: str, SMILES string :param num_conf: float, number of conformers to serach :return: str, xyz coordinates

d3tales_api.D3database.info_from_smiles.image_to_base64(img)[source]

Produce base 64 string representation of image

Parameters

img – python Image object

Returns

str representing the image

d3tales_api.D3database.restapi module

class d3tales_api.D3database.restapi.D3talesData(username='', password='')[source]

Bases: object

__init__(username='', password='')[source]

This class pulls data from the D3Tales database and outputs plots or Pandas dataframes

Parameters
  • username – D3TaLES website username (must have REST API permissions)

  • password – D3TaLES website password (must have REST API permissions)

get_master_df(master_fn='d3tales_props.csv')[source]

Get all major properties from D3TaLES database.

Parameters

master_fn – str, filepath to CSV file in which to save data

uses the D3database FrontDB module by default, which required the DB_INFO_FILE to be defined to work.

Returns

pandas DataFrame with all data

get_prop_data(query, max_cutoff=None, min_cutoff=None, database='molecules', limit=0)[source]

Get property data from D3TaLES database based on RESTAPI query

Parameters
  • query – str, D3TaLES REST API query

  • max_cutoff – float, maximum value to return for specified property

  • min_cutoff – float, minimum value to return for specified property

  • database – str, name of database to query

  • limit – limit query items to return

Returns

pandas DataFrame with query data

hist_1d(query, **kwargs)[source]

Plot histogram data from D3TaLES database based on RESTAPI query

Parameters

query – str, D3TaLES REST API query

Returns

seaborn histogram plot

hist_2d(query1, query2, db1='molecules', db2='molecules', **kwargs)[source]

Plot histogram data from D3TaLES database based on RESTAPI query

Parameters
  • query1 – str, D3TaLES REST API query for x axis

  • query2 – str, D3TaLES REST API query for y axis

  • db1 – str, name of database for query1

  • db2 – str, name of database for query2

Returns

seaborn 2D histogram plot

rgetkeys(_dict, keys, **kwargs)[source]

Functions for getting property data

Parameters
  • _dict

  • keys

Returns

class d3tales_api.D3database.restapi.RESTAPI(method=None, url='https://d3tales.as.uky.edu', endpoint=None, login_endpoint='login', username='', password='', upload_file=None, params=None, expected_endpoint=None, return_json=False)[source]

Bases: object

__init__(method=None, url='https://d3tales.as.uky.edu', endpoint=None, login_endpoint='login', username='', password='', upload_file=None, params=None, expected_endpoint=None, return_json=False)[source]

Upload a file to through d3tales.as.uky.edu file upload feature.

Parameters
  • method – str, html method (such as post or get)

  • url – str, base url

  • endpoint – str, post or get endpoint url (not containing base url)

  • login_endpoint – str, login url (not containing base url)

  • username – str, user username

  • password – str, user password

  • upload_file – str, path to file to be uploaded

  • params – dict, form parameters for post

  • return_json – bool, get or post method returns json if true

Copyright 2021, University of Kentucky

property cookies
property csrftoken
get_client()[source]
get_process()[source]
post_process()[source]

d3tales_api.D3database.schema2class module

class d3tales_api.D3database.schema2class.Schema2Class(database=None, schema_name=None, schema_directory=None, named_only=False)[source]

Bases: object

Get D3TaLES schema from GitHub and load it to a class Copyright 2021, University of Kentucky

__init__(database=None, schema_name=None, schema_directory=None, named_only=False)[source]
Parameters
  • database – str, database name

  • schema_name – str, schema name

  • schema_directory – str, schema directory

  • named_only – If true, only properties with an actual title attribute will be included in the resulting namespace

md_table(prop_level='properties')[source]

Generate Markdown table for properties in a schema level

Parameters

prop_level – str, schema layer from which to extract table

Returns

text for Markdown table

d3tales_api.D3database.schema2model module

Json Schema to Django Model

d3tales_api.D3database.schema2model.determine_model_name(model_id=None, filename=None)[source]

Get the model name

Parameters
  • model_id – str, model id

  • filename – str, filename

Returns

str, model name

d3tales_api.D3database.schema2model.get_required_string(key_name, required_fields, field_type='string', is_pk_field=False)[source]

Gets the required portion of model field

Parameters
  • is_pk_field

  • field_type

  • key_name

  • required_fields

Returns

str, required model string

d3tales_api.D3database.schema2model.parse_model(json_model, filename)[source]

Convert JSON object into Django model

Parameters
  • json_model – json object containing model

  • filename – filename of model

Returns

str containing Django model

Module contents