materials_commons.cli.cloned_project module

class materials_commons.cli.cloned_project.ClonedProject(email=None, mcurl=None, proj_id=None, path=None, parent_path=None, name=None)[source]

Bases: object

A cloned Materials Commons project instance

local_path

Location of the cloned Materials Commons project

Type

pathlib.Path

proj

Materials Commons project object

Type

materials_commons.api.models.Project

tmpdir

Temporary directory instance. If not None, the temporary directory is the parent of the cloned Materials Commons project directory.

Type

tempfile.TemporaryDirectory or None

Construct a cloned Materials Commons project instance

Examples

Open a project that has already been cloned:

path = "/path/to/materials_commons_projects/ProjectName"
mc_proj = ClonedProject(path=path)

Clone project to a particular directory or open if already cloned:

email = "username@domain.com"
mcurl = "https://materialscommons.org/api"
proj_id = 25
parent_path = "/path/to/materials_commons_projects"
name = None  # default uses remote project name
mc_proj = ClonedProject(email=email,
                        mcurl=mcurl,
                        proj_id=proj_id,
                        parent_path=parent_path,
                        name=name)

Clone project to a temporary directory:

email = "username@domain.com"
mcurl = "https://materialscommons.org/api"
proj_id = 25
mc_proj = ClonedProject(email=email, mcurl=mcurl, proj_id=proj_id)
Parameters
  • email (str) – User account email

  • mcurl (str) – URL for Materials Commons remote instance containing the project. Example: “https://materialscommons.org/api”.

  • proj_id (int) – ID of project to clone.

  • path (str) – Path where the project exists, if already cloned.

  • parent_path (str) – Path to parent directory where the project should be cloned if path is None. If neither path nor parent_path are given, uses a tempfile.TemporaryDirectory for parent_path.

  • name (str) – Name of created project directory. Default is remote project name.

download(*paths, recursive=False, only_print=False, force=False, output=None, globus=False, label=None, no_compare=False)[source]

Download requested files from the Materials Commons project

Parameters
  • recursive (bool) – Download directory contents recursively

  • force (bool) – Force overwrite of existing files

  • only_print (bool) – Print file, do not write

  • output (str) – Download file name. Only allowed if len(paths) == 1.

  • globus (bool) – Use globus to download files

  • label (str) – Globus transfer label to make finding tasks simpler

  • no_compare (bool) – Download remote without checking if local is equivalent

  • *paths (str) – Files or directories to download, specified either using absolute paths or paths relative to the project root directory (self.local_path).

glob(pattern)[source]

Helper to construct paths for upload or download

Parameters

pattern (str) – Pattern, relative to local project directory root, passed as argument to self.local_path.glob(pattern).

Returns

List of str, File paths found from use of glob, made relative to self.local_path and converted to str.

upload(*paths, recursive=False, limit=None, globus=False, label=None, no_compare=False, upload_as=None)[source]

Upload requested files to Materials Commons

Parameters
  • recursive (bool) – Download directory contents recursively

  • limit (str) – File size upload limit (MB). Default=”50” (50MB). Does not apply to Globus uploads.

  • globus (bool) – Use globus to download files

  • label (str) – Globus transfer label to make finding tasks simpler

  • no_compare (bool) – Download remote without checking if local is equivalent

  • upload_as (str) – Upload a file or directory to a particular location in the project. Raises if len(paths) != 1.

  • *paths (str) – Files or directories to upload, specified either using absolute paths or paths relative to the project root directory (self.local_path).