gt4sd.frameworks.gflownet.envs.mol_building_env module

Summary

Classes:

MolBuildingEnvContext

A context environment for building molecular graphs.

Reference

class MolBuildingEnvContext(atoms=['H', 'C', 'N', 'O', 'F'], num_cond_dim=32, device='cpu')[source]

Bases: GraphBuildingEnvContext

A context environment for building molecular graphs.

__init__(atoms=['H', 'C', 'N', 'O', 'F'], num_cond_dim=32, device='cpu')[source]

Initialize a generic context environment for molecules.

A specification of what is being generated for a GraphBuildingEnv. This context specifies how to create molecules atom-by-atom (and attribute-by-attribute).

Code adapted from: https://github.com/recursionpharma/gflownet/tree/trunk/src/gflownet/envs

Parameters
  • atoms (List[str]) – basic building blocks. In principle we can infer this information from the dataset.

  • num_cond_dim (int) – number of conditional dimensions.s

  • device – device to use (cpu, cuda).

aidx_to_graph_action(g, action_idx)[source]

Translate an action index (e.g. from a GraphActionCategorical) to a GraphAction.

Parameters
  • g (Data) – The graph to act on.

  • action_idx (Tuple[int, int, int]) – The action index.

Raises

ValueError – If the action index is invalid.

Return type

GraphAction

Returns

The action corresponding to the action index.

graph_action_to_aidx(g, action)[source]

Translate a GraphAction to an index tuple.

Parameters
  • g (Data) – The graph to act on.

  • action (GraphAction) – The action to translate.

Return type

Tuple[int, int, int]

Returns

The index corresponding to the action.

graph_to_data(g)[source]

Convert a networkx Graph to a torch geometric Data instance.

Parameters

g (Graph) – Networkx Graph to convert.

Return type

Data

Returns

torch geometric Data instance.

collate(graphs)[source]

Batch Data instances.

Parameters

graphs (List[Data]) – List of Data instances.

Returns

Batch of Data instances.

mol_to_graph(mol)[source]

Convert an RDMol to a Graph.

Parameters

mol (Mol) – RDKit molecule format.

Return type

Graph

Returns

Graph format.

graph_to_mol(g)[source]

Convert a Graph to an RDKit molecule.

Parameters

g (Graph) – Graph format.

Return type

Mol

Returns

RDKit molecule format.

is_sane(g)[source]

Check if a graph is sane.

Parameters

g (Graph) – Graph format.

Return type

bool

Returns

True if sane, False otherwise.

__annotations__ = {}
__doc__ = 'A context environment for building molecular graphs.'
__module__ = 'gt4sd.frameworks.gflownet.envs.mol_building_env'