MDTrees package

Submodules

MDTrees.mdbranch module

class MDTrees.mdbranch.MDBranch(name=None, s3=None, path=None, orionID=None, trajectory=None, children={}, parent_hash=None, parent_frame=-1, metadata={})

Bases: object

delete_data(local=True, s3=False, orion=False)

Deletes trajectory data from selected locations

Parameters
  • local (bool) – Select local trajectory file for deletion (Default value = True)

  • s3 (bool) – Select S3 object for deletion (Default value = False)

  • orion (bool) – Select Orion file for deletion (Default value = False)

delete_metadata(name)
download_orion(path)

Downloads a trajectory from Orion

Parameters

path (str) – Target download path

Returns

path to trajectory

Return type

str

download_s3(path)

Downloads a trajectory from S3

Parameters

path (str) – Target download path

Returns

path to trajectory

Return type

str

get_metadata(name)
get_trajectory(frame=None)

Retrieve the trajectory object for the branch

Parameters

frame (int, optional) – frame to retrieve, by default None

Returns

Trajectory object for the branch

Return type

MDTraj

has_child(branch)

See if the given branch is the child of this branch.

Parameters

branch (MDBranch) – Branch to check

Returns

True if the input branch is a child of this branch, False otherwise

Return type

bool

has_metadata(name)
property hash

hash the whole trajectory with the MDtraj hash function TODO Write automatic download from s3 or orion

Returns

Trajectory hash

Return type

str

hash_snapshot(index=0)

Generate a hash value for a given frame, it will default to first frame for branching check

Parameters

index (int) – Frame index to hash (Default value = 0)

Returns

Hash for the frame

Return type

str

list_metadata_name()
load_trajectory(path=None)

Read from local file, if no file is provided then it will try reading from the self.path

Parameters

path (str or None) – Optional path to trajectory file (Default value = None)

Returns

Loaded trajectory object

Return type

mdtraj.Trajectory

set_metadata(name, value: list, in_dict=True)
upload_orion(path=None)

Uploads a trajectory file to Orion

Parameters

path (str) – optional path to h5 trajectory file (Default value = None)

Returns

Orion file ID

Return type

int

upload_s3(path=None)

Uploads a trajectory file to S3.

Parameters

path (str) – optional path to h5 trajectory file (Default value = None)

Returns

S3 object path

Return type

str

write(path=None, overwrite=False)

Write to local file, if no file is provided then it will try reading from the self.path

Parameters
  • path – str or None (Default value = None)

  • overwrite – bool (Default value = False)

Returns

Trajectory file path

Return type

str

MDTrees.mdbranch.get_minio_client()

Constructs a Minio storage client with the appropriate credentials

Returns

Minio client object

Return type

minio.Minio

MDTrees.mdtree module

class MDTrees.mdtree.MDTree(parmed=None, tree_json=None, master_branch=None)

Bases: object

append(branch)

Automatically attached new trajectory to the end of other simulation, need the tree to be linear.

Parameters

branch (MDBranch) – Branch to insert

check()

Performs a sanity check on the current Tree, including 1. The Tree is not cyclic 2. The Tree has data 3. There is a master branch 4. All children and parents of any branch is also in the Tree.

Returns

True if all criteria is passed, else False

Return type

bool

children_count(branch)

Tells you how many child a given branch has

Parameters

branch (MDBranch or str) – Branch in the tree or its hash

Returns

Count of the children of the branch

Return type

int

delete_branch(branch: str, force_remove_children=False, delete_data=False)

This method will delete one branch only when they have no child branches, and if a child branch is present, it will fail and raise an error. However if the force_remove_children is True it will automatically delete all Children branches as well. You can also specify if you want to delete the data on disk, orion, or s3 as well.

TODO: write delete_data capability

Parameters
  • branch (str or MDBranch) – Hash or branch to remove

  • force_remove_children (bool) – Set to True to force delete branches with children(Default value = False)

  • delete_data (bool) – Delete trajectory data for the branch (Default value = False)

get_branch_by_name(name)

Retrieves branches in the tree that match a given name

Parameters

name (str) – Branch name

Yields

MDBranch – Branch with matching name

get_children(branch)

Generator function for the child branches of a given branch

Parameters

branch (MDBranch or str) – Branch/hash to get the children for

Yields

MDBranch – Children of the branch

get_end_branch()

Get the end branch for a linear tree

Returns

The end branch of the tree or None if the tree is not linear

Return type

MDBranch or None

get_master_branch()

Get the master branch of the current Tree, a master branch is defined as the only Tree with no parent.

Returns

Return type

MDBranch

get_topology()
insert(branch, parent, frame)

Inserts a branch into the tree

Parameters
  • branch (MDBranch) – Branch to insert

  • parent (str or MDBranch) – Parent branch to insert under

  • frame (int) – Parent frame to insert under

property is_cyclic

Perform self check and return if a cyclic (illegal) structure is detected.

Returns

Whether the tree contains a cycle

Return type

bool

property is_linear

Check if the tree is linear with no branching, useful for doing simple sequential simulation.

Returns

Whether the tree is linear

Return type

bool

load(tree_json)

Load from a json file or object and populate the internal data structure

Parameters

json (str or dict) – json file path or object to read from

Returns

True if the operation succeeded, False otherwise

Return type

bool

remove(branch)

Remove a branch if it is inside the tree and doesn’t have children, else raise error

Parameters

branch (MDBranch) –

remove_child(branch)

Remove all children branch of the this branch, does not remove the branch itself. :param branch: :type branch: MDBranch

remove_parent(branch)

Remove the all parents and all the children branch of the parents branch. Does not remove the branch itself.

Parameters

branch (MDBranch) –

serialize()
set_master_branch(branch)

Set a branch as a master branch for this Tree, if the tree is empty then this Branch is added. If the branch is not empty, then the branch must be inside the Tree, and all parents of the branch is removed by remove_parent function.

Parameters

branch (MDBranch) –

write(json_path)

Writes the json representation to a local file

Parameters

json_path (str) – Path to directory to write to

Returns

True if the operation succeeded, False otherwise

Return type

bool

write_to_orion(json_fn='mdtree.json')

Writes the json representation to an Orion file

Parameters

json_fn (str) – Filename to use (Default value = “mdtree.json”)

Returns

Orion id for the uploaded file

Return type

int

write_to_s3(bucket, key)

Writes the json representation to an S3 object

Parameters
  • bucket (str) – Name of s3 bucket to write to

  • key (str) – Name of object key to write to

Module contents