3.1.1.2. obj_tables.chem package

3.1.1.2.1. Submodules

3.1.1.2.2. obj_tables.chem.core module

Chemistry attributes

Author

Jonathan Karr <karr@mssm.edu>

Date

2017-05-10

Copyright

2017, Karr Lab

License

MIT

class obj_tables.chem.core.ChemicalFormulaAttribute(default=None, none_value=None, verbose_name='', description="A chemical formula (e.g. 'H2O', 'CO2', or 'NaCl')", primary=False, unique=False)[source]

Bases: obj_tables.core.LiteralAttribute

Chemical formula attribute

Parameters
  • default (chem.EmpiricalFormula, dict, str, or None, optional) – default value

  • none_value (object, optional) – none value

  • verbose_name (str, optional) – verbose name

  • description (str, optional) – description

  • primary (bool, optional) – indicate if attribute is primary attribute

  • unique (bool, optional) – indicate if attribute value must be unique

deserialize(value)[source]

Deserialize value

Parameters

value (str) – semantically equivalent representation

Returns

  • chem.EmpiricalFormula: cleaned value

  • core.InvalidAttribute: cleaning error

Return type

tuple

from_builtin(json)[source]

Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML

Parameters

json (dict) – simple Python representation of a value of the attribute

Returns

decoded value of the attribute

Return type

chem.EmpiricalFormula

get_xlsx_validation(sheet_models=None, doc_metadata_model=None)[source]

Get XLSX validation

Parameters
  • sheet_models (list of Model, optional) – models encoded as separate sheets

  • doc_metadata_model (type) – model whose worksheet contains the document metadata

Returns

validation

Return type

wc_utils.workbook.io.FieldValidation

serialize(value)[source]

Serialize string

Parameters

value (chem.EmpiricalFormula) – Python representation

Returns

simple Python representation

Return type

str

to_builtin(value)[source]

Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML

Parameters

value (chem.EmpiricalFormula) – value of the attribute

Returns

simple Python representation of a value of the attribute

Return type

dict

validate(obj, value)[source]

Determine if value is a valid value

Parameters
  • obj (Model) – class being validated

  • value (chem.EmpiricalFormula) – value of attribute to validate

Returns

None if attribute is valid, other return

list of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

validate_unique(objects, values)[source]

Determine if the attribute values are unique

Parameters
  • objects (list of Model) – list of Model objects

  • values (list of chem.EmpiricalFormula) – list of values

Returns

None if values are unique, otherwise return a

list of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

class obj_tables.chem.core.ChemicalStructure(value=None, serialized_format=None)[source]

Bases: object

A chemical structure

Attributes

value (openbabel.OBMol, bpforms.BpForm, bcforms.BcForm): value serialized_value (str): serialized value serialized_format (ChemicalStructureFormat): serialized format

_value (openbabel.OBMol, bpforms.BpForm, bcforms.BcForm): value _serialized_value (str): serialized value _serialized_format (ChemicalStructureFormat): serialized format

Parameters
  • value (str, openbabel.OBMol, bpforms.BpForm, bcforms.BcForm, optional) – value

  • serialized_format (ChemicalStructureFormat, openbabel) – serialized format

deserialize(serialized_value)[source]

Set value from a string representation

Parameters

serialized_value (str) – string representation

Returns

self

Return type

ChemicalStructure

from_dict(dict_value)[source]

Set value from a dictionary representation

Parameters

dict_value (dict) – dictionary representation

Returns

self

Return type

ChemicalStructure

serialize()[source]

Generate a string representation

Returns

string representation

Return type

str

property serialized_format[source]
property serialized_value[source]
to_dict()[source]

Get a dictionary representation

Returns

dictionary representation

Return type

dict

property value[source]
class obj_tables.chem.core.ChemicalStructureFormat[source]

Bases: int, wc_utils.util.enumerate.CaseInsensitiveEnum

Format of a chemical structure

bcforms = 4[source]
bpforms = 3[source]
inchi = 1[source]
smiles = 2[source]
class obj_tables.chem.core.ChemicalStructureAttribute(verbose_name='', description='The InChI, SMILES-, BpForms, BcForms-encoded structure of a compound.nnExamples:n Small molecules (SMILES): C([N+])C([O-])=On DNA (BpForms/dna): A{m2C}GTn RNA (BpForms/rna): AC{02G}Un Protein (BpForms/protein): RNC{AA0037}En Complex (BcForms): 2 * subunit-A + subunit-B', primary=False, unique=False)[source]

Bases: obj_tables.core.LiteralAttribute

Attribute for the structures of chemical compounds

Parameters
  • verbose_name (str, optional) – verbose name

  • description (str, optional) – description

  • primary (bool, optional) – indicate if attribute is primary attribute

  • unique (bool, optional) – indicate if attribute value must be unique

deserialize(value)[source]

Deserialize value

Parameters

value (str) – string representation of structure

Returns

  • str: cleaned value

  • core.InvalidAttribute: cleaning error

Return type

tuple

from_builtin(json)[source]

Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML

Parameters

json (dict) – simple Python representation of a value of the attribute

Returns

chemical structure

Return type

ChemicalStructure

get_xlsx_validation(sheet_models=None, doc_metadata_model=None)[source]

Get XLSX validation

Parameters
  • sheet_models (list of Model, optional) – models encoded as separate sheets

  • doc_metadata_model (type) – model whose worksheet contains the document metadata

Returns

validation

Return type

wc_utils.workbook.io.FieldValidation

serialize(value)[source]

Serialize chemical structure

Parameters

value (ChemicalStructure) – structure

Returns

string representation

Return type

str

to_builtin(value)[source]

Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML

Parameters

value (ChemicalStructure) – chemical structure

Returns

simple Python representation of a value of the attribute

Return type

dict

validate(obj, value)[source]

Determine if value is a valid value

Parameters
  • obj (Model) – class being validated

  • value (ChemicalStructure) – value of attribute to validate

Returns

None if attribute is valid, other return list of

errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

validate_unique(objects, values)[source]

Determine if the attribute values are unique

Parameters
  • objects (list of Model) – list of Model objects

  • values (list of ChemicalStructure) – list of values

Returns

None if values are unique, otherwise return a

list of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

class obj_tables.chem.core.ReactionEquation[source]

Bases: list

Reaction equation

class ParseTreeTransformer(species=None, compartments=None)[source]

Bases: lark.visitors.Transformer

Transforms parse trees into an instance of ReactionEquation

species[source]

dictionary that maps species ids to instances

Type

dict

compartments[source]

dictionary that maps compartment ids to instances

Type

dict

Parameters
  • species (dict, optional) – dictionary that maps species ids to instances

  • compartments (dict, optional) – dictionary that maps compartment ids to instances

gbl(*args)[source]
gbl_part(*args)[source]
gbl_parts(*args)[source]
lcl(*args)[source]
lcl_part(*args)[source]
lcl_parts(*args)[source]
start(parts)[source]
deserialize(value, species=None, compartments=None)[source]

Set the participants from a string representation

Parameters
  • value (str) – string representation

  • species (dict, optional) – dictionary that maps species ids to instances

  • compartments (dict, optional) – dictionary that maps compartment ids to instances

file = <_io.TextIOWrapper name='/root/project/obj_tables/chem/reaction_equation.lark' mode='r' encoding='UTF-8'>[source]
is_equal(other)[source]

Determine if two reaction equations are semantically equivalent

Parameters

other (ReactionEquation) – other reaction equation

Returns

True if the objects are semantically equivalent

Return type

bool

parser = Lark(open('<string>'), parser='earley', lexer='dynamic', ...)[source]
serialize()[source]

Generate a string representation

Returns

string representation

Return type

str

to_dict()[source]

Get a simple Python representation compatible with JSON

Returns

simple Python representation

Return type

list

class obj_tables.chem.core.ReactionParticipant(species=None, compartment=None, stoichiometry=None)[source]

Bases: object

Participant in a reaction

species[source]

species

Type

str or core.Model

compartment[source]

compartment

Type

str or core.Model

stoichiometry[source]

stoichiometry

Type

float

Parameters
  • species (str or core.Model, optional) – species

  • compartment (str or core.Model, optional) – compartment

  • stoichiometry (float, optional) – stoichiometry

is_equal(other)[source]

Determine if two reaction participants are semantically equivalent

Parameters

other (ReactionParticipant) – other reaction equation

Returns

True if the objects are semantically equivalent

Return type

bool

serialize(include_compartment=True)[source]

Generate a string representation

Parameters

include_compartment (bool, optional) – if True, include compartment in string representation

Returns

string representation

Return type

str

to_dict()[source]

Get a simple Python representation compatible with JSON

Returns

simple Python representation

Return type

dict

class obj_tables.chem.core.ReactionEquationAttribute(verbose_name='', description="A reaction equation (e.g. 'A[c] <=> B[e]', '[c]: A <=> B')", none=True, unique=False, species_cls=None, compartment_cls=None)[source]

Bases: obj_tables.core.BaseRelatedAttribute, obj_tables.core.LiteralAttribute

Reaction equation attribute

none[source]

if False, the attribute is invalid if its value is None

Type

bool

species_cls[source]

class which represents species compartment_cls (type or str): class which represents compartments

Type

type or str

Parameters
  • verbose_name (str, optional) – verbose name

  • description (str, optional) – description

  • none (bool, optional) – if False, the attribute is invalid if its value is None

  • unique (bool, optional) – indicate if attribute value must be unique

  • species_cls (type or str, optional) – class which represents species

  • compartment_cls (type or str, optional) – class which represents compartments

deserialize(value, objects=None, decoded=None)[source]

Deserialize value

Parameters
  • value (str) – semantically equivalent representation

  • objects (dict, optional) – dictionary of objects, grouped by model

  • decoded (dict, optional) – dictionary of objects that have already been decoded

Returns

Return type

tuple

from_builtin(json)[source]

Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML

Parameters

json (dict) – simple Python representation of a value of the attribute

Returns

decoded value of the attribute

Return type

ReactionEquation

get_xlsx_validation(sheet_models=None, doc_metadata_model=None)[source]

Get XLSX validation

Parameters
  • sheet_models (list of Model, optional) – models encoded as separate sheets

  • doc_metadata_model (type) – model whose worksheet contains the document metadata

Returns

validation

Return type

wc_utils.workbook.io.FieldValidation

serialize(value)[source]

Serialize string

Parameters

value (ReactionEquation) – Python representation

Returns

simple Python representation

Return type

str

to_builtin(value)[source]

Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML

Parameters

value (ReactionEquation) – value of the attribute

Returns

simple Python representation of a value of the attribute

Return type

dict

validate(obj, value)[source]

Determine if value is a valid value

Parameters
  • obj (Model) – class being validated

  • value (ReactionEquation) – value of attribute to validate

Returns

None if attribute is valid, other return

list of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

validate_unique(objects, values)[source]

Determine if the attribute values are unique

Parameters
  • objects (list of Model) – list of Model objects

  • values (list of ReactionEquation) – list of values

Returns

None if values are unique, otherwise return a

list of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

3.1.1.2.3. Module contents