orsopy.slddb package

Package for a database of Scattering Length Density data (SLD) for neutron and x-ray scattering. The query to the DB includes recalculation of SLD for needed radiation.

Part of ORSO initiative, see: https://www.reflectometry.org/

Contributers:

Artur Glavic <artur.glavic@psi.ch>

Subpackages

Submodules

orsopy.slddb.comparators module

Classes to represent comparisons in SQLite queries.

class orsopy.slddb.comparators.Comparator(value, key=None)[source]

Bases: ABC

abstract query_string()[source]

Return the SQL query string used when searching. Should contain one question mark for each argument that is used.

abstract query_args()[source]

Return the arguments used for the query. The number of arguments should be equal to the number of question marks returned by query_string.

class orsopy.slddb.comparators.GenericComparator(value, key=None)[source]

Bases: Comparator

Comparator used for the generic case. Makes a simple comparison based on the type of the argument.

query_string()[source]

Return the SQL query string used when searching. Should contain one question mark for each argument that is used.

query_args()[source]

Return the arguments used for the query. The number of arguments should be equal to the number of question marks returned by query_string.

class orsopy.slddb.comparators.ExactString(value, key=None)[source]

Bases: Comparator

Perform an exact string comparison.

query_string()[source]

Return the SQL query string used when searching. Should contain one question mark for each argument that is used.

query_args()[source]

Return the arguments used for the query. The number of arguments should be equal to the number of question marks returned by query_string.

class orsopy.slddb.comparators.FormulaComparator(value, key=None)[source]

Bases: Comparator

Compare to formula string.

query_string()[source]

Return the SQL query string used when searching. Should contain one question mark for each argument that is used.

query_args()[source]

Return the arguments used for the query. The number of arguments should be equal to the number of question marks returned by query_string.

class orsopy.slddb.comparators.FuzzyFloat(value, key=None)[source]

Bases: Comparator

Compare a float value against a range or +/-10% of given value.

query_string()[source]

Return the SQL query string used when searching. Should contain one question mark for each argument that is used.

query_args()[source]

Return the arguments used for the query. The number of arguments should be equal to the number of question marks returned by query_string.

orsopy.slddb.constants module

Physical constants and conversion factors used in the package.

The values given here have been taken from the CODATA Internationally recommended 2018 values of the Fundamental Physical Constants provided at https://physics.nist.gov/cuu/Constants/index.html

orsopy.slddb.converters module

Classes for conversion of specific data into sqlite types and back.

class orsopy.slddb.converters.Converter[source]

Bases: ABC

Base class for all other converters, can’t be used stand alone.

sql_type = 'TEXT'
html_list = False
comparator

alias of GenericComparator

html_title = None
validate(data)[source]
abstract convert(data)[source]

Converts data to SQLite format

revert(db_data)[source]
revert_serializable(db_data)[source]
html_input(field, value)[source]
class orsopy.slddb.converters.CType(fromtype, dbtype, db_repstr=None)[source]

Bases: Converter

convert(data)[source]

Converts data to SQLite format

revert(db_data)[source]
class orsopy.slddb.converters.CDate[source]

Bases: Converter

sql_type = 'TEXT'
convert(data)[source]

Converts data to SQLite format

revert(db_data)[source]
revert_serializable(db_data)[source]
html_input(field, value)[source]
class orsopy.slddb.converters.CFormula[source]

Bases: Converter

comparator

alias of FormulaComparator

convert(data)[source]

Converts data to SQLite format

revert(db_data)[source]
html_input(field, value)[source]
class orsopy.slddb.converters.ValidatedString[source]

Bases: CType

regex = None
placeholder = ''
convert(data)[source]

Converts data to SQLite format

html_input(field, value)[source]
class orsopy.slddb.converters.CUrl[source]

Bases: ValidatedString

regex = re.compile('^https?://(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\\.)+(?:[A-Z]{2,6}\\.?|[A-Z0-9-]{2,}\\.?)|localhost|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})(?::\\d+)?(?:/?|[/?]\\S+)$', re.IGNORECASE)
placeholder = 'http://www.your_website.net'
class orsopy.slddb.converters.CMail[source]

Bases: CType

placeholder = 'your.name@domain.net'
html_input(field, value)[source]
class orsopy.slddb.converters.Cdoi[source]

Bases: ValidatedString

regex = re.compile('^https://doi.org/(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\\.)+(?:[A-Z]{2,6}\\.?|[A-Z0-9-]{2,}\\.?)|localhost|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})(?::\\d+)?(?:/?|[/?]\\S+)$', re.IGNORECASE)
placeholder = 'https://doi.org/your/ref'
convert(data)[source]

Converts data to SQLite format

class orsopy.slddb.converters.Ccas[source]

Bases: ValidatedString

regex = re.compile('\\b[1-9][0-9]{1,5}-\\d{2}-\\d\\b', re.IGNORECASE)
placeholder = 'xxxxxxx-yy-z'
class orsopy.slddb.converters.CArray(shape=None, ndim=None)[source]

Bases: Converter

sql_type = 'BLOB'
convert(data)[source]

Converts data to SQLite format

revert(db_data)[source]
revert_serializable(db_data)[source]
class orsopy.slddb.converters.CLimited(fromtype, db_type, low_lim=None, up_lim=None, db_repstr=None)[source]

Bases: CType

validate(data)[source]
convert(data)[source]

Converts data to SQLite format

html_input(field, value)[source]
class orsopy.slddb.converters.CComplex[source]

Bases: CArray

convert(data)[source]

Converts data to SQLite format

revert(db_data)[source]
revert_serializable(db_data)[source]
html_input(field, value)[source]
class orsopy.slddb.converters.CSelect(options)[source]

Bases: CType

convert(data)[source]

Converts data to SQLite format

html_input(field, value)[source]
class orsopy.slddb.converters.CMultiSelect(options)[source]

Bases: CType

html_list = True
convert(data)[source]

Converts data to SQLite format

revert(db_data)[source]
html_input(field, value)[source]

orsopy.slddb.database module

Manage database creation, insertion and access.

class orsopy.slddb.database.SLDDB(dbfile)[source]

Bases: object

Database to store material parameters to calculate scattering length densities (SLDs) for neutron and x-ray scattering.

import_material(filename, name=None, commit=True)[source]
add_material(name, formula, commit=True, **data)[source]
update_material(ID, commit=True, **data)[source]
search_material(join_and=True, serializable=False, filter_invalid=True, limit=100, offset=0, **data)[source]
count_material(join_and=True, filter_invalid=True, **data)[source]
select_material(result)[source]
Return type:

Material

validate_material(ID, user)[source]
invalidate_material(ID, user)[source]
create_table()[source]
create_database()[source]
update_fields()[source]
backup(filename)[source]

orsopy.slddb.dbconfig module

Configure the database file as well as parameters for DB tables used.

orsopy.slddb.importers module

Functions to create database compatible entries from other file formats.

class orsopy.slddb.importers.Importer(filename, validate=True)[source]

Bases: dict

Base class for importing database entries. Includes checks for correctness used by all importers.

formula = None
static validate(**full_entry)[source]
build_data()[source]
class orsopy.slddb.importers.CifImporter(filename, validate=True, sequence=1)[source]

Bases: Importer

suffix = 'cif'
static float_werr(value)[source]
build_data()[source]

orsopy.slddb.material module

Class to hold information for one material and allow calculation of x-ray and neutron SLDs for different applications.

class orsopy.slddb.material.PolymerSequence[source]

Bases: str

Used to represent a chain of amino acids. Currently, no checking is done and this is just a string containing the appropriate letters.

class orsopy.slddb.material.Material(elements, dens=None, fu_volume=None, rho_n=None, mu=0.0, xsld=None, xE=None, fu_dens=None, M=None, ID=None, name=None, extra_data=None)[source]

Bases: object

Units used: b: fm fu_volume: ų fu_dens: 1/ų dens: g/cm³ roh_n: Å^{-2} roh_m: Å^{-2} mu: muB/FU M: kA/m = emu/cm³

property fu_volume
property rho_n
property rho_m
property M
f_of_E(E=8.04116)[source]
rho_of_E(E)[source]
delta_of_E(E)[source]
beta_of_E(E)[source]
mu_of_E(E)[source]
rho_vs_E()[source]
delta_vs_E()[source]
beta_vs_E()[source]
mu_vs_E()[source]
property dens
property fu_mass
property fu_b
property has_ndata
b_of_L(Li)[source]
rho_n_of_L(Li)[source]
b_vs_L()[source]
rho_n_vs_L()[source]
property formula
static convert_subscript(number)[source]
property deuterated
deuterate(fraction)[source]

Return a partially deuterated molecule with fraction of D instead of H.

property edeuterated
property exchanged
property not_exchanged
exchange(D_fraction, D2O_fraction, exchange=0.9)[source]

Return a partially deuterated modlecule within H2O/D2O solution given amount of exchange.

property match_point
match_exchange(D_fraction=0.0, exchange=0.9)[source]
export(xray_units='sld')[source]

Export material data to dictionary.

xray_units: one of “edens”, “n_db” or “sld”

orsopy.slddb.webapi module

class orsopy.slddb.webapi.SLD_API[source]

Bases: object

Python API for users of the SLDDB data.

Allows to query the online database for materials, calculate SLDs and add new materials. If connection to the server fails, a local copy of the database is used, instead.

Usage:

from orsopy.slddb import api res=api.search(formula=”Fe2O3”) res[0][‘density’] => ….

m=api.material(res[0][‘ID’]) # retrieve all data for the given material, see Material class. sldn=m.rho_n # get nuclear neutron SLD (complex number) sldm=m.rho_m # get magnetic neutron SLD (real number) sldx=m.f_of_E(E=8.047823) # get x-ray SLD (complex number) for given energy, default is Cu-Kalpha

# custom material just for SLD calculation, requires either dens, fu_volume, rho_n or xsld+xE m=api.custom(formula=’Au’, dens=19.3)

Units of results/queries:

density: g/cm³ roh_n: Å^{-2} roh_m: Å^{-2} sldx: Å^{-2} fu_volume: ų

db_suburl = 'download_db'
max_age = 1
db: SLDDB = None
check()[source]
download_db()[source]
static webquery(qdict)[source]
localquery(qdict)[source]
localmaterial(ID)[source]
search(**opts)[source]

Search for a particular material using a combination of provided search keys.

Examples:

api.search(formula=”Fe2O3”) api.search(density=5.242) api.search(name=’iron’)

material(ID)[source]

Returns the material object for a certain database entry specified by its unique ID.

Example:

res=api.search(formula=’Fe’) material=api.material(res[0][‘ID’]) print(material.dens, material.rho_n, material.f_of_E(8.0))

static custom(formula, dens=None, fu_volume=None, rho_n=None, mu=0.0, xsld=None, xE=None)[source]

Returns the material object for a certain material as specified by caller.

Example:

res=api.custom(‘Fe’, dens=7.8) print(material.dens, material.rho_n, material.f_of_E(8.0))

bio_blender(sequence, molecule='protein')[source]

Get material for protein, DNA or RNA. Provide a letter sequence and molecule type (‘protein’, ‘dna’, ‘rna’).