Skip to content

inputs #

Helpers for loading inputs from a standard directory structure.

Classes:

  • Structure

    A basic representation of a single structure (i.e. a ligand or a receptor).

  • Edge

    A basic representation of an edge in a free energy network.

  • Network

    A basic definition of a free energy network of edges.

Functions:

  • find_edges

    Attempts to find the input files for a network free energy 'edges' in the

Structure #

A basic representation of a single structure (i.e. a ligand or a receptor).

Attributes:

  • name (str) –

    The name of the structure.

  • coords (Path) –

    The path to the associated coordinate file (.rst7, .mol2, .pdb).

  • params (Path | None) –

    The path to the associated parameter file (.parm7).

  • metadata (dict[str, Any]) –

    Any additional metadata associated with the structure.

name instance-attribute #

name: str

The name of the structure.

coords instance-attribute #

coords: Path

The path to the associated coordinate file (.rst7, .mol2, .pdb).

params instance-attribute #

params: Path | None

The path to the associated parameter file (.parm7).

metadata instance-attribute #

metadata: dict[str, Any]

Any additional metadata associated with the structure.

Edge #

A basic representation of an edge in a free energy network.

Attributes:

ligand_1 instance-attribute #

ligand_1: Structure

The first ligand.

ligand_2 instance-attribute #

ligand_2: Structure | None

The second ligand if computing a RBFE.

Network #

A basic definition of a free energy network of edges.

Methods:

Attributes:

receptor instance-attribute #

receptor: Structure

The receptor.

edges instance-attribute #

edges: list[Edge]

The edges in the network.

find_edge #

find_edge(
    ligand_1: str, ligand_2: str | None = None
) -> Edge

Find an edge in the network.

Parameters:

  • ligand_1 (str) –

    The name of the first ligand.

  • ligand_2 (str | None, default: None ) –

    The name of the second ligand.

Returns:

  • Edge

    The edge.

Source code in femto/fe/inputs.py
def find_edge(self, ligand_1: str, ligand_2: str | None = None) -> Edge:
    """Find an edge in the network.

    Args:
        ligand_1: The name of the first ligand.
        ligand_2: The name of the second ligand.

    Returns:
        The edge.
    """

    edges = [edge for edge in self.edges if edge.ligand_1.name == ligand_1]

    filter_fn = (
        (lambda e: e.ligand_2 is not None and e.ligand_2.name == ligand_2)
        if ligand_2 is not None
        else (lambda e: e.ligand_2 is None)
    )
    edges = [edge for edge in edges if filter_fn(edge)]

    if len(edges) == 0:
        raise RuntimeError(f"Could not find {ligand_1}~{ligand_2}")

    assert len(edges) == 1, f"found multiple edges for {ligand_1}~{ligand_2}"
    return edges[0]

find_edges #

find_edges(
    root_dir: Path,
    config_cls: type[Network] = femto.fe.config.Network,
    config_path: Path | None = None,
) -> Network

Attempts to find the input files for a network free energy 'edges' in the standard directory structure.

Parameters:

  • root_dir (Path) –

    The root of the directory structure.

  • config_cls (type[Network], default: Network ) –

    The class to use to parse the 'edges.yaml' file if present.

  • config_path (Path | None, default: None ) –

    The path to the file defining the edges to run.

Source code in femto/fe/inputs.py
def find_edges(
    root_dir: pathlib.Path,
    config_cls: type[femto.fe.config.Network] = femto.fe.config.Network,
    config_path: pathlib.Path | None = None,
) -> Network:
    """Attempts to find the input files for a network free energy 'edges' in the
    standard directory structure.

    Args:
        root_dir: The root of the directory structure.
        config_cls: The class to use to parse the ``'edges.yaml'`` file if present.
        config_path: The path to the file defining the edges to run.
    """

    config = (
        _find_config(root_dir, config_cls)
        if config_path is None
        else config_cls(**yaml.safe_load(config_path.read_text()))
    )

    receptor = _find_receptor(root_dir, config.receptor, config.receptor_metadata)
    edges = [_find_edge(root_dir, edge) for edge in config.edges]

    return Network(receptor, edges)