pestifer.tasks.basetask module

This module defines the BaseTask class, which serves as a base class for all task types in the pestifer framework. The BaseTask class provides a common interface and some basic functionality for tasks, including task initialization, logging, state management, and file handling. It is intended to be subclassed by specific task types that implement their own specific behavior and functionality. The BaseTask class includes methods for task execution, state variable management, file collection, and task name management. It also provides a mechanism for inheriting state from prior tasks, saving the task state to a YAML file, and copying the state to files based on specified extensions. The class also includes methods for converting coordinate files to PDB files and vice versa, as well as creating constraint PDB files based on task specifications. The BaseTask class is designed to be flexible and extensible, allowing for the creation of various task types that can perform different operations on molecular structures.

Available tasks that inherit from BaseTask include all those in the pestifer.tasks subpackage.

class pestifer.tasks.basetask.BaseTask(specs: dict = None, **kwargs)[source]

Bases: ABC

A base class for Tasks. This class is intended to be subclassed by specific task types. It provides a common interface and some basic functionality for tasks. All tasks are assigned to a PipelineContext owned by a Controller.

Parameters:
  • config_specs (dict, optional) – A dictionary of configuration specifications. This can include task-specific settings.

  • controller_specs (dict, optional) – A dictionary of specifications provided by the controller that created this task. It can include attributes like prior, index, scripters, taskname, and controller_index.

abstractmethod do() int[source]

This a stub method that should be overridden by subclasses. It is intended to be the main method that performs the task’s operations. Subclasses should implement this method to define the specific behavior of the task. This method is called when the task is executed.

execute() int[source]

Execute the task. This method calls the do method, which should be implemented by subclasses to perform the task’s operations. It also logs the initiation and completion of the task.

get_current_artifact(key, **kwargs)[source]

Get the current artifact with the specified key from the context. This method retrieves the artifact from the context that matches the specified key.

Parameters:

key (str) – The key of the artifact to retrieve from the context.

Returns:

The artifact associated with the specified key, or None if not found.

Return type:

Artifact

get_current_artifact_data(key)[source]

Get the current artifact data with the specified key from the context. This method retrieves the artifact from the context that matches the specified key.

Parameters:

key (str) – The key of the artifact to retrieve from the context.

Returns:

The artifact associated with the specified key, or None if not found.

Return type:

Artifact

get_current_artifact_path(key, default=None)[source]

Get the current artifact path with the specified key from the context. This method retrieves the artifact from the context that matches the specified key.

Parameters:

key (str) – The key of the artifact to retrieve from the context.

Returns:

The artifact associated with the specified key, or None if not found.

Return type:

Artifact

get_my_artifactfile_collection() FileArtifactList[source]

Get a collection of artifact files produced by the current task. This method retrieves all artifact files that have been registered in the context and are associated with the current task.

Returns:

A list of artifact files associated with the current task.

Return type:

list

get_scripter(name: str)[source]

Get a scripter by name from the pipeline’s scripters.

Parameters:

name (str) – The name of the scripter to retrieve.

Returns:

The scripter instance associated with the given name.

Return type:

Scripter

import_artifacts(pipeline: PipelineContext)[source]

Imports artifacts from the pipeline context into the task.

property is_provisioned: bool

Check if the task has been provisioned with necessary resources.

Returns:

True if the task has been provisioned, False otherwise.

Return type:

bool

log_message(message, **kwargs)[source]

Logs a message with the task’s index and name.

Parameters:
  • message (str) – The message to log.

  • **kwargs (dict) – Additional keyword arguments that can be used to add extra information to the log message. These are typically used to provide additional context or details about the task’s execution.

next_basename(extra_label: str = '')[source]

Generates a new basename for the task based on the controller index, task index, subtask count, and task name. If the specs dictionary contains a ‘basename’ key, it overrides the default basename. The basename is constructed in the format: (controller_index)-(task_index)-(subtask_count)_(taskname)[-(label)]. If extra_label is provided, it is used as the label. For example, next_basename(‘mylabel’) would result in a basename like 01-02-03_taskname-mylabel.

override_taskname(taskname)[source]

Override the task name with a new name. Certain situations may require a Controller to override the task name. This method is used to change the task name after the task has been created.

Parameters:

taskname (str) – The new task name to set.

provision(packet: dict = None)[source]

Provision the task with necessary resources. This method is called to set up the task with the required resources and context. It can be overridden by subclasses to provide additional provisioning logic.

Parameters:

packet (dict, optional) – A dictionary of provisions to be used for the task. If not provided, the existing provisions will be used.

register(data: object, key: str, artifact_type=<class 'pestifer.core.artifacts.DataArtifact'>, **kwargs)[source]

Register data as an artifact in the pipeline context.

Parameters:
  • data (object) – The data to be registered as an artifact.

  • key (str) – The key under which the artifact will be registered.

  • **kwargs (dict) – Additional keyword arguments that may include metadata or other information

register_if_exists(data: object, requestor: object, artifact_type: type = <class 'pestifer.core.artifacts.FileArtifact'>, **kwargs) FileArtifact | None[source]
stash_current_artifact(key)[source]

Stash the current artifact with the specified key into the history. This method moves the current artifact from the context to the history list.

class pestifer.tasks.basetask.VMDTask(specs: dict = None, **kwargs)[source]

Bases: BaseTask, ABC

A base class for tasks that require VMD scripting. This class extends the BaseTask class and provides additional functionality for tasks that involve VMD scripting. It includes methods for converting coordinate files to PDB files, converting PDB files to coordinate files, and creating constraint PDB files. The VMDTask class is intended to be subclassed.

coor_to_pdb(coorfilename: str, psffilename: str) str[source]

Converts a namdbin coordinate file to a PDB file using catdcd.

make_constraint_pdb(specs: dict, statekey: str = 'consref')[source]

Creates a PDB file with constraints based on the specifications provided. This method generates a VMD script that selects atoms based on the specifications and writes a PDB file with the specified constraints. The resulting PDB file is named based on the task’s basename and the state key. This allows the task to keep track of the constraints PDB file in its state. The method uses the VMD script writer to create and run the script that generates the constraints PDB file. The script selects all atoms, sets their occupancy to 0.0, selects the constrained atoms based on the specifications, and sets their occupancy to the specified force constant. Finally, it writes the PDB file with the specified name. If the ‘consref’ key is not provided in the specifications, it defaults to f'{self.basename}-constraints.pdb'. The resulting PDB file is then stored in the task’s state variables under the specified statekey. If the specified atoms are not found in the PDB, an error will be raised.

Parameters:
  • specs (dict) –

    A dictionary containing the specifications for the constraints. It should include:

    • k: The force constant for the constraints (default is taken from the config).

    • atoms: A string defining the atoms to be constrained (default is all).

    • consref: The name of the output PDB file for constraints (default is f'{self.basename}-constraints.pdb').

  • statekey (str, optional) – The key under which the resulting PDB file will be stored in the state variables. Default is consref.

make_ssrestraints_file(specs: dict, statekey: str = 'extrabonds') str[source]

Run the VMD ssrestraints plugin against the current state’s PSF/PDB and produce a NAMD extraBonds file. Registers the resulting file (and the Tcl driver script + VMD log) as artifacts.

Parameters:
  • specs (dict) – The ssrestraints sub-dict from the md task spec; see the schema entry for the full set of keys.

  • statekey (str, optional) – Artifact key under which the generated extraBonds file is registered. Default is extrabonds.

Returns:

Filename of the generated extraBonds file (<basename>.extrabonds).

Return type:

str

pdb_to_coor(pdbfilename: str) str[source]

Converts a PDB file to a namdbin coordinate file using catdcd.