schrodinger.structutils.block_data module

Access non-scalar structured data stored on a Structure.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.structutils.block_data.get_blocks(st, truncate=False)

Return a dict representation of data blocks in given a Structure object. A block is a dict, and subblocks are stored in a list which is a value within the parent block’s dict. This includes data in the both the unrequested and additiona data handles.

Parameters
  • st (structure.Structure or int) – structure object or mmct handle

  • truncate (bool) – whether to truncate multiple instances of the same blocks as a single dict containing only the first subblock, or return all repeated blocks as a list of dicts

schrodinger.structutils.block_data.write_blocks(st, data, truncate=False)

NOTE: This is provided for working with legacy products only; please use structure properties instead of introducing new m2io data blocks.

Inverse function to get_blocks(). Writes a dict representation of data blocks to a Structure object. Top-level blocks that already exist in the Structure object and are given in the input dict representation will be overwritten. If you wish to merge some blocks instead of overwriting them, try exporting existing data blocks and merging it with the desired blocks, and then pass the merged dictionary to write_blocks. Automatic merge is not provided as the operation is ambiguous and may be product-dependent. Note that read_blocks()- write_blocks()-read_blocks() cycle performed on a structure may return error if there are ‘None’ values in the data blocks. To circumvent the problem, after write_blocks() try writing structure to a string and reading it back. Afterwards you may safely perform read_blocks().

Parameters
  • st (structure.Structure or int) – structure object or mmct handle

  • data (dict) – data structure containing data blocks in the same format as returned by get_blocks()

  • truncate (boolean) – controls whether the data provided is in truncated representation, as described in read_blocks()

schrodinger.structutils.block_data.has_block(st, block_name: str) bool

Does the Structure have a block named block_name?

schrodinger.structutils.block_data.get_handle_for_block(st, block_name) int

Return the data handle that has the given block name, or None.

schrodinger.structutils.block_data.append_row_to_data(data, table_name, row_object)

Helper function to present a table-like interface for interacting with blocks. Handles the matching of object properties to block columns, and raises an exception if the object doesn’t contain all table columns. :param data: data object to be written to the maestro block. If no table with the specified name is present, it creates one. :type data: dict

Parameters
  • row_object (dict) – object corresponding to the new row to be appended

  • table_name (string) – name of the table to be appended.